Search in sources :

Example 41 with Location

use of org.spongepowered.api.world.Location in project guardian by ichorpowered.

the class MaterialCapture method update.

@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
    if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
        return;
    final Player player = entry.getEntity(Player.class).get();
    final Location<World> location = player.getLocation();
    final MapValue<String, Integer> activeMaterials = GuardianMapValue.builder(MaterialCapture.ACTIVE_MATERIAL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
    activeMaterials.put(GAS, 0);
    activeMaterials.put(LIQUID, 0);
    activeMaterials.put(SOLID, 0);
    captureContainer.offerIfEmpty(activeMaterials);
    captureContainer.offerIfEmpty(GuardianValue.builder(MaterialCapture.SPEED_MODIFIER).defaultElement(1d).element(1d).create());
    final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
    final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
    final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
    final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
    final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
    if (!WorldUtil.containsBlocksUnder(location, playerBox, 1.25)) {
        final double gasSpeed = this.matterSpeed.get(GAS);
        captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * gasSpeed));
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(GAS, value.get().get(GAS) + 1));
    } else if (WorldUtil.anyLiquidAtDepth(location, playerBox, 1d) || WorldUtil.anyLiquidAtDepth(location, playerBox, 0) || WorldUtil.anyLiquidAtDepth(location, playerBox, isSneaking ? -(playerHeight - 0.25) : -playerHeight)) {
        final double liquidSpeed = this.matterSpeed.get(LIQUID);
        captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * liquidSpeed));
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(LIQUID, value.get().get(LIQUID) + 1));
    } else {
        final List<BlockType> surroundingBlockTypes = WorldUtil.getBlocksUnder(location, playerBox, 1.25);
        for (final BlockType blockType : surroundingBlockTypes) {
            final double speedModifier = this.materialSpeed.getOrDefault(blockType.getName().toLowerCase(), this.matterSpeed.get(SOLID));
            captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * speedModifier));
        }
        captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(SOLID, value.get().get(SOLID) + 1));
    }
}
Also used : ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) GuardianCaptureKey(com.ichorpowered.guardian.sequence.capture.GuardianCaptureKey) TypeToken(com.google.common.reflect.TypeToken) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) ContentUtil(com.ichorpowered.guardian.util.ContentUtil) CaptureKey(com.ichorpowered.guardianapi.detection.capture.CaptureKey) Maps(com.google.common.collect.Maps) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) Detection(com.ichorpowered.guardianapi.detection.Detection) List(java.util.List) AbstractCapture(com.ichorpowered.guardian.sequence.capture.AbstractCapture) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) MapValue(com.ichorpowered.guardianapi.util.item.value.mutable.MapValue) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) PlayerEntry(com.ichorpowered.guardianapi.entry.entity.PlayerEntry) WorldUtil(com.ichorpowered.guardian.util.WorldUtil) Player(org.spongepowered.api.entity.living.player.Player) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) BoundingBox(com.ichorpowered.guardian.util.entity.BoundingBox) List(java.util.List)

Example 42 with Location

use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.

the class ChopListener method onChop.

@Listener
public void onChop(final ChangeBlockEvent.Break event, @First Player player) {
    if (!player.getItemInHand(HandTypes.MAIN_HAND).isPresent() || event.getCause().getContext().containsKey(EventContextKeys.PLAYER_SIMULATED)) {
        return;
    }
    ItemStack axe = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null);
    if (axe == null || axe.getType() != DIAMOND_AXE || axe.get(Keys.ITEM_DURABILITY).orElse(0) <= 0 || !axe.get(Keys.ITEM_ENCHANTMENTS).orElse(emptyList()).contains(Enchantment.builder().type(EnchantmentTypes.PUNCH).level(5).build())) {
        return;
    }
    if (!module.use.check(player)) {
        return;
    }
    Sponge.getCauseStackManager().addContext(EventContextKeys.PLAYER_SIMULATED, player.getProfile());
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType type = transaction.getOriginal().getState().getType();
        Location<World> orig = transaction.getOriginal().getLocation().get();
        BlockType belowType = orig.getBlockRelative(DOWN).getBlockType();
        if (isLog(type) && isSoil(belowType)) {
            TreeType treeType = transaction.getOriginal().get(TREE_TYPE).get();
            Set<Location<World>> treeBlocks = findTreeBlocks(orig, treeType);
            if (treeBlocks.isEmpty()) {
                return;
            }
            int logs = 0;
            int leaves = 0;
            Set<Location> saplings = new HashSet<>();
            for (Location<World> block : treeBlocks) {
                if (isLog(block.getBlockType())) {
                    if (!block.equals(orig)) {
                        block.getExtent().playSound(SoundTypes.BLOCK_WOOD_STEP, block.getPosition(), 1);
                    }
                    logs++;
                    block.setBlockType(BlockTypes.AIR);
                    BlockType belowTyp = block.getBlockRelative(DOWN).getBlockType();
                    if (isSoil(belowTyp)) {
                        saplings.add(block);
                    }
                }
                if (block.getBlockType() == LEAVES || block.getBlockType() == LEAVES2) {
                    block.setBlockType(BlockTypes.AIR);
                    // TODO leaves sound?
                    block.getExtent().playSound(SoundTypes.BLOCK_GRASS_STEP, block.getPosition(), 1);
                    leaves++;
                }
            }
            ItemStack log = ItemStack.builder().itemType(type.getItem().get()).quantity(logs).build();
            log.offer(TREE_TYPE, treeType);
            int apples = 0;
            if (treeType == JUNGLE) {
                leaves = leaves / 40;
            } else {
                if (treeType == DARK_OAK || treeType == OAK) {
                    apples = leaves / 200;
                }
                leaves = leaves / 20;
            }
            if (leaves == 0) {
                leaves = 1;
            }
            BlockState sapState = BlockTypes.SAPLING.getDefaultState().with(TREE_TYPE, treeType).get();
            if (this.module.autoplant.check(player)) {
                leaves -= saplings.size();
                leaves = Math.max(0, leaves);
                transaction.setCustom(sapState.snapshotFor(transaction.getOriginal().getLocation().get()));
                saplings.forEach(l -> l.setBlock(sapState));
            }
            final int uses = axe.get(Keys.ITEM_DURABILITY).get() - logs;
            axe.offer(Keys.ITEM_DURABILITY, uses);
            player.setItemInHand(HandTypes.MAIN_HAND, axe);
            World world = player.getWorld();
            Entity itemEntity;
            Sponge.getCauseStackManager().removeContext(EventContextKeys.PLAYER_SIMULATED);
            Sponge.getCauseStackManager().pushCause(player);
            if (apples > 0) {
                ItemStack apple = ItemStack.builder().itemType(APPLE).quantity(apples).build();
                itemEntity = world.createEntity(ITEM, orig.getPosition());
                itemEntity.offer(REPRESENTED_ITEM, apple.createSnapshot());
                world.spawnEntity(itemEntity);
            }
            if (leaves > 0) {
                ItemStack sap = ItemStack.builder().fromBlockState(sapState).build();
                sap.setQuantity(leaves);
                itemEntity = world.createEntity(ITEM, orig.getPosition());
                itemEntity.offer(REPRESENTED_ITEM, sap.createSnapshot());
                world.spawnEntity(itemEntity);
            }
            itemEntity = world.createEntity(ITEM, orig.getPosition());
            itemEntity.offer(REPRESENTED_ITEM, log.createSnapshot());
            world.spawnEntity(itemEntity);
            return;
        }
    }
}
Also used : TreeType(org.spongepowered.api.data.type.TreeType) Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) HashSet(java.util.HashSet) Listener(org.spongepowered.api.event.Listener)

Example 43 with Location

use of org.spongepowered.api.world.Location in project RedProtect by FabioZumbi12.

the class RPCommands method process.

