Search in sources :

Example 11 with TextInput

use of com.earth2me.essentials.textreader.TextInput in project Essentials by EssentialsX.

the class EssentialsPlayerListener method delayedJoin.

public void delayedJoin(final Player player, final String message) {
    if (!player.isOnline()) {
        return;
    }
    ess.getBackup().onPlayerJoin();
    final User dUser = ess.getUser(player);
    dUser.startTransaction();
    if (dUser.isNPC()) {
        dUser.setNPC(false);
    }
    final long currentTime = System.currentTimeMillis();
    dUser.checkMuteTimeout(currentTime);
    dUser.updateActivityOnInteract(false);
    dUser.stopTransaction();
    class DelayJoinTask implements Runnable {

        @Override
        public void run() {
            final User user = ess.getUser(player);
            if (!user.getBase().isOnline()) {
                return;
            }
            user.startTransaction();
            user.setLastAccountName(user.getBase().getName());
            user.setLastLogin(currentTime);
            user.setDisplayNick();
            updateCompass(user);
            if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
                for (String p : ess.getVanishedPlayersNew()) {
                    Player toVanish = ess.getServer().getPlayerExact(p);
                    if (toVanish != null && toVanish.isOnline()) {
                        user.getBase().hidePlayer(toVanish);
                        if (ess.getSettings().isDebug()) {
                            ess.getLogger().info("Hiding vanished player: " + p);
                        }
                    }
                }
            }
            if (user.isAuthorized("essentials.sleepingignored")) {
                user.getBase().setSleepingIgnored(true);
            }
            if (ess.getSettings().allowSilentJoinQuit() && (user.isAuthorized("essentials.silentjoin") || user.isAuthorized("essentials.silentjoin.vanish"))) {
                if (user.isAuthorized("essentials.silentjoin.vanish")) {
                    user.setVanished(true);
                }
            } else if (message == null) {
            // NOOP
            } else if (ess.getSettings().isCustomJoinMessage()) {
                String msg = ess.getSettings().getCustomJoinMessage().replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName()).replace("{UNIQUE}", NumberFormat.getInstance().format(ess.getUserMap().getUniqueUsers()));
                ess.getServer().broadcastMessage(msg);
            } else if (ess.getSettings().allowSilentJoinQuit()) {
                ess.getServer().broadcastMessage(message);
            }
            int motdDelay = ess.getSettings().getMotdDelay() / 50;
            DelayMotdTask motdTask = new DelayMotdTask(user);
            if (motdDelay > 0) {
                ess.scheduleSyncDelayedTask(motdTask, motdDelay);
            } else {
                motdTask.run();
            }
            if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
                final List<String> mail = user.getMails();
                if (mail.isEmpty()) {
                    if (ess.getSettings().isNotifyNoNewMail()) {
                        // Only notify if they want us to.
                        user.sendMessage(tl("noNewMail"));
                    }
                } else {
                    user.notifyOfMail();
                }
            }
            if (user.isAuthorized("essentials.fly.safelogin")) {
                user.getBase().setFallDistance(0);
                if (LocationUtil.shouldFly(user.getLocation())) {
                    user.getBase().setAllowFlight(true);
                    user.getBase().setFlying(true);
                    if (ess.getSettings().isSendFlyEnableOnJoin()) {
                        user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName()));
                    }
                }
            }
            if (!user.isAuthorized("essentials.speed")) {
                user.getBase().setFlySpeed(0.1f);
                user.getBase().setWalkSpeed(0.2f);
            }
            if (user.isSocialSpyEnabled() && !user.isAuthorized("essentials.socialspy")) {
                user.setSocialSpyEnabled(false);
                ess.getLogger().log(Level.INFO, "Set socialspy to false for {0} because they had it enabled without permission.", user.getName());
            }
            if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) {
                user.setGodModeEnabled(false);
                ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName());
            }
            user.stopTransaction();
        }

        class DelayMotdTask implements Runnable {

            private User user;

            public DelayMotdTask(User user) {
                this.user = user;
            }

            @Override
            public void run() {
                IText tempInput = null;
                if (!ess.getSettings().isCommandDisabled("motd")) {
                    try {
                        tempInput = new TextInput(user.getSource(), "motd", true, ess);
                    } catch (IOException ex) {
                        if (ess.getSettings().isDebug()) {
                            LOGGER.log(Level.WARNING, ex.getMessage(), ex);
                        } else {
                            LOGGER.log(Level.WARNING, ex.getMessage());
                        }
                    }
                }
                final IText input = tempInput;
                if (input != null && !input.getLines().isEmpty() && user.isAuthorized("essentials.motd")) {
                    final IText output = new KeywordReplacer(input, user.getSource(), ess);
                    final TextPager pager = new TextPager(output, true);
                    pager.showPage("1", null, "motd", user.getSource());
                }
            }
        }
    }
    ess.scheduleSyncDelayedTask(new DelayJoinTask());
}
Also used : Player(org.bukkit.entity.Player) TextPager(com.earth2me.essentials.textreader.TextPager) IOException(java.io.IOException) KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) IText(com.earth2me.essentials.textreader.IText) TextInput(com.earth2me.essentials.textreader.TextInput)

Example 12 with TextInput

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

the class EssentialsPlayerListener method delayedJoin.

