From b490c5f196984ad21ecfa26238e952936b555034 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 29 May 2011 16:28:29 -0500 Subject: [PATCH] Laundry list of changes for 1.2.0 release: /f map now has a nifty faction name key (LexManos) There are now War Zones; these work similar to Safe Zones, except PvP is enabled and monsters are not blocked (Brettflan) Players now only regenerate power while actually online (Brettflan) New command available to prevent power loss in specific worlds (Brettflan) New command available to prevent faction land claims in specific worlds (doesn't affect safezone and warzone claims) (Brettflan) New command to unclaim all safezone areas (Brettflan) Players are now prevented from using /f home if an enemy is nearby, and the players isn't in a safezone or their own faction territory (Brettflan) New option to make membership default to closed for newly created factions (Brettflan) When an admin has bypass mode enabled (/f bypass), they can now unclaim any faction land they're standing on (Brettflan) --- plugin.yml | 2 +- src/org/mcteam/factions/Board.java | 23 +++++++- src/org/mcteam/factions/Conf.java | 16 ++++++ src/org/mcteam/factions/FPlayer.java | 4 ++ src/org/mcteam/factions/Faction.java | 21 +++++++- src/org/mcteam/factions/Factions.java | 50 ++++++----------- .../factions/commands/FCommandClaim.java | 19 +++++-- .../factions/commands/FCommandHelp.java | 12 +++++ .../factions/commands/FCommandHome.java | 39 ++++++++++++++ .../factions/commands/FCommandList.java | 1 + .../commands/FCommandSafeunclaimall.java | 34 ++++++++++++ .../factions/commands/FCommandUnclaim.java | 17 ++++++ .../factions/commands/FCommandWarclaim.java | 54 +++++++++++++++++++ .../commands/FCommandWarunclaimall.java | 34 ++++++++++++ .../commands/FCommandWorldNoClaim.java | 39 ++++++++++++++ .../commands/FCommandWorldNoPowerLoss.java | 39 ++++++++++++++ .../listeners/FactionsBlockListener.java | 7 +++ .../listeners/FactionsEntityListener.java | 48 ++++++++++++++--- .../listeners/FactionsPlayerListener.java | 15 ++++++ 19 files changed, 423 insertions(+), 51 deletions(-) create mode 100644 src/org/mcteam/factions/commands/FCommandSafeunclaimall.java create mode 100644 src/org/mcteam/factions/commands/FCommandWarclaim.java create mode 100644 src/org/mcteam/factions/commands/FCommandWarunclaimall.java create mode 100644 src/org/mcteam/factions/commands/FCommandWorldNoClaim.java create mode 100644 src/org/mcteam/factions/commands/FCommandWorldNoPowerLoss.java diff --git a/plugin.yml b/plugin.yml index 1bd4019f..4b56a209 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: Factions -version: 1.1.8 +version: 1.2.0 main: org.mcteam.factions.Factions commands: f: diff --git a/src/org/mcteam/factions/Board.java b/src/org/mcteam/factions/Board.java index 9fbf044d..ae195e09 100644 --- a/src/org/mcteam/factions/Board.java +++ b/src/org/mcteam/factions/Board.java @@ -130,6 +130,13 @@ public class Board { int width = halfWidth * 2 + 1; int height = halfHeight * 2 + 1; + if (Conf.showMapFactionKey) { + height--; + } + + Map fList = new HashMap(); + int chrIdx = 0; + // For each row for (int dx = 0; dx < height; dx++) { // Draw and add that row @@ -144,8 +151,13 @@ public class Board { row += ChatColor.GRAY+"-"; } else if (factionHere.isSafeZone()) { row += ChatColor.GOLD+"+"; + } else if (factionHere.isWarZone()) { + row += ChatColor.DARK_RED+"+"; } else { - row += factionHere.getRelation(faction).getColor()+"+"; + if (!fList.containsKey(factionHere.getTag())) + fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]); + char tag = fList.get(factionHere.getTag()); + row += factionHere.getRelation(faction).getColor() + "" + tag; } } } @@ -160,6 +172,15 @@ public class Board { ret.set(2, asciiCompass.get(1)+ret.get(2).substring(3*3)); ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3)); + // Add the faction key + if (Conf.showMapFactionKey) { + String fRow = ""; + for(String key : fList.keySet()) { + fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key); + } + ret.add(fRow); + } + return ret; } diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index ec5ee21a..c148cc47 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -34,6 +34,10 @@ public class Conf { public static int factionTagLengthMax = 10; public static boolean factionTagForceUpperCase = false; + public static boolean newFactionsDefaultOpen = true; + + public static boolean showMapFactionKey = true; + // Configuration on the Faction tag in chat messages. public static boolean chatTagEnabled = true; @@ -48,6 +52,7 @@ public class Conf { public static boolean homesEnabled = true; public static boolean homesTeleportToOnDeath = true; + public static double homesTeleportAllowedEnemyDistance = 32; public static double territoryShieldFactor = 0.5; public static boolean territoryBlockCreepers = false; @@ -58,13 +63,24 @@ public class Conf { public static boolean safeZoneDenyUseage = true; public static boolean safeZoneBlockTNT = true; + public static boolean warZoneBlockCreepers = false; + public static boolean warZoneBlockFireballs = false; + public static boolean warZoneBlockTNT = true; + public static boolean warZoneDenyBuild = true; + public static boolean warZoneDenyUseage = true; + public static boolean warZonePowerLoss = true; + public static Set territoryProtectedMaterials = new HashSet(); public static Set territoryDenyUseageMaterials = new HashSet(); public static transient Set safeZoneNerfedCreatureTypes = new HashSet(); + public static Set worldsNoClaiming = new HashSet(); + public static Set worldsNoPowerLoss = new HashSet(); + public static transient int mapHeight = 8; public static transient int mapWidth = 39; + public static transient char[] mapKeyChrs = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray(); static { territoryProtectedMaterials.add(Material.WOODEN_DOOR); diff --git a/src/org/mcteam/factions/FPlayer.java b/src/org/mcteam/factions/FPlayer.java index 1f3598a1..4bf8e552 100644 --- a/src/org/mcteam/factions/FPlayer.java +++ b/src/org/mcteam/factions/FPlayer.java @@ -131,6 +131,7 @@ public class FPlayer { public void setLastLoginTime(long lastLoginTime) { this.lastLoginTime = lastLoginTime; + this.lastPowerUpdateTime = lastLoginTime; } public boolean isMapAutoUpdating() { @@ -325,6 +326,9 @@ public class FPlayer { } protected void updatePower() { + if (this.isOffline()) { + return; + } long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime; this.lastPowerUpdateTime = now; diff --git a/src/org/mcteam/factions/Faction.java b/src/org/mcteam/factions/Faction.java index 95210e36..03d6a7b1 100644 --- a/src/org/mcteam/factions/Faction.java +++ b/src/org/mcteam/factions/Faction.java @@ -40,7 +40,7 @@ public class Faction { public Faction() { this.relationWish = new HashMap(); this.invites = new HashSet(); - this.open = true; + this.open = Conf.newFactionsDefaultOpen; this.tag = "???"; this.description = "Default faction description :("; } @@ -116,6 +116,10 @@ public class Faction { return this.getId() == -1; } + public boolean isWarZone() { + return this.getId() == -2; + } + // ------------------------------- // Invites - uses lowercase name // ------------------------------- @@ -374,7 +378,7 @@ public class Faction { instances.put(faction.id, faction); } - // Make sure the safe zone faciton exists + // Make sure the safe zone faction exists if ( ! instances.containsKey(-1)) { Faction faction = new Faction(); faction.tag = ChatColor.GOLD+"Safe Zone"; @@ -383,6 +387,15 @@ public class Faction { instances.put(faction.id, faction); } + // Make sure the war zone faction exists + if ( ! instances.containsKey(-2)) { + Faction faction = new Faction(); + faction.tag = ChatColor.DARK_RED+"War Zone"; + faction.description = "Not the safest place to be"; + faction.id = -2; + instances.put(faction.id, faction); + } + return true; } @@ -414,6 +427,10 @@ public class Faction { return instances.get(-1); } + public static Faction getWarZone() { + return instances.get(-2); + } + public static boolean exists(Integer factionId) { return instances.containsKey(factionId); } diff --git a/src/org/mcteam/factions/Factions.java b/src/org/mcteam/factions/Factions.java index e59c76f6..57de5e2f 100644 --- a/src/org/mcteam/factions/Factions.java +++ b/src/org/mcteam/factions/Factions.java @@ -18,39 +18,7 @@ import org.bukkit.event.Event; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.mcteam.factions.commands.FBaseCommand; -import org.mcteam.factions.commands.FCommandAdmin; -import org.mcteam.factions.commands.FCommandBypass; -import org.mcteam.factions.commands.FCommandChat; -import org.mcteam.factions.commands.FCommandClaim; -import org.mcteam.factions.commands.FCommandCreate; -import org.mcteam.factions.commands.FCommandDeinvite; -import org.mcteam.factions.commands.FCommandDescription; -import org.mcteam.factions.commands.FCommandDisband; -import org.mcteam.factions.commands.FCommandHelp; -import org.mcteam.factions.commands.FCommandHome; -import org.mcteam.factions.commands.FCommandInvite; -import org.mcteam.factions.commands.FCommandJoin; -import org.mcteam.factions.commands.FCommandKick; -import org.mcteam.factions.commands.FCommandLeave; -import org.mcteam.factions.commands.FCommandList; -import org.mcteam.factions.commands.FCommandLock; -import org.mcteam.factions.commands.FCommandMap; -import org.mcteam.factions.commands.FCommandMod; -import org.mcteam.factions.commands.FCommandOpen; -import org.mcteam.factions.commands.FCommandRelationAlly; -import org.mcteam.factions.commands.FCommandRelationEnemy; -import org.mcteam.factions.commands.FCommandRelationNeutral; -import org.mcteam.factions.commands.FCommandReload; -import org.mcteam.factions.commands.FCommandSafeclaim; -import org.mcteam.factions.commands.FCommandSaveAll; -import org.mcteam.factions.commands.FCommandSethome; -import org.mcteam.factions.commands.FCommandShow; -import org.mcteam.factions.commands.FCommandTag; -import org.mcteam.factions.commands.FCommandTitle; -import org.mcteam.factions.commands.FCommandUnclaim; -import org.mcteam.factions.commands.FCommandUnclaimall; -import org.mcteam.factions.commands.FCommandVersion; +import org.mcteam.factions.commands.*; import org.mcteam.factions.gson.Gson; import org.mcteam.factions.gson.GsonBuilder; import org.mcteam.factions.listeners.FactionsBlockListener; @@ -125,8 +93,9 @@ public class Factions extends JavaPlugin { commands.add(new FCommandRelationEnemy()); commands.add(new FCommandRelationNeutral()); commands.add(new FCommandReload()); - commands.add(new FCommandSaveAll()); commands.add(new FCommandSafeclaim()); + commands.add(new FCommandSafeunclaimall()); + commands.add(new FCommandSaveAll()); commands.add(new FCommandSethome()); commands.add(new FCommandShow()); commands.add(new FCommandTag()); @@ -134,6 +103,10 @@ public class Factions extends JavaPlugin { commands.add(new FCommandUnclaim()); commands.add(new FCommandUnclaimall()); commands.add(new FCommandVersion()); + commands.add(new FCommandWarclaim()); + commands.add(new FCommandWarunclaimall()); + commands.add(new FCommandWorldNoClaim()); + commands.add(new FCommandWorldNoPowerLoss()); // Ensure base folder exists! this.getDataFolder().mkdirs(); @@ -151,6 +124,7 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this); pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal, this); @@ -217,6 +191,10 @@ public class Factions extends JavaPlugin { public static boolean hasPermManageSafeZone(CommandSender sender) { return hasPerm(sender, "factions.manageSafeZone", true); } + + public static boolean hasPermManageWarZone(CommandSender sender) { + return hasPerm(sender, "factions.manageWarZone", true); + } public static boolean hasPermAdminBypass(CommandSender sender) { return hasPerm(sender, "factions.adminBypass", true); @@ -238,6 +216,10 @@ public class Factions extends JavaPlugin { return hasPerm(sender, "factions.disband", true); } + public static boolean hasPermWorlds(CommandSender sender) { + return hasPerm(sender, "factions.worldOptions", true); + } + private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) { if (Factions.Permissions == null || ! (sender instanceof Player)) { return fallbackOnlyOp == false || sender.isOp(); diff --git a/src/org/mcteam/factions/commands/FCommandClaim.java b/src/org/mcteam/factions/commands/FCommandClaim.java index 1c92edf9..663feaf2 100644 --- a/src/org/mcteam/factions/commands/FCommandClaim.java +++ b/src/org/mcteam/factions/commands/FCommandClaim.java @@ -39,6 +39,20 @@ public class FCommandClaim extends FBaseCommand { } + if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { + sendMessage("Sorry, this world has land claiming disabled."); + return; + } + + if (otherFaction.isSafeZone()) { + sendMessage("You can not claim a Safe Zone."); + return; + } + else if (otherFaction.isWarZone()) { + sendMessage("You can not claim a War Zone."); + return; + } + if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { sendMessage("You can't claim more land! You need more power!"); return; @@ -49,11 +63,6 @@ public class FCommandClaim extends FBaseCommand { return; } - if (otherFaction.isSafeZone()) { - sendMessage("You can not claim a SafeZone."); - return; - } - if (otherFaction.isNone()) { myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); } else { //if (otherFaction.isNormal()) { diff --git a/src/org/mcteam/factions/commands/FCommandHelp.java b/src/org/mcteam/factions/commands/FCommandHelp.java index 45370229..aaa6b2e5 100644 --- a/src/org/mcteam/factions/commands/FCommandHelp.java +++ b/src/org/mcteam/factions/commands/FCommandHelp.java @@ -127,8 +127,20 @@ public class FCommandHelp extends FBaseCommand { pageLines.add("Finally some commands for the server admins:"); pageLines.add( new FCommandVersion().getUseageTemplate() ); pageLines.add( new FCommandSafeclaim().getUseageTemplate() ); + pageLines.add( new FCommandSafeunclaimall().getUseageTemplate() ); + pageLines.add( new FCommandWarclaim().getUseageTemplate() ); + pageLines.add( new FCommandWarunclaimall().getUseageTemplate() ); + pageLines.add( new FCommandWorldNoClaim().getUseageTemplate() ); + pageLines.add( new FCommandWorldNoPowerLoss().getUseageTemplate() ); pageLines.add( new FCommandBypass().getUseageTemplate() ); helpPages.add(pageLines); + + pageLines = new ArrayList(); + pageLines.add("More commands for server admins:"); + pageLines.add( new FCommandLock().getUseageTemplate() ); + pageLines.add( new FCommandReload().getUseageTemplate() ); + pageLines.add( new FCommandSaveAll().getUseageTemplate() ); + helpPages.add(pageLines); } } diff --git a/src/org/mcteam/factions/commands/FCommandHome.java b/src/org/mcteam/factions/commands/FCommandHome.java index f15fc8c7..62a3b95d 100644 --- a/src/org/mcteam/factions/commands/FCommandHome.java +++ b/src/org/mcteam/factions/commands/FCommandHome.java @@ -1,7 +1,14 @@ package org.mcteam.factions.commands; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.mcteam.factions.Board; import org.mcteam.factions.Conf; import org.mcteam.factions.Faction; +import org.mcteam.factions.FLocation; +import org.mcteam.factions.FPlayer; +import org.mcteam.factions.struct.Relation; import org.mcteam.factions.struct.Role; public class FCommandHome extends FBaseCommand { @@ -30,6 +37,38 @@ public class FCommandHome extends FBaseCommand { return; } + Faction faction = Board.getFactionAt(new FLocation(player.getLocation())); + + // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby + if (Conf.homesTeleportAllowedEnemyDistance > 0 && ! faction.isSafeZone() && ! me.isInOwnTerritory()) { + Location loc = player.getLocation(); + World w = loc.getWorld(); + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + for (Player p : player.getServer().getOnlinePlayers()) + { + if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w) + continue; + + FPlayer fp = FPlayer.get(p); + if (me.getRelation(fp) != Relation.ENEMY) + continue; + + Location l = p.getLocation(); + int dx = Math.abs(x - l.getBlockX()); + int dy = Math.abs(y - l.getBlockY()); + int dz = Math.abs(z - l.getBlockZ()); + int delta = dx + dy + dz; + if (delta > Conf.homesTeleportAllowedEnemyDistance) + continue; + + me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you."); + return; + } + } + player.teleport(myFaction.getHome()); } diff --git a/src/org/mcteam/factions/commands/FCommandList.java b/src/org/mcteam/factions/commands/FCommandList.java index 96ec0198..f4eff044 100644 --- a/src/org/mcteam/factions/commands/FCommandList.java +++ b/src/org/mcteam/factions/commands/FCommandList.java @@ -30,6 +30,7 @@ public class FCommandList extends FBaseCommand { ArrayList FactionList = new ArrayList(Faction.getAll()); FactionList.remove(Faction.getNone()); FactionList.remove(Faction.getSafeZone()); + FactionList.remove(Faction.getWarZone()); int page = 1; if (parameters.size() > 0) { diff --git a/src/org/mcteam/factions/commands/FCommandSafeunclaimall.java b/src/org/mcteam/factions/commands/FCommandSafeunclaimall.java new file mode 100644 index 00000000..960b2de9 --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandSafeunclaimall.java @@ -0,0 +1,34 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Board; +import org.mcteam.factions.Faction; +import org.mcteam.factions.Factions; + +public class FCommandSafeunclaimall extends FBaseCommand { + + public FCommandSafeunclaimall() { + aliases.add("safeunclaimall"); + aliases.add("safedeclaimall"); + + helpDescription = "Unclaim all safezone land"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermManageSafeZone(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + Board.unclaimAll(Faction.getSafeZone().getId()); + sendMessage("You unclaimed ALL safe zone land."); + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandUnclaim.java b/src/org/mcteam/factions/commands/FCommandUnclaim.java index cb67c5d5..183b6eff 100644 --- a/src/org/mcteam/factions/commands/FCommandUnclaim.java +++ b/src/org/mcteam/factions/commands/FCommandUnclaim.java @@ -35,6 +35,23 @@ public class FCommandUnclaim extends FBaseCommand { } return; } + else if (otherFaction.isWarZone()) { + if (Factions.hasPermManageWarZone(sender)) { + Board.removeAt(flocation); + sendMessage("War zone was unclaimed."); + } else { + sendMessage("This is a war zone. You lack permissions to unclaim."); + } + return; + } + + if (Conf.adminBypassPlayers.contains(player.getName())) { + Board.removeAt(flocation); + + otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" unclaimed some of your land."); + sendMessage("You unclaimed this land."); + return; + } if ( ! assertHasFaction()) { return; diff --git a/src/org/mcteam/factions/commands/FCommandWarclaim.java b/src/org/mcteam/factions/commands/FCommandWarclaim.java new file mode 100644 index 00000000..4e2b6133 --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandWarclaim.java @@ -0,0 +1,54 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Board; +import org.mcteam.factions.FLocation; +import org.mcteam.factions.Faction; +import org.mcteam.factions.Factions; + +public class FCommandWarclaim extends FBaseCommand { + + public FCommandWarclaim() { + aliases.add("warclaim"); + aliases.add("war"); + + optionalParameters.add("radius"); + + helpDescription = "Claim land for the warzone"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermManageWarZone(sender); + } + + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + // The current location of the player + FLocation playerFlocation = new FLocation(me); + + // Was a radius set? + if (parameters.size() > 0) { + int radius = Integer.parseInt(parameters.get(0)); + + FLocation from = playerFlocation.getRelative(radius, radius); + FLocation to = playerFlocation.getRelative(-radius, -radius); + + for (FLocation locToClaim : FLocation.getArea(from, to)) { + Board.setFactionAt(Faction.getWarZone(), locToClaim); + } + + sendMessage("You claimed "+(1+radius*2)*(1+radius*2)+" chunks for the war zone."); + + } else { + Board.setFactionAt(Faction.getWarZone(), playerFlocation); + sendMessage("This land is now a war zone"); + } + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandWarunclaimall.java b/src/org/mcteam/factions/commands/FCommandWarunclaimall.java new file mode 100644 index 00000000..152e4038 --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandWarunclaimall.java @@ -0,0 +1,34 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Board; +import org.mcteam.factions.Faction; +import org.mcteam.factions.Factions; + +public class FCommandWarunclaimall extends FBaseCommand { + + public FCommandWarunclaimall() { + aliases.add("warunclaimall"); + aliases.add("wardeclaimall"); + + helpDescription = "Unclaim all warzone land"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermManageWarZone(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + Board.unclaimAll(Faction.getWarZone().getId()); + sendMessage("You unclaimed ALL war zone land."); + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandWorldNoClaim.java b/src/org/mcteam/factions/commands/FCommandWorldNoClaim.java new file mode 100644 index 00000000..4fba3e5d --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandWorldNoClaim.java @@ -0,0 +1,39 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Conf; +import org.mcteam.factions.Factions; + +public class FCommandWorldNoClaim extends FBaseCommand { + + public FCommandWorldNoClaim() { + aliases.add("worldnoclaim"); + + helpDescription = "Disable claims in this world"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermWorlds(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + String worldName = me.getPlayer().getWorld().getName(); + + if ( ! Conf.worldsNoClaiming.contains(worldName)) { + Conf.worldsNoClaiming.add(worldName); + me.sendMessage("Faction land claiming is now DISALLOWED in this world (\"" + worldName + "\")."); + } else { + Conf.worldsNoClaiming.remove(worldName); + me.sendMessage("Faction land claiming is now ALLOWED in this world (\"" + worldName + "\")."); + } + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandWorldNoPowerLoss.java b/src/org/mcteam/factions/commands/FCommandWorldNoPowerLoss.java new file mode 100644 index 00000000..53a46d2c --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandWorldNoPowerLoss.java @@ -0,0 +1,39 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Conf; +import org.mcteam.factions.Factions; + +public class FCommandWorldNoPowerLoss extends FBaseCommand { + + public FCommandWorldNoPowerLoss() { + aliases.add("worldnopowerloss"); + + helpDescription = "Disable power loss in this world"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermWorlds(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + String worldName = me.getPlayer().getWorld().getName(); + + if ( ! Conf.worldsNoPowerLoss.contains(worldName)) { + Conf.worldsNoPowerLoss.add(worldName); + me.sendMessage("Power loss from death is now DISABLED in this world (\"" + worldName + "\")."); + } else { + Conf.worldsNoPowerLoss.remove(worldName); + me.sendMessage("Power loss from death is now ENABLED in this world (\"" + worldName + "\")."); + } + } + +} diff --git a/src/org/mcteam/factions/listeners/FactionsBlockListener.java b/src/org/mcteam/factions/listeners/FactionsBlockListener.java index fc1c85fb..52714664 100644 --- a/src/org/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/org/mcteam/factions/listeners/FactionsBlockListener.java @@ -73,6 +73,13 @@ public class FactionsBlockListener extends BlockListener { me.sendMessage("You can't "+action+" in a safe zone."); return false; } + else if (otherFaction.isWarZone()) { + if (Factions.hasPermManageWarZone(player) || !Conf.warZoneDenyBuild) { + return true; + } + me.sendMessage("You can't "+action+" in a war zone."); + return false; + } Faction myFaction = me.getFaction(); diff --git a/src/org/mcteam/factions/listeners/FactionsEntityListener.java b/src/org/mcteam/factions/listeners/FactionsEntityListener.java index be48c996..33f62a6d 100644 --- a/src/org/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/org/mcteam/factions/listeners/FactionsEntityListener.java @@ -36,9 +36,22 @@ public class FactionsEntityListener extends EntityListener { if ( ! (entity instanceof Player)) { return; } - + Player player = (Player) entity; FPlayer fplayer = FPlayer.get(player); + Faction faction = Board.getFactionAt(new FLocation(player.getLocation())); + if (faction.isWarZone()) { // war zones always override worldsNoPowerLoss either way, thus this layout + if (! Conf.warZonePowerLoss) { + fplayer.sendMessage("You didn't lose any power since you were in a war zone."); + return; + } + if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { + fplayer.sendMessage("The world you are in has power loss normally disabled, but you still lost power since you were in a war zone."); + } + } else if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { + fplayer.sendMessage("You didn't lose any power due to the world you died in."); + return; + } fplayer.onDeath(); fplayer.sendMessage("Your power is now "+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded()); } @@ -83,18 +96,30 @@ public class FactionsEntityListener extends EntityListener { return; } - if ((Conf.territoryBlockCreepers || faction.isSafeZone()) && event.getEntity() instanceof Creeper) { - // creeper which might need prevention, if inside faction territory + if (event.getEntity() instanceof Creeper && ( + (faction.isNormal() && Conf.territoryBlockCreepers) || + (faction.isWarZone() && Conf.warZoneBlockCreepers) || + faction.isSafeZone() + )) { + // creeper which needs prevention event.setCancelled(true); - } else if ((Conf.territoryBlockFireballs || faction.isSafeZone()) && event.getEntity() instanceof Fireball) { - // ghast fireball which might need prevention, if inside faction territory + } else if (event.getEntity() instanceof Fireball && ( + (faction.isNormal() && Conf.territoryBlockFireballs) || + (faction.isWarZone() && Conf.warZoneBlockFireballs) || + faction.isSafeZone() + )) { + // ghast fireball which needs prevention event.setCancelled(true); - } else if (Conf.territoryBlockTNT || (faction.isSafeZone() && Conf.safeZoneBlockTNT)) { - // we'll assume it's TNT, which might need prevention, if inside faction territory or safe zone + } else if ( + (faction.isNormal() && Conf.territoryBlockTNT) || + (faction.isWarZone() && Conf.warZoneBlockTNT) || + (faction.isSafeZone() && Conf.safeZoneBlockTNT) + ) { + // we'll assume it's TNT, which needs prevention event.setCancelled(true); } } - + public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub) { Entity damager = sub.getDamager(); Entity damagee = sub.getEntity(); @@ -251,6 +276,13 @@ public class FactionsEntityListener extends EntityListener { me.sendMessage("You can't "+action+" paintings in a safe zone."); return false; } + else if (otherFaction.isWarZone()) { + if (Factions.hasPermManageWarZone(player) || !Conf.warZoneDenyBuild) { + return true; + } + me.sendMessage("You can't "+action+" paintings in a war zone."); + return false; + } Faction myFaction = me.getFaction(); diff --git a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java index 50392263..a04c0679 100644 --- a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java @@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.mcteam.factions.Board; import org.mcteam.factions.Conf; @@ -109,6 +110,13 @@ public class FactionsPlayerListener extends PlayerListener{ FPlayer.autoLeaveOnInactivityRoutine(); } + @Override + public void onPlayerQuit(PlayerQuitEvent event) { + // Make sure player's power is up to date when they log off. + FPlayer me = FPlayer.get(event.getPlayer()); + me.getPower(); + } + @Override public void onPlayerMove(PlayerMoveEvent event) { FPlayer me = FPlayer.get(event.getPlayer()); @@ -192,6 +200,13 @@ public class FactionsPlayerListener extends PlayerListener{ me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a safe zone."); return false; } + else if (otherFaction.isWarZone() && Conf.warZoneDenyUseage) { + if (Factions.hasPermManageWarZone(player)) { + return true; + } + me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a war zone."); + return false; + } Faction myFaction = me.getFaction();