diff --git a/MobArena.jar b/MobArena.jar index 181b8c7..9fc61f3 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/bin/com/garbagemule/MobArena/AbstractArena.class b/bin/com/garbagemule/MobArena/AbstractArena.class new file mode 100644 index 0000000..53a08d1 Binary files /dev/null and b/bin/com/garbagemule/MobArena/AbstractArena.class differ diff --git a/bin/com/garbagemule/MobArena/Arena$1.class b/bin/com/garbagemule/MobArena/Arena$1.class new file mode 100644 index 0000000..93acaa2 Binary files /dev/null and b/bin/com/garbagemule/MobArena/Arena$1.class differ diff --git a/bin/com/garbagemule/MobArena/Arena$2.class b/bin/com/garbagemule/MobArena/Arena$2.class new file mode 100644 index 0000000..303d9dc Binary files /dev/null and b/bin/com/garbagemule/MobArena/Arena$2.class differ diff --git a/bin/com/garbagemule/MobArena/Arena$3.class b/bin/com/garbagemule/MobArena/Arena$3.class new file mode 100644 index 0000000..547ab96 Binary files /dev/null and b/bin/com/garbagemule/MobArena/Arena$3.class differ diff --git a/bin/com/garbagemule/MobArena/Arena$4.class b/bin/com/garbagemule/MobArena/Arena$4.class new file mode 100644 index 0000000..7b12807 Binary files /dev/null and b/bin/com/garbagemule/MobArena/Arena$4.class differ diff --git a/bin/com/garbagemule/MobArena/Arena.class b/bin/com/garbagemule/MobArena/Arena.class new file mode 100644 index 0000000..0a93d08 Binary files /dev/null and b/bin/com/garbagemule/MobArena/Arena.class differ diff --git a/bin/com/garbagemule/MobArena/ArenaListener.class b/bin/com/garbagemule/MobArena/ArenaListener.class new file mode 100644 index 0000000..2b8b0de Binary files /dev/null and b/bin/com/garbagemule/MobArena/ArenaListener.class differ diff --git a/bin/com/garbagemule/MobArena/ArenaLog.class b/bin/com/garbagemule/MobArena/ArenaLog.class new file mode 100644 index 0000000..ce6f336 Binary files /dev/null and b/bin/com/garbagemule/MobArena/ArenaLog.class differ diff --git a/bin/com/garbagemule/MobArena/ArenaMaster.class b/bin/com/garbagemule/MobArena/ArenaMaster.class new file mode 100644 index 0000000..dcadb28 Binary files /dev/null and b/bin/com/garbagemule/MobArena/ArenaMaster.class differ diff --git a/bin/com/garbagemule/MobArena/ArenaPlayer.class b/bin/com/garbagemule/MobArena/ArenaPlayer.class new file mode 100644 index 0000000..fb61099 Binary files /dev/null and b/bin/com/garbagemule/MobArena/ArenaPlayer.class differ diff --git a/bin/com/garbagemule/MobArena/EntityPosition.class b/bin/com/garbagemule/MobArena/EntityPosition.class new file mode 100644 index 0000000..c72ef1e Binary files /dev/null and b/bin/com/garbagemule/MobArena/EntityPosition.class differ diff --git a/bin/com/garbagemule/MobArena/Lobby.class b/bin/com/garbagemule/MobArena/Lobby.class new file mode 100644 index 0000000..6ea0ea7 Binary files /dev/null and b/bin/com/garbagemule/MobArena/Lobby.class differ diff --git a/bin/com/garbagemule/MobArena/MABlockListener.class b/bin/com/garbagemule/MobArena/MABlockListener.class new file mode 100644 index 0000000..9cf7d09 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MABlockListener.class differ diff --git a/bin/com/garbagemule/MobArena/MACommands$1.class b/bin/com/garbagemule/MobArena/MACommands$1.class new file mode 100644 index 0000000..f16e4a2 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MACommands$1.class differ diff --git a/bin/com/garbagemule/MobArena/MACommands.class b/bin/com/garbagemule/MobArena/MACommands.class new file mode 100644 index 0000000..b4ae3cc Binary files /dev/null and b/bin/com/garbagemule/MobArena/MACommands.class differ diff --git a/bin/com/garbagemule/MobArena/MAEntityListener.class b/bin/com/garbagemule/MobArena/MAEntityListener.class new file mode 100644 index 0000000..5f2b77f Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAEntityListener.class differ diff --git a/bin/com/garbagemule/MobArena/MAInventoryItem.class b/bin/com/garbagemule/MobArena/MAInventoryItem.class new file mode 100644 index 0000000..042cf79 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAInventoryItem.class differ diff --git a/bin/com/garbagemule/MobArena/MAListener$1.class b/bin/com/garbagemule/MobArena/MAListener$1.class new file mode 100644 index 0000000..75e5e85 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAListener$1.class differ diff --git a/bin/com/garbagemule/MobArena/MAListener.class b/bin/com/garbagemule/MobArena/MAListener.class new file mode 100644 index 0000000..2aa6d48 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAListener.class differ diff --git a/bin/com/garbagemule/MobArena/MAMessages$Msg.class b/bin/com/garbagemule/MobArena/MAMessages$Msg.class new file mode 100644 index 0000000..f4739d1 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAMessages$Msg.class differ diff --git a/bin/com/garbagemule/MobArena/MAMessages.class b/bin/com/garbagemule/MobArena/MAMessages.class new file mode 100644 index 0000000..d656679 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAMessages.class differ diff --git a/bin/com/garbagemule/MobArena/MAPlayerListener$1.class b/bin/com/garbagemule/MobArena/MAPlayerListener$1.class new file mode 100644 index 0000000..28b8ff2 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAPlayerListener$1.class differ diff --git a/bin/com/garbagemule/MobArena/MAPlayerListener.class b/bin/com/garbagemule/MobArena/MAPlayerListener.class new file mode 100644 index 0000000..072a7ae Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAPlayerListener.class differ diff --git a/bin/com/garbagemule/MobArena/MASpawnThread.class b/bin/com/garbagemule/MobArena/MASpawnThread.class new file mode 100644 index 0000000..1b17ce2 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MASpawnThread.class differ diff --git a/bin/com/garbagemule/MobArena/MAUtils.class b/bin/com/garbagemule/MobArena/MAUtils.class new file mode 100644 index 0000000..b0109f0 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MAUtils.class differ diff --git a/bin/com/garbagemule/MobArena/MobArena.class b/bin/com/garbagemule/MobArena/MobArena.class new file mode 100644 index 0000000..9de2775 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MobArena.class differ diff --git a/bin/com/garbagemule/MobArena/MobArenaHandler.class b/bin/com/garbagemule/MobArena/MobArenaHandler.class new file mode 100644 index 0000000..8e9e7ac Binary files /dev/null and b/bin/com/garbagemule/MobArena/MobArenaHandler.class differ diff --git a/bin/com/garbagemule/MobArena/MobArenaListener.class b/bin/com/garbagemule/MobArena/MobArenaListener.class new file mode 100644 index 0000000..36cfa60 Binary files /dev/null and b/bin/com/garbagemule/MobArena/MobArenaListener.class differ diff --git a/bin/com/garbagemule/MobArena/util/FileUtils$Libs.class b/bin/com/garbagemule/MobArena/util/FileUtils$Libs.class new file mode 100644 index 0000000..e56949d Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/FileUtils$Libs.class differ diff --git a/bin/com/garbagemule/MobArena/util/FileUtils.class b/bin/com/garbagemule/MobArena/util/FileUtils.class new file mode 100644 index 0000000..6a5c699 Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/FileUtils.class differ diff --git a/bin/com/garbagemule/MobArena/util/TextUtils.class b/bin/com/garbagemule/MobArena/util/TextUtils.class new file mode 100644 index 0000000..692f0de Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/TextUtils.class differ diff --git a/bin/com/garbagemule/MobArena/util/WaveUtils$1.class b/bin/com/garbagemule/MobArena/util/WaveUtils$1.class new file mode 100644 index 0000000..453805c Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/WaveUtils$1.class differ diff --git a/bin/com/garbagemule/MobArena/util/WaveUtils$2.class b/bin/com/garbagemule/MobArena/util/WaveUtils$2.class new file mode 100644 index 0000000..97c39dd Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/WaveUtils$2.class differ diff --git a/bin/com/garbagemule/MobArena/util/WaveUtils.class b/bin/com/garbagemule/MobArena/util/WaveUtils.class new file mode 100644 index 0000000..d1db0d1 Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/WaveUtils.class differ diff --git a/bin/com/garbagemule/MobArena/util/data/PlainText.class b/bin/com/garbagemule/MobArena/util/data/PlainText.class new file mode 100644 index 0000000..35a2169 Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/data/PlainText.class differ diff --git a/bin/com/garbagemule/MobArena/util/data/Totals.class b/bin/com/garbagemule/MobArena/util/data/Totals.class new file mode 100644 index 0000000..97d116a Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/data/Totals.class differ diff --git a/bin/com/garbagemule/MobArena/util/data/XML.class b/bin/com/garbagemule/MobArena/util/data/XML.class new file mode 100644 index 0000000..2af1485 Binary files /dev/null and b/bin/com/garbagemule/MobArena/util/data/XML.class differ diff --git a/bin/com/garbagemule/MobArena/waves/AbstractWave.class b/bin/com/garbagemule/MobArena/waves/AbstractWave.class new file mode 100644 index 0000000..c6f3156 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/AbstractWave.class differ diff --git a/bin/com/garbagemule/MobArena/waves/BossWave.class b/bin/com/garbagemule/MobArena/waves/BossWave.class new file mode 100644 index 0000000..c954ea8 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/BossWave.class differ diff --git a/bin/com/garbagemule/MobArena/waves/DefaultWave.class b/bin/com/garbagemule/MobArena/waves/DefaultWave.class new file mode 100644 index 0000000..29b2312 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/DefaultWave.class differ diff --git a/bin/com/garbagemule/MobArena/waves/RecurrentWave.class b/bin/com/garbagemule/MobArena/waves/RecurrentWave.class new file mode 100644 index 0000000..e3e3f52 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/RecurrentWave.class differ diff --git a/bin/com/garbagemule/MobArena/waves/SingleWave.class b/bin/com/garbagemule/MobArena/waves/SingleWave.class new file mode 100644 index 0000000..e564eab Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/SingleWave.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$BossAbility.class b/bin/com/garbagemule/MobArena/waves/Wave$BossAbility.class new file mode 100644 index 0000000..a8af6e1 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$BossAbility.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$BossHealth.class b/bin/com/garbagemule/MobArena/waves/Wave$BossHealth.class new file mode 100644 index 0000000..587a69f Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$BossHealth.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$SwarmAmount.class b/bin/com/garbagemule/MobArena/waves/Wave$SwarmAmount.class new file mode 100644 index 0000000..cd7e573 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$SwarmAmount.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$WaveBranch.class b/bin/com/garbagemule/MobArena/waves/Wave$WaveBranch.class new file mode 100644 index 0000000..a8a51a5 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$WaveBranch.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$WaveGrowth.class b/bin/com/garbagemule/MobArena/waves/Wave$WaveGrowth.class new file mode 100644 index 0000000..0c54741 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$WaveGrowth.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave$WaveType.class b/bin/com/garbagemule/MobArena/waves/Wave$WaveType.class new file mode 100644 index 0000000..b5b16d1 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave$WaveType.class differ diff --git a/bin/com/garbagemule/MobArena/waves/Wave.class b/bin/com/garbagemule/MobArena/waves/Wave.class new file mode 100644 index 0000000..4190499 Binary files /dev/null and b/bin/com/garbagemule/MobArena/waves/Wave.class differ diff --git a/bin/com/garbagemule/register/payment/Method$MethodAccount.class b/bin/com/garbagemule/register/payment/Method$MethodAccount.class new file mode 100644 index 0000000..9dbce6f Binary files /dev/null and b/bin/com/garbagemule/register/payment/Method$MethodAccount.class differ diff --git a/bin/com/garbagemule/register/payment/Method$MethodBankAccount.class b/bin/com/garbagemule/register/payment/Method$MethodBankAccount.class new file mode 100644 index 0000000..9a3f124 Binary files /dev/null and b/bin/com/garbagemule/register/payment/Method$MethodBankAccount.class differ diff --git a/bin/com/garbagemule/register/payment/Method.class b/bin/com/garbagemule/register/payment/Method.class new file mode 100644 index 0000000..e754386 Binary files /dev/null and b/bin/com/garbagemule/register/payment/Method.class differ diff --git a/bin/com/garbagemule/register/payment/Methods.class b/bin/com/garbagemule/register/payment/Methods.class new file mode 100644 index 0000000..789ffde Binary files /dev/null and b/bin/com/garbagemule/register/payment/Methods.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE$BOSEAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE$BOSEAccount.class new file mode 100644 index 0000000..02850a7 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE$BOSEAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE$BOSEBankAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE$BOSEBankAccount.class new file mode 100644 index 0000000..904d21d Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE$BOSEBankAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE.class b/bin/com/garbagemule/register/payment/methods/BOSE.class new file mode 100644 index 0000000..151360f Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEAccount.class new file mode 100644 index 0000000..a1daef4 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEBankAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEBankAccount.class new file mode 100644 index 0000000..36f1dca Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE6$BOSEBankAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE6.class b/bin/com/garbagemule/register/payment/methods/BOSE6.class new file mode 100644 index 0000000..545a2a1 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE6.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEAccount.class new file mode 100644 index 0000000..f752dbb Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEBankAccount.class b/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEBankAccount.class new file mode 100644 index 0000000..66d8a29 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE7$BOSEBankAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/BOSE7.class b/bin/com/garbagemule/register/payment/methods/BOSE7.class new file mode 100644 index 0000000..5b618fe Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/BOSE7.class differ diff --git a/bin/com/garbagemule/register/payment/methods/EE17$EEcoAccount.class b/bin/com/garbagemule/register/payment/methods/EE17$EEcoAccount.class new file mode 100644 index 0000000..aa0f3e4 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/EE17$EEcoAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/EE17.class b/bin/com/garbagemule/register/payment/methods/EE17.class new file mode 100644 index 0000000..b12b788 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/EE17.class differ diff --git a/bin/com/garbagemule/register/payment/methods/iCo4$iCoAccount.class b/bin/com/garbagemule/register/payment/methods/iCo4$iCoAccount.class new file mode 100644 index 0000000..445e792 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/iCo4$iCoAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/iCo4.class b/bin/com/garbagemule/register/payment/methods/iCo4.class new file mode 100644 index 0000000..329ef90 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/iCo4.class differ diff --git a/bin/com/garbagemule/register/payment/methods/iCo5$iCoAccount.class b/bin/com/garbagemule/register/payment/methods/iCo5$iCoAccount.class new file mode 100644 index 0000000..a1e3c09 Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/iCo5$iCoAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/iCo5$iCoBankAccount.class b/bin/com/garbagemule/register/payment/methods/iCo5$iCoBankAccount.class new file mode 100644 index 0000000..666ab2f Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/iCo5$iCoBankAccount.class differ diff --git a/bin/com/garbagemule/register/payment/methods/iCo5.class b/bin/com/garbagemule/register/payment/methods/iCo5.class new file mode 100644 index 0000000..ad7ef6b Binary files /dev/null and b/bin/com/garbagemule/register/payment/methods/iCo5.class differ diff --git a/src/com/garbagemule/MobArena/Arena.java b/src/com/garbagemule/MobArena/Arena.java index 77bb2c6..d255009 100644 --- a/src/com/garbagemule/MobArena/Arena.java +++ b/src/com/garbagemule/MobArena/Arena.java @@ -5,6 +5,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -76,7 +77,7 @@ public class Arena // Arena sets/maps protected Set hasPaid, rewardedPlayers, notifyPlayers, randoms; - protected Set monsters; + protected Set monsters, explodingSheep, plaguedPigs, madCows; protected Set blocks; protected Set pets; protected Map petMap; @@ -117,6 +118,9 @@ public class Arena rewardedPlayers = new HashSet(); hasPaid = new HashSet(); monsters = new HashSet(); + explodingSheep = new HashSet(); + plaguedPigs = new HashSet(); + madCows = new HashSet(); blocks = new HashSet(); pets = new HashSet(); petMap = new HashMap(); @@ -259,7 +263,6 @@ public class Arena lobbyPlayers.clear(); readyPlayers.clear(); - //rewardMap.clear(); monsters.clear(); spawnTaskId = -1; @@ -292,7 +295,7 @@ public class Arena MAUtils.clearInventory(p); restoreInvAndGiveRewards(p); - if (log.players.get(p) != null) log.players.get(p).lastWave = spawnThread.wave - 1; + if (log.players.get(p) != null) log.players.get(p).lastWave = spawnThread.getWave() - 1; movePlayerToEntry(p); finishWithPlayer(p); endArena(); @@ -302,7 +305,7 @@ public class Arena { MAUtils.clearInventory(p); restoreInvAndGiveRewards(p); - log.players.get(p).lastWave = spawnThread.wave - 1; + log.players.get(p).lastWave = spawnThread.getWave() - 1; if (specOnDeath) { @@ -368,7 +371,7 @@ public class Arena // Stop the spawn thread. if (spawnThread != null) { - Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId); + Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId()); Bukkit.getServer().getScheduler().cancelTask(spawnTaskId); spawnTaskId = -1; spawnThread = null; @@ -544,6 +547,9 @@ public class Arena removePets(); removeEntities(); monsters.clear(); + explodingSheep.clear(); + plaguedPigs.clear(); + madCows.clear(); blocks.clear(); pets.clear(); } @@ -552,6 +558,12 @@ public class Arena { for (LivingEntity e : monsters) e.remove(); + for (LivingEntity e : explodingSheep) + e.remove(); + for (LivingEntity e : plaguedPigs) + e.remove(); + for (LivingEntity e : madCows) + e.remove(); } private void removeBlocks() @@ -653,16 +665,15 @@ public class Arena spawnpoints = MAUtils.getArenaSpawnpoints(config, world, configName); // NEW WAVES - singleWaves = WaveUtils.getWaves(config, configName, WaveBranch.SINGLE); - recurrentWaves = WaveUtils.getWaves(config, configName, WaveBranch.RECURRENT); + singleWaves = WaveUtils.getWaves(this, config, WaveBranch.SINGLE); + recurrentWaves = WaveUtils.getWaves(this, config, WaveBranch.RECURRENT); System.out.println(); System.out.println("ARENA: " + configName); System.out.println("Single waves"); - int si = singleWaves.size(); - for (int i = 0; i < si; i++) - System.out.println("- " + singleWaves.pollFirst()); + for (Wave w : singleWaves) + System.out.println("- " + w); System.out.println("Reccurent waves"); for (Wave w : recurrentWaves) System.out.println("- " + w); @@ -854,6 +865,31 @@ public class Arena return name; } + public World getWorld() + { + return world; + } + + public List getClasses() + { + return classes; + } + + public Collection getSpawnpoints() + { + return spawnpoints.values(); + } + + public int getPlayerCount() + { + return spawnThread.getPlayerCount(); + } + + public void addMonster(LivingEntity e) + { + monsters.add(e); + } + public List getAllPlayers() { List result = new LinkedList(); @@ -884,9 +920,9 @@ public class Arena return; // Reset the previousSize, cancel the previous timer, and start the new timer. - spawnThread.previousSize = monsters.size(); - Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId); - spawnThread.taskId = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, + spawnThread.setPreviousSize(monsters.size()); + Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId()); + int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() @@ -898,7 +934,7 @@ public class Arena monsters.remove(e); // Compare the current size with the previous size. - if (monsters.size() < spawnThread.previousSize || spawnThread.previousSize == 0) + if (monsters.size() < spawnThread.getPreviousSize() || spawnThread.getPreviousSize() == 0) { resetIdleTimer(); return; @@ -914,6 +950,7 @@ public class Arena } } }, maxIdleTime); + spawnThread.setTaskId(id); } public void addTrunkAndLeaves(Block b) @@ -1017,12 +1054,7 @@ public class Arena MAUtils.giveItems(p, entryFee, false, plugin); hasPaid.remove(p); } - - public List getClasses() - { - return classes; - } - + /** * The "perfect equals method" cf. "Object-Oriented Design and Patterns" * by Cay S. Horstmann. diff --git a/src/com/garbagemule/MobArena/ArenaLog.java b/src/com/garbagemule/MobArena/ArenaLog.java index f7f0288..723a6fa 100644 --- a/src/com/garbagemule/MobArena/ArenaLog.java +++ b/src/com/garbagemule/MobArena/ArenaLog.java @@ -40,7 +40,7 @@ public class ArenaLog public void end() { - lastWave = arena.spawnThread.wave - 1; + lastWave = arena.spawnThread.getWave() - 1; endTime = new Timestamp((new Date()).getTime()); } diff --git a/src/com/garbagemule/MobArena/MASpawnThread.java b/src/com/garbagemule/MobArena/MASpawnThread.java index 08264d0..d9eb482 100644 --- a/src/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/com/garbagemule/MobArena/MASpawnThread.java @@ -5,27 +5,19 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import org.bukkit.Location; -import org.bukkit.entity.Wolf; -import org.bukkit.entity.Ghast; -import org.bukkit.entity.Slime; import org.bukkit.entity.Creeper; import org.bukkit.entity.Player; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.CreatureType; import org.bukkit.inventory.ItemStack; import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.util.WaveUtils; -import com.garbagemule.MobArena.waves.RecurrentWave; -import com.garbagemule.MobArena.waves.SingleWave; import com.garbagemule.MobArena.waves.Wave; /** @@ -38,26 +30,28 @@ import com.garbagemule.MobArena.waves.Wave; */ public class MASpawnThread implements Runnable { - protected int wave, previousSize, taskId; - private int ran, noOfPlayers, modulo; - private int dZombies, dSkeletons, dSpiders, dCreepers, dWolves; - private int dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts; - private Random random; private MobArena plugin; private Arena arena; + private int wave, taskId, previousSize, playerCount; // NEW WAVES - /* Single waves are waves with a frequency of 0, and they only - * spawn once. Their priority is infinity, meaning they will always - * spawn instead of recurrent waves, if the wave numbers clash. */ private Wave defaultWave; - private TreeSet singleWaves; - private TreeSet recurrentWaves; + private TreeSet recurrentWaves; + private TreeSet singleWaves; public MASpawnThread(MobArena plugin, Arena arena) { - this.plugin = plugin; - this.arena = arena; + // WAVES + defaultWave = arena.recurrentWaves.first(); + recurrentWaves = arena.recurrentWaves; + singleWaves = arena.singleWaves; + + this.plugin = plugin; + this.arena = arena; + wave = 1; + playerCount = arena.arenaPlayers.size(); + + /* modulo = arena.specialModulo; if (modulo <= 0) modulo = -32768; @@ -84,9 +78,10 @@ public class MASpawnThread implements Runnable dGiants = dAngryWolves + arena.distSpecial.get("giants"); dGhasts = dGiants + arena.distSpecial.get("ghasts"); if (dGhasts < 1) { dPoweredCreepers = 1; dPigZombies = 2; dSlimes = 3; dMonsters = 4; dAngryWolves = 5; dGiants = 5; dGhasts = 5; } + */ } - public void run2() + public void run() { // Clear out all dead monsters in the monster set. removeDeadMonsters(); @@ -132,7 +127,7 @@ public class MASpawnThread implements Runnable } private void spawnWave(int wave) - { + { Wave w = null; // Check the first element of the single waves. @@ -145,23 +140,10 @@ public class MASpawnThread implements Runnable else { SortedSet matches = getMatchingRecurrentWaves(wave); - - if (matches.isEmpty()) - w = defaultWave; - else - w = matches.last(); + w = matches.isEmpty() ? defaultWave : matches.last(); } - w.spawn(wave, arena.spawnpoints.values()); - /* - // Otherwise, check the recurrent waves. - SortedSet matches = getMatchingRecurrentWaves(wave); - - if (matches.isEmpty()) - defaultWave.spawn(wave, arena.spawnpoints.values()); - else - matches.last().spawn(wave, arena.spawnpoints.values()); - */ + w.spawn(wave); } private SortedSet getMatchingRecurrentWaves(int wave) @@ -177,7 +159,46 @@ public class MASpawnThread implements Runnable return result; } - public void run() + + + /*//////////////////////////////////////////////////////////////////// + // + // Getters/setters + // + ////////////////////////////////////////////////////////////////////*/ + + public int getWave() + { + return wave; + } + + public int getTaskId() + { + return taskId; + } + + public int getPreviousSize() + { + return previousSize; + } + + public int getPlayerCount() + { + return playerCount; + } + + public void setTaskId(int taskId) + { + this.taskId = taskId; + } + + public void setPreviousSize(int previousSize) + { + this.previousSize = previousSize; + } + + /* + public void run1() { if (arena.arenaPlayers.isEmpty()) return; @@ -228,6 +249,7 @@ public class MASpawnThread implements Runnable wave++; if (arena.maxIdleTime > 0 && arena.monsters.isEmpty()) arena.resetIdleTimer(); } + */ /** * Rewards all players with an item from the input String. @@ -238,12 +260,9 @@ public class MASpawnThread implements Runnable { if (arena.log.players.get(p) == null) continue; - /*if (arena.rewardMap.get(p) == null) - continue;*/ ItemStack reward = MAUtils.getRandomReward(rewards); arena.log.players.get(p).rewards.add(reward); - //arena.rewardMap.get(p).add(reward); if (reward == null) { @@ -266,7 +285,7 @@ public class MASpawnThread implements Runnable /** * Spawns a default wave of monsters. */ - private void defaultWave() + /*private void defaultWave() { Location loc; List spawnpoints = getValidSpawnpoints(); @@ -283,7 +302,7 @@ public class MASpawnThread implements Runnable * we're able to evaluate the random number in this way. * If dSpiders = 0, then dSpiders = dSkeletons, which * means if the random number is below that value, we will - * spawn a skeleton and break out of the statement. */ + * spawn a skeleton and break out of the statement. */ /* if (ran < dZombies) mob = CreatureType.ZOMBIE; else if (ran < dSkeletons) mob = CreatureType.SKELETON; else if (ran < dSpiders) mob = CreatureType.SPIDER; @@ -301,12 +320,12 @@ public class MASpawnThread implements Runnable Creature c = (Creature) e; c.setTarget(getClosestPlayer(e)); } - } + }*/ /** * Spawns a special wave of monsters. */ - private void specialWave() + /*private void specialWave() { Location loc; List spawnpoints = getValidSpawnpoints(); @@ -389,7 +408,7 @@ public class MASpawnThread implements Runnable // Lightning, just for effect ;) for (Location spawn : arena.spawnpoints.values()) arena.world.strikeLightningEffect(spawn); - } + }*/ /** * "Detonates" all the Creepers in the monsterSet. diff --git a/src/com/garbagemule/MobArena/MobArena.java b/src/com/garbagemule/MobArena/MobArena.java index 0b9a1a4..ccfd58f 100644 --- a/src/com/garbagemule/MobArena/MobArena.java +++ b/src/com/garbagemule/MobArena/MobArena.java @@ -105,6 +105,7 @@ public class MobArena extends JavaPlugin config = new Configuration(file); config.load(); + config.setHeader(header()); } private void registerListeners() @@ -178,4 +179,12 @@ public class MobArena extends JavaPlugin public Configuration getConfig() { return config; } public ArenaMaster getAM() { return am; } // More convenient. public ArenaMaster getArenaMaster() { return am; } + + private String header() + { + String sep = System.getProperty("line.separator"); + return "# MobArena v" + desc.getVersion() + " - Config-file" + sep + + "# Read the Wiki for details on how to set up this file: http://goo.gl/F5TTc" + sep + + "# Note: You -must- use spaces instead of tabs!"; + } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/util/WaveUtils.java b/src/com/garbagemule/MobArena/util/WaveUtils.java index ef603a8..4bac3a7 100644 --- a/src/com/garbagemule/MobArena/util/WaveUtils.java +++ b/src/com/garbagemule/MobArena/util/WaveUtils.java @@ -8,20 +8,15 @@ import java.util.TreeSet; import org.bukkit.Location; import org.bukkit.entity.CreatureType; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.config.Configuration; +import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MobArena; -import com.garbagemule.MobArena.waves.RecurrentWave; -import com.garbagemule.MobArena.waves.SingleWave; -import com.garbagemule.MobArena.waves.Wave; -import com.garbagemule.MobArena.waves.Wave.BossAbility; -import com.garbagemule.MobArena.waves.Wave.BossHealth; -import com.garbagemule.MobArena.waves.Wave.SwarmAmount; -import com.garbagemule.MobArena.waves.Wave.WaveBranch; -import com.garbagemule.MobArena.waves.Wave.WaveGrowth; -import com.garbagemule.MobArena.waves.Wave.WaveType; +import com.garbagemule.MobArena.waves.*; +import com.garbagemule.MobArena.waves.Wave.*; public class WaveUtils { @@ -59,18 +54,49 @@ public class WaveUtils // Else, return the valid spawnpoints. return result; } + + + public static Player getClosestPlayer(Arena arena, Entity e) + { + // Set up the comparison variable and the result. + double dist = 0; + double current = Double.POSITIVE_INFINITY; + Player result = null; + + /* Iterate through the ArrayList, and update current and result every + * time a squared distance smaller than current is found. */ + //for (Player p : arena.livePlayers) + for (Player p : arena.getLivingPlayers()) + { + if (!arena.getWorld().equals(p.getWorld())) + { + System.out.println("[MobArena] Player '" + p.getName() + "' is not in the right world. Force leaving..."); + arena.playerLeave(p); + MAUtils.tellPlayer(p, "You warped out of the arena world."); + continue; + } + + dist = p.getLocation().distanceSquared(e.getLocation()); + if (dist < current && dist < MobArena.MIN_PLAYER_DISTANCE) + { + current = dist; + result = p; + } + } + return result; + } /** * Grab and process all the waves in the config-file for the arena. */ - public static TreeSet getWaves(Configuration config, String arena, WaveBranch branch) + public static TreeSet getWaves(Arena arena, Configuration config, WaveBranch branch) { // Determine the branch type of the wave, and grab the appropriate comparator String b = branch.toString().toLowerCase(); TreeSet result = new TreeSet(getComparator(branch)); // Grab the waves from the config-file - String path = "arenas." + arena + ".waves." + b; + String path = "arenas." + arena.configName() + ".waves." + b; // waves.yml, change to either "waves." + b, or simply b List waves = config.getKeys(path); // If there are any waves, process them @@ -80,7 +106,7 @@ public class WaveUtils for (String w : waves) { // path argument becomes: "arenas..waves..." - wave = getWave(config, path + "." + w + ".", w, branch); + wave = getWave(arena, config, path + "." + w + ".", w, branch); if (wave != null) result.add(wave); } } @@ -88,12 +114,12 @@ public class WaveUtils // If there are no waves and the type is 'recurrent', add a default wave. if (branch == WaveBranch.RECURRENT && (result.isEmpty() || waves == null)) { - RecurrentWave def = new RecurrentWave("DEF_WAVE_AUTO", 1, 1, 1); + /* + DefaultWave def = new DefaultWave(arena, "DEF_WAVE_AUTO", 1, 1, 1, null, null); def.setType(WaveType.DEFAULT); def.setGrowth(WaveGrowth.MEDIUM); - def.setDefault(true); - result.add(def); + */ } return result; @@ -103,9 +129,9 @@ public class WaveUtils * Get a single wave based on the config-file, the path, and branch * @return A Wave object if it is well defined, null otherwise. */ - private static Wave getWave(Configuration config, String path, String name, WaveBranch branch) + private static Wave getWave(Arena arena, Configuration config, String path, String name, WaveBranch branch) { - // Grab the wave type, if null, return null + // Grab the wave type, if null or not well defined, return null WaveType type = WaveType.fromString(config.getString(path + "type")); if (type == null || !isWaveWellDefined(config, path, branch, type)) return null; @@ -117,210 +143,26 @@ public class WaveUtils int frequency = config.getInt(path + "frequency", 0); int priority = config.getInt(path + "priority", 0); int wave = config.getInt(path + "wave", frequency); - result = new RecurrentWave(name, wave, frequency, priority); + + //if (type == WaveType.DEFAULT) + result = new DefaultWave(arena, name, wave, frequency, priority, config, path); + result.setGrowth(WaveGrowth.OLD); + //else + // result = new SpecialWave(arena, name, wave, frequency, priority, config, path); } else { int wave = config.getInt(path + "wave", 0); - result = new SingleWave(name, wave); - } - return result; - } - /* - public static RecurrentWave getRecurrentWave(Configuration config, String arena, String w) - { - // Grab the path - String path = "arenas." + arena + ".waves.recurrent." + w + "."; - - // Ensure that frequency and priority exist, otherwise return null - int frequency = config.getInt(path + "frequency", 0); - int priority = config.getInt(path + "priority", 0); - if (frequency == 0 || priority == 0) return null; - - // Grab other variables - int wave = config.getInt(path + "wave", frequency); - WaveType type = WaveType.fromString(config.getString(path + "type", "default")); - WaveGrowth growth = WaveGrowth.fromString(config.getString(path + "growth", "medium")); - - // Grab monster distribution - //Map monsters = getWaveMonsters(config, arena, path, type); - - // Create the wave - RecurrentWave result = new RecurrentWave(w, wave, frequency, priority, type, growth); - - - return result; - } - - public static SingleWave getSingleWave(Configuration config, String arena, String w) - { - // Grab the path - String path = "arenas." + arena + ".waves.single." + w + "."; - - // Ensure that the wave number exists, otherwise return null - int wave = config.getInt(path + "wave", 0); - if (wave == 0) return null; - - // Grab other variables - - SingleWave result = new SingleWave(w, wave); - - return result; - } - - public static Map getWaveMonsters(Configuration config, String arena, String path, String type) - { - Map result = new HashMap(); - - List monsters = config.getKeys(path + "monsters"); - - // If no monsters specified, make sure to add some - if (monsters == null) - { - if (type.equals("default")) - { - result.put(CreatureType.ZOMBIE, 10); - result.put(CreatureType.SKELETON, 10); - result.put(CreatureType.SPIDER, 10); - result.put(CreatureType.CREEPER, 10); - result.put(CreatureType.WOLF, 10); - } - else if (type.equals("default")) - { - - } - } - - return result; - } - */ - - - /*//////////////////////////////////////////////////////////////////// - // - // Comparators - // - ////////////////////////////////////////////////////////////////////*/ - - /** - * Get a comparator based on the WaveBranch parameter. - */ - public static Comparator getComparator(WaveBranch branch) - { - if (branch == WaveBranch.SINGLE) - return getSingleComparator(); - else if (branch == WaveBranch.RECURRENT) - return getRecurrentComparator(); - else - return null; - } - - /** - * Get a Comparator that compares Wave objects by wave number. - * If the wave numbers are equal, the waves are equal. This is to - * DISALLOW "duplicates" in the SINGLE WAVES collection. - * @return Comparator whose compare()-method compares wave numbers. - */ - public static Comparator getSingleComparator() - { - return new Comparator() - { - public int compare(Wave w1, Wave w2) - { - if (w1.getWave() < w2.getWave()) - return -1; - else if (w1.getWave() > w2.getWave()) - return 1; - else return 0; - } - }; - } - - /** - * Get a Comparator that compares Wave objects by priority. - * If the priorities are equal, the names are compared. This is to - * ALLOW "duplicates" in the RECURRENT WAVES collection. - * @return Comparator whose compare()-method compares wave priorities. - */ - public static Comparator getRecurrentComparator() - { - return new Comparator() - { - public int compare(Wave w1, Wave w2) - { - if (w1.getPriority() < w2.getPriority()) - return -1; - else if (w1.getPriority() > w2.getPriority()) - return 1; - else return w1.getName().compareTo(w2.getName()); - } - }; - } - - /** - * Get all the single waves for the given arena. - */ - /*public static TreeSet getSingleWaves(Configuration config, String arena) - { - TreeSet result = new TreeSet(); - - List waves = config.getKeys("arenas." + arena + ".waves.single"); - if (waves != null) - { - int wave; - for (String w : waves) - { - wave = config.getInt("arenas." + arena + ".waves.single." + w + ".wave", 0); - if (wave == 0) continue; - result.add(new SingleWave(w, wave)); - } + //if (type == WaveType.DEFAULT) + result = new DefaultWave(arena, name, wave, config, path); + result.setGrowth(WaveGrowth.OLD); + //else + // result = new SpecialWave(arena, name, wave, config, path); } - return result; - }*/ + } - /** - * Get all the recurrent waves for the given arena. - * If no waves are found, a default wave is added. This ensures that - * the arena always has monsters spawning, regardless of how badly the - * user messes up the config-file. - */ - /*public static TreeSet getRecurrentWaves(Configuration config, String arena) - { - TreeSet result = new TreeSet(); - - List waves = config.getKeys("arenas." + arena + ".waves.recurrent"); - if (waves != null) - { - int wave, frequency, priority; - - for (String w : waves) - { - frequency = config.getInt("arenas." + arena + ".waves.recurrent." + w + ".frequency", 0); - priority = config.getInt("arenas." + arena + ".waves.recurrent." + w + ".priority", 0); - if (frequency == 0 || priority == 0) continue; - - wave = config.getInt("arenas." + arena + ".waves.single." + w + ".wave", frequency); - result.add(new RecurrentWave(w, wave, frequency, priority)); - } - } - else - { - RecurrentWave def = new RecurrentWave("DEF_WAVE_AUTO", 1, 1, 1); - def.setType(WaveType.DEFAULT); - def.setGrowth(WaveGrowth.MEDIUM); - - RecurrentWave spec = new RecurrentWave("SPEC_WAVE_AUTO", 4, 4, 4); - spec.setType(WaveType.SPECIAL); - - result.add(def); - result.add(spec); - } - - return result; - }*/ - /*//////////////////////////////////////////////////////////////////// @@ -407,7 +249,8 @@ public class WaveUtils for (String monster : monsters) { - if (getEnumFromString(CreatureType.class, monster) != null) + //if (getEnumFromString(CreatureType.class, monster) != null) + if (getEnumFromString(MACreature.class, monster) != null) continue; MAUtils.error("Invalid monster type '" + monster + "' in " + path); @@ -491,7 +334,70 @@ public class WaveUtils return true; } - + + + + /*//////////////////////////////////////////////////////////////////// + // + // Comparators + // + ////////////////////////////////////////////////////////////////////*/ + + /** + * Get a comparator based on the WaveBranch parameter. + */ + public static Comparator getComparator(WaveBranch branch) + { + if (branch == WaveBranch.SINGLE) + return getSingleComparator(); + else if (branch == WaveBranch.RECURRENT) + return getRecurrentComparator(); + else + return null; + } + + /** + * Get a Comparator that compares Wave objects by wave number. + * If the wave numbers are equal, the waves are equal. This is to + * DISALLOW "duplicates" in the SINGLE WAVES collection. + * @return Comparator whose compare()-method compares wave numbers. + */ + public static Comparator getSingleComparator() + { + return new Comparator() + { + public int compare(Wave w1, Wave w2) + { + if (w1.getWave() < w2.getWave()) + return -1; + else if (w1.getWave() > w2.getWave()) + return 1; + else return 0; + } + }; + } + + /** + * Get a Comparator that compares Wave objects by priority. + * If the priorities are equal, the names are compared. This is to + * ALLOW "duplicates" in the RECURRENT WAVES collection. + * @return Comparator whose compare()-method compares wave priorities. + */ + public static Comparator getRecurrentComparator() + { + return new Comparator() + { + public int compare(Wave w1, Wave w2) + { + if (w1.getPriority() < w2.getPriority()) + return -1; + else if (w1.getPriority() > w2.getPriority()) + return 1; + else return w1.getName().compareTo(w2.getName()); + } + }; + } + /*//////////////////////////////////////////////////////////////////// diff --git a/src/com/garbagemule/MobArena/waves/AbstractWave.java b/src/com/garbagemule/MobArena/waves/AbstractWave.java index b34d548..f4e86cb 100644 --- a/src/com/garbagemule/MobArena/waves/AbstractWave.java +++ b/src/com/garbagemule/MobArena/waves/AbstractWave.java @@ -1,64 +1,96 @@ package com.garbagemule.MobArena.waves; +import org.bukkit.World; + +import com.garbagemule.MobArena.Arena; + public abstract class AbstractWave implements Wave { - private String name; + private Arena arena; + private World world; + private String waveName; private int wave, frequency, priority; + private WaveBranch branch; private WaveType type; private WaveGrowth growth; /** * Basic wave constructor. - * Constructs a wave with an initial wave number, a wave frequency, and - * a wave priority. + * @param name The config-file identifier * @param wave Initial wave number. This is the first wave number this wave can spawn at. * @param frequency How often the wave can spawn. * @param priority The priority of the wave. - */ - public AbstractWave(String name, int wave, int frequency, int priority) + * @param branch The branch type (single, recurrent) + */ + public AbstractWave(Arena arena, String waveName, int wave, int frequency, int priority, WaveBranch branch) { - this.name = name; - this.wave = wave; - this.frequency = frequency; - this.priority = priority; + this.arena = arena; + this.world = arena.getWorld(); + this.waveName = waveName; + this.wave = wave; + this.frequency = frequency; + this.priority = priority; + this.branch = branch; } - - /** - * Default wave constructor. - * Constructs a basic wave with additional information in the type of - * wave and the wave growth. - * @param wave Initial wave number. This is the first wave number this wave can spawn at. - * @param frequency How often the wave can spawn. - * @param priority The priority of the wave. - * @param type The type of wave. - * @param growth The growth rate of the wave. - */ - public AbstractWave(String name, int wave, int frequency, int priority, WaveType type, WaveGrowth growth) + + // Default recurrent wave constructor + public AbstractWave(Arena arena, String name, int wave, int frequency, int priority) { - this(name, wave, frequency, priority); - this.type = type; - this.growth = growth; + this(arena, name, wave, frequency, priority, WaveBranch.RECURRENT); + } + + // Default single wave constructor + public AbstractWave(Arena arena, String name, int wave) + { + this(arena, name, wave, 0, 0, WaveBranch.SINGLE); + } + + /** + * Check if a wave matches a wave number. + * SINGLE WAVES match, if their wave number is the same as the + * parameter. + * RECURRENT WAVES match, if their wave number subtracted from + * the parameter divides the frequency. The wave number must be + * greater than or equal to the parameter. + * @param wave The wave number to compare + * @return true, if the wave matches the wave number + */ + public boolean matches(int wave) + { + if (branch == WaveBranch.SINGLE) + return this.wave == wave; + + if (branch == WaveBranch.RECURRENT && wave >= this.wave) + return ((wave - this.wave) % frequency == 0); + + return false; + } + + // GETTERS + public Arena getArena() + { + return arena; + } + + public World getWorld() + { + return world; + } + + public WaveBranch getBranch() + { + return branch; } public WaveType getType() { return type; } - - public void setType(WaveType type) - { - this.type = type; - } public WaveGrowth getGrowth() { return growth; } - - public void setGrowth(WaveGrowth growth) - { - this.growth = growth; - } public int getWave() { @@ -77,12 +109,29 @@ public abstract class AbstractWave implements Wave public String getName() { - return name; + return waveName; + } + + // SETTERS + public void setBranch(WaveBranch branch) + { + this.branch = branch; } + public void setType(WaveType type) + { + this.type = type; + } + + public void setGrowth(WaveGrowth growth) + { + this.growth = growth; + } + + // MISC public String toString() { - return "[name=" + name + + return "[name=" + waveName + ", wave=" + wave + ", frequency=" + frequency + ", priority=" + priority + "]"; diff --git a/src/com/garbagemule/MobArena/waves/BossWave.java b/src/com/garbagemule/MobArena/waves/BossWave.java index 3552363..a0a2507 100644 --- a/src/com/garbagemule/MobArena/waves/BossWave.java +++ b/src/com/garbagemule/MobArena/waves/BossWave.java @@ -1,12 +1,14 @@ package com.garbagemule.MobArena.waves; +import java.util.Collection; import java.util.Set; +import org.bukkit.Location; import org.bukkit.entity.Creature; import com.garbagemule.MobArena.waves.Wave.BossAbility; -public class BossWave +public class BossWave // TODO: implement/extend something? { private Creature boss; private Set abilities; @@ -32,4 +34,17 @@ public class BossWave { this.health = health; } + + public void spawn(int wave, Collection spawnpoints) + { + // Spawn boss and adds + // Something like this, perhaps? Pseudo-code + // LivingEntity b = spawnCreature(bossType, random location) + // boss = (Creature) b; + // boss.setHealth(health); + // for (String a : ablts) + // abilities.add(BossAbility.fromString(a)); + // for (int i = 0; i < addCount; i++) + // adds.add(spawnCreature(addType, bossLocation); + } } diff --git a/src/com/garbagemule/MobArena/waves/DefaultWave.java b/src/com/garbagemule/MobArena/waves/DefaultWave.java new file mode 100644 index 0000000..8eba3c3 --- /dev/null +++ b/src/com/garbagemule/MobArena/waves/DefaultWave.java @@ -0,0 +1,99 @@ +package com.garbagemule.MobArena.waves; + +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.TreeMap; + +import org.bukkit.Location; +import org.bukkit.entity.Creature; +import org.bukkit.entity.LivingEntity; +import org.bukkit.util.config.Configuration; + +import com.garbagemule.MobArena.Arena; +import com.garbagemule.MobArena.util.WaveUtils; + +public class DefaultWave extends AbstractWave +{ + private int totalProbability = 0; + private Map probabilities = new TreeMap(); + + // Recurrent + public DefaultWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) + { + super(arena, name, wave, frequency, priority); + load(config, path); + } + + // Single + public DefaultWave(Arena arena, String name, int wave, Configuration config, String path) + { + super(arena, name, wave); + load(config, path); + } + + /** + * Prepare the wave for spawning by initializing the variables and + * populating the collections needed. + * @param config The config-file + * @param path The absolute path of the wave + */ + public void load(Configuration config, String path) + { + // Extract the monster probabilities and calculate the sum + totalProbability = 0; + int prob; + for (String m : config.getKeys(path + "monsters")) + { + prob = config.getInt(path + "monsters." + m, 1); + totalProbability += prob; + probabilities.put(totalProbability, MACreature.fromString(m)); + } + } + + public void spawn(int wave) + { + // Get the valid spawnpoints, and initialize counter + List validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena().getSpawnpoints(), getArena().getLivingPlayers()); + int noOfSpawnpoints = validSpawnpoints.size(); + + // Initialize the total amount of mobs to spawn + int totalToSpawn = getGrowth().getAmount(wave, getArena().getPlayerCount()); + + // Allocate some variables + Random random = new Random(); + int randomNumber; + Location loc; + + // Spawn monsters + for (int i = 0; i < totalToSpawn; i++) + { + // Grab the next location. + loc = validSpawnpoints.get(i % noOfSpawnpoints); + + // Grab a random number. + randomNumber = random.nextInt(totalProbability); + + // Find the monster that corresponds to the random number, and spawn it + for (Map.Entry entry : probabilities.entrySet()) + { + if (randomNumber > entry.getKey()) continue; + + // Spawn and add to collection + LivingEntity e = entry.getValue().spawn(getWorld(), loc); + getArena().addMonster(e); + + // Grab a random target. + if (e instanceof Creature) + { + Creature c = (Creature) e; + c.setTarget(WaveUtils.getClosestPlayer(getArena(), e)); + } + + break; + } + } + + System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType()); + } +} diff --git a/src/com/garbagemule/MobArena/waves/MACreature.java b/src/com/garbagemule/MobArena/waves/MACreature.java new file mode 100644 index 0000000..d6a12eb --- /dev/null +++ b/src/com/garbagemule/MobArena/waves/MACreature.java @@ -0,0 +1,97 @@ +package com.garbagemule.MobArena.waves; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.CreatureType; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Wolf; + +import com.garbagemule.MobArena.util.WaveUtils; + +public enum MACreature +{ + // Default creatures + ZOMBIES(CreatureType.ZOMBIE), + SKELETONS(CreatureType.SKELETON), + SPIDERS(CreatureType.SPIDER), + CREEPERS(CreatureType.CREEPER), + WOLVES(CreatureType.WOLF), + + // Special creatures + ZOMBIE_PIGMEN(CreatureType.PIG_ZOMBIE), + POWERED_CREEPERS(CreatureType.CREEPER), + ANGRY_WOLVES(CreatureType.WOLF), + HUMANS(CreatureType.MONSTER), + SLIMES(CreatureType.SLIME), + GIANTS(CreatureType.GIANT), + GHASTS(CreatureType.GHAST); + + // Misc + // EXPLODING_SHEEP(CreatureType.SHEEP), // Explode (power: 1) when close enough to players + // PLAGUED_PIGS(CreatureType.PIG), // Damage "aura" (getNearbyEntities) + // MAD_COWS(CreatureType.COW); // Ram/throw players + // + + private CreatureType type; + + private MACreature(CreatureType type) + { + this.type = type; + } + + public CreatureType getType() + { + return type; + } + + public static MACreature fromString(String string) + { + return WaveUtils.getEnumFromString(MACreature.class, string); + } + + public LivingEntity spawn(World world, Location loc) + { + LivingEntity e = world.spawnCreature(loc, type); + + switch (this) + { + case POWERED_CREEPERS: + ((Creeper) e).setPowered(true); + break; + case ANGRY_WOLVES: + ((Wolf) e).setAngry(true); + break; + case SLIMES: + ((Slime) e).setSize(2); + break; + default: + break; + } + + return e; + } + + public static LivingEntity spawn(MACreature creature, World world, Location loc) + { + LivingEntity e = world.spawnCreature(loc, creature.type); + + switch (creature) + { + case POWERED_CREEPERS: + ((Creeper) e).setPowered(true); + break; + case ANGRY_WOLVES: + ((Wolf) e).setAngry(true); + break; + case SLIMES: + ((Slime) e).setSize(2); + break; + default: + break; + } + + return e; + } +} diff --git a/src/com/garbagemule/MobArena/waves/RecurrentWave.java b/src/com/garbagemule/MobArena/waves/RecurrentWave.java index c0d7201..dab265d 100644 --- a/src/com/garbagemule/MobArena/waves/RecurrentWave.java +++ b/src/com/garbagemule/MobArena/waves/RecurrentWave.java @@ -13,7 +13,7 @@ public class RecurrentWave extends AbstractWave public RecurrentWave(String name, int wave, int frequency, int priority, WaveType type, WaveGrowth growth) { - super(name, wave, frequency, priority, type, growth); + super(name, wave, frequency, priority, WaveBranch.RECURRENT, type, growth); } public void spawn(int wave, Collection spawnpoints) @@ -28,7 +28,10 @@ public class RecurrentWave extends AbstractWave public boolean matches(int wave) { - return wave % getWave() + getFrequency() == 0; + if (wave < getWave()) + return false; + + return (wave - getWave()) % getFrequency() == 0; } /** @@ -36,6 +39,7 @@ public class RecurrentWave extends AbstractWave * If the priorities are equal, the names are compared. This is to * ALLOW "duplicates" in the RECURRENT WAVES collection. */ + /* public int compareTo(Wave w) { if (getPriority() < w.getPriority()) @@ -44,4 +48,5 @@ public class RecurrentWave extends AbstractWave return 1; else return getName().compareTo(w.getName()); } + */ } diff --git a/src/com/garbagemule/MobArena/waves/SingleWave.java b/src/com/garbagemule/MobArena/waves/SingleWave.java index 057217c..d37990e 100644 --- a/src/com/garbagemule/MobArena/waves/SingleWave.java +++ b/src/com/garbagemule/MobArena/waves/SingleWave.java @@ -9,6 +9,7 @@ public class SingleWave extends AbstractWave public SingleWave(String name, int wave) { super(name, wave, 0, 0); + setBranch(WaveBranch.SINGLE); } public void spawn(int wave, Collection spawnpoints) @@ -26,6 +27,7 @@ public class SingleWave extends AbstractWave * If the wave numbers are equal, the waves are equal. This is to * DISALLOW "duplicates" in the SINGLE WAVES collection. */ + /* public int compareTo(Wave w) { if (this.getWave() < w.getWave()) @@ -34,4 +36,5 @@ public class SingleWave extends AbstractWave return 1; else return 0; } + */ } diff --git a/src/com/garbagemule/MobArena/waves/SpecialWave.java b/src/com/garbagemule/MobArena/waves/SpecialWave.java new file mode 100644 index 0000000..4b98d58 --- /dev/null +++ b/src/com/garbagemule/MobArena/waves/SpecialWave.java @@ -0,0 +1,23 @@ +package com.garbagemule.MobArena.waves; + +import com.garbagemule.MobArena.Arena; + +public class SpecialWave extends AbstractWave +{ + // Recurrent + public SpecialWave(Arena arena, String name, int wave, int frequency, int priority) + { + super(arena, name, wave, frequency, priority); + } + + // Single + public SpecialWave(Arena arena, String name, int wave) + { + super(arena, name, wave); + } + + public void spawn(int wave) + { + System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType()); + } +} diff --git a/src/com/garbagemule/MobArena/waves/Wave.java b/src/com/garbagemule/MobArena/waves/Wave.java index 29913f2..157531e 100644 --- a/src/com/garbagemule/MobArena/waves/Wave.java +++ b/src/com/garbagemule/MobArena/waves/Wave.java @@ -1,12 +1,8 @@ package com.garbagemule.MobArena.waves; -import java.util.Collection; - -import org.bukkit.Location; - import com.garbagemule.MobArena.util.WaveUtils; -public interface Wave extends Comparable +public interface Wave { public enum WaveBranch { @@ -25,11 +21,28 @@ public interface Wave extends Comparable public enum WaveGrowth { - SLOW, MEDIUM, FAST; - + OLD(0), SLOW(0.5), MEDIUM(0.65), FAST(0.8), PSYCHO(1.1); + private double exp; + + private WaveGrowth(double exp) + { + this.exp = exp; + } + public static WaveGrowth fromString(String string) { - return WaveUtils.getEnumFromString(WaveGrowth.class, string, MEDIUM); + return WaveUtils.getEnumFromString(WaveGrowth.class, string, OLD); + } + + public int getAmount(int wave, int playerCount) + { + if (this == OLD) return wave + playerCount; + + double pc = (double) playerCount; + double w = (double) wave; + + double base = Math.min(Math.ceil(pc/2) + 1, 13); + return (int) ( base * Math.pow(w, exp) ); } } @@ -69,7 +82,7 @@ public interface Wave extends Comparable * be modified by the wave parameter. * @param wave Wave number */ - public void spawn(int wave, Collection spawnpoints); + public void spawn(int wave); /** * Get the type of wave. @@ -106,6 +119,12 @@ public interface Wave extends Comparable * @return The name */ public String getName(); + + /** + * Set the wave's growth + * @param growth How fast the wave will grow + */ + public void setGrowth(WaveGrowth growth); /** * Check if this wave matches the wave number. diff --git a/src/com/garbagemule/register/payment/Method.java b/src/com/garbagemule/register/payment/Method.java index 921b9cf..ec1481b 100644 --- a/src/com/garbagemule/register/payment/Method.java +++ b/src/com/garbagemule/register/payment/Method.java @@ -3,27 +3,121 @@ package com.garbagemule.register.payment; import org.bukkit.plugin.Plugin; /** - * Method.java - * Interface for all sub-methods for payment. + * Interface to be implemented by a payment method. * - * @author: Nijikokun (@nijikokun) - * @copyright: Copyright (C) 2011 - * @license: GNUv3 Affero License + * @author Nijikokun (@nijikokun) + * @copyright Copyright (C) 2011 + * @license AOL license */ public interface Method { + /** + * Encodes the Plugin into an Object disguised as the Plugin. + * If you want the original Plugin Class you must cast it to the correct + * Plugin, to do so you have to verify the name and or version then cast. + * + *
+     *  if(method.getName().equalsIgnoreCase("iConomy"))
+     *   iConomy plugin = ((iConomy)method.getPlugin());
+ * + * @return Object + * @see #getName() + * @see #getVersion() + */ public Object getPlugin(); + + /** + * Returns the actual name of this method. + * + * @return String Plugin name. + */ public String getName(); + + /** + * Returns the actual version of this method. + * + * @return String Plugin version. + */ public String getVersion(); + + + /** + * Formats amounts into this payment methods style of currency display. + * + * @param amount Double + * @return String - Formatted Currency Display. + */ public String format(double amount); + + /** + * Allows the verification of bank API existence in this payment method. + * + * @return boolean + */ public boolean hasBanks(); + + /** + * Determines the existence of a bank via name. + * + * @param bank Bank name + * @return boolean + * @see #hasBanks + */ public boolean hasBank(String bank); + + /** + * Determines the existence of an account via name. + * + * @param name Account name + * @return boolean + */ public boolean hasAccount(String name); + + /** + * Check to see if an account name is tied to a bank. + * + * @param bank Bank name + * @param name Account name + * @return boolean + */ public boolean hasBankAccount(String bank, String name); + + /** + * Returns a MethodAccount class for an account name. + * + * @param name Account name + * @return MethodAccount or Null + */ public MethodAccount getAccount(String name); + + + /** + * Returns a MethodBankAccount class for an account name. + * + * @param bank Bank name + * @param name Account name + * @return MethodBankAccount or Null + */ public MethodBankAccount getBankAccount(String bank, String name); + + /** + * Checks to verify the compatibility between this Method and a plugin. + * Internal usage only, for the most part. + * + * @param plugin Plugin + * @return boolean + */ public boolean isCompatible(Plugin plugin); + + /** + * Set Plugin data. + * + * @param plugin Plugin + */ public void setPlugin(Plugin plugin); + /** + * Contains Calculator and Balance functions for Accounts. + */ public interface MethodAccount { public double balance(); public boolean set(double amount); @@ -41,6 +135,9 @@ public interface Method { public String toString(); } + /** + * Contains Calculator and Balance functions for Bank Accounts. + */ public interface MethodBankAccount { public double balance(); public String getBankName(); diff --git a/src/com/garbagemule/register/payment/Methods.java b/src/com/garbagemule/register/payment/Methods.java index a8eb99f..117a236 100644 --- a/src/com/garbagemule/register/payment/Methods.java +++ b/src/com/garbagemule/register/payment/Methods.java @@ -1,21 +1,31 @@ package com.garbagemule.register.payment; -import com.garbagemule.register.payment.methods.BOSE6; -import com.garbagemule.register.payment.methods.BOSE7; - -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - import java.util.HashSet; import java.util.Set; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + /** - * Methods.java - * Controls the getting / setting of methods & the method of payment used. + * The Methods initializes Methods that utilize the Method interface + * based on a "first come, first served" basis. * - * @author: Nijikokun (@nijikokun) + * Allowing you to check whether a payment method exists or not. + * + *
+ *  Methods methods = new Methods();
+ * 
+ * + * Methods also allows you to set a preferred method of payment before it captures + * payment plugins in the initialization process. + * + *
+ *  Methods methods = new Methods("iConomy");
+ * 
+ * + * @author: Nijikokun (@nijikokun) * @copyright: Copyright (C) 2011 - * @license: GNUv3 Affero License + * @license: AOL license */ public class Methods { private boolean self = false; @@ -25,14 +35,18 @@ public class Methods { private Set Dependencies = new HashSet(); private Set Attachables = new HashSet(); + /** + * Initialize Method class + */ public Methods() { this._init(); } /** - * Allows you to set which economy plugin is most preferred. + * Initializes Methods class utilizing a "preferred" payment method check before + * returning the first method that was initialized. * - * @param preferred - preferred economy plugin + * @param preferred Payment method that is most preferred for this setup. */ public Methods(String preferred) { this._init(); @@ -42,18 +56,40 @@ public class Methods { } } + /** + * Implement all methods along with their respective name & class. + * + * @see #Methods() + * @see #Methods(java.lang.String) + */ private void _init() { - this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo4()); + this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo6()); this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo5()); - this.addMethod("BOSEconomy", new BOSE6()); - this.addMethod("BOSEconomy", new BOSE7()); + this.addMethod("iConomy", new com.garbagemule.register.payment.methods.iCo4()); + this.addMethod("BOSEconomy", new com.garbagemule.register.payment.methods.BOSE6()); + this.addMethod("BOSEconomy", new com.garbagemule.register.payment.methods.BOSE7()); this.addMethod("Essentials", new com.garbagemule.register.payment.methods.EE17()); + this.addMethod("MultiCurrency", new com.garbagemule.register.payment.methods.MCUR()); } + /** + * Returns an array of payment method names that have been loaded + * through the _init method. + * + * @return Set - Array of payment methods that are loaded. + * @see #setMethod(org.bukkit.plugin.Plugin) + */ public Set getDependencies() { return Dependencies; } + /** + * Interprets Plugin class data to verify whether it is compatible with an existing payment + * method to use for payments and other various economic activity. + * + * @param plugin Plugin data from bukkit, Internal Class file. + * @return Method or Null + */ public Method createMethod(Plugin plugin) { for (Method method: Methods) { if (method.isCompatible(plugin)) { @@ -70,17 +106,31 @@ public class Methods { Methods.add(method); } + /** + * Verifies if Register has set a payment method for usage yet. + * + * @return boolean + * @see #setMethod(org.bukkit.plugin.Plugin) + * @see #checkDisabled(org.bukkit.plugin.Plugin) + */ public boolean hasMethod() { return (Method != null); } + /** + * Checks Plugin Class against a multitude of checks to verify it's usability + * as a payment method. + * + * @param method Plugin data from bukkit, Internal Class file. + * @return boolean True on success, False on failure. + */ public boolean setMethod(Plugin method) { if(hasMethod()) return true; if(self) { self = false; return false; } int count = 0; boolean match = false; - Plugin plugin; + Plugin plugin = null; PluginManager manager = method.getServer().getPluginManager(); for(String name: this.getDependencies()) { @@ -129,10 +179,22 @@ public class Methods { return hasMethod(); } + /** + * Grab the existing and initialized (hopefully) Method Class. + * + * @return Method or Null + */ public Method getMethod() { return Method; } + /** + * Verify is a plugin is disabled, only does this if we there is an existing payment + * method initialized in Register. + * + * @param method Plugin data from bukkit, Internal Class file. + * @return boolean + */ public boolean checkDisabled(Plugin method) { if(!hasMethod()) return true; if (Method.isCompatible(method)) Method = null; diff --git a/src/com/garbagemule/register/payment/methods/BOSE6.java b/src/com/garbagemule/register/payment/methods/BOSE6.java index 3ca97f6..5dfdf3b 100644 --- a/src/com/garbagemule/register/payment/methods/BOSE6.java +++ b/src/com/garbagemule/register/payment/methods/BOSE6.java @@ -1,10 +1,16 @@ package com.garbagemule.register.payment.methods; import com.garbagemule.register.payment.Method; - import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; +/** + * BOSEconomy 6 Implementation of Method + * + * @author Nijikokun (@nijikokun) + * @copyright (c) 2011 + * @license AOL license + */ public class BOSE6 implements Method { private BOSEconomy BOSEconomy; @@ -61,8 +67,8 @@ public class BOSE6 implements Method { } public class BOSEAccount implements MethodAccount { - private String name; - private BOSEconomy BOSEconomy; + private final String name; + private final BOSEconomy BOSEconomy; public BOSEAccount(String name, BOSEconomy bOSEconomy) { this.name = name; @@ -70,7 +76,7 @@ public class BOSE6 implements Method { } public double balance() { - return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name)); + return (double) this.BOSEconomy.getPlayerMoney(this.name); } public boolean set(double amount) { @@ -123,8 +129,8 @@ public class BOSE6 implements Method { } public class BOSEBankAccount implements MethodBankAccount { - private String bank; - private BOSEconomy BOSEconomy; + private final String bank; + private final BOSEconomy BOSEconomy; public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { this.bank = bank; @@ -140,7 +146,7 @@ public class BOSE6 implements Method { } public double balance() { - return Double.valueOf(this.BOSEconomy.getBankMoney(bank)); + return (double) this.BOSEconomy.getBankMoney(bank); } public boolean set(double amount) { diff --git a/src/com/garbagemule/register/payment/methods/BOSE7.java b/src/com/garbagemule/register/payment/methods/BOSE7.java index 18e98fa..ab8c418 100644 --- a/src/com/garbagemule/register/payment/methods/BOSE7.java +++ b/src/com/garbagemule/register/payment/methods/BOSE7.java @@ -1,14 +1,17 @@ package com.garbagemule.register.payment.methods; import com.garbagemule.register.payment.Method; - import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; /** + * BOSEconomy 7 Implementation of Method + * * @author Acrobot + * @author Nijikokun (@nijikokun) + * @copyright (c) 2011 + * @license AOL license */ - public class BOSE7 implements Method { private BOSEconomy BOSEconomy; diff --git a/src/com/garbagemule/register/payment/methods/EE17.java b/src/com/garbagemule/register/payment/methods/EE17.java index 388483f..e9abb75 100644 --- a/src/com/garbagemule/register/payment/methods/EE17.java +++ b/src/com/garbagemule/register/payment/methods/EE17.java @@ -4,11 +4,21 @@ import com.earth2me.essentials.Essentials; import com.earth2me.essentials.api.Economy; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; -import com.garbagemule.register.payment.Method; +import com.garbagemule.register.payment.Method; import org.bukkit.plugin.Plugin; +/** + * Essentials 17 Implementation of Method + * + * @author Nijikokun (@nijikokun) + * @author Snowleo + * @author Acrobot + * @author KHobbits + * @copyright (c) 2011 + * @license AOL license + */ public class EE17 implements Method { private Essentials Essentials; diff --git a/src/com/garbagemule/register/payment/methods/MCUR.java b/src/com/garbagemule/register/payment/methods/MCUR.java new file mode 100644 index 0000000..77c9f2a --- /dev/null +++ b/src/com/garbagemule/register/payment/methods/MCUR.java @@ -0,0 +1,120 @@ +package com.garbagemule.register.payment.methods; + +import com.garbagemule.register.payment.Method; + +import me.ashtheking.currency.Currency; +import me.ashtheking.currency.CurrencyList; + +import org.bukkit.plugin.Plugin; + +/** + * MultiCurrency Method implementation. + * + * @author Acrobot + * @copyright (c) 2011 + * @license AOL license + */ +public class MCUR implements Method { + private Currency currencyList; + + public Object getPlugin() { + return this.currencyList; + } + + public String getName() { + return "MultiCurrency"; + } + + public String getVersion() { + return "0.09"; + } + + public String format(double amount) { + return amount + " Currency"; + } + + public boolean hasBanks() { + return false; + } + + public boolean hasBank(String bank) { + return false; + } + + public boolean hasAccount(String name) { + return true; + } + + public boolean hasBankAccount(String bank, String name) { + return false; + } + + public MethodAccount getAccount(String name) { + return new MCurrencyAccount(name); + } + + public MethodBankAccount getBankAccount(String bank, String name) { + return null; + } + + public boolean isCompatible(Plugin plugin) { + return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency; + } + + public void setPlugin(Plugin plugin) { + currencyList = (Currency) plugin; + } + + public class MCurrencyAccount implements MethodAccount{ + private String name; + + public MCurrencyAccount(String name) { + this.name = name; + } + + public double balance() { + return CurrencyList.getValue((String) CurrencyList.maxCurrency(name)[0], name); + } + + public boolean set(double amount) { + CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, amount); + return true; + } + + public boolean add(double amount) { + return CurrencyList.add(name, amount); + } + + public boolean subtract(double amount) { + return CurrencyList.subtract(name, amount); + } + + public boolean multiply(double amount) { + return CurrencyList.multiply(name, amount); + } + + public boolean divide(double amount) { + return CurrencyList.divide(name, amount); + } + + public boolean hasEnough(double amount) { + return CurrencyList.hasEnough(name, amount); + } + + public boolean hasOver(double amount) { + return CurrencyList.hasOver(name, amount); + } + + public boolean hasUnder(double amount) { + return CurrencyList.hasUnder(name, amount); + } + + public boolean isNegative() { + return CurrencyList.isNegative(name); + } + + public boolean remove() { + return CurrencyList.remove(name); + } + } +} diff --git a/src/com/garbagemule/register/payment/methods/iCo4.java b/src/com/garbagemule/register/payment/methods/iCo4.java index 2c96115..eb76708 100644 --- a/src/com/garbagemule/register/payment/methods/iCo4.java +++ b/src/com/garbagemule/register/payment/methods/iCo4.java @@ -1,12 +1,19 @@ package com.garbagemule.register.payment.methods; -import com.garbagemule.register.payment.Method; import com.nijiko.coelho.iConomy.iConomy; import com.nijiko.coelho.iConomy.system.Account; +import com.garbagemule.register.payment.Method; import org.bukkit.plugin.Plugin; +/** + * iConomy 4 Implementation of Method + * + * @author Nijikokun (@nijikokun) + * @copyright (c) 2011 + * @license AOL license + */ public class iCo4 implements Method { private iConomy iConomy; @@ -51,7 +58,7 @@ public class iCo4 implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") && plugin instanceof iConomy; } public void setPlugin(Plugin plugin) { diff --git a/src/com/garbagemule/register/payment/methods/iCo5.java b/src/com/garbagemule/register/payment/methods/iCo5.java index 2e0ede8..318090e 100644 --- a/src/com/garbagemule/register/payment/methods/iCo5.java +++ b/src/com/garbagemule/register/payment/methods/iCo5.java @@ -1,15 +1,22 @@ package com.garbagemule.register.payment.methods; -import com.garbagemule.register.payment.Method; import com.iConomy.iConomy; import com.iConomy.system.Account; import com.iConomy.system.BankAccount; import com.iConomy.system.Holdings; import com.iConomy.util.Constants; +import com.garbagemule.register.payment.Method; import org.bukkit.plugin.Plugin; +/** + * iConomy 5 Implementation of Method + * + * @author Nijikokun (@nijikokun) + * @copyright (c) 2011 + * @license AOL license + */ public class iCo5 implements Method { private iConomy iConomy; @@ -34,7 +41,7 @@ public class iCo5 implements Method { } public boolean hasBank(String bank) { - return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank); + return (hasBanks()) && this.iConomy.Banks.exists(bank); } public boolean hasAccount(String name) { @@ -42,7 +49,7 @@ public class iCo5 implements Method { } public boolean hasBankAccount(String bank, String name) { - return (!hasBank(bank)) ? false : this.iConomy.getBank(bank).hasAccount(name); + return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name); } public MethodAccount getAccount(String name) { @@ -52,7 +59,7 @@ public class iCo5 implements Method { public MethodBankAccount getBankAccount(String bank, String name) { return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name)); } - + public boolean isCompatible(Plugin plugin) { return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; } @@ -208,4 +215,4 @@ public class iCo5 implements Method { return true; } } -} +} \ No newline at end of file diff --git a/src/com/garbagemule/register/payment/methods/iCo6.java b/src/com/garbagemule/register/payment/methods/iCo6.java new file mode 100644 index 0000000..4950ee0 --- /dev/null +++ b/src/com/garbagemule/register/payment/methods/iCo6.java @@ -0,0 +1,142 @@ +package com.garbagemule.register.payment.methods; + +import com.iCo6.iConomy; +import com.iCo6.system.Account; +import com.iCo6.system.Accounts; +import com.iCo6.system.Holdings; + +import com.garbagemule.register.payment.Method; + +import org.bukkit.plugin.Plugin; + +/** + * iConomy 6 Implementation of Method + * + * @author Nijikokun (@nijikokun) + * @copyright (c) 2011 + * @license AOL license + */ +public class iCo6 implements Method { + private iConomy iConomy; + + public iConomy getPlugin() { + return this.iConomy; + } + + public String getName() { + return "iConomy"; + } + + public String getVersion() { + return "6"; + } + + public String format(double amount) { + return this.iConomy.format(amount); + } + + public boolean hasBanks() { + return false; + } + + public boolean hasBank(String bank) { + return false; + } + + public boolean hasAccount(String name) { + return (new Accounts()).exists(name); + } + + public boolean hasBankAccount(String bank, String name) { + return false; + } + + public MethodAccount getAccount(String name) { + return new iCoAccount((new Accounts()).get(name)); + } + + public MethodBankAccount getBankAccount(String bank, String name) { + return null; + } + + public boolean isCompatible(Plugin plugin) { + try { Class.forName("com.iCo6.IO"); } + catch(Exception e) { return false; } + + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iCo6.iConomy") && plugin instanceof iConomy; + } + + public void setPlugin(Plugin plugin) { + iConomy = (iConomy)plugin; + } + + public class iCoAccount implements MethodAccount { + private Account account; + private Holdings holdings; + + public iCoAccount(Account account) { + this.account = account; + this.holdings = account.getHoldings(); + } + + public Account getiCoAccount() { + return account; + } + + public double balance() { + return this.holdings.getBalance(); + } + + public boolean set(double amount) { + if(this.holdings == null) return false; + this.holdings.setBalance(amount); + return true; + } + + public boolean add(double amount) { + if(this.holdings == null) return false; + this.holdings.add(amount); + return true; + } + + public boolean subtract(double amount) { + if(this.holdings == null) return false; + this.holdings.subtract(amount); + return true; + } + + public boolean multiply(double amount) { + if(this.holdings == null) return false; + this.holdings.multiply(amount); + return true; + } + + public boolean divide(double amount) { + if(this.holdings == null) return false; + this.holdings.divide(amount); + return true; + } + + public boolean hasEnough(double amount) { + return this.holdings.hasEnough(amount); + } + + public boolean hasOver(double amount) { + return this.holdings.hasOver(amount); + } + + public boolean hasUnder(double amount) { + return this.holdings.hasUnder(amount); + } + + public boolean isNegative() { + return this.holdings.isNegative(); + } + + public boolean remove() { + if(this.account == null) return false; + this.account.remove(); + return true; + } + } +}