From 26c708b65eac4aeb8715f114140a60450d56b532 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 6 Apr 2011 05:04:57 -0500 Subject: [PATCH] changes AdminBypass permission to enable new "bypass" command which toggles admin bypass mode on or off, defaults to off added tracking for the SaveTask() and shutdown of it when the plugin is disabled --- src/com/bukkit/mcteam/factions/Conf.java | 4 +++ src/com/bukkit/mcteam/factions/Factions.java | 10 +++++- .../factions/commands/FCommandBypass.java | 33 +++++++++++++++++++ .../factions/commands/FCommandHelp.java | 1 + .../listeners/FactionsBlockListener.java | 2 +- .../listeners/FactionsPlayerListener.java | 4 +-- 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandBypass.java diff --git a/src/com/bukkit/mcteam/factions/Conf.java b/src/com/bukkit/mcteam/factions/Conf.java index 30fc0c05..3ad11b61 100644 --- a/src/com/bukkit/mcteam/factions/Conf.java +++ b/src/com/bukkit/mcteam/factions/Conf.java @@ -87,6 +87,10 @@ public class Conf { safeZoneNerfedCreatureTypes.add(CreatureType.SLIME); safeZoneNerfedCreatureTypes.add(CreatureType.ZOMBIE); } + + // track players with admin access who have enabled "admin bypass" mode, and should therefore be able to build anywhere + // not worth saving between server restarts, I think + public static transient Set adminBypassPlayers = Collections.synchronizedSet(new HashSet()); // -------------------------------------------- // // Persistance diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 4300398e..e5de2221 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -21,6 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin; import com.bukkit.mcteam.factions.commands.FBaseCommand; import com.bukkit.mcteam.factions.commands.FCommandAdmin; +import com.bukkit.mcteam.factions.commands.FCommandBypass; import com.bukkit.mcteam.factions.commands.FCommandChat; import com.bukkit.mcteam.factions.commands.FCommandClaim; import com.bukkit.mcteam.factions.commands.FCommandCreate; @@ -65,6 +66,7 @@ public class Factions extends JavaPlugin { // Fields // -------------------------------------------- // public static Factions instance; + private Integer saveTask = null; public final static Gson gson = new GsonBuilder() .setPrettyPrinting() @@ -97,6 +99,7 @@ public class Factions extends JavaPlugin { // Add the commands commands.add(new FCommandHelp()); commands.add(new FCommandAdmin()); + commands.add(new FCommandBypass()); commands.add(new FCommandChat()); commands.add(new FCommandClaim()); commands.add(new FCommandCreate()); @@ -153,13 +156,18 @@ public class Factions extends JavaPlugin { // Register recurring tasks long saveTicks = 20 * 60 * 30; // Approximately every 30 min - this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(), saveTicks, saveTicks); + if (saveTask == null) + saveTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(), saveTicks, saveTicks); log("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ==="); } @Override public void onDisable() { + if (saveTask != null) { + this.getServer().getScheduler().cancelTask(saveTask); + saveTask = null; + } saveAll(); log("Disabled"); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandBypass.java b/src/com/bukkit/mcteam/factions/commands/FCommandBypass.java new file mode 100644 index 00000000..39a445c7 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandBypass.java @@ -0,0 +1,33 @@ +package com.bukkit.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.Factions; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandBypass extends FBaseCommand { + + public FCommandBypass() { + aliases.add("bypass"); + + helpDescription = "Enable admin bypass mode; build/destroy anywhere"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermAdminBypass(sender); + } + + @Override + public void perform() { + if ( ! Conf.adminBypassPlayers.contains(player.getName())) { + Conf.adminBypassPlayers.add(player.getName()); + me.sendMessage("You have enabled admin bypass mode. You will be able to build or destroy anywhere."); + } else { + Conf.adminBypassPlayers.remove(player.getName()); + me.sendMessage("You have disabled admin bypass mode."); + } + } +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java index d325e85c..f957dc92 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java @@ -127,6 +127,7 @@ public class FCommandHelp extends FBaseCommand { pageLines.add("Finally some commands for the server admins:"); pageLines.add( new FCommandVersion().getUseageTemplate(true, true) ); pageLines.add( new FCommandSafeclaim().getUseageTemplate(true, true) ); + pageLines.add( new FCommandBypass().getUseageTemplate(true, true) ); helpPages.add(pageLines); } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java index bae95f36..fe76e765 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java @@ -54,7 +54,7 @@ public class FactionsBlockListener extends BlockListener { public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) { - if (Factions.hasPermAdminBypass(player)) { + if (Conf.adminBypassPlayers.contains(player.getName())) { return true; } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index bba6c352..32d72cf9 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -165,7 +165,7 @@ public class FactionsPlayerListener extends PlayerListener{ public boolean playerCanUseItemHere(Player player, Block block, Material material) { - if (Factions.hasPermAdminBypass(player)) { + if (Conf.adminBypassPlayers.contains(player.getName())) { return true; } @@ -202,7 +202,7 @@ public class FactionsPlayerListener extends PlayerListener{ public boolean canPlayerUseBlock(Player player, Block block) { - if (Factions.hasPermAdminBypass(player)) { + if (Conf.adminBypassPlayers.contains(player.getName())) { return true; }