-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Added NMSChunk.getX and NMSChunk.getZ -Created NMSChunkDef to hold some internal chunk methods, without exposing them -Added NMSChunk.saveAndRefresh with a race condition fix for 1.8 Took 50 minutes
- Loading branch information
1 parent
09f4242
commit 3306b0f
Showing
29 changed files
with
385 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nms/api/src/main/java/com/kamikazejam/kamicommon/nms/wrappers/chunk/impl/NMSChunkDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.kamikazejam.kamicommon.nms.wrappers.chunk.impl; | ||
|
||
import com.kamikazejam.kamicommon.nms.wrappers.chunk.NMSChunk; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
public interface NMSChunkDef extends NMSChunk { | ||
|
||
@Override | ||
default void saveAndRefresh(boolean withUpdatePackets) { | ||
this.saveAndRefreshI(withUpdatePackets); | ||
} | ||
|
||
// Create a default inside this internal interface, to not expose this method | ||
@SuppressWarnings("deprecation") | ||
default void saveAndRefreshI(boolean withUpdatePackets) { | ||
World world = this.getNMSChunkProvider().getNMSWorld().getBukkitWorld(); | ||
world.refreshChunk(this.getX(), this.getZ()); | ||
// Use the unload method with save | ||
world.unloadChunk(this.getX(), this.getZ(), true); | ||
|
||
// Re-send some chunk packets so that stubborn clients update | ||
if (withUpdatePackets) { | ||
int viewDistance = Bukkit.getViewDistance(); | ||
for (Player player : world.getPlayers()) { | ||
int cX = player.getLocation().getChunk().getX(); | ||
int cZ = player.getLocation().getChunk().getZ(); | ||
|
||
if (this.getX() > cX + viewDistance || this.getX() < cX - viewDistance) { continue; } | ||
if (this.getZ() > cZ + viewDistance || this.getZ() < cZ - viewDistance) { continue; } | ||
|
||
this.sendUpdatePacket(player); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.