TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java

150 lines
4.6 KiB
Java
Raw Normal View History

2013-09-28 16:21:16 +00:00
package com.earth2me.essentials.commands;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
2013-09-28 16:21:16 +00:00
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
2013-09-28 16:21:16 +00:00
import java.util.List;
import java.util.Locale;
2014-04-13 05:53:11 +00:00
import java.util.UUID;
import net.ess3.api.MaxMoneyException;
2013-09-28 16:21:16 +00:00
import org.bukkit.Server;
import org.bukkit.entity.Player;
public abstract class EssentialsLoopCommand extends EssentialsCommand
{
public EssentialsLoopCommand(String command)
{
super(command);
}
protected void loopOfflinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, boolean matchWildcards, final String searchTerm, final String[] commandArgs)
throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException
2013-09-28 16:21:16 +00:00
{
if (searchTerm.isEmpty())
{
throw new PlayerNotFoundException();
}
if (matchWildcards && searchTerm.contentEquals("**"))
2013-09-28 16:21:16 +00:00
{
2014-04-13 05:53:11 +00:00
for (UUID sUser : ess.getUserMap().getAllUniqueUsers())
2013-09-28 16:21:16 +00:00
{
final User matchedUser = ess.getUser(sUser);
updatePlayer(server, sender, matchedUser, commandArgs);
}
}
else if (matchWildcards && searchTerm.contentEquals("*"))
2013-09-28 16:21:16 +00:00
{
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
for (User onlineUser : ess.getOnlineUsers())
2013-09-28 16:21:16 +00:00
{
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlineUser.getBase()))
2013-09-28 16:21:16 +00:00
{
continue;
}
updatePlayer(server, sender, onlineUser, commandArgs);
}
}
else if (multipleStringMatches)
{
if (searchTerm.trim().length() < 3)
{
throw new PlayerNotFoundException();
}
final List<Player> matchedPlayers = server.matchPlayer(searchTerm);
if (matchedPlayers.isEmpty())
{
final User matchedUser = getPlayer(server, searchTerm, true, true);
updatePlayer(server, sender, matchedUser, commandArgs);
}
for (Player matchPlayer : matchedPlayers)
{
final User matchedUser = ess.getUser(matchPlayer);
updatePlayer(server, sender, matchedUser, commandArgs);
}
}
else
{
final User user = getPlayer(server, searchTerm, true, true);
updatePlayer(server, sender, user, commandArgs);
}
}
protected void loopOnlinePlayers(final Server server, final CommandSource sender, final boolean multipleStringMatches, boolean matchWildcards, final String searchTerm, final String[] commandArgs)
throws PlayerNotFoundException, NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException
2013-09-28 16:21:16 +00:00
{
if (searchTerm.isEmpty())
{
throw new PlayerNotFoundException();
}
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
2013-09-28 16:21:16 +00:00
if (matchWildcards && (searchTerm.contentEquals("**") || searchTerm.contentEquals("*")))
2013-09-28 16:21:16 +00:00
{
for (User onlineUser : ess.getOnlineUsers())
2013-09-28 16:21:16 +00:00
{
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlineUser.getBase()))
2013-09-28 16:21:16 +00:00
{
continue;
}
updatePlayer(server, sender, onlineUser, commandArgs);
}
}
else if (multipleStringMatches)
{
if (searchTerm.trim().length() < 2)
{
throw new PlayerNotFoundException();
}
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(searchTerm);
if (matchedPlayers.isEmpty())
2013-09-28 16:21:16 +00:00
{
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (User player : ess.getOnlineUsers())
2013-09-28 16:21:16 +00:00
{
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(player.getBase()))
{
continue;
}
final String displayName = FormatUtil.stripFormat(player.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText))
{
foundUser = true;
updatePlayer(server, sender, player, commandArgs);
}
}
}
else
{
for (Player matchPlayer : matchedPlayers)
{
final User player = ess.getUser(matchPlayer);
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
{
continue;
}
foundUser = true;
updatePlayer(server, sender, player, commandArgs);
2013-09-28 16:21:16 +00:00
}
}
if (!foundUser)
{
throw new PlayerNotFoundException();
}
}
else
{
final User player = getPlayer(server, sender, searchTerm);
2013-09-28 16:21:16 +00:00
updatePlayer(server, sender, player, commandArgs);
}
}
protected abstract void updatePlayer(Server server, CommandSource sender, User user, String[] args)
throws NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException;
2013-09-28 16:21:16 +00:00
}