diff --git a/AreaShop/config.yml b/AreaShop/config.yml index 94f1f98..78a1ba6 100644 --- a/AreaShop/config.yml +++ b/AreaShop/config.yml @@ -20,6 +20,8 @@ language: EN enableSchematics: true ## Maximum number of blocks to save to or restore from a .schemetic maximumBlocks: 1000000 +## Maximum number of locations the teleport function should check to find a safe spot +maximumTries: 50000 ## Enable sending stats to http://mcstats.org/ (Metrics plugin) sendStats: true ## Use colors when sending messages to console and log files @@ -28,9 +30,6 @@ useColorsInConsole: false postCommandErrors: true ## Version of the config, do not change! version: 2.0.0 -## The y location within the region to start searching for safe teleport spots (x and z will be in the middle of the region) -## Possible values: bottom, middle, top -teleportLocationY: bottom ## The different tags you can write on the sign to trigger the plugin signTags: ## Tag for adding a rent region diff --git a/AreaShop/default.yml b/AreaShop/default.yml index 52cb54b..2b8e902 100644 --- a/AreaShop/default.yml +++ b/AreaShop/default.yml @@ -13,29 +13,13 @@ general: signProfile: 'default' ## The profile for the WorldGuard flags as specified in the config flagProfile: 'default' - runCommands: - created: - before: - after: - - "say An AreaShop region has been created: %region%" - deleted: - before: - after: - rented: - before: - after: - extended: - before: - after: - unrented: - before: - after: - bought: - before: - after: - sold: - before: - after: + ## The y location within the region to start searching for safe teleport spots (x and z will be in the middle of the region) + ## Possible values: bottom, middle, top + teleportLocationY: bottom + ## If true the teleportation algorithm only allows telportation to inside the region, otherwise it will expand algorithm + ## a cube from the starting point to check for safe spots (then it could end outside the region) + ## If you set a teleport location outside of the region with /as settp then setting this to true breaks that teleport (players cannot use it) + teleportIntoRegion: true ########## RENTING ########## rent: diff --git a/AreaShop/lang/EN.yml b/AreaShop/lang/EN.yml index d4c0676..06080b8 100644 --- a/AreaShop/lang/EN.yml +++ b/AreaShop/lang/EN.yml @@ -153,7 +153,7 @@ setprice-successRent: "Price of region %0% changed to %1% per %2%" setprice-successBuy: "Price of region %0% changed to %1%" rentduration-noPermission: "You don't have permission to change the duration of a rent" -rentduration-help: "/as rentduration " +rentduration-help: "/as rentduration [region], the region you stand in will be used if not specified" rentduration-notRegistered: "%0% is not registered as a rent" rentduration-wrongAmount: "'%0%' is not a valid amount, use a whole number" rentduration-wrongFormat: "'%0%' is not a proper timeformat, check the documentation on Bukkit" @@ -183,7 +183,7 @@ teleport-noRentOrBuy: "Region '%0%' is not registered as rent or buy" teleport-noPermission: "You don't have permission to teleport to a region" teleport-noPermissionOther: "You don't have permission to teleport to region you do not own" teleport-success: "You teleported to %0%" -teleport-noSafe: "No safe position found in region %0%, change the region or set position yourself" +teleport-noSafe: "No safe position found in region %0%, no spots in region left or maximum tries exceeded (%1%/%2%)" setteleport-help: "/as settp [region] [reset], the region you stand in will be used if not specified" setteleport-noPermission: "You don't have permission to set the teleport location" @@ -231,6 +231,7 @@ schemevent-help: "/as schemevent [region] [world]" add-noPermission: "You don't have permission to add a region to AreaShop" diff --git a/AreaShop/plugin.yml b/AreaShop/plugin.yml index a654dad..e8f7b05 100644 --- a/AreaShop/plugin.yml +++ b/AreaShop/plugin.yml @@ -1,6 +1,6 @@ name: AreaShop main: nl.evolutioncoding.AreaShop.AreaShop -version: 2.0.0 +version: 2.0.1 depend: [Vault, WorldGuard, WorldEdit] softdepend: [Multiverse-Core] commands: diff --git a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/BuyCommand.java b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/BuyCommand.java index 5ca192e..1e0ce6e 100644 --- a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/BuyCommand.java +++ b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/BuyCommand.java @@ -50,7 +50,7 @@ public class BuyCommand extends CommandAreaShop { if(regions.size() != 1) { plugin.message(sender, "buy-help"); } else { - if(!regions.get(0).isRentRegion()) { + if(!regions.get(0).isBuyRegion()) { plugin.message(sender, "buy-notBuyable"); } else { ((BuyRegion)regions.get(0)).buy(player); diff --git a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentCommand.java b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentCommand.java index 8b5b07b..235963c 100644 --- a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentCommand.java +++ b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentCommand.java @@ -55,6 +55,7 @@ public class RentCommand extends CommandAreaShop { } else { ((RentRegion)regions.get(0)).rent(player); } + plugin.saveConfig(); } } } diff --git a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentdurationCommand.java b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentdurationCommand.java index 68dc497..cad1233 100644 --- a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentdurationCommand.java +++ b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/RentdurationCommand.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.List; import nl.evolutioncoding.AreaShop.AreaShop; +import nl.evolutioncoding.AreaShop.regions.GeneralRegion; import nl.evolutioncoding.AreaShop.regions.RentRegion; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class RentdurationCommand extends CommandAreaShop { @@ -34,26 +36,45 @@ public class RentdurationCommand extends CommandAreaShop { plugin.message(sender, "rentduration-noPermission"); return; } - if(args.length < 4 || args[1] == null || args[2] == null || args[3] == null) { + if(args.length < 3 || args[1] == null || args[2] == null) { plugin.message(sender, "rentduration-help"); return; } - RentRegion rent = plugin.getFileManager().getRent(args[1]); + RentRegion rent = null; + if(args.length <= 3) { + if(sender instanceof Player) { + // get the region by location + List regions = plugin.getFileManager().getApplicalbeASRegions(((Player)sender).getLocation()); + if(regions.size() != 1) { + plugin.message(sender, "rentduration-help"); + return; + } else { + if(regions.get(0).isRentRegion()) { + rent = (RentRegion)regions.get(0); + } + } + } else { + plugin.message(sender, "rentduration-help"); + return; + } + } else { + rent = plugin.getFileManager().getRent(args[3]); + } if(rent == null) { - plugin.message(sender, "rentduration-notRegistered", args[1]); + plugin.message(sender, "rentduration-notRegistered", args[3]); return; } try { - Integer.parseInt(args[2]); + Integer.parseInt(args[1]); } catch(NumberFormatException e) { - plugin.message(sender, "rentduration-wrongAmount", args[2]); + plugin.message(sender, "rentduration-wrongAmount", args[1]); return; } - if(!plugin.checkTimeFormat(args[2] + " " + args[3])) { - plugin.message(sender, "rentduration-wrongFormat", args[2]+" "+args[3]); + if(!plugin.checkTimeFormat(args[1] + " " + args[2])) { + plugin.message(sender, "rentduration-wrongFormat", args[1]+" "+args[2]); return; } - rent.setDuration(args[2]+" "+args[3]); + rent.setDuration(args[1]+" "+args[2]); rent.updateRegionFlags(); rent.updateSigns(); rent.save(); diff --git a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/SchematiceventCommand.java b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/SchematiceventCommand.java index 13229af..b4f11bd 100644 --- a/AreaShop/src/nl/evolutioncoding/AreaShop/commands/SchematiceventCommand.java +++ b/AreaShop/src/nl/evolutioncoding/AreaShop/commands/SchematiceventCommand.java @@ -33,6 +33,11 @@ public class SchematiceventCommand extends CommandAreaShop { @Override public void execute(CommandSender sender, Command command, String[] args) { + if(!sender.hasPermission("areashop.schematicevents")) { + plugin.message(sender, "schemevent-noPermission"); + return; + } + if(args.length < 3 || args[1] == null || args[2] == null) { plugin.message(sender, "schemevent-help"); return; diff --git a/AreaShop/src/nl/evolutioncoding/AreaShop/regions/GeneralRegion.java b/AreaShop/src/nl/evolutioncoding/AreaShop/regions/GeneralRegion.java index b62cb76..a2bcddd 100644 --- a/AreaShop/src/nl/evolutioncoding/AreaShop/regions/GeneralRegion.java +++ b/AreaShop/src/nl/evolutioncoding/AreaShop/regions/GeneralRegion.java @@ -856,7 +856,8 @@ public abstract class GeneralRegion { if(region != null) { // Set to block in the middle, y configured in the config Vector middle = Vector.getMidpoint(region.getMaximumPoint(), region.getMinimumPoint()); - String configSetting = plugin.config().getString("teleportLocationY"); + String configSetting = getStringSetting("general.teleportLocationY"); + AreaShop.debug("teleportLocationY = " + configSetting); if("bottom".equalsIgnoreCase(configSetting)) { middle = middle.setY(region.getMinimumPoint().getBlockY()); } else if("top".equalsIgnoreCase(configSetting)) { @@ -869,6 +870,10 @@ public abstract class GeneralRegion { return false; } } + boolean insideRegion = getBooleanSetting("general.teleportIntoRegion"); + AreaShop.debug("insideRegion = " + insideRegion); + int maxTries = plugin.config().getInt("maximumTries"); + AreaShop.debug("maxTries = " + maxTries); // set location in the center of the block startLocation.setX(startLocation.getBlockX() + 0.5); @@ -878,18 +883,26 @@ public abstract class GeneralRegion { // radius around that (until no block in the region is found at all cube sides) Location saveLocation = startLocation; int radius = 1; - boolean done = isSave(saveLocation); + boolean blocksInRegion = region.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ()); + boolean done = isSave(saveLocation) && ((blocksInRegion && insideRegion) || (!insideRegion)); boolean north=false, east=false, south=false, west=false, top=false, bottom=false; boolean track; - while(!done) { + while(((blocksInRegion && insideRegion) || (!insideRegion)) && !done) { + blocksInRegion = false; // North side track = false; for(int x=-radius+1; x<=radius && !done && !north; x++) { for(int y=-radius+1; y256 || saveLocation.getBlockY()<0) { + continue; + } + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } north = north || !track; @@ -899,9 +912,15 @@ public abstract class GeneralRegion { for(int z=-radius+1; z<=radius && !done && !east; z++) { for(int y=-radius+1; y256 || saveLocation.getBlockY()<0) { + continue; + } + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } east = east || !track; @@ -911,9 +930,15 @@ public abstract class GeneralRegion { for(int x=radius-1; x>=-radius && !done && !south; x--) { for(int y=-radius+1; y256 || saveLocation.getBlockY()<0) { + continue; + } + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } south = south || !track; @@ -923,50 +948,74 @@ public abstract class GeneralRegion { for(int z=radius-1; z>=-radius && !done && !west; z--) { for(int y=-radius+1; y256 || saveLocation.getBlockY()<0) { + continue; + } + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } - west = west || !track; + west = west || !west; // Top side track = false; // Middle block of the top + if((startLocation.getBlockY() + radius) > 256) { + top = true; + } if(!done && !top) { saveLocation = startLocation.clone().add(0, radius, 0); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } for(int r=1; r<=radius && !done && !top; r++) { // North for(int x=-r+1; x<=r && !done; x++) { saveLocation = startLocation.clone().add(x, radius, -r); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // East for(int z=-r+1; z<=r && !done; z++) { saveLocation = startLocation.clone().add(r, radius, z); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // South side for(int x=r-1; x>=-r && !done; x--) { saveLocation = startLocation.clone().add(x, radius, r); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // West side for(int z=r-1; z>=-r && !done; z--) { saveLocation = startLocation.clone().add(-r, radius, z); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } top = top || !track; @@ -974,40 +1023,58 @@ public abstract class GeneralRegion { // Bottom side track = false; // Middle block of the bottom + if(startLocation.getBlockY() - radius < 0) { + bottom = true; + } if(!done && !bottom) { saveLocation = startLocation.clone().add(0, -radius, 0); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } for(int r=1; r<=radius && !done && !bottom; r++) { // North for(int x=-r+1; x<=r && !done; x++) { saveLocation = startLocation.clone().add(x, -radius, -r); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // East for(int z=-r+1; z<=r && !done; z++) { saveLocation = startLocation.clone().add(r, -radius, z); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // South side for(int x=r-1; x>=-r && !done; x--) { saveLocation = startLocation.clone().add(x, -radius, r); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } // West side for(int z=r-1; z>=-r && !done; z--) { saveLocation = startLocation.clone().add(-r, -radius, z); - done = isSave(saveLocation); - track = true; - checked++; + if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) { + checked++; + done = isSave(saveLocation) || checked > maxTries; + blocksInRegion = true; + track = true; + } } } bottom = bottom || !track; @@ -1015,14 +1082,14 @@ public abstract class GeneralRegion { // Increase cube radius radius++; } - if(done) { + if(done && isSave(saveLocation)) { plugin.message(player, "teleport-success", getName()); player.teleport(saveLocation); - AreaShop.debug("Found location: " + saveLocation.toString() + " Tries: " + checked); + AreaShop.debug("Found location: " + saveLocation.toString() + " Tries: " + (checked-1)); return true; } else { - plugin.message(player, "teleport-noSafe", getName()); - AreaShop.debug("No location found, checked " + checked + " spots"); + plugin.message(player, "teleport-noSafe", getName(), checked-1, maxTries); + AreaShop.debug("No location found, checked " + (checked-1) + " spots of max " + maxTries); return false; } } @@ -1089,7 +1156,7 @@ public abstract class GeneralRegion { if(cannotSpawnBeside.contains(material)) { return false; } - } + } return true; }