Search in sources :

Example 6 with GeneralRegion

use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.

the class SetrestoreCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.setrestore")) {
        plugin.message(sender, "setrestore-noPermission");
        return;
    }
    if (args.length <= 2 || args[1] == null || args[2] == null) {
        plugin.message(sender, "setrestore-help");
        return;
    }
    GeneralRegion region = plugin.getFileManager().getRegion(args[1]);
    if (region == null) {
        plugin.message(sender, "setrestore-notRegistered", args[1]);
        return;
    }
    Boolean value = null;
    if (args[2].equalsIgnoreCase("true")) {
        value = true;
    } else if (args[2].equalsIgnoreCase("false")) {
        value = false;
    }
    region.setRestoreSetting(value);
    String valueString = "general";
    if (value != null) {
        valueString = value + "";
    }
    if (args.length > 3) {
        region.setSchematicProfile(args[3]);
        plugin.message(sender, "setrestore-successProfile", valueString, args[3], region);
    } else {
        plugin.message(sender, "setrestore-success", valueString, region);
    }
    region.update();
}
Also used : GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion)

Example 7 with GeneralRegion

use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.

the class AddsignCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.addsign")) {
        plugin.message(sender, "addsign-noPermission");
        return;
    }
    if (!(sender instanceof Player)) {
        plugin.message(sender, "cmd-onlyByPlayer");
        return;
    }
    Player player = (Player) sender;
    // Get the sign
    Block block = null;
    BlockIterator blockIterator = new BlockIterator(player, 100);
    while (blockIterator.hasNext() && block == null) {
        Block next = blockIterator.next();
        if (next.getType() != Material.AIR) {
            block = next;
        }
    }
    if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
        plugin.message(sender, "addsign-noSign");
        return;
    }
    GeneralRegion region;
    if (args.length > 1) {
        // Get region by argument
        region = plugin.getFileManager().getRegion(args[1]);
        if (region == null) {
            plugin.message(sender, "cmd-notRegistered", args[1]);
            return;
        }
    } else {
        // Get region by sign position
        List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
        if (regions.isEmpty()) {
            plugin.message(sender, "addsign-noRegions");
            return;
        } else if (regions.size() > 1) {
            plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
            return;
        }
        region = regions.get(0);
    }
    Sign sign = (Sign) block.getState().getData();
    String profile = null;
    if (args.length > 2) {
        profile = args[2];
        Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
        if (!profiles.contains(profile)) {
            plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
            return;
        }
    }
    RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
    if (regionSign != null) {
        plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
        return;
    }
    region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile);
    if (profile == null) {
        plugin.message(sender, "addsign-success", region);
    } else {
        plugin.message(sender, "addsign-successProfile", profile, region);
    }
    region.update();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) Block(org.bukkit.block.Block) Sign(org.bukkit.material.Sign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign)

Example 8 with GeneralRegion

use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.

the class InfoCommand method showSortedPagedList.

/**
 * Display a page of a list of regions.
 * @param sender      The CommandSender to send the messages to
 * @param regions     The regions to display
 * @param filterGroup The group to filter the regions by
 * @param keyHeader   The header to print above the page
 * @param pageInput   The page number, if any
 * @param baseCommand The command to execute for next/previous page (/areashop will be added)
 */