public void delayedJoin(final Player player, final String message) {
    if (!player.isOnline()) {
        return;
    }
    ess.getBackup().onPlayerJoin();
    final User dUser = ess.getUser(player);
    dUser.startTransaction();
    if (dUser.isNPC()) {
        dUser.setNPC(false);
    }
    final long currentTime = System.currentTimeMillis();
    dUser.checkMuteTimeout(currentTime);
    dUser.updateActivityOnInteract(false);
    dUser.stopTransaction();
    class DelayJoinTask implements Runnable {

        @Override
        public void run() {
            final User user = ess.getUser(player);
            if (!user.getBase().isOnline()) {
                return;
            }
            user.startTransaction();
            user.setLastAccountName(user.getBase().getName());
            user.setLastLogin(currentTime);
            user.setDisplayNick();
            updateCompass(user);
            if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
                for (String p : ess.getVanishedPlayersNew()) {
                    Player toVanish = ess.getServer().getPlayerExact(p);
                    if (toVanish != null && toVanish.isOnline()) {
                        user.getBase().hidePlayer(toVanish);
                        if (ess.getSettings().isDebug()) {
                            ess.getLogger().info("Hiding vanished player: " + p);
                        }
                    }
                }
            }
            if (user.isAuthorized("essentials.sleepingignored")) {
                user.getBase().setSleepingIgnored(true);
            }
            if (ess.getSettings().allowSilentJoinQuit() && (user.isAuthorized("essentials.silentjoin") || user.isAuthorized("essentials.silentjoin.vanish"))) {
                if (user.isAuthorized("essentials.silentjoin.vanish")) {
                    user.setVanished(true);
                }
            } else if (message == null) {
            // NOOP
            } else if (ess.getSettings().isCustomJoinMessage()) {
                String msg = ess.getSettings().getCustomJoinMessage().replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName()).replace("{UNIQUE}", NumberFormat.getInstance().format(ess.getUserMap().getUniqueUsers()));
                ess.getServer().broadcastMessage(msg);
            } else if (ess.getSettings().allowSilentJoinQuit()) {
                ess.getServer().broadcastMessage(message);
            }
            int motdDelay = ess.getSettings().getMotdDelay() / 50;
            DelayMotdTask motdTask = new DelayMotdTask(user);
            if (motdDelay > 0) {
                ess.scheduleSyncDelayedTask(motdTask, motdDelay);
            } else {
                motdTask.run();
            }
            if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
                final List<String> mail = user.getMails();
                if (mail.isEmpty()) {
                    if (ess.getSettings().isNotifyNoNewMail()) {
                        // Only notify if they want us to.
                        user.sendMessage(tl("noNewMail"));
                    }
                } else {
                    user.notifyOfMail();
                }
            }
            if (user.isAuthorized("essentials.fly.safelogin")) {
                user.getBase().setFallDistance(0);
                if (LocationUtil.shouldFly(user.getLocation())) {
                    user.getBase().setAllowFlight(true);
                    user.getBase().setFlying(true);
                    if (ess.getSettings().isSendFlyEnableOnJoin()) {
                        user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName()));
                    }
                }
            }
            if (!user.isAuthorized("essentials.speed")) {
                user.getBase().setFlySpeed(0.1f);
                user.getBase().setWalkSpeed(0.2f);
            }
            if (user.isSocialSpyEnabled() && !user.isAuthorized("essentials.socialspy")) {
                user.setSocialSpyEnabled(false);
                ess.getLogger().log(Level.INFO, "Set socialspy to false for {0} because they had it enabled without permission.", user.getName());
            }
            if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) {
                user.setGodModeEnabled(false);
                ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName());
            }
            user.stopTransaction();
        }

        class DelayMotdTask implements Runnable {

            private User user;

            public DelayMotdTask(User user) {
                this.user = user;
            }

            @Override
            public void run() {
                IText tempInput = null;
                if (!ess.getSettings().isCommandDisabled("motd")) {
                    try {
                        tempInput = new TextInput(user.getSource(), "motd", true, ess);
                    } catch (IOException ex) {
                        if (ess.getSettings().isDebug()) {
                            LOGGER.log(Level.WARNING, ex.getMessage(), ex);
                        } else {
                            LOGGER.log(Level.WARNING, ex.getMessage());
                        }
                    }
                }
                final IText input = tempInput;
                if (input != null && !input.getLines().isEmpty() && user.isAuthorized("essentials.motd")) {
                    final IText output = new KeywordReplacer(input, user.getSource(), ess);
                    final TextPager pager = new TextPager(output, true);
                    pager.showPage("1", null, "motd", user.getSource());
                }
            }
        }
    }
    ess.scheduleSyncDelayedTask(new DelayJoinTask());
}
Also used : Player(org.bukkit.entity.Player) TextPager(com.earth2me.essentials.textreader.TextPager) IOException(java.io.IOException) KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) IText(com.earth2me.essentials.textreader.IText) TextInput(com.earth2me.essentials.textreader.TextInput)

Aggregations

IText (com.earth2me.essentials.textreader.IText)12 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)12 TextInput (com.earth2me.essentials.textreader.TextInput)12 TextPager (com.earth2me.essentials.textreader.TextPager)12 IOException (java.io.IOException)4 Trade (com.earth2me.essentials.Trade)2 Player (org.bukkit.entity.Player)2