@Override public boolean execute( SimplePVPToggle plugin, CommandSender sender, String commandLabel, String[] args) { final Localisation localisation = plugin.getLocalisation(); if (args.length > 0) { final String path = "Server.Default"; final boolean current = plugin.getConfig().getBoolean(path); final Boolean newValue = BooleanParser.parse(args[0], current); if (newValue == null) { sender.sendMessage(localisation.get(LocalisationEntry.ERR_SPECIFY_STATUS)); return false; } plugin.getConfig().set(path, newValue.booleanValue()); plugin.saveConfig(); sender.sendMessage( localisation.get( LocalisationEntry.MSG_SERVER_PVP_SET, new Object[] {plugin.getConfig().getBoolean(path)})); for (Player p : plugin.getServer().getOnlinePlayers()) { TagUtils.refreshPlayer(p, new HashSet<>(p.getWorld().getPlayers()), plugin); } return true; } else { sender.sendMessage(localisation.get(LocalisationEntry.ERR_SPECIFY_STATUS)); return false; } }
/** * Entity damaged by another entity event. Cancels the event and sends damager a message if either * damager or attacked player have not enabled PvP * * @param event event being handled */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { if (event.getEntity() instanceof Player) { final Player attackedPlayer = (Player) event.getEntity(); final Player attacker; if (event.getDamager() instanceof Player) { attacker = (Player) event.getDamager(); } else if (event.getDamager() instanceof Projectile) { if (((Projectile) event.getDamager()).getShooter() instanceof Player) { attacker = (Player) ((Projectile) event.getDamager()).getShooter(); } else { return; } } else { return; } final World world = attacker.getWorld(); final Localisation localisation = plugin.getLocalisation(); if (PVPConfigUtils.getPlayerStatus(attacker, world, plugin)) { if (PVPConfigUtils.getPlayerStatus(attackedPlayer, world, plugin)) { LastPVPActionTimeConfigUtils.update(attacker, world, plugin); if (DebugConfigUtils.getDebugEnabled(plugin)) { attacker.sendMessage( localisation.get( LocalisationEntry.DEBUG_ATTACKED_PLAYER, new Object[] {attackedPlayer.getDisplayName(), event.getDamage()})); attackedPlayer.sendMessage( localisation.get( LocalisationEntry.DEBUG_ATTACKED_BY_PLAYER, new Object[] {attacker.getDisplayName(), event.getDamage()})); } } else { event.setCancelled(true); attacker.sendMessage( localisation.get( LocalisationEntry.MSG_ATTACK_CANCELLED_PLAYER_DOES_NOT_HAVE_PVP_ENABLED, new Object[] {attackedPlayer.getDisplayName()})); } } else { event.setCancelled(true); attacker.sendMessage( localisation.get(LocalisationEntry.MSG_ATTACK_CANCELLED_PVP_NOT_ENABLED)); } // Stop arrows bouncing back, possibly hitting you. if ((event.isCancelled()) && (event.getDamager() instanceof Projectile)) { ((Projectile) event.getDamager()).setBounce(false); } } }
@Override public String getDescription(Localisation localisation) { return localisation.get(LocalisationEntry.DESCRIPTION_SET_SERVER_DEFAULT); }