private void showSortedPagedList(@Nonnull CommandSender sender, @Nonnull List<? extends GeneralRegion> regions, @Nullable RegionGroup filterGroup, @Nonnull String keyHeader, @Nullable String pageInput, @Nonnull String baseCommand) {
    int maximumItems = 20;
    int itemsPerPage = maximumItems - 2;
    int page = 1;
    if (pageInput != null && Utils.isNumeric(pageInput)) {
        try {
            page = Integer.parseInt(pageInput);
        } catch (NumberFormatException e) {
            plugin.message(sender, "info-wrongPage", pageInput);
            return;
        }
    }
    if (filterGroup != null) {
        regions.removeIf(generalRegion -> !filterGroup.isMember(generalRegion));
    }
    if (regions.isEmpty()) {
        plugin.message(sender, "info-noRegions");
    } else {
        // First sort by type, then by name
        regions.sort((one, two) -> {
            int typeCompare = getTypeOrder(two).compareTo(getTypeOrder(one));
            if (typeCompare != 0) {
                return typeCompare;
            } else {
                return one.getName().compareTo(two.getName());
            }
        });
        // Header
        Message limitedToGroup = Message.empty();
        if (filterGroup != null) {
            limitedToGroup = Message.fromKey("info-limitedToGroup").replacements(filterGroup.getName());
        }
        plugin.message(sender, keyHeader, limitedToGroup);
        // Page entries
        // Clip page to correct boundaries, not much need to tell the user
        int totalPages = (int) Math.ceil(regions.size() / (double) itemsPerPage);
        if (regions.size() == itemsPerPage + 1) {
            // 19 total items is mapped to 1 page of 19
            itemsPerPage++;
            totalPages = 1;
        }
        page = Math.max(1, Math.min(totalPages, page));
        // header
        int linesPrinted = 1;
        for (int i = (page - 1) * itemsPerPage; i < page * itemsPerPage && i < regions.size(); i++) {
            String state;
            GeneralRegion region = regions.get(i);
            if (region.getType() == GeneralRegion.RegionType.RENT) {
                if (region.getOwner() == null) {
                    state = "Forrent";
                } else {
                    state = "Rented";
                }
            } else {
                if (region.getOwner() == null) {
                    state = "Forsale";
                } else if (!((BuyRegion) region).isInResellingMode()) {
                    state = "Sold";
                } else {
                    state = "Reselling";
                }
            }
            plugin.messageNoPrefix(sender, "info-entry" + state, region);
            linesPrinted++;
        }
        Message footer = Message.empty();
        // Previous button
        if (page > 1) {
            footer.append(Message.fromKey("info-pagePrevious").replacements(baseCommand + " " + (page - 1)));
        } else {
            footer.append(Message.fromKey("info-pageNoPrevious"));
        }
        // Page status
        if (totalPages > 1) {
            String pageString = "" + page;
            for (int i = pageString.length(); i < (totalPages + "").length(); i++) {
                pageString = "0" + pageString;
            }
            footer.append(Message.fromKey("info-pageStatus").replacements(page, totalPages));
            if (page < totalPages) {
                footer.append(Message.fromKey("info-pageNext").replacements(baseCommand + " " + (page + 1)));
            } else {
                footer.append(Message.fromKey("info-pageNoNext"));
            }
            // Fill up space if the page is not full (aligns header nicely)
            for (int i = linesPrinted; i < maximumItems - 1; i++) {
                sender.sendMessage(" ");
            }
            footer.send(sender);
        }
    }
}
Also used : Message(me.wiefferink.interactivemessenger.processing.Message) BuyRegion(me.wiefferink.areashop.regions.BuyRegion) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion)

Example 9 with GeneralRegion

use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.

the class AddfriendCommand method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
        plugin.message(sender, "addfriend-noPermission");
        return;
    }
    if (args.length < 2) {
        plugin.message(sender, "addfriend-help");
        return;
    }
    GeneralRegion region;
    if (args.length <= 2) {
        if (sender instanceof Player) {
            // get the region by location
            List<GeneralRegion> regions = Utils.getImportantRegions(((Player) sender).getLocation());
            if (regions.isEmpty()) {
                plugin.message(sender, "cmd-noRegionsAtLocation");
                return;
            } else if (regions.size() > 1) {
                plugin.message(sender, "cmd-moreRegionsAtLocation");
                return;
            } else {
                region = regions.get(0);
            }
        } else {
            plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
            return;
        }
    } else {
        region = plugin.getFileManager().getRegion(args[2]);
        if (region == null) {
            plugin.message(sender, "cmd-notRegistered", args[2]);
            return;
        }
    }
    if (sender.hasPermission("areashop.addfriendall")) {
        if ((region instanceof RentRegion && !((RentRegion) region).isRented()) || (region instanceof BuyRegion && !((BuyRegion) region).isSold())) {
            plugin.message(sender, "addfriend-noOwner", region);
            return;
        }
        OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
        if (friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
            plugin.message(sender, "addfriend-notVisited", args[1], region);
            return;
        }
        if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
            plugin.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
            return;
        }
        if (region.isOwner(friend.getUniqueId())) {
            plugin.message(sender, "addfriend-self", friend.getName(), region);
            return;
        }
        if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
            region.update();
            plugin.message(sender, "addfriend-successOther", friend.getName(), region);
        }
    } else {
        if (sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
            if (region.isOwner((Player) sender)) {
                OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
                if (friend.getLastPlayed() == 0 && !friend.isOnline() && !plugin.getConfig().getBoolean("addFriendNotExistingPlayers")) {
                    plugin.message(sender, "addfriend-notVisited", args[1], region);
                    return;
                }
                if (region.getFriendsFeature().getFriends().contains(friend.getUniqueId())) {
                    plugin.message(sender, "addfriend-alreadyAdded", friend.getName(), region);
                    return;
                }
                if (region.isOwner(friend.getUniqueId())) {
                    plugin.message(sender, "addfriend-self", friend.getName(), region);
                    return;
                }
                if (region.getFriendsFeature().addFriend(friend.getUniqueId(), sender)) {
                    region.update();
                    plugin.message(sender, "addfriend-success", friend.getName(), region);
                }
            } else {
                plugin.message(sender, "addfriend-noPermissionOther", region);
            }
        } else {
            plugin.message(sender, "addfriend-noPermission", region);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) BuyRegion(me.wiefferink.areashop.regions.BuyRegion) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) OfflinePlayer(org.bukkit.OfflinePlayer) RentRegion(me.wiefferink.areashop.regions.RentRegion)

