From 0c5f909d3a2bf61ebf64d9609869d839ba2098d7 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:21:18 +0200 Subject: [PATCH] Split Support Item / Missile Item --- src/de/steamwar/misslewars/Config.java | 8 +++-- src/de/steamwar/misslewars/items/Missile.java | 5 +++ .../misslewars/items/SpecialItem.java | 35 ++++++++++++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index 7807c6e..4e4ed04 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -48,9 +48,11 @@ public class Config { public static final int ShieldFlyTime; public static final int EndTime; - static{ + public static final double MissileChance; + + static { File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); - if(!configfile.exists()){ + if (!configfile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); Bukkit.shutdown(); } @@ -62,6 +64,8 @@ public class Config { ShieldFlyTime = config.getInt("ShieldFlyTime"); EndTime = config.getInt("EndTime"); + MissileChance = config.getDouble("MissileChance"); + ConfigurationSection arena = config.getConfigurationSection("Arena"); assert arena != null; ArenaMinX = arena.getInt("MinX"); diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index a1434d5..4b67021 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -161,6 +161,11 @@ public class Missile extends SpecialItem { return true; } + @Override + public boolean isMissile() { + return true; + } + public static void init(){ File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){ diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index bf131e6..6f6266e 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars.items; +import de.steamwar.misslewars.Config; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -30,14 +31,22 @@ public abstract class SpecialItem { private static final Random random = new Random(); - private static List items = new ArrayList<>(); + private static List supportItems = new ArrayList<>(); + private static List missileItems = new ArrayList<>(); - SpecialItem(){ - items.add(this); + SpecialItem() { + if (this.isMissile()) { + missileItems.add(this); + } else { + supportItems.add(this); + } } public abstract ItemStack getItem(); public abstract boolean handleUse(Player p); + public boolean isMissile() { + return false; + } public ItemStack createItem(Material material, String name, int amount) { ItemStack item = new ItemStack(material, amount); @@ -48,16 +57,26 @@ public abstract class SpecialItem { return item; } - public static boolean handleUse(ItemStack item, Player player){ - for(SpecialItem specialItem : items){ - if(item.isSimilar(specialItem.getItem())){ + public static boolean handleUse(ItemStack item, Player player) { + for (SpecialItem missileItem : missileItems) { + if (item.isSimilar(missileItem.getItem())) { + return missileItem.handleUse(player); + } + } + for (SpecialItem specialItem : supportItems) { + if (item.isSimilar(specialItem.getItem())) { return specialItem.handleUse(player); } } return false; } - public static ItemStack getRandomItem(){ - return items.get(random.nextInt(items.size())).getItem(); + public static ItemStack getRandomItem() { + if (random.nextDouble() > Config.MissileChance) { + return supportItems.get(random.nextInt(supportItems.size())).getItem(); + } else { + return missileItems.get(random.nextInt(missileItems.size())).getItem(); + } } + }