Search in sources :

Example 6 with IText

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

the class Commandmotd method run.

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (sender.isPlayer()) {
        ess.getUser(sender.getPlayer()).setDisplayNick();
    }
    final IText input = new TextInput(sender, "motd", true, ess);
    final IText output = new KeywordReplacer(input, sender, ess);
    final TextPager pager = new TextPager(output);
    pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) TextPager(com.earth2me.essentials.textreader.TextPager) IText(com.earth2me.essentials.textreader.IText) TextInput(com.earth2me.essentials.textreader.TextInput)

Example 7 with IText

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

the class Commandinfo method run.

@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (sender.isPlayer()) {
        ess.getUser(sender.getPlayer()).setDisplayNick();
    }
    final IText input = new TextInput(sender, "info", true, ess);
    final IText output = new KeywordReplacer(input, sender, ess);
    final TextPager pager = new TextPager(output);
    pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) TextPager(com.earth2me.essentials.textreader.TextPager) IText(com.earth2me.essentials.textreader.IText) TextInput(com.earth2me.essentials.textreader.TextInput)

Example 8 with IText

use of com.earth2me.essentials.textreader.IText 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 9 with IText

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

the class SignInfo method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
    final Trade charge = getTrade(sign, 3, ess);
    charge.isAffordableFor(player);
    String chapter = sign.getLine(1);
    String page = sign.getLine(2);
    final IText input;
    try {
        player.setDisplayNick();
        input = new TextInput(player.getSource(), "info", true, ess);
        final IText output = new KeywordReplacer(input, player.getSource(), ess);
        final TextPager pager = new TextPager(output);
        pager.showPage(chapter, page, null, player.getSource());
    } catch (IOException ex) {
        throw new SignException(ex.getMessage(), ex);
    }
    charge.charge(player);
    Trade.log("Sign", "Info", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
    return true;
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) Trade(com.earth2me.essentials.Trade) TextPager(com.earth2me.essentials.textreader.TextPager) IText(com.earth2me.essentials.textreader.IText) IOException(java.io.IOException) TextInput(com.earth2me.essentials.textreader.TextInput)

Example 10 with IText

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

the class MetaItemStack method addStringMeta.

