Skip to content

Commit

Permalink
Merge pull request #12 from StarLightMinecraft/master
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
cavallium authored Jun 7, 2022
2 parents 846e8c0 + 0f2722f commit 2b9b663
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private PacketContainer cloneTileEntityData(PacketContainer packet) {
packet = packet.shallowClone();
int i = 0;
for (final NbtBase<?> obj : packet.getNbtModifier().getValues()) {
if (obj == null) continue;
packet.getNbtModifier().write(i, obj.deepClone());
i++;
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/org/warp/coordinatesobfuscator/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public class PlayerManager {
private static LastPlayerCoordinateManager lastPlayerCoordinateManager;

public static void spawnPlayer(final Player player, final World world) {
coordsOffsetsManager.put(player, world, generateOffset());
coordsOffsetsManager.put(player, world, generateOffset(player, world)); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
lastPlayerCoordinateManager.setLastPlayerLocation(player.getUniqueId(), player.getLocation());
}

public static CoordinateOffset respawnPlayer(final Player player, final World world) {
CoordinateOffset offset = generateOffset();
CoordinateOffset offset = generateOffset(player,world); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
coordsOffsetsManager.replace(player, world, offset);
lastPlayerCoordinateManager.setLastPlayerLocation(player.getUniqueId(), player.getLocation());
return offset;
}

public static CoordinateOffset teleportPlayer(final Player player, final World world, boolean overrideLastLocation) {
CoordinateOffset offset = generateOffset();
CoordinateOffset offset = generateOffset(player,world); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
coordsOffsetsManager.replace(player, world, offset);
if (overrideLastLocation) {
lastPlayerCoordinateManager.setLastPlayerLocation(player.getUniqueId(), player.getLocation());
Expand All @@ -43,16 +43,22 @@ public static CoordinateOffset teleportPlayer(final Player player, final World w

public static void joinPlayer(final Player player) {
if (!(player instanceof TemporaryPlayer)) {
coordsOffsetsManager.getOrPut(player, player.getWorld(), PlayerManager::generateOffset);
coordsOffsetsManager.getOrPut(player, player.getWorld(), () -> generateOffset(player,player.getWorld())); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
lastPlayerCoordinateManager.setLastPlayerLocation(player.getUniqueId(), player.getLocation());
} else {
lastPlayerCoordinateManager.resetLastPlayerLocation(player.getUniqueId());
}
}

private static CoordinateOffset generateOffset() {
private static CoordinateOffset generateOffset(Player player, World world) {
if (player.hasPermission("coordinatesobfuscator.bypass")) return CoordinateOffset.of(0, 0); //StarLightMinecraft - permission to bypass the obfuscation
//return CoordinateOffset.of(64 * 16, 64 * 16);
return CoordinateOffset.of(getRandomChunkOffset(true) * 16, getRandomChunkOffset(false) * 16);
// StarLightMinecraft Start - make center and size of the world border into the offset to make sure it's always generate in the world border
int x = world.getWorldBorder().getCenter().getBlockX();
int z = world.getWorldBorder().getCenter().getBlockZ();
double size = world.getWorldBorder().getSize();
// StarLightMinecraft End
return CoordinateOffset.of((getRandomChunkOffset(true) * 16) % (size * 2) - x, getRandomChunkOffset(false) * 16 % (size * 2) - z); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
}

private static int getRandomChunkOffset(boolean x) {
Expand Down Expand Up @@ -100,11 +106,11 @@ public static CoordinateOffset getOffsetOrJoinPlayer(Player player, World world)
AtomicBoolean generated = new AtomicBoolean(false);
CoordinateOffset result = coordsOffsetsManager.getOrPut(player, world, () -> {
generated.set(true);
return generateOffset();
return generateOffset(player,world); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
});
if (generated.get()) {
if (!(player instanceof TemporaryPlayer)) {
coordsOffsetsManager.getOrPut(player, player.getWorld(), PlayerManager::generateOffset);
coordsOffsetsManager.getOrPut(player, player.getWorld(), () -> generateOffset(player,world)); // StarLightMinecraft - make center and size of the world border into the offset to make sure it's always generate in the world border
}
lastPlayerCoordinateManager.resetLastPlayerLocation(player.getUniqueId());
}
Expand Down

0 comments on commit 2b9b663

Please sign in to comment.