Minor bit of code cleanup

This commit is contained in:
Brettflan 2015-05-19 09:17:24 -05:00
parent dcea6c1a07
commit 99bfc689f2
4 changed files with 14 additions and 34 deletions

View File

@ -264,6 +264,9 @@ public class Config
public static void setPreventBlockPlace(boolean enable) public static void setPreventBlockPlace(boolean enable)
{ {
if (preventBlockPlace != enable)
WorldBorder.plugin.enableBlockPlaceListener(enable);
preventBlockPlace = enable; preventBlockPlace = enable;
log("prevent block place " + (enable ? "enabled" : "disabled") + "."); log("prevent block place " + (enable ? "enabled" : "disabled") + ".");
save(true); save(true);
@ -271,6 +274,9 @@ public class Config
public static void setPreventMobSpawn(boolean enable) public static void setPreventMobSpawn(boolean enable)
{ {
if (preventMobSpawn != enable)
WorldBorder.plugin.enableMobSpawnListener(enable);
preventMobSpawn = enable; preventMobSpawn = enable;
log("prevent mob spawn " + (enable ? "enabled" : "disabled") + "."); log("prevent mob spawn " + (enable ? "enabled" : "disabled") + ".");
save(true); save(true);

View File

@ -29,14 +29,10 @@ public class WorldBorder extends JavaPlugin
getServer().getPluginManager().registerEvents(new WBListener(), this); getServer().getPluginManager().registerEvents(new WBListener(), this);
if (Config.preventBlockPlace()) if (Config.preventBlockPlace())
{
enableBlockPlaceListener(true); enableBlockPlaceListener(true);
}
if (Config.preventMobSpawn()) if (Config.preventMobSpawn())
{
enableMobSpawnListener(true); enableMobSpawnListener(true);
}
// integrate with DynMap if it's available // integrate with DynMap if it's available
DynMapFeatures.setup(); DynMapFeatures.setup();
@ -70,25 +66,19 @@ public class WorldBorder extends JavaPlugin
return getWorldBorder(worldName); return getWorldBorder(worldName);
} }
public void enableBlockPlaceListener(boolean enable) { public void enableBlockPlaceListener(boolean enable)
{
if (enable) if (enable)
{
getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this); getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this);
}
else if (blockPlaceListener != null) else if (blockPlaceListener != null)
{
blockPlaceListener.unregister(); blockPlaceListener.unregister();
}
} }
public void enableMobSpawnListener(boolean enable) { public void enableMobSpawnListener(boolean enable)
{
if (enable) if (enable)
{
getServer().getPluginManager().registerEvents(this.mobSpawnListener = new MobSpawnListener(), this); getServer().getPluginManager().registerEvents(this.mobSpawnListener = new MobSpawnListener(), this);
}
else if (mobSpawnListener != null) else if (mobSpawnListener != null)
{
mobSpawnListener.unregister(); mobSpawnListener.unregister();
}
} }
} }

View File

@ -6,14 +6,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.wimbli.WorldBorder.Config; import com.wimbli.WorldBorder.Config;
import com.wimbli.WorldBorder.WorldBorder;
public class CmdPreventPlace extends WBCmd { public class CmdPreventPlace extends WBCmd {
public CmdPreventPlace() { public CmdPreventPlace() {
name = permission = "preventblockplace"; name = permission = "preventblockplace";
minParams = 0; minParams = maxParams = 1;
maxParams = 1;
addCmdExample(nameEmphasized() + "<on|off> - stop block placement past border."); addCmdExample(nameEmphasized() + "<on|off> - stop block placement past border.");
helpText = "Default value: off. When enabled, this setting will prevent players from placing blocks outside the world's border."; helpText = "Default value: off. When enabled, this setting will prevent players from placing blocks outside the world's border.";
@ -28,13 +26,7 @@ public class CmdPreventPlace extends WBCmd {
@Override @Override
public void execute(CommandSender sender, Player player, List<String> params, String worldName) public void execute(CommandSender sender, Player player, List<String> params, String worldName)
{ {
if (params.size() == 1) { Config.setPreventBlockPlace(strAsBool(params.get(0)));
boolean previousSetting = Config.preventBlockPlace();
Config.setPreventBlockPlace(strAsBool(params.get(0)));
if (previousSetting != Config.preventBlockPlace()) {
WorldBorder.plugin.enableBlockPlaceListener(Config.preventBlockPlace());
}
}
if (player != null) if (player != null)
{ {

View File

@ -1,7 +1,6 @@
package com.wimbli.WorldBorder.cmd; package com.wimbli.WorldBorder.cmd;
import com.wimbli.WorldBorder.Config; import com.wimbli.WorldBorder.Config;
import com.wimbli.WorldBorder.WorldBorder;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,8 +10,7 @@ public class CmdPreventSpawn extends WBCmd {
public CmdPreventSpawn() { public CmdPreventSpawn() {
name = permission = "preventmobspawn"; name = permission = "preventmobspawn";
minParams = 0; minParams = maxParams = 1;
maxParams = 1;
addCmdExample(nameEmphasized() + "<on|off> - stop mob spawning past border."); addCmdExample(nameEmphasized() + "<on|off> - stop mob spawning past border.");
helpText = "Default value: off. When enabled, this setting will prevent mobs from naturally spawning outside the world's border."; helpText = "Default value: off. When enabled, this setting will prevent mobs from naturally spawning outside the world's border.";
@ -27,13 +25,7 @@ public class CmdPreventSpawn extends WBCmd {
@Override @Override
public void execute(CommandSender sender, Player player, List<String> params, String worldName) public void execute(CommandSender sender, Player player, List<String> params, String worldName)
{ {
if (params.size() == 1) { Config.setPreventMobSpawn(strAsBool(params.get(0)));
boolean previousSetting = Config.preventMobSpawn();
Config.setPreventMobSpawn(strAsBool(params.get(0)));
if (previousSetting != Config.preventMobSpawn()) {
WorldBorder.plugin.enableMobSpawnListener(Config.preventMobSpawn());
}
}
if (player != null) if (player != null)
{ {