From b6fcec2dead096f95cbf9ce87cc561d3769e80be Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 19:54:41 -0800 Subject: [PATCH 1/8] Restructure the default config file. --- src/main/resources/config.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 80b9dc5..dcb5cc0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,9 +1,14 @@ +tnt: + enabled: true -preferences: - tnt: true - weather: true - slimes: true - spawnItems: false -meta: - weather: - world: world +weather: + enabled: true + worlds: + - name: world + reduction : 0.75 + +slimes: + enabled: true + +spawn_items: + enabled: false From a43a32881e42d090c84866844f6c6ad1d3b03143 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:04:43 -0800 Subject: [PATCH 2/8] Read for multiple worlds and their respective reduction rates. --- src/main/java/com/bitlimit/Tweaks/Tweaks.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/bitlimit/Tweaks/Tweaks.java b/src/main/java/com/bitlimit/Tweaks/Tweaks.java index 3759861..274e27d 100644 --- a/src/main/java/com/bitlimit/Tweaks/Tweaks.java +++ b/src/main/java/com/bitlimit/Tweaks/Tweaks.java @@ -6,6 +6,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import java.util.HashMap; +import java.util.List; + public class Tweaks extends JavaPlugin { private int weatherId; @@ -29,7 +32,7 @@ public void saveConfig() { this.getConfig().options().copyDefaults(true); this.reloadConfig(); - setRepeatingTaskEnabled(this.getConfig().getConfigurationSection("preferences").getBoolean("weather")); + setRepeatingTaskEnabled(this.getConfig().getConfigurationSection("weather").getBoolean("enabled")); } public void setRepeatingTaskEnabled(boolean enabled) { @@ -44,14 +47,19 @@ class BitLimitRecurringTask implements Runnable { } public void run() { - World world = this.plugin.getServer().getWorld(plugin.getConfig().getConfigurationSection("meta").getConfigurationSection("weather").getString("world")); + for (HashMap worldDefinition : (List>)this.plugin.getConfig().getConfigurationSection("weather").getList("worlds")) + { + String worldName = (String)worldDefinition.get("name"); + World world = this.plugin.getServer().getWorld(worldName); - if (!world.hasStorm()) { - int weatherDuration = world.getWeatherDuration(); - double ratio = 0.75; // 75% less often. - int calculatedAddback = (int)(1200 * ratio); - world.setWeatherDuration(weatherDuration + calculatedAddback); - } + if (!world.hasStorm()) + { + int weatherDuration = world.getWeatherDuration(); + Float ratio = (Float)worldDefinition.get("reduction"); + int counterAmount = (int)(1200 * ratio); + world.setWeatherDuration(weatherDuration + counterAmount); + } + } } } From 235572ad745c19f282151a25b71e81e9aff0fa0e Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:06:46 -0800 Subject: [PATCH 3/8] Correct which configuration section is set. Reduce code duplicity as well. --- .../com/bitlimit/Tweaks/TweaksCommandExecutor.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java b/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java index 9665300..9c8f25b 100644 --- a/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java +++ b/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java @@ -34,14 +34,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } boolean newValue = parsedBooleanInput(args[1]); - ConfigurationSection configurationSection = config.getConfigurationSection("preferences"); - - if (args[0].toLowerCase().equals("tnt")) { - configurationSection.set("tnt", newValue); - } else if (args[0].toLowerCase().equals("weather")) { - configurationSection.set("weather", newValue); - } else if (args[0].toLowerCase().equals("slimes")) { - configurationSection.set("slimes", newValue); + String modified = args[0].toLowerCase(); + + if (modified.equals("tnt") || modified.equals("weather") || modified.equals("slimes")) + { + config.getConfigurationSection(modified).set("enabled", newValue); } else if (args[0].toLowerCase().equals("spawnitems")) { if (args[1].toLowerCase().equals("location")) { From 25c69ef7ca0579ecebaed79d7a3fe9bb3a2300d9 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:07:22 -0800 Subject: [PATCH 4/8] Fix capitalization of preferences and alignment. --- src/main/resources/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dcb5cc0..36b2f1e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,11 +4,11 @@ tnt: weather: enabled: true worlds: - - name: world - reduction : 0.75 + - name: world + reduction: 0.75 slimes: enabled: true -spawn_items: +spawnItems: enabled: false From d30efedfc5485f7a14e381e862e178815b5af453 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:14:14 -0800 Subject: [PATCH 5/8] Revise all usage of configuration to match the new style. --- .../Tweaks/TweaksCommandExecutor.java | 38 ++++++++++++++----- .../com/bitlimit/Tweaks/TweaksListener.java | 8 ++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java b/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java index 9c8f25b..1269cc3 100644 --- a/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java +++ b/src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java @@ -39,14 +39,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (modified.equals("tnt") || modified.equals("weather") || modified.equals("slimes")) { config.getConfigurationSection(modified).set("enabled", newValue); - } else if (args[0].toLowerCase().equals("spawnitems")) { - + } + else if (args[0].toLowerCase().equals("spawnitems")) + { if (args[1].toLowerCase().equals("location")) { try { - ConfigurationSection section = config.getConfigurationSection("meta").createSection("spawnItems").createSection("location"); - if (sender instanceof Player) { + ConfigurationSection section = null; + ConfigurationSection spawnItemsSection = config.getConfigurationSection("spawnItems"); + + if (spawnItemsSection.contains("location")) + { + section = spawnItemsSection.getConfigurationSection("location"); + } + else + { + section = spawnItemsSection.createSection("location"); + } + + if (sender instanceof Player) + { Player player = (Player)sender; this.putLocationInSection(player.getLocation(), section); sender.sendMessage(ChatColor.GREEN + "Location set successfully."); @@ -60,7 +73,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } else { - configurationSection.set("spawnItems", newValue); + config.getConfigurationSection("spawnItems").set("enabled", newValue); } } else { sender.sendMessage(ChatColor.RED + "Invalid parameter. Expected TNT, weather, or slimes."); @@ -76,14 +89,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St String newValueString = newValue ? "enabled" : "disabled"; sender.sendMessage(ChatColor.AQUA + argument + " tweaks are now " + ChatColor.GOLD + newValueString +ChatColor.AQUA + "."); } else if (args.length == 1) { - String argument = args[0].toLowerCase(); - if (argument.equals("tnt") || argument.equals("weather") || argument.equals("slimes") || argument.equals("spawnItems")) { - boolean enabled = config.getBoolean("enabled-" + argument); + String argument = args[0]; + if (argument.equals("tnt") || argument.equals("weather") || argument.equals("slimes") || argument.equals("spawnItems")) + { + boolean enabled = config.getConfigurationSection(argument).getBoolean("enabled"); if (argument.equals("tnt")) { argument = "TNT"; - } else { + } + else if (argument.equals("spawnItems")) + { + argument = "Item-spawning"; + } + else { argument = capitalizedString(argument); } + if (enabled) { sender.sendMessage(ChatColor.AQUA + argument + ChatColor.GREEN + " tweaks are currently enabled."); } else { diff --git a/src/main/java/com/bitlimit/Tweaks/TweaksListener.java b/src/main/java/com/bitlimit/Tweaks/TweaksListener.java index 2b8c6fa..d04c323 100644 --- a/src/main/java/com/bitlimit/Tweaks/TweaksListener.java +++ b/src/main/java/com/bitlimit/Tweaks/TweaksListener.java @@ -56,7 +56,7 @@ public void onCreatureSpawnEvent(CreatureSpawnEvent event) { // CreatureSpawnEvent (Entity spawnee, CreatureType type, Location loc, SpawnReason reason FileConfiguration config = this.plugin.getConfig(); - if (!config.getConfigurationSection("preferences").getBoolean("slimes")) + if (!config.getConfigurationSection("slimes").getBoolean("enabled")) return; // Gather information to determine if these are the slimes we are looking for. @@ -79,7 +79,7 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) { // Event reference // BlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild) - boolean confinementEnabled = this.plugin.getConfig().getConfigurationSection("preferences").getBoolean("tnt"); + boolean confinementEnabled = this.plugin.getConfig().getConfigurationSection("tnt").getBoolean("enabled"); if (event.getItemInHand().getType() == Material.TNT && confinementEnabled) { WorldGuardPlugin worldGuard = getWorldGuard(); @@ -561,10 +561,10 @@ public void onExplosionEvent(EntityExplodeEvent event) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerJoinEvent(PlayerJoinEvent event) { if (!event.getPlayer().hasPlayedBefore()) { - if (!this.plugin.getConfig().getConfigurationSection("preferences").getBoolean("spawnItems")) + if (!this.plugin.getConfig().getConfigurationSection("spawnItems").getBoolean("enabled")) return; - Location location = this.parseLocation(this.plugin.getConfig().getConfigurationSection("meta").getConfigurationSection("spawnItems").getConfigurationSection("location")); + Location location = this.parseLocation(this.plugin.getConfig().getConfigurationSection("spawnItems").getConfigurationSection("location")); Block block = location.getWorld().getBlockAt(location); if (block.getType() == Material.CHEST) { From bc621ebeef69d1faa2ff2a4029c2739bd14096a4 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:35:38 -0800 Subject: [PATCH 6/8] Fix cast class exception from Float in preferences. --- Tweaks.iml | 28 +++++++++++++++++++ src/main/java/com/bitlimit/Tweaks/Tweaks.java | 15 +++++++--- src/main/resources/config.yml | 5 ++-- 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 Tweaks.iml diff --git a/Tweaks.iml b/Tweaks.iml new file mode 100644 index 0000000..9fbea64 --- /dev/null +++ b/Tweaks.iml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/bitlimit/Tweaks/Tweaks.java b/src/main/java/com/bitlimit/Tweaks/Tweaks.java index 274e27d..f0b4c2a 100644 --- a/src/main/java/com/bitlimit/Tweaks/Tweaks.java +++ b/src/main/java/com/bitlimit/Tweaks/Tweaks.java @@ -1,5 +1,7 @@ package com.bitlimit.Tweaks; +import com.sk89q.worldedit.bukkit.BukkitBiomeType; +import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.plugin.Plugin; @@ -38,7 +40,10 @@ public void saveConfig() { public void setRepeatingTaskEnabled(boolean enabled) { Server server = this.getServer(); BukkitScheduler scheduler = server.getScheduler(); - if (enabled && this.weatherId == 0) { + final long baseDuration = 1200L; + + if (enabled && this.weatherId == 0) + { class BitLimitRecurringTask implements Runnable { Plugin plugin; @@ -55,15 +60,17 @@ public void run() { if (!world.hasStorm()) { int weatherDuration = world.getWeatherDuration(); - Float ratio = (Float)worldDefinition.get("reduction"); - int counterAmount = (int)(1200 * ratio); + Double ratio = (Double)worldDefinition.get("reduction"); + int counterAmount = (int)(baseDuration * ratio); world.setWeatherDuration(weatherDuration + counterAmount); + + Bukkit.broadcastMessage("Reducing weather counter with ratio " + ratio + " in world " + world); } } } } - this.weatherId = scheduler.scheduleSyncRepeatingTask(this, new BitLimitRecurringTask(this), 1200L, 1200L); + this.weatherId = scheduler.scheduleSyncRepeatingTask(this, new BitLimitRecurringTask(this), baseDuration, baseDuration); } else if (this.weatherId != 0) { scheduler.cancelTask(this.weatherId); this.weatherId = 0; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 36b2f1e..0219ad3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,8 +4,9 @@ tnt: weather: enabled: true worlds: - - name: world - reduction: 0.75 + - + name : world + reduction: 0.75 slimes: enabled: true From b8ea65947199fd3ab70383f426697a5eb18bb9c6 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:35:57 -0800 Subject: [PATCH 7/8] Remove superfluous debug broadcast. --- src/main/java/com/bitlimit/Tweaks/Tweaks.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/bitlimit/Tweaks/Tweaks.java b/src/main/java/com/bitlimit/Tweaks/Tweaks.java index f0b4c2a..05e5948 100644 --- a/src/main/java/com/bitlimit/Tweaks/Tweaks.java +++ b/src/main/java/com/bitlimit/Tweaks/Tweaks.java @@ -63,8 +63,6 @@ public void run() { Double ratio = (Double)worldDefinition.get("reduction"); int counterAmount = (int)(baseDuration * ratio); world.setWeatherDuration(weatherDuration + counterAmount); - - Bukkit.broadcastMessage("Reducing weather counter with ratio " + ratio + " in world " + world); } } } From 6d24ad59f8711df2eba7a63c679a6ea9960f81e3 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 13 Jan 2014 20:36:40 -0800 Subject: [PATCH 8/8] Version bump and description revision. --- src/main/resources/plugin.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 451453e..c4150db 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,12 +1,12 @@ main: com.bitlimit.Tweaks.Tweaks name: Tweaks -version: 1.6.3 +version: 1.6.4 author: Kolin Krewinkel & BitLimit Team -description: Code-level runtime tweaks for BitLimit Private Survival. +description: Gameplay tweaks for BitLimit Private Survival. website: http://github.com/BitLimit/Tweaks/ commands: tweaks: - description: /tweaks [tnt|slimes|weather] [state] to set the state or omit the state to return the current config status. + description: /tweaks [tnt|slimes|weather|spawnItems] [state] to set the state or omit the state to return the current config status. permissions: tweaks.*: description: Gives all permissions of BitLimit Tweaks plugin toggling.