Search in sources :

Example 1 with KeywordReplacer

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

the class Commandcustomtext 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, "custom", true, ess);
    final IText output = new KeywordReplacer(input, sender, ess);
    final TextPager pager = new TextPager(output);
    String chapter = commandLabel;
    String page;
    if (commandLabel.equalsIgnoreCase("customtext") && args.length > 0 && !NumberUtil.isInt(commandLabel)) {
        chapter = args[0];
        page = args.length > 1 ? args[1] : null;
    } else {
        page = args.length > 0 ? args[0] : null;
    }
    pager.showPage(chapter, page, null, 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 2 with KeywordReplacer

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

the class Commandrules 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, "rules", 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 3 with KeywordReplacer

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

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

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

the class EssentialsSpawnPlayerListener method delayedJoin.

public void delayedJoin(final Player player) {
    if (player.hasPlayedBefore()) {
        LOGGER.log(Level.FINE, "Old player join");
        List<String> spawnOnJoinGroups = ess.getSettings().getSpawnOnJoinGroups();
        if (!spawnOnJoinGroups.isEmpty()) {
            final User user = ess.getUser(player);
            if (ess.getSettings().isUserInSpawnOnJoinGroup(user) && !user.isAuthorized("essentials.spawn-on-join.exempt")) {
                ess.scheduleSyncDelayedTask(new Runnable() {

                    @Override
                    public void run() {
                        Location spawn = spawns.getSpawn(user.getGroup());
                        try {
                            // We don't use user.getTeleport() because it stores last location, which is unwanted in this case.
                            user.getBase().teleport(spawn, TeleportCause.PLUGIN);
                        } catch (Exception e) {
                            ess.showError(user.getSource(), e, "spawn-on-join");
                        }
                    }
                });
            }
        }
        return;
    }
    final User user = ess.getUser(player);
    if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn())) {
        ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
    }
    ess.scheduleSyncDelayedTask(new Runnable() {

        @Override
        public void run() {
            if (!user.getBase().isOnline()) {
                return;
            }
            //This method allows for multiple line player announce messages using multiline yaml syntax #EasterEgg
            if (ess.getSettings().getAnnounceNewPlayers()) {
                final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user.getSource(), ess);
                final SimpleTextPager pager = new SimpleTextPager(output);
                for (String line : pager.getLines()) {
                    ess.broadcastMessage(user, line);
                }
            }
            final String kitName = ess.getSettings().getNewPlayerKit();
            if (!kitName.isEmpty()) {
                try {
                    final Kit kit = new Kit(kitName.toLowerCase(Locale.ENGLISH), ess);
                    kit.expandItems(user);
                } catch (Exception ex) {
                    LOGGER.log(Level.WARNING, ex.getMessage());
                }
            }
            LOGGER.log(Level.FINE, "New player join");
        }
    }, 2L);
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) User(com.earth2me.essentials.User) SimpleTextPager(com.earth2me.essentials.textreader.SimpleTextPager) Kit(com.earth2me.essentials.Kit) IText(com.earth2me.essentials.textreader.IText) Location(org.bukkit.Location)

Aggregations

IText (com.earth2me.essentials.textreader.IText)10 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)10 TextInput (com.earth2me.essentials.textreader.TextInput)6 TextPager (com.earth2me.essentials.textreader.TextPager)6 SimpleTextInput (com.earth2me.essentials.textreader.SimpleTextInput)3 Player (org.bukkit.entity.Player)3 User (com.earth2me.essentials.User)2 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 SimpleTextPager (com.earth2me.essentials.textreader.SimpleTextPager)1 BigDecimal (java.math.BigDecimal)1 Location (org.bukkit.Location)1 ItemStack (org.bukkit.inventory.ItemStack)1