|
Bukkit.getScheduler().runTaskTimer(this, () -> { |
|
if (game != null && game.isRunning()) { |
|
// Update the compass to the players location |
|
Player hunted = game.getHuntedPlayer(); |
|
if (hunted == null) return; |
|
final Location overworldLoc; |
|
final Location loadstoneLoc; |
|
switch (hunted.getWorld().getEnvironment()) { |
|
case NETHER: |
|
overworldLoc = game.getNetherPortalOverworld(); |
|
loadstoneLoc = hunted.getLocation(); |
|
break; |
|
case THE_END: |
|
overworldLoc = game.getEndPortal(); |
|
loadstoneLoc = game.getNetherPortalNether(); |
|
break; |
|
default: |
|
overworldLoc = hunted.getLocation(); |
|
loadstoneLoc = game.getNetherPortalNether(); |
|
break; |
|
} |
|
game.getHunterPlayers().forEach(p -> { |
|
if (p.getWorld().getEnvironment() == World.Environment.NETHER) { |
|
if(loadstoneLoc == null) return; |
|
for(int i = 0; i < 36; i++) { |
|
ItemStack it = p.getInventory().getStorageContents()[i]; |
|
if(it.getItemMeta() != null && it.getType() == Material.COMPASS) { |
|
CompassMeta meta = (CompassMeta) it.getItemMeta(); |
|
meta.setLodestoneTracked(false); |
|
meta.setLodestone(loadstoneLoc); |
|
it.setItemMeta(meta); |
|
} |
|
} |
|
} else { |
|
p.setCompassTarget(overworldLoc); |
|
} |
|
}); |
|
|
|
// If a player is holding a compass+ then update their action bar to show the distance from the player |
|
// the hunted player is in |
|
|
|
for (Player p : Bukkit.getOnlinePlayers()) { |
|
if (p.getInventory().getItemInMainHand().equals(COMPASS_PLUS) || p.getInventory().getItemInOffHand().equals(COMPASS_PLUS)) { |
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, |
|
new ComponentBuilder() |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "Dimension: ") |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "ยงl" + Util.dimensionName(hunted.getLocation())) |
|
.append(" ") |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "Distance: ") |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "ยงl" + Math.round(p.getLocation().distance(p.getWorld().getEnvironment() == World.Environment.NETHER ? loadstoneLoc : overworldLoc)) + "m") |
|
.create()); |
|
} else if (p.getInventory().getItemInMainHand().equals(COMPASS) || p.getInventory().getItemInOffHand().equals(COMPASS)) { |
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, |
|
new ComponentBuilder() |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "Dimension: ") |
|
.append(Util.colorFromDimension(hunted.getLocation()).toString() + "ยงl" + Util.dimensionName(hunted.getLocation())) |
|
.create()); |
|
} |
|
|
|
} |
|
|
|
} |
|
}, 100, 10); |