Search in sources :

Example 6 with Kit

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

the class Commandkit method giveKits.

private void giveKits(final User userTo, final User userFrom, final String kitNames) throws Exception {
    if (kitNames.isEmpty()) {
        throw new Exception(tl("kitNotFound"));
    }
    String[] kitList = kitNames.split(",");
    List<Kit> kits = new ArrayList<Kit>();
    for (final String kitName : kitList) {
        if (kitName.isEmpty()) {
            throw new Exception(tl("kitNotFound"));
        }
        Kit kit = new Kit(kitName, ess);
        kit.checkPerms(userFrom);
        kit.checkDelay(userFrom);
        kit.checkAffordable(userFrom);
        kits.add(kit);
    }
    for (final Kit kit : kits) {
        try {
            kit.checkDelay(userFrom);
            kit.checkAffordable(userFrom);
            kit.setTime(userFrom);
            kit.expandItems(userTo);
            kit.chargeUser(userTo);
            if (!userFrom.equals(userTo)) {
                userFrom.sendMessage(tl("kitGiveTo", kit.getName(), userTo.getDisplayName()));
            }
            userTo.sendMessage(tl("kitReceive", kit.getName()));
        } catch (NoChargeException ex) {
            if (ess.getSettings().isDebug()) {
                ess.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex);
            }
        } catch (Exception ex) {
            ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName());
        }
    }
}
Also used : Kit(com.earth2me.essentials.Kit) ArrayList(java.util.ArrayList)

Example 7 with Kit

use of com.earth2me.essentials.Kit in project Essentials by EssentialsX.

the class Commandkit method run.

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 2) {
        final String kitList = ess.getKits().listKits(ess, null);
        sender.sendMessage(kitList.length() > 0 ? tl("kits", kitList) : tl("noKits"));
        throw new NoChargeException();
    } else {
        final User userTo = getPlayer(server, args, 1, true, false);
        final String[] kits = args[0].toLowerCase(Locale.ENGLISH).split(",");
        for (final String kitName : kits) {
            final Kit kit = new Kit(kitName, ess);
            kit.expandItems(userTo);
            sender.sendMessage(tl("kitGiveTo", kitName, userTo.getDisplayName()));
            userTo.sendMessage(tl("kitReceive", kitName));
        }
    }
}
Also used : User(com.earth2me.essentials.User) Kit(com.earth2me.essentials.Kit)

Example 8 with Kit

use of com.earth2me.essentials.Kit in project Essentials by EssentialsX.

the class Commandkit method giveKits.

private void giveKits(final User userTo, final User userFrom, final String kitNames) throws Exception {
    if (kitNames.isEmpty()) {
        throw new Exception(tl("kitNotFound"));
    }
    String[] kitList = kitNames.split(",");
    List<Kit> kits = new ArrayList<Kit>();
    for (final String kitName : kitList) {
        if (kitName.isEmpty()) {
            throw new Exception(tl("kitNotFound"));
        }
        Kit kit = new Kit(kitName, ess);
        kit.checkPerms(userFrom);
        kit.checkDelay(userFrom);
        kit.checkAffordable(userFrom);
        kits.add(kit);
    }
    for (final Kit kit : kits) {
        try {
            kit.checkDelay(userFrom);
            kit.checkAffordable(userFrom);
            kit.setTime(userFrom);
            kit.expandItems(userTo);
            kit.chargeUser(userTo);
            if (!userFrom.equals(userTo)) {
                userFrom.sendMessage(tl("kitGiveTo", kit.getName(), userTo.getDisplayName()));
            }
            userTo.sendMessage(tl("kitReceive", kit.getName()));
        } catch (NoChargeException ex) {
            if (ess.getSettings().isDebug()) {
                ess.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex);
            }
        } catch (Exception ex) {
            ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName());
        }
    }
}
Also used : Kit(com.earth2me.essentials.Kit) ArrayList(java.util.ArrayList)

Example 9 with Kit

use of com.earth2me.essentials.Kit in project Essentials by EssentialsX.

the class Commandshowkit method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length != 1) {
        throw new NotEnoughArgumentsException();
    }
    final String[] kits = args[0].toLowerCase(Locale.ENGLISH).split(",");
    for (final String kitName : kits) {
        Kit kit = new Kit(kitName, ess);
        user.sendMessage(tl("kitContains", kitName));
        for (String s : kit.getItems()) {
            user.sendMessage(tl("kitItem", s));
        }
    }
}
Also used : Kit(com.earth2me.essentials.Kit)

Example 10 with Kit

use of com.earth2me.essentials.Kit in project Essentials by EssentialsX.

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

Kit (com.earth2me.essentials.Kit)10 User (com.earth2me.essentials.User)4 ChargeException (com.earth2me.essentials.ChargeException)2 Trade (com.earth2me.essentials.Trade)2 NoChargeException (com.earth2me.essentials.commands.NoChargeException)2 IText (com.earth2me.essentials.textreader.IText)2 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)2 SimpleTextPager (com.earth2me.essentials.textreader.SimpleTextPager)2 ArrayList (java.util.ArrayList)2 Location (org.bukkit.Location)2