Added some basic Event API.
- Arena End - Join Arena - Leave Arena
This commit is contained in:
parent
dfdb7e84c3
commit
f578efbd40
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,11 +1,15 @@
|
|||||||
# Mac Filesystem.
|
# Eclipse
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Other unneeded files.
|
|
||||||
/bin
|
|
||||||
/manifest.mf
|
|
||||||
.classpath
|
.classpath
|
||||||
.settings.classpath
|
|
||||||
.settings
|
|
||||||
.project
|
.project
|
||||||
/target
|
.settings/
|
||||||
|
|
||||||
|
# Intellij
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# Maven
|
||||||
|
log/
|
||||||
|
target/
|
||||||
|
|
||||||
|
*.gitignore
|
@ -5,6 +5,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import nl.Steffion.BlockHunt.Arena.ArenaState;
|
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.PermissionsC.Permissions;
|
||||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||||
import nl.Steffion.BlockHunt.Managers.PermissionsM;
|
import nl.Steffion.BlockHunt.Managers.PermissionsM;
|
||||||
@ -97,6 +100,8 @@ public class ArenaHandler {
|
|||||||
}
|
}
|
||||||
System.out.println("[BlockHunt] " + player.getName() + " has joined " + arenaname);
|
System.out.println("[BlockHunt] " + player.getName() + " has joined " + arenaname);
|
||||||
arena.playersInArena.add(player);
|
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
|
PlayerArenaData pad = new PlayerArenaData(player.getLocation(), player.getGameMode(), player.getInventory().getContents(), player
|
||||||
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getHealth(), player.getFoodLevel(),
|
.getInventory().getArmorContents(), player.getExp(), player.getLevel(), player.getHealth(), player.getFoodLevel(),
|
||||||
@ -142,7 +147,7 @@ public class ArenaHandler {
|
|||||||
// player
|
// 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
|
if (W.shop.getFile().get(player.getName() + ".blockchooser") != null
|
||||||
|| PermissionsM.hasPerm(player, Permissions.shopblockchooser, false)) {
|
|| PermissionsM.hasPerm(player, Permissions.shopblockchooser, false)) {
|
||||||
ItemStack shopBlockChooser = new ItemStack(Material.getMaterial((String) W.config.get(ConfigC.shop_blockChooserv1IDname)), 1);
|
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) {
|
if (W.shop.getFile().getInt(player.getName() + ".blockhuntpass") != 0) {
|
||||||
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) W.config.get(ConfigC.shop_BlockHuntPassv2IDName)),
|
ItemStack shopBlockHuntPass = new ItemStack(Material.getMaterial((String) W.config.get(ConfigC.shop_BlockHuntPassv2IDName)),
|
||||||
1);
|
1);
|
||||||
@ -225,6 +230,8 @@ public class ArenaHandler {
|
|||||||
|
|
||||||
if (arena != null) {
|
if (arena != null) {
|
||||||
System.out.println("[BlockHunt] " + player.getName() + " has left " + arena.arenaName);
|
System.out.println("[BlockHunt] " + player.getName() + " has left " + arena.arenaName);
|
||||||
|
LeaveArenaEvent event = new LeaveArenaEvent(player, arena);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (cleanup) {
|
if (cleanup) {
|
||||||
arena.playersInArena.remove(player);
|
arena.playersInArena.remove(player);
|
||||||
@ -339,7 +346,16 @@ public class ArenaHandler {
|
|||||||
public static void seekersWin(Arena arena) {
|
public static void seekersWin(Arena arena) {
|
||||||
System.out.println("[BlockHunt] Seekers have won " + arena.arenaName);
|
System.out.println("[BlockHunt] Seekers have won " + arena.arenaName);
|
||||||
ArenaHandler.sendFMessage(arena, ConfigC.normal_winSeekers);
|
ArenaHandler.sendFMessage(arena, ConfigC.normal_winSeekers);
|
||||||
|
|
||||||
|
List<Player> winners = new ArrayList<Player>();
|
||||||
|
List<Player> losers = new ArrayList<Player>();
|
||||||
|
|
||||||
for (Player player : arena.playersInArena) {
|
for (Player player : arena.playersInArena) {
|
||||||
|
|
||||||
|
if (arena.seekers.contains(player)) {
|
||||||
|
|
||||||
|
winners.add(player);
|
||||||
|
|
||||||
if (arena.seekersWinCommands != null) {
|
if (arena.seekersWinCommands != null) {
|
||||||
for (String command : arena.seekersWinCommands) {
|
for (String command : arena.seekersWinCommands) {
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName()));
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName()));
|
||||||
@ -354,9 +370,19 @@ public class ArenaHandler {
|
|||||||
W.shop.save();
|
W.shop.save();
|
||||||
|
|
||||||
MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.seekersTokenWin);
|
MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.seekersTokenWin);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
losers.add(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EndArenaEvent event = new EndArenaEvent(winners, losers, arena);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
arena.seekers.clear();
|
arena.seekers.clear();
|
||||||
|
|
||||||
for (Player player : arena.playersInArena) {
|
for (Player player : arena.playersInArena) {
|
||||||
@ -372,8 +398,20 @@ public class ArenaHandler {
|
|||||||
public static void hidersWin(Arena arena) {
|
public static void hidersWin(Arena arena) {
|
||||||
System.out.println("[BlockHunt] Hiders have won " + arena.arenaName);
|
System.out.println("[BlockHunt] Hiders have won " + arena.arenaName);
|
||||||
ArenaHandler.sendFMessage(arena, ConfigC.normal_winHiders);
|
ArenaHandler.sendFMessage(arena, ConfigC.normal_winHiders);
|
||||||
|
|
||||||
|
List<Player> winners = new ArrayList<Player>();
|
||||||
|
List<Player> losers = new ArrayList<Player>();
|
||||||
|
|
||||||
for (Player player : arena.playersInArena) {
|
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) {
|
if (arena.hidersWinCommands != null) {
|
||||||
for (String command : arena.hidersWinCommands) {
|
for (String command : arena.hidersWinCommands) {
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%player%", player.getName()));
|
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);
|
MessageM.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + arena.hidersTokenWin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EndArenaEvent event = new EndArenaEvent(winners, losers, arena);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
arena.seekers.clear();
|
arena.seekers.clear();
|
||||||
|
|
||||||
for (Player player : arena.playersInArena) {
|
for (Player player : arena.playersInArena) {
|
||||||
|
43
src/nl/Steffion/BlockHunt/Events/EndArenaEvent.java
Normal file
43
src/nl/Steffion/BlockHunt/Events/EndArenaEvent.java
Normal file
@ -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<Player> winners = null;
|
||||||
|
private List<Player> losers = null;
|
||||||
|
private Arena arena = null;
|
||||||
|
|
||||||
|
public EndArenaEvent(List<Player> winners, List<Player> losers, Arena arena) {
|
||||||
|
this.winners = winners;
|
||||||
|
this.losers = losers;
|
||||||
|
this.arena = arena;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getWinners() {
|
||||||
|
return winners;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getLosers() {
|
||||||
|
return losers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Arena getArena() {
|
||||||
|
return arena;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
src/nl/Steffion/BlockHunt/Events/JoinArenaEvent.java
Normal file
35
src/nl/Steffion/BlockHunt/Events/JoinArenaEvent.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
src/nl/Steffion/BlockHunt/Events/LeaveArenaEvent.java
Normal file
35
src/nl/Steffion/BlockHunt/Events/LeaveArenaEvent.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user