Search in sources :

Example 6 with Replacer

use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.

the class CommandHandler method onCommand.

@Listener(order = Order.EARLY)
public void onCommand(SendCommandEvent e, @First CommandSource source) {
    String[] args = e.getArguments().split(" ");
    StringBuilder commandArgsAbr = new StringBuilder();
    Arrays.stream(args).forEach(arg -> commandArgsAbr.append(arg).append(" "));
    String commandArgs = commandArgsAbr.substring(0, commandArgsAbr.length() - 1);
    if (args.length >= 1 && (e.getCommand().equals("redprotect") || e.getCommand().equals("rp"))) {
        List<String> conditions = RedProtect.get().getConfigManager().configRoot().command_confirm;
        conditions.addAll(Arrays.asList(getCmd("yes"), getCmd("no")));
        if (conditions.stream().anyMatch(cmd -> checkCmd(args[0], cmd))) {
            String cmd = conditions.stream().filter(c -> checkCmd(args[0], c)).findFirst().get();
            if (!cmdConfirm.containsKey(source.getName()) && !checkCmd(cmd, "yes") && !checkCmd(cmd, "no")) {
                // Segure delete command
                if (source instanceof Player && cmd.equalsIgnoreCase("delete") && commandArgs.split(" ").length == 2) {
                    if (RedProtect.get().getRegionManager().getTopRegion(((Player) source).getLocation(), CommandHandler.class.getName()) == null)
                        return;
                    Region r = RedProtect.get().getRegionManager().getTopRegion(((Player) source).getLocation(), CommandHandler.class.getName());
                    commandArgs = commandArgs + " " + r.getName() + " " + r.getWorld();
                }
                cmdConfirm.put(source.getName(), commandArgs);
                RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + e.getCommand() + " " + cmd), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
                e.setCancelled(true);
            }
        }
        if (cmdConfirm.containsKey(source.getName())) {
            if (checkCmd(args[0], "yes")) {
                String cmd1 = cmdConfirm.get(source.getName());
                e.setArguments(cmd1);
                cmdConfirm.remove(source.getName());
            } else if (checkCmd(args[0], "no")) {
                cmdConfirm.remove(source.getName());
                RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.usagecancelled");
                e.setCancelled(true);
            } else {
                RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + e.getCommand() + " " + cmdConfirm.get(source.getName())), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
                e.setCancelled(true);
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) Listener(org.spongepowered.api.event.Listener)

Example 7 with Replacer

use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.

the class CommandHandlers method handleKillWorld.

public static void handleKillWorld(CommandSource sender, World world, EntityType type) {
    int killed = 0;
    int total = 0;
    int living = 0;
    for (Entity e : world.getEntities().stream().filter(entity -> !(entity instanceof Player) && ((entity instanceof Living && type == null) || entity.getType().equals(type))).collect(Collectors.toList())) {
        total++;
        if (RedProtect.get().getRegionManager().getTopRegion(e.getLocation(), CommandHandlers.class.getName()) == null) {
            e.remove();
            killed++;
        } else if (e instanceof Living && type == null) {
            living++;
        } else if (e.getType().equals(type)) {
            living++;
        }
    }
    RedProtect.get().getLanguageManager().sendMessage(sender, "cmdmanager.kill", new Replacer[] { new Replacer("{total}", String.valueOf(total)), new Replacer("{living}", String.valueOf(living)), new Replacer("{killed}", String.valueOf(killed)), new Replacer("{world}", world.getName()) });
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) java.util(java.util) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.RenameRegionEvent) BigDecimal(java.math.BigDecimal) ParticleType(org.spongepowered.api.effect.particle.ParticleType) Text(org.spongepowered.api.text.Text) Living(org.spongepowered.api.entity.living.Living) DimensionTypes(org.spongepowered.api.world.DimensionTypes) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) BlockTypes(org.spongepowered.api.block.BlockTypes) Sponge(org.spongepowered.api.Sponge) RedProtect(br.net.fabiozumbi12.RedProtect.Sponge.RedProtect) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent) TimeUnit(java.util.concurrent.TimeUnit) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) EntityType(org.spongepowered.api.entity.EntityType) Player(org.spongepowered.api.entity.living.player.Player) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) ItemFlagGui(br.net.fabiozumbi12.RedProtect.Sponge.guis.ItemFlagGui) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer)

Example 8 with Replacer

use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.

the class CommandHandler method onPreCommand.

