Search in sources :

Example 6 with User

use of com.earth2me.essentials.User in project Essentials by drtshock.

the class EssentialsToggleCommand method toggleOtherPlayers.

protected void toggleOtherPlayers(final Server server, final CommandSource sender, final String[] args) throws PlayerNotFoundException, NotEnoughArgumentsException {
    if (args.length < 1 || args[0].trim().length() < 2) {
        throw new PlayerNotFoundException();
    }
    boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
    boolean foundUser = false;
    final List<Player> matchedPlayers = server.matchPlayer(args[0]);
    for (Player matchPlayer : matchedPlayers) {
        final User player = ess.getUser(matchPlayer);
        if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer)) {
            continue;
        }
        foundUser = true;
        if (args.length > 1) {
            Boolean toggle = matchToggleArgument(args[1]);
            if (toggle == true) {
                togglePlayer(sender, player, true);
            } else {
                togglePlayer(sender, player, false);
            }
        } else {
            togglePlayer(sender, player, null);
        }
    }
    if (!foundUser) {
        throw new PlayerNotFoundException();
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User)

Example 7 with User

use of com.earth2me.essentials.User in project Essentials by drtshock.

the class SimpleMessageRecipient method onReceiveMessage.

@Override
public MessageResponse onReceiveMessage(IMessageRecipient sender, String message) {
    if (!isReachable()) {
        return MessageResponse.UNREACHABLE;
    }
    User user = getUser(this);
    boolean afk = false;
    if (user != null) {
        if (user.isIgnoreMsg() && !(sender instanceof Console)) {
            // Console must never be ignored.
            return MessageResponse.MESSAGES_IGNORED;
        }
        afk = user.isAfk();
        // Check whether this recipient ignores the sender, only if the sender is not the console.
        if (sender instanceof IUser && user.isIgnoredPlayer((IUser) sender)) {
            return MessageResponse.SENDER_IGNORED;
        }
    }
    // Display the formatted message to this recipient.
    sendMessage(tl("msgFormat", sender.getDisplayName(), tl("me"), message));
    if (ess.getSettings().isLastMessageReplyRecipient()) {
        // If this recipient doesn't have a reply recipient, initiate by setting the first
        // message sender to this recipient's replyRecipient.
        long timeout = ess.getSettings().getLastMessageReplyRecipientTimeout() * 1000;
        if (getReplyRecipient() == null || !getReplyRecipient().isReachable() || System.currentTimeMillis() - this.lastMessageMs > timeout) {
            setReplyRecipient(sender);
        }
    } else {
        // Old message functionality, always set the reply recipient to the last person who sent us a message.
        setReplyRecipient(sender);
    }
    this.lastMessageMs = System.currentTimeMillis();
    return afk ? MessageResponse.SUCCESS_BUT_AFK : MessageResponse.SUCCESS;
}
Also used : IUser(com.earth2me.essentials.IUser) User(com.earth2me.essentials.User) Console(com.earth2me.essentials.Console) IUser(com.earth2me.essentials.IUser)

Example 8 with User

use of com.earth2me.essentials.User in project Essentials by drtshock.

the class EssentialsCommand method getPlayer.

private User getPlayer(final Server server, final User sourceUser, final String searchTerm, boolean getHidden, final boolean getOffline) throws PlayerNotFoundException {
    final User user;
    Player exPlayer;
    try {
        exPlayer = server.getPlayer(UUID.fromString(searchTerm));
    } catch (IllegalArgumentException ex) {
        exPlayer = server.getPlayer(searchTerm);
    }
    if (exPlayer != null) {
        user = ess.getUser(exPlayer);
    } else {
        user = ess.getUser(searchTerm);
    }
    if (user != null) {
        if (!getOffline && !user.getBase().isOnline()) {
            throw new PlayerNotFoundException();
        }
        if (getHidden || canInteractWith(sourceUser, user)) {
            return user;
        }
        throw new PlayerNotFoundException();
    }
    final List<Player> matches = server.matchPlayer(searchTerm);
    if (matches.isEmpty()) {
        final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
        for (User userMatch : ess.getOnlineUsers()) {
            if (getHidden || canInteractWith(sourceUser, userMatch)) {
                final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
                if (displayName.contains(matchText)) {
                    return userMatch;
                }
            }
        }
    } else {
        for (Player player : matches) {
            final User userMatch = ess.getUser(player);
            if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch))) {
                return userMatch;
            }
        }
        final User userMatch = ess.getUser(matches.get(0));
        if (getHidden || canInteractWith(sourceUser, userMatch)) {
            return userMatch;
        }
    }
    throw new PlayerNotFoundException();
}
Also used : Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User)

Example 9 with User

use of com.earth2me.essentials.User in project Essentials by drtshock.

the class Commandwarp method run.

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 2 || NumberUtil.isInt(args[0])) {
        warpList(sender, args, null);
        throw new NoChargeException();
    }
    User otherUser = getPlayer(server, args, 1, true, false);
    otherUser.getTeleport().warp(otherUser, args[0], null, TeleportCause.COMMAND);
    throw new NoChargeException();
}
Also used : IUser(net.ess3.api.IUser) User(com.earth2me.essentials.User)

Example 10 with User

use of com.earth2me.essentials.User in project Essentials by drtshock.

the class Commandtp method run.

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 2) {
        throw new NotEnoughArgumentsException();
    }
    final User target = getPlayer(server, args, 0, true, false);
    if (args.length == 2) {
        final User toPlayer = getPlayer(server, args, 1, true, false);
        target.sendMessage(tl("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
        target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND);
    } else if (args.length > 3) {
        final double x = args[1].startsWith("~") ? target.getLocation().getX() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]);
        final double y = args[2].startsWith("~") ? target.getLocation().getY() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]);
        final double z = args[3].startsWith("~") ? target.getLocation().getZ() + (args[3].length() > 1 ? Double.parseDouble(args[3].substring(1)) : 0) : Double.parseDouble(args[3]);
        if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
            throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
        }
        final Location loc = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
        sender.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
        target.getTeleport().now(loc, false, TeleportCause.COMMAND);
        target.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
    } else {
        throw new NotEnoughArgumentsException();
    }
}
Also used : User(com.earth2me.essentials.User) Location(org.bukkit.Location)

Aggregations

User (com.earth2me.essentials.User)231 Player (org.bukkit.entity.Player)39 Location (org.bukkit.Location)30 EventHandler (org.bukkit.event.EventHandler)29 World (org.bukkit.World)18 Trade (com.earth2me.essentials.Trade)14 ItemStack (org.bukkit.inventory.ItemStack)14 Material (org.bukkit.Material)8 ArrayList (java.util.ArrayList)7 IText (com.earth2me.essentials.textreader.IText)6 List (java.util.List)6 UUID (java.util.UUID)6 IOException (java.io.IOException)5 IUser (com.earth2me.essentials.IUser)4 Kit (com.earth2me.essentials.Kit)4 OfflinePlayer (com.earth2me.essentials.OfflinePlayer)4 PlayerList (com.earth2me.essentials.PlayerList)4 Teleport (com.earth2me.essentials.Teleport)4 UserMap (com.earth2me.essentials.UserMap)4 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)4