Added the '/as stack' command to easily create and register regions

/as stack <amount> <gap> <name> <rent|buy> [group]
    <amount> Number of regions that will be created
    <gap> Blocks distance between the regions
    <name> Name of the regions (number will be behind it)
    <rent|buy> The type of the region
    [group] A group to add the created regions to
    The regions will be created in the direction you are facing
This commit is contained in:
Thijs Wiefferink 2015-02-22 17:08:32 +01:00
parent b1be87014f
commit 3bbca11cc9
10 changed files with 273 additions and 16 deletions

View File

@ -304,7 +304,7 @@ expireWarning:
## The time between checking if expiration warning need to be sent ## The time between checking if expiration warning need to be sent
delay: 5 delay: 5
## Number of regions to update per tick (there are 20 ticks in a second) ## Number of regions to update per tick (there are 20 ticks in a second)
regionsPerTick: 1 regionsPerTick: 3
## Timings for updating signs and region flags ('/as reload' or after '/as groupadd' or '/as groupdel') ## Timings for updating signs and region flags ('/as reload' or after '/as groupadd' or '/as groupdel')
update: update:
## Number of regions to update per tick (there are 20 ticks in a second) ## Number of regions to update per tick (there are 20 ticks in a second)
@ -321,12 +321,15 @@ signs:
## Time between updates of all signs (seconds) ## Time between updates of all signs (seconds)
delay: 60 delay: 60
## Number of regions to update signs for per tick (there are 20 ticks in a second) ## Number of regions to update signs for per tick (there are 20 ticks in a second)
regionsPerTick: 1 regionsPerTick: 3
## Number of regions per tick to check when a player joins to see if his name changed for regions he owned (updates the regions when changed) ## Number of regions per tick to check when a player joins to see if his name changed for regions he owned (updates the regions when changed)
nameupdate: nameupdate:
## Number of regions to update signs for per tick (there are 20 ticks in a second) ## Number of regions to update signs for per tick (there are 20 ticks in a second)
regionsPerTick: 5 regionsPerTick: 5
## Timings for adding regions to AreaShop ('/as stack')
adding:
## Number of regions to add per tick (there are 20 ticks in a second)
regionsPerTick: 2

View File

@ -60,6 +60,7 @@ help-addFriendAll: "&6/as addfriend &7-&r Add a friend to a region."
help-delFriend: "&6/as delfriend &7-&r Delete a friend from your region." help-delFriend: "&6/as delfriend &7-&r Delete a friend from your region."
help-delFriendAll: "&6/as delfriend &7-&r Delete a friend from a region." help-delFriendAll: "&6/as delfriend &7-&r Delete a friend from a region."
help-linksigns: "&6/as linksigns &7-&r Use bulk sign linking mode." help-linksigns: "&6/as linksigns &7-&r Use bulk sign linking mode."
help-stack: "&6/as stack &7-&r Create multiple regions and add them."
rent-help: "/as rent [regionname], the region you stand in will be used if not specified." rent-help: "/as rent [regionname], the region you stand in will be used if not specified."
rent-noPermission: "You don't have permission to rent a region." rent-noPermission: "You don't have permission to rent a region."
@ -385,6 +386,17 @@ linksigns-next: "&7Leftclick to select a sign, rightclick to select a region, us
linksigns-noPermission: "You don't have permission to enter bulk sign linking mode." linksigns-noPermission: "You don't have permission to enter bulk sign linking mode."
linksigns-stopped: "Exited sign linking mode." linksigns-stopped: "Exited sign linking mode."
stack-help: "/as stack <amount> <gap> <name> <rent|buy> [group].\n&7 <amount> Number of regions that will be created.\n <gap> Blocks distance between the regions.\n <name> Name of the regions (number will be behind it).\n <rent|buy> Make then rent or buy regions.\n [group] A group to add the created regions to.\n The regions will be created in the direction you are facing."
stack-accepted: "Starting to create %0% %1% regions with %2% blocks in between, names start with %3% and have a number behind them.%4%"
stack-addToGroup: " Created regions will be added to the group '%0%'."
stack-noPermission: "You don't have permission to create and add regions to AreaShop in bulk."
stack-wrongAmount: "'%0%' is not a correct amount of regions."
stack-wrongGap: "'%0%' is not a correct number for the number of blocks gap between regions."
stack-noSelection: "You don't have a selection that indicates where the first region should be created."
stack-addStart: "&7Adding %0% regions at %1% per second."
stack-addComplete: "&7Adding regions complete."
stack-unclearDirection: "Please look clearly in the north, east, south or west direction, currently detected %0%."
timeleft-years: "%0% years" timeleft-years: "%0% years"
timeleft-months: "%0% months" timeleft-months: "%0% months"
timeleft-days: "%0% days" timeleft-days: "%0% days"

