1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-12 09:35:26 +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:
ementalo
2012-06-18 13:55:25 +01:00
parent 88e7e684af
commit 89eca7d991
15 changed files with 184 additions and 101 deletions

View File

@@ -440,7 +440,7 @@ public class Essentials extends JavaPlugin implements IEssentials
for (Player player : players) for (Player player : players)
{ {
final IUser user = getUser(player); final IUser user = getUser(player);
if (!user.isIgnoringPlayer(sender.getName())) if (!user.isIgnoringPlayer(sender))
{ {
player.sendMessage(message); player.sendMessage(message);
} }

View File

@@ -70,9 +70,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
boolean isGodModeEnabled(); boolean isGodModeEnabled();
boolean isIgnoringPlayer(String name); boolean isIgnoringPlayer(IUser user);
void setIgnoredPlayer(String name, boolean set); void setIgnoredPlayer(IUser user, boolean set);
Location getAfkPosition(); Location getAfkPosition();
@@ -124,4 +124,6 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
void setGodModeEnabled(boolean set); void setGodModeEnabled(boolean set);
void setVanished(boolean set);
} }

View File

@@ -2,9 +2,10 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.craftbukkit.SetExpFix; import com.earth2me.essentials.craftbukkit.SetExpFix;
import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.permissions.Permissions;
import com.earth2me.essentials.utils.Util;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -13,6 +14,7 @@ public class Commandexp extends EssentialsCommand
@Override @Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length == 0) if (args.length == 0)
{ {
showExp(user, user); showExp(user, user);
@@ -21,68 +23,106 @@ public class Commandexp extends EssentialsCommand
{ {
if (args.length == 3 && Permissions.EXP_SET_OTHERS.isAuthorized(user)) if (args.length == 3 && Permissions.EXP_SET_OTHERS.isAuthorized(user))
{ {
boolean foundUser = false; expMatch(user, args[1], args[2], false);
for (Player matchPlayer : server.matchPlayer(args[1])) }
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); setExp(user, user, args[1], false);
} }
}
else if (args[0].equalsIgnoreCase("give") && Permissions.EXP_GIVE.isAuthorized(user)) else if (args[0].equalsIgnoreCase("give") && Permissions.EXP_GIVE.isAuthorized(user))
{ {
if (args.length == 3 && Permissions.EXP_GIVE_OTHERS.isAuthorized(user)) if (args.length == 3 && Permissions.EXP_GIVE_OTHERS.isAuthorized(user))
{ {
boolean foundUser = false; expMatch(user, args[1], args[2], true);
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);
} }
else else
{ {
String search = args[0].trim(); setExp(user, user, args[1], true);
}
}
else
{
String match = args[0].trim();
if (args.length == 2) 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); showExp(user, user);
return;
} }
for (Player matchPlayer : server.matchPlayer(search)) else
{ {
IUser target = ess.getUser(matchPlayer); showMatch(user, match);
showExp(user, target);
} }
} }
} }
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 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)); 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); Long amount = Long.parseLong(strAmount);
if (give) if (give)
@@ -94,6 +134,6 @@ public class Commandexp extends EssentialsCommand
amount = (long)Integer.MAX_VALUE; amount = (long)Integer.MAX_VALUE;
} }
SetExpFix.setTotalExperience(target, amount.intValue()); SetExpFix.setTotalExperience(target, amount.intValue());
user.sendMessage(_("expSet", target.getDisplayName(), amount)); sender.sendMessage(_("expSet", target.getDisplayName(), amount));
} }
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
@@ -11,6 +12,24 @@ public class Commandhat extends EssentialsCommand
{ {
@Override @Override
protected void run(IUser user, String commandLabel, String[] args) throws Exception 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) if (user.getItemInHand().getType() != Material.AIR)
{ {
@@ -23,7 +42,9 @@ public class Commandhat extends EssentialsCommand
inv.setHelmet(hand); inv.setHelmet(hand);
inv.setItemInHand(head); inv.setItemInHand(head);
user.sendMessage(_("hatPlaced")); user.sendMessage(_("hatPlaced"));
} else { }
else
{
user.sendMessage(_("hatArmor")); user.sendMessage(_("hatArmor"));
} }
} }
@@ -33,3 +54,4 @@ public class Commandhat extends EssentialsCommand
} }
} }
} }
}