@SuppressWarnings("deprecation")
public CommandResult process(CommandSource sender, String arguments) throws CommandException {
    CommandResult cmdr = CommandResult.success();
    String[] args = arguments.split(" ");
    if (!(sender instanceof Player)) {
        if (args.length == 1) {
            if (args[0].equalsIgnoreCase("single-to-files")) {
                RedProtect.get().logger.sucess("[" + RPUtil.SingleToFiles() + "]" + " regions converted to your own files with success");
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("files-to-single")) {
                RedProtect.get().logger.sucess("[" + RPUtil.FilesToSingle() + "]" + " regions converted to unified world file with success");
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("fileToMysql")) {
                try {
                    if (!RPUtil.fileToMysql()) {
                        RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'file' before convert from FILE to Mysql.");
                        return cmdr;
                    } else {
                        RedProtect.get().cfgs.setConfig("file-type", "mysql");
                        RedProtect.get().cfgs.save();
                        RedProtect.get().reload();
                        RedProtect.get().logger.sucess("Redprotect reloaded with Mysql as database! Ready to use!");
                        return cmdr;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return cmdr;
                }
            }
            if (args[0].equalsIgnoreCase("mysqlToFile")) {
                try {
                    if (!RPUtil.mysqlToFile()) {
                        RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'mysql' before convert from MYSQL to File.");
                        return cmdr;
                    } else {
                        RedProtect.get().cfgs.setConfig("file-type", "file");
                        RedProtect.get().cfgs.save();
                        RedProtect.get().reload();
                        RedProtect.get().logger.sucess("Redprotect reloaded with File as database! Ready to use!");
                        return cmdr;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return cmdr;
                }
            }
            if (args[0].isEmpty()) {
                sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------- " + RedProtect.get().container.getName() + " ----------------"));
                sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "Developed by &eFabioZumbi12" + RPLang.get("general.color") + "."));
                sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For more information about the commands, type [&e/rp ?" + RPLang.get("general.color") + "]."));
                sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For a tutorial, type [&e/rp tutorial" + RPLang.get("general.color") + "]."));
                sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------------------------------------------"));
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("list-all")) {
                int total = 0;
                for (Region r : RedProtect.get().rm.getAllRegions()) {
                    RedProtect.get().logger.info("&a[" + total + "]" + "Region: " + r.getName() + "&r | &3World: " + r.getWorld() + "&r");
                    total++;
                }
                RedProtect.get().logger.sucess(total + " regions for " + Sponge.getServer().getWorlds().size() + " worlds.");
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("save-all")) {
                RedProtect.get().rm.saveAll();
                RedProtect.get().logger.SaveLogs();
                RedProtect.get().logger.sucess(RedProtect.get().rm.getAllRegions().size() + " regions saved with success!");
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("load-all")) {
                RedProtect.get().rm.clearDB();
                try {
                    RedProtect.get().rm.loadAll();
                } catch (Exception e) {
                    RedProtect.get().logger.severe("Error on load all regions from database files:");
                    e.printStackTrace();
                }
                RedProtect.get().logger.sucess(RedProtect.get().rm.getAllRegions().size() + " regions has been loaded from database files!");
                return cmdr;
            }
            if (checkCmd(args[0], "reload")) {
                for (Player p : RedProtect.get().game.getServer().getOnlinePlayers()) {
                    RedProtect.get().getPVHelper().closeInventory(p);
                }
                RedProtect.get().reload();
                RedProtect.get().logger.sucess("Redprotect reloaded with success!");
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("reload-config")) {
                RedProtect.get().cfgs = new RPConfig();
                RPLang.init();
                RedProtect.get().logger.sucess("Redprotect Plus configs reloaded!");
                return cmdr;
            }
        }
        if (args.length == 2) {
            // rp removeall <player>
            if (checkCmd(args[0], "removeall")) {
                int removed = RedProtect.get().rm.removeAll(args[1]);
                if (removed <= 0) {
                    RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneremoved"));
                } else {
                    RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.removed").replace("{regions}", removed + "").replace("{player}", args[1]));
                }
                return cmdr;
            }
            // rp regenall <player>
            if (checkCmd(args[0], "regenall")) {
                int regen = RedProtect.get().rm.regenAll(args[1]);
                if (regen <= 0) {
                    RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneregenerated"));
                } else {
                    RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.regenerated").replace("{regions}", regen + "").replace("{player}", args[1]));
                }
                return cmdr;
            }
            // rp regen stop
            if (checkCmd(args[0], "regen") && args[1].equalsIgnoreCase("stop")) {
                if (!RedProtect.get().WE) {
                    return cmdr;
                }
                RPUtil.stopRegen = true;
                RPLang.sendMessage(sender, "&aRegen will stop now. To continue reload the plugin!");
                return cmdr;
            }
            // rp list <player>
            if (checkCmd(args[0], "list")) {
                getRegionforList(sender, RPUtil.PlayerToUUID(args[1]), 1);
                return cmdr;
            }
            // rp clamilimit player
            if (checkCmd(args[0], "claimlimit")) {
                User offp = RPUtil.getUser(args[1]);
                if (offp == null) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
                    return cmdr;
                }
                int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
                if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
                    return cmdr;
                }
                int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName())).size();
                sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
                return cmdr;
            }
            // rp limit player
            if (checkCmd(args[0], "limit")) {
                User offp = RPUtil.getUser(args[1]);
                if (offp == null) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
                    return cmdr;
                }
                int limit = RedProtect.get().ph.getPlayerBlockLimit(offp);
                if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.blocks.unlimited")) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
                    return cmdr;
                }
                int currentUsed = RedProtect.get().rm.getTotalRegionSize(RPUtil.PlayerToUUID(offp.getName()), offp.getPlayer().isPresent() ? offp.getPlayer().get().getWorld().getName() : null);
                sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
                return cmdr;
            }
        }
        if (args.length == 3) {
            // rp clamilimit player world
            if (checkCmd(args[0], "claimlimit")) {
                User offp = RPUtil.getUser(args[1]);
                World w = null;
                if (RedProtect.get().serv.getWorld(args[2]).isPresent()) {
                    w = RedProtect.get().serv.getWorld(args[2]).get();
                }
                if (offp == null) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
                    return cmdr;
                }
                int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
                if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
                    return cmdr;
                }
                if (w == null) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.invalidworld")));
                    return cmdr;
                }
                int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName()), w).size();
                sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
                return cmdr;
            }
            if (args[0].equalsIgnoreCase("setconfig")) {
                if (args[1].contains("debug-messages") || args[1].contains("file-type")) {
                    Object from = RedProtect.get().cfgs.getObject(args[1]);
                    if (args[2].equals("true") || args[2].equals("false")) {
                        RedProtect.get().cfgs.setConfig(args[1], Boolean.parseBoolean(args[2]));
                    } else {
                        try {
                            int value = Integer.parseInt(args[2]);
                            RedProtect.get().cfgs.setConfig(args[1], value);
                        } catch (NumberFormatException ex) {
                            RedProtect.get().cfgs.setConfig(args[1], args[2]);
                        }
                    }
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.configset") + " " + from + " > " + args[2]));
                    RedProtect.get().cfgs.save();
                    return cmdr;
                } else {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.confignotset") + " " + args[1]));
                    return cmdr;
                }
            }
            // rp info <region> <world>
            if (checkCmd(args[0], "info")) {
                if (Sponge.getServer().getWorld(args[2]).isPresent()) {
                    Region r = RedProtect.get().rm.getRegion(args[1], Sponge.getServer().getWorld(args[2]).get());
                    if (r != null) {
                        sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
                        sender.sendMessage(r.info());
                        sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
                    } else {
                        sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid region: " + args[1]));
                    }
                } else {
                    sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + " " + "&eInvalid World: " + args[2]));
                }
                return cmdr;
            }
        }
        if (args.length == 4) {
            if (checkCmd(args[0], "teleport")) {
                // rp tp <player> <region> <world>
                Player play = null;
                if (RedProtect.get().serv.getPlayer(args[1]).isPresent()) {
                    play = RedProtect.get().serv.getPlayer(args[1]).get();
                }
                if (play != null) {
                    World w = null;
                    if (RedProtect.get().serv.getWorld(args[3]).isPresent()) {
                        w = RedProtect.get().serv.getWorld(args[3]).get();
                    }
                    if (w == null) {
                        sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.invalidworld")));
                        return cmdr;
                    }
                    Region region = RedProtect.get().rm.getRegion(args[2], w);
                    if (region == null) {
                        sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]));
                        return cmdr;
                    }
                    Location<World> loc = null;
                    if (region.getTPPoint() != null) {
                        loc = new Location<>(w, region.getTPPoint().getBlockX() + 0.500, region.getTPPoint().getBlockY(), region.getTPPoint().getBlockZ() + 0.500);
                    } else {
                        int limit = 256;
                        if (w.getDimension().equals(DimensionTypes.NETHER)) {
                            limit = 124;
                        }
                        for (int i = limit; i > 0; i--) {
                            BlockType mat = new Location<>(w, region.getCenterX(), i, region.getCenterZ()).getBlockType();
                            BlockType mat1 = new Location<>(w, region.getCenterX(), i + 1, region.getCenterZ()).getBlockType();
                            BlockType mat2 = new Location<>(w, region.getCenterX(), i + 2, region.getCenterZ()).getBlockType();
                            if (!mat.equals(BlockTypes.LAVA) && !mat.equals(BlockTypes.AIR) && mat1.equals(BlockTypes.AIR) && mat2.equals(BlockTypes.AIR)) {
                                loc = new Location<>(w, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500);
                                break;
                            }
                        }
                    }
                    play.setLocation(loc);
                    RPLang.sendMessage(play, RPLang.get("cmdmanager.region.tp") + " " + args[2]);
                    sender.sendMessage(RPUtil.toText("&3Player teleported to " + args[2]));
                    return cmdr;
                } else {
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
                    HandleHelPage(sender, 1);
                    return cmdr;
                }
            }
            // rp flag info <region> <world>
            if (checkCmd(args[0], "flag") && checkCmd(args[1], "info")) {
                if (Sponge.getServer().getWorld(args[3]).isPresent()) {
                    Region r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
                    if (r != null) {
                        sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------[" + RPLang.get("cmdmanager.region.flag.values") + "]------------"));
                        sender.sendMessage(r.getFlagInfo());
                        sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
                    } else {
                        sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid region: " + args[2]));
                    }
                } else {
                    sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid World: " + args[3]));
                }
                return cmdr;
            }
        }
        if (args.length == 5) {
            /*/rp flag <regionName> <flag> <value> <world>*/
            if (checkCmd(args[0], "flag")) {
                World w = null;
                if (RedProtect.get().serv.getWorld(args[4]).isPresent()) {
                    w = RedProtect.get().serv.getWorld(args[4]).get();
                }
                if (w == null) {
                    sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&e rp flag <regionName> <flag> <value> <world>"));
                    return cmdr;
                }
                Region r = RedProtect.get().rm.getRegion(args[1], w);
                if (r != null && (RedProtect.get().cfgs.getDefFlags().contains(args[2]) || RedProtect.get().cfgs.AdminFlags.contains(args[2]))) {
                    Object objflag = RPUtil.parseObject(args[3]);
                    r.setFlag(args[2], objflag);
                    sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + args[2] + "'") + " " + r.getFlagString(args[2])));
                    RedProtect.get().logger.addLog("Console changed flag " + args[2] + " to " + r.getFlagString(args[2]));
                    return cmdr;
                }
            }
        }
        HandleHelPage(sender, 1);
        return cmdr;
    }
    // commands as player
    final Player player = (Player) sender;
    if (args.length == 1) {
        // rp regen
        if (checkCmd(args[0], "regen") && player.hasPermission("redprotect.regen")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.doesexists");
                return cmdr;
            }
            WEListener.regenRegion(r, Sponge.getServer().getWorld(r.getWorld()).get(), r.getMaxLocation(), r.getMinLocation(), 0, sender, false);
            return cmdr;
        }
        // rp undo
        if (args[0].equalsIgnoreCase("undo") && player.hasPermission("redprotect.regen")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.doesexists");
                return cmdr;
            }
            if (WEListener.undo(r.getID())) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.sucess").replace("{region}", r.getName()));
            } else {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.none").replace("{region}", r.getName()));
            }
            return cmdr;
        }
        String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
        if (claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH") || RedProtect.get().ph.hasGenPerm(player, "redefine")) {
            // rp pos1
            if (checkCmd(args[0], "pos1")) {
                Location<World> pl = player.getLocation();
                RedProtect.get().firstLocationSelections.put(player, pl);
                player.sendMessage(RPUtil.toText(RPLang.get("playerlistener.wand1") + RPLang.get("general.color") + " (&6" + pl.getBlockX() + RPLang.get("general.color") + ", &6" + pl.getBlockY() + RPLang.get("general.color") + ", &6" + pl.getBlockZ() + RPLang.get("general.color") + ")."));
                // show preview border
                if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
                    Location<World> loc1 = RedProtect.get().firstLocationSelections.get(player);
                    Location<World> loc2 = RedProtect.get().secondLocationSelections.get(player);
                    if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().cfgs.getInt("region-settings.define-max-distance") && !player.hasPermission("redprotect.bypass.define-max-distance")) {
                        Double dist = loc1.getPosition().distanceSquared(loc2.getPosition());
                        RPLang.sendMessage(player, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RedProtect.get().cfgs.getInt("region-settings.define-max-distance"), dist.intValue()));
                    } else {
                        RPUtil.addBorder(player, RPUtil.get4Points(loc1, loc2, player.getLocation().getBlockY()));
                    }
                }
                return cmdr;
            } else // rp pos2
            if (checkCmd(args[0], "pos2")) {
                Location<World> pl = player.getLocation();
                RedProtect.get().secondLocationSelections.put(player, pl);
                player.sendMessage(RPUtil.toText(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (&6" + pl.getBlockX() + RPLang.get("general.color") + ", &6" + pl.getBlockY() + RPLang.get("general.color") + ", &6" + pl.getBlockZ() + RPLang.get("general.color") + ")."));
                // show preview border
                if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
                    Location<World> loc1 = RedProtect.get().firstLocationSelections.get(player);
                    Location<World> loc2 = RedProtect.get().secondLocationSelections.get(player);
                    if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().cfgs.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(player, "redprotect.bypass.define-max-distance")) {
                        Double dist = loc1.getPosition().distanceSquared(loc2.getPosition());
                        RPLang.sendMessage(player, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RedProtect.get().cfgs.getInt("region-settings.define-max-distance"), dist.intValue()));
                    } else {
                        RPUtil.addBorder(player, RPUtil.get4Points(loc1, loc2, player.getLocation().getBlockY()));
                    }
                }
                return cmdr;
            }
        }
        if (args[0].isEmpty()) {
            sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------- " + RedProtect.get().container.getName() + " ----------------"));
            sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "Developed by &eFabioZumbi12" + RPLang.get("general.color") + "."));
            sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For more information about the commands, type [&e/rp ?" + RPLang.get("general.color") + "]."));
            sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For a tutorial, type [&e/rp tutorial" + RPLang.get("general.color") + "]."));
            sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------------------------------------------"));
            return cmdr;
        }
        if (checkCmd(args[0], "laccept")) {
            if (RedProtect.get().alWait.containsKey(player)) {
                // info = region+world+pname
                String info = RedProtect.get().alWait.get(player);
                Player lsender = Sponge.getServer().getPlayer(info.split("@")[2]).get();
                Region r = RedProtect.get().rm.getRegion(info.split("@")[0], info.split("@")[1]);
                String VictimUUID = player.getName();
                if (RedProtect.get().OnlineMode) {
                    VictimUUID = player.getUniqueId().toString();
                }
                if (r != null) {
                    if (RedProtect.get().ph.getPlayerClaimLimit(player) == (RedProtect.get().rm.getRegions(VictimUUID, r.getWorld()).size() + 1)) {
                        RPLang.sendMessage(player, "regionbuilder.claim.limit");
                        return cmdr;
                    }
                    r.addLeader(VictimUUID);
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.leader.youadded").replace("{region}", r.getName()) + " " + lsender.getName());
                    if (lsender != null && lsender.isOnline()) {
                        RPLang.sendMessage(lsender, RPLang.get("cmdmanager.region.leader.accepted").replace("{region}", r.getName()).replace("{player}", player.getName()));
                    }
                } else {
                    RPLang.sendMessage(player, "cmdmanager.region.doesexists");
                }
                RedProtect.get().alWait.remove(player);
                return cmdr;
            } else {
                RPLang.sendMessage(player, "cmdmanager.norequests");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "ldeny")) {
            if (RedProtect.get().alWait.containsKey(player)) {
                // info = region+world+pname
                String info = RedProtect.get().alWait.get(player);
                Player lsender = Sponge.getServer().getPlayer(info.split("@")[2]).get();
                Region r = RedProtect.get().rm.getRegion(info.split("@")[0], info.split("@")[1]);
                if (r != null) {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.leader.youdenied").replace("{region}", r.getName()).replace("{player}", lsender.getName()));
                    if (lsender != null && lsender.isOnline()) {
                        RPLang.sendMessage(lsender, RPLang.get("cmdmanager.region.leader.denied").replace("{region}", r.getName()).replace("{player}", player.getName()));
                    }
                } else {
                    RPLang.sendMessage(player, "cmdmanager.region.doesexists");
                }
                RedProtect.get().alWait.remove(player);
                return cmdr;
            } else {
                RPLang.sendMessage(player, "cmdmanager.norequests");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "settp") && RedProtect.get().ph.hasGenPerm(player, "settp")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r != null) {
                if (RedProtect.get().ph.hasRegionPermLeader(player, "settp", r)) {
                    r.setTPPoint(player.getLocation());
                    RPLang.sendMessage(player, "cmdmanager.region.settp.ok");
                    return cmdr;
                } else {
                    RPLang.sendMessage(player, "playerlistener.region.cantuse");
                    return cmdr;
                }
            } else {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "deltp") && RedProtect.get().ph.hasGenPerm(player, "settp")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r != null) {
                if (RedProtect.get().ph.hasRegionPermLeader(player, "settp", r)) {
                    r.setTPPoint(null);
                    RPLang.sendMessage(player, "cmdmanager.region.settp.removed");
                    return cmdr;
                } else {
                    RPLang.sendMessage(player, "playerlistener.region.cantuse");
                    return cmdr;
                }
            } else {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "border") && RedProtect.get().ph.hasGenPerm(player, "border")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r != null) {
                RPUtil.addBorder(player, r.get4Points(player.getLocation().getBlockY()));
                return cmdr;
            } else {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "cancelbuy") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.cancelbuy")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
            if (r.isLeader(RPUtil.PlayerToUUID(player.getName()))) {
                if (r.isForSale()) {
                    r.setFlag("for-sale", false);
                    r.setWelcome("");
                    if (r.leaderSize() == 0) {
                        if (RedProtect.get().cfgs.getEcoBool("rename-region")) {
                            RedProtect.get().rm.renameRegion(RPUtil.nameGen(player.getName(), r.getWorld()), r);
                        }
                        r.addLeader(RPUtil.PlayerToUUID(player.getName()));
                    } else {
                        if (RedProtect.get().cfgs.getEcoBool("rename-region")) {
                            RedProtect.get().rm.renameRegion(RPUtil.nameGen(RPUtil.UUIDtoPlayer(r.getLeaders().get(0)), r.getWorld()), r);
                        }
                    }
                    RPLang.sendMessage(player, "economy.region.cancelbuy");
                    RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " cancelled buy stat of region " + r.getName());
                    return cmdr;
                } else {
                    RPLang.sendMessage(player, "economy.region.buy.notforsale");
                    return cmdr;
                }
            } else {
                RPLang.sendMessage(player, "economy.region.sell.own");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "value") && RedProtect.get().ph.hasGenPerm(player, "value")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r != null) {
                if (RedProtect.get().ph.hasRegionPermLeader(player, "value", r)) {
                    if (r.getArea() < RedProtect.get().cfgs.getEcoInt("max-area-toget-value")) {
                        RPLang.sendMessage(player, RPLang.get("cmdmanager.value.is").replace("{value}", RPEconomy.getFormatted(RPEconomy.getRegionValue(r)) + " " + RedProtect.get().cfgs.getEcoString("economy-name")));
                        RedProtect.get().logger.debug("player", "Region Value: " + RPEconomy.getRegionValue(r));
                        return cmdr;
                    } else {
                        RPLang.sendMessage(player, RPLang.get("cmdmanager.value.areabig").replace("{maxarea}", RedProtect.get().cfgs.getEcoInt("max-area-toget-value").toString()));
                        return cmdr;
                    }
                } else {
                    RPLang.sendMessage(player, "playerlistener.region.cantuse");
                    return cmdr;
                }
            } else {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
        }
        if (args[0].equalsIgnoreCase("save-all")) {
            if (RedProtect.get().ph.hasGenPerm(player, "save-all")) {
                RedProtect.get().rm.saveAll();
                RedProtect.get().logger.SaveLogs();
                RPLang.sendMessage(player, "&a" + RedProtect.get().rm.getAllRegions().size() + " regions saved with success!");
                return cmdr;
            }
        }
        if (args[0].equalsIgnoreCase("load-all")) {
            if (RedProtect.get().ph.hasGenPerm(player, "load-all")) {
                RedProtect.get().rm.clearDB();
                try {
                    RedProtect.get().rm.loadAll();
                } catch (Exception e) {
                    RPLang.sendMessage(player, "Error on load all regions from database files:");
                    e.printStackTrace();
                }
                RPLang.sendMessage(player, "&a" + RedProtect.get().rm.getAllRegions().size() + " regions has been loaded from database files!");
                return cmdr;
            }
        }
        if (checkCmd(args[0], "define")) {
            if (!RedProtect.get().ph.hasGenPerm(player, "define")) {
                RPLang.sendMessage(player, "no.permission");
                return cmdr;
            }
            String serverName = RedProtect.get().cfgs.getString("region-settings.default-leader");
            String name = RPUtil.nameGen(serverName, player.getWorld().getName());
            RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new LinkedList<>(), true);
            if (rb2.ready()) {
                Region r2 = rb2.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " DEFINED region " + r2.getName());
            }
            return cmdr;
        }
        // rp claim
        if (checkCmd(args[0], "claim")) {
            if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasGenPerm(player, "claim")) {
                RPLang.sendMessage(player, "blocklistener.region.blockmode");
                return cmdr;
            }
            String name = RPUtil.nameGen(player.getName(), player.getWorld().getName());
            String leader = player.getUniqueId().toString();
            if (!RedProtect.get().OnlineMode) {
                leader = player.getName().toLowerCase();
            }
            RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, new LinkedList<>(), false);
            if (rb2.ready()) {
                Region r2 = rb2.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
            }
            return cmdr;
        }
        if (checkCmd(args[0], "reload") && RedProtect.get().ph.hasGenPerm(player, "reload")) {
            for (Player p : RedProtect.get().game.getServer().getOnlinePlayers()) {
                RedProtect.get().getPVHelper().closeInventory(p);
            }
            RedProtect.get().reload();
            RPLang.sendMessage(player, "cmdmanager.reloaded");
            return cmdr;
        }
        if (checkCmd(args[0], "wand") && player.hasPermission("redprotect.magicwand")) {
            Inventory inv = player.getInventory();
            ItemType mat = (ItemType) RPUtil.getRegistryFor(ItemType.class, RedProtect.get().cfgs.getString("wands.adminWandID"));
            ItemStack item = ItemStack.of(mat, 1);
            item.offer(Keys.ITEM_ENCHANTMENTS, new ArrayList<>());
            Iterable<Slot> slotIter = player.getInventory().slots();
            for (Slot slot : slotIter) {
                if (slot.peek().isPresent()) {
                    ItemStack stack = slot.peek().get();
                    if (stack.getItem().equals(mat)) {
                        RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
                        return cmdr;
                    }
                }
            }
            if (inv.query(Inventory.class).offer(item).getType().equals(Type.SUCCESS)) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.given").replace("{item}", mat.getName()));
            } else {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
            }
            return cmdr;
        }
        if (checkCmd(args[0], "help")) {
            HandleHelPage(sender, 1);
            return cmdr;
        }
        if (checkCmd(args[0], "tutorial")) {
            RPLang.sendMessage(player, "cmdmanager.tutorial");
            RPLang.sendMessage(player, "cmdmanager.tutorial1");
            RPLang.sendMessage(player, "cmdmanager.tutorial2");
            RPLang.sendMessage(player, "cmdmanager.tutorial3");
            RPLang.sendMessage(player, "cmdmanager.tutorial4");
            RPLang.sendMessage(player, "cmdmanager.tutorial5");
            return cmdr;
        }
        if (checkCmd(args[0], "near")) {
            if (RedProtect.get().ph.hasUserPerm(player, "redprotect.near")) {
                Set<Region> regions = RedProtect.get().rm.getRegionsNear(player, 60, player.getWorld());
                if (regions.size() == 0) {
                    RPLang.sendMessage(player, "cmdmanager.noregions.nearby");
                } else {
                    Iterator<Region> i = regions.iterator();
                    player.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.regionwith40")));
                    player.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
                    while (i.hasNext()) {
                        Region r = i.next();
                        player.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.name") + r.getName() + RPLang.get("general.color") + " | " + RPLang.get("region.center") + " (&6X,Z" + RPLang.get("general.color") + "): &6" + r.getCenterX() + ", " + r.getCenterZ()));
                    }
                    player.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
                }
            } else {
                RPLang.sendMessage(player, "no.permission");
            }
            return cmdr;
        }
        if (checkCmd(args[0], "flag")) {
            if (RedProtect.get().ph.hasUserPerm(player, "flaggui")) {
                Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
                if (r != null) {
                    if (r.isLeader(player) || r.isAdmin(player) || RedProtect.get().ph.hasAdminFlagPerm(player, "redprotect.admin.flaggui")) {
                        RPGui gui = new RPGui(r.getName(), player, r, RedProtect.get().cfgs.getGuiMaxSlot());
                        gui.open();
                        return cmdr;
                    } else {
                        sendNoPermissionMessage(player);
                        return cmdr;
                    }
                } else {
                    RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                    return cmdr;
                }
            }
        }
        // rp renew-rent
        if (checkCmd(args[0], "renew-rent") && RedProtect.get().ph.hasGenPerm(player, "redprotect.rent.renew-rent")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.doesexists");
                return cmdr;
            }
            String puuid = RPUtil.PlayerToUUID(player.getName());
            if (!r.isRentFor(puuid)) {
                RPLang.sendMessage(player, "cmdmanager.rent.younotrented");
                return cmdr;
            }
            if (RPUtil.getNowMillis() != r.getRentDateMillis(puuid) && !RedProtect.get().cfgs.getBool("region-settings.rent.renew-anytime")) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.cantrenewanytime").replace("{renew}", r.getRentDateFormated(puuid)));
                return cmdr;
            }
            UniqueAccount acc = RedProtect.get().econ.getOrCreateAccount(player.getUniqueId()).get();
            if (acc.getBalance(RedProtect.get().econ.getDefaultCurrency()).doubleValue() >= r.getRentValue(puuid)) {
                Calendar cal = Calendar.getInstance();
                String[] opts = RedProtect.get().cfgs.getString("region-settings.rent.command-renew-adds").split(":");
                if (opts[1].equalsIgnoreCase("MONTH")) {
                    cal.add(Calendar.MONTH, Integer.valueOf(opts[0]));
                } else if (opts[1].equalsIgnoreCase("DAY")) {
                    cal.add(Calendar.DAY_OF_MONTH, Integer.valueOf(opts[0]));
                }
                acc.withdraw(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(r.getRentValue(puuid)), RedProtect.get().getPVHelper().getCause(player));
                r.setRent(puuid, cal.getTimeInMillis());
                RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renewsuccess").replace("{region}", r.getName()).replace("{value}", RPEconomy.getFormatted(r.getRentValue(puuid))));
            } else {
                RPLang.sendMessage(player, "cmdmanager.rent.renewfail");
            }
            return cmdr;
        }
    }
    if (args.length == 2) {
        // rp removeall <player>
        if (checkCmd(args[0], "removeall") && sender.hasPermission("redprotect.removeall")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            int removed = RedProtect.get().rm.removeAll(args[1]);
            if (removed <= 0) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneremoved"));
            } else {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.removed").replace("{regions}", removed + "").replace("{player}", args[1]));
            }
            return cmdr;
        }
        // rp regenall <player>
        if (checkCmd(args[0], "regenall") && sender.hasPermission("redprotect.regenall")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            int regen = RedProtect.get().rm.regenAll(args[1]);
            if (regen <= 0) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneregenerated"));
            } else {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.regenerated").replace("{regions}", regen + "").replace("{player}", args[1]));
            }
            return cmdr;
        }
        // rp regen stop
        if (checkCmd(args[0], "regen") && args[1].equalsIgnoreCase("stop") && player.hasPermission("redprotect.regen")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            RPUtil.stopRegen = true;
            RPLang.sendMessage(player, "&aRegen will stop now. To continue reload the plugin!");
            return cmdr;
        }
        if (checkCmd(args[0], "help")) {
            try {
                int page = Integer.parseInt(args[1]);
                HandleHelPage(sender, page);
            } catch (NumberFormatException e) {
                RPLang.sendMessage(player, RPLang.get("correct.usage") + "&e/rp ? [page]");
            }
            return cmdr;
        }
        // rp define [nameOfRegion]
        if (checkCmd(args[0], "define")) {
            if (!RedProtect.get().ph.hasGenPerm(player, "define")) {
                RPLang.sendMessage(player, "no.permission");
                return cmdr;
            }
            String serverName = RedProtect.get().cfgs.getString("region-settings.default-leader");
            String name = args[1].replace("/", "|");
            RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new LinkedList<>(), true);
            if (rb2.ready()) {
                Region r2 = rb2.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " DEFINED region " + r2.getName());
            }
            return cmdr;
        }
        // rp claim [nameOfRegion]
        if (checkCmd(args[0], "claim")) {
            String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
            if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !player.hasPermission("redprotect.admin.claim")) {
                RPLang.sendMessage(player, "blocklistener.region.blockmode");
                return cmdr;
            }
            String name = args[1].replace("/", "|");
            String leader = player.getUniqueId().toString();
            if (!RedProtect.get().OnlineMode) {
                leader = player.getName().toLowerCase();
            }
            RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, new LinkedList<>(), false);
            if (rb2.ready()) {
                Region r2 = rb2.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
            }
            return cmdr;
        }
        if (checkCmd(args[0], "redefine")) {
            Region oldRect = RedProtect.get().rm.getRegion(args[1], player.getWorld());
            if (oldRect == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
                return cmdr;
            }
            if (!RedProtect.get().ph.hasRegionPermLeader(player, "redefine", oldRect)) {
                RPLang.sendMessage(player, "no.permission");
                return cmdr;
            }
            RedefineRegionBuilder rb = new RedefineRegionBuilder(player, oldRect, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player));
            if (rb.ready()) {
                Region r2 = rb.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.redefined") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " REDEFINED region " + r2.getName());
            }
            return cmdr;
        }
        // rp del-rent <player>
        if (checkCmd(args[0], "del-rent") && RedProtect.get().ph.hasUserPerm(player, "del-rent")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
            if (!r.isLeader(player) && !RedProtect.get().ph.hasGenPerm(player, "redprotect.rent.others")) {
                sendNoPermissionMessage(player);
                return cmdr;
            }
            if (r.isRentFor(RPUtil.PlayerToUUID(args[1]))) {
                r.removeRent(RPUtil.PlayerToUUID(args[1]));
                RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.playerremoved").replace("{region}", r.getName()));
            } else {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.noplayerrented"));
            }
            return cmdr;
        }
    }
    if (args.length == 3) {
        // rp regen <region> <world>
        if (checkCmd(args[0], "regen") && player.hasPermission("redprotect.regen")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            World w = RedProtect.get().serv.getWorld(args[2]).get();
            if (w == null) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.invalidworld"));
                return cmdr;
            }
            Region r = RedProtect.get().rm.getRegion(args[1], w);
            if (r == null) {
                RPLang.sendMessage(sender, RPLang.get("correct.usage") + " &eInvalid region: " + args[1]);
                return cmdr;
            }
            WEListener.regenRegion(r, Sponge.getServer().getWorld(r.getWorld()).get(), r.getMaxLocation(), r.getMinLocation(), 0, sender, false);
            return cmdr;
        }
        // rp undo <region> <world>
        if (args[0].equalsIgnoreCase("undo") && player.hasPermission("redprotect.regen")) {
            if (!RedProtect.get().WE) {
                return cmdr;
            }
            World w = RedProtect.get().serv.getWorld(args[2]).get();
            if (w == null) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.invalidworld"));
                return cmdr;
            }
            Region r = RedProtect.get().rm.getRegion(args[1], w);
            if (r == null) {
                RPLang.sendMessage(sender, RPLang.get("correct.usage") + " &eInvalid region: " + args[1]);
                return cmdr;
            }
            if (WEListener.undo(r.getID())) {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.sucess").replace("{region}", r.getName()));
            } else {
                RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.none").replace("{region}", r.getName()));
            }
            return cmdr;
        }
        // rp edit-rent <player> <valor/date>
        if (checkCmd(args[0], "edit-rent") && RedProtect.get().ph.hasUserPerm(player, "edit-rent")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
            if (!r.isLeader(player) && !RedProtect.get().ph.hasUserPerm(player, "rent.others")) {
                sendNoPermissionMessage(player);
                return cmdr;
            }
            if (!r.isRentFor(RPUtil.PlayerToUUID(args[1]))) {
                RPLang.sendMessage(player, "cmdmanager.rent.playernotrented");
                return cmdr;
            }
            try {
                int value = Integer.valueOf(args[2]);
                r.setRent(RPUtil.PlayerToUUID(args[1]), value);
                RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renteditok").replace("{player}", args[1]).replace("{value}", args[2]));
                return cmdr;
            } catch (NumberFormatException ex) {
                Calendar cal = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat(RedProtect.get().cfgs.getString("region-settings.date-format"));
                try {
                    cal.setTime(sdf.parse(args[2]));
                    r.setRent(RPUtil.PlayerToUUID(args[1]), cal.getTimeInMillis());
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renteditok").replace("{player}", args[1]).replace("{value}", args[2]));
                    return cmdr;
                } catch (ParseException ignored) {
                }
            }
        }
        // rp claim [regionName] [leader]
        if (checkCmd(args[0], "claim")) {
            String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
            if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !player.hasPermission("redprotect.admin.claim")) {
                RPLang.sendMessage(player, "blocklistener.region.blockmode");
                return cmdr;
            }
            String name = args[1].replace("/", "|");
            String leader = player.getUniqueId().toString();
            List<String> addedAdmins = new ArrayList<>();
            addedAdmins.add(RPUtil.PlayerToUUID(args[2]));
            if (!RedProtect.get().OnlineMode) {
                leader = player.getName().toLowerCase();
            }
            RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, addedAdmins, false);
            if (rb2.ready()) {
                Region r2 = rb2.build();
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
                RedProtect.get().rm.add(r2, player.getWorld());
                RedProtect.get().firstLocationSelections.remove(player);
                RedProtect.get().secondLocationSelections.remove(player);
                RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
            }
            return cmdr;
        }
        // - /rp copyflag from to
        if (checkCmd(args[0], "copyflag")) {
            if (!RedProtect.get().ph.hasGenPerm(player, "copyflag")) {
                RPLang.sendMessage(player, "no.permission");
                return cmdr;
            }
            World w = player.getWorld();
            Region from = RedProtect.get().rm.getRegion(args[1], w);
            Region to = RedProtect.get().rm.getRegion(args[2], w);
            if (from == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
                return cmdr;
            }
            if (to == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
                return cmdr;
            }
            for (String key : from.flags.keySet()) {
                to.setFlag(key, from.flags.get(key));
            }
            RPLang.sendMessage(player, RPLang.get("cmdmanager.region.flag.copied") + args[1] + " > " + args[2]);
            RedProtect.get().logger.addLog("Player " + player.getName() + " Copied FLAGS from " + args[1] + " to " + args[2]);
            return cmdr;
        }
    }
    if (args.length == 4 || args.length == 5) {
        // rp add-rent <player> <valor> <date>
        if (checkCmd(args[0], "add-rent") && player.hasPermission("redprotect.add-rent")) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
            if (!r.isLeader(player) && !player.hasPermission("redprotect.rent.others")) {
                sendNoPermissionMessage(player);
                return cmdr;
            }
            int value = 0;
            long renewal = 0;
            try {
                Calendar cal = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat(RedProtect.get().cfgs.getString("region-settings.date-format"));
                cal.setTime(sdf.parse(args[3]));
                renewal = cal.getTimeInMillis();
                value = Integer.valueOf(args[2]);
            } catch (Exception ex) {
                RPLang.sendMessage(player, RPLang.get("correct.command") + " &b/rp " + getCmd("help"));
                ex.printStackTrace();
                return cmdr;
            }
            String play = RPUtil.PlayerToUUID(args[1]);
            if (args.length == 4) {
                r.addrent(play, value, renewal, RedProtect.get().cfgs.getString("region-settings.rent.default-level"));
            } else if (args.length == 5) {
                if (args[4].equalsIgnoreCase("member") || args[4].equalsIgnoreCase("admin") || args[4].equalsIgnoreCase("leader")) {
                    r.addrent(play, value, renewal, args[4]);
                } else {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.validranks").replace("{ranks}", "member, admin, leader"));
                    return cmdr;
                }
            }
            RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.addedrent").replace("{player}", args[1]).replace("{date}", args[3]).replace("{cost}", args[2]));
            if (RedProtect.get().serv.getPlayer(args[1]).isPresent()) {
                RPLang.sendMessage(RedProtect.get().serv.getPlayer(args[1]).get(), RPLang.get("cmdmanager.rent.playeraddedrent").replace("{region}", r.getName()).replace("{date}", args[3]).replace("{cost}", args[2]));
            }
            return cmdr;
        }
    }
    // rp expand-vert [region] [world]
    if (checkCmd(args[0], "expand-vert")) {
        if (!RedProtect.get().ph.hasGenPerm(player, "expandvert")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        Region r = null;
        // rp expand-vert
        if (args.length == 1) {
            r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                return cmdr;
            }
        } else // rp expand-vert [region]
        if (args.length == 2) {
            r = RedProtect.get().rm.getRegion(args[1], player.getWorld());
            if (r == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
                return cmdr;
            }
        } else // rp expand-vert [region] [world]
        if (args.length == 3) {
            if (!Sponge.getServer().getWorld(args[2]).isPresent()) {
                RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
                return cmdr;
            }
            r = RedProtect.get().rm.getRegion(args[1], Sponge.getServer().getWorld(args[2]).get());
            if (r == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
                return cmdr;
            }
        } else {
            RPLang.sendMessage(player, RPLang.get("cmdmanager.help.expandvert").replace("{cmd}", getCmd("expandvert")).replace("{alias}", getCmdAlias("expandvert")));
            return cmdr;
        }
        r.setMaxY(256);
        r.setMinY(0);
        RPLang.sendMessage(player, RPLang.get("cmdmanager.region.expandvert.success").replace("{region}", r.getName()).replace("{miny}", String.valueOf(r.getMinY())).replace("{maxy}", String.valueOf(r.getMaxY())));
        return cmdr;
    }
    // rp setmaxy <size> [region] [world]
    if (checkCmd(args[0], "setmaxy")) {
        if (!RedProtect.get().ph.hasGenPerm(player, "setmaxy")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        Region r = null;
        // rp setmaxy <size>
        switch(args.length) {
            case 2:
                r = RedProtect.get().rm.getTopRegion(player.getLocation());
                if (r == null) {
                    RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                    return cmdr;
                }
                break;
            // rp setmaxy <size> [region]
            case 3:
                r = RedProtect.get().rm.getRegion(args[2], player.getWorld());
                if (r == null) {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
                    return cmdr;
                }
                break;
            // rp setmaxy <size> [region] [world]
            case 4:
                if (!Sponge.getServer().getWorld(args[3]).isPresent()) {
                    RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
                    return cmdr;
                }
                r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
                if (r == null) {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
                    return cmdr;
                }
                break;
            default:
                RPLang.sendMessage(player, RPLang.get("cmdmanager.help.setmaxy").replace("{cmd}", getCmd("setmaxy")).replace("{alias}", getCmdAlias("setmaxy")));
                return cmdr;
        }
        String from = String.valueOf(r.getMaxY());
        try {
            int size = Integer.parseInt(args[1]);
            if ((size - r.getMinY()) <= 1) {
                RPLang.sendMessage(player, "cmdmanager.region.ysiszesmatch");
                return cmdr;
            }
            r.setMaxY(size);
            RPLang.sendMessage(player, RPLang.get("cmdmanager.region.setmaxy.success").replace("{region}", r.getName()).replace("{fromsize}", from).replace("{size}", String.valueOf(size)));
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SETMAXY of region " + r.getName() + " to " + args[1]);
            return cmdr;
        } catch (NumberFormatException e) {
            RPLang.sendMessage(player, "cmdmanager.region.invalid.number");
            return cmdr;
        }
    }
    // rp setmaxy <size> [region] [world]
    if (checkCmd(args[0], "setminy")) {
        if (!RedProtect.get().ph.hasGenPerm(player, "setminy")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        Region r = null;
        // rp setmaxy <size>
        switch(args.length) {
            case 2:
                r = RedProtect.get().rm.getTopRegion(player.getLocation());
                if (r == null) {
                    RPLang.sendMessage(player, "cmdmanager.region.todo.that");
                    return cmdr;
                }
                break;
            // rp setmaxy <size> [region]
            case 3:
                r = RedProtect.get().rm.getRegion(args[2], player.getWorld());
                if (r == null) {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
                    return cmdr;
                }
                break;
            // rp setmaxy <size> [region] [world]
            case 4:
                if (!Sponge.getServer().getWorld(args[3]).isPresent()) {
                    RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
                    return cmdr;
                }
                r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
                if (r == null) {
                    RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
                    return cmdr;
                }
                break;
            default:
                RPLang.sendMessage(player, RPLang.get("cmdmanager.help.setminy").replace("{cmd}", getCmd("setminy")).replace("{alias}", getCmdAlias("setminy")));
                return cmdr;
        }
        String from = String.valueOf(r.getMinY());
        try {
            int size = Integer.parseInt(args[1]);
            if ((r.getMaxY() - size) <= 1) {
                RPLang.sendMessage(player, "cmdmanager.region.ysiszesmatch");
                return cmdr;
            }
            r.setMinY(size);
            RPLang.sendMessage(player, RPLang.get("cmdmanager.region.setminy.success").replace("{region}", r.getName()).replace("{fromsize}", from).replace("{size}", String.valueOf(size)));
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SETMINY of region " + r.getName() + " to " + args[1]);
            return cmdr;
        } catch (NumberFormatException e) {
            RPLang.sendMessage(player, "cmdmanager.region.invalid.number");
            return cmdr;
        }
    }
    if (checkCmd(args[0], "buy") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.buy")) {
        Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
        if (r == null) {
            RPLang.sendMessage(player, "cmdmanager.region.todo.that");
            return cmdr;
        }
        if (!r.isForSale()) {
            RPLang.sendMessage(player, "economy.region.buy.notforsale");
            return cmdr;
        }
        if (args.length == 1) {
            buyHandler(player, r.getValue(), r);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " BUY region " + r.getName() + " for " + r.getValue());
            return cmdr;
        }
    }
    if (checkCmd(args[0], "sell") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.sell")) {
        Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
        if (r == null) {
            RPLang.sendMessage(player, "cmdmanager.region.todo.that");
            return cmdr;
        }
        if (r.isForSale()) {
            RPLang.sendMessage(player, "economy.region.sell.already");
            return cmdr;
        }
        if (args.length == 1) {
            r.setValue(RPEconomy.getRegionValue(r));
            if (r.isLeader(player)) {
                sellHandler(r, player, RPUtil.PlayerToUUID(player.getName()), r.getValue());
            } else {
                sellHandler(r, player, r.getLeaders().get(0), r.getValue());
            }
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " for " + r.getValue());
            return cmdr;
        }
        if (args.length == 2) {
            // rp sell <value/player>
            try {
                long value = Long.valueOf(args[1]);
                if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.setvalue")) {
                    r.setValue(value);
                    if (r.isLeader(player)) {
                        sellHandler(r, player, RPUtil.PlayerToUUID(player.getName()), r.getValue());
                    } else {
                        sellHandler(r, player, r.getLeaders().get(0), r.getValue());
                    }
                    RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " for " + r.getValue());
                    return cmdr;
                }
            } catch (NumberFormatException e) {
                if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.others")) {
                    r.setValue(RPEconomy.getRegionValue(r));
                    sellHandler(r, player, RPUtil.PlayerToUUID(args[1]), r.getValue());
                    RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " in name of player " + args[1] + " for " + r.getValue());
                    return cmdr;
                }
            }
        }
        if (args.length == 3) {
            // rp sell player value
            try {
                long value = Long.valueOf(args[2]);
                if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.setvalue")) {
                    r.setValue(value);
                    sellHandler(r, player, RPUtil.PlayerToUUID(args[1]), value);
                    RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " in name of player " + args[1] + " for " + value);
                    return cmdr;
                }
            } catch (NumberFormatException e) {
                RPLang.sendMessage(player, "cmdmanager.eco.notdouble");
                return cmdr;
            }
        }
    }
    if (checkCmd(args[0], "teleport")) {
        if (args.length == 1) {
            RPLang.sendMessage(player, RPLang.get("cmdmanager.help.teleport").replace("{cmd}", getCmd("teleport")).replace("{alias}", getCmdAlias("teleport")));
            return cmdr;
        }
        if (args.length == 2) {
            handletp(player, args[1], player.getWorld().getName(), null);
            return cmdr;
        }
        if (args.length == 3) {
            handletp(player, args[1], args[2], null);
            return cmdr;
        }
        if (args.length == 4) {
            // /rp tp <player> <region> <world>
            Player play = null;
            if (Sponge.getServer().getPlayer(args[1]).isPresent()) {
                play = Sponge.getServer().getPlayer(args[1]).get();
            }
            if (play != null) {
                handletp(player, args[2], args[3], play);
                return cmdr;
            } else {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
                RPLang.sendMessage(player, RPLang.get("cmdmanager.help.teleport").replace("{cmd}", getCmd("teleport")).replace("{alias}", getCmdAlias("teleport")));
                return cmdr;
            }
        }
    }
    if (checkCmd(args[0], "limit")) {
        if (!RedProtect.get().ph.hasUserPerm(player, "limit")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        if (args.length == 1) {
            int limit = RedProtect.get().ph.getPlayerBlockLimit(player);
            if (limit < 0 || RedProtect.get().ph.hasPerm(player, "redprotect.limit.blocks.unlimited")) {
                RPLang.sendMessage(player, "cmdmanager.nolimit");
                return cmdr;
            }
            String uuid = player.getUniqueId().toString();
            if (!RedProtect.get().OnlineMode) {
                uuid = player.getName().toLowerCase();
            }
            int currentUsed = RedProtect.get().rm.getTotalRegionSize(uuid, player.getPlayer().isPresent() ? player.getPlayer().get().getWorld().getName() : null);
            RPLang.sendMessage(player, RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
            return cmdr;
        }
        if (!RedProtect.get().ph.hasPerm(player, "redprotect.other.limit")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        if (args.length == 2) {
            User offp = RPUtil.getUser(args[1]);
            if (offp == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
                return cmdr;
            }
            int limit = RedProtect.get().ph.getPlayerBlockLimit(offp);
            if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.blocks.unlimited")) {
                RPLang.sendMessage(player, "cmdmanager.nolimit");
                return cmdr;
            }
            int currentUsed = RedProtect.get().rm.getTotalRegionSize(RPUtil.PlayerToUUID(offp.getName()), offp.getPlayer().isPresent() ? offp.getPlayer().get().getWorld().getName() : null);
            RPLang.sendMessage(player, RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.limit").replace("{cmd}", getCmd("limit")).replace("{alias}", getCmdAlias("limit")));
        return cmdr;
    }
    if (checkCmd(args[0], "claimlimit")) {
        if (!RedProtect.get().ph.hasUserPerm(player, "claimlimit")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        if (args.length == 1) {
            int limit = RedProtect.get().ph.getPlayerClaimLimit(player);
            if (limit < 0 || RedProtect.get().ph.hasPerm(player, "redprotect.claimunlimited")) {
                RPLang.sendMessage(player, "cmdmanager.nolimit");
                return cmdr;
            }
            int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(player.getName()), player.getWorld()).size();
            RPLang.sendMessage(player, RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
            return cmdr;
        }
        if (!RedProtect.get().ph.hasPerm(player, "redprotect.other.claimlimit")) {
            RPLang.sendMessage(player, "no.permission");
            return cmdr;
        }
        if (args.length == 2) {
            User offp = RPUtil.getUser(args[1]);
            if (offp == null) {
                RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
                return cmdr;
            }
            int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
            if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
                RPLang.sendMessage(player, "cmdmanager.nolimit");
                return cmdr;
            }
            int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName()), player.getWorld()).size();
            RPLang.sendMessage(player, RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.claimlimit").replace("{cmd}", getCmd("claimlimit")).replace("{alias}", getCmdAlias("claimlimit")));
        return cmdr;
    }
    if (checkCmd(args[0], "welcome")) {
        if (args.length >= 2) {
            String wMessage = "";
            if (args[1].equals("off")) {
                handleWelcome(player, wMessage);
                return cmdr;
            } else {
                for (int i = 1; i < args.length; i++) {
                    wMessage = wMessage + args[i] + " ";
                }
                handleWelcome(player, wMessage);
                return cmdr;
            }
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.welcome").replace("{cmd}", getCmd("welcome")).replace("{alias}", getCmdAlias("welcome")));
        return cmdr;
    }
    if (checkCmd(args[0], "priority")) {
        int prior = 0;
        if (args.length == 2) {
            try {
                prior = Integer.parseInt(args[1]);
            } catch (NumberFormatException e) {
                RPLang.sendMessage(player, "cmdmanager.region.notnumber");
                return cmdr;
            }
            handlePriority(player, prior);
            return cmdr;
        }
        if (args.length == 3) {
            try {
                prior = Integer.parseInt(args[2]);
            } catch (NumberFormatException e) {
                RPLang.sendMessage(player, "cmdmanager.region.notnumber");
                return cmdr;
            }
            handlePrioritySingle(player, prior, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.priority").replace("{cmd}", getCmd("priority")).replace("{alias}", getCmdAlias("priority")));
        return cmdr;
    }
    if (checkCmd(args[0], "delete")) {
        // rp del [region] [world]
        if (args.length == 1) {
            handleDelete(player);
            return cmdr;
        }
        if (args.length == 2) {
            handleDeleteName(player, args[1], "");
            return cmdr;
        }
        if (args.length == 3) {
            handleDeleteName(player, args[1], args[2]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.delete").replace("{cmd}", getCmd("delete")).replace("{alias}", getCmdAlias("delete")));
        return cmdr;
    }
    if (checkCmd(args[0], "info")) {
        // rp info [region] [world]
        if (args.length == 1) {
            handleInfoTop(player);
            return cmdr;
        }
        if (args.length == 2) {
            handleInfo(player, args[1], "");
            return cmdr;
        }
        if (args.length == 3) {
            handleInfo(player, args[1], args[2]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.info").replace("{cmd}", getCmd("info")).replace("{alias}", getCmdAlias("info")));
        return cmdr;
    }
    if (checkCmd(args[0], "addmember")) {
        if (args.length == 2) {
            handleAddMember(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addmember").replace("{cmd}", getCmd("addmember")).replace("{alias}", getCmdAlias("addmember")));
        return cmdr;
    }
    if (checkCmd(args[0], "addadmin")) {
        if (args.length == 2) {
            handleAddAdmin(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addadmin").replace("{cmd}", getCmd("addadmin")).replace("{alias}", getCmdAlias("addadmin")));
        return cmdr;
    }
    if (checkCmd(args[0], "addleader")) {
        if (args.length == 2) {
            handleAddLeader(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addleader").replace("{cmd}", getCmd("addleader")).replace("{alias}", getCmdAlias("addleader")));
        return cmdr;
    }
    if (checkCmd(args[0], "removemember")) {
        if (args.length == 2) {
            handleRemoveMember(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removemember").replace("{cmd}", getCmd("removemember")).replace("{alias}", getCmdAlias("removemember")));
        return cmdr;
    }
    if (checkCmd(args[0], "removeadmin")) {
        if (args.length == 2) {
            handleRemoveAdmin(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removeadmin").replace("{cmd}", getCmd("removeadmin")).replace("{alias}", getCmdAlias("removeadmin")));
        return cmdr;
    }
    if (checkCmd(args[0], "removeleader")) {
        if (args.length == 2) {
            handleRemoveLeader(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removeleader").replace("{cmd}", getCmd("removeleader")).replace("{alias}", getCmdAlias("removeleader")));
        return cmdr;
    }
    if (checkCmd(args[0], "rename")) {
        if (args.length == 2) {
            handleRename(player, args[1]);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.rename").replace("{cmd}", getCmd("rename")).replace("{alias}", getCmdAlias("rename")));
        return cmdr;
    }
    if (checkCmd(args[0], "flag")) {
        Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
        if (r == null) {
            RPLang.sendMessage(player, "cmdmanager.region.todo.that");
            return cmdr;
        }
        if (args.length == 2) {
            if (RedProtect.get().cfgs.getBool("flags-configuration.change-flag-delay.enable")) {
                if (RedProtect.get().cfgs.getStringList("flags-configuration.change-flag-delay.flags").contains(args[1])) {
                    if (!RedProtect.get().changeWait.contains(r.getName() + args[1])) {
                        RPUtil.startFlagChanger(r.getName(), args[1], player);
                        handleFlag(player, args[1], "", r);
                        return cmdr;
                    } else {
                        RPLang.sendMessage(player, RPLang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().cfgs.getString("flags-configuration.change-flag-delay.seconds")));
                        return cmdr;
                    }
                }
            }
            handleFlag(player, args[1], "", r);
            return cmdr;
        }
        if (args.length >= 3) {
            String text = "";
            for (int i = 2; i < args.length; i++) {
                text = text + " " + args[i];
            }
            if (RedProtect.get().cfgs.getBool("flags-configuration.change-flag-delay.enable")) {
                if (RedProtect.get().cfgs.getStringList("flags-configuration.change-flag-delay.flags").contains(args[1])) {
                    if (!RedProtect.get().changeWait.contains(r.getName() + args[1])) {
                        RPUtil.startFlagChanger(r.getName(), args[1], player);
                        handleFlag(player, args[1], text.substring(1), r);
                        return cmdr;
                    } else {
                        RPLang.sendMessage(player, RPLang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().cfgs.getString("flags-configuration.change-flag-delay.seconds")));
                        return cmdr;
                    }
                }
            }
            handleFlag(player, args[1], text.substring(1), r);
            return cmdr;
        }
        RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.flag").replace("{cmd}", getCmd("flag")).replace("{alias}", getCmdAlias("flag")));
        return cmdr;
    }
    if (checkCmd(args[0], "list")) {
        // rp list
        if (args.length == 1) {
            handleList(player, RPUtil.PlayerToUUID(player.getName()), 1);
            return cmdr;
        }
        // rp list [player]
        if (args.length == 2) {
            handleList(player, RPUtil.PlayerToUUID(args[1]), 1);
            return cmdr;
        }
        // rp list [player] [page]
        if (args.length == 3) {
            try {
                int Page = Integer.parseInt(args[2]);
                handleList(player, RPUtil.PlayerToUUID(args[1]), Page);
                return cmdr;
            } catch (NumberFormatException e) {
                RPLang.sendMessage(player, "cmdmanager.region.listpage.error");
                return cmdr;
            }
        }
    }
    RPLang.sendMessage(player, RPLang.get("correct.command") + " &e/rp " + getCmd("help"));
    return cmdr;
}
Also used : User(org.spongepowered.api.entity.living.player.User) RedefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.RedefineRegionBuilder) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) ItemType(org.spongepowered.api.item.ItemType) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) RPConfig(br.net.fabiozumbi12.RedProtect.Sponge.config.RPConfig) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder) Player(org.spongepowered.api.entity.living.player.Player) Calendar(java.util.Calendar) ParseException(java.text.ParseException) CommandException(org.spongepowered.api.command.CommandException) CommandResult(org.spongepowered.api.command.CommandResult) BlockType(org.spongepowered.api.block.BlockType) Slot(org.spongepowered.api.item.inventory.Slot) ParseException(java.text.ParseException) DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder) RedefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.RedefineRegionBuilder) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SimpleDateFormat(java.text.SimpleDateFormat) Inventory(org.spongepowered.api.item.inventory.Inventory) Location(org.spongepowered.api.world.Location)

Example 44 with Location

use of org.spongepowered.api.world.Location in project RedProtect by FabioZumbi12.

the class Region method getLimitLocs.

public List<Location<World>> getLimitLocs(int miny, int maxy, boolean define) {
    final List<Location<World>> locBlocks = new ArrayList<>();
    Location<World> loc1 = this.getMinLocation();
    Location<World> loc2 = this.getMaxLocation();
    World w = Sponge.getServer().getWorld(this.getWorld()).get();
    for (int x = loc1.getBlockX(); x <= loc2.getBlockX(); ++x) {
        for (int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); ++z) {
            for (int y = miny; y <= maxy; ++y) {
                if ((z == loc1.getBlockZ() || z == loc2.getBlockZ() || x == loc1.getBlockX() || x == loc2.getBlockX()) && (define || new Location<>(w, x, y, z).getBlock().getType().getName().contains(RedProtect.get().cfgs.getString("region-settings.block-id")))) {
                    locBlocks.add(new Location<>(w, x, y, z));
                }
            }
        }
    }
    return locBlocks;
}
Also used : ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 45 with Location

use of org.spongepowered.api.world.Location in project TotalEconomy by Erigitic.

the class ShopManager method onItemPurchase.

/**
 * Handles a user purchasing an item from a shop.
 *
 * @param event Primary (Left mouse) click inventory
 * @param player The player clicking within an inventory
 * @param inventory The inventory being interacted with
 */
@Listener
@Exclude(ClickInventoryEvent.Shift.class)
public void onItemPurchase(ClickInventoryEvent.Primary event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
    Optional<PlayerShopInfo> playerShopInfoOpt = player.get(ShopKeys.PLAYER_SHOP_INFO);
    if (playerShopInfoOpt.isPresent()) {
        Location location = playerShopInfoOpt.get().getOpenShopLocation();
        Optional<TileEntity> tileEntityOpt = location.getTileEntity();
        if (tileEntityOpt.isPresent()) {
            Optional<Shop> shopOpt = tileEntityOpt.get().get(ShopKeys.SINGLE_SHOP);
            if (shopOpt.isPresent()) {
                Shop shop = shopOpt.get();
                ItemStack clickedItem = ItemStack.builder().fromSnapshot(event.getCursorTransaction().getDefault().copy()).build();
                Optional<ShopItem> shopItemOpt = clickedItem.get(ShopKeys.SHOP_ITEM);
                if (shopItemOpt.isPresent()) {
                    event.getCursorTransaction().setValid(false);
                    ShopItem shopItem = shopItemOpt.get();
                    TEAccount ownerAccount = (TEAccount) accountManager.getOrCreateAccount(shop.getOwner()).get();
                    TEAccount customerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                    if (customerAccount.getBalance(totalEconomy.getDefaultCurrency()).doubleValue() >= shopItem.getPrice()) {
                        ItemStack purchasedItem = removeShopItemData(clickedItem.copy());
                        Collection<ItemStackSnapshot> rejectedItems = player.getInventory().query(GridInventory.class, Hotbar.class).offer(purchasedItem).getRejectedItems();
                        if (rejectedItems.size() == 0) {
                            customerAccount.transfer(ownerAccount, totalEconomy.getDefaultCurrency(), BigDecimal.valueOf(shopItem.getPrice()), event.getCause());
                            Slot clickedSlot = event.getTransactions().get(0).getSlot();
                            updateItemInSlot(clickedSlot, clickedItem, clickedItem.getQuantity() - 1);
                        } else {
                            event.getTransactions().get(0).setValid(false);
                            player.sendMessage(messageManager.getMessage("shops.purchase.noroom"));
                        }
                    } else {
                        event.getTransactions().get(0).setValid(false);
                        player.sendMessage(messageManager.getMessage("shops.purchase.insufficientfunds"));
                    }
                } else {
                    event.getCursorTransaction().setValid(false);
                    invalidateTransactions(event.getTransactions());
                }
            }
        }
    }
}
Also used : TEAccount(com.erigitic.config.TEAccount) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener) Exclude(org.spongepowered.api.event.filter.type.Exclude)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14