public boolean canPlayerUseBlock(Player player, Block block) { if (Conf.adminBypassPlayers.contains(player.getName())) { return true; } Material material = block.getType(); FLocation loc = new FLocation(block); Faction otherFaction = Board.getFactionAt(loc); // no door/chest/whatever protection in wilderness, war zones, or safe zones if (!otherFaction.isNormal()) { return true; } // We only care about some material types. if (otherFaction.hasPlayersOnline()) { if (!Conf.territoryProtectedMaterials.contains(material)) { return true; } } else { if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) { return true; } } FPlayer me = FPlayer.get(player); Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelation(otherFaction); boolean ownershipFail = Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc); // You may use any block unless it is another faction's territory... if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) { me.sendMessage( "You can't use " + TextUtil.getMaterialName(material) + " in the territory of " + otherFaction.getTag(myFaction)); return false; } // Also cancel if player doesn't have ownership rights for this claim else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) { me.sendMessage( "You can't use " + TextUtil.getMaterialName(material) + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); return false; } return true; }
@Override public void onMessageToChannel(CAPIMessageToChannelEvent event) { if (event.isCancelled()) return; if (!myChannelIds.contains(event.getChannel().getId())) return; Player me = event.getMe(); FPlayer fme = FPlayers.i.get(me); Faction myFaction = fme.getFaction(); if (event.getChannel().getId().equals("faction") && myFaction.isNormal()) { event.getThem().addAll(myFaction.getOnlinePlayers()); } else if (event.getChannel().getId().equals("allies")) { for (Player somePlayer : Bukkit.getServer().getOnlinePlayers()) { FPlayer someFPlayer = FPlayers.i.get(somePlayer); if (someFPlayer.getRelationTo(fme).isAtLeast(Rel.ALLY)) { event.getThem().add(somePlayer); } } } }
@Override public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); FPlayer me = FPlayer.get(player); // Did we change coord? FLocation from = me.getLastStoodAt(); FLocation to = new FLocation(player.getLocation()); if (from.equals(to)) { return; } // Yes we did change coord (: me.setLastStoodAt(to); if (me.isMapAutoUpdating()) { me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw())); } else { // Did we change "host"(faction)? Faction factionFrom = Board.getFactionAt(from); Faction factionTo = Board.getFactionAt(to); Faction myFaction = me.getFaction(); String ownersTo = myFaction.getOwnerListString(to); if (factionFrom != factionTo) { me.sendFactionHereMessage(); if (Conf.ownedAreasEnabled && Conf.ownedMessageOnBorder && myFaction == factionTo && !ownersTo.isEmpty()) { me.sendMessage(Conf.ownedLandMessage + ownersTo); } } else if (Conf.ownedAreasEnabled && Conf.ownedMessageInsideTerritory && factionFrom == factionTo && myFaction == factionTo) { String ownersFrom = myFaction.getOwnerListString(from); if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) { if (!ownersTo.isEmpty()) { me.sendMessage(Conf.ownedLandMessage + ownersTo); } else if (!Conf.publicLandMessage.isEmpty()) { me.sendMessage(Conf.publicLandMessage); } } } } if (me.autoClaimEnabled()) { Faction myFaction = me.getFaction(); Faction otherFaction = Board.getFactionAt(to); double cost = Econ.calculateClaimCost(myFaction.getLandRounded(), otherFaction.isNormal()); if (me.getRole().value < Role.MODERATOR.value) { me.sendMessage("You must be " + Role.MODERATOR + " to claim land."); me.enableAutoClaim(false); } else if (Conf.worldsNoClaiming.contains(to.getWorldName())) { me.sendMessage("Sorry, this world has land claiming disabled."); me.enableAutoClaim(false); } else if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { me.sendMessage("You can't claim more land! You need more power!"); me.enableAutoClaim(false); } else if (!Econ.canAfford(player.getName(), cost)) { String costString = Econ.moneyString(cost); me.sendMessage( "Claiming this land will cost " + costString + ", which you can't currently afford."); me.enableAutoClaim(false); } else me.attemptClaim(false); } else if (me.autoSafeZoneEnabled()) { if (!Factions.hasPermManageSafeZone((CommandSender) player)) { me.enableAutoSafeZone(false); } else { FLocation playerFlocation = new FLocation(me); if (!Board.getFactionAt(playerFlocation).isSafeZone()) { Board.setFactionAt(Faction.getSafeZone(), playerFlocation); me.sendMessage("This land is now a safe zone."); } } } else if (me.autoWarZoneEnabled()) { if (!Factions.hasPermManageWarZone((CommandSender) player)) { me.enableAutoWarZone(false); } else { FLocation playerFlocation = new FLocation(me); if (!Board.getFactionAt(playerFlocation).isWarZone()) { Board.setFactionAt(Faction.getWarZone(), playerFlocation); me.sendMessage("This land is now a war zone."); } } } }