@Override public void onPlayerTeleport(PlayerTeleportEvent event) { if (Permissions.TELEPORT.has(event.getPlayer())) return; if (event.getFrom().getWorld().equals(event.getTo().getWorld()) && event.getFrom().distance(event.getTo()) < 5) return; ChunkyResident chunkyResident = new ChunkyResident(event.getPlayer()); ChunkyTown myTown = chunkyResident.getTown(); if (myTown == null) return; TownChunk fromChunk = new TownChunk(ChunkyManager.getChunkyChunk(event.getFrom())); TownChunk toChunk = new TownChunk(ChunkyManager.getChunkyChunk(event.getTo())); ChunkyTown fromTown = fromChunk.getTown(); if (fromTown != null && fromTown.getEffectiveStance(myTown) != ChunkyTown.Stance.ALLY) { Strings.NO_TELEPORT.bad(chunkyResident); event.setCancelled(true); return; } ChunkyTown toTown = toChunk.getTown(); if (toTown != null && toTown.getEffectiveStance(myTown) != ChunkyTown.Stance.ALLY) { Strings.NO_TELEPORT.bad(chunkyResident); event.setCancelled(true); return; } }
public void onCommand( CommandSender sender, ChunkyCommand chunkyCommand, String s, String[] strings) { if (!(sender instanceof Player)) { Language.IN_GAME_ONLY.bad(sender); return; } if (!Permissions.CREATE_TOWN.has(sender)) { Language.NO_COMMAND_PERMISSION.bad(sender); return; } Player player = (Player) sender; ChunkyResident chunkyResident = new ChunkyResident(player); if (chunkyResident.getTown() != null) { Language.sendBad(chunkyResident.getChunkyPlayer(), "You are already part of a town."); return; } if (strings.length < 1) { Language.sendBad(chunkyResident.getChunkyPlayer(), "Please specify the town name."); return; } ChunkyChunk chunkyChunk = chunkyResident.getChunkyPlayer().getCurrentChunk(); if (chunkyChunk.isOwned()) { Language.sendBad(chunkyResident.getChunkyPlayer(), "This chunk is already owned."); return; } String id = strings[0]; ChunkyTown chunkyTown = new ChunkyTown(); chunkyTown.setId(ChunkyManager.getUniqueId()); chunkyTown.setMayor(chunkyResident).setHome(chunkyChunk).setName(id); chunkyChunk.setOwner(chunkyTown, true, true); chunkyChunk.save(); Language.sendGood( chunkyResident.getChunkyPlayer(), "You've just created a town called " + chunkyTown.getName()); }