Adds the code from version 2.0.1

This commit is contained in:
Thijs Wiefferink 2014-09-06 22:49:29 +02:00
parent b3ea7f7e73
commit 6886db8edc
9 changed files with 167 additions and 89 deletions

View File

@ -20,6 +20,8 @@ language: EN
enableSchematics: true enableSchematics: true
## Maximum number of blocks to save to or restore from a .schemetic ## Maximum number of blocks to save to or restore from a .schemetic
maximumBlocks: 1000000 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) ## Enable sending stats to http://mcstats.org/ (Metrics plugin)
sendStats: true sendStats: true
## Use colors when sending messages to console and log files ## Use colors when sending messages to console and log files
@ -28,9 +30,6 @@ useColorsInConsole: false
postCommandErrors: true postCommandErrors: true
## Version of the config, do not change! ## Version of the config, do not change!
version: 2.0.0 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 ## The different tags you can write on the sign to trigger the plugin
signTags: signTags:
## Tag for adding a rent region ## Tag for adding a rent region

View File

@ -13,29 +13,13 @@ general:
signProfile: 'default' signProfile: 'default'
## The profile for the WorldGuard flags as specified in the config ## The profile for the WorldGuard flags as specified in the config
flagProfile: 'default' flagProfile: 'default'
runCommands: ## The y location within the region to start searching for safe teleport spots (x and z will be in the middle of the region)
created: ## Possible values: bottom, middle, top
before: teleportLocationY: bottom
after: ## If true the teleportation algorithm only allows telportation to inside the region, otherwise it will expand algorithm
- "say An AreaShop region has been created: %region%" ## a cube from the starting point to check for safe spots (then it could end outside the region)
deleted: ## 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)
before: teleportIntoRegion: true
after:
rented:
before:
after:
extended:
before:
after:
unrented:
before:
after:
bought:
before:
after:
sold:
before:
after:
########## RENTING ########## ########## RENTING ##########
rent: rent:

View File

@ -153,7 +153,7 @@ setprice-successRent: "Price of region %0% changed to %1% per %2%"
setprice-successBuy: "Price of region %0% changed to %1%" setprice-successBuy: "Price of region %0% changed to %1%"
rentduration-noPermission: "You don't have permission to change the duration of a rent" rentduration-noPermission: "You don't have permission to change the duration of a rent"
rentduration-help: "/as rentduration <region> <amount> <identifier>" rentduration-help: "/as rentduration <amount> <identifier> [region], the region you stand in will be used if not specified"
rentduration-notRegistered: "%0% is not registered as a rent" rentduration-notRegistered: "%0% is not registered as a rent"
rentduration-wrongAmount: "'%0%' is not a valid amount, use a whole number" 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" 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-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-noPermissionOther: "You don't have permission to teleport to region you do not own"
teleport-success: "You teleported to %0%" 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-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" setteleport-noPermission: "You don't have permission to set the teleport location"
@ -231,6 +231,7 @@ schemevent-help: "/as schemevent <region> <created|deleted|rented|unrented|bough
schemevent-noRegion: "The specified region is not registered: %0%" schemevent-noRegion: "The specified region is not registered: %0%"
schemevent-wrongEvent: "The specified event '%0%' does not exist, use one of the following: &7%1%" schemevent-wrongEvent: "The specified event '%0%' does not exist, use one of the following: &7%1%"
schemevent-success: "Event '%0%' has succesfully been triggered for region %1%" schemevent-success: "Event '%0%' has succesfully been triggered for region %1%"
schemevent-noPermission: "You don't have permission to trigger schematic events"
add-help: "/as add <rent|buy> [region] [world]" add-help: "/as add <rent|buy> [region] [world]"
add-noPermission: "You don't have permission to add a region to AreaShop" add-noPermission: "You don't have permission to add a region to AreaShop"

View File

@ -1,6 +1,6 @@
name: AreaShop name: AreaShop
main: nl.evolutioncoding.AreaShop.AreaShop main: nl.evolutioncoding.AreaShop.AreaShop
version: 2.0.0 version: 2.0.1
depend: [Vault, WorldGuard, WorldEdit] depend: [Vault, WorldGuard, WorldEdit]
softdepend: [Multiverse-Core] softdepend: [Multiverse-Core]
commands: commands:

View File

@ -50,7 +50,7 @@ public class BuyCommand extends CommandAreaShop {
if(regions.size() != 1) { if(regions.size() != 1) {
plugin.message(sender, "buy-help"); plugin.message(sender, "buy-help");
} else { } else {
if(!regions.get(0).isRentRegion()) { if(!regions.get(0).isBuyRegion()) {
plugin.message(sender, "buy-notBuyable"); plugin.message(sender, "buy-notBuyable");
} else { } else {
((BuyRegion)regions.get(0)).buy(player); ((BuyRegion)regions.get(0)).buy(player);

View File

@ -55,6 +55,7 @@ public class RentCommand extends CommandAreaShop {
} else { } else {
((RentRegion)regions.get(0)).rent(player); ((RentRegion)regions.get(0)).rent(player);
} }
plugin.saveConfig();
} }
} }
} }

