diff --git a/.gitignore b/.gitignore index dabfb7b..145efd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ -# Mac Filesystem. -.DS_Store - -# Other unneeded files. -/bin -/manifest.mf +# Eclipse .classpath -.settings.classpath -.settings .project -/target +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Maven +log/ +target/ + +*.gitignore \ No newline at end of file diff --git a/src/nl/Steffion/BlockHunt/ArenaHandler.java b/src/nl/Steffion/BlockHunt/ArenaHandler.java index 9df7cbe..4e48f31 100644 --- a/src/nl/Steffion/BlockHunt/ArenaHandler.java +++ b/src/nl/Steffion/BlockHunt/ArenaHandler.java @@ -5,6 +5,9 @@ import java.util.List; import me.libraryaddict.disguise.DisguiseAPI; import nl.Steffion.BlockHunt.Arena.ArenaState; +import nl.Steffion.BlockHunt.Events.EndArenaEvent; +import nl.Steffion.BlockHunt.Events.JoinArenaEvent; +import nl.Steffion.BlockHunt.Events.LeaveArenaEvent; import nl.Steffion.BlockHunt.PermissionsC.Permissions; import nl.Steffion.BlockHunt.Managers.MessageM; import nl.Steffion.BlockHunt.Managers.PermissionsM; @@ -97,6 +100,8 @@ public class ArenaHandler { } System.out.println("[BlockHunt] " + player.getName() + " has joined " + arenaname); arena.playersInArena.add(player); + JoinArenaEvent event = new JoinArenaEvent(player, arena); + Bukkit.getPluginManager().callEvent(event); PlayerArenaData pad = new PlayerArenaData(player.getLocation(), player.getGameMode(), player.getInventory().getContents(), player .getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getHealth(), player.getFoodLevel(), @@ -142,7 +147,7 @@ public class ArenaHandler { // player } - if ((Boolean) W.config.get(ConfigC.shop_blockChooserv1Enabled) == true) { + if ((Boolean) W.config.get(ConfigC.shop_blockChooserv1Enabled)) { if (W.shop.getFile().get(player.getName() + ".blockchooser") != null || PermissionsM.hasPerm(player, Permissions.shopblockchooser, false)) { ItemStack shopBlockChooser = new ItemStack(Material.getMaterial((String) W.config.get(ConfigC.shop_blockChooserv1IDname)), 1); @@ -160,7 +165,7 @@ public class ArenaHandler { } } - if ((Boolean) W.config.get(ConfigC.shop_BlockHuntPassv2Enabled) == true) { + if ((Boolean) W.config.get(ConfigC.shop_BlockHuntPassv2Enabled)) { if (W.shop.getFile().getInt(player.getName() + ".blockhuntpass") != 0) { ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) W.config.get(ConfigC.shop_BlockHuntPassv2IDName)), 1); @@ -225,6 +230,8 @@ public class ArenaHandler { if (arena != null) { System.out.println("[BlockHunt] " + player.getName() + " has left " + arena.arenaName); + LeaveArenaEvent event = new LeaveArenaEvent(player, arena); + Bukkit.getPluginManager().callEvent(event); if (cleanup) { arena.playersInArena.remove(player); @@ -339,24 +346,43 @@ public class ArenaHandler { public static void seekersWin(Arena arena) { System.out.println("[BlockHunt] Seekers have won " + arena.arenaName); ArenaHandler.sendFMessage(arena, ConfigC.normal_winSeekers); + + List winners = new ArrayList(); + List losers = new ArrayList(); + for (Player player : arena.playersInArena) { - if (arena.seekersWinCommands != null) { - for (String command : arena.seekersWinCommands) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName())); - } - if (W.shop.getFile().get(player.getName() + ".tokens") == null) { - W.shop.getFile().set(player.getName() + ".tokens", 0); - W.shop.save(); - } - int playerTokens = W.shop.getFile().getInt(player.getName() + ".tokens"); - W.shop.getFile().set(player.getName() + ".tokens", playerTokens + arena.seekersTokenWin); - W.shop.save(); + if (arena.seekers.contains(player)) { + + winners.add(player); + + if (arena.seekersWinCommands != null) { + for (String command : arena.seekersWinCommands) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName())); + } + + if (W.shop.getFile().get(player.getName() + ".tokens") == null) { + W.shop.getFile().set(player.getName() + ".tokens", 0); + W.shop.save(); + } + int playerTokens = W.shop.getFile().getInt(player.getName() + ".tokens"); + W.shop.getFile().set(player.getName() + ".tokens", playerTokens + arena.seekersTokenWin); + W.shop.save(); + + MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.seekersTokenWin); + + } + + } else { + + losers.add(player); - MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.seekersTokenWin); } } + EndArenaEvent event = new EndArenaEvent(winners, losers, arena); + Bukkit.getServer().getPluginManager().callEvent(event); + arena.seekers.clear(); for (Player player : arena.playersInArena) { @@ -372,8 +398,20 @@ public class ArenaHandler { public static void hidersWin(Arena arena) { System.out.println("[BlockHunt] Hiders have won " + arena.arenaName); ArenaHandler.sendFMessage(arena, ConfigC.normal_winHiders); + + List winners = new ArrayList(); + List losers = new ArrayList(); + for (Player player : arena.playersInArena) { - if (!arena.seekers.contains(player)) { + + if (arena.seekers.contains(player)) { + + losers.add(player); + + } else { + + winners.add(player); + if (arena.hidersWinCommands != null) { for (String command : arena.hidersWinCommands) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName())); @@ -390,8 +428,12 @@ public class ArenaHandler { MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.hidersTokenWin); } } + } + EndArenaEvent event = new EndArenaEvent(winners, losers, arena); + Bukkit.getServer().getPluginManager().callEvent(event); + arena.seekers.clear(); for (Player player : arena.playersInArena) { diff --git a/src/nl/Steffion/BlockHunt/Events/EndArenaEvent.java b/src/nl/Steffion/BlockHunt/Events/EndArenaEvent.java new file mode 100644 index 0000000..ff3b8ca --- /dev/null +++ b/src/nl/Steffion/BlockHunt/Events/EndArenaEvent.java @@ -0,0 +1,43 @@ +package nl.Steffion.BlockHunt.Events; + +import nl.Steffion.BlockHunt.Arena; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import java.util.List; + +public class EndArenaEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private List winners = null; + private List losers = null; + private Arena arena = null; + + public EndArenaEvent(List winners, List losers, Arena arena) { + this.winners = winners; + this.losers = losers; + this.arena = arena; + } + + public List getWinners() { + return winners; + } + + public List getLosers() { + return losers; + } + + public Arena getArena() { + return arena; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/nl/Steffion/BlockHunt/Events/JoinArenaEvent.java b/src/nl/Steffion/BlockHunt/Events/JoinArenaEvent.java new file mode 100644 index 0000000..69a4235 --- /dev/null +++ b/src/nl/Steffion/BlockHunt/Events/JoinArenaEvent.java @@ -0,0 +1,35 @@ +package nl.Steffion.BlockHunt.Events; + +import nl.Steffion.BlockHunt.Arena; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class JoinArenaEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private Player player = null; + private Arena arena = null; + + public JoinArenaEvent(Player player, Arena arena) { + this.player = player; + this.arena = arena; + } + + public Player getPlayer() { + return player; + } + + public Arena getArena() { + return arena; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/nl/Steffion/BlockHunt/Events/LeaveArenaEvent.java b/src/nl/Steffion/BlockHunt/Events/LeaveArenaEvent.java new file mode 100644 index 0000000..4d7b480 --- /dev/null +++ b/src/nl/Steffion/BlockHunt/Events/LeaveArenaEvent.java @@ -0,0 +1,35 @@ +package nl.Steffion.BlockHunt.Events; + +import nl.Steffion.BlockHunt.Arena; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class LeaveArenaEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private Player player = null; + private Arena arena = null; + + public LeaveArenaEvent(Player player, Arena arena) { + this.player = player; + this.arena = arena; + } + + public Player getPlayer() { + return player; + } + + public Arena getArena() { + return arena; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +}