mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-12 17:45:08 +02:00
2.9 Merges
Make /vanish follow the same rules as /fly, /god and /gamemode Add espawn to plugin.yml Allow your hat to be removed with /hat remove void silent command failures on /hat (ie typing /hat fish will no longer silently return as if broken) Fix /exp so it can be used in the console Using /exp, show can't find player message, if no matching player is found Replace op ignore exempt with ignore exempt chat permission: essentials.chat.ignoreexempt This permission won't prevent a player from ignoring the player, but the player will see the chat messages anyway. Fix chat showing [spy] prefix when social spy was not required to see the message Players should not be able to ignore Console Also implement chat exempt permission in other commands. Prevent joinbots from triggering join code, unless they are actually connected to the server and online.
This commit is contained in:
@@ -440,7 +440,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
for (Player player : players)
|
||||
{
|
||||
final IUser user = getUser(player);
|
||||
if (!user.isIgnoringPlayer(sender.getName()))
|
||||
if (!user.isIgnoringPlayer(sender))
|
||||
{
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
@@ -70,9 +70,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
|
||||
|
||||
boolean isGodModeEnabled();
|
||||
|
||||
boolean isIgnoringPlayer(String name);
|
||||
boolean isIgnoringPlayer(IUser user);
|
||||
|
||||
void setIgnoredPlayer(String name, boolean set);
|
||||
void setIgnoredPlayer(IUser user, boolean set);
|
||||
|
||||
Location getAfkPosition();
|
||||
|
||||
@@ -124,4 +124,6 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
|
||||
|
||||
void setGodModeEnabled(boolean set);
|
||||
|
||||
void setVanished(boolean set);
|
||||
|
||||
}
|
||||
|
@@ -2,9 +2,10 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -13,6 +14,7 @@ public class Commandexp extends EssentialsCommand
|
||||
@Override
|
||||
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
showExp(user, user);
|
||||
@@ -21,68 +23,106 @@ public class Commandexp extends EssentialsCommand
|
||||
{
|
||||
if (args.length == 3 && Permissions.EXP_SET_OTHERS.isAuthorized(user))
|
||||
{
|
||||
boolean foundUser = false;
|
||||
for (Player matchPlayer : server.matchPlayer(args[1]))
|
||||
expMatch(user, args[1], args[2], false);
|
||||
}
|
||||
else
|
||||
{
|
||||
IUser target = ess.getUser(matchPlayer);
|
||||
setExp(user, target, args[2], false);
|
||||
foundUser = true;
|
||||
}
|
||||
if (foundUser == false)
|
||||
{
|
||||
throw new NoSuchFieldException(_("playerNotFound"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
setExp(user, user, args[1], false);
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("give") && Permissions.EXP_GIVE.isAuthorized(user))
|
||||
{
|
||||
if (args.length == 3 && Permissions.EXP_GIVE_OTHERS.isAuthorized(user))
|
||||
{
|
||||
boolean foundUser = false;
|
||||
for (Player matchPlayer : server.matchPlayer(args[1]))
|
||||
{
|
||||
IUser target = ess.getUser(matchPlayer);
|
||||
setExp(user, target, args[2], true);
|
||||
foundUser = true;
|
||||
}
|
||||
if (foundUser == false)
|
||||
{
|
||||
throw new NoSuchFieldException(_("playerNotFound"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
setExp(user, user, args[1], true);
|
||||
expMatch(user, args[1], args[2], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
String search = args[0].trim();
|
||||
setExp(user, user, args[1], true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String match = args[0].trim();
|
||||
if (args.length == 2)
|
||||
{
|
||||
search = args[1].trim();
|
||||
match = args[1].trim();
|
||||
}
|
||||
if (search.equalsIgnoreCase("show") || !Permissions.EXP_OTHERS.isAuthorized(user))
|
||||
if (match.equalsIgnoreCase("show") || !Permissions.EXP_OTHERS.isAuthorized(user))
|
||||
{
|
||||
showExp(user, user);
|
||||
return;
|
||||
}
|
||||
for (Player matchPlayer : server.matchPlayer(search))
|
||||
else
|
||||
{
|
||||
IUser target = ess.getUser(matchPlayer);
|
||||
showExp(user, target);
|
||||
showMatch(user, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showExp(final IUser user, final IUser target)
|
||||
|
||||
public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
else if (args.length > 2 && args[0].equalsIgnoreCase("set"))
|
||||
{
|
||||
expMatch(sender, args[1], args[2], false);
|
||||
}
|
||||
else if (args.length > 2 && args[0].equalsIgnoreCase("give"))
|
||||
{
|
||||
expMatch(sender, args[1], args[2], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
String match = args[0].trim();
|
||||
if (args.length == 2)
|
||||
{
|
||||
match = args[1].trim();
|
||||
}
|
||||
showMatch(sender, match);
|
||||
}
|
||||
}
|
||||
|
||||
private void showMatch(final CommandSender sender, final String match) throws NotEnoughArgumentsException
|
||||
{
|
||||
boolean foundUser = false;
|
||||
for (Player matchPlayer : server.matchPlayer(match))
|
||||
{
|
||||
foundUser = true;
|
||||
final IUser target = ess.getUser(matchPlayer);
|
||||
showExp(sender, target);
|
||||
}
|
||||
if (!foundUser)
|
||||
{
|
||||
throw new NotEnoughArgumentsException(_("playerNotFound"));
|
||||
}
|
||||
}
|
||||
|
||||
private void expMatch(final CommandSender sender, final String match, final String amount, final boolean toggle) throws NotEnoughArgumentsException
|
||||
{
|
||||
boolean foundUser = false;
|
||||
for (Player matchPlayer : server.matchPlayer(match))
|
||||
{
|
||||
final IUser target = ess.getUser(matchPlayer);
|
||||
setExp(sender, target, amount, toggle);
|
||||
foundUser = true;
|
||||
}
|
||||
if (!foundUser)
|
||||
{
|
||||
throw new NotEnoughArgumentsException(_("playerNotFound"));
|
||||
}
|
||||
}
|
||||
|
||||
private void showExp(final CommandSender sender, final IUser target)
|
||||
{
|
||||
final int totalExp = SetExpFix.getTotalExperience(target);
|
||||
final int expLeft = (int)Util.roundDouble(((((3.5 * target.getLevel()) + 6.7) - (totalExp - ((1.75 * (target.getLevel() * target.getLevel())) + (5.00 * target.getLevel())))) + 1));
|
||||
user.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target), target.getLevel(), expLeft));
|
||||
sender.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target), target.getLevel(), expLeft));
|
||||
}
|
||||
|
||||
private void setExp(final IUser user, final IUser target, final String strAmount, final boolean give)
|
||||
private void setExp(final CommandSender sender, final IUser target, final String strAmount, final boolean give)
|
||||
{
|
||||
Long amount = Long.parseLong(strAmount);
|
||||
if (give)
|
||||
@@ -94,6 +134,6 @@ public class Commandexp extends EssentialsCommand
|
||||
amount = (long)Integer.MAX_VALUE;
|
||||
}
|
||||
SetExpFix.setTotalExperience(target, amount.intValue());
|
||||
user.sendMessage(_("expSet", target.getDisplayName(), amount));
|
||||
sender.sendMessage(_("expSet", target.getDisplayName(), amount));
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@@ -11,6 +12,24 @@ public class Commandhat extends EssentialsCommand
|
||||
{
|
||||
@Override
|
||||
protected void run(IUser user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length > 0 && (args[0].contains("rem") || args[0].contains("off") || args[0].equalsIgnoreCase("0")))
|
||||
{
|
||||
final PlayerInventory inv = user.getInventory();
|
||||
final ItemStack head = inv.getHelmet();
|
||||
if (head == null || head.getType() == Material.AIR)
|
||||
{
|
||||
user.sendMessage(_("hatEmpty"));
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack air = new ItemStack(Material.AIR);
|
||||
inv.setHelmet(air);
|
||||
InventoryWorkaround.addItem(user.getInventory(), true, head);
|
||||
user.sendMessage(_("hatRemoved"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.getItemInHand().getType() != Material.AIR)
|
||||
{
|
||||
@@ -23,7 +42,9 @@ public class Commandhat extends EssentialsCommand
|
||||
inv.setHelmet(hand);
|
||||
inv.setItemInHand(head);
|
||||
user.sendMessage(_("hatPlaced"));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("hatArmor"));
|
||||
}
|
||||
}
|
||||
@@ -33,3 +54,4 @@ public class Commandhat extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,16 +26,16 @@ public class Commandignore extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
final String name = player.getName();
|
||||
|
||||
user.acquireWriteLock();
|
||||
if (user.isIgnoringPlayer(name))
|
||||
if (user.isIgnoringPlayer(player))
|
||||
{
|
||||
user.setIgnoredPlayer(name, false);
|
||||
user.setIgnoredPlayer(player, false);
|
||||
user.sendMessage(_("unignorePlayer", player.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
user.setIgnoredPlayer(name, true);
|
||||
user.setIgnoredPlayer(player, true);
|
||||
user.sendMessage(_("ignorePlayer", player.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class Commandmail extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("playerNeverOnServer", args[1]));
|
||||
}
|
||||
if (!u.isIgnoringPlayer(user.getName()))
|
||||
if (!u.isIgnoringPlayer(user))
|
||||
{
|
||||
final String mail = Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2)));
|
||||
u.addMail(user.getName() + ": " + mail);
|
||||
|
@@ -86,7 +86,7 @@ public class Commandmsg extends EssentialsCommand
|
||||
{
|
||||
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
|
||||
final IUser matchedUser = ess.getUser(matchedPlayer);
|
||||
if (sender instanceof Player && (matchedUser.isIgnoringPlayer(((Player)sender).getName()) || matchedUser.isHidden()))
|
||||
if (sender instanceof Player && (matchedUser.isIgnoringPlayer(ess.getUser(sender)) || matchedUser.isHidden()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class Commandtpa extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName()));
|
||||
}
|
||||
if (!player.isIgnoringPlayer(user.getName()))
|
||||
if (!player.isIgnoringPlayer(user))
|
||||
{
|
||||
player.requestTeleport(user, false);
|
||||
player.sendMessage(_("teleportRequest", user.getDisplayName()));
|
||||
|
@@ -2,23 +2,36 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandvanish extends EssentialsCommand
|
||||
{
|
||||
@Override
|
||||
protected void run(IUser user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
user.toggleVanished();
|
||||
if (user.isVanished())
|
||||
{
|
||||
user.sendMessage(_("unvanished"));
|
||||
user.sendMessage(_("vanished"));
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(_("unvanished"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[0].contains("on") || args[0].contains("ena") || args[0].equalsIgnoreCase("1"))
|
||||
{
|
||||
user.setVanished(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.setVanished(false);
|
||||
}
|
||||
user.sendMessage(user.isVanished() ? _("vanished") : _("unvanished"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
while (it.hasNext())
|
||||
{
|
||||
final IUser player = ess.getUser(it.next());
|
||||
if (player.isIgnoringPlayer(user.getName()))
|
||||
if (player.isIgnoringPlayer(user))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
@@ -147,6 +147,10 @@ public class EssentialsPlayerListener implements Listener
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event)
|
||||
{
|
||||
if (!event.getPlayer().isOnline())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ess.getBackup().startTask();
|
||||
@Cleanup
|
||||
final IUser user = ess.getUser(event.getPlayer());
|
||||
|
@@ -20,6 +20,7 @@ public enum Permissions implements IPermission
|
||||
BAN_OFFLINE,
|
||||
BREAK_BEDROCK,
|
||||
CHAT_COLOR,
|
||||
CHAT_IGNORE_EXEMPT,
|
||||
CHAT_SPY,
|
||||
CLEARINVENTORY_OTHERS,
|
||||
DELHOME_OTHERS,
|
||||
|
@@ -741,11 +741,11 @@ public class User extends UserBase implements IUser
|
||||
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleVanished()
|
||||
|
||||
public void setVanished(boolean set)
|
||||
{
|
||||
vanished = !vanished;
|
||||
if (vanished)
|
||||
vanished = set;
|
||||
if (set)
|
||||
{
|
||||
for (Player p : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
|
@@ -3,7 +3,9 @@ package com.earth2me.essentials.user;
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.ISettings;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.api.InvalidNameException;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||
import com.earth2me.essentials.storage.Location.WorldNotLoadedException;
|
||||
import java.io.File;
|
||||
@@ -328,12 +330,12 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIgnoringPlayer(final String name)
|
||||
public boolean isIgnoringPlayer(final IUser user)
|
||||
{
|
||||
acquireReadLock();
|
||||
try
|
||||
{
|
||||
return getData().getIgnore() == null ? false : getData().getIgnore().contains(name.toLowerCase(Locale.ENGLISH));
|
||||
return getData().getIgnore() == null ? false : getData().getIgnore().contains(user.getName().toLowerCase(Locale.ENGLISH)) && Permissions.CHAT_IGNORE_EXEMPT.isAuthorized(user);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -341,7 +343,7 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
|
||||
}
|
||||
}
|
||||
|
||||
public void setIgnoredPlayer(final String name, final boolean set)
|
||||
public void setIgnoredPlayer(final IUser user, final boolean set)
|
||||
{
|
||||
acquireWriteLock();
|
||||
try
|
||||
@@ -352,11 +354,11 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
|
||||
}
|
||||
if (set)
|
||||
{
|
||||
getData().getIgnore().add(name.toLowerCase(Locale.ENGLISH));
|
||||
getData().getIgnore().add(user.getName().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
else
|
||||
{
|
||||
getData().getIgnore().remove(name.toLowerCase(Locale.ENGLISH));
|
||||
getData().getIgnore().remove(user.getName().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@@ -137,7 +137,7 @@ commands:
|
||||
aliases: [tgm,godmode,egod,etgm,egodmode]
|
||||
hat:
|
||||
description: Get some cool new headgear
|
||||
usage: /<command>
|
||||
usage: /<command> [remove]
|
||||
aliases: [ehat]
|
||||
heal:
|
||||
description: Heals you or the given player.
|
||||
@@ -321,7 +321,7 @@ commands:
|
||||
spawn:
|
||||
description: Teleport to the spawnpoint.
|
||||
usage: /<command> [player]
|
||||
aliases: [esetspawn]
|
||||
aliases: [espawn]
|
||||
spawner:
|
||||
description: Change the mob type of a spawner
|
||||
usage: /<command> <mob>
|
||||
@@ -424,7 +424,7 @@ commands:
|
||||
aliases: [eunlimited,ul,unl,eul,eunl]
|
||||
vanish:
|
||||
description: Hide yourself from other players.
|
||||
usage: /<command>
|
||||
usage: /<command> [on|off]
|
||||
aliases: [evanish]
|
||||
warp:
|
||||
description: List all warps or warp to the specified location.
|
||||
|
@@ -37,36 +37,35 @@ public class EssentialsLocalChatEventListener implements Listener
|
||||
{
|
||||
String type = _("chatTypeLocal");
|
||||
final IUser user = ess.getUser(onlinePlayer);
|
||||
//TODO: remove reference to op
|
||||
if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp())
|
||||
if (user.isIgnoringPlayer(ess.getUser(sender)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!user.equals(sender))
|
||||
{
|
||||
if (Permissions.CHAT_SPY.isAuthorized(user))
|
||||
{
|
||||
type = type.concat(_("chatTypeSpy"));
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean abort = false;
|
||||
final Location playerLoc = user.getLocation();
|
||||
if (playerLoc.getWorld() != world)
|
||||
{
|
||||
continue;
|
||||
abort = true;
|
||||
}
|
||||
final double delta = playerLoc.distanceSquared(loc);
|
||||
|
||||
if (delta > event.getRadius())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
abort = true;
|
||||
}
|
||||
|
||||
if (abort)
|
||||
{
|
||||
if (ChatPermissions.getPermission("spy").isAuthorized(user))
|
||||
{
|
||||
type = type.concat(_("chatTypeSpy"));
|
||||
}
|
||||
}
|
||||
}
|
||||
final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage()));
|
||||
user.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user