From a45ce796ac4c29b4dd7845842c3f6d867b2fec49 Mon Sep 17 00:00:00 2001 From: minecon724 Date: Wed, 28 Sep 2022 16:03:57 +0200 Subject: [PATCH] n'egger --- .classpath | 9 ++++- pom.xml | 9 +++-- src/main/java/pl/minecon724/giants/Main.java | 38 +++++++++++++------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.classpath b/.classpath index 4975bcf..2c36148 100644 --- a/.classpath +++ b/.classpath @@ -11,7 +11,7 @@ - + @@ -21,5 +21,12 @@ + + + + + + + diff --git a/pom.xml b/pom.xml index 2b5d22f..5ff0273 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 giants giants - 22.2.4 + 22.9.0 1.8 @@ -20,13 +20,13 @@ org.spigotmc spigot-api - 1.18.1-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT provided org.bstats bstats-bukkit - 2.2.1 + 3.0.0 compile @@ -42,12 +42,11 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.4.0 org.bstats - pl.minecon724.giants diff --git a/src/main/java/pl/minecon724/giants/Main.java b/src/main/java/pl/minecon724/giants/Main.java index 38759f4..b53b7bb 100644 --- a/src/main/java/pl/minecon724/giants/Main.java +++ b/src/main/java/pl/minecon724/giants/Main.java @@ -9,7 +9,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Random; -import org.apache.commons.lang.StringUtils; import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; @@ -71,10 +70,10 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { attackDamage = config.getDouble("attackDamage", 1.0D); attackReach = config.getDouble("attackReach", 2D); expandUp = config.getDouble("expandUp", 0D); - for (Object s : config.getList("effects", new ArrayList())) { + for (Object o : config.getList("effects", new ArrayList())) { try { - String[] parts = ((String) s).split(":"); - if (!(StringUtils.isNumeric(parts[1]))) { + String[] parts = ((String) o).split(":"); + if (!isNumeric(parts[1])) { throw new IllegalArgumentException(parts[1] + " is not a number"); } PotionEffectType effectType = PotionEffectType.getByName(parts[0]); @@ -84,20 +83,19 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { Integer duration = Integer.valueOf(parts[1]); effects.put(effectType, duration); } catch (Exception e) { - Bukkit.getLogger().severe("Exception while parsing " + s); + Bukkit.getLogger().severe("Exception while parsing " + o); e.printStackTrace(); continue; } } - for (Object s : config.getList("drops", new ArrayList())) { + for (Object o : config.getList("drops", new ArrayList())) { try { - String[] parts = ((String) s).split(":"); - /* - TODO find a better way to do this - if (!(StringUtils.isNumeric(parts[1]))) { - throw new IllegalArgumentException(parts[1] + " is not a number"); + String[] parts = ((String) o).split(":"); + for (String s : parts) { + if (!isNumeric(s)) { + throw new IllegalArgumentException(parts[1] + " is not a number"); + } } - */ Material material = Material.getMaterial(parts[0]); if (material == null) { throw new IllegalArgumentException(parts[0] + " is not a Material"); @@ -108,7 +106,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { data.add(Integer.parseInt(parts[3])); drops.put(material, data); } catch (Exception e) { - Bukkit.getLogger().severe("Exception while parsing " + s); + Bukkit.getLogger().severe("Exception while parsing " + o); e.printStackTrace(); continue; } @@ -198,6 +196,7 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { passenger.setInvulnerable(true); passenger.setPersistent(true); passenger.setMetadata("giant", new FixedMetadataValue(this, "y")); + passenger.setHealth(Integer.MAX_VALUE); entity.addPassenger(passenger); } for (Entry t : effects.entrySet()) { @@ -207,4 +206,17 @@ public class Main extends JavaPlugin implements Listener, CommandExecutor { giants.add(entity); return entity; } + + // sorry + public static boolean isNumeric(String strNum) { + if (strNum == null) { + return false; + } + try { + double d = Double.parseDouble(strNum); + } catch (NumberFormatException nfe) { + return false; + } + return true; + } }