mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-13 18:14:38 +02:00
Fix instanceof Player
This commit is contained in:
@@ -21,7 +21,7 @@ public class Commandban extends EssentialsCommand
|
||||
final IUser user = ess.getUserMap().matchUser(args[0], true);
|
||||
if (!user.isOnline())
|
||||
{
|
||||
if (sender instanceof Player && Permissions.BAN_OFFLINE.isAuthorized(user))
|
||||
if (isUser(sender) && Permissions.BAN_OFFLINE.isAuthorized(user))
|
||||
{
|
||||
sender.sendMessage(_("banExempt"));
|
||||
return;
|
||||
@@ -36,7 +36,7 @@ public class Commandban extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
||||
final String senderName = isUser(sender) ? getPlayer(sender).getDisplayName() : Console.NAME;
|
||||
String banReason;
|
||||
user.getData().setBan(new Ban());
|
||||
if (args.length > 1)
|
||||
|
@@ -5,6 +5,7 @@ import java.util.Locale;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.bukkit.LivingEntities;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.*;
|
||||
@@ -20,9 +21,9 @@ public class Commandkillall extends EssentialsCommand
|
||||
String type = "all";
|
||||
int radius = -1;
|
||||
World world;
|
||||
if (sender instanceof Player)
|
||||
if (isUser(sender))
|
||||
{
|
||||
world = ((Player)sender).getWorld();
|
||||
world = getPlayer(sender).getWorld();
|
||||
if (args.length == 1)
|
||||
{
|
||||
try
|
||||
@@ -81,13 +82,14 @@ public class Commandkillall extends EssentialsCommand
|
||||
entityClass = LivingEntities.fromName(killType).getEntityClass();
|
||||
}
|
||||
int numKills = 0;
|
||||
Location loc = isUser(sender) ? getPlayer(sender).getLocation() : null;
|
||||
for (Chunk chunk : world.getLoadedChunks())
|
||||
{
|
||||
for (Entity entity : chunk.getEntities())
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
if (loc != null)
|
||||
{
|
||||
if (radius >= 0 && ((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius)
|
||||
if (radius >= 0 && loc.distanceSquared(entity.getLocation()) > radius)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -103,7 +105,7 @@ public class Commandkillall extends EssentialsCommand
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(entity instanceof Ocelot)
|
||||
if (entity instanceof Ocelot)
|
||||
{
|
||||
if (((Ocelot)entity).isTamed())
|
||||
{
|
||||
@@ -148,4 +150,4 @@ public class Commandkillall extends EssentialsCommand
|
||||
}
|
||||
sender.sendMessage(_("kill", numKills));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,11 +10,10 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
|
||||
public class Commandptime extends EssentialsCommand
|
||||
{
|
||||
public static final Set<String> getAliases = new HashSet<String>();
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
getAliases.add("get");
|
||||
@@ -22,7 +21,7 @@ public class Commandptime extends EssentialsCommand
|
||||
getAliases.add("show");
|
||||
getAliases.add("display");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -40,14 +39,14 @@ public class Commandptime extends EssentialsCommand
|
||||
getUsersTime(sender, users);
|
||||
return;
|
||||
}
|
||||
|
||||
IUser user = sender instanceof Player ? ess.getUserMap().getUser((Player)sender) : null;
|
||||
|
||||
IUser user = isUser(sender) ? getUser(sender) : null;
|
||||
if ((!users.contains(user) || users.size() > 1) && user != null && !Permissions.PTIME_OTHERS.isAuthorized(user))
|
||||
{
|
||||
user.sendMessage(_("pTimeOthersPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Long ticks;
|
||||
// Parse the target time int ticks from args[0]
|
||||
String timeParam = args[0];
|
||||
@@ -57,7 +56,7 @@ public class Commandptime extends EssentialsCommand
|
||||
relative = false;
|
||||
timeParam = timeParam.substring(1);
|
||||
}
|
||||
|
||||
|
||||
if (getAliases.contains(timeParam))
|
||||
{
|
||||
getUsersTime(sender, users);
|
||||
@@ -78,7 +77,7 @@ public class Commandptime extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setUsersTime(sender, users, ticks, relative);
|
||||
}
|
||||
|
||||
@@ -91,7 +90,7 @@ public class Commandptime extends EssentialsCommand
|
||||
{
|
||||
sender.sendMessage(_("pTimePlayers"));
|
||||
}
|
||||
|
||||
|
||||
for (IUser user : users)
|
||||
{
|
||||
if (user.getPlayer().getPlayerTimeOffset() == 0)
|
||||
@@ -143,7 +142,7 @@ public class Commandptime extends EssentialsCommand
|
||||
user.getPlayer().setPlayerTime(time, relative);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
for (IUser user : users)
|
||||
{
|
||||
@@ -151,7 +150,7 @@ public class Commandptime extends EssentialsCommand
|
||||
{
|
||||
msg.append(", ");
|
||||
}
|
||||
|
||||
|
||||
msg.append(user.getName());
|
||||
}
|
||||
|
||||
@@ -183,7 +182,7 @@ public class Commandptime extends EssentialsCommand
|
||||
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
|
||||
if (selector == null)
|
||||
{
|
||||
final IUser user = sender instanceof Player ? ess.getUserMap().getUser((Player)sender) : null;
|
||||
final IUser user = isUser(sender) ? getUser(sender) : null;
|
||||
if (user == null)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
@@ -205,7 +204,7 @@ public class Commandptime extends EssentialsCommand
|
||||
{
|
||||
user = ess.getUserMap().getUser(matchedPlayers.get(0));
|
||||
}
|
||||
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
users.add(user);
|
||||
@@ -223,7 +222,7 @@ public class Commandptime extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
|
||||
|
||||
return users;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import net.ess3.api.IUser;
|
||||
import net.ess3.permissions.Permissions;
|
||||
import net.ess3.utils.FormatUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandr extends EssentialsCommand
|
||||
@@ -24,9 +23,9 @@ public class Commandr extends EssentialsCommand
|
||||
IReplyTo replyTo;
|
||||
String senderName;
|
||||
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
IUser user = ess.getUserMap().getUser((Player)sender);
|
||||
IUser user = getUser(sender);
|
||||
if (Permissions.MSG_COLOR.isAuthorized(user))
|
||||
{
|
||||
message = FormatUtil.replaceFormat(message);
|
||||
@@ -46,18 +45,16 @@ public class Commandr extends EssentialsCommand
|
||||
}
|
||||
|
||||
final CommandSender target = replyTo.getReplyTo();
|
||||
final String targetName = target instanceof Player ? ((Player)target).getDisplayName() : Console.NAME;
|
||||
|
||||
if (target == null || ((target instanceof Player) && !((Player)target).isOnline()))
|
||||
if (target == null || (isUser(target) && !getUser(target).isOnline()))
|
||||
{
|
||||
throw new Exception(_("foreverAlone"));
|
||||
}
|
||||
final String targetName = isUser(target) ? getPlayer(target).getDisplayName() : Console.NAME;
|
||||
|
||||
sender.sendMessage(_("msgFormat", _("me"), targetName, message));
|
||||
if (target instanceof Player)
|
||||
if (isUser(target))
|
||||
{
|
||||
IUser player = ess.getUserMap().getUser((Player)target);
|
||||
if (sender instanceof Player && player.isIgnoringPlayer(ess.getUserMap().getUser((Player)sender)))
|
||||
if (isUser(sender) && getUser(target).isIgnoringPlayer(getUser(sender)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -66,9 +63,9 @@ public class Commandr extends EssentialsCommand
|
||||
replyTo.setReplyTo(target);
|
||||
if (target != sender)
|
||||
{
|
||||
if (target instanceof Player)
|
||||
if (isUser(target))
|
||||
{
|
||||
ess.getUserMap().getUser((Player)target).setReplyTo(sender);
|
||||
getUser(target).setReplyTo(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -46,7 +46,7 @@ public class Commandtempban extends EssentialsCommand
|
||||
user.setBanned(true);
|
||||
user.queueSave();
|
||||
user.getPlayer().kickPlayer(banReason);
|
||||
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
||||
final String senderName = isUser(sender) ? getPlayer(sender).getDisplayName() : Console.NAME;
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
|
@@ -122,14 +122,14 @@ public class Commandtime extends EssentialsCommand
|
||||
// If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user.
|
||||
if (selector == null)
|
||||
{
|
||||
final IUser user = sender instanceof Player ? ess.getUserMap().getUser((Player)sender) : null;
|
||||
final Player user = getPlayerOrNull(sender);
|
||||
if (user == null)
|
||||
{
|
||||
worlds.addAll(server.getWorlds());
|
||||
}
|
||||
else
|
||||
{
|
||||
worlds.add(user.getPlayer().getWorld());
|
||||
worlds.add(user.getWorld());
|
||||
}
|
||||
return worlds;
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ public class Commandtpaall extends EssentialsCommand
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
if (isUser(sender))
|
||||
{
|
||||
teleportAAllPlayers(sender, ess.getUserMap().getUser((Player)sender));
|
||||
return;
|
||||
|
@@ -16,7 +16,7 @@ public class Commandtpall extends EssentialsCommand
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
if (isUser(sender))
|
||||
{
|
||||
teleportAllPlayers(sender, ess.getUserMap().getUser((Player)sender));
|
||||
return;
|
||||
|
@@ -120,7 +120,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
final String quitMessage = ess.getSettings().getData().getGeneral().getLeaveMessage();
|
||||
if (quitMessage != null)
|
||||
{
|
||||
final IText itOutput = new KeywordReplacer(new SimpleTextInput(quitMessage), event.getPlayer(), ess);
|
||||
final IText itOutput = new KeywordReplacer(new SimpleTextInput(quitMessage), ess.getUserMap().getUser(event.getPlayer()), ess);
|
||||
final SimpleTextPager stPager = new SimpleTextPager(itOutput);
|
||||
event.setQuitMessage(FormatUtil.replaceFormat(stPager.getString(0)));
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
final String joinMessage = ess.getSettings().getData().getGeneral().getJoinMessage();
|
||||
if (joinMessage != null)
|
||||
{
|
||||
final IText itOutput = new KeywordReplacer(new SimpleTextInput(joinMessage), event.getPlayer(), ess);
|
||||
final IText itOutput = new KeywordReplacer(new SimpleTextInput(joinMessage), ess.getUserMap().getUser(event.getPlayer()), ess);
|
||||
final SimpleTextPager stPager = new SimpleTextPager(itOutput);
|
||||
event.setJoinMessage(FormatUtil.replaceFormat(stPager.getString(0)));
|
||||
}
|
||||
|
@@ -34,9 +34,9 @@ public class KeywordReplacer implements IText
|
||||
String worlds, online, unique, playerlist, date, time;
|
||||
String worldTime12, worldTime24, worldDate, plugins;
|
||||
String userName, address, version;
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
final IUser user = ess.getUserMap().getUser((Player)sender);
|
||||
final IUser user = (IUser)sender;
|
||||
user.setDisplayNick();
|
||||
displayName = user.getPlayer().getDisplayName();
|
||||
userName = user.getPlayer().getName();
|
||||
@@ -55,11 +55,12 @@ public class KeywordReplacer implements IText
|
||||
}
|
||||
|
||||
int playerHidden = 0;
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
final Player playerUser = ((IUser)sender).getPlayer();
|
||||
for (Player p : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
if (!p.canSee((Player)sender))
|
||||
if (!p.canSee(playerUser))
|
||||
{
|
||||
playerHidden++;
|
||||
}
|
||||
@@ -80,11 +81,12 @@ public class KeywordReplacer implements IText
|
||||
worlds = worldsBuilder.toString();
|
||||
|
||||
final StringBuilder playerlistBuilder = new StringBuilder();
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
final Player playerUser = ((IUser)sender).getPlayer();
|
||||
for (Player p : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
if (!p.canSee((Player)sender))
|
||||
if (!p.canSee(playerUser))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -24,11 +24,11 @@ public class TextInput implements IText
|
||||
{
|
||||
|
||||
File file = null;
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
final IUser user = ess.getUserMap().getUser((Player)sender);
|
||||
final IUser user = (IUser)sender;
|
||||
file = new File(ess.getPlugin().getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
||||
if (!file.exists())
|
||||
{
|
||||
|
@@ -69,9 +69,9 @@ public abstract class EssentialsChatPlayer implements Listener
|
||||
|
||||
protected void charge(final CommandSender sender, final Trade charge) throws ChargeException
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof IUser)
|
||||
{
|
||||
charge.charge(ess.getUserMap().getUser((Player)sender));
|
||||
charge.charge((IUser)sender);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user