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
This commit is contained in:
Brettflan 2011-04-06 05:04:57 -05:00
parent 542ad4a6a0
commit 26c708b65e
6 changed files with 50 additions and 4 deletions

View File

@ -87,6 +87,10 @@ public class Conf {
safeZoneNerfedCreatureTypes.add(CreatureType.SLIME); safeZoneNerfedCreatureTypes.add(CreatureType.SLIME);
safeZoneNerfedCreatureTypes.add(CreatureType.ZOMBIE); 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<String> adminBypassPlayers = Collections.synchronizedSet(new HashSet<String>());
// -------------------------------------------- // // -------------------------------------------- //
// Persistance // Persistance

View File

@ -21,6 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.bukkit.mcteam.factions.commands.FBaseCommand; import com.bukkit.mcteam.factions.commands.FBaseCommand;
import com.bukkit.mcteam.factions.commands.FCommandAdmin; 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.FCommandChat;
import com.bukkit.mcteam.factions.commands.FCommandClaim; import com.bukkit.mcteam.factions.commands.FCommandClaim;
import com.bukkit.mcteam.factions.commands.FCommandCreate; import com.bukkit.mcteam.factions.commands.FCommandCreate;
@ -65,6 +66,7 @@ public class Factions extends JavaPlugin {
// Fields // Fields
// -------------------------------------------- // // -------------------------------------------- //
public static Factions instance; public static Factions instance;
private Integer saveTask = null;
public final static Gson gson = new GsonBuilder() public final static Gson gson = new GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
@ -97,6 +99,7 @@ public class Factions extends JavaPlugin {
// Add the commands // Add the commands
commands.add(new FCommandHelp()); commands.add(new FCommandHelp());
commands.add(new FCommandAdmin()); commands.add(new FCommandAdmin());
commands.add(new FCommandBypass());
commands.add(new FCommandChat()); commands.add(new FCommandChat());
commands.add(new FCommandClaim()); commands.add(new FCommandClaim());
commands.add(new FCommandCreate()); commands.add(new FCommandCreate());
@ -153,13 +156,18 @@ public class Factions extends JavaPlugin {
// Register recurring tasks // Register recurring tasks
long saveTicks = 20 * 60 * 30; // Approximately every 30 min 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) ==="); log("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
} }
@Override @Override
public void onDisable() { public void onDisable() {
if (saveTask != null) {
this.getServer().getScheduler().cancelTask(saveTask);
saveTask = null;
}
saveAll(); saveAll();
log("Disabled"); log("Disabled");
} }

View File

@ -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.");
}
}
}

View File

@ -127,6 +127,7 @@ public class FCommandHelp extends FBaseCommand {
pageLines.add("Finally some commands for the server admins:"); pageLines.add("Finally some commands for the server admins:");
pageLines.add( new FCommandVersion().getUseageTemplate(true, true) ); pageLines.add( new FCommandVersion().getUseageTemplate(true, true) );
pageLines.add( new FCommandSafeclaim().getUseageTemplate(true, true) ); pageLines.add( new FCommandSafeclaim().getUseageTemplate(true, true) );
pageLines.add( new FCommandBypass().getUseageTemplate(true, true) );
helpPages.add(pageLines); helpPages.add(pageLines);
} }

View File

@ -54,7 +54,7 @@ public class FactionsBlockListener extends BlockListener {
public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) { public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
if (Factions.hasPermAdminBypass(player)) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
} }

View File

@ -165,7 +165,7 @@ public class FactionsPlayerListener extends PlayerListener{
public boolean playerCanUseItemHere(Player player, Block block, Material material) { public boolean playerCanUseItemHere(Player player, Block block, Material material) {
if (Factions.hasPermAdminBypass(player)) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
} }
@ -202,7 +202,7 @@ public class FactionsPlayerListener extends PlayerListener{
public boolean canPlayerUseBlock(Player player, Block block) { public boolean canPlayerUseBlock(Player player, Block block) {
if (Factions.hasPermAdminBypass(player)) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
} }