Search in sources :

Example 1 with SimpleTextInput

use of com.earth2me.essentials.textreader.SimpleTextInput in project Essentials by drtshock.

the class Essentials method broadcastMessage.

private int broadcastMessage(final IUser sender, final String permission, final String message, final boolean keywords) {
    if (sender != null && sender.isHidden()) {
        return 0;
    }
    IText broadcast = new SimpleTextInput(message);
    final Collection<Player> players = getOnlinePlayers();
    for (Player player : players) {
        final User user = getUser(player);
        if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
            if (keywords) {
                broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false);
            }
            for (String messageText : broadcast.getLines()) {
                user.sendMessage(messageText);
            }
        }
    }
    return players.size();
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) Player(org.bukkit.entity.Player) SimpleTextInput(com.earth2me.essentials.textreader.SimpleTextInput) IText(com.earth2me.essentials.textreader.IText)

Example 2 with SimpleTextInput

use of com.earth2me.essentials.textreader.SimpleTextInput in project Essentials by drtshock.

the class Kit method expandItems.

public void expandItems(final User user, final List<String> items) throws Exception {
    try {
        IText input = new SimpleTextInput(items);
        IText output = new KeywordReplacer(input, user.getSource(), ess);
        boolean spew = false;
        final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
        for (String kitItem : output.getLines()) {
            if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) {
                BigDecimal value = new BigDecimal(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
                Trade t = new Trade(value, ess);
                t.pay(user, OverflowType.DROP);
                continue;
            }
            if (kitItem.startsWith("/")) {
                String command = kitItem.substring(1);
                String name = user.getName();
                command = command.replace("{player}", name);
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
                continue;
            }
            final String[] parts = kitItem.split(" +");
            final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
            if (parseStack.getType() == Material.AIR) {
                continue;
            }
            final MetaItemStack metaStack = new MetaItemStack(parseStack);
            if (parts.length > 2) {
                // We pass a null sender here because kits should not do perm checks
                metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
            }
            final Map<Integer, ItemStack> overfilled;
            final boolean allowOversizedStacks = user.isAuthorized("essentials.oversizedstacks");
            if (allowOversizedStacks) {
                overfilled = InventoryWorkaround.addOversizedItems(user.getBase().getInventory(), ess.getSettings().getOversizedStackSize(), metaStack.getItemStack());
            } else {
                overfilled = InventoryWorkaround.addItems(user.getBase().getInventory(), metaStack.getItemStack());
            }
            for (ItemStack itemStack : overfilled.values()) {
                int spillAmount = itemStack.getAmount();
                if (!allowOversizedStacks) {
                    itemStack.setAmount(spillAmount < itemStack.getMaxStackSize() ? spillAmount : itemStack.getMaxStackSize());
                }
                while (spillAmount > 0) {
                    user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
                    spillAmount -= itemStack.getAmount();
                }
                spew = true;
            }
        }
        user.getBase().updateInventory();
        if (spew) {
            user.sendMessage(tl("kitInvFull"));
        }
    } catch (Exception e) {
        user.getBase().updateInventory();
        ess.getLogger().log(Level.WARNING, e.getMessage());
        throw new Exception(tl("kitError2"), e);
    }
}
Also used : BigDecimal(java.math.BigDecimal) NoChargeException(com.earth2me.essentials.commands.NoChargeException) KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) SimpleTextInput(com.earth2me.essentials.textreader.SimpleTextInput) IText(com.earth2me.essentials.textreader.IText) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with SimpleTextInput

use of com.earth2me.essentials.textreader.SimpleTextInput in project Essentials by drtshock.

the class Commandmail method run.

//TODO: Tidy this up / TL these errors.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) {
        final List<String> mail = user.getMails();
        if (mail.isEmpty()) {
            user.sendMessage(tl("noMail"));
            throw new NoChargeException();
        }
        IText input = new SimpleTextInput(mail);
        final TextPager pager = new TextPager(input);
        pager.showPage(args.length > 1 ? args[1] : null, null, commandLabel + " " + args[0], user.getSource());
        user.sendMessage(tl("mailClear"));
        return;
    }
    if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) {
        if (!user.isAuthorized("essentials.mail.send")) {
            throw new Exception(tl("noPerm", "essentials.mail.send"));
        }
        if (user.isMuted()) {
            throw new Exception(tl("voiceSilenced"));
        }
        User u = getPlayer(server, args[1], true, true);
        if (u == null) {
            throw new Exception(tl("playerNeverOnServer", args[1]));
        }
        final String mail = tl("mailFormat", user.getName(), StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2))));
        if (mail.length() > 1000) {
            throw new Exception(tl("mailTooLong"));
        }
        if (!u.isIgnoredPlayer(user)) {
            if (Math.abs(System.currentTimeMillis() - timestamp) > 60000) {
                timestamp = System.currentTimeMillis();
                mailsPerMinute = 0;
            }
            mailsPerMinute++;
            if (mailsPerMinute > ess.getSettings().getMailsPerMinute()) {
                throw new Exception(tl("mailDelay", ess.getSettings().getMailsPerMinute()));
            }
            u.addMail(tl("mailMessage", mail));
        }
        user.sendMessage(tl("mailSentTo", u.getDisplayName(), u.getName()));
        user.sendMessage(mail);
        return;
    }
    if (args.length > 1 && "sendall".equalsIgnoreCase(args[0])) {
        if (!user.isAuthorized("essentials.mail.sendall")) {
            throw new Exception(tl("noPerm", "essentials.mail.sendall"));
        }
        ess.runTaskAsynchronously(new SendAll(tl("mailFormat", user.getName(), FormatUtil.stripFormat(getFinalArg(args, 1)))));
        user.sendMessage(tl("mailSent"));
        return;
    }
    if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) {
        user.setMails(null);
        user.sendMessage(tl("mailCleared"));
        return;
    }
    throw new NotEnoughArgumentsException();
}
Also used : User(com.earth2me.essentials.User) SimpleTextInput(com.earth2me.essentials.textreader.SimpleTextInput) TextPager(com.earth2me.essentials.textreader.TextPager) IText(com.earth2me.essentials.textreader.IText)

Example 4 with SimpleTextInput

use of com.earth2me.essentials.textreader.SimpleTextInput in project Essentials by drtshock.

the class Commandbroadcastworld method sendToWorld.

private void sendToWorld(World world, String message) {
    IText broadcast = new SimpleTextInput(message);
    final Collection<Player> players = ess.getOnlinePlayers();
    for (Player player : players) {
        if (player.getWorld().equals(world)) {
            final User user = ess.getUser(player);
            broadcast = new KeywordReplacer(broadcast, new CommandSource(player), ess, false);
            for (String messageText : broadcast.getLines()) {
                user.sendMessage(messageText);
            }
        }
    }
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) SimpleTextInput(com.earth2me.essentials.textreader.SimpleTextInput) IText(com.earth2me.essentials.textreader.IText) CommandSource(com.earth2me.essentials.CommandSource)

Aggregations

IText (com.earth2me.essentials.textreader.IText)4 SimpleTextInput (com.earth2me.essentials.textreader.SimpleTextInput)4 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)3 User (com.earth2me.essentials.User)2 Player (org.bukkit.entity.Player)2 CommandSource (com.earth2me.essentials.CommandSource)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1 TextPager (com.earth2me.essentials.textreader.TextPager)1 BigDecimal (java.math.BigDecimal)1 ItemStack (org.bukkit.inventory.ItemStack)1