Search in sources :

Example 6 with CuboidSelection

use of com.sk89q.worldedit.bukkit.selections.CuboidSelection in project AreaShop by NLthijs48.

the class SignsFeature method onSignChange.

@EventHandler(priority = EventPriority.MONITOR)
public void onSignChange(SignChangeEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Player player = event.getPlayer();
    if (!plugin.isReady()) {
        plugin.message(player, "general-notReady");
        return;
    }
    // Check if the sign is meant for this plugin
    if (event.getLine(0).contains(plugin.getConfig().getString("signTags.rent"))) {
        if (!player.hasPermission("areashop.createrent") && !player.hasPermission("areashop.createrent.member") && !player.hasPermission("areashop.createrent.owner")) {
            plugin.message(player, "setup-noPermissionRent");
            return;
        }
        // Get the other lines
        String secondLine = event.getLine(1);
        String thirdLine = event.getLine(2);
        String fourthLine = event.getLine(3);
        // Get the regionManager for accessing regions
        RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
        // If the secondLine does not contain a name try to find the region by location
        if (secondLine == null || secondLine.length() == 0) {
            Set<ProtectedRegion> regions = plugin.getWorldGuardHandler().getApplicableRegionsSet(event.getBlock().getLocation());
            if (regions != null) {
                boolean first = true;
                ProtectedRegion candidate = null;
                for (ProtectedRegion pr : regions) {
                    if (first) {
                        candidate = pr;
                        first = false;
                    } else {
                        if (pr.getPriority() > candidate.getPriority()) {
                            candidate = pr;
                        } else if (pr.getPriority() < candidate.getPriority()) {
                        // Already got the correct one
                        } else if (pr.getParent() != null && pr.getParent().equals(candidate)) {
                            candidate = pr;
                        } else if (candidate.getParent() != null && candidate.getParent().equals(pr)) {
                        // Already got the correct one
                        } else {
                            plugin.message(player, "setup-couldNotDetect", candidate.getId(), pr.getId());
                            return;
                        }
                    }
                }
                if (candidate != null) {
                    secondLine = candidate.getId();
                }
            }
        }
        boolean priceSet = fourthLine != null && fourthLine.length() != 0;
        boolean durationSet = thirdLine != null && thirdLine.length() != 0;
        // check if all the lines are correct
        if (secondLine == null || secondLine.length() == 0) {
            plugin.message(player, "setup-noRegion");
            return;
        }
        ProtectedRegion region = regionManager.getRegion(secondLine);
        if (region == null) {
            plugin.message(player, "cmd-noRegion", secondLine);
            return;
        }
        FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), GeneralRegion.RegionType.RENT);
        if (addResult == FileManager.AddResult.BLACKLISTED) {
            plugin.message(player, "setup-blacklisted", secondLine);
        } else if (addResult == FileManager.AddResult.ALREADYADDED) {
            plugin.message(player, "setup-alreadyRentSign");
        } else if (addResult == FileManager.AddResult.NOPERMISSION) {
            plugin.message(player, "setup-noPermission", secondLine);
        } else if (thirdLine != null && thirdLine.length() != 0 && !Utils.checkTimeFormat(thirdLine)) {
            plugin.message(player, "setup-wrongDuration");
        } else {
            double price = 0.0;
            if (priceSet) {
                // Check the fourth line
                try {
                    price = Double.parseDouble(fourthLine);
                } catch (NumberFormatException e) {
                    plugin.message(player, "setup-wrongPrice");
                    return;
                }
            }
            // Add rent to the FileManager
            final RentRegion rent = new RentRegion(secondLine, event.getPlayer().getWorld());
            boolean isMember = plugin.getWorldGuardHandler().containsMember(rent.getRegion(), player.getUniqueId());
            boolean isOwner = plugin.getWorldGuardHandler().containsOwner(rent.getRegion(), player.getUniqueId());
            boolean landlord = (!player.hasPermission("areashop.createrent") && ((player.hasPermission("areashop.createrent.owner") && isOwner) || (player.hasPermission("areashop.createrent.member") && isMember)));
            if (landlord) {
                rent.setLandlord(player.getUniqueId(), player.getName());
            }
            if (priceSet) {
                rent.setPrice(price);
            }
            if (durationSet) {
                rent.setDuration(thirdLine);
            }
            org.bukkit.material.Sign sign = (org.bukkit.material.Sign) event.getBlock().getState().getData();
            rent.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
            // Run commands
            rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
            plugin.getFileManager().addRent(rent);
            rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
            plugin.message(player, "setup-rentSuccess", rent);
            // Update the region after the event has written its lines
            Do.sync(rent::update);
            // Run commands
            rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
        }
    } else if (event.getLine(0).contains(plugin.getConfig().getString("signTags.buy"))) {
        // Check for permission
        if (!player.hasPermission("areashop.createbuy") && !player.hasPermission("areashop.createbuy.member") && !player.hasPermission("areashop.createbuy.owner")) {
            plugin.message(player, "setup-noPermissionBuy");
            return;
        }
        // Get the other lines
        String secondLine = event.getLine(1);
        String thirdLine = event.getLine(2);
        // Get the regionManager for accessing regions
        RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
        // If the secondLine does not contain a name try to find the region by location
        if (secondLine == null || secondLine.length() == 0) {
            Set<ProtectedRegion> regions = plugin.getWorldGuardHandler().getApplicableRegionsSet(event.getBlock().getLocation());
            if (regions != null) {
                boolean first = true;
                ProtectedRegion candidate = null;
                for (ProtectedRegion pr : regions) {
                    if (first) {
                        candidate = pr;
                        first = false;
                    } else {
                        if (pr.getPriority() > candidate.getPriority()) {
                            candidate = pr;
                        } else if (pr.getPriority() < candidate.getPriority()) {
                        // Already got the correct one
                        } else if (pr.getParent() != null && pr.getParent().equals(candidate)) {
                            candidate = pr;
                        } else if (candidate.getParent() != null && candidate.getParent().equals(pr)) {
                        // Already got the correct one
                        } else {
                            plugin.message(player, "setup-couldNotDetect", candidate.getId(), pr.getId());
                            return;
                        }
                    }
                }
                if (candidate != null) {
                    secondLine = candidate.getId();
                }
            }
        }
        boolean priceSet = thirdLine != null && thirdLine.length() != 0;
        // Check if all the lines are correct
        if (secondLine == null || secondLine.length() == 0) {
            plugin.message(player, "setup-noRegion");
            return;
        }
        ProtectedRegion region = regionManager.getRegion(secondLine);
        if (region == null) {
            plugin.message(player, "cmd-noRegion", secondLine);
            return;
        }
        FileManager.AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, GeneralRegion.RegionType.BUY);
        if (addResult == FileManager.AddResult.BLACKLISTED) {
            plugin.message(player, "setup-blacklisted", secondLine);
        } else if (addResult == FileManager.AddResult.ALREADYADDED) {
            plugin.message(player, "setup-alreadyRentSign");
        } else if (addResult == FileManager.AddResult.NOPERMISSION) {
            plugin.message(player, "setup-noPermission", secondLine);
        } else {
            double price = 0.0;
            if (priceSet) {
                // Check the fourth line
                try {
                    price = Double.parseDouble(thirdLine);
                } catch (NumberFormatException e) {
                    plugin.message(player, "setup-wrongPrice");
                    return;
                }
            }
            // Add buy to the FileManager
            final BuyRegion buy = new BuyRegion(secondLine, event.getPlayer().getWorld());
            boolean isMember = plugin.getWorldGuardHandler().containsMember(buy.getRegion(), player.getUniqueId());
            boolean isOwner = plugin.getWorldGuardHandler().containsOwner(buy.getRegion(), player.getUniqueId());
            boolean landlord = (!player.hasPermission("areashop.createbuy") && ((player.hasPermission("areashop.createbuy.owner") && isOwner) || (player.hasPermission("areashop.createbuy.member") && isMember)));
            if (landlord) {
                buy.setLandlord(player.getUniqueId(), player.getName());
            }
            if (priceSet) {
                buy.setPrice(price);
            }
            org.bukkit.material.Sign sign = (org.bukkit.material.Sign) event.getBlock().getState().getData();
            buy.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
            // Run commands
            buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
            plugin.getFileManager().addBuy(buy);
            buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
            plugin.message(player, "setup-buySuccess", buy);
            // Update the region after the event has written its lines
            Do.sync(buy::update);
            // Run commands
            buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
        }
    } else if (event.getLine(0).contains(plugin.getConfig().getString("signTags.add"))) {
        // Check for permission
        if (!player.hasPermission("areashop.addsign")) {
            plugin.message(player, "addsign-noPermission");
            return;
        }
        // Get the other lines
        String secondLine = event.getLine(1);
        String thirdLine = event.getLine(2);
        GeneralRegion region;
        if (secondLine != null && secondLine.length() != 0) {
            // Get region by secondLine of the sign
            region = plugin.getFileManager().getRegion(secondLine);
            if (region == null) {
                plugin.message(player, "addSign-notRegistered", secondLine);
                return;
            }
        } else {
            // Get region by sign position
            List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(event.getBlock().getWorld(), event.getBlock().getLocation(), event.getBlock().getLocation()));
            if (regions.isEmpty()) {
                plugin.message(player, "addsign-noRegions");
                return;
            } else if (regions.size() > 1) {
                plugin.message(player, "addsign-couldNotDetectSign", regions.get(0).getName(), regions.get(1).getName());
                return;
            }
            region = regions.get(0);
        }
        org.bukkit.material.Sign sign = (org.bukkit.material.Sign) event.getBlock().getState().getData();
        if (thirdLine == null || thirdLine.length() == 0) {
            region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), null);
            plugin.message(player, "addsign-success", region);
        } else {
            region.getSignsFeature().addSign(event.getBlock().getLocation(), event.getBlock().getType(), sign.getFacing(), thirdLine);
            plugin.message(player, "addsign-successProfile", thirdLine, region);
        }
        // Update the region later because this event will do it first
        Do.sync(region::update);
    }
}
Also used : Player(org.bukkit.entity.Player) Set(java.util.Set) RentRegion(me.wiefferink.areashop.regions.RentRegion) FileManager(me.wiefferink.areashop.managers.FileManager) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) BuyRegion(me.wiefferink.areashop.regions.BuyRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) EventHandler(org.bukkit.event.EventHandler)

