mirror of
https://github.com/taoneill/war.git
synced 2024-12-02 23:23:30 +01:00
Properly implement War event API, some cleaning.
I changed some of the new event API code from @BenMenking to use more Bukkit provided frameworks like Player and use basic java structures instead of checking integers.
This commit is contained in:
parent
e2f6e02ae7
commit
a4f1b29922
@ -6,10 +6,13 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -20,6 +23,9 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
@ -30,12 +36,11 @@ import com.tommytony.war.config.TeamConfigBag;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.config.WarzoneConfigBag;
|
||||
import com.tommytony.war.event.WarBattleWinEvent;
|
||||
import com.tommytony.war.event.WarPlayerDeathEvent;
|
||||
import com.tommytony.war.event.WarPlayerLeaveEvent;
|
||||
import com.tommytony.war.event.WarPlayerThiefEvent;
|
||||
import com.tommytony.war.event.WarScoreCapEvent;
|
||||
import com.tommytony.war.event.WarTeamWinEvent;
|
||||
import com.tommytony.war.event.WarThiefDeathEvent;
|
||||
import com.tommytony.war.job.InitZoneJob;
|
||||
import com.tommytony.war.job.LoadoutResetJob;
|
||||
import com.tommytony.war.job.LogKillsDeathsJob;
|
||||
@ -58,15 +63,6 @@ import com.tommytony.war.utility.PotionEffectHelper;
|
||||
import com.tommytony.war.volume.BlockInfo;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import com.tommytony.war.volume.ZoneVolume;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import java.util.Map;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -989,20 +985,15 @@ public class Warzone {
|
||||
|
||||
// whoever didn't lose, reward them
|
||||
//
|
||||
List<Team> winningTeams = new ArrayList<Team>(teams.size());
|
||||
for( Team t : teams ) {
|
||||
if( !t.getPlayers().contains(player)) {
|
||||
//War.war.getServer().getLogger().info("WAR: team " + t.getName() + " are winners!");
|
||||
ArrayList<String> winnerNames = new ArrayList<String>();
|
||||
for(Player name : t.getPlayers()) {
|
||||
winnerNames.add(name.getName());
|
||||
//War.war.getServer().getLogger().info("WAR: adding " + name.getName() + " to the list");
|
||||
}
|
||||
|
||||
WarTeamWinEvent event1 = new WarTeamWinEvent(winnerNames.toArray(new String[winnerNames.size()]));
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
winningTeams.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
WarBattleWinEvent event1 = new WarBattleWinEvent(this, winningTeams);
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
|
||||
if (!scores.equals("")) {
|
||||
for (Team t : teams) {
|
||||
t.teamcast("New scores - " + scores);
|
||||
@ -1115,9 +1106,6 @@ public class Warzone {
|
||||
|
||||
// Decrement lifepool
|
||||
playerTeam.setRemainingLives(remaining - 1);
|
||||
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(player.getName());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
|
||||
// Lifepool empty warning
|
||||
if (remaining - 1 == 0) {
|
||||
@ -1269,7 +1257,7 @@ public class Warzone {
|
||||
// Flags
|
||||
public void addFlagThief(Team lostFlagTeam, String flagThief) {
|
||||
this.flagThieves.put(flagThief, lostFlagTeam);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(flagThief, WarPlayerThiefEvent.STOLE_FLAG);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(flagThief), WarPlayerThiefEvent.StolenObject.FLAG);
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
}
|
||||
|
||||
@ -1291,7 +1279,7 @@ public class Warzone {
|
||||
// Bomb
|
||||
public void addBombThief(Bomb bomb, String bombThief) {
|
||||
this.bombThieves.put(bombThief, bomb);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(bombThief, WarPlayerThiefEvent.STOLE_BOMB);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(bombThief), WarPlayerThiefEvent.StolenObject.BOMB);
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
}
|
||||
|
||||
@ -1314,7 +1302,7 @@ public class Warzone {
|
||||
|
||||
public void addCakeThief(Cake cake, String cakeThief) {
|
||||
this.cakeThieves.put(cakeThief, cake);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(cakeThief, WarPlayerThiefEvent.STOLE_CAKE);
|
||||
WarPlayerThiefEvent event1 = new WarPlayerThiefEvent(Bukkit.getPlayerExact(cakeThief), WarPlayerThiefEvent.StolenObject.CAKE);
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
}
|
||||
|
||||
@ -1351,7 +1339,11 @@ public class Warzone {
|
||||
public void handleScoreCapReached(String winnersStr) {
|
||||
// Score cap reached. Reset everything.
|
||||
this.isEndOfGame = true;
|
||||
WarScoreCapEvent event1 = new WarScoreCapEvent(winnersStr.split(" "));
|
||||
List<Team> winningTeams = new ArrayList<Team>(teams.size());
|
||||
for (String team : winnersStr.split(" ")) {
|
||||
winningTeams.add(this.getTeamByKind(TeamKind.getTeam(team)));
|
||||
}
|
||||
WarScoreCapEvent event1 = new WarScoreCapEvent(winningTeams);
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
|
||||
new ScoreCapReachedJob(this, winnersStr).run(); // run inventory and teleports immediately to avoid inv reset problems
|
||||
|
@ -136,4 +136,13 @@ public enum TeamKind {
|
||||
public MaterialData getBlockData() {
|
||||
return new Wool(this.dyeColor);
|
||||
}
|
||||
|
||||
public static TeamKind getTeam(String teamName) {
|
||||
for (TeamKind team : TeamKind.values()) {
|
||||
if (team.toString().equalsIgnoreCase(teamName)) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +182,8 @@ public class WarEntityListener implements Listener {
|
||||
War.war.getKillstreakReward().rewardPlayer(a, defenderWarzone.getKillCount(a.getName()));
|
||||
}
|
||||
}
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, a, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
defenderWarzone.handleDeath(d);
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
// fast respawn, don't really die
|
||||
@ -194,6 +196,8 @@ public class WarEntityListener implements Listener {
|
||||
Bomb bomb = defenderWarzone.getBombForThief(d.getName());
|
||||
|
||||
// Kill the bomber
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
if (defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
@ -289,7 +293,8 @@ public class WarEntityListener implements Listener {
|
||||
team.teamcast(deathMessage);
|
||||
}
|
||||
}
|
||||
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
@ -468,7 +473,8 @@ public class WarEntityListener implements Listener {
|
||||
teamToMsg.teamcast(deathMessage);
|
||||
}
|
||||
}
|
||||
|
||||
WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(zone, player, null, event.getCause());
|
||||
War.war.getServer().getPluginManager().callEvent(event1);
|
||||
zone.handleDeath(player);
|
||||
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
|
||||
|
@ -1,20 +1,44 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class WarPlayerDeathEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String victim;
|
||||
|
||||
public WarPlayerDeathEvent(String victim) {
|
||||
private Player victim;
|
||||
private Warzone zone;
|
||||
private Entity killer;
|
||||
private DamageCause cause;
|
||||
|
||||
public WarPlayerDeathEvent(Warzone zone, Player victim, Entity killer,
|
||||
DamageCause cause) {
|
||||
this.zone = zone;
|
||||
this.victim = victim;
|
||||
this.killer = killer;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public String getVictim() {
|
||||
|
||||
public Warzone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public Entity getKiller() {
|
||||
return killer;
|
||||
}
|
||||
|
||||
public DamageCause getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public Player getVictim() {
|
||||
return victim;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -1,31 +0,0 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerKillEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String attacker, victim;
|
||||
|
||||
public WarPlayerKillEvent(String attacker, String victim) {
|
||||
this.attacker = attacker;
|
||||
this.victim = victim;
|
||||
}
|
||||
|
||||
public String getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
public String getVictim() {
|
||||
return victim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,23 +1,24 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarPlayerThiefEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String player;
|
||||
private int type;
|
||||
private Player player;
|
||||
private StolenObject type;
|
||||
|
||||
public WarPlayerThiefEvent(String thief, int stolen) {
|
||||
public WarPlayerThiefEvent(Player thief, StolenObject stolen) {
|
||||
this.player = thief;
|
||||
this.type = stolen;
|
||||
}
|
||||
|
||||
public String getThief() {
|
||||
public Player getThief() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getStolenObject() {
|
||||
public StolenObject getStolenObject() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -30,7 +31,9 @@ public class WarPlayerThiefEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static final int STOLE_FLAG = 0;
|
||||
public static final int STOLE_BOMB = 1;
|
||||
public static final int STOLE_CAKE = 2;
|
||||
public enum StolenObject {
|
||||
FLAG,
|
||||
BOMB,
|
||||
CAKE
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,24 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
public class WarScoreCapEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String[] members;
|
||||
|
||||
public WarScoreCapEvent(String[] members) {
|
||||
this.members = members;
|
||||
private List<Team> winningTeams;
|
||||
|
||||
public List<Team> getWinningTeams() {
|
||||
return winningTeams;
|
||||
}
|
||||
|
||||
public String[] getWinners() {
|
||||
return members;
|
||||
|
||||
public WarScoreCapEvent(List<Team> winningTeams) {
|
||||
this.winningTeams = winningTeams;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -1,26 +0,0 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarTeamWinEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String[] members;
|
||||
|
||||
public WarTeamWinEvent(String[] members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public String[] getWinners() {
|
||||
return members;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.tommytony.war.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class WarThiefDeathEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String player;
|
||||
private int type;
|
||||
|
||||
public WarThiefDeathEvent(String player, int type) {
|
||||
this.player = player;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getThiefName() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public int getThiefType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static final int FLAG_THIEF = 0;
|
||||
public static final int BOMB_THIEF = 1;
|
||||
public static final int CAKE_THIEF = 2;
|
||||
}
|
Loading…
Reference in New Issue
Block a user