Skip to content

Commit

Permalink
Add competent API
Browse files Browse the repository at this point in the history
  • Loading branch information
Double0negative authored and Double0negative committed Jul 17, 2013
1 parent 0cf8965 commit ee9214e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/mcsg/survivalgames/Game.java
Expand Up @@ -15,6 +15,8 @@
import org.bukkit.plugin.Plugin;
import org.mcsg.survivalgames.MessageManager.PrefixType;
import org.mcsg.survivalgames.api.PlayerJoinArenaEvent;
import org.mcsg.survivalgames.api.PlayerKilledEvent;
import org.mcsg.survivalgames.api.PlayerLeaveArenaEvent;
import org.mcsg.survivalgames.hooks.HookManager;
import org.mcsg.survivalgames.logging.QueueManager;
import org.mcsg.survivalgames.stats.StatsManager;
Expand Down Expand Up @@ -218,6 +220,7 @@ public boolean addPlayer(Player p) {
msgmgr.sendMessage(PrefixType.INFO, "Joining Arena " + gameID, p);
PlayerJoinArenaEvent joinarena = new PlayerJoinArenaEvent(p, GameManager.getInstance().getGame(gameID));
Bukkit.getServer().getPluginManager().callEvent(joinarena);
if(joinarena.isCancelled()) return false;
boolean placed = false;
int spawnCount = SettingsManager.getInstance().getSpawnCount(gameID);

Expand Down Expand Up @@ -517,6 +520,7 @@ public void removePlayer(Player p, boolean b) {

HookManager.getInstance().runHook("PLAYER_REMOVED", "player-"+p.getName());

PlayerLeaveArenaEvent pl = new PlayerLeaveArenaEvent(p, this, b);

LobbyManager.getInstance().updateWall(gameID);
}
Expand Down Expand Up @@ -547,6 +551,7 @@ public void killPlayer(Player p, boolean left) {

activePlayers.remove(p);
inactivePlayers.add(p);
PlayerKilledEvent pk = null;
if (left) {
msgFall(PrefixType.INFO, "game.playerleavegame","player-"+p.getName() );
} else {
Expand All @@ -562,19 +567,26 @@ public void killPlayer(Player p, boolean left) {
"item-"+((killer!=null)?ItemReader.getFriendlyItemName(killer.getItemInHand().getType()) : "Unknown Item"));
if(killer != null && p != null)
sm.addKill(killer, p, gameID);
pk = new PlayerKilledEvent(p, this, killer, p.getLastDamageCause().getCause());
}
else{
msgFall(PrefixType.INFO, "death."+p.getLastDamageCause().getEntityType(), "player-"
+(SurvivalGames.auth.contains(p.getName()) ? ChatColor.DARK_RED + "" + ChatColor.BOLD : "")
+ p.getName(), "killer-"+p.getLastDamageCause().getEntityType());
pk = new PlayerKilledEvent(p, this, null, p.getLastDamageCause().getCause());

}
break;
default:
msgFall(PrefixType.INFO, "death."+p.getLastDamageCause().getCause(),
"player-"+(SurvivalGames.auth.contains(p.getName()) ? ChatColor.DARK_RED + "" + ChatColor.BOLD : "") + p.getName(),
"killer-"+p.getLastDamageCause().getCause());
pk = new PlayerKilledEvent(p, this, null, p.getLastDamageCause().getCause());

break;
}
Bukkit.getServer().getPluginManager().callEvent(pk);

if (getActivePlayers() > 1) {
for (Player pl: getAllPlayers()) {
msgmgr.sendMessage(PrefixType.INFO, ChatColor.DARK_AQUA + "There are " + ChatColor.YELLOW + ""
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/mcsg/survivalgames/GameManager.java
Expand Up @@ -194,12 +194,6 @@ public Game getGame(int a) {
}

public void removePlayer(Player p, boolean b) {
for (Game g : games) {
if (g.getAllPlayers().contains(p)) {
PlayerLeaveArenaEvent leavearena = new PlayerLeaveArenaEvent(p, g);
Bukkit.getServer().getPluginManager().callEvent(leavearena);
}
}
getGame(getPlayerGameId(p)).removePlayer(p, b);
}

Expand Down
@@ -1,17 +1,19 @@
package org.mcsg.survivalgames.api;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.mcsg.survivalgames.Game;



public class PlayerJoinArenaEvent extends Event {
public class PlayerJoinArenaEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();
private Player player;
private Game game;
private boolean cancelled = false;

public PlayerJoinArenaEvent(Player p, Game g) {
player = p;
Expand All @@ -33,4 +35,14 @@ public HandlerList getHandlers() {
public static HandlerList getHandlerList() {
return handlers;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean arg0) {
cancelled = arg0;
}
}
Expand Up @@ -12,8 +12,9 @@ public class PlayerLeaveArenaEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Player player;
private Game game;

public PlayerLeaveArenaEvent(Player p, Game g) {
private boolean logout;

public PlayerLeaveArenaEvent(Player p, Game g, boolean logout) {
player = p;
game = g;
}
Expand All @@ -29,6 +30,10 @@ public Game getGame() {
public HandlerList getHandlers() {
return handlers;
}

public boolean isLogout(){
return logout;
}

public static HandlerList getHandlerList() {
return handlers;
Expand Down
Expand Up @@ -70,7 +70,7 @@ public void rollback(final int id, final boolean shutdown){
else{
Bukkit.getScheduler().scheduleSyncDelayedTask(GameManager.getInstance().getPlugin(),
new RemoveEntities(id), 5);
}
}//


}
Expand Down Expand Up @@ -220,7 +220,7 @@ public void run(){
new Rollback(id, shutdown, totalRollback + rb, iteration+1, time), 1);
}
else{
SurvivalGames.$ ("Arena "+id+" reset. Rolled back "+(totalRollback+rb)+" blocks in "+iteration+" iterations ("+pt+" blocks per iteration Total time spent rolling back was "+time+"ms");
SurvivalGames.$ ("Arena "+id+" reset. Rolled back "+(totalRollback+rb)+" blocks in "+iteration+" iterations ("+pt+" blocks per iteration Total time spent rolling back was "+time+"ms)");
game.resetCallback();
}
}else{
Expand Down

0 comments on commit ee9214e

Please sign in to comment.