Try to unify player matching for hidden users:

kill, lightning and ptime still need cleanup
This commit is contained in:
KHobbits 2013-03-19 23:17:34 +00:00
parent 1d6ac42311
commit 8f6c61fa99
13 changed files with 119 additions and 81 deletions

View File

@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.craftbukkit.SetExpFix;
import java.util.List;
import java.util.Locale;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -117,7 +118,8 @@ public class Commandexp extends EssentialsCommand
private void showMatch(final Server server, final CommandSender sender, final String match) throws NotEnoughArgumentsException
{
boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(match))
final List<Player> matchedPlayers = server.matchPlayer(match);
for (Player matchPlayer : matchedPlayers)
{
foundUser = true;
final User target = ess.getUser(matchPlayer);
@ -132,11 +134,12 @@ public class Commandexp extends EssentialsCommand
private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException
{
boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(match))
final List<Player> matchedPlayers = server.matchPlayer(match);
for (Player matchPlayer : matchedPlayers)
{
foundUser = true;
final User target = ess.getUser(matchPlayer);
setExp(sender, target, amount, give);
foundUser = true;
}
if (!foundUser)
{

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -40,10 +41,17 @@ public class Commandext extends EssentialsCommand
private void extinguishPlayers(final Server server, final CommandSender sender, final String name) throws Exception
{
for (Player matchPlayer : server.matchPlayer(name))
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(name);
for (Player matchPlayer : matchedPlayers)
{
foundUser = true;
matchPlayer.setFireTicks(0);
sender.sendMessage(_("extinguishOthers", matchPlayer.getDisplayName()));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}

View File

@ -20,7 +20,7 @@ public class Commandfeed extends EssentialsCommand
{
if (args.length > 0 && user.isAuthorized("essentials.feed.others"))
{
feedOtherPlayers(server,user,args[0]);
feedOtherPlayers(server, user, args[0]);
}
else
{
@ -29,24 +29,25 @@ public class Commandfeed extends EssentialsCommand
user.sendMessage(_("feed"));
}
}
private void feedOtherPlayers(final Server server, final CommandSender sender, final String name)
private void feedOtherPlayers(final Server server, final CommandSender sender, final String name) throws NotEnoughArgumentsException
{
final List<Player> players = server.matchPlayer(name);
if (players.isEmpty())
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(name);
for (Player matchPlayer : matchedPlayers)
{
sender.sendMessage(_("playerNotFound"));
return;
}
for (Player player : players)
{
if (ess.getUser(player).isHidden())
if (ess.getUser(matchPlayer).isHidden())
{
continue;
}
player.setFoodLevel(20);
player.setSaturation(10);
sender.sendMessage(_("feedOther", player.getDisplayName()));
foundUser = true;
matchPlayer.setFoodLevel(20);
matchPlayer.setSaturation(10);
sender.sendMessage(_("feedOther", matchPlayer.getDisplayName()));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -60,16 +61,18 @@ public class Commandfly extends EssentialsCommand
user.sendMessage(_("flyMode", _(user.getAllowFlight() ? "enabled" : "disabled"), user.getDisplayName()));
}
private void flyOtherPlayers(final Server server, final CommandSender sender, final String[] args)
private void flyOtherPlayers(final Server server, final CommandSender sender, final String[] args) throws NotEnoughArgumentsException
{
for (Player matchPlayer : server.matchPlayer(args[0]))
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (player.isHidden())
{
continue;
}
foundUser = true;
if (args.length > 1)
{
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
@ -92,5 +95,9 @@ public class Commandfly extends EssentialsCommand
}
sender.sendMessage(_("flyMode", _(player.getAllowFlight() ? "enabled" : "disabled"), player.getDisplayName()));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import java.util.Locale;
import org.bukkit.GameMode;
import org.bukkit.Server;
@ -85,16 +86,17 @@ public class Commandgamemode extends EssentialsCommand
}
boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(player))
final List<Player> matchedPlayers = server.matchPlayer(player);
for (Player matchPlayer : matchedPlayers)
{
final User user = ess.getUser(matchPlayer);
if (user.isHidden())
{
continue;
}
user.setGameMode(gameMode);
sender.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
foundUser = true;
user.setGameMode(gameMode);
sender.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
}
if (!foundUser)
{

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -47,16 +48,18 @@ public class Commandgod extends EssentialsCommand
}
}
private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args)
private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args) throws NotEnoughArgumentsException
{
for (Player matchPlayer : server.matchPlayer(args[0]))
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (player.isHidden())
{
continue;
}
foundUser = true;
boolean enabled;
if (args.length > 1)
{
@ -78,5 +81,9 @@ public class Commandgod extends EssentialsCommand
player.sendMessage(_("godMode", (enabled ? _("enabled") : _("disabled"))));
sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", matchPlayer.getDisplayName())));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}

View File

@ -50,19 +50,22 @@ public class Commandheal extends EssentialsCommand
private void healOtherPlayers(final Server server, final CommandSender sender, final String name) throws Exception
{
final List<Player> players = server.matchPlayer(name);
if (players.isEmpty())
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(name);
for (Player matchPlayer : matchedPlayers)
{
throw new Exception(_("playerNotFound"));
}
for (Player p : players)
{
if (ess.getUser(p).isHidden())
if (ess.getUser(matchPlayer).isHidden())
{
continue;
}
healPlayer(p);
sender.sendMessage(_("healOther", p.getDisplayName()));
foundUser = true;
healPlayer(matchPlayer);
sender.sendMessage(_("healOther", matchPlayer.getDisplayName()));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -28,7 +29,8 @@ public class Commandkill extends EssentialsCommand
throw new NotEnoughArgumentsException("You need to specify a player to kill.");
}
for (Player matchPlayer : server.matchPlayer(args[0]))
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender instanceof Player && ((Player)sender).getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE);
server.getPluginManager().callEvent(ede);
@ -36,9 +38,8 @@ public class Commandkill extends EssentialsCommand
{
continue;
}
matchPlayer.damage(Short.MAX_VALUE);
if (matchPlayer.getHealth() > 0)
{
matchPlayer.setHealth(0);

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.LightningStrike;
@ -30,11 +31,6 @@ public class Commandlightning extends EssentialsCommand
}
}
if (server.matchPlayer(args[0]).isEmpty())
{
throw new Exception(_("playerNotFound"));
}
int power = 5;
if (args.length > 1)
{
@ -47,12 +43,13 @@ public class Commandlightning extends EssentialsCommand
}
}
for (Player matchPlayer : server.matchPlayer(args[0]))
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
sender.sendMessage(_("lightningUse", matchPlayer.getDisplayName()));
final LightningStrike strike = matchPlayer.getWorld().strikeLightningEffect(matchPlayer.getLocation());
if (!ess.getUser(matchPlayer).isGodModeEnabled())
{
matchPlayer.damage(power, strike);

View File

@ -56,49 +56,36 @@ public class Commandmsg extends EssentialsCommand
return;
}
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
if (matchedPlayers.isEmpty())
{
throw new Exception(_("playerNotFound"));
}
int i = 0;
for (Player matchedPlayer : matchedPlayers)
{
final User u = ess.getUser(matchedPlayer);
if (u.isHidden())
{
i++;
}
}
if (i == matchedPlayers.size())
{
throw new Exception(_("playerNotFound"));
}
for (Player matchedPlayer : matchedPlayers)
for (Player matchPlayer : matchedPlayers)
{
final User matchedUser = ess.getUser(matchedPlayer);
final User matchedUser = ess.getUser(matchPlayer);
if (sender instanceof Player && matchedUser.isHidden())
{
continue;
}
foundUser = true;
if (matchedUser.isAfk())
{
sender.sendMessage(_("userAFK", matchedPlayer.getDisplayName()));
sender.sendMessage(_("userAFK", matchPlayer.getDisplayName()));
}
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
sender.sendMessage(_("msgFormat", translatedMe, matchPlayer.getDisplayName(), message));
if (sender instanceof Player && matchedUser.isIgnoredPlayer(ess.getUser(sender)))
{
continue;
}
matchedPlayer.sendMessage(_("msgFormat", senderName, translatedMe, message));
matchPlayer.sendMessage(_("msgFormat", senderName, translatedMe, message));
replyTo.setReplyTo(matchedUser);
ess.getUser(matchedPlayer).setReplyTo(sender);
ess.getUser(matchPlayer).setReplyTo(sender);
}
if (!foundUser) {
throw new Exception(_("playerNotFound"));
}
}
}

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@ -29,18 +30,19 @@ public class Commandpay extends EssentialsCommand
}
double amount = Double.parseDouble(args[1].replaceAll("[^0-9\\.]", ""));
boolean foundUser = false;
for (Player p : server.matchPlayer(args[0]))
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
User u = ess.getUser(p);
User u = ess.getUser(matchPlayer);
if (u.isHidden())
{
continue;
}
foundUser = true;
user.payUser(u, amount);
Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), u.getName(), new Trade(amount, ess), user.getLocation(), ess);
foundUser = true;
}
if (!foundUser)

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -65,10 +66,18 @@ public class Commandspeed extends EssentialsCommand
}
}
private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final float speed, final String target)
private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final float speed, final String target) throws NotEnoughArgumentsException
{
for (Player matchPlayer : server.matchPlayer(target))
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(target);
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (player.isHidden())
{
continue;
}
foundUser = true;
if (isFly)
{
matchPlayer.setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass));
@ -80,6 +89,10 @@ public class Commandspeed extends EssentialsCommand
sender.sendMessage(_("moveSpeed", _("walking"), speed, matchPlayer.getDisplayName()));
}
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
private Boolean flyPermCheck(User user, boolean input) throws Exception

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -37,16 +38,18 @@ public class Commandtptoggle extends EssentialsCommand
user.sendMessage(user.toggleTeleportEnabled() ? _("teleportationEnabled") : _("teleportationDisabled"));
}
private void toggleOtherPlayers(final Server server, final CommandSender sender, final String[] args)
private void toggleOtherPlayers(final Server server, final CommandSender sender, final String[] args) throws NotEnoughArgumentsException
{
for (Player matchPlayer : server.matchPlayer(args[0]))
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (player.isHidden())
{
continue;
}
foundUser = true;
if (args.length > 1)
{
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
@ -69,5 +72,9 @@ public class Commandtptoggle extends EssentialsCommand
player.sendMessage(enabled ? _("teleportationEnabled") : _("teleportationDisabled"));
sender.sendMessage(enabled ? _("teleportationEnabledFor", matchPlayer.getDisplayName()) : _("teleportationDisabledFor", matchPlayer.getDisplayName()));
}
if (!foundUser)
{
throw new NotEnoughArgumentsException(_("playerNotFound"));
}
}
}