public void playerLeave(final Player p, boolean teleport) { msgFall(PrefixType.INFO, "game.playerleavegame", "player-" + p.getName()); if (teleport) { p.teleport(SettingsManager.getInstance().getLobbySpawn()); } // Remove any potion/fire effects for (PotionEffect effect : p.getActivePotionEffects()) { p.removePotionEffect(effect.getType()); } if (p.getFireTicks() > 0) { p.setFireTicks(0); } sm.removePlayer(p, gameID); scoreBoard.removePlayer(p); activePlayers.remove(p); inactivePlayers.remove(p); voted.remove(p); for (Object in : spawns.keySet().toArray()) { if (spawns.get(in) == p) spawns.remove(in); } HookManager.getInstance().runHook("PLAYER_REMOVED", "player-" + p.getName()); LobbyManager.getInstance().updateWall(gameID); if (activePlayers.size() < 2 && mode == GameMode.INGAME) { mode = GameMode.FINISHING; tasks.add( Bukkit.getScheduler() .scheduleSyncDelayedTask( GameManager.getInstance().getPlugin(), new Runnable() { public void run() { playerWin(p); endGame(); } }, 1L)); } }
public void vote(Player pl) { if (GameMode.STARTING == mode) { msgmgr.sendMessage(PrefixType.WARNING, "Game already starting!", pl); return; } if (GameMode.WAITING != mode) { msgmgr.sendMessage(PrefixType.WARNING, "Game already started!", pl); return; } if (voted.contains(pl)) { msgmgr.sendMessage(PrefixType.WARNING, "You already voted!", pl); return; } vote++; voted.add(pl); msgFall(PrefixType.INFO, "game.playervote", "player-" + pl.getName()); HookManager.getInstance().runHook("PLAYER_VOTE", "player-" + pl.getName()); scoreBoard.playerLiving(pl); /*for(Player p: activePlayers){ p.sendMessage(ChatColor.AQUA+pl.getName()+" Voted to start the game! "+ Math.round((vote +0.0) / ((getActivePlayers() +0.0)*100)) +"/"+((c.getInt("auto-start-vote")+0.0))+"%"); }*/ // Bukkit.getServer().broadcastPrefixType((vote +0.0) / (getActivePlayers() +0.0) +"% voted, // needs "+(c.getInt("auto-start-vote")+0.0)/100); if ((((vote + 0.0) / (getActivePlayers() + 0.0)) >= (config.getInt("auto-start-vote") + 0.0) / 100) && getActivePlayers() > 1) { countdown(config.getInt("auto-start-time")); for (Player p : activePlayers) { // p.sendMessage(ChatColor.LIGHT_PURPLE + "Game Starting in " + // c.getInt("auto-start-time")); msgmgr.sendMessage( PrefixType.INFO, "Game starting in " + config.getInt("auto-start-time") + "!", p); scoreBoard.playerLiving(pl); } } }
/* * * ################################################ * * HANDLE PLAYER DEATH * * PLAYERS DIE A REAL DEATH WHICH IS HANDLED HERE * * ################################################ * * */ public void playerDeath(PlayerDeathEvent e) { final Player p = e.getEntity(); if (!activePlayers.contains(p)) return; sm.playerDied(p, activePlayers.size(), gameID, new Date().getTime() - startTime); scoreBoard.playerDead(p); activePlayers.remove(p); inactivePlayers.add(p); for (Object in : spawns.keySet().toArray()) { if (spawns.get(in) == p) spawns.remove(in); } PlayerKilledEvent pk = null; if (mode != GameMode.WAITING && p.getLastDamageCause() != null && p.getLastDamageCause().getCause() != null) { DamageCause cause = p.getLastDamageCause().getCause(); switch (cause) { case ENTITY_ATTACK: if (p.getLastDamageCause().getEntityType() == EntityType.PLAYER) { EntityType enttype = p.getLastDamageCause().getEntityType(); Player killer = p.getKiller(); String killername = "Unknown"; if (killer != null) { killername = killer.getName(); } String itemname = "Unknown Item"; if (killer != null) { itemname = ItemReader.getFriendlyItemName(killer.getItemInHand().getType()); } msgFall( PrefixType.INFO, "death." + enttype, "player-" + p.getName(), "killer-" + killername, "item-" + itemname); if (killer != null && p != null) { sm.addKill(killer, p, gameID); scoreBoard.incScore(killer); } pk = new PlayerKilledEvent(p, this, killer, cause); } else { msgFall( PrefixType.INFO, "death." + p.getLastDamageCause().getEntityType(), "player-" + p.getName(), "killer-" + p.getLastDamageCause().getEntityType()); pk = new PlayerKilledEvent(p, this, null, cause); } break; default: msgFall( PrefixType.INFO, "death." + cause.name(), "player-" + p.getName(), "killer-" + cause); pk = new PlayerKilledEvent(p, this, null, cause); break; } Bukkit.getServer().getPluginManager().callEvent(pk); if (getActivePlayers() > 1) { for (Player pl : getAllPlayers()) { msgmgr.sendMessage( PrefixType.INFO, ChatColor.DARK_AQUA + "There are " + ChatColor.YELLOW + "" + getActivePlayers() + ChatColor.DARK_AQUA + " players remaining!", pl); } } } for (Player pe : activePlayers) { Location l = pe.getLocation(); l.setY(l.getWorld().getMaxHeight()); l.getWorld().strikeLightningEffect(l); } if (getActivePlayers() <= config.getInt("endgame.players") && config.getBoolean("endgame.fire-lighting.enabled") && !endgameRunning) { tasks.add( Bukkit.getScheduler() .scheduleSyncRepeatingTask( GameManager.getInstance().getPlugin(), new EndgameManager(), 0, config.getInt("endgame.fire-lighting.interval") * 20)); } if (activePlayers.size() < 2 && mode == GameMode.INGAME) { mode = GameMode.FINISHING; LobbyManager.getInstance().updateWall(gameID); tasks.add( Bukkit.getScheduler() .scheduleSyncDelayedTask( GameManager.getInstance().getPlugin(), new Runnable() { public void run() { playerWin(p); endGame(); } }, 10L)); } LobbyManager.getInstance().updateWall(gameID); }
@SuppressWarnings("deprecation") public boolean addPlayer(final Player p) { if (SettingsManager.getInstance().getLobbySpawn() == null) { msgmgr.sendFMessage(PrefixType.WARNING, "error.nolobbyspawn", p); return false; } if (!p.hasPermission("sg.arena.join." + gameID)) { debug("permission needed to join arena: " + "sg.arena.join." + gameID); msgmgr.sendFMessage(PrefixType.WARNING, "game.nopermission", p, "arena-" + gameID); return false; } HookManager.getInstance() .runHook( "GAME_PRE_ADDPLAYER", "arena-" + gameID, "player-" + p.getName(), "maxplayers-" + spawns.size(), "players-" + activePlayers.size()); GameManager.getInstance().removeFromOtherQueues(p, gameID); if (GameManager.getInstance().getPlayerGameId(p) != -1) { if (GameManager.getInstance().isPlayerActive(p)) { msgmgr.sendMessage(PrefixType.ERROR, "Cannot join multiple games!", p); return false; } } if (p.isInsideVehicle()) { p.leaveVehicle(); } if (spectators.contains(p)) removeSpectator(p); if (mode == GameMode.WAITING || mode == GameMode.STARTING) { if (activePlayers.size() < SettingsManager.getInstance().getSpawnCount(gameID)) { msgmgr.sendMessage(PrefixType.INFO, "Joining Arena '" + name + "'", 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); for (int a = 1; a <= spawnCount; a++) { if (spawns.get(a) == null) { placed = true; spawns.put(a, p); p.setGameMode(org.bukkit.GameMode.SURVIVAL); // p.teleport(SettingsManager.getInstance().getLobbySpawn()); p.teleport(SettingsManager.getInstance().getSpawnPoint(gameID, a)); p.setHealth(p.getMaxHealth()); p.setFoodLevel(20); p.getInventory().clear(); p.getEquipment().setArmorContents(null); p.updateInventory(); p.setFlying(false); p.setAllowFlight(false); p.setWalkSpeed(0.2F); p.setFireTicks(0); activePlayers.add(p); sm.addPlayer(p, gameID); scoreBoard.addPlayer(p); hookvars.put("activeplayers", activePlayers.size() + ""); LobbyManager.getInstance().updateWall(gameID); HookManager.getInstance() .runHook("GAME_POST_ADDPLAYER", "activePlayers-" + activePlayers.size()); if (spawnCount == activePlayers.size()) { countdown(5); } Bukkit.getServer() .getScheduler() .scheduleSyncDelayedTask( GameManager.getInstance().getPlugin(), new Runnable() { public void run() { p.setFlying(false); p.setAllowFlight(false); p.setWalkSpeed(0.2F); p.setFireTicks(0); p.getInventory().clear(); p.getEquipment().setArmorContents(null); p.updateInventory(); showMenu(p); for (PotionEffect effect : p.getActivePotionEffects()) { p.removePotionEffect(effect.getType()); } } }, 1L); break; } } if (!placed) { msgmgr.sendFMessage(PrefixType.ERROR, "error.gamefull", p, "arena-" + gameID); return false; } } else if (SettingsManager.getInstance().getSpawnCount(gameID) == 0) { msgmgr.sendMessage(PrefixType.WARNING, "No spawns set for Arena " + gameID + "!", p); return false; } else { msgmgr.sendFMessage(PrefixType.WARNING, "error.gamefull", p, "arena-" + gameID); return false; } msgFall( PrefixType.INFO, "game.playerjoingame", "player-" + p.getName(), "activeplayers-" + getActivePlayers(), "maxplayers-" + SettingsManager.getInstance().getSpawnCount(gameID)); if (activePlayers.size() >= config.getInt("auto-start-players") && !countdownRunning) countdown(config.getInt("auto-start-time")); return true; } else { if (config.getBoolean("enable-player-queue")) { if (!queue.contains(p)) { queue.add(p); msgmgr.sendFMessage( PrefixType.INFO, "game.playerjoinqueue", p, "queuesize-" + queue.size()); } int a = 1; for (Player qp : queue) { if (qp == p) { msgmgr.sendFMessage(PrefixType.INFO, "game.playercheckqueue", p, "queuepos-" + a); break; } a++; } } } if (mode == GameMode.INGAME) msgmgr.sendFMessage(PrefixType.WARNING, "error.alreadyingame", p); else if (mode == GameMode.DISABLED) msgmgr.sendFMessage(PrefixType.WARNING, "error.gamedisabled", p, "arena-" + gameID); else if (mode == GameMode.RESETING) msgmgr.sendFMessage(PrefixType.WARNING, "error.gamereseting", p); else msgmgr.sendMessage(PrefixType.INFO, "Cannot join game!", p); LobbyManager.getInstance().updateWall(gameID); return false; }