public void clean() { PlayerInventory inv = this.player.getInventory(); inv.setArmorContents(new ItemStack[4]); inv.setContents(new ItemStack[] {}); this.player.setAllowFlight(false); this.player.setFlying(false); this.player.setExp(0.0F); this.player.setLevel(0); this.player.setSneaking(false); this.player.setSprinting(false); this.player.setFoodLevel(20); this.player.setMaxHealth(20.0D); this.player.setHealth(20.0D); this.player.setFireTicks(0); this.player.setGameMode(GameMode.SURVIVAL); boolean teamnameOnTab = Main.getInstance().getBooleanConfig("teamname-on-tab", true); boolean overwriteNames = Main.getInstance().getBooleanConfig("overwrite-names", false); if (overwriteNames) { Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player); if (game != null) { Team team = game.getPlayerTeam(this.player); if (team != null) { this.player.setDisplayName(team.getChatColor() + this.player.getName()); } else { this.player.setDisplayName(this.player.getName()); } } } if (teamnameOnTab && Utils.isSupportingTitles()) { Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player); if (game != null) { Team team = game.getPlayerTeam(this.player); if (team != null) { this.player.setPlayerListName( team.getChatColor() + team.getName() + ChatColor.WHITE + " | " + team.getChatColor() + this.player.getName()); } else { this.player.setPlayerListName(this.player.getName()); } } } if (this.player.isInsideVehicle()) { this.player.leaveVehicle(); } for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.updateInventory(); }
@EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent ce) { if (ce.isCancelled()) { return; } Player player = ce.getPlayer(); Game game = Main.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { boolean seperateGameChat = Main.getInstance().getBooleanConfig("seperate-game-chat", true); if (!seperateGameChat) { return; } Iterator<Player> recipiens = ce.getRecipients().iterator(); while (recipiens.hasNext()) { Player recipient = recipiens.next(); Game recipientGame = Main.getInstance().getGameManager().getGameOfPlayer(recipient); if (recipientGame != null) { recipiens.remove(); } } return; } if (game.getState() == GameState.STOPPED) { return; } Team team = game.getPlayerTeam(player); String message = ce.getMessage(); boolean isSpectator = game.isSpectator(player); if (Main.getInstance().getBooleanConfig("overwrite-names", false)) { if (team == null || isSpectator) { player.setDisplayName(ChatColor.stripColor(player.getName())); player.setPlayerListName(ChatColor.stripColor(player.getName())); } else { player.setDisplayName(team.getChatColor() + ChatColor.stripColor(player.getName())); player.setPlayerListName(team.getChatColor() + ChatColor.stripColor(player.getName())); } } if (Main.getInstance().getBooleanConfig("teamname-on-tab", false) && Utils.isSupportingTitles()) { if (team == null || isSpectator) { player.setPlayerListName(ChatColor.stripColor(player.getDisplayName())); } else { player.setPlayerListName( team.getChatColor() + team.getName() + ChatColor.WHITE + " | " + team.getChatColor() + ChatColor.stripColor(player.getDisplayName())); } } if (game.getState() != GameState.RUNNING && game.getState() == GameState.WAITING) { String format = null; if (team == null) { format = this.getChatFormat( Main.getInstance().getStringConfig("lobby-chatformat", "$player$: $msg$"), null, false, true); } else { format = this.getChatFormat( Main.getInstance().getStringConfig("ingame-chatformat", "<$team$>$player$: $msg$"), team, false, true); } ce.setFormat(format); return; } String toAllPrefix = Main.getInstance().getConfig().getString("chat-to-all-prefix", "@"); if (message.trim().startsWith(toAllPrefix) || isSpectator || (game.getCycle().isEndGameRunning() && Main.getInstance().getBooleanConfig("global-chat-after-end", true))) { boolean seperateSpectatorChat = Main.getInstance().getBooleanConfig("seperate-spectator-chat", false); message = message.trim(); if (!isSpectator && !(game.getCycle().isEndGameRunning() && Main.getInstance().getBooleanConfig("global-chat-after-end", true))) { ce.setMessage(message.substring(1, message.length())); } else { ce.setMessage(message); } String format = this.getChatFormat( Main.getInstance() .getStringConfig("ingame-chatformat-all", "[$all$] <$team$>$player$: $msg$"), team, isSpectator, true); ce.setFormat(format); if (!Main.getInstance().isBungee() || seperateSpectatorChat) { Iterator<Player> recipiens = ce.getRecipients().iterator(); while (recipiens.hasNext()) { Player recipient = recipiens.next(); if (!game.isInGame(recipient)) { recipiens.remove(); continue; } if (!seperateSpectatorChat) { continue; } if (isSpectator && !game.isSpectator(recipient)) { recipiens.remove(); } else if (!isSpectator && game.isSpectator(recipient)) { recipiens.remove(); } } } } else { message = message.trim(); ce.setMessage(message); ce.setFormat( this.getChatFormat( Main.getInstance().getStringConfig("ingame-chatformat", "<$team$>$player$: $msg$"), team, false, false)); Iterator<Player> recipiens = ce.getRecipients().iterator(); while (recipiens.hasNext()) { Player recipient = recipiens.next(); if (!game.isInGame(recipient) || !team.isInTeam(recipient)) { recipiens.remove(); } } } }
@EventHandler(priority = EventPriority.HIGH) public void onInteractEntity(PlayerInteractEntityEvent event) { if (event.getRightClicked() == null) { return; } Entity entity = event.getRightClicked(); Player player = event.getPlayer(); if (!player.hasMetadata("bw-addteamjoin")) { if (!(entity instanceof LivingEntity)) { return; } LivingEntity livEntity = (LivingEntity) entity; Game game = Main.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.WAITING) { return; } Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName())); if (team == null) { return; } game.playerJoinTeam(player, team); event.setCancelled(true); return; } List<MetadataValue> values = player.getMetadata("bw-addteamjoin"); if (values == null || values.size() == 0) { return; } event.setCancelled(true); TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0); if (!((boolean) value.value())) { return; } if (!(entity instanceof LivingEntity)) { player.sendMessage( ChatWriter.pluginMessage(ChatColor.RED + Main._l("errors.entitynotcompatible"))); return; } LivingEntity living = (LivingEntity) entity; living.setRemoveWhenFarAway(false); living.setCanPickupItems(false); living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName()); living.setCustomNameVisible( Main.getInstance().getBooleanConfig("jointeam-entity.show-name", true)); if (Utils.isSupportingTitles()) { if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) { Utils.equipArmorStand(living, value.getTeam()); } } player.removeMetadata("bw-addteamjoin", Main.getInstance()); player.sendMessage( ChatWriter.pluginMessage( ChatColor.GREEN + Main._l( "success.teamjoinadded", ImmutableMap.of( "team", value.getTeam().getChatColor() + value.getTeam().getDisplayName() + ChatColor.GREEN)))); }