Search in sources :

Example 1 with RegionSign

use of me.wiefferink.areashop.features.signs.RegionSign 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 2 with RegionSign

use of me.wiefferink.areashop.features.signs.RegionSign in project AreaShop by NLthijs48.

the class DelsignCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.delsign")) {
        plugin.message(sender, "delsign-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, "delsign-noSign");
        return;
    }
    RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
    if (regionSign == null) {
        plugin.message(sender, "delsign-noRegion");
        return;
    }
    plugin.message(sender, "delsign-success", regionSign.getRegion());
    regionSign.remove();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) RegionSign(me.wiefferink.areashop.features.signs.RegionSign)

Example 3 with RegionSign

use of me.wiefferink.areashop.features.signs.RegionSign in project AreaShop by NLthijs48.

the class ImportJob method importRegionSettings.

/**
 * Import region specific settings from a RegionForSale source to an AreaShop target ConfigurationSection.
 * @param from RegionForSale config section that specifies region settings
 * @param to AreaShop config section that specifies region settings
 * @param region GeneralRegion to copy settings to, or null if doing generic settings
 */
private void importRegionSettings(ConfigurationSection from, ConfigurationSection to, GeneralRegion region) {
    // Maximum rental time, TODO check if this is actually the same
    if (from.isLong("permissions.max-rent-time")) {
        to.set("rent.maxRentTime", minutesToString(from.getLong("permissions.max-rent-time")));
    }
    // Region rebuild
    if (from.getBoolean("region-rebuilding.auto-rebuild")) {
        to.set("general.enableRestore", true);
    }
    // Get price settings
    String unit = from.getString("economic-settings.unit-type");
    String rentPrice = from.getString("economic-settings.cost-per-unit.rent");
    String buyPrice = from.getString("economic-settings.cost-per-unit.buy");
    String sellPrice = from.getString("economic-settings.cost-per-unit.selling-price");
    // TODO: There is no easy way to import this, setup eventCommandsProfile?
    String taxes = from.getString("economic-settings.cost-per-unit.taxes");
    // Determine unit and add that to the price
    String unitSuffix = "";
    if ("region".equalsIgnoreCase(unit)) {
    // add nothing
    } else if ("m3".equalsIgnoreCase(unit)) {
        unitSuffix = "*%volume%";
    } else {
        // m2 or nothing (in case not set, we should actually look in parent files to correctly set this...)
        // This is better than width*depth because of polygon regions
        unitSuffix = "*(%volume%/%height%)";
    }
    // Apply settings
    if (rentPrice != null) {
        to.set("rent.price", rentPrice + unitSuffix);
    }
    if (buyPrice != null) {
        to.set("buy.price", buyPrice + unitSuffix);
        if (sellPrice != null) {
            try {
                double buyPriceAmount = Double.parseDouble(buyPrice);
                double sellPriceAmount = Double.parseDouble(sellPrice);
                to.set("buy.moneyBack", sellPriceAmount / buyPriceAmount * 100);
            } catch (NumberFormatException e) {
                // There is not always a region here for the message, should probably indicate something though
                message("import-moneyBackFailed", buyPrice, sellPrice);
            }
        }
    }
    // Set rented until
    if (from.isLong("info.last-withdrawal") && region != null && region instanceof RentRegion) {
        RentRegion rentRegion = (RentRegion) region;
        long lastWithdrawal = from.getLong("info.last-withdrawal");
        // Because the rental duration is already imported into the region and its parents this should be correct
        rentRegion.setRentedUntil(lastWithdrawal + rentRegion.getDuration());
    }
    // Import signs (list of strings like "297, 71, -22")
    if (from.isList("info.signs") && region != null) {
        for (String signLocation : from.getStringList("info.signs")) {
            String[] locationParts = signLocation.split(", ");
            if (locationParts.length != 3) {
                message("import-invalidSignLocation", region.getName(), signLocation);
                continue;
            }
            // Parse the location
            Location location;
            try {
                location = new Location(region.getWorld(), Double.parseDouble(locationParts[0]), Double.parseDouble(locationParts[1]), Double.parseDouble(locationParts[2]));
            } catch (NumberFormatException e) {
                message("import-invalidSignLocation", region.getName(), signLocation);
                continue;
            }
            // Check if this location is already added to a region
            RegionSign regionSign = SignsFeature.getSignByLocation(location);
            if (regionSign != null) {
                if (!regionSign.getRegion().equals(region)) {
                    message("import-signAlreadyAdded", region.getName(), signLocation, regionSign.getRegion().getName());
                }
                continue;
            }
            // SignType and Facing will be written when the sign is updated later
            region.getSignsFeature().addSign(location, null, null, null);
        }
    }
}
Also used : RentRegion(me.wiefferink.areashop.regions.RentRegion) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) Location(org.bukkit.Location)

Example 4 with RegionSign

use of me.wiefferink.areashop.features.signs.RegionSign in project AreaShop by NLthijs48.

the class SignLinkerManager method onPlayerInteract.