View File

@ -50,6 +50,7 @@ permissions:
areashop.addfriendall: true areashop.addfriendall: true
areashop.delfriendall: true areashop.delfriendall: true
areashop.notifyupdate: true areashop.notifyupdate: true
areashop.stack: true
areashop.help: areashop.help:
description: Allows you to see the help pages description: Allows you to see the help pages
default: true default: true
@ -202,4 +203,7 @@ permissions:
default: op default: op
areashop.linksigns: areashop.linksigns:
description: Allows you to enter sign linking mode description: Allows you to enter sign linking mode
default: op
areashop.stack:
description: Allows you to create regions and add them to AreaShop like the WorldEdit //stack command
default: op default: op

View File

@ -4,6 +4,7 @@ import java.util.Collection;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -78,6 +79,16 @@ public class Utils {
return result; return result;
} }
public static final BlockFace[] facings = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
/**
* Get the facing direction based on the yaw
* @param yaw The horizontal angle that for example the player is looking
* @return The Block Face of the angle
*/
public static BlockFace yawToFacing(float yaw) {
return facings[Math.round(yaw / 45f) & 0x7];
}
} }

View File

@ -47,7 +47,6 @@ public class GroupaddCommand extends CommandAreaShop {
if(group == null) { if(group == null) {
group = new RegionGroup(plugin, args[1]); group = new RegionGroup(plugin, args[1]);
plugin.getFileManager().addGroup(group); plugin.getFileManager().addGroup(group);
group.saveRequired();
} }
if(args.length == 2) { if(args.length == 2) {
if(!(sender instanceof Player)) { if(!(sender instanceof Player)) {

View File

@ -0,0 +1,221 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
public class StackCommand extends CommandAreaShop {
public StackCommand(AreaShop plugin) {
super(plugin);
}
@Override
public String getCommandStart() {
return "areashop stack";
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.stack")) {
return plugin.getLanguageManager().getLang("help-stack");
}
return null;
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
// Check permission
if(!sender.hasPermission("areashop.stack")) {
plugin.message(sender, "stack-noPermission");
return;
}
// Only from ingame
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
final Player player = (Player)sender;
// Specify enough arguments
if(args.length < 5) {
plugin.message(sender, "stack-help");
return;
}
// Check amount
int tempAmount = -1;
try {
tempAmount = Integer.parseInt(args[1]);
} catch(NumberFormatException e) {}
if(tempAmount <= 0) {
plugin.message(player, "stack-wrongAmount", args[1]);
return;
}
// Check gap
int gap = -1;
try {
gap = Integer.parseInt(args[2]);
} catch(NumberFormatException e) {
plugin.message(player, "stack-wrongGap", args[2]);
return;
}
// Check region type
if(!"rent".equalsIgnoreCase(args[4]) && !"buy".equalsIgnoreCase(args[4])) {
plugin.message(sender, "stack-help");
return;
}
// Get WorldEdit selection
final Selection selection = plugin.getWorldEdit().getSelection(player);
if(selection == null) {
plugin.message(player, "stack-noSelection");
return;
}
// Get or create group
RegionGroup group = null;
if(args.length > 5) {
group = plugin.getFileManager().getGroup(args[5]);
if(group == null) {
group = new RegionGroup(plugin, args[5]);
plugin.getFileManager().addGroup(group);
}
}
// Get facing of the player (must be clearly one of the four directions to make sure it is no mistake)
BlockFace facing = Utils.yawToFacing(player.getLocation().getYaw());
if(!(facing == BlockFace.NORTH || facing == BlockFace.EAST || facing == BlockFace.SOUTH || facing == BlockFace.WEST)) {
plugin.message(player, "stack-unclearDirection", facing.toString().toLowerCase().replace('_', '-'));
return;
}
final Location shift = new Location(selection.getWorld(), 0, 0, 0);
if(facing == BlockFace.SOUTH) {
shift.setY(-selection.getLength() - gap);
} else if(facing == BlockFace.WEST) {
shift.setX(selection.getWidth() + gap);
} else if(facing == BlockFace.NORTH) {
shift.setY(selection.getLength() + gap);
} else if(facing == BlockFace.EAST) {
shift.setX(-selection.getWidth() - gap);
}
AreaShop.debug(" calculated shift vector: " + shift + ", with facing=" + facing);
// Create regions and add them to AreaShop
final String namePrefix = args[3];
final int regionsPerTick = plugin.getConfig().getInt("adding.regionsPerTick");
final boolean rentRegions = "rent".equalsIgnoreCase(args[4]);
final int amount = tempAmount;
final RegionGroup finalGroup = group;
String type = null;
if(rentRegions) {
type = "rent";
} else {
type = "buy";
}
String groupsMessage = "";
if(group != null) {
groupsMessage = plugin.getLanguageManager().getLang("stack-addToGroup", group.getName());
}
plugin.message(player, "stack-accepted", amount, type, gap, namePrefix, groupsMessage);
plugin.message(player, "stack-addStart", amount, regionsPerTick*20);
new BukkitRunnable() {
private int current = 0;
private RegionManager manager = AreaShop.getInstance().getWorldGuard().getRegionManager(selection.getWorld());
private int counter = 1;
@Override
public void run() {
for(int i=0; i<regionsPerTick; i++) {
if(current < amount) {
// Create the region name
String regionName = namePrefix + counter;
while(manager.getRegion(regionName) != null || AreaShop.getInstance().getFileManager().getRegion(regionName) != null) {
counter++;
regionName = namePrefix + counter;
}
// Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName,
new BlockVector(
selection.getMinimumPoint().getBlockX() + shift.getBlockX()*current,
selection.getMinimumPoint().getBlockY() + shift.getBlockY()*current,
selection.getMinimumPoint().getBlockZ() + shift.getBlockZ()*current
),
new BlockVector(
selection.getMaximumPoint().getBlockX() + shift.getBlockX()*current,
selection.getMaximumPoint().getBlockY() + shift.getBlockY()*current,
selection.getMaximumPoint().getBlockZ() + shift.getBlockZ()*current
)
);
manager.addRegion(region);
// Add the region to AreaShop
if(rentRegions) {
RentRegion rent = new RentRegion(plugin, region.getId(), selection.getWorld());
if(finalGroup != null) {
finalGroup.addMember(rent);
}
rent.runEventCommands(RegionEvent.CREATED, true);
plugin.getFileManager().addRent(rent);
rent.handleSchematicEvent(RegionEvent.CREATED);
rent.updateRegionFlags();
rent.runEventCommands(RegionEvent.CREATED, false);
rent.saveRequired();
} else {
BuyRegion buy = new BuyRegion(plugin, region.getId(), selection.getWorld());
if(finalGroup != null) {
finalGroup.addMember(buy);
}
buy.runEventCommands(RegionEvent.CREATED, true);
plugin.getFileManager().addBuy(buy);
buy.handleSchematicEvent(RegionEvent.CREATED);
buy.updateRegionFlags();
buy.runEventCommands(RegionEvent.CREATED, false);
buy.saveRequired();
}
current++;
}
}
if(current >= amount) {
if(player.isOnline()) {
plugin.message(player, "stack-addComplete");
}
this.cancel();
}
}
}.runTaskTimer(plugin, 1, 1);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
if(toComplete == 5) {
result.add("rent");
result.add("buy");
} else if(toComplete == 6) {
result.addAll(plugin.getFileManager().getGroupNames());
}
return result;
}
}

View File

@ -21,6 +21,7 @@ import nl.evolutioncoding.areashop.commands.GroupinfoCommand;
import nl.evolutioncoding.areashop.commands.GrouplistCommand; import nl.evolutioncoding.areashop.commands.GrouplistCommand;
import nl.evolutioncoding.areashop.commands.HelpCommand; import nl.evolutioncoding.areashop.commands.HelpCommand;
import nl.evolutioncoding.areashop.commands.InfoCommand; import nl.evolutioncoding.areashop.commands.InfoCommand;
import nl.evolutioncoding.areashop.commands.LinksignsCommand;
import nl.evolutioncoding.areashop.commands.MeCommand; import nl.evolutioncoding.areashop.commands.MeCommand;
import nl.evolutioncoding.areashop.commands.ReloadCommand; import nl.evolutioncoding.areashop.commands.ReloadCommand;
import nl.evolutioncoding.areashop.commands.RentCommand; import nl.evolutioncoding.areashop.commands.RentCommand;
@ -32,6 +33,7 @@ import nl.evolutioncoding.areashop.commands.SetownerCommand;
import nl.evolutioncoding.areashop.commands.SetpriceCommand; import nl.evolutioncoding.areashop.commands.SetpriceCommand;
import nl.evolutioncoding.areashop.commands.SetrestoreCommand; import nl.evolutioncoding.areashop.commands.SetrestoreCommand;
import nl.evolutioncoding.areashop.commands.SetteleportCommand; import nl.evolutioncoding.areashop.commands.SetteleportCommand;
import nl.evolutioncoding.areashop.commands.StackCommand;
import nl.evolutioncoding.areashop.commands.StopresellCommand; import nl.evolutioncoding.areashop.commands.StopresellCommand;
import nl.evolutioncoding.areashop.commands.TeleportCommand; import nl.evolutioncoding.areashop.commands.TeleportCommand;
import nl.evolutioncoding.areashop.commands.UnrentCommand; import nl.evolutioncoding.areashop.commands.UnrentCommand;
@ -82,7 +84,8 @@ public class CommandManager implements CommandExecutor, TabCompleter {
commands.add(new DelCommand(plugin)); commands.add(new DelCommand(plugin));
commands.add(new AddsignCommand(plugin)); commands.add(new AddsignCommand(plugin));
commands.add(new DelsignCommand(plugin)); commands.add(new DelsignCommand(plugin));
//commands.add(new LinksignsCommand(plugin)); commands.add(new LinksignsCommand(plugin));
commands.add(new StackCommand(plugin));
/* Register commands in bukkit */ /* Register commands in bukkit */
plugin.getCommand("AreaShop").setExecutor(this); plugin.getCommand("AreaShop").setExecutor(this);

View File

@ -243,7 +243,8 @@ public class FileManager {
/** /**
* Remove a rent from the list * Remove a rent from the list
* @param regionName * @param rent The region to remove
* @param giveMoneyBack use true to give money back to the player if someone is currently renting this region, otherwise false
*/ */
public boolean removeRent(RentRegion rent, boolean giveMoneyBack) { public boolean removeRent(RentRegion rent, boolean giveMoneyBack) {
boolean result = false; boolean result = false;
@ -903,6 +904,7 @@ public class FileManager {
* @return true * @return true
*/ */
public boolean loadRegionFiles() { public boolean loadRegionFiles() {
regions.clear();
File file = new File(regionsPath); File file = new File(regionsPath);
if(!file.exists()) { if(!file.exists()) {
file.mkdirs(); file.mkdirs();

View File

@ -63,6 +63,10 @@ public class LanguageManager {
OutputStream output = null; OutputStream output = null;
try { try {
input = plugin.getResource(AreaShop.languageFolder + "/" + languages[i] + ".yml"); input = plugin.getResource(AreaShop.languageFolder + "/" + languages[i] + ".yml");
if(input == null) {
plugin.getLogger().warning("Could not save default language to the '" + AreaShop.languageFolder + "' folder: " + languages[i] + ".yml");
continue;
}
output = new FileOutputStream(langFile); output = new FileOutputStream(langFile);
int read = 0; int read = 0;

View File

@ -156,11 +156,11 @@ public abstract class GeneralRegion {
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
if(getWorld() == null if(getWorld() == null) {
|| plugin.getWorldGuard().getRegionManager(getWorld()) == null throw new RegionCreateException("World '"+ getWorldName() +"' of region '" + getName() + "' does not exist anymore, removed region from AreaShop");
|| plugin.getWorldGuard().getRegionManager(getWorld()).getRegion(getName()) == null) { } else if(plugin.getWorldGuard().getRegionManager(getWorld()) == null
|| plugin.getWorldGuard().getRegionManager(getWorld()).getRegion(getName()) == null) {
throw new RegionCreateException("Region of " + getName() + " does not exist anymore"); throw new RegionCreateException("WorldGuard region '" + getName() + "' does not exist anymore, removed region from AreaShop");
} }
} }
@ -307,11 +307,7 @@ public abstract class GeneralRegion {
* @return The name of the world of the region * @return The name of the world of the region
*/ */
public String getWorldName() { public String getWorldName() {
String world = getStringSetting("general.world"); return getStringSetting("general.world");
if(world == null) {
return null;
}
return world;
} }
/** /**
@ -890,6 +886,7 @@ public abstract class GeneralRegion {
} }
// Get the origin and size of the region // Get the origin and size of the region
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ()); Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
AreaShop.debug("origin of restoreoperation: " + origin);
// The path to save the schematic // The path to save the schematic
File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName + AreaShop.schematicExtension); File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName + AreaShop.schematicExtension);
@ -909,6 +906,7 @@ public abstract class GeneralRegion {
WorldData worldData = world.getWorldData(); WorldData worldData = world.getWorldData();
LocalSession session = new LocalSession(plugin.getWorldEdit().getLocalConfiguration()); LocalSession session = new LocalSession(plugin.getWorldEdit().getLocalConfiguration());
Clipboard clipboard = reader.read(worldData); Clipboard clipboard = reader.read(worldData);
clipboard.setOrigin(clipboard.getMinimumPoint());
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData); ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData);
session.setBlockChangeLimit(plugin.getConfig().getInt("maximumBlocks")); session.setBlockChangeLimit(plugin.getConfig().getInt("maximumBlocks"));
session.setClipboard(clipboardHolder); session.setClipboard(clipboardHolder);