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:
parent
542ad4a6a0
commit
26c708b65e
@ -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<String> adminBypassPlayers = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Persistance
|
||||
|
@ -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");
|
||||
}
|
||||
|
33
src/com/bukkit/mcteam/factions/commands/FCommandBypass.java
Normal file
33
src/com/bukkit/mcteam/factions/commands/FCommandBypass.java
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user