mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-16 07:15:23 +01:00
Change to a Maven project
Changed project layout to Maven, all dependencies except Vault (does not have a maven repo) are now included in the pom.xml and will be automatically downloaded by Maven when building. The project setup uses modules to support both WorldGuard and WorldEdit version with 1 jar file instead of having 2 files as the last versions of AreaShop had. Small bug with boolean settings in the config files has been fixed. Problem with '/as stack' stacking in the Y direction instead of Z has been fixed. Plus some refactoring and small changes.
This commit is contained in:
parent
2785a72457
commit
796b95c9f9
1
AreaShop/.gitignore
vendored
Normal file
1
AreaShop/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
159
AreaShop/pom.xml
Normal file
159
AreaShop/pom.xml
Normal file
@ -0,0 +1,159 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop</name>
|
||||
<version>2.2.0</version> <!-- Main plugin version -->
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo-wg</id>
|
||||
<url>http://maven.sk89q.com/artifactory/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.2</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-worldguard-5</artifactId>
|
||||
<version>WorldGuard-5</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-worldguard-6</artifactId>
|
||||
<version>WorldGuard-6</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>AreaShopInterface</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-worldedit-5</artifactId>
|
||||
<version>WorldEdit-5</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-worldedit-6</artifactId>
|
||||
<version>WorldEdit-6</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../Dependencies/Vault.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<finalName>AreaShop</finalName>
|
||||
<!-- Include all required resources -->
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
<include>config.yml</include>
|
||||
<include>default.yml</include>
|
||||
<include>README.md</include>
|
||||
<include>lang/*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<targer>1.7</targer>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Copy resulting file to local server, change to your own path -->
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy file="./target/${project.build.finalName}.jar" tofile="C:\Games\Minecraft\Spigot 1.8\plugins\${project.build.finalName}.jar"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target failonerror="false"></target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -9,6 +9,9 @@ import java.util.logging.Logger;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import nl.evolutioncoding.areashop.Updater.UpdateResult;
|
||||
import nl.evolutioncoding.areashop.Updater.UpdateType;
|
||||
import nl.evolutioncoding.areashop.interfaces.AreaShopInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldEditInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldGuardInterface;
|
||||
import nl.evolutioncoding.areashop.listeners.PlayerLoginListener;
|
||||
import nl.evolutioncoding.areashop.listeners.SignBreakListener;
|
||||
import nl.evolutioncoding.areashop.listeners.SignChangeListener;
|
||||
@ -37,12 +40,14 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
* Main class for the AreaShop plugin
|
||||
* @author NLThijs48
|
||||
*/
|
||||
public final class AreaShop extends JavaPlugin {
|
||||
public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
/* General variables */
|
||||
private static AreaShop instance = null;
|
||||
|
||||
private WorldGuardPlugin worldGuard = null;
|
||||
private WorldGuardInterface worldGuardInterface = null;
|
||||
private WorldEditPlugin worldEdit = null;
|
||||
private WorldEditInterface worldEditInterface = null;
|
||||
private FileManager fileManager = null;
|
||||
private LanguageManager languageManager = null;
|
||||
private CommandManager commandManager = null;
|
||||
@ -70,7 +75,7 @@ public final class AreaShop extends JavaPlugin {
|
||||
public static final String versionFiles = "files";
|
||||
public static final int versionFilesCurrent = 2;
|
||||
|
||||
/* Keys for replacing parts of flags */
|
||||
/* Keys for replacing parts of flags, commands, strings */
|
||||
public static final String tagPlayerName = "%player%";
|
||||
public static final String tagPlayerUUID = "%uuid%";
|
||||
public static final String tagWorldName = "%world%";
|
||||
@ -111,40 +116,81 @@ public final class AreaShop extends JavaPlugin {
|
||||
AreaShop.instance = this;
|
||||
boolean error = false;
|
||||
|
||||
/* Check if WorldGuard is present */
|
||||
// Check if WorldGuard is present
|
||||
String wgVersion = null;
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
|
||||
this.getLogger().severe("WorldGuard plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
} else {
|
||||
worldGuard = (WorldGuardPlugin)plugin;
|
||||
// Get correct WorldGuardInterface (handles things that changed version to version)
|
||||
if(worldGuard.getDescription().getVersion().startsWith("5.")) {
|
||||
wgVersion = "5";
|
||||
} else {
|
||||
wgVersion = "6";
|
||||
}
|
||||
|
||||
if(getWorldGuard() != null && getWorldGuard().getDescription().getVersion().startsWith("5.")) {
|
||||
getLogger().severe("This version of AreaShop is not meant for WorldGuard 5.x, use the correct version matching your WorldGuard version");
|
||||
try {
|
||||
final Class<?> clazz = Class.forName("nl.evolutioncoding.areashop.handlers.WorldGuardHandler" + wgVersion);
|
||||
// Check if we have a NMSHandler class at that location.
|
||||
if (WorldGuardInterface.class.isAssignableFrom(clazz)) { // Make sure it actually implements WorldGuardInterface
|
||||
this.worldGuardInterface = (WorldGuardInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
this.getLogger().severe("Could not load the handler for WorldGuard (tried to load " + wgVersion + "), report this problem to the author.");
|
||||
error = true;
|
||||
wgVersion = null;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if WorldEdit is present */
|
||||
// Check if WorldEdit is present
|
||||
String weVersion = null;
|
||||
plugin = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (plugin == null || !(plugin instanceof WorldEditPlugin)) {
|
||||
this.getLogger().severe("WorldEdit plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
} else {
|
||||
worldEdit = (WorldEditPlugin)plugin;
|
||||
// Get correct WorldEditInterface (handles things that changed version to version)
|
||||
if(worldEdit.getDescription().getVersion().startsWith("5.")) {
|
||||
weVersion = "5";
|
||||
} else {
|
||||
weVersion = "6";
|
||||
}
|
||||
try {
|
||||
final Class<?> clazz = Class.forName("nl.evolutioncoding.areashop.handlers.WorldEditHandler" + weVersion);
|
||||
// Check if we have a NMSHandler class at that location.
|
||||
if (WorldEditInterface.class.isAssignableFrom(clazz)) { // Make sure it actually implements WorldEditInterface
|
||||
this.worldEditInterface = (WorldEditInterface) clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
this.getLogger().severe("Could not load the handler for WorldEdit (tried to load " + weVersion + "), report this problem to the author.");
|
||||
error = true;
|
||||
weVersion = null;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if Vault is present */
|
||||
// Check if Vault is present
|
||||
if(getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
this.getLogger().severe("Vault plugin is not present or has not loaded correctly");
|
||||
error = true;
|
||||
}
|
||||
|
||||
/* Load all data from files and check versions */
|
||||
// Load all data from files and check versions
|
||||
fileManager = new FileManager(this);
|
||||
error = error & !fileManager.loadFiles();
|
||||
|
||||
/* Create a LanguageMananager */
|
||||
// Print loaded version of WG and WE in debug
|
||||
if(wgVersion != null) {
|
||||
AreaShop.debug("Loaded WorldGuardHandler" + wgVersion);
|
||||
}
|
||||
if(weVersion != null) {
|
||||
AreaShop.debug("Loaded WorldEditHandler" + weVersion);
|
||||
}
|
||||
|
||||
// Create a LanguageMananager
|
||||
languageManager = new LanguageManager(this);
|
||||
|
||||
if(error) {
|
||||
@ -264,6 +310,14 @@ public final class AreaShop extends JavaPlugin {
|
||||
return worldGuard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get WorldGuardInterface for version dependent things
|
||||
* @return WorldGuardInterface
|
||||
*/
|
||||
public WorldGuardInterface getWorldGuardHandler() {
|
||||
return this.worldGuardInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the WorldEdit plugin
|
||||
* @return WorldEditPlugin
|
||||
@ -272,6 +326,14 @@ public final class AreaShop extends JavaPlugin {
|
||||
return worldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get WorldGuardInterface for version dependent things
|
||||
* @return WorldGuardInterface
|
||||
*/
|
||||
public WorldEditInterface getWorldEditHandler() {
|
||||
return this.worldEditInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the LanguageManager
|
||||
* @return the LanguageManager
|
||||
@ -349,7 +411,11 @@ public final class AreaShop extends JavaPlugin {
|
||||
for(String group : section.getKeys(false)) {
|
||||
if(!"default".equals(group)) {
|
||||
Permission perm = new Permission("areashop.limits." + group);
|
||||
try {
|
||||
Bukkit.getPluginManager().addPermission(perm);
|
||||
} catch(IllegalArgumentException e) {
|
||||
this.getLogger().warning("Could not add the following permission to be used as limit: " + perm.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
Bukkit.getPluginManager().recalculatePermissionDefaults(Bukkit.getPluginManager().getPermission("playerwarps.limits"));
|
||||
@ -498,7 +564,7 @@ public final class AreaShop extends JavaPlugin {
|
||||
String result = null;
|
||||
if(input != null) {
|
||||
result = ChatColor.translateAlternateColorCodes('&', input);
|
||||
result = result.replaceAll("€", "\u20AC");
|
||||
result = result.replaceAll("<EFBFBD>", "\u20AC");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -515,9 +581,12 @@ public final class AreaShop extends JavaPlugin {
|
||||
after = after.replace(currencyEuro, "\u20ac");
|
||||
BigDecimal bigDecimal = new BigDecimal(amount);
|
||||
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
|
||||
amount = bigDecimal.doubleValue();
|
||||
if(getConfig().getBoolean("hideEmptyFractionalPart") && (amount%1.0) == 0.0) {
|
||||
return before + ((int)amount) + after;
|
||||
if(bigDecimal.doubleValue() > 1000000000) {
|
||||
bigDecimal = bigDecimal.stripTrailingZeros();
|
||||
}
|
||||
double newAmount = bigDecimal.doubleValue();
|
||||
if(getConfig().getBoolean("hideEmptyFractionalPart") && (newAmount%1.0) == 0.0) {
|
||||
return before + bigDecimal.toString().replace(".0", "") + after;
|
||||
} else {
|
||||
return before + bigDecimal.toString() + after;
|
||||
}
|
||||
@ -589,6 +658,9 @@ public final class AreaShop extends JavaPlugin {
|
||||
AreaShop.getInstance().getLogger().info("Debug: " + message);
|
||||
}
|
||||
}
|
||||
public void debugI(String message) {
|
||||
AreaShop.debug(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload all files of the plugin and update all regions
|
278
AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java
Normal file
278
AreaShop/src/main/java/nl/evolutioncoding/areashop/Utils.java
Normal file
@ -0,0 +1,278 @@
|
||||
package nl.evolutioncoding.areashop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class Utils {
|
||||
|
||||
// Not used
|
||||
private Utils() {}
|
||||
|
||||
|
||||
/**
|
||||
* Create a map from a location, to save it in the config
|
||||
* @param location The location to transform
|
||||
* @return The map with the location values
|
||||
*/
|
||||
public static ConfigurationSection locationToConfig(Location location, boolean setPitchYaw) {
|
||||
if(location == null) {
|
||||
return null;
|
||||
}
|
||||
ConfigurationSection result = new YamlConfiguration();
|
||||
result.set("world", location.getWorld().getName());
|
||||
result.set("x", location.getX());
|
||||
result.set("y", location.getY());
|
||||
result.set("z", location.getZ());
|
||||
if(setPitchYaw) {
|
||||
result.set("yaw", Float.toString(location.getYaw()));
|
||||
result.set("pitch", Float.toString(location.getPitch()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static ConfigurationSection locationToConfig(Location location) {
|
||||
return locationToConfig(location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a location from a map, reconstruction from the config values
|
||||
* @param map The map to reconstruct from
|
||||
* @return The location
|
||||
*/
|
||||
public static Location configToLocation(ConfigurationSection config) {
|
||||
if(config == null
|
||||
|| !config.isString("world")
|
||||
|| !config.isDouble("x")
|
||||
|| !config.isDouble("y")
|
||||
|| !config.isDouble("z")) {
|
||||
return null;
|
||||
}
|
||||
Location result = new Location(
|
||||
Bukkit.getWorld(config.getString("world")),
|
||||
(Double)config.getDouble("x"),
|
||||
(Double)config.getDouble("y"),
|
||||
(Double)config.getDouble("z"));
|
||||
if(config.isString("yaw") && config.isString("pitch")) {
|
||||
result.setPitch(Float.parseFloat(config.getString("pitch")));
|
||||
result.setYaw(Float.parseFloat(config.getString("yaw")));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String createCommaSeparatedList(Collection<? extends Object> input) {
|
||||
String result = "";
|
||||
boolean first = true;
|
||||
for(Object object : input) {
|
||||
if(object != null) {
|
||||
if(first) {
|
||||
first = false;
|
||||
result += object.toString();
|
||||
} else {
|
||||
result += ", " + object.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
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];
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Methods to get WorldGuard or AreaShop regions by location or selection
|
||||
// ======================================================================
|
||||
/**
|
||||
* Get all AreaShop regions intersecting with a WorldEdit selection
|
||||
* @param selection The selection to check
|
||||
* @return A list with all the AreaShop regions intersecting with the selection
|
||||
*/
|
||||
public static List<GeneralRegion> getASRegionsInSelection(Selection selection) {
|
||||
ArrayList<GeneralRegion> result = new ArrayList<GeneralRegion>();
|
||||
for(ProtectedRegion region : getWERegionsInSelection(selection)) {
|
||||
GeneralRegion asRegion = AreaShop.getInstance().getFileManager().getRegion(region.getId());
|
||||
if(asRegion != null) {
|
||||
result.add(asRegion);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Get all AreaShop regions containing a location
|
||||
* @param location The location to check
|
||||
* @return A list with all the AreaShop regions that contain the location
|
||||
*/
|
||||
public static List<GeneralRegion> getASRegionsByLocation(Location location) {
|
||||
Selection selection = new CuboidSelection(location.getWorld(), location, location);
|
||||
return getASRegionsInSelection(selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all WorldGuard regions intersecting with a WorldEdit selection
|
||||
* @param selection The selection to check
|
||||
* @return A list with all the WorldGuard regions intersecting with the selection
|
||||
*/
|
||||
public static List<ProtectedRegion> getWERegionsInSelection(Selection selection) {
|
||||
// Get all regions inside or intersecting with the WorldEdit selection of the player
|
||||
World world = selection.getWorld();
|
||||
RegionManager regionManager = AreaShop.getInstance().getWorldGuard().getRegionManager(world);
|
||||
ArrayList<ProtectedRegion> result = new ArrayList<ProtectedRegion>();
|
||||
Location selectionMin = selection.getMinimumPoint();
|
||||
Location selectionMax = selection.getMaximumPoint();
|
||||
for(ProtectedRegion region : regionManager.getRegions().values()) {
|
||||
BlockVector regionMin = region.getMinimumPoint();
|
||||
BlockVector regionMax = region.getMaximumPoint();
|
||||
if(
|
||||
( // x part, resolves to true if the selection and region overlap anywhere on the x-axis
|
||||
(regionMin.getBlockX() <= selectionMax.getBlockX() && regionMin.getBlockX() >= selectionMin.getBlockX())
|
||||
|| (regionMax.getBlockX() <= selectionMax.getBlockX() && regionMax.getBlockX() >= selectionMin.getBlockX())
|
||||
|| (selectionMin.getBlockX() >= regionMin.getBlockX() && selectionMin.getBlockX() <= regionMax.getBlockX())
|
||||
|| (selectionMax.getBlockX() >= regionMin.getBlockX() && selectionMax.getBlockX() <= regionMax.getBlockX())
|
||||
) && ( // Y part, resolves to true if the selection and region overlap anywhere on the y-axis
|
||||
(regionMin.getBlockY() <= selectionMax.getBlockY() && regionMin.getBlockY() >= selectionMin.getBlockY())
|
||||
|| (regionMax.getBlockY() <= selectionMax.getBlockY() && regionMax.getBlockY() >= selectionMin.getBlockY())
|
||||
|| (selectionMin.getBlockY() >= regionMin.getBlockY() && selectionMin.getBlockY() <= regionMax.getBlockY())
|
||||
|| (selectionMax.getBlockY() >= regionMin.getBlockY() && selectionMax.getBlockY() <= regionMax.getBlockY())
|
||||
) && ( // Z part, resolves to true if the selection and region overlap anywhere on the z-axis
|
||||
(regionMin.getBlockZ() <= selectionMax.getBlockZ() && regionMin.getBlockZ() >= selectionMin.getBlockZ())
|
||||
|| (regionMax.getBlockZ() <= selectionMax.getBlockZ() && regionMax.getBlockZ() >= selectionMin.getBlockZ())
|
||||
|| (selectionMin.getBlockZ() >= regionMin.getBlockZ() && selectionMin.getBlockZ() <= regionMax.getBlockZ())
|
||||
|| (selectionMax.getBlockZ() >= regionMin.getBlockZ() && selectionMax.getBlockZ() <= regionMax.getBlockZ())
|
||||
)
|
||||
) {
|
||||
result.add(region);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of regions around a location
|
||||
* - Returns highest priority, child instead of parent regions
|
||||
* @param location The location to check for regions
|
||||
* @return empty list if no regions found, 1 member if 1 region is a priority, more if regions with the same priority
|
||||
*/
|
||||
public static List<ProtectedRegion> getApplicableRegions(Location location) {
|
||||
List<ProtectedRegion> result = new ArrayList<ProtectedRegion>();
|
||||
Set<ProtectedRegion> regions = AreaShop.getInstance().getWorldGuardHandler().getApplicableRegionsSet(location);
|
||||
if(regions != null) {
|
||||
boolean first = true;
|
||||
for(ProtectedRegion pr : regions) {
|
||||
if(first) {
|
||||
result.add(pr);
|
||||
first = false;
|
||||
} else {
|
||||
if(pr.getPriority() > result.get(0).getPriority()) {
|
||||
result.clear();
|
||||
result.add(pr);
|
||||
} else if(pr.getParent() != null && pr.getParent().equals(result.get(0))) {
|
||||
result.clear();
|
||||
result.add(pr);
|
||||
} else {
|
||||
result.add(pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Methods to get the most important AreaShop regions at a certain location
|
||||
public static List<RentRegion> getApplicableRentRegions(Location location) {
|
||||
List<RentRegion> result = new ArrayList<RentRegion>();
|
||||
for(GeneralRegion region : getApplicableASRegions(location, RegionType.RENT)) {
|
||||
result.add((RentRegion)region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static List<BuyRegion> getApplicableBuyRegions(Location location) {
|
||||
List<BuyRegion> result = new ArrayList<BuyRegion>();
|
||||
for(GeneralRegion region : getApplicableASRegions(location, RegionType.BUY)) {
|
||||
result.add((BuyRegion)region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static List<GeneralRegion> getAllApplicableRegions(Location location) {
|
||||
return getApplicableASRegions(location, null);
|
||||
}
|
||||
public static List<GeneralRegion> getApplicableASRegions(Location location, RegionType type) {
|
||||
List<GeneralRegion> result = new ArrayList<GeneralRegion>();
|
||||
// TODO move to version specific classes
|
||||
Set<ProtectedRegion> regions = AreaShop.getInstance().getWorldGuardHandler().getApplicableRegionsSet(location);
|
||||
if(regions != null) {
|
||||
List<GeneralRegion> candidates = new ArrayList<GeneralRegion>();
|
||||
for(ProtectedRegion pr : regions) {
|
||||
GeneralRegion region = AreaShop.getInstance().getFileManager().getRegion(pr.getId());
|
||||
if(region != null && (
|
||||
(type == RegionType.RENT && region.isRentRegion())
|
||||
|| (type == RegionType.BUY && region.isBuyRegion())
|
||||
|| type == null)) {
|
||||
candidates.add(region);
|
||||
}
|
||||
}
|
||||
boolean first = true;
|
||||
for(GeneralRegion region : candidates) {
|
||||
if(region == null) {
|
||||
AreaShop.debug("skipped null region");
|
||||
continue;
|
||||
}
|
||||
if(first) {
|
||||
result.add(region);
|
||||
first = false;
|
||||
} else {
|
||||
if(region.getRegion().getPriority() > result.get(0).getRegion().getPriority()) {
|
||||
result.clear();
|
||||
result.add(region);
|
||||
} else if(region.getRegion().getParent() != null && region.getRegion().getParent().equals(result.get(0))) {
|
||||
result.clear();
|
||||
result.add(region);
|
||||
} else {
|
||||
result.add(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<GeneralRegion>(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class AddCommand extends CommandAreaShop {
|
||||
return;
|
||||
}
|
||||
world = selection.getWorld();
|
||||
regions = plugin.getFileManager().getWERegionsInSelection(selection);
|
||||
regions = Utils.getWERegionsInSelection(selection);
|
||||
if(regions.size() == 0) {
|
||||
plugin.message(player, "cmd-noWERegionsFound");
|
||||
return;
|
@ -4,6 +4,7 @@ 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;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
@ -52,7 +53,7 @@ public class AddfriendCommand extends CommandAreaShop {
|
||||
if(args.length <= 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -73,7 +73,7 @@ public class AddsignCommand extends CommandAreaShop {
|
||||
}
|
||||
} else {
|
||||
// Get region by sign position
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
|
||||
List<GeneralRegion> regions = Utils.getASRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
|
||||
if(regions.isEmpty()) {
|
||||
plugin.message(sender, "addsign-noRegions");
|
||||
return;
|
@ -4,6 +4,7 @@ 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 org.bukkit.command.Command;
|
||||
@ -49,7 +50,7 @@ public class BuyCommand extends CommandAreaShop {
|
||||
}
|
||||
} else {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = plugin.getFileManager().getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
List<BuyRegion> regions = Utils.getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -52,7 +52,7 @@ public class DelCommand extends CommandAreaShop {
|
||||
plugin.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsInSelection(selection);
|
||||
List<GeneralRegion> regions = Utils.getASRegionsInSelection(selection);
|
||||
if(regions == null || regions.size() == 0) {
|
||||
plugin.message(player, "cmd-noRegionsFound");
|
||||
return;
|
@ -4,6 +4,7 @@ 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;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
@ -50,7 +51,7 @@ public class DelfriendCommand extends CommandAreaShop {
|
||||
if(args.length <= 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -59,7 +59,7 @@ public class GroupaddCommand extends CommandAreaShop {
|
||||
plugin.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsInSelection(selection);
|
||||
List<GeneralRegion> regions = Utils.getASRegionsInSelection(selection);
|
||||
if(regions.size() == 0) {
|
||||
plugin.message(player, "cmd-noRegionsFound");
|
||||
return;
|
@ -60,7 +60,7 @@ public class GroupdelCommand extends CommandAreaShop {
|
||||
plugin.message(player, "cmd-noSelection");
|
||||
return;
|
||||
}
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsInSelection(selection);
|
||||
List<GeneralRegion> regions = Utils.getASRegionsInSelection(selection);
|
||||
if(regions.size() == 0) {
|
||||
plugin.message(player, "cmd-noRegionsFound");
|
||||
return;
|
@ -214,7 +214,7 @@ public class InfoCommand extends CommandAreaShop {
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
@ -49,7 +50,7 @@ public class RentCommand extends CommandAreaShop {
|
||||
}
|
||||
} else {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = plugin.getFileManager().getApplicableRentRegions(((Player) sender).getLocation());
|
||||
List<RentRegion> regions = Utils.getApplicableRentRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ 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 org.bukkit.command.Command;
|
||||
@ -53,7 +54,7 @@ public class ResellCommand extends CommandAreaShop {
|
||||
if(args.length <= 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = plugin.getFileManager().getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
List<BuyRegion> regions = Utils.getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ 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 org.bukkit.command.Command;
|
||||
@ -41,7 +42,7 @@ public class SellCommand extends CommandAreaShop {
|
||||
if(args.length <= 1) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = plugin.getFileManager().getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
List<BuyRegion> regions = Utils.getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
@ -47,7 +48,7 @@ public class SetdurationCommand extends CommandAreaShop {
|
||||
if(args.length <= regionArgument) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = plugin.getFileManager().getApplicableRentRegions(((Player) sender).getLocation());
|
||||
List<RentRegion> regions = Utils.getApplicableRentRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -50,7 +51,7 @@ public class SetlandlordCommand extends CommandAreaShop {
|
||||
if(args.length < 3) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
@ -49,7 +50,7 @@ public class SetownerCommand extends CommandAreaShop {
|
||||
if(args.length == 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ 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;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
@ -45,7 +46,7 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
if(args.length < 3) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
@ -89,6 +90,7 @@ public class SetpriceCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "setprice-wrongPrice", args[1]);
|
||||
return;
|
||||
}
|
||||
AreaShop.debug("price: " + price + ", raw: " + args[1]);
|
||||
if(region.isRentRegion()) {
|
||||
((RentRegion)region).setPrice(price);
|
||||
plugin.message(sender, "setprice-successRent", region);
|
@ -43,19 +43,22 @@ public class SetrestoreCommand extends CommandAreaShop {
|
||||
plugin.message(sender, "setrestore-notRegistered", args[1]);
|
||||
return;
|
||||
}
|
||||
String value = null;
|
||||
if(args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("general")) {
|
||||
value = args[2].toLowerCase();
|
||||
} else {
|
||||
plugin.message(sender, "setrestore-invalidSetting", args[2]);
|
||||
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.setRestoreProfile(args[3]);
|
||||
plugin.message(sender, "setrestore-successProfile", region.getName(), value, args[3]);
|
||||
plugin.message(sender, "setrestore-successProfile", region.getName(), valueString, args[3]);
|
||||
} else {
|
||||
plugin.message(sender, "setrestore-success", region.getName(), value);
|
||||
plugin.message(sender, "setrestore-success", region.getName(), valueString);
|
||||
}
|
||||
region.saveRequired();
|
||||
}
|
@ -4,6 +4,7 @@ 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;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
@ -50,7 +51,7 @@ public class SetteleportCommand extends CommandAreaShop {
|
||||
if(args.length < 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -104,11 +104,11 @@ public class StackCommand extends CommandAreaShop {
|
||||
}
|
||||
final Location shift = new Location(selection.getWorld(), 0, 0, 0);
|
||||
if(facing == BlockFace.SOUTH) {
|
||||
shift.setY(-selection.getLength() - gap);
|
||||
shift.setZ(-selection.getLength() - gap);
|
||||
} else if(facing == BlockFace.WEST) {
|
||||
shift.setX(selection.getWidth() + gap);
|
||||
} else if(facing == BlockFace.NORTH) {
|
||||
shift.setY(selection.getLength() + gap);
|
||||
shift.setZ(selection.getLength() + gap);
|
||||
} else if(facing == BlockFace.EAST) {
|
||||
shift.setX(-selection.getWidth() - gap);
|
||||
}
|
@ -4,6 +4,7 @@ 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 org.bukkit.command.Command;
|
||||
@ -42,7 +43,7 @@ public class StopresellCommand extends CommandAreaShop {
|
||||
if(args.length <= 1) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<BuyRegion> regions = plugin.getFileManager().getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
List<BuyRegion> regions = Utils.getApplicableBuyRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
@ -41,7 +42,7 @@ public class UnrentCommand extends CommandAreaShop {
|
||||
if(args.length <= 1) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<RentRegion> regions = plugin.getFileManager().getApplicableRentRegions(((Player) sender).getLocation());
|
||||
List<RentRegion> regions = Utils.getApplicableRentRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
@ -3,6 +3,7 @@ package nl.evolutioncoding.areashop.listeners;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.managers.FileManager.AddResult;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
@ -70,6 +71,7 @@ public final class SignChangeListener implements Listener {
|
||||
|
||||
// If the secondLine does not contain a name try to find the region by location
|
||||
if(secondLine == null || secondLine.length() == 0) {
|
||||
// TODO move to version specific classes or use available method
|
||||
ApplicableRegionSet regions = regionManager.getApplicableRegions(event.getBlock().getLocation());
|
||||
if(regions != null) {
|
||||
boolean first = true;
|
||||
@ -95,8 +97,6 @@ public final class SignChangeListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
boolean priceSet = fourthLine != null && fourthLine.length() != 0;
|
||||
boolean durationSet = thirdLine != null && thirdLine.length() != 0;
|
||||
// check if all the lines are correct
|
||||
@ -307,7 +307,7 @@ public final class SignChangeListener implements Listener {
|
||||
}
|
||||
} else {
|
||||
// Get region by sign position
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsInSelection(new CuboidSelection(event.getBlock().getWorld(), event.getBlock().getLocation(), event.getBlock().getLocation()));
|
||||
List<GeneralRegion> regions = Utils.getASRegionsInSelection(new CuboidSelection(event.getBlock().getWorld(), event.getBlock().getLocation(), event.getBlock().getLocation()));
|
||||
if(regions.isEmpty()) {
|
||||
plugin.message(player, "addsign-noRegions");
|
||||
return;
|
@ -41,10 +41,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
@ -669,7 +665,11 @@ public class FileManager {
|
||||
RegionManager manager = plugin.getWorldGuard().getRegionManager(bukkitWorld);
|
||||
if(manager != null) {
|
||||
try {
|
||||
if(plugin.getWorldGuard().getDescription().getVersion().startsWith("5.")) {
|
||||
manager.save();
|
||||
} else {
|
||||
manager.saveChanges();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
plugin.getLogger().warning("WorldGuard regions in world " + world + " could not be saved");
|
||||
}
|
||||
@ -1350,151 +1350,6 @@ public class FileManager {
|
||||
public void setGroupSetting(RegionGroup group, String path, Object setting) {
|
||||
groupsConfig.set(group.getName().toLowerCase() + "." + path, setting);
|
||||
}
|
||||
|
||||
// UTILITIES
|
||||
/**
|
||||
* Get all AreaShop regions intersecting with a WorldEdit selection
|
||||
* @param selection The selection to check
|
||||
* @return A list with all the AreaShop regions intersecting with the selection
|
||||
*/
|
||||
public List<GeneralRegion> getASRegionsInSelection(Selection selection) {
|
||||
ArrayList<GeneralRegion> result = new ArrayList<GeneralRegion>();
|
||||
for(ProtectedRegion region : getWERegionsInSelection(selection)) {
|
||||
GeneralRegion asRegion = getRegion(region.getId());
|
||||
if(asRegion != null) {
|
||||
result.add(asRegion);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<GeneralRegion> getASRegionsByLocation(Location location) {
|
||||
Selection selection = new CuboidSelection(location.getWorld(), location, location);
|
||||
return getASRegionsInSelection(selection);
|
||||
}
|
||||
|
||||
public List<ProtectedRegion> getWERegionsInSelection(Selection selection) {
|
||||
// Get all regions inside or intersecting with the WorldEdit selection of the player
|
||||
World world = selection.getWorld();
|
||||
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world);
|
||||
ArrayList<ProtectedRegion> result = new ArrayList<ProtectedRegion>();
|
||||
Location selectionMin = selection.getMinimumPoint();
|
||||
Location selectionMax = selection.getMaximumPoint();
|
||||
for(ProtectedRegion region : regionManager.getRegions().values()) {
|
||||
BlockVector regionMin = region.getMinimumPoint();
|
||||
BlockVector regionMax = region.getMaximumPoint();
|
||||
if(
|
||||
( // x part, resolves to true if the selection and region overlap anywhere on the x-axis
|
||||
(regionMin.getBlockX() <= selectionMax.getBlockX() && regionMin.getBlockX() >= selectionMin.getBlockX())
|
||||
|| (regionMax.getBlockX() <= selectionMax.getBlockX() && regionMax.getBlockX() >= selectionMin.getBlockX())
|
||||
|| (selectionMin.getBlockX() >= regionMin.getBlockX() && selectionMin.getBlockX() <= regionMax.getBlockX())
|
||||
|| (selectionMax.getBlockX() >= regionMin.getBlockX() && selectionMax.getBlockX() <= regionMax.getBlockX())
|
||||
) && ( // Y part, resolves to true if the selection and region overlap anywhere on the y-axis
|
||||
(regionMin.getBlockY() <= selectionMax.getBlockY() && regionMin.getBlockY() >= selectionMin.getBlockY())
|
||||
|| (regionMax.getBlockY() <= selectionMax.getBlockY() && regionMax.getBlockY() >= selectionMin.getBlockY())
|
||||
|| (selectionMin.getBlockY() >= regionMin.getBlockY() && selectionMin.getBlockY() <= regionMax.getBlockY())
|
||||
|| (selectionMax.getBlockY() >= regionMin.getBlockY() && selectionMax.getBlockY() <= regionMax.getBlockY())
|
||||
) && ( // Z part, resolves to true if the selection and region overlap anywhere on the z-axis
|
||||
(regionMin.getBlockZ() <= selectionMax.getBlockZ() && regionMin.getBlockZ() >= selectionMin.getBlockZ())
|
||||
|| (regionMax.getBlockZ() <= selectionMax.getBlockZ() && regionMax.getBlockZ() >= selectionMin.getBlockZ())
|
||||
|| (selectionMin.getBlockZ() >= regionMin.getBlockZ() && selectionMin.getBlockZ() <= regionMax.getBlockZ())
|
||||
|| (selectionMax.getBlockZ() >= regionMin.getBlockZ() && selectionMax.getBlockZ() <= regionMax.getBlockZ())
|
||||
)
|
||||
) {
|
||||
result.add(region);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of regions around a location
|
||||
* - Returns highest priority, child instead of parent regions
|
||||
* @param location The location to check for regions
|
||||
* @return empty list if no regions found, 1 member if 1 region is a priority, more if regions with the same priority
|
||||
*/
|
||||
public List<ProtectedRegion> getApplicableRegions(Location location) {
|
||||
List<ProtectedRegion> result = new ArrayList<ProtectedRegion>();
|
||||
// If the secondLine does not contain a name try to find the region by location
|
||||
ApplicableRegionSet regions = plugin.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
|
||||
if(regions != null) {
|
||||
boolean first = true;
|
||||
for(ProtectedRegion pr : regions) {
|
||||
if(first) {
|
||||
result.add(pr);
|
||||
first = false;
|
||||
} else {
|
||||
if(pr.getPriority() > result.get(0).getPriority()) {
|
||||
result.clear();
|
||||
result.add(pr);
|
||||
} else if(pr.getParent() != null && pr.getParent().equals(result.get(0))) {
|
||||
result.clear();
|
||||
result.add(pr);
|
||||
} else {
|
||||
result.add(pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Methods to get the most important AreaShop regions at a certain location
|
||||
public List<RentRegion> getApplicableRentRegions(Location location) {
|
||||
List<RentRegion> result = new ArrayList<RentRegion>();
|
||||
for(GeneralRegion region : getApplicableASRegions(location, RegionType.RENT)) {
|
||||
result.add((RentRegion)region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BuyRegion> getApplicableBuyRegions(Location location) {
|
||||
List<BuyRegion> result = new ArrayList<BuyRegion>();
|
||||
for(GeneralRegion region : getApplicableASRegions(location, RegionType.BUY)) {
|
||||
result.add((BuyRegion)region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<GeneralRegion> getAllApplicableRegions(Location location) {
|
||||
return getApplicableASRegions(location, null);
|
||||
}
|
||||
public List<GeneralRegion> getApplicableASRegions(Location location, RegionType type) {
|
||||
List<GeneralRegion> result = new ArrayList<GeneralRegion>();
|
||||
ApplicableRegionSet regions = plugin.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
|
||||
if(regions != null) {
|
||||
List<GeneralRegion> candidates = new ArrayList<GeneralRegion>();
|
||||
for(ProtectedRegion pr : regions) {
|
||||
GeneralRegion region = getRegion(pr.getId());
|
||||
if(region != null && (
|
||||
(type == RegionType.RENT && region.isRentRegion())
|
||||
|| (type == RegionType.BUY && region.isBuyRegion())
|
||||
|| type == null)) {
|
||||
candidates.add(region);
|
||||
}
|
||||
}
|
||||
boolean first = true;
|
||||
for(GeneralRegion region : candidates) {
|
||||
if(region == null) {
|
||||
AreaShop.debug("skipped null region");
|
||||
continue;
|
||||
}
|
||||
if(first) {
|
||||
result.add(region);
|
||||
first = false;
|
||||
} else {
|
||||
if(region.getRegion().getPriority() > result.get(0).getRegion().getPriority()) {
|
||||
result.clear();
|
||||
result.add(region);
|
||||
} else if(region.getRegion().getParent() != null && region.getRegion().getParent().equals(result.get(0))) {
|
||||
result.clear();
|
||||
result.add(region);
|
||||
} else {
|
||||
result.add(region);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<GeneralRegion>(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class SignLinkerManager implements Listener {
|
||||
BlockIterator blockIterator = new BlockIterator(player, 100);
|
||||
while(blockIterator.hasNext()) {
|
||||
Block next = blockIterator.next();
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getASRegionsByLocation(next.getLocation());
|
||||
List<GeneralRegion> regions = Utils.getASRegionsByLocation(next.getLocation());
|
||||
if(regions.size() == 1) {
|
||||
linker.setRegion(regions.get(0));
|
||||
return;
|
@ -1,10 +1,6 @@
|
||||
package nl.evolutioncoding.areashop.regions;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -19,6 +15,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.Utils;
|
||||
import nl.evolutioncoding.areashop.interfaces.GeneralRegionInterface;
|
||||
import nl.evolutioncoding.areashop.managers.FileManager;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
@ -36,34 +33,16 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
|
||||
import com.sk89q.worldguard.util.io.Closer;
|
||||
|
||||
public abstract class GeneralRegion {
|
||||
public abstract class GeneralRegion implements GeneralRegionInterface {
|
||||
protected YamlConfiguration config;
|
||||
private static ArrayList<Material> canSpawnIn = new ArrayList<Material>(Arrays.asList(Material.WOOD_DOOR, Material.WOODEN_DOOR, Material.SIGN_POST, Material.WALL_SIGN, Material.STONE_PLATE, Material.IRON_DOOR_BLOCK, Material.WOOD_PLATE, Material.TRAP_DOOR, Material.REDSTONE_LAMP_OFF, Material.REDSTONE_LAMP_ON, Material.DRAGON_EGG, Material.GOLD_PLATE, Material.IRON_PLATE));
|
||||
private static ArrayList<Material> cannotSpawnOn = new ArrayList<Material>(Arrays.asList(Material.PISTON_EXTENSION, Material.PISTON_MOVING_PIECE, Material.SIGN_POST, Material.WALL_SIGN, Material.STONE_PLATE, Material.IRON_DOOR_BLOCK, Material.WOOD_PLATE, Material.TRAP_DOOR, Material.REDSTONE_LAMP_OFF, Material.REDSTONE_LAMP_ON, Material.CACTUS, Material.IRON_FENCE, Material.FENCE_GATE, Material.THIN_GLASS, Material.NETHER_FENCE, Material.DRAGON_EGG, Material.GOLD_PLATE, Material.IRON_PLATE, Material.STAINED_GLASS_PANE));
|
||||
@ -857,7 +836,7 @@ public abstract class GeneralRegion {
|
||||
* Change the restore setting
|
||||
* @param restore true, false or general
|
||||
*/
|
||||
public void setRestoreSetting(String restore) {
|
||||
public void setRestoreSetting(Boolean restore) {
|
||||
setSetting("general.enableRestore", restore);
|
||||
}
|
||||
|
||||
@ -883,31 +862,8 @@ public abstract class GeneralRegion {
|
||||
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, save failed");
|
||||
return false;
|
||||
}
|
||||
// Find the correct world wrapper in WorldEdit, seems weird there is no getWorld(String name) method
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if(getWorld() != null) {
|
||||
world = LocalWorldAdapter.adapt(new BukkitWorld(getWorld()));
|
||||
}
|
||||
if(world == null) {
|
||||
plugin.getLogger().warning("Did not save region " + getName() + ", world not found: " + getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = plugin.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, plugin.getConfig().getInt("maximumBlocks"));
|
||||
// The path to save the schematic
|
||||
File saveFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName + AreaShop.schematicExtension);
|
||||
// Create a clipboard
|
||||
CuboidRegion selection = new CuboidRegion(world, region.getMinimumPoint(), region.getMaximumPoint());
|
||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
|
||||
clipboard.setOrigin(region.getMinimumPoint());
|
||||
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, region.getMinimumPoint(), region.getMaximumPoint()), clipboard, region.getMinimumPoint());
|
||||
try {
|
||||
Operations.completeLegacy(copy);
|
||||
} catch (MaxChangedBlocksException e1) {
|
||||
plugin.getLogger().warning("Exeeded the block limit while saving schematic of " + getName());
|
||||
return false;
|
||||
}
|
||||
Closer closer = Closer.create();
|
||||
try {
|
||||
// Create parent directories
|
||||
File parent = saveFile.getParentFile();
|
||||
if (parent != null && !parent.exists()) {
|
||||
@ -916,21 +872,10 @@ public abstract class GeneralRegion {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
FileOutputStream fos = closer.register(new FileOutputStream(saveFile));
|
||||
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
|
||||
ClipboardWriter writer = closer.register(ClipboardFormat.SCHEMATIC.getWriter(bos));
|
||||
writer.write(clipboard, world.getWorldData());
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occured while restoring schematic of " + getName() + ", enable debug to see the complete stacktrace");
|
||||
AreaShop.debug(ExceptionUtils.getStackTrace(e));
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
boolean result = plugin.getWorldEditHandler().saveRegionBlocks(saveFile, this);
|
||||
if(result) {
|
||||
AreaShop.debug("Saved schematic for region " + getName());
|
||||
}
|
||||
}
|
||||
AreaShop.debug("Saved schematic for " + getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -942,67 +887,21 @@ public abstract class GeneralRegion {
|
||||
* @return
|
||||
*/
|
||||
public boolean restoreRegionBlocks(String fileName) {
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if(getWorld() != null) {
|
||||
world = LocalWorldAdapter.adapt(new BukkitWorld(getWorld()));
|
||||
}
|
||||
if(world == null) {
|
||||
plugin.getLogger().info("Did not restore region " + getName() + ", world not found: " + getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = plugin.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, plugin.getConfig().getInt("maximumBlocks"));
|
||||
editSession.enableQueue();
|
||||
ProtectedRegion region = getRegion();
|
||||
if(region == null) {
|
||||
if(getRegion() == null) {
|
||||
AreaShop.debug("Region '" + getName() + "' does not exist in WorldGuard, restore failed");
|
||||
return false;
|
||||
}
|
||||
// Get the origin and size of the region
|
||||
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
|
||||
|
||||
// The path to save the schematic
|
||||
File restoreFile = new File(plugin.getFileManager().getSchematicFolder() + File.separator + fileName + AreaShop.schematicExtension);
|
||||
|
||||
if(!restoreFile.exists() || !restoreFile.isFile()) {
|
||||
plugin.getLogger().info("Did not restore region " + getName() + ", file does not exist: " + restoreFile);
|
||||
plugin.getLogger().info("Did not restore region " + getName() + ", schematic file does not exist: " + restoreFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the schematic and paste it into the world
|
||||
Closer closer = Closer.create();
|
||||
try {
|
||||
FileInputStream fis = closer.register(new FileInputStream(restoreFile));
|
||||
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
|
||||
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis);
|
||||
|
||||
WorldData worldData = world.getWorldData();
|
||||
LocalSession session = new LocalSession(plugin.getWorldEdit().getLocalConfiguration());
|
||||
Clipboard clipboard = reader.read(worldData);
|
||||
clipboard.setOrigin(clipboard.getMinimumPoint());
|
||||
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData);
|
||||
session.setBlockChangeLimit(plugin.getConfig().getInt("maximumBlocks"));
|
||||
session.setClipboard(clipboardHolder);
|
||||
Operation operation = clipboardHolder
|
||||
.createPaste(editSession, editSession.getWorld().getWorldData())
|
||||
.to(origin)
|
||||
.build();
|
||||
Operations.completeLegacy(operation);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
plugin.getLogger().warning("Exeeded the block limit while restoring schematic of " + getName());
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("An error occured while restoring schematic of " + getName() + ", enable debug to see the complete stacktrace");
|
||||
AreaShop.debug(ExceptionUtils.getStackTrace(e));
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
boolean result = plugin.getWorldEditHandler().restoreRegionBlocks(restoreFile, this);
|
||||
if(result) {
|
||||
AreaShop.debug("Restored schematic for region " + getName());
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
AreaShop.debug("Restored schematic for " + getName());
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1103,69 +1002,10 @@ public abstract class GeneralRegion {
|
||||
value = translateBukkitToWorldGuardColors(value);
|
||||
}
|
||||
if(flagName.equalsIgnoreCase("members")) {
|
||||
// Split the string and parse all values
|
||||
String[] names = value.split(", ");
|
||||
DefaultDomain members = region.getMembers();
|
||||
members.removeAll();
|
||||
for(String member : names) {
|
||||
if(member != null && !member.isEmpty()) {
|
||||
// Check for groups
|
||||
if(member.startsWith("g:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addGroup(member.substring(2));
|
||||
}
|
||||
} else if(member.startsWith("n:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addPlayer(member);
|
||||
}
|
||||
} else {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(member);
|
||||
} catch(IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("Tried using '" + member + "' as uuid for a region member, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
members.addPlayer(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setMembers(members);
|
||||
plugin.getWorldGuardHandler().setMembers(region, value);
|
||||
//AreaShop.debug(" Flag " + flagName + " set: " + members.toUserFriendlyString());
|
||||
} else if(flagName.equalsIgnoreCase("owners")) {
|
||||
// Split the string and parse all values
|
||||
String[] names = value.split(", ");
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.removeAll();
|
||||
for(String owner : names) {
|
||||
if(owner != null && !owner.isEmpty()) {
|
||||
// Check for groups
|
||||
if(owner.startsWith("g:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addGroup(owner.substring(2));
|
||||
}
|
||||
} else if(owner.startsWith("n:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addPlayer(owner);
|
||||
}
|
||||
} else {
|
||||
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(owner);
|
||||
} catch(IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("Tried using '" + owner + "' as uuid for a region owner, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
owners.addPlayer(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setOwners(owners);
|
||||
plugin.getWorldGuardHandler().setOwners(region, value);
|
||||
//AreaShop.debug(" Flag " + flagName + " set: " + owners.toUserFriendlyString());
|
||||
} else if(flagName.equalsIgnoreCase("priority")) {
|
||||
try {
|
||||
@ -1731,8 +1571,11 @@ public abstract class GeneralRegion {
|
||||
|
||||
|
||||
// CONFIG
|
||||
public boolean getBooleanSetting(String path) {
|
||||
public boolean getBooleanSetting(String path) { // Handles strings as booleans
|
||||
if(config.isSet(path)) {
|
||||
if(config.isString(path)) {
|
||||
return config.getString(path).equalsIgnoreCase("true");
|
||||
}
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
boolean result = false;
|
||||
@ -1740,7 +1583,11 @@ public abstract class GeneralRegion {
|
||||
boolean found = false;
|
||||
for(RegionGroup group : plugin.getFileManager().getGroups()) {
|
||||
if(group.isMember(this) && group.getSettings().isSet(path) && group.getPriority() > priority) {
|
||||
if(group.getSettings().isString(path)) {
|
||||
result = group.getSettings().getString(path).equalsIgnoreCase("true");
|
||||
} else {
|
||||
result = group.getSettings().getBoolean(path);
|
||||
}
|
||||
priority = group.getPriority();
|
||||
found = true;
|
||||
}
|
||||
@ -1748,6 +1595,10 @@ public abstract class GeneralRegion {
|
||||
if(found) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if(this.getFileManager().getDefaultSettings().isString(path)) {
|
||||
return this.getFileManager().getDefaultSettings().getString(path).equalsIgnoreCase("true");
|
||||
}
|
||||
return this.getFileManager().getDefaultSettings().getBoolean(path);
|
||||
}
|
||||
|
||||
@ -2165,6 +2016,7 @@ public abstract class GeneralRegion {
|
||||
public void handleSchematicEvent(RegionEvent type) {
|
||||
// Check the individual>group>default setting
|
||||
if(!isRestoreEnabled()) {
|
||||
AreaShop.debug("Schematic operations for " + getName() + " not enabled, skipped");
|
||||
return;
|
||||
}
|
||||
// Get the safe and restore names
|
@ -48,7 +48,7 @@ updateRegionsOnStartup: true
|
||||
## Enables / disables debug messages in the console, could be useful to figure out where errors come from
|
||||
debug: false
|
||||
## Version of the config, do not change!
|
||||
version: 2.1.5
|
||||
version: ${project.version}
|
||||
|
||||
|
||||
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
@ -1,6 +1,6 @@
|
||||
name: AreaShop
|
||||
main: nl.evolutioncoding.areashop.AreaShop
|
||||
version: 2.1.5
|
||||
version: ${project.version}
|
||||
depend: [Vault, WorldGuard, WorldEdit]
|
||||
softdepend: [Multiverse-Core]
|
||||
author: NLThijs48
|
1
WorldEdit 5/.gitignore
vendored
Normal file
1
WorldEdit 5/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
48
WorldEdit 5/pom.xml
Normal file
48
WorldEdit 5/pom.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldedit-5</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldEdit 5</name>
|
||||
<version>WorldEdit-5</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.2</version>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>AreaShopInterface</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>5.7-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,93 @@
|
||||
package nl.evolutioncoding.areashop.handlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import nl.evolutioncoding.areashop.interfaces.AreaShopInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.GeneralRegionInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldEditInterface;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
import com.sk89q.worldedit.CuboidClipboard;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.schematic.SchematicFormat;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class WorldEditHandler5 extends WorldEditInterface {
|
||||
|
||||
public WorldEditHandler5(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
boolean result = true;
|
||||
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
// Get the origin and size of the region
|
||||
Vector origin = new Vector(regionInterface.getRegion().getMinimumPoint().getBlockX(), regionInterface.getRegion().getMinimumPoint().getBlockY(), regionInterface.getRegion().getMinimumPoint().getBlockZ());
|
||||
|
||||
editSession.enableQueue();
|
||||
Exception otherException = null;
|
||||
try {
|
||||
CuboidClipboard clipBoard = SchematicFormat.MCEDIT.load(file);
|
||||
if(clipBoard.getHeight() != regionInterface.getHeight()
|
||||
|| clipBoard.getWidth() != regionInterface.getWidth()
|
||||
|| clipBoard.getLength() != regionInterface.getDepth()) {
|
||||
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI("schematic|region, x:" + clipBoard.getWidth() + "|" + regionInterface.getWidth() + ", y:" + clipBoard.getHeight() + "|" + regionInterface.getHeight() + ", z:" + clipBoard.getLength() + "|" + regionInterface.getDepth());
|
||||
}
|
||||
clipBoard.place(editSession, origin, false);
|
||||
} catch(MaxChangedBlocksException e) {
|
||||
pluginInterface.getLogger().warning("Exeeded the block limit while restoring schematic of " + regionInterface.getName());
|
||||
result = false;
|
||||
} catch(DataException e) {
|
||||
otherException = e;
|
||||
} catch(IOException e) {
|
||||
otherException = e;
|
||||
}
|
||||
if(otherException != null) {
|
||||
pluginInterface.getLogger().warning("Failed to restore schematic for region " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
|
||||
result = false;
|
||||
}
|
||||
editSession.flushQueue();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
boolean result = true;
|
||||
ProtectedRegion region = regionInterface.getRegion();
|
||||
// Get the origin and size of the region
|
||||
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
|
||||
Vector size = (new Vector(region.getMaximumPoint().getBlockX(), region.getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockZ()).subtract(origin)).add(new Vector(1,1,1));
|
||||
EditSession editSession = new EditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
// Save the schematic
|
||||
editSession.enableQueue();
|
||||
CuboidClipboard clipboard = new CuboidClipboard(size, origin);
|
||||
clipboard.copy(editSession);
|
||||
Exception otherException = null;
|
||||
try {
|
||||
SchematicFormat.MCEDIT.save(clipboard, file);
|
||||
} catch (DataException e) {
|
||||
otherException = e;
|
||||
} catch (IOException e) {
|
||||
otherException = e;
|
||||
}
|
||||
if(otherException != null) {
|
||||
pluginInterface.getLogger().warning("Failed to save schematic for region " + regionInterface.getName());
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
|
||||
result = false;
|
||||
}
|
||||
editSession.flushQueue();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
1
WorldEdit 6/.gitignore
vendored
Normal file
1
WorldEdit 6/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
48
WorldEdit 6/pom.xml
Normal file
48
WorldEdit 6/pom.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldedit-6</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldEdit 6</name>
|
||||
<version>WorldEdit-6</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.2</version>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>AreaShopInterface</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,163 @@
|
||||
package nl.evolutioncoding.areashop.handlers;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import nl.evolutioncoding.areashop.interfaces.AreaShopInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.GeneralRegionInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldEditInterface;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.io.Closer;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class WorldEditHandler6 extends WorldEditInterface {
|
||||
|
||||
public WorldEditHandler6(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if(regionInterface.getName() != null) {
|
||||
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
|
||||
}
|
||||
if(world == null) {
|
||||
pluginInterface.getLogger().info("Did not restore region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
editSession.enableQueue();
|
||||
ProtectedRegion region = regionInterface.getRegion();
|
||||
// Get the origin and size of the region
|
||||
Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
|
||||
|
||||
// Read the schematic and paste it into the world
|
||||
Closer closer = Closer.create();
|
||||
try {
|
||||
FileInputStream fis = closer.register(new FileInputStream(file));
|
||||
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
|
||||
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(bis);
|
||||
|
||||
WorldData worldData = world.getWorldData();
|
||||
LocalSession session = new LocalSession(pluginInterface.getWorldEdit().getLocalConfiguration());
|
||||
Clipboard clipboard = reader.read(worldData);
|
||||
if(clipboard.getDimensions().getY() != regionInterface.getHeight()
|
||||
|| clipboard.getDimensions().getX() != regionInterface.getWidth()
|
||||
|| clipboard.getDimensions().getZ() != regionInterface.getDepth()) {
|
||||
pluginInterface.getLogger().warning("Size of the region " + regionInterface.getName() + " is not the same as the schematic to restore!");
|
||||
pluginInterface.debugI("schematic|region, x:" + clipboard.getDimensions().getX() + "|" + regionInterface.getWidth() + ", y:" + clipboard.getDimensions().getY() + "|" + regionInterface.getHeight() + ", z:" + clipboard.getDimensions().getZ() + "|" + regionInterface.getDepth());
|
||||
}
|
||||
clipboard.setOrigin(clipboard.getMinimumPoint());
|
||||
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, worldData);
|
||||
session.setBlockChangeLimit(pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
session.setClipboard(clipboardHolder);
|
||||
Operation operation = clipboardHolder
|
||||
.createPaste(editSession, editSession.getWorld().getWorldData())
|
||||
.to(origin)
|
||||
.build();
|
||||
Operations.completeLegacy(operation);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
pluginInterface.getLogger().warning("Exeeded the block limit while restoring schematic of " + regionInterface.getName());
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
pluginInterface.getLogger().warning("An error occured while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
|
||||
// Find the correct world wrapper in WorldEdit, seems weird there is no getWorld(String name) method
|
||||
com.sk89q.worldedit.world.World world = null;
|
||||
if(regionInterface.getWorld() != null) {
|
||||
world = LocalWorldAdapter.adapt(new BukkitWorld(regionInterface.getWorld()));
|
||||
}
|
||||
if(world == null) {
|
||||
pluginInterface.getLogger().warning("Did not save region " + regionInterface.getName() + ", world not found: " + regionInterface.getWorldName());
|
||||
return false;
|
||||
}
|
||||
EditSession editSession = pluginInterface.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(world, pluginInterface.getConfig().getInt("maximumBlocks"));
|
||||
// Create a clipboard
|
||||
CuboidRegion selection = new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint());
|
||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(selection);
|
||||
clipboard.setOrigin(regionInterface.getRegion().getMinimumPoint());
|
||||
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, new CuboidRegion(world, regionInterface.getRegion().getMinimumPoint(), regionInterface.getRegion().getMaximumPoint()), clipboard, regionInterface.getRegion().getMinimumPoint());
|
||||
try {
|
||||
Operations.completeLegacy(copy);
|
||||
} catch (MaxChangedBlocksException e1) {
|
||||
pluginInterface.getLogger().warning("Exeeded the block limit while saving schematic of " + regionInterface.getName());
|
||||
return false;
|
||||
}
|
||||
Closer closer = Closer.create();
|
||||
try {
|
||||
FileOutputStream fos = closer.register(new FileOutputStream(file));
|
||||
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
|
||||
ClipboardWriter writer = closer.register(ClipboardFormat.SCHEMATIC.getWriter(bos));
|
||||
writer.write(clipboard, world.getWorldData());
|
||||
} catch (IOException e) {
|
||||
pluginInterface.getLogger().warning("An error occured while restoring schematic of " + regionInterface.getName() + ", enable debug to see the complete stacktrace");
|
||||
pluginInterface.debugI(ExceptionUtils.getStackTrace(e));
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
1
WorldEditInterface/.gitignore
vendored
Normal file
1
WorldEditInterface/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
42
WorldEditInterface/pom.xml
Normal file
42
WorldEditInterface/pom.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop Interface</name>
|
||||
<version>AreaShopInterface</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,16 @@
|
||||
package nl.evolutioncoding.areashop.interfaces;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
public interface AreaShopInterface {
|
||||
public void debugI(String message);
|
||||
public YamlConfiguration getConfig();
|
||||
public WorldGuardPlugin getWorldGuard();
|
||||
public WorldEditPlugin getWorldEdit();
|
||||
public Logger getLogger();
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package nl.evolutioncoding.areashop.interfaces;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public interface GeneralRegionInterface {
|
||||
public ProtectedRegion getRegion();
|
||||
public String getName();
|
||||
public World getWorld();
|
||||
public String getWorldName();
|
||||
public int getWidth();
|
||||
public int getDepth();
|
||||
public int getHeight();
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package nl.evolutioncoding.areashop.interfaces;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class WorldEditInterface {
|
||||
protected AreaShopInterface pluginInterface;
|
||||
|
||||
public WorldEditInterface(AreaShopInterface pluginInterface) {
|
||||
this.pluginInterface = pluginInterface;
|
||||
}
|
||||
|
||||
// Different way to restore blocks per implementation, newer ones support entities as well
|
||||
public abstract boolean restoreRegionBlocks(File file, GeneralRegionInterface regionInterface);
|
||||
// Different way to save blocks per implementation, newer ones support entities as well
|
||||
public abstract boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package nl.evolutioncoding.areashop.interfaces;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public abstract class WorldGuardInterface {
|
||||
protected AreaShopInterface pluginInterface;
|
||||
|
||||
public WorldGuardInterface(AreaShopInterface pluginInterface) {
|
||||
this.pluginInterface = pluginInterface;
|
||||
}
|
||||
|
||||
// Players set by UUID or name depending on implementation
|
||||
public abstract void setOwners(ProtectedRegion region, String input);
|
||||
// Players set by UUID or name depending on implementation
|
||||
public abstract void setMembers(ProtectedRegion region, String input);
|
||||
// Looping through the ApplicableRegionSet from WorldGuard is different per implementation
|
||||
public abstract Set<ProtectedRegion> getApplicableRegionsSet(Location location);
|
||||
}
|
1
WorldGuard 5/.gitignore
vendored
Normal file
1
WorldGuard 5/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
41
WorldGuard 5/pom.xml
Normal file
41
WorldGuard 5/pom.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldguard-5</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldGuard 5</name>
|
||||
<version>WorldGuard-5</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.2</version>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>AreaShopInterface</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.9.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,108 @@
|
||||
package nl.evolutioncoding.areashop.handlers;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import nl.evolutioncoding.areashop.interfaces.AreaShopInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldGuardInterface;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class WorldGuardHandler5 extends WorldGuardInterface {
|
||||
|
||||
public WorldGuardHandler5(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
public void setOwners(ProtectedRegion region, String input) {
|
||||
// Split the string and parse all values
|
||||
String[] names = input.split(", ");
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.removeAll();
|
||||
for(String owner : names) {
|
||||
if(owner != null && !owner.isEmpty()) {
|
||||
// Check for groups
|
||||
if(owner.startsWith("g:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addGroup(owner.substring(2));
|
||||
}
|
||||
} else if(owner.startsWith("n:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addPlayer(owner);
|
||||
}
|
||||
} else {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(owner);
|
||||
} catch(IllegalArgumentException e) {
|
||||
System.out.println("Tried using '" + owner + "' as uuid for a region owner, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if(offlinePlayer != null && offlinePlayer.getName() != null) {
|
||||
owners.addPlayer(offlinePlayer.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setOwners(owners);
|
||||
//System.out.println(" Flag " + flagName + " set: " + owners.toUserFriendlyString());
|
||||
}
|
||||
|
||||
public void setMembers(ProtectedRegion region, String input) {
|
||||
// Split the string and parse all values
|
||||
String[] names = input.split(", ");
|
||||
DefaultDomain members = region.getMembers();
|
||||
members.removeAll();
|
||||
for(String member : names) {
|
||||
if(member != null && !member.isEmpty()) {
|
||||
// Check for groups
|
||||
if(member.startsWith("g:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addGroup(member.substring(2));
|
||||
}
|
||||
} else if(member.startsWith("n:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addPlayer(member);
|
||||
}
|
||||
} else {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(member);
|
||||
} catch(IllegalArgumentException e) {
|
||||
System.out.println("Tried using '" + member + "' as uuid for a region member, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if(offlinePlayer != null && offlinePlayer.getName() != null) {
|
||||
members.addPlayer(offlinePlayer.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setMembers(members);
|
||||
//System.out.println(" Flag " + flagName + " set: " + members.toUserFriendlyString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
|
||||
Set<ProtectedRegion> result = new HashSet<ProtectedRegion>();
|
||||
ApplicableRegionSet regions = pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
|
||||
for(ProtectedRegion region : regions) {
|
||||
result.add(region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
1
WorldGuard 6/.gitignore
vendored
Normal file
1
WorldGuard 6/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
41
WorldGuard 6/pom.xml
Normal file
41
WorldGuard 6/pom.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldguard-6</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldGuard 6</name>
|
||||
<version>WorldGuard-6</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.2</version>
|
||||
<type>jar</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-interface</artifactId>
|
||||
<version>AreaShopInterface</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,102 @@
|
||||
package nl.evolutioncoding.areashop.handlers;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import nl.evolutioncoding.areashop.interfaces.AreaShopInterface;
|
||||
import nl.evolutioncoding.areashop.interfaces.WorldGuardInterface;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
public class WorldGuardHandler6 extends WorldGuardInterface {
|
||||
|
||||
public WorldGuardHandler6(AreaShopInterface pluginInterface) {
|
||||
super(pluginInterface);
|
||||
}
|
||||
|
||||
public void setOwners(ProtectedRegion region, String input) {
|
||||
// Split the string and parse all values
|
||||
String[] names = input.split(", ");
|
||||
DefaultDomain owners = region.getOwners();
|
||||
owners.removeAll();
|
||||
for(String owner : names) {
|
||||
if(owner != null && !owner.isEmpty()) {
|
||||
// Check for groups
|
||||
if(owner.startsWith("g:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addGroup(owner.substring(2));
|
||||
}
|
||||
} else if(owner.startsWith("n:")) {
|
||||
if(owner.length() > 2) {
|
||||
owners.addPlayer(owner);
|
||||
}
|
||||
} else {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(owner);
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Don't like this but cannot access main plugin class from this module...
|
||||
System.out.println("[AreaShop] Tried using '" + owner + "' as uuid for a region owner, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
owners.addPlayer(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setOwners(owners);
|
||||
//System.out.println(" Flag " + flagName + " set: " + owners.toUserFriendlyString());
|
||||
}
|
||||
|
||||
public void setMembers(ProtectedRegion region, String input) {
|
||||
// Split the string and parse all values
|
||||
String[] names = input.split(", ");
|
||||
DefaultDomain members = region.getMembers();
|
||||
members.removeAll();
|
||||
for(String member : names) {
|
||||
if(member != null && !member.isEmpty()) {
|
||||
// Check for groups
|
||||
if(member.startsWith("g:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addGroup(member.substring(2));
|
||||
}
|
||||
} else if(member.startsWith("n:")) {
|
||||
if(member.length() > 2) {
|
||||
members.addPlayer(member);
|
||||
}
|
||||
} else {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(member);
|
||||
} catch(IllegalArgumentException e) {
|
||||
// Don't like this but cannot access main plugin class from this module...
|
||||
System.out.println("[AreaShop] Tried using '" + member + "' as uuid for a region member, is your flagProfiles section correct?");
|
||||
uuid = null;
|
||||
}
|
||||
if(uuid != null) {
|
||||
members.addPlayer(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.setMembers(members);
|
||||
//System.out.println(" Flag " + flagName + " set: " + members.toUserFriendlyString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
|
||||
Set<ProtectedRegion> result = new HashSet<ProtectedRegion>();
|
||||
ApplicableRegionSet regions = pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
|
||||
for(ProtectedRegion region : regions) {
|
||||
result.add(region);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
1
WorldGuardInterface/.gitignore
vendored
Normal file
1
WorldGuardInterface/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
35
WorldGuardInterface/pom.xml
Normal file
35
WorldGuardInterface/pom.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>areashop-worldguard-interface</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>AreaShop WorldGuard Interface</name>
|
||||
<version>WorldGuardInterface</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
40
pom.xml
Normal file
40
pom.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.evolutioncoding</groupId>
|
||||
<artifactId>areashop-parent</artifactId>
|
||||
<!-- Artifact ID doesn't matter for anything but the final product
|
||||
At least, it doesn't matter externally to this setup -->
|
||||
<packaging>pom</packaging>
|
||||
<!-- Packaging? POM -->
|
||||
<version>parent</version>
|
||||
<!-- I keep my versions of the internal projects static, so I don't have to rename them all the time. -->
|
||||
<name>AreaShop Parent</name>
|
||||
<url>http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>WorldGuard 5</module>
|
||||
<module>WorldGuard 6</module>
|
||||
<module>WorldGuardInterface</module>
|
||||
<module>WorldEdit 5</module>
|
||||
<module>WorldEdit 6</module>
|
||||
<module>WorldEditInterface</module>
|
||||
<module>AreaShop</module>
|
||||
</modules>
|
||||
|
||||
<!-- Define the repo here since multiple modules will be using it -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo-wg</id>
|
||||
<url>http://maven.sk89q.com/artifactory/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@ -1,107 +0,0 @@
|
||||
package nl.evolutioncoding.areashop;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class Utils {
|
||||
|
||||
// Not used
|
||||
private Utils() {}
|
||||
|
||||
|
||||
/**
|
||||
* Create a map from a location, to save it in the config
|
||||
* @param location The location to transform
|
||||
* @return The map with the location values
|
||||
*/
|
||||
public static ConfigurationSection locationToConfig(Location location, boolean setPitchYaw) {
|
||||
if(location == null) {
|
||||
return null;
|
||||
}
|
||||
ConfigurationSection result = new YamlConfiguration();
|
||||
result.set("world", location.getWorld().getName());
|
||||
result.set("x", location.getX());
|
||||
result.set("y", location.getY());
|
||||
result.set("z", location.getZ());
|
||||
if(setPitchYaw) {
|
||||
result.set("yaw", Float.toString(location.getYaw()));
|
||||
result.set("pitch", Float.toString(location.getPitch()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static ConfigurationSection locationToConfig(Location location) {
|
||||
return locationToConfig(location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a location from a map, reconstruction from the config values
|
||||
* @param map The map to reconstruct from
|
||||
* @return The location
|
||||
*/
|
||||
public static Location configToLocation(ConfigurationSection config) {
|
||||
if(config == null
|
||||
|| !config.isString("world")
|
||||
|| !config.isDouble("x")
|
||||
|| !config.isDouble("y")
|
||||
|| !config.isDouble("z")) {
|
||||
return null;
|
||||
}
|
||||
Location result = new Location(
|
||||
Bukkit.getWorld(config.getString("world")),
|
||||
(Double)config.getDouble("x"),
|
||||
(Double)config.getDouble("y"),
|
||||
(Double)config.getDouble("z"));
|
||||
if(config.isString("yaw") && config.isString("pitch")) {
|
||||
result.setPitch(Float.parseFloat(config.getString("pitch")));
|
||||
result.setYaw(Float.parseFloat(config.getString("yaw")));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String createCommaSeparatedList(Collection<? extends Object> input) {
|
||||
String result = "";
|
||||
boolean first = true;
|
||||
for(Object object : input) {
|
||||
if(object != null) {
|
||||
if(first) {
|
||||
first = false;
|
||||
result += object.toString();
|
||||
} else {
|
||||
result += ", " + object.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user