Permalink
Browse files

Added: T shape, plus shape

Fixed: Spelling mistake
Added: /ulava status (not 100% yet)
Changed: Load variables into memory
Added: real multiworld support!
Changed: Exception behavior
Updated: Metrics

Thanks to Xastabus for Patch #1
  • Loading branch information...
1 parent 856bdc7 commit 9529ccb50e72c3d086fd51ed3a85813cd460fb59 @timbru31 committed Jun 23, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,11 +1,16 @@
package de.dustplanet.unlimitedlava;
import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Logger;
+
+import org.bukkit.World;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.*;
import org.bukkit.entity.Player;
@@ -22,6 +27,7 @@
* @thanks to loganwm for the help!!
* @thanks to Edward Hand for the idea and original InfiniteLava plugin!
* @thanks to ferrybig for the awesome fall code!
+ * @thanks to Xastabus for the cool improvements of the checks!
*
*/
@@ -30,6 +36,9 @@
private final UnlimitedLavaBlockListener blockListener = new UnlimitedLavaBlockListener(this);
private final UnlimitedLavaPlayerListener playerListener = new UnlimitedLavaPlayerListener(this);
private final UnlimitedLavaInventoryListener inventoryListener = new UnlimitedLavaInventoryListener(this);
+ public boolean three, two, other, big, plus, T, lavaFall, waterFall, messages = true, permissions = true, furnace;
+ public int height = 60;
+ public List<String> enabledWords = new ArrayList<String>();
public FileConfiguration config;
public FileConfiguration localization;
public File configFile;
@@ -58,6 +67,7 @@ public void onEnable() {
}
config = this.getConfig();
loadConfig();
+ loadValues();
// Localization
localizationFile = new File(getDataFolder(), "localization.yml");
@@ -66,14 +76,9 @@ public void onEnable() {
copy(getResource("localization.yml"), localizationFile);
}
// Try to load
- try {
- localization = YamlConfiguration.loadConfiguration(localizationFile);
- loadLocalization();
- }
- // if it failed, tell it
- catch (Exception e) {
- log.warning("UnlimitedLava failed to load the localization!");
- }
+ localization = YamlConfiguration.loadConfiguration(localizationFile);
+ loadLocalization();
+
//Refer to UnlimitedLavaCommands
executor = new UnlimitedLavaCommands(this);
@@ -85,10 +90,9 @@ public void onEnable() {
// Stats
try {
- Metrics metrics = new Metrics();
- metrics.beginMeasuringPlugin(this);
- }
- catch (IOException e) {}
+ Metrics metrics = new Metrics(this);
+ metrics.start();
+ } catch (IOException e) {}
}
// Reloads the config file, via command /unlimitedlava reload or /ulava reload and at the start!
@@ -102,13 +106,38 @@ public void loadConfig() {
config.addDefault("sources.two", true);
config.addDefault("sources.other", false);
config.addDefault("sources.big", false);
+ config.addDefault("sources.plus", true);
+ config.addDefault("sources.T", true);
config.addDefault("sources.lava_fall", true);
config.addDefault("sources.water_fall", false);
config.addDefault("furnace.item", "BUCKET");
+ List<World> temp = getServer().getWorlds();
+ List<String> tempList = new ArrayList<String>();
+ for (World w : temp) {
+ tempList.add(w.getName());
+ }
+ config.addDefault("enabled_worlds", tempList);
config.options().copyDefaults(true);
saveConfig();
}
+ // Load the values into memory
+ public void loadValues() {
+ three = config.getBoolean("sources.three");
+ two = config.getBoolean("sources.two");
+ other = config.getBoolean("sources.other");
+ big = config.getBoolean("sources.big");
+ plus = config.getBoolean("sources.plus");
+ T = config.getBoolean("sources.T");
+ lavaFall = config.getBoolean("sources.lava_fall");
+ waterFall = config.getBoolean("sources.water_Fall");
+ permissions = config.getBoolean("configuration.permissions");
+ messages = config.getBoolean("configuration.messages");
+ furnace = config.getBoolean("configuration.furnace");
+ height = config.getInt("configuration.height");
+ enabledWords = config.getStringList("enabled_worlds");
+ }
+
// Loads the localization
public void loadLocalization() {
localization.options().header("The underscores are used for the different lines!");
@@ -134,6 +163,7 @@ public void loadLocalization() {
localization.addDefault("disable_permissions_1", "&2UnlimitedLava permissions disabled! Only OPs");
localization.addDefault("disable_permissions_2", "&4All players can use the plugin!");
localization.addDefault("disable_furnace", "&2UnlimitedLava &4furnace &2disabled!");
+ localization.addDefault("status", "&2Currently enabled sources: &4 %source%");
localization.options().copyDefaults(true);
saveLocalization();
}
@@ -142,9 +172,8 @@ public void loadLocalization() {
public void saveLocalization() {
try {
localization.save(localizationFile);
- }
- catch (IOException e) {
- log.warning("UnlimitedLava failed to save the localization! Please report this!");
+ } catch (IOException e) {
+ log.warning("UnlimitedLava failed to save the localization! Please report this! (I/O)");
}
}
@@ -155,9 +184,12 @@ public void loadConfigsAgain() {
saveConfig();
localization.load(localizationFile);
saveLocalization();
- }
- catch (Exception e) {
- e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ log.warning("UnlimitedLava failed to save the localization! Please report this! (FileNotFound)");
+ } catch (IOException e) {
+ log.warning("UnlimitedLava failed to save the localization! Please report this! (I/O)");
+ } catch (InvalidConfigurationException e) {
+ log.warning("UnlimitedLava failed to save the localization! Please report this! (InvalidConfiguration)");
}
}
@@ -172,8 +204,9 @@ private void copy(InputStream in, File file) {
}
out.close();
in.close();
- }
- catch (Exception e) {
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
e.printStackTrace();
}
}
@@ -20,6 +20,7 @@
* @thanks to loganwm for the help!!
* @thanks to Edward Hand for the idea and original InfiniteLava plugin!
* @thanks to ferrybig for the awesome fall code!
+ * @thanks to Xastabus for the cool improvements of the checks!
*
*/
@@ -37,11 +38,13 @@ public void onBlockFromTo(BlockFromToEvent event) {
Block sourceBlock = event.getBlock();
Block targetBlock = event.getToBlock();
+ if (!plugin.enabledWords.contains(sourceBlock.getWorld().getName())) return;
+
// Only if the height is greater or the same
- if (sourceBlock.getY() < plugin.config.getInt("configuration.height")) return;
+ if (sourceBlock.getY() <= plugin.height) return;
// Lava fall
- if (plugin.config.getBoolean("sources.lava_fall") == true) {
+ if (plugin.lavaFall) {
// Security check with 0
if (sourceBlock.getY() > 0) {
if(event.getFace() == BlockFace.DOWN) {
@@ -55,9 +58,9 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
}
}
-
+
// Water fall
- if (plugin.config.getBoolean("sources.water_fall") == true) {
+ if (plugin.waterFall) {
// Security check with 0
if (sourceBlock.getY() > 0) {
if(event.getFace() == BlockFace.DOWN) {
@@ -73,43 +76,36 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
// Check if we got a full block of lava
- if (sourceBlock.getData() != 0x0) {
- return;
- }
+ if (sourceBlock.getData() != 0x0) return;
if (sourceBlock.getType() == Material.LAVA || sourceBlock.getType() == Material.STATIONARY_LAVA) {
// Check if we can use the surrounded check
if (targetBlock.getType() == Material.LAVA || targetBlock.getType() == Material.STATIONARY_LAVA) {
// Full block (0x0) and not falling (0x8)
if (targetBlock.getData() != 0x0 && targetBlock.getData() != 0x8) {
- // Spread if possible for TWO
- if (plugin.config.getBoolean("sources.two") == true) {
- if (UnlimitedLavaCheck.checkSpreadValidityTwo(targetBlock)) {
- // Only full blocks
- event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
- }
- }
- // Spread if possible for THREE
- if (plugin.config.getBoolean("sources.three") == true) {
- if (UnlimitedLavaCheck.checkSpreadValidityThree(targetBlock)) {
- // Only full blocks
- event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
- }
- }
- // Spread if possible for OTHER
- if (plugin.config.getBoolean("sources.other") == true) {
- if (UnlimitedLavaCheck.checkSpreadValidityOther(targetBlock)) {
- // Only full blocks
- event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
- }
- }
- // Spread if possible for BIG
- if (plugin.config.getBoolean("sources.big") == true) {
- if (UnlimitedLavaCheck.checkSpreadValidityBig(targetBlock)) {
- // Only full blocks
- event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
- }
- }
+ // Check which cases are valid
+ int faces = UnlimitedLavaCheck.checkSpreadValidityFaces(targetBlock);
+ int corners = UnlimitedLavaCheck.checkSpreadValidityCorners(targetBlock);
+ boolean lake = UnlimitedLavaCheck.checkIsInLake(targetBlock);
+ boolean border = UnlimitedLavaCheck.checkIsOnBorder(targetBlock);
+ // Big
+ if (plugin.big && faces == 4 && corners == 4 && lake == true && border == false)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
+ // Three
+ else if (plugin.three && faces == 4 && corners == 4 && lake == false && border == false)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
+ // Two
+ else if (plugin.two && faces == 2 && corners == 1 && lake == false && border == true)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
+ // Plus
+ else if (plugin.plus && faces == 4 && corners == 0 && lake == false && border == true)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
+ // Other
+ else if (plugin.other && faces == 2 && corners == 0 && lake == false && border == true)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
+ // T Shape
+ else if (plugin.T && faces == 3 && corners == 0 && lake == false && border == true)
+ event.getToBlock().setTypeIdAndData(Material.LAVA.getId(), (byte) 0x0, true);
}
}
}
Oops, something went wrong.

0 comments on commit 9529ccb

Please sign in to comment.