From 1a6e93f0df0f5a7d6c49449be4c0aabb858188c2 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Wed, 28 Sep 2011 16:28:09 -0600 Subject: [PATCH 01/10] Add aditional checks for onPlayerPortal --- .../onarandombox/MultiverseCore/listeners/MVPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 997c4579..6eb20e05 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -145,7 +145,7 @@ public class MVPlayerListener extends PlayerListener { @Override public void onPlayerPortal(PlayerPortalEvent event) { - if (event.isCancelled()) { + if (event.isCancelled() || event.getTo() == null || event.getFrom() == null) { return; } MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); From f0ae8cbb8eb6a0bed56bea1fd8a0c5e6deb49121 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Wed, 28 Sep 2011 17:02:21 -0600 Subject: [PATCH 02/10] Ensure that the world players are going to is not null --- .../MultiverseCore/listeners/MVPlayerListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 6eb20e05..1bc1278e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -173,6 +173,9 @@ public class MVPlayerListener extends PlayerListener { } } if (fromWorld != null) { + if (toWorld == null) { + return true; + } if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) { player.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString()); return true; From ea6e94d99dfd35ec89968c1acc4ee9365685b9c3 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Wed, 28 Sep 2011 19:34:00 -0600 Subject: [PATCH 03/10] Fix Signportals not going anywhere --- .../onarandombox/MultiverseCore/MVWorld.java | 4 ++- .../listeners/MVPlayerListener.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 67466f37..7ca5d4d3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -380,7 +380,9 @@ public class MVWorld { this.setMonsters(value); } else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) { this.setSpawnInMemory(value); - } else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { + } else if (name.equalsIgnoreCase("hunger")) { + this.setHunger(value); + }else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { this.setEnableWeather(value); } else { return false; diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 1bc1278e..e8c53116 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -129,6 +129,10 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled()) { return; } + // Handle the Players GameMode setting for the new world. + if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { + this.handleGameMode(event.getPlayer(), event.getTo().getWorld()); + } MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); @@ -145,9 +149,14 @@ public class MVPlayerListener extends PlayerListener { @Override public void onPlayerPortal(PlayerPortalEvent event) { + if (event.isCancelled() || event.getTo() == null || event.getFrom() == null) { return; } + // Handle the Players GameMode setting for the new world. + if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { + this.handleGameMode(event.getPlayer(), event.getTo().getWorld()); + } MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); @@ -171,27 +180,19 @@ public class MVPlayerListener extends PlayerListener { player.sendMessage("You don't have access to go here..."); return true; } + } else { + // The toworld is not handled by MV, we don't care about payments + return false; } if (fromWorld != null) { - if (toWorld == null) { - return true; - } if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) { player.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString()); return true; } } - if (toWorld == null) { - // The toworld is not handled by MV, we don't care about payments - return false; - } + // Only check payments if it's a different world: if (!toWorld.equals(fromWorld)) { - // Handle the Players GameMode setting for the new world. - if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { - this.handleGameMode(player, toWorld); - } - // If the player does not have to pay, return now. if (toWorld.isExempt(player)) { return false; From d97bbfb1b1d24f7d8fd7a6c99548f2ea8ade1a3d Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Wed, 28 Sep 2011 19:56:41 -0600 Subject: [PATCH 04/10] Fixed Hunger/Food setting Closes #119 --- .../com/onarandombox/MultiverseCore/MVPlayerSession.java | 8 -------- .../java/com/onarandombox/MultiverseCore/MVWorld.java | 2 +- .../com/onarandombox/MultiverseCore/MultiverseCore.java | 1 + .../MultiverseCore/commands/InfoCommand.java | 1 + .../MultiverseCore/commands/ModifyCommand.java | 2 +- .../MultiverseCore/listeners/MVPlayerListener.java | 9 --------- 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java b/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java index def86ec9..15fdac12 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java @@ -20,7 +20,6 @@ public class MVPlayerSession { private Long messageLast = 0L; // Timestamp for the Players last Alert Message. private Configuration config; // Configuration file to find out Cooldown Timers. - private int cachedHunger = 20; public MVPlayerSession(Player player, Configuration config, MultiverseCore multiVerseCore) { this.player = player; @@ -48,11 +47,4 @@ public class MVPlayerSession { return false; } } - - public void setCachedHunger() { - this.cachedHunger = this.player.getFoodLevel(); - } - public int getCachedHunger() { - return this.cachedHunger; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 7ca5d4d3..a40e4f81 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -380,7 +380,7 @@ public class MVWorld { this.setMonsters(value); } else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) { this.setSpawnInMemory(value); - } else if (name.equalsIgnoreCase("hunger")) { + } else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))){ this.setHunger(value); }else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { this.setEnableWeather(value); diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 922323fb..880b2dff 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -208,6 +208,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning. + pm.registerEvent(Event.Type.FOOD_LEVEL_CHANGE, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this); pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index 8fbf311f..9b484f19 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -126,6 +126,7 @@ public class InfoCommand extends MultiverseCommand { message = new ArrayList(); message.add(new FancyHeader("More World Settings", colors)); message.add(new FancyMessage("Weather: ", world.getWeatherEnabled() + "", colors)); + message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors)); message.add(new FancyMessage("Keep spawn in memory: ", world.getKeepSpawnInMemory() + "", colors)); message.add(new FancyHeader("PVP Settings", colors)); message.add(new FancyMessage("Multiverse Setting: ", world.getPvp().toString(), colors)); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java index b0ee8990..0b26177e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java @@ -27,7 +27,7 @@ enum Action { // Color == Aliascolor enum SetProperties { - alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, gamemode, mode, hunger + alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, gamemode, mode, hunger, food } public class ModifyCommand extends MultiverseCommand { diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index e8c53116..92055540 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -136,15 +136,6 @@ public class MVPlayerListener extends PlayerListener { MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); - // Dunno If I like these... @fernferret -// if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) { -// // If to has hunger, and from doesn't, save the hunger -// this.plugin.getPlayerSession(event.getPlayer()).setCachedHunger(); -// } -// else if (toWorld != null && toWorld.getHunger() && fromWorld != null && !fromWorld.getHunger() && !event.isCancelled()) { -// // If from has hunger, and to doesn't, restore the hunger -// event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger()); -// } } @Override From c566ead9ef0d26c0599280b2ce0b768491ad621f Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 2 Oct 2011 21:18:25 -0600 Subject: [PATCH 05/10] Add multiworld difficulty --- .../onarandombox/MultiverseCore/MVWorld.java | 27 +++++++++++++++++++ .../commands/ModifyCommand.java | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index a40e4f81..807220ac 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -406,6 +406,9 @@ public class MVWorld { * @return */ public boolean setVariable(String name, String value) { + if (name.equalsIgnoreCase("diff") || name.equalsIgnoreCase("difficulty")) { + return this.setDifficulty(value); + } if (name.equalsIgnoreCase("alias")) { this.setAlias(value); return true; @@ -733,4 +736,28 @@ public class MVWorld { public Location getSpawnLocation() { return this.spawnLocation; } + + public World.Difficulty getDifficulty() { + return this.getCBWorld().getDifficulty(); + } + + public boolean setDifficulty(String difficulty) { + try { + World.Difficulty worlddiff = World.Difficulty.valueOf(difficulty); + this.getCBWorld().setDifficulty(worlddiff); + return true; + } catch (Exception e) { + try { + int diff = Integer.parseInt(difficulty); + if(diff >= 0 && diff <= 3) { + World.Difficulty worlddiff = World.Difficulty.getDifficulty(diff); + this.getCBWorld().setDifficulty(worlddiff); + return true; + } + } catch (Exception e2) { + } + return false; + } + + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java index 0b26177e..6bcdc175 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java @@ -27,7 +27,7 @@ enum Action { // Color == Aliascolor enum SetProperties { - alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, gamemode, mode, hunger, food + alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, gamemode, mode, hunger, food, diff, difficulty } public class ModifyCommand extends MultiverseCommand { From 091c5a962136812543f38980525ecc54d6095f56 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 3 Oct 2011 17:43:57 -0600 Subject: [PATCH 06/10] Move GameMode check to onPlayerChangeWorld, fix difficulty case settings --- .../onarandombox/MultiverseCore/MVWorld.java | 2 +- .../MultiverseCore/MultiverseCore.java | 1 + .../listeners/MVPlayerListener.java | 25 ++++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 807220ac..5370df5d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -743,7 +743,7 @@ public class MVWorld { public boolean setDifficulty(String difficulty) { try { - World.Difficulty worlddiff = World.Difficulty.valueOf(difficulty); + World.Difficulty worlddiff = World.Difficulty.valueOf(difficulty.toUpperCase()); this.getCBWorld().setDifficulty(worlddiff); return true; } catch (Exception e) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 880b2dff..63e887dc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -204,6 +204,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.Monitor, this); // To switch gamemode + pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 92055540..37b125c9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -63,10 +63,6 @@ public class MVPlayerListener extends PlayerListener { } if (event.isBedSpawn() && this.plugin.getConfig().getBoolean("bedrespawn", true)) { - // Handle the Players GameMode setting for the new world. - if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { - this.handleGameMode(event.getPlayer(), event.getRespawnLocation().getWorld()); - } this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed"); return; } @@ -90,11 +86,6 @@ public class MVPlayerListener extends PlayerListener { MVRespawnEvent respawnEvent = new MVRespawnEvent(respawnLocation, event.getPlayer(), "compatability"); this.plugin.getServer().getPluginManager().callEvent(respawnEvent); event.setRespawnLocation(respawnEvent.getPlayersRespawnLocation()); - - // Handle the Players GameMode setting for the new world. - if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { - this.handleGameMode(event.getPlayer(), respawnEvent.getPlayersRespawnLocation().getWorld()); - } } private Location getMostAccurateRespawnLocation(World w) { @@ -119,6 +110,14 @@ public class MVPlayerListener extends PlayerListener { } } + @Override + public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { + // Handle the Players GameMode setting for the new world. + if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { + this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); + } + } + @Override public void onPlayerQuit(PlayerQuitEvent event) { this.plugin.removePlayerSession(event.getPlayer()); @@ -129,10 +128,6 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled()) { return; } - // Handle the Players GameMode setting for the new world. - if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { - this.handleGameMode(event.getPlayer(), event.getTo().getWorld()); - } MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); @@ -144,10 +139,6 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled() || event.getTo() == null || event.getFrom() == null) { return; } - // Handle the Players GameMode setting for the new world. - if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) { - this.handleGameMode(event.getPlayer(), event.getTo().getWorld()); - } MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer())); From 9be14a2a0c6b2a8f7b4c5235311da510d02133b4 Mon Sep 17 00:00:00 2001 From: Rigby Date: Tue, 4 Oct 2011 01:28:42 +0100 Subject: [PATCH 07/10] You just can't get the right staff these days... --- src/main/java/com/onarandombox/MultiverseCore/MVWorld.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 5370df5d..76a9d433 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -8,6 +8,7 @@ package com.onarandombox.MultiverseCore; import org.bukkit.ChatColor; +import org.bukkit.Difficulty; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; @@ -737,20 +738,20 @@ public class MVWorld { return this.spawnLocation; } - public World.Difficulty getDifficulty() { + public Difficulty getDifficulty() { return this.getCBWorld().getDifficulty(); } public boolean setDifficulty(String difficulty) { try { - World.Difficulty worlddiff = World.Difficulty.valueOf(difficulty.toUpperCase()); + Difficulty worlddiff = Difficulty.valueOf(difficulty.toUpperCase()); this.getCBWorld().setDifficulty(worlddiff); return true; } catch (Exception e) { try { int diff = Integer.parseInt(difficulty); if(diff >= 0 && diff <= 3) { - World.Difficulty worlddiff = World.Difficulty.getDifficulty(diff); + Difficulty worlddiff = Difficulty.getByValue(diff); this.getCBWorld().setDifficulty(worlddiff); return true; } From 86d3628b1c291abccb289885aed174e0fb465e56 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 3 Oct 2011 19:24:38 -0600 Subject: [PATCH 08/10] Actually save the difficulty --- .../onarandombox/MultiverseCore/MVWorld.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 76a9d433..6885b260 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -7,11 +7,7 @@ package com.onarandombox.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.Difficulty; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.World.Environment; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; @@ -105,6 +101,7 @@ public class MVWorld { private String generator; private Permission permission; private Permission exempt; + private Difficulty difficulty; private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor. private boolean allowWeather; @@ -140,6 +137,7 @@ public class MVWorld { this.setScaling(config.getDouble("worlds." + this.name + ".scale", this.getDefaultScale(this.environment))); this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", "")); this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true)); + this.setDifficulty(config.getString("worlds." + this.name + ".difficulty", "EASY")); this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true)); this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true)); @@ -381,9 +379,9 @@ public class MVWorld { this.setMonsters(value); } else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) { this.setSpawnInMemory(value); - } else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))){ + } else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))) { this.setHunger(value); - }else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { + } else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { this.setEnableWeather(value); } else { return false; @@ -743,22 +741,22 @@ public class MVWorld { } public boolean setDifficulty(String difficulty) { + Difficulty worlddiff = null; try { - Difficulty worlddiff = Difficulty.valueOf(difficulty.toUpperCase()); - this.getCBWorld().setDifficulty(worlddiff); - return true; + worlddiff = Difficulty.valueOf(difficulty.toUpperCase()); } catch (Exception e) { try { int diff = Integer.parseInt(difficulty); - if(diff >= 0 && diff <= 3) { - Difficulty worlddiff = Difficulty.getByValue(diff); - this.getCBWorld().setDifficulty(worlddiff); - return true; + if (diff >= 0 && diff <= 3) { + worlddiff = Difficulty.getByValue(diff); } } catch (Exception e2) { + return false; } - return false; } - + this.getCBWorld().setDifficulty(worlddiff); + config.setProperty("worlds." + this.name + ".difficulty", worlddiff); + saveConfig(); + return true; } } From 6e7daf4e851c6950c3904ff1968590484c9facd3 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 3 Oct 2011 19:40:21 -0600 Subject: [PATCH 09/10] And this is why we need unit tests... --- src/main/java/com/onarandombox/MultiverseCore/MVWorld.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 6885b260..32693508 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -749,13 +749,15 @@ public class MVWorld { int diff = Integer.parseInt(difficulty); if (diff >= 0 && diff <= 3) { worlddiff = Difficulty.getByValue(diff); + } else { + return false; } } catch (Exception e2) { return false; } } this.getCBWorld().setDifficulty(worlddiff); - config.setProperty("worlds." + this.name + ".difficulty", worlddiff); + config.setProperty("worlds." + this.name + ".difficulty", worlddiff.getValue()); saveConfig(); return true; } From ae19604eab8e736b3e0b560a1bc199eb510cd13a Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 3 Oct 2011 19:59:29 -0600 Subject: [PATCH 10/10] Add difficulty to the info command --- .../com/onarandombox/MultiverseCore/commands/InfoCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index 9b484f19..39232382 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -125,6 +125,7 @@ public class InfoCommand extends MultiverseCommand { // Page 2 message = new ArrayList(); message.add(new FancyHeader("More World Settings", colors)); + message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors)); message.add(new FancyMessage("Weather: ", world.getWeatherEnabled() + "", colors)); message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors)); message.add(new FancyMessage("Keep spawn in memory: ", world.getKeepSpawnInMemory() + "", colors));