@EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (!repairable && !isComplete()) { if (region.contains(event.getBlock().getLocation()) && partOfObjective(event.getBlock())) { if (TeamUtils.getTeamByPlayer(event.getPlayer()).getName() != team.getName()) { ChatUtils.sendWarningMessage( event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_ENEMY_OBJECTIVE)); event.setCancelled(true); } else { ChatUtils.sendWarningMessage( event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_REPAIR_OBJECTIVE)); event.setCancelled(true); } } } }
@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)); } } } }