View File

@@ -26,16 +26,16 @@ public class Commandignore extends EssentialsCommand
{ {
throw new Exception(_("playerNotFound")); throw new Exception(_("playerNotFound"));
} }
final String name = player.getName();
user.acquireWriteLock(); user.acquireWriteLock();
if (user.isIgnoringPlayer(name)) if (user.isIgnoringPlayer(player))
{ {
user.setIgnoredPlayer(name, false); user.setIgnoredPlayer(player, false);
user.sendMessage(_("unignorePlayer", player.getName())); user.sendMessage(_("unignorePlayer", player.getName()));
} }
else else
{ {
user.setIgnoredPlayer(name, true); user.setIgnoredPlayer(player, true);
user.sendMessage(_("ignorePlayer", player.getName())); user.sendMessage(_("ignorePlayer", player.getName()));
} }
} }

View File

@@ -52,7 +52,7 @@ public class Commandmail extends EssentialsCommand
{ {
throw new Exception(_("playerNeverOnServer", args[1])); 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))); final String mail = Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2)));
u.addMail(user.getName() + ": " + mail); u.addMail(user.getName() + ": " + mail);

View File

@@ -86,7 +86,7 @@ public class Commandmsg extends EssentialsCommand
{ {
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message)); sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
final IUser matchedUser = ess.getUser(matchedPlayer); 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; continue;
} }

View File