View File

@ -4,10 +4,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import nl.evolutioncoding.AreaShop.AreaShop; import nl.evolutioncoding.AreaShop.AreaShop;
import nl.evolutioncoding.AreaShop.regions.GeneralRegion;
import nl.evolutioncoding.AreaShop.regions.RentRegion; import nl.evolutioncoding.AreaShop.regions.RentRegion;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RentdurationCommand extends CommandAreaShop { public class RentdurationCommand extends CommandAreaShop {
@ -34,26 +36,45 @@ public class RentdurationCommand extends CommandAreaShop {
plugin.message(sender, "rentduration-noPermission"); plugin.message(sender, "rentduration-noPermission");
return; 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"); plugin.message(sender, "rentduration-help");
return; 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<GeneralRegion> 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) { if(rent == null) {
plugin.message(sender, "rentduration-notRegistered", args[1]); plugin.message(sender, "rentduration-notRegistered", args[3]);
return; return;
} }
try { try {
Integer.parseInt(args[2]); Integer.parseInt(args[1]);
} catch(NumberFormatException e) { } catch(NumberFormatException e) {
plugin.message(sender, "rentduration-wrongAmount", args[2]); plugin.message(sender, "rentduration-wrongAmount", args[1]);
return; return;
} }
if(!plugin.checkTimeFormat(args[2] + " " + args[3])) { if(!plugin.checkTimeFormat(args[1] + " " + args[2])) {
plugin.message(sender, "rentduration-wrongFormat", args[2]+" "+args[3]); plugin.message(sender, "rentduration-wrongFormat", args[1]+" "+args[2]);
return; return;
} }
rent.setDuration(args[2]+" "+args[3]); rent.setDuration(args[1]+" "+args[2]);
rent.updateRegionFlags(); rent.updateRegionFlags();
rent.updateSigns(); rent.updateSigns();
rent.save(); rent.save();

View File

@ -33,6 +33,11 @@ public class SchematiceventCommand extends CommandAreaShop {
@Override @Override
public void execute(CommandSender sender, Command command, String[] args) { 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) { if(args.length < 3 || args[1] == null || args[2] == null) {
plugin.message(sender, "schemevent-help"); plugin.message(sender, "schemevent-help");
return; return;

View File

@ -856,7 +856,8 @@ public abstract class GeneralRegion {
if(region != null) { if(region != null) {
// Set to block in the middle, y configured in the config // Set to block in the middle, y configured in the config
Vector middle = Vector.getMidpoint(region.getMaximumPoint(), region.getMinimumPoint()); 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)) { if("bottom".equalsIgnoreCase(configSetting)) {
middle = middle.setY(region.getMinimumPoint().getBlockY()); middle = middle.setY(region.getMinimumPoint().getBlockY());
} else if("top".equalsIgnoreCase(configSetting)) { } else if("top".equalsIgnoreCase(configSetting)) {
@ -869,6 +870,10 @@ public abstract class GeneralRegion {
return false; 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 // set location in the center of the block
startLocation.setX(startLocation.getBlockX() + 0.5); 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) // radius around that (until no block in the region is found at all cube sides)
Location saveLocation = startLocation; Location saveLocation = startLocation;
int radius = 1; 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 north=false, east=false, south=false, west=false, top=false, bottom=false;
boolean track; boolean track;
while(!done) { while(((blocksInRegion && insideRegion) || (!insideRegion)) && !done) {
blocksInRegion = false;
// North side // North side
track = false; track = false;
for(int x=-radius+1; x<=radius && !done && !north; x++) { for(int x=-radius+1; x<=radius && !done && !north; x++) {
for(int y=-radius+1; y<radius && !done; y++) { for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(x, y, -radius); saveLocation = startLocation.clone().add(x, y, -radius);
done = isSave(saveLocation); if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
track = true; continue;
checked++; }
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
} }
north = north || !track; north = north || !track;
@ -899,9 +912,15 @@ public abstract class GeneralRegion {
for(int z=-radius+1; z<=radius && !done && !east; z++) { for(int z=-radius+1; z<=radius && !done && !east; z++) {
for(int y=-radius+1; y<radius && !done; y++) { for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(radius, y, z); saveLocation = startLocation.clone().add(radius, y, z);
done = isSave(saveLocation); if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
track = true; continue;
checked++; }
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
} }
east = east || !track; east = east || !track;
@ -911,9 +930,15 @@ public abstract class GeneralRegion {
for(int x=radius-1; x>=-radius && !done && !south; x--) { for(int x=radius-1; x>=-radius && !done && !south; x--) {
for(int y=-radius+1; y<radius && !done; y++) { for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(x, y, radius); saveLocation = startLocation.clone().add(x, y, radius);
done = isSave(saveLocation); if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
track = true; continue;
checked++; }
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
} }
south = south || !track; south = south || !track;
@ -923,50 +948,74 @@ public abstract class GeneralRegion {
for(int z=radius-1; z>=-radius && !done && !west; z--) { for(int z=radius-1; z>=-radius && !done && !west; z--) {
for(int y=-radius+1; y<radius && !done; y++) { for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(-radius, y, z); saveLocation = startLocation.clone().add(-radius, y, z);
done = isSave(saveLocation); if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
track = true; continue;
checked++; }
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 // Top side
track = false; track = false;
// Middle block of the top // Middle block of the top
if((startLocation.getBlockY() + radius) > 256) {
top = true;
}
if(!done && !top) { if(!done && !top) {
saveLocation = startLocation.clone().add(0, radius, 0); saveLocation = startLocation.clone().add(0, radius, 0);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
for(int r=1; r<=radius && !done && !top; r++) { for(int r=1; r<=radius && !done && !top; r++) {
// North // North
for(int x=-r+1; x<=r && !done; x++) { for(int x=-r+1; x<=r && !done; x++) {
saveLocation = startLocation.clone().add(x, radius, -r); saveLocation = startLocation.clone().add(x, radius, -r);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// East // East
for(int z=-r+1; z<=r && !done; z++) { for(int z=-r+1; z<=r && !done; z++) {
saveLocation = startLocation.clone().add(r, radius, z); saveLocation = startLocation.clone().add(r, radius, z);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// South side // South side
for(int x=r-1; x>=-r && !done; x--) { for(int x=r-1; x>=-r && !done; x--) {
saveLocation = startLocation.clone().add(x, radius, r); saveLocation = startLocation.clone().add(x, radius, r);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// West side // West side
for(int z=r-1; z>=-r && !done; z--) { for(int z=r-1; z>=-r && !done; z--) {
saveLocation = startLocation.clone().add(-r, radius, z); saveLocation = startLocation.clone().add(-r, radius, z);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
} }
top = top || !track; top = top || !track;
@ -974,40 +1023,58 @@ public abstract class GeneralRegion {
// Bottom side // Bottom side
track = false; track = false;
// Middle block of the bottom // Middle block of the bottom
if(startLocation.getBlockY() - radius < 0) {
bottom = true;
}
if(!done && !bottom) { if(!done && !bottom) {
saveLocation = startLocation.clone().add(0, -radius, 0); saveLocation = startLocation.clone().add(0, -radius, 0);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
for(int r=1; r<=radius && !done && !bottom; r++) { for(int r=1; r<=radius && !done && !bottom; r++) {
// North // North
for(int x=-r+1; x<=r && !done; x++) { for(int x=-r+1; x<=r && !done; x++) {
saveLocation = startLocation.clone().add(x, -radius, -r); saveLocation = startLocation.clone().add(x, -radius, -r);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// East // East
for(int z=-r+1; z<=r && !done; z++) { for(int z=-r+1; z<=r && !done; z++) {
saveLocation = startLocation.clone().add(r, -radius, z); saveLocation = startLocation.clone().add(r, -radius, z);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// South side // South side
for(int x=r-1; x>=-r && !done; x--) { for(int x=r-1; x>=-r && !done; x--) {
saveLocation = startLocation.clone().add(x, -radius, r); saveLocation = startLocation.clone().add(x, -radius, r);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
// West side // West side
for(int z=r-1; z>=-r && !done; z--) { for(int z=r-1; z>=-r && !done; z--) {
saveLocation = startLocation.clone().add(-r, -radius, z); saveLocation = startLocation.clone().add(-r, -radius, z);
done = isSave(saveLocation); if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
track = true; checked++;
checked++; done = isSave(saveLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
} }
} }
bottom = bottom || !track; bottom = bottom || !track;
@ -1015,14 +1082,14 @@ public abstract class GeneralRegion {
// Increase cube radius // Increase cube radius
radius++; radius++;
} }
if(done) { if(done && isSave(saveLocation)) {
plugin.message(player, "teleport-success", getName()); plugin.message(player, "teleport-success", getName());
player.teleport(saveLocation); player.teleport(saveLocation);
AreaShop.debug("Found location: " + saveLocation.toString() + " Tries: " + checked); AreaShop.debug("Found location: " + saveLocation.toString() + " Tries: " + (checked-1));
return true; return true;
} else { } else {
plugin.message(player, "teleport-noSafe", getName()); plugin.message(player, "teleport-noSafe", getName(), checked-1, maxTries);
AreaShop.debug("No location found, checked " + checked + " spots"); AreaShop.debug("No location found, checked " + (checked-1) + " spots of max " + maxTries);
return false; return false;
} }
} }
@ -1089,7 +1156,7 @@ public abstract class GeneralRegion {
if(cannotSpawnBeside.contains(material)) { if(cannotSpawnBeside.contains(material)) {
return false; return false;
} }
} }
return true; return true;
} }