public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception {
    final String[] split = splitPattern.split(string, 2);
    if (split.length < 1) {
        return;
    }
    Material banner = null;
    Material shield = null;
    try {
        // 1.8
        banner = Material.valueOf("BANNER");
        // 1.9
        shield = Material.valueOf("SHIELD");
    } catch (IllegalArgumentException ignored) {
    }
    if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess)) {
        final String displayName = FormatUtil.replaceFormat(split[1].replace('_', ' '));
        final ItemMeta meta = stack.getItemMeta();
        meta.setDisplayName(displayName);
        stack.setItemMeta(meta);
    } else if (split.length > 1 && (split[0].equalsIgnoreCase("lore") || split[0].equalsIgnoreCase("desc")) && hasMetaPermission(sender, "lore", false, true, ess)) {
        final List<String> lore = new ArrayList<String>();
        for (String line : split[1].split("\\|")) {
            lore.add(FormatUtil.replaceFormat(line.replace('_', ' ')));
        }
        final ItemMeta meta = stack.getItemMeta();
        meta.setLore(lore);
        stack.setItemMeta(meta);
    } else if (split.length > 1 && (split[0].equalsIgnoreCase("unbreakable") && hasMetaPermission(sender, "unbreakable", false, true, ess))) {
        setUnbreakable(stack, Boolean.valueOf(split[1]));
    } else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && stack.getType() == Material.SKULL_ITEM && hasMetaPermission(sender, "head", false, true, ess)) {
        if (stack.getDurability() == 3) {
            final String owner = split[1];
            final SkullMeta meta = (SkullMeta) stack.getItemMeta();
            meta.setOwner(owner);
            stack.setItemMeta(meta);
        } else {
            throw new Exception(tl("onlyPlayerSkulls"));
        }
    } else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == Material.WRITTEN_BOOK && (hasMetaPermission(sender, "book", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) {
        final BookMeta meta = (BookMeta) stack.getItemMeta();
        final IText input = new BookInput("book", true, ess);
        final BookPager pager = new BookPager(input);
        List<String> pages = pager.getPages(split[1]);
        meta.setPages(pages);
        stack.setItemMeta(meta);
    } else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess)) {
        final String author = FormatUtil.replaceFormat(split[1]);
        final BookMeta meta = (BookMeta) stack.getItemMeta();
        meta.setAuthor(author);
        stack.setItemMeta(meta);
    } else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) {
        final String title = FormatUtil.replaceFormat(split[1].replace('_', ' '));
        final BookMeta meta = (BookMeta) stack.getItemMeta();
        meta.setTitle(title);
        stack.setItemMeta(meta);
    } else if (split.length > 1 && split[0].equalsIgnoreCase("power") && stack.getType() == Material.FIREWORK && hasMetaPermission(sender, "firework-power", false, true, ess)) {
        final int power = NumberUtil.isInt(split[1]) ? Integer.parseInt(split[1]) : 0;
        final FireworkMeta meta = (FireworkMeta) stack.getItemMeta();
        meta.setPower(power > 3 ? 4 : power);
        stack.setItemMeta(meta);
    } else if (stack.getType() == Material.FIREWORK) {
        //WARNING - Meta for fireworks will be ignored after this point.
        addFireworkMeta(sender, false, string, ess);
    } else if (isPotion(stack.getType())) {
        //WARNING - Meta for potions will be ignored after this point.
        addPotionMeta(sender, false, string, ess);
    } else if (banner != null && stack.getType() == banner) {
        //WARNING - Meta for banners will be ignored after this point.
        addBannerMeta(sender, false, string, ess);
    } else if (shield != null && stack.getType() == shield) {
        //WARNING - Meta for shields will be ignored after this point.
        addBannerMeta(sender, false, string, ess);
    } else if (split.length > 1 && (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour")) && (stack.getType() == Material.LEATHER_BOOTS || stack.getType() == Material.LEATHER_CHESTPLATE || stack.getType() == Material.LEATHER_HELMET || stack.getType() == Material.LEATHER_LEGGINGS)) {
        final String[] color = split[1].split("(\\||,)");
        if (color.length == 1 && (NumberUtil.isInt(color[0]) || color[0].startsWith("#"))) {
            // int rgb and hex
            final LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
            String input = color[0];
            if (input.startsWith("#")) {
                meta.setColor(Color.fromRGB(Integer.valueOf(input.substring(1, 3), 16), Integer.valueOf(input.substring(3, 5), 16), Integer.valueOf(input.substring(5, 7), 16)));
            } else {
                meta.setColor(Color.fromRGB(Integer.parseInt(input)));
            }
            stack.setItemMeta(meta);
        } else if (color.length == 3) {
            // r,g,b
            final int red = NumberUtil.isInt(color[0]) ? Integer.parseInt(color[0]) : 0;
            final int green = NumberUtil.isInt(color[1]) ? Integer.parseInt(color[1]) : 0;
            final int blue = NumberUtil.isInt(color[2]) ? Integer.parseInt(color[2]) : 0;
            final LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
            meta.setColor(Color.fromRGB(red, green, blue));
            stack.setItemMeta(meta);
        } else {
            throw new Exception(tl("leatherSyntax"));
        }
    } else {
        parseEnchantmentStrings(sender, allowUnsafe, split, ess);
    }
}
Also used : BookInput(com.earth2me.essentials.textreader.BookInput) Material(org.bukkit.Material) IText(com.earth2me.essentials.textreader.IText) BookPager(com.earth2me.essentials.textreader.BookPager)

Aggregations

IText (com.earth2me.essentials.textreader.IText)12 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)10 TextPager (com.earth2me.essentials.textreader.TextPager)7 TextInput (com.earth2me.essentials.textreader.TextInput)6 SimpleTextInput (com.earth2me.essentials.textreader.SimpleTextInput)4 User (com.earth2me.essentials.User)3 Player (org.bukkit.entity.Player)3 IOException (java.io.IOException)2 CommandSource (com.earth2me.essentials.CommandSource)1 Kit (com.earth2me.essentials.Kit)1 Trade (com.earth2me.essentials.Trade)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1 BookInput (com.earth2me.essentials.textreader.BookInput)1 BookPager (com.earth2me.essentials.textreader.BookPager)1 SimpleTextPager (com.earth2me.essentials.textreader.SimpleTextPager)1 BigDecimal (java.math.BigDecimal)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1