Example 10 with GeneralRegion

use of me.wiefferink.areashop.regions.GeneralRegion in project AreaShop by NLthijs48.

the class SetpriceCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
        plugin.message(sender, "setprice-noPermission");
        return;
    }
    if (args.length < 2 || args[1] == null) {
        plugin.message(sender, "setprice-help");
        return;
    }
    GeneralRegion region;
    if (args.length < 3) {
        if (sender instanceof Player) {
            // get the region by location
            List<GeneralRegion> regions = Utils.getImportantRegions(((Player) sender).getLocation());
            if (regions.isEmpty()) {
                plugin.message(sender, "cmd-noRegionsAtLocation");
                return;
            } else if (regions.size() > 1) {
                plugin.message(sender, "cmd-moreRegionsAtLocation");
                return;
            } else {
                region = regions.get(0);
            }
        } else {
            plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
            return;
        }
    } else {
        region = plugin.getFileManager().getRegion(args[2]);
    }
    if (region == null) {
        plugin.message(sender, "setprice-notRegistered", args[2]);
        return;
    }
    if (!sender.hasPermission("areashop.setprice") && !(sender instanceof Player && region.isLandlord(((Player) sender).getUniqueId()))) {
        plugin.message(sender, "setprice-noLandlord", region);
        return;
    }
    if ("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1])) {
        if (region instanceof RentRegion) {
            ((RentRegion) region).setPrice(null);
        } else if (region instanceof BuyRegion) {
            ((BuyRegion) region).setPrice(null);
        }
        region.update();
        plugin.message(sender, "setprice-successRemoved", region);
        return;
    }
    double price;
    try {
        price = Double.parseDouble(args[1]);
    } catch (NumberFormatException e) {
        plugin.message(sender, "setprice-wrongPrice", args[1], region);
        return;
    }
    if (region instanceof RentRegion) {
        ((RentRegion) region).setPrice(price);
        plugin.message(sender, "setprice-successRent", region);
    } else if (region instanceof BuyRegion) {
        ((BuyRegion) region).setPrice(price);
        plugin.message(sender, "setprice-successBuy", region);
    }
    region.update();
}
Also used : Player(org.bukkit.entity.Player) BuyRegion(me.wiefferink.areashop.regions.BuyRegion) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) RentRegion(me.wiefferink.areashop.regions.RentRegion)

Aggregations

GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)25 Player (org.bukkit.entity.Player)18 BuyRegion (me.wiefferink.areashop.regions.BuyRegion)15 RentRegion (me.wiefferink.areashop.regions.RentRegion)14 ArrayList (java.util.ArrayList)8 OfflinePlayer (org.bukkit.OfflinePlayer)7 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)5 Selection (com.sk89q.worldedit.bukkit.selections.Selection)4 TreeSet (java.util.TreeSet)4 RegionGroup (me.wiefferink.areashop.regions.RegionGroup)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 UUID (java.util.UUID)3 EventHandler (org.bukkit.event.EventHandler)3 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)2 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)2 File (java.io.File)2 RegionSign (me.wiefferink.areashop.features.signs.RegionSign)2 FileManager (me.wiefferink.areashop.managers.FileManager)2 Message (me.wiefferink.interactivemessenger.processing.Message)2