@Command( aliases = {"toggle"}, desc = "Toggle a setting.", usage = "<setting>", min = 1) public static void toggle(final CommandContext cmd, CommandSender sender) throws CommandException { if (sender instanceof Player) { if (Settings.getSettingByName(cmd.getString(0)) != null) { int index = Settings.getSettingByName(cmd.getString(0)) .getValues() .indexOf( Settings.getSettingByName(cmd.getString(0)).getValueByPlayer((Player) sender)); index++; if (index >= Settings.getSettingByName(cmd.getString(0)).getValues().size()) index = 0; Bukkit.dispatchCommand( sender, "set " + cmd.getString(0) + " " + Settings.getSettingByName(cmd.getString(0)).getValues().get(index).getValue()); } else throw new CommandException("No setting by this name!"); } else throw new CommandException("Console cannot use this command."); }
@Command( aliases = {"set"}, desc = "Set a setting to a specific value.", usage = "<setting> <value>", min = 2) public static void set(final CommandContext cmd, CommandSender sender) throws CommandException { if (sender instanceof Player) { if (Settings.getSettingByName(cmd.getString(0)) != null) { if (Settings.getSettingByName(cmd.getString(0)).getSettingValueByName(cmd.getString(1)) != null) { Settings.getSettingByName(cmd.getString(0)) .setValueByPlayer( (Player) sender, Settings.getSettingByName(cmd.getString(0)) .getSettingValueByName(cmd.getString(1))); sender.sendMessage( ChatColor.YELLOW + Settings.getSettingByName(cmd.getString(0)).getNames().get(0) + ": " + ChatColor.WHITE + Settings.getSettingByName(cmd.getString(0)) .getSettingValueByName(cmd.getString(1)) .getValue()); if (Settings.getSettingByName("Observers") != null && Settings.getSettingByName(cmd.getString(0)) .equals(Settings.getSettingByName("Observers"))) { Bukkit.getServer() .getPluginManager() .callEvent(new PlayerVisibilityChangeEvent((Player) sender)); } } else throw new CommandException("No value by this name!"); } else throw new CommandException("No setting by this name!"); } else throw new CommandException("Console cannot use this command."); }
@Command( aliases = {"settings"}, desc = "List all settings.", usage = "[page]") public static void settings(final CommandContext cmd, CommandSender sender) throws CommandException { if (cmd.argsLength() == 0) { Bukkit.dispatchCommand(sender, "settings 1"); } else { int page = cmd.getInteger(0); if (page > (Settings.getSettings().size() + 7) / 8) throw new CommandException( "Invalid page number specified! " + ((Settings.getSettings().size() + 7) / 8) + " total pages."); sender.sendMessage( ChatColor.RED + "" + ChatColor.STRIKETHROUGH + "--------------" + ChatColor.YELLOW + " Settings (Page " + page + " of " + ((Settings.getSettings().size() + 7) / 8) + ") " + ChatColor.RED + "" + ChatColor.STRIKETHROUGH + "--------------"); for (int i = (page - 1) * 8; i < page * 8; i++) { if (i < Settings.getSettings().size()) sender.sendMessage( ChatColor.YELLOW + Settings.getSettings().get(i).getNames().get(0) + ": " + ChatColor.WHITE + Settings.getSettings().get(i).getDescription()); } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { if (!event.isCancelled()) { List<Block> objectiveBlownUp = new ArrayList<>(); for (Block block : event.blockList()) { if (getBlocks().contains(block)) { objectiveBlownUp.add(block); } } boolean oldState = this.isTouched(); boolean blownUp = false; Player eventPlayer = null; int originalPercent = getPercent(); boolean touchMessage = false; for (Block block : objectiveBlownUp) { boolean blockDestroyed = false; if (TntTracker.getWhoPlaced(event.getEntity()) != null) { UUID player = TntTracker.getWhoPlaced(event.getEntity()); if (Bukkit.getOfflinePlayer(player).isOnline()) { if (TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)) == team) { event.blockList().remove(block); } else { if (!playersTouched.contains(player)) { playersTouched.add(player); TeamModule teamModule = TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)); if (this.show && !this.completed) { TeamUtils.getTeamChannel(teamModule) .sendLocalizedMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + Bukkit.getPlayer(player).getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE)); for (Player player1 : Bukkit.getOnlinePlayers()) { if (TeamUtils.getTeamByPlayer(player1) != null && TeamUtils.getTeamByPlayer(player1).isObserver()) { player1.sendMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + Bukkit.getPlayer(player).getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE) .getMessage(player1.getLocale())); } if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds") .getValueByPlayer(player1) .getValue() .equalsIgnoreCase("on")) { player1.playSound(player1.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1); } } touchMessage = true; } } blockDestroyed = true; blownUp = true; eventPlayer = Bukkit.getPlayer(player); } } else { if (!playersTouched.contains(player)) { playersTouched.add(player); } blockDestroyed = true; blownUp = true; } } else { blockDestroyed = true; blownUp = true; } if (blockDestroyed) { this.complete++; if (eventPlayer != null) this.playersCompleted.put( eventPlayer.getUniqueId(), (playersCompleted.containsKey(eventPlayer.getUniqueId()) ? playersCompleted.get(eventPlayer.getUniqueId()) + 1 : 1)); if ((this.complete / size) >= this.required && !this.completed) { this.completed = true; if (this.show) { for (Player player : Bukkit.getOnlinePlayers()) player.sendMessage( ChatColor.GRAY + new UnlocalizedChatMessage( "{0}", new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DESTROYED, team.getCompleteName() + ChatColor.GRAY, ChatColor.AQUA + name + ChatColor.GRAY, getWhoDestroyed(player.getLocale()))) .getMessage(player.getLocale())); Bukkit.getLogger() .info( ChatColor.GRAY + new UnlocalizedChatMessage( "{0}", new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DESTROYED, team.getCompleteName() + ChatColor.GRAY, ChatColor.AQUA + name + ChatColor.GRAY, getWhoDestroyed(Locale.getDefault().toString()))) .getMessage(Locale.getDefault().toString())); } ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, eventPlayer); Bukkit.getServer().getPluginManager().callEvent(compEvent); } } } if (!this.completed && blownUp) { ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent( this, eventPlayer, !oldState || (getPercent() != originalPercent), touchMessage); Bukkit.getServer().getPluginManager().callEvent(touchEvent); } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { if (!event.isCancelled()) { if (getBlocks().contains(event.getBlock())) { if (TeamUtils.getTeamByPlayer(event.getPlayer()) != team) { boolean touchMessage = false; if (!playersTouched.contains(event.getPlayer().getUniqueId())) { playersTouched.add(event.getPlayer().getUniqueId()); TeamModule teamModule = TeamUtils.getTeamByPlayer(event.getPlayer()); if (this.show && !this.completed) { TeamUtils.getTeamChannel(teamModule) .sendLocalizedMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE)); for (Player player : Bukkit.getOnlinePlayers()) { if (TeamUtils.getTeamByPlayer(player) != null && TeamUtils.getTeamByPlayer(player).isObserver()) { player.sendMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE) .getMessage(player.getLocale())); } if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds") .getValueByPlayer(player) .getValue() .equalsIgnoreCase("on")) { player.playSound(player.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1); } } } } boolean oldState = this.isTouched(); this.complete++; this.playersCompleted.put( event.getPlayer().getUniqueId(), (playersCompleted.containsKey(event.getPlayer().getUniqueId()) ? playersCompleted.get(event.getPlayer().getUniqueId()) + 1 : 1)); if ((this.complete / size) >= this.required && !this.completed) { this.completed = true; event.setCancelled(false); if (this.show) { for (Player player : Bukkit.getOnlinePlayers()) player.sendMessage( ChatColor.GRAY + new UnlocalizedChatMessage( "{0}", new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DESTROYED, team.getCompleteName() + ChatColor.GRAY, ChatColor.AQUA + name + ChatColor.GRAY, getWhoDestroyed(player.getLocale()))) .getMessage(player.getLocale())); } FireworkUtil.spawnFirework( event.getPlayer().getLocation(), event.getPlayer().getWorld(), MiscUtils.convertChatColorToColor(team.getColor())); ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer()); Bukkit.getServer().getPluginManager().callEvent(compEvent); } else if (!this.completed) { ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent( this, event.getPlayer(), !oldState || showPercent, touchMessage); Bukkit.getServer().getPluginManager().callEvent(touchEvent); } } else { event.setCancelled(true); if (this.show) ChatUtils.sendWarningMessage( event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_OBJECTIVE)); } } } }