@@ -32,7 +32,7 @@ public class Commandtpa extends EssentialsCommand
{ {
throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName())); throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName()));
} }
if (!player.isIgnoringPlayer(user.getName())) if (!player.isIgnoringPlayer(user))
{ {
player.requestTeleport(user, false); player.requestTeleport(user, false);
player.sendMessage(_("teleportRequest", user.getDisplayName())); player.sendMessage(_("teleportRequest", user.getDisplayName()));

View File

@@ -2,23 +2,36 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.permissions.Permissions;
import org.bukkit.entity.Player;
public class Commandvanish extends EssentialsCommand public class Commandvanish extends EssentialsCommand
{ {
@Override @Override
protected void run(IUser user, String commandLabel, String[] args) throws Exception protected void run(IUser user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{ {
user.toggleVanished(); user.toggleVanished();
if (user.isVanished()) if (user.isVanished())
{ {
user.sendMessage(_("unvanished")); user.sendMessage(_("vanished"));
} }
else else
{ {
user.sendMessage(_("unvanished")); 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"));
}
}
} }

View File

@@ -74,7 +74,7 @@ public class EssentialsPlayerListener implements Listener
while (it.hasNext()) while (it.hasNext())
{ {
final IUser player = ess.getUser(it.next()); final IUser player = ess.getUser(it.next());
if (player.isIgnoringPlayer(user.getName())) if (player.isIgnoringPlayer(user))
{ {
it.remove(); it.remove();
} }
@@ -147,6 +147,10 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event) public void onPlayerJoin(final PlayerJoinEvent event)
{ {
if (!event.getPlayer().isOnline())
{
return;
}
ess.getBackup().startTask(); ess.getBackup().startTask();
@Cleanup @Cleanup
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());

View File

@@ -20,6 +20,7 @@ public enum Permissions implements IPermission
BAN_OFFLINE, BAN_OFFLINE,
BREAK_BEDROCK, BREAK_BEDROCK,
CHAT_COLOR, CHAT_COLOR,
CHAT_IGNORE_EXEMPT,
CHAT_SPY, CHAT_SPY,
CLEARINVENTORY_OTHERS, CLEARINVENTORY_OTHERS,
DELHOME_OTHERS, DELHOME_OTHERS,

View File

@@ -741,11 +741,11 @@ public class User extends UserBase implements IUser
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis(); return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
} }
@Override
public void toggleVanished() public void setVanished(boolean set)
{ {
vanished = !vanished; vanished = set;
if (vanished) if (set)
{ {
for (Player p : ess.getServer().getOnlinePlayers()) for (Player p : ess.getServer().getOnlinePlayers())
{ {

View File

@@ -3,7 +3,9 @@ package com.earth2me.essentials.user;
import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.api.InvalidNameException; import com.earth2me.essentials.api.InvalidNameException;
import com.earth2me.essentials.permissions.Permissions;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import com.earth2me.essentials.storage.Location.WorldNotLoadedException; import com.earth2me.essentials.storage.Location.WorldNotLoadedException;
import java.io.File; 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(); acquireReadLock();
try 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 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(); acquireWriteLock();
try try
@@ -352,11 +354,11 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
} }
if (set) if (set)
{ {
getData().getIgnore().add(name.toLowerCase(Locale.ENGLISH)); getData().getIgnore().add(user.getName().toLowerCase(Locale.ENGLISH));
} }
else else
{ {
getData().getIgnore().remove(name.toLowerCase(Locale.ENGLISH)); getData().getIgnore().remove(user.getName().toLowerCase(Locale.ENGLISH));
} }
} }
finally finally

View File

@@ -137,7 +137,7 @@ commands:
aliases: [tgm,godmode,egod,etgm,egodmode] aliases: [tgm,godmode,egod,etgm,egodmode]
hat: hat:
description: Get some cool new headgear description: Get some cool new headgear
usage: /<command> usage: /<command> [remove]
aliases: [ehat] aliases: [ehat]
heal: heal:
description: Heals you or the given player. description: Heals you or the given player.
@@ -321,7 +321,7 @@ commands:
spawn: spawn:
description: Teleport to the spawnpoint. description: Teleport to the spawnpoint.
usage: /<command> [player] usage: /<command> [player]
aliases: [esetspawn] aliases: [espawn]
spawner: spawner:
description: Change the mob type of a spawner description: Change the mob type of a spawner
usage: /<command> <mob> usage: /<command> <mob>
@@ -424,7 +424,7 @@ commands:
aliases: [eunlimited,ul,unl,eul,eunl] aliases: [eunlimited,ul,unl,eul,eunl]
vanish: vanish:
description: Hide yourself from other players. description: Hide yourself from other players.
usage: /<command> usage: /<command> [on|off]
aliases: [evanish] aliases: [evanish]
warp: warp:
description: List all warps or warp to the specified location. description: List all warps or warp to the specified location.

View File

@@ -37,36 +37,35 @@ public class EssentialsLocalChatEventListener implements Listener
{ {
String type = _("chatTypeLocal"); String type = _("chatTypeLocal");
final IUser user = ess.getUser(onlinePlayer); final IUser user = ess.getUser(onlinePlayer);
//TODO: remove reference to op if (user.isIgnoringPlayer(ess.getUser(sender)))
if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp())
{ {
continue; continue;
} }
if (!user.equals(sender)) if (!user.equals(sender))
{ {
if (Permissions.CHAT_SPY.isAuthorized(user)) boolean abort = false;
{
type = type.concat(_("chatTypeSpy"));
}
else
{
final Location playerLoc = user.getLocation(); final Location playerLoc = user.getLocation();
if (playerLoc.getWorld() != world) if (playerLoc.getWorld() != world)
{ {
continue; abort = true;
} }
final double delta = playerLoc.distanceSquared(loc); final double delta = playerLoc.distanceSquared(loc);
if (delta > event.getRadius()) 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())); final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage()));
user.sendMessage(message); user.sendMessage(message);
} }
} }
}
} }