diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index 5320bfd..df45dd7 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -24,6 +24,7 @@ import com.garbagemule.MobArena.repairable.RepairableComparator; import com.garbagemule.MobArena.repairable.RepairableContainer; import com.garbagemule.MobArena.things.InvalidThingInputString; import com.garbagemule.MobArena.things.Thing; +import com.garbagemule.MobArena.things.ThingPicker; import com.garbagemule.MobArena.util.ClassChests; import com.garbagemule.MobArena.util.inventory.InventoryManager; import com.garbagemule.MobArena.util.timer.AutoStartTimer; @@ -121,7 +122,7 @@ public class ArenaImpl implements Arena private WaveManager waveManager; private MASpawnThread spawnThread; private SheepBouncer sheepBouncer; - private Map> everyWaveMap, afterWaveMap; + private Map everyWaveMap, afterWaveMap; // Misc private ArenaListener eventListener; @@ -337,12 +338,12 @@ public class ArenaImpl implements Arena } @Override - public Set>> getEveryWaveEntrySet() { + public Set> getEveryWaveEntrySet() { return everyWaveMap.entrySet(); } @Override - public List getAfterWaveReward(int wave) { + public ThingPicker getAfterWaveReward(int wave) { return afterWaveMap.get(wave); } diff --git a/src/main/java/com/garbagemule/MobArena/MASpawnThread.java b/src/main/java/com/garbagemule/MobArena/MASpawnThread.java index 7ed300f..7b5d07a 100644 --- a/src/main/java/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/main/java/com/garbagemule/MobArena/MASpawnThread.java @@ -8,6 +8,7 @@ import com.garbagemule.MobArena.healthbar.HealthBar; import com.garbagemule.MobArena.region.ArenaRegion; import com.garbagemule.MobArena.things.ExperienceThing; import com.garbagemule.MobArena.things.Thing; +import com.garbagemule.MobArena.things.ThingPicker; import com.garbagemule.MobArena.waves.MABoss; import com.garbagemule.MobArena.waves.MACreature; import com.garbagemule.MobArena.waves.Wave; @@ -353,13 +354,13 @@ public class MASpawnThread implements Runnable } private void grantRewards(int wave) { - for (Map.Entry> entry : arena.getEveryWaveEntrySet()) { + for (Map.Entry entry : arena.getEveryWaveEntrySet()) { if (wave > 0 && wave % entry.getKey() == 0) { addReward(entry.getValue()); } } - List after = arena.getAfterWaveReward(wave); + ThingPicker after = arena.getAfterWaveReward(wave); if (after != null) { addReward(after); } @@ -388,9 +389,9 @@ public class MASpawnThread implements Runnable /** * Rewards all players with an item from the input String. */ - private void addReward(List rewards) { + private void addReward(ThingPicker picker) { for (Player p : arena.getPlayersInArena()) { - Thing reward = rewards.get(MobArena.random.nextInt(rewards.size())); + Thing reward = picker.pick(); rewardManager.addReward(p, reward); if (reward == null) { diff --git a/src/main/java/com/garbagemule/MobArena/MAUtils.java b/src/main/java/com/garbagemule/MobArena/MAUtils.java index 56a32ab..9650e3d 100644 --- a/src/main/java/com/garbagemule/MobArena/MAUtils.java +++ b/src/main/java/com/garbagemule/MobArena/MAUtils.java @@ -4,7 +4,10 @@ import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.framework.ArenaMaster; import com.garbagemule.MobArena.region.ArenaRegion; import com.garbagemule.MobArena.things.InvalidThingInputString; +import com.garbagemule.MobArena.things.RandomThingPicker; +import com.garbagemule.MobArena.things.SingleThingPicker; import com.garbagemule.MobArena.things.Thing; +import com.garbagemule.MobArena.things.ThingPicker; import com.garbagemule.MobArena.util.TextUtils; import org.bukkit.Location; import org.bukkit.Material; @@ -40,10 +43,10 @@ public class MAUtils * type of wave ("after" or "every") and the config-file. If * no keys exist in the config-file, an empty map is returned. */ - public static Map> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type) + public static Map getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type) { //String arenaPath = "arenas." + arena + ".rewards.waves."; - Map> result = new HashMap<>(); + Map result = new HashMap<>(); String typePath = "rewards.waves." + type; if (!config.contains(typePath)) return result; @@ -61,16 +64,17 @@ public class MAUtils String path = typePath + "." + wave; String rewards = config.getString(path); - List things = new ArrayList<>(); + List pickers = new ArrayList<>(); for (String reward : rewards.split(",")) { try { Thing thing = plugin.getThingManager().parse(reward.trim()); - things.add(thing); + ThingPicker picker = new SingleThingPicker(thing); + pickers.add(picker); } catch (InvalidThingInputString e) { throw new ConfigError("Failed to parse reward for wave " + wave + " in the '" + type + "' branch of arena " + arena + ": " + e.getInput()); } } - result.put(wave, things); + result.put(wave, new RandomThingPicker(pickers, MobArena.random)); } return result; } diff --git a/src/main/java/com/garbagemule/MobArena/framework/Arena.java b/src/main/java/com/garbagemule/MobArena/framework/Arena.java index 70e3a01..afaf7c9 100644 --- a/src/main/java/com/garbagemule/MobArena/framework/Arena.java +++ b/src/main/java/com/garbagemule/MobArena/framework/Arena.java @@ -15,6 +15,7 @@ import com.garbagemule.MobArena.leaderboards.Leaderboard; import com.garbagemule.MobArena.region.ArenaRegion; import com.garbagemule.MobArena.repairable.Repairable; import com.garbagemule.MobArena.things.Thing; +import com.garbagemule.MobArena.things.ThingPicker; import com.garbagemule.MobArena.util.inventory.InventoryManager; import com.garbagemule.MobArena.util.timer.AutoStartTimer; import com.garbagemule.MobArena.waves.WaveManager; @@ -65,9 +66,9 @@ public interface Arena List getEntryFee(); - Set>> getEveryWaveEntrySet(); + Set> getEveryWaveEntrySet(); - List getAfterWaveReward(int wave); + ThingPicker getAfterWaveReward(int wave); Set getPlayersInArena();