@EventHandler(priority = EventPriority.NORMAL) public void onEntityDeath(final EntityDeathEvent e) { Entity ent = e.getEntity(); if (ent instanceof Creature) { Creature creature = (Creature) e.getEntity(); switch (creature.getType()) { case CHICKEN: case COW: case PIG: case SHEEP: case VILLAGER: case WOLF: Player p = creature.getKiller(); if (p != null) { GamePlayer rmp = GamePlayer.getPlayerByName(p.getName()); if (rmp != null) { if (rmp.isIngame()) { Game game = rmp.getGameInProgress(); game.addLog(creature); } } } break; } } }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityExplode(final EntityExplodeEvent e) { if (Game.getGames().size() != 0) { List<Block> blockList = e.blockList(); List<Game> affectedGames = new ArrayList<Game>(); for (Game game : Game.getGames().values()) { if (affectedGames.contains(game)) continue; GameConfig config = game.getGameConfig(); List<Block> gameBlocks = config.getPartList().getList(); for (Block b : blockList) { if (gameBlocks.contains(b)) { affectedGames.add(game); break; } } } if (affectedGames.size() != 0) { e.setCancelled(true); for (Game game : affectedGames) { GameConfig config = game.getGameConfig(); game.broadcastMessage( Text.getLabelArgs("game.canceled_explosion", config.getName(), "" + config.getId())); } } Entity ent = e.getEntity(); if ((ent instanceof Creature) || (ent instanceof Explosive)) { Debug.warning("Entity found"); World w = ent.getWorld(); for (Game rmGame : Game.getGames().values()) { if (rmGame.getGameConfig().getWorld() == w) { Debug.warning("Same world found"); if (rmGame.inRangeXZ(ent, rmGame.getGameConfig().getSettingInt(Setting.playarea))) { rmGame.addLog(blockList.toArray(new Block[blockList.size()])); return; } for (GamePlayer rmp : rmGame.getOnlineTeamPlayers()) { Debug.warning("rmp: " + rmp.getName()); if (rmp.inRange(ent.getLocation(), 32)) { rmGame.addLog(blockList.toArray(new Block[blockList.size()])); return; } else Debug.warning("not near location"); } } } } } }
/** изменяем ресурсы при новом ходе для текущего игрока */ private void cang_res() { curent_player.chang(Resources_player.BEASTS, curent_player.getRes(Resources_player.BEASTS_MOD)); curent_player.chang(Resources_player.BRICKS, curent_player.getRes(Resources_player.BRICKS_MOD)); curent_player.chang(Resources_player.GEMS, curent_player.getRes(Resources_player.GEMS_MOD)); n_curent_player.chang(Resources_player.BEASTS, 0); n_curent_player.chang(Resources_player.BRICKS, 0); n_curent_player.chang(Resources_player.GEMS, 0); n_curent_player.chang(Resources_player.BEASTS_MOD, 0); n_curent_player.chang(Resources_player.BRICKS_MOD, 0); n_curent_player.chang(Resources_player.GEMS_MOD, 0); }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityDamageByEntity(final EntityDamageByEntityEvent e) { Entity ent = e.getEntity(); Entity entDamager = e.getDamager(); if ((ent instanceof Player) && (entDamager instanceof Player)) { GamePlayer rmp = GamePlayer.getPlayerByName(((Player) ent).getName()); GamePlayer rmpDamager = GamePlayer.getPlayerByName(((Player) entDamager).getName()); if ((rmp != null) && (rmpDamager != null)) { if ((rmp.isIngame()) && (rmpDamager.isIngame())) { GameConfig config = rmp.getGame().getGameConfig(); Timer pvpTimer = config.getPvpTimer(); if (!config.getSettingBool(Setting.allowpvp)) { e.setCancelled(true); } else if (rmp.getTeam() == rmpDamager.getTeam()) { if (!config.getSettingBool(Setting.friendlyfire)) { e.setCancelled(true); } } else if ((rmp.isSafe()) || (rmpDamager.isSafe())) { e.setCancelled(true); rmpDamager.sendMessage(Text.getLabel("game.safezone.pvp")); } else if ((pvpTimer.isSet()) && (pvpTimer.isTicking())) { e.setCancelled(true); // rmpDamager.sendMessage(RMText.getLabelArgs("game.pvp.delay", // pvpTimer.getTextTimeRemaining())); rmpDamager.sendMessage(Text.getLabelArgs("game.pvp.disabled")); } } } } }
public void broadcast(String message) { for (GamePlayer p : players) { p.getPlayer().sendMessage(message); // You could add a prefix. } }
public static void main(String[] args) throws FileNotFoundException { GamePlayer p = new AlphaBuster("Alpha Buster Player"); // create player with nikename p.compete(args, 1); }