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

View File

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

View File

@ -6,14 +6,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.wimbli.WorldBorder.Config;
import com.wimbli.WorldBorder.WorldBorder;
public class CmdPreventPlace extends WBCmd {
public CmdPreventPlace() {
name = permission = "preventblockplace";
minParams = 0;
maxParams = 1;
minParams = maxParams = 1;
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.";
@ -28,13 +26,7 @@ public class CmdPreventPlace extends WBCmd {
@Override
public void execute(CommandSender sender, Player player, List<String> params, String worldName)
{
if (params.size() == 1) {
boolean previousSetting = Config.preventBlockPlace();
Config.setPreventBlockPlace(strAsBool(params.get(0)));
if (previousSetting != Config.preventBlockPlace()) {
WorldBorder.plugin.enableBlockPlaceListener(Config.preventBlockPlace());
}
}
Config.setPreventBlockPlace(strAsBool(params.get(0)));
if (player != null)
{

View File

@ -1,7 +1,6 @@
package com.wimbli.WorldBorder.cmd;
import com.wimbli.WorldBorder.Config;
import com.wimbli.WorldBorder.WorldBorder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,8 +10,7 @@ public class CmdPreventSpawn extends WBCmd {
public CmdPreventSpawn() {
name = permission = "preventmobspawn";
minParams = 0;
maxParams = 1;
minParams = maxParams = 1;
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.";
@ -27,13 +25,7 @@ public class CmdPreventSpawn extends WBCmd {
@Override
public void execute(CommandSender sender, Player player, List<String> params, String worldName)
{
if (params.size() == 1) {
boolean previousSetting = Config.preventMobSpawn();
Config.setPreventMobSpawn(strAsBool(params.get(0)));
if (previousSetting != Config.preventMobSpawn()) {
WorldBorder.plugin.enableMobSpawnListener(Config.preventMobSpawn());
}
}
Config.setPreventMobSpawn(strAsBool(params.get(0)));
if (player != null)
{