/**
 * On player interactions.
 * @param event The PlayerInteractEvent
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (isInSignLinkMode(event.getPlayer())) {
        event.setCancelled(true);
        Player player = event.getPlayer();
        SignLinker linker = signLinkers.get(event.getPlayer().getUniqueId());
        if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            // Get the region
            BlockIterator blockIterator = new BlockIterator(player, 100);
            while (blockIterator.hasNext()) {
                Block next = blockIterator.next();
                List<GeneralRegion> regions = Utils.getRegions(next.getLocation());
                if (regions.size() == 1) {
                    linker.setRegion(regions.get(0));
                    return;
                } else if (regions.size() > 1) {
                    Set<String> names = new HashSet<>();
                    for (GeneralRegion region : regions) {
                        names.add(region.getName());
                    }
                    plugin.message(player, "linksigns-multipleRegions", Utils.createCommaSeparatedList(names));
                    plugin.message(player, "linksigns-multipleRegionsAdvice");
                    return;
                }
            }
            // No regions found within the maximum range
            plugin.message(player, "linksigns-noRegions");
        } else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
            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(player, "linksigns-noSign");
                return;
            }
            RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
            if (regionSign != null) {
                plugin.message(player, "linksigns-alreadyRegistered", regionSign.getRegion());
                return;
            }
            Sign sign = (Sign) block.getState().getData();
            linker.setSign(block.getLocation(), block.getType(), sign.getFacing());
        }
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) HashSet(java.util.HashSet) Set(java.util.Set) 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) EventHandler(org.bukkit.event.EventHandler)

Example 5 with RegionSign

use of me.wiefferink.areashop.features.signs.RegionSign in project AreaShop by NLthijs48.

the class TeleportFeature method getStartLocation.

/**
 * Get the start location of a safe teleport search.
 * @param player The player to get it for
 * @param toSign true to try teleporting to the first sign, false for teleporting to the region
 * @return The start location
 */
private Location getStartLocation(Player player, Value<Boolean> toSign) {
    Location startLocation = null;
    ProtectedRegion worldguardRegion = getRegion().getRegion();
    // Try to get sign location
    List<RegionSign> signs = getRegion().getSignsFeature().getSigns();
    boolean signAvailable = !signs.isEmpty();
    if (toSign.get()) {
        if (signAvailable) {
            // Use the location 1 below the sign to prevent weird spawing above the sign
            // .subtract(0.0, 1.0, 0.0);
            startLocation = signs.get(0).getLocation();
            startLocation.setPitch(player.getLocation().getPitch());
            startLocation.setYaw(player.getLocation().getYaw());
            // Move player x blocks away from the sign
            double distance = getRegion().getDoubleSetting("general.teleportSignDistance");
            if (distance > 0) {
                BlockFace facing = getRegion().getSignsFeature().getSigns().get(0).getFacing();
                Vector facingVector = new Vector(facing.getModX(), facing.getModY(), facing.getModZ()).normalize().multiply(distance);
                startLocation.setX(startLocation.getBlockX() + 0.5);
                startLocation.setZ(startLocation.getBlockZ() + 0.5);
                startLocation.add(facingVector);
            }
        } else {
            // No sign available
            getRegion().message(player, "teleport-changedToNoSign");
            toSign.set(false);
        }
    }
    // Use teleportation location that is set for the region
    if (startLocation == null && hasTeleportLocation()) {
        startLocation = getTeleportLocation();
    }
    // Calculate a default location
    if (startLocation == null) {
        // Set to block in the middle, y configured in the config
        com.sk89q.worldedit.Vector middle = com.sk89q.worldedit.Vector.getMidpoint(worldguardRegion.getMaximumPoint(), worldguardRegion.getMinimumPoint());
        String configSetting = getRegion().getStringSetting("general.teleportLocationY");
        if ("bottom".equalsIgnoreCase(configSetting)) {
            middle = middle.setY(worldguardRegion.getMinimumPoint().getBlockY());
        } else if ("top".equalsIgnoreCase(configSetting)) {
            middle = middle.setY(worldguardRegion.getMaximumPoint().getBlockY());
        } else if ("middle".equalsIgnoreCase(configSetting)) {
            middle = middle.setY(middle.getBlockY());
        } else {
            try {
                int vertical = Integer.parseInt(configSetting);
                middle = middle.setY(vertical);
            } catch (NumberFormatException e) {
                AreaShop.warn("Could not parse general.teleportLocationY: '" + configSetting + "'");
            }
        }
        startLocation = new Location(getRegion().getWorld(), middle.getX(), middle.getY(), middle.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
    }
    // Set location in the center of the block
    startLocation.setX(startLocation.getBlockX() + 0.5);
    startLocation.setZ(startLocation.getBlockZ() + 0.5);
    return startLocation;
}
Also used : BlockFace(org.bukkit.block.BlockFace) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

RegionSign (me.wiefferink.areashop.features.signs.RegionSign)5 Block (org.bukkit.block.Block)3 Player (org.bukkit.entity.Player)3 BlockIterator (org.bukkit.util.BlockIterator)3 GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)2 Location (org.bukkit.Location)2 Sign (org.bukkit.material.Sign)2 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 RentRegion (me.wiefferink.areashop.regions.RentRegion)1 BlockFace (org.bukkit.block.BlockFace)1 EventHandler (org.bukkit.event.EventHandler)1 Vector (org.bukkit.util.Vector)1