@EventHandler
public void onPreCommand(PlayerCommandPreprocessEvent e) {
    Player p = e.getPlayer();
    String[] args = e.getMessage().split(" ");
    StringBuilder commandArgsAbr = new StringBuilder();
    Arrays.stream(args).forEach(arg -> commandArgsAbr.append(arg).append(" "));
    String commandArgs = commandArgsAbr.substring(1, commandArgsAbr.length() - 1);
    if (args.length >= 2 && (args[0].equals("/redprotect") || args[0].equals("/rp"))) {
        // Check perms
        if (hasCommand(args[1]) && !RedProtect.get().getPermissionHandler().hasCommandPerm(e.getPlayer(), getCmdFromAlias(args[1]))) {
            RedProtect.get().getLanguageManager().sendMessage(e.getPlayer(), "no.permission");
            e.setCancelled(true);
            return;
        }
        List<String> conditions = RedProtect.get().getConfigManager().configRoot().command_confirm;
        conditions.addAll(Arrays.asList(getCmd("yes"), getCmd("no")));
        if (conditions.stream().anyMatch(cmd -> checkCmd(args[1], cmd))) {
            String cmd = conditions.stream().filter(c -> checkCmd(args[1], c)).findFirst().get();
            if (!cmdConfirm.containsKey(p.getName()) && !checkCmd(cmd, "yes") && !checkCmd(cmd, "no")) {
                // Secure delete command
                if (cmd.equalsIgnoreCase("delete") && commandArgs.split(" ").length == 2) {
                    if (RedProtect.get().getRegionManager().getTopRegion(p.getLocation()) == null)
                        return;
                    Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation());
                    commandArgs = commandArgs + " " + r.getName() + " " + r.getWorld();
                }
                cmdConfirm.put(p.getName(), commandArgs);
                RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + args[0] + " " + cmd), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
                e.setCancelled(true);
            }
        }
        if (cmdConfirm.containsKey(p.getName())) {
            if (checkCmd(args[1], "yes")) {
                String cmd1 = cmdConfirm.get(p.getName());
                e.setMessage("/" + cmd1);
                cmdConfirm.remove(p.getName());
            } else if (checkCmd(args[1], "no")) {
                cmdConfirm.remove(p.getName());
                RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.usagecancelled");
                e.setCancelled(true);
            } else {
                RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + cmdConfirm.get(p.getName())), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
                e.setCancelled(true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Replacer

use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.

the class FlagGui method open.

public void open() {
    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
        if (player.getOpenInventory().getTopInventory().equals(this.inv)) {
            Region r = RedProtect.get().getRegionManager().getTopRegion(player.getLocation());
            if (r != null && r.equals(this.region) && !player.equals(this.player)) {
                RedProtect.get().getLanguageManager().sendMessage(this.player, "cmdmanager.region.rpgui-other", new Replacer[] { new Replacer("{player}", player.getName()) });
                return;
            }
        }
    }
    // Register Listener
    RedProtect.get().getServer().getPluginManager().registerEvents(this, RedProtect.get());
    this.inv = Bukkit.createInventory(player, this.size, this.name);
    inv.setContents(this.guiItems);
    player.openInventory(inv);
}
Also used : Player(org.bukkit.entity.Player) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer)

Example 10 with Replacer

use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.

the class CommandHandlers method handleKillWorld.

public static void handleKillWorld(CommandSender sender, World world, EntityType type) {
    int killed = 0;
    int total = 0;
    int living = 0;
    for (Entity e : world.getEntities().stream().filter(entity -> !(entity instanceof Player) && ((entity instanceof LivingEntity && type == null) || entity.getType().equals(type))).collect(Collectors.toList())) {
        total++;
        if (RedProtect.get().getRegionManager().getTopRegion(e.getLocation()) == null) {
            e.remove();
            killed++;
        } else if (e instanceof LivingEntity && type == null) {
            living++;
        } else if (e.getType().equals(type)) {
            living++;
        }
    }
    RedProtect.get().getLanguageManager().sendMessage(sender, "cmdmanager.kill", new Replacer[] { new Replacer("{total}", String.valueOf(total)), new Replacer("{living}", String.valueOf(living)), new Replacer("{killed}", String.valueOf(killed)), new Replacer("{world}", world.getName()) });
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent) CommandSender(org.bukkit.command.CommandSender) java.util(java.util) MobFlagGui(br.net.fabiozumbi12.RedProtect.Bukkit.guis.MobFlagGui) RedProtect(br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) Collectors(java.util.stream.Collectors) org.bukkit(org.bukkit) ItemFlagGui(br.net.fabiozumbi12.RedProtect.Bukkit.guis.ItemFlagGui) RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.API.events.RenameRegionEvent) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Clan(net.sacredlabyrinth.phaed.simpleclans.Clan) UltimateFancy(br.net.fabiozumbi12.UltimateFancy.UltimateFancy) PotionEffectType(org.bukkit.potion.PotionEffectType) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) org.bukkit.entity(org.bukkit.entity) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer)

Aggregations

Replacer (br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer)11 Player (org.bukkit.entity.Player)7 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)3 Player (org.spongepowered.api.entity.living.player.Player)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 DeleteRegionEvent (br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent)1 RenameRegionEvent (br.net.fabiozumbi12.RedProtect.Bukkit.API.events.RenameRegionEvent)1 RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)1 ItemFlagGui (br.net.fabiozumbi12.RedProtect.Bukkit.guis.ItemFlagGui)1 MobFlagGui (br.net.fabiozumbi12.RedProtect.Bukkit.guis.MobFlagGui)1 PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)1 RedProtect (br.net.fabiozumbi12.RedProtect.Sponge.RedProtect)1 DeleteRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent)1 RenameRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.RenameRegionEvent)1 ItemFlagGui (br.net.fabiozumbi12.RedProtect.Sponge.guis.ItemFlagGui)1 UltimateFancy (br.net.fabiozumbi12.UltimateFancy.UltimateFancy)1