Example 7 with CuboidSelection

use of com.sk89q.worldedit.bukkit.selections.CuboidSelection in project Village_Defense by Plajer.

the class MainCommand method performSetup.

void performSetup(Player player, String[] args) {
    if (args[1].equalsIgnoreCase("setup") || args[1].equals("edit")) {
        if (ArenaRegistry.getArena(args[0]) == null) {
            player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
            return;
        }
        new SetupInventory(ArenaRegistry.getArena(args[0])).openInventory(player);
        return;
    }
    if (!(args.length > 2))
        return;
    FileConfiguration config = ConfigurationManager.getConfig("arenas");
    if (!config.contains("instances." + args[0])) {
        player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
        player.sendMessage(ChatColor.RED + "Usage: /vd < ARENA ID > set <MINPLAYRS | MAXPLAYERS | MAPNAME | SCHEMATIC | LOBBYLOCATION | EndLOCATION | STARTLOCATION  >  < VALUE>");
        return;
    }
    if (args[1].equalsIgnoreCase("addspawn")) {
        if (args[2].equalsIgnoreCase("zombie")) {
            int i;
            if (!config.contains("instances." + args[0] + ".zombiespawns")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + args[0] + ".zombiespawns").getKeys(false).size();
            }
            i++;
            Util.saveLoc("instances." + args[0] + ".zombiespawns." + i, player.getLocation(), false);
            player.sendMessage(ChatColor.GREEN + "Zombie spawn added!");
            return;
        }
        if (args[2].equalsIgnoreCase("villager")) {
            int i;
            if (!config.contains("instances." + args[0] + ".villagerspawns")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + args[0] + ".villagerspawns").getKeys(false).size();
            }
            i++;
            Util.saveLoc("instances." + args[0] + ".villagerspawns." + i, player.getLocation(), false);
            player.sendMessage(ChatColor.GREEN + "Villager spawn added!");
            return;
        }
        if (args[2].equalsIgnoreCase("doors")) {
            String ID = args[0];
            int counter = 0;
            int i;
            if (plugin.getWorldEditPlugin().getSelection(player) == null)
                return;
            if (!config.contains("instances." + ID + ".doors")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + ID + ".doors").getKeys(false).size();
            }
            i++;
            Selection selection = plugin.getWorldEditPlugin().getSelection(player);
            if (selection instanceof CuboidSelection) {
                CuboidSelection cuboidSelection = (CuboidSelection) selection;
                Vector min = cuboidSelection.getNativeMinimumPoint();
                Vector max = cuboidSelection.getNativeMaximumPoint();
                for (int x = min.getBlockX(); x <= max.getBlockX(); x = x + 1) {
                    for (int y = min.getBlockY(); y <= max.getBlockY(); y = y + 1) {
                        for (int z = min.getBlockZ(); z <= max.getBlockZ(); z = z + 1) {
                            Location temporaryBlock = new Location(player.getWorld(), x, y, z);
                            if (temporaryBlock.getBlock().getType() == Material.WOODEN_DOOR) {
                                String location = temporaryBlock.getWorld().getName() + "," + temporaryBlock.getX() + "," + temporaryBlock.getY() + "," + temporaryBlock.getZ() + "," + temporaryBlock.getYaw() + "," + temporaryBlock.getPitch();
                                config.set("instances." + ID + ".doors." + i + ".location", location);
                                config.set("instances." + ID + ".doors." + i + ".byte", temporaryBlock.getBlock().getData());
                                counter++;
                                i++;
                            }
                        }
                    }
                }
            } else {
                if (selection.getMaximumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
                    String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
                    config.set("instances." + ID + ".doors." + i + ".location", location);
                    config.set("instances." + ID + ".doors." + i + ".byte", selection.getMaximumPoint().getBlock().getData());
                    counter++;
                    i++;
                }
                if (selection.getMinimumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
                    String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
                    config.set("instances." + ID + ".doors." + i + ".location", location);
                    config.set("instances." + ID + ".doors." + i + ".byte", selection.getMinimumPoint().getBlock().getData());
                    counter++;
                    i++;
                }
            }
            player.sendMessage(ChatColor.GREEN + "" + (int) Math.ceil(counter / 2) + " doors were added!");
        }
        ConfigurationManager.saveConfig(config, "arenas");
        return;
    }
    if (!(args[1].equalsIgnoreCase("set")))
        return;
    if (args.length == 3) {
        if (args[2].equalsIgnoreCase("lobbylocation") || args[2].equalsIgnoreCase("lobbyloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".lobbylocation", location);
            player.sendMessage("VillageDefense: Lobby location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else if (args[2].equalsIgnoreCase("Startlocation") || args[2].equalsIgnoreCase("Startloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".Startlocation", location);
            player.sendMessage("VillageDefense: Start location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else if (args[2].equalsIgnoreCase("Endlocation") || args[2].equalsIgnoreCase("Endloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".Endlocation", location);
            player.sendMessage("VillageDefense: End location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else {
            player.sendMessage(ChatColor.RED + "Invalid Command!");
            player.sendMessage(ChatColor.RED + "Usage: /vd <ARENA > set <StartLOCTION | LOBBYLOCATION | EndLOCATION>");
        }
    } else if (args.length == 4) {
        if (args[2].equalsIgnoreCase("MAXPLAYERS") || args[2].equalsIgnoreCase("maximumplayers")) {
            config.set("instances." + args[0] + ".maximumplayers", Integer.parseInt(args[3]));
            player.sendMessage("VillageDefense: Maximum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
        } else if (args[2].equalsIgnoreCase("MINPLAYERS") || args[2].equalsIgnoreCase("minimumplayers")) {
            config.set("instances." + args[0] + ".minimumplayers", Integer.parseInt(args[3]));
            player.sendMessage("VillageDefense: Minimum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
        } else if (args[2].equalsIgnoreCase("MAPNAME") || args[2].equalsIgnoreCase("NAME")) {
            config.set("instances." + args[0] + ".mapname", args[3]);
            player.sendMessage("VillageDefense: Map name for arena/instance " + args[0] + " set to " + args[3]);
        } else if (args[2].equalsIgnoreCase("WORLD") || args[2].equalsIgnoreCase("MAP")) {
            boolean exists = false;
            for (World world : Bukkit.getWorlds()) {
                if (world.getName().equalsIgnoreCase(args[3]))
                    exists = true;
            }
            if (!exists) {
                player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatColor.RED + "That world doesn't exists!");
                return;
            }
            config.set("instances." + args[0] + ".world", args[3]);
            player.sendMessage("VillageDefense: World for arena/instance " + args[0] + " set to " + args[3]);
        } else {
            player.sendMessage(ChatColor.RED + "Invalid Command!");
            player.sendMessage(ChatColor.RED + "Usage: /vd set <MINPLAYERS | MAXPLAYERS> <value>");
        }
    }
    ConfigurationManager.saveConfig(config, "arenas");
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) Selection(com.sk89q.worldedit.bukkit.selections.Selection) World(org.bukkit.World) SetupInventory(pl.plajer.villagedefense3.utils.SetupInventory) Vector(com.sk89q.worldedit.Vector) Location(org.bukkit.Location)

Aggregations

CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)7 EditSession (com.sk89q.worldedit.EditSession)4 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)4 Region (com.sk89q.worldedit.regions.Region)4 EditSessionBuilder (com.boydti.fawe.util.EditSessionBuilder)2 GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)2 Player (org.bukkit.entity.Player)2 Vector (com.sk89q.worldedit.Vector)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 Set (java.util.Set)1 RegionSign (me.wiefferink.areashop.features.signs.RegionSign)1 FileManager (me.wiefferink.areashop.managers.FileManager)1 BuyRegion (me.wiefferink.areashop.regions.BuyRegion)1 RentRegion (me.wiefferink.areashop.regions.RentRegion)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Block (org.bukkit.block.Block)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1