Cleanup code, fix some small bugs

Most of these things have been found with help of Intellij IDEA, preferring it over Eclipse already
This commit is contained in:
Thijs Wiefferink 2015-11-15 23:30:45 +01:00
parent b04871c553
commit 872d81b0a9
53 changed files with 769 additions and 1095 deletions

5
.gitignore vendored
View File

@ -25,4 +25,7 @@ local.properties
.cproject
# PDT-specific
.buildpath
.buildpath
# IntelliJ IDEA
*.iml

View File

@ -31,22 +31,6 @@
<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>
@ -55,22 +39,6 @@
<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>
@ -148,9 +116,6 @@
<goals>
<goal>run</goal>
</goals>
<configuration>
<target failonerror="false"></target>
</configuration>
</execution>
</executions>
</plugin>

View File

@ -1,12 +1,7 @@
package nl.evolutioncoding.areashop;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.UUID;
import java.util.logging.Logger;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import net.milkbowl.vault.economy.Economy;
import nl.evolutioncoding.areashop.Updater.UpdateResult;
import nl.evolutioncoding.areashop.Updater.UpdateType;
@ -22,7 +17,6 @@ import nl.evolutioncoding.areashop.managers.FileManager;
import nl.evolutioncoding.areashop.managers.LanguageManager;
import nl.evolutioncoding.areashop.managers.SignLinkerManager;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -35,8 +29,12 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.UUID;
import java.util.logging.Logger;
/**
* Main class for the AreaShop plugin
@ -387,7 +385,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
/**
* Get the current chatPrefix
* @return
* @return The current chatPrefix
*/
public String getChatPrefix() {
return chatprefix;
@ -694,7 +692,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
/* Check if the suffix is one of these values */
String suffix = time.substring(time.indexOf(' ')+1, time.length());
ArrayList<String> identifiers = new ArrayList<String>();
ArrayList<String> identifiers = new ArrayList<>();
identifiers.addAll(this.getConfig().getStringList("seconds"));
identifiers.addAll(this.getConfig().getStringList("minutes"));
identifiers.addAll(this.getConfig().getStringList("hours"));
@ -727,19 +725,21 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(0);
ArrayList<String> seconds = new ArrayList<String>(this.getConfig().getStringList("seconds"));
ArrayList<String> minutes = new ArrayList<String>(this.getConfig().getStringList("minutes"));
ArrayList<String> hours = new ArrayList<String>(this.getConfig().getStringList("hours"));
ArrayList<String> days = new ArrayList<String>(this.getConfig().getStringList("days"));
ArrayList<String> weeks = new ArrayList<String>(this.getConfig().getStringList("weeks"));
ArrayList<String> months = new ArrayList<String>(this.getConfig().getStringList("months"));
ArrayList<String> years = new ArrayList<String>(this.getConfig().getStringList("years"));
ArrayList<String> seconds = new ArrayList<>(this.getConfig().getStringList("seconds"));
ArrayList<String> minutes = new ArrayList<>(this.getConfig().getStringList("minutes"));
ArrayList<String> hours = new ArrayList<>(this.getConfig().getStringList("hours"));
ArrayList<String> days = new ArrayList<>(this.getConfig().getStringList("days"));
ArrayList<String> weeks = new ArrayList<>(this.getConfig().getStringList("weeks"));
ArrayList<String> months = new ArrayList<>(this.getConfig().getStringList("months"));
ArrayList<String> years = new ArrayList<>(this.getConfig().getStringList("years"));
String durationString = duration.substring(duration.indexOf(' ')+1, duration.length());
int durationInt = 0;
try {
durationInt = Integer.parseInt(duration.substring(0, duration.indexOf(' ')));
} catch(NumberFormatException exception) {}
} catch(NumberFormatException exception) {
// No Number found, add zero
}
if(seconds.contains(durationString)) {
calendar.add(Calendar.SECOND, durationInt);
@ -874,18 +874,16 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
* @return the name of the player
*/
public String toName(String uuid) {
if(uuid == null) {
return "";
} else {
UUID parsed = null;
String result = "";
if(uuid != null) {
try {
parsed = UUID.fromString(uuid);
} catch(IllegalArgumentException e) {}
if(parsed == null) {
return "";
UUID parsed = UUID.fromString(uuid);
result = this.toName(parsed);
} catch(IllegalArgumentException e) {
// Incorrect UUID
}
return this.toName(parsed);
}
return result;
}
/**
* Conversion to name by uuid object

View File

@ -34,23 +34,12 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
@ -628,7 +617,7 @@ public class Metrics {
/**
* The set of plotters that are contained within this graph
*/
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
private final Set<Plotter> plotters = new LinkedHashSet<>();
private Graph(final String name) {
this.name = name;

View File

@ -1,15 +1,14 @@
package nl.evolutioncoding.areashop;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
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;
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;
@ -17,11 +16,10 @@ 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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class Utils {
@ -55,7 +53,7 @@ public class Utils {
/**
* Create a location from a map, reconstruction from the config values
* @param map The map to reconstruct from
* @param config The config section to reconstruct from
* @return The location
*/
public static Location configToLocation(ConfigurationSection config) {
@ -68,10 +66,10 @@ public class Utils {
return null;
}
Location result = new Location(
Bukkit.getWorld(config.getString("world")),
(Double)config.getDouble("x"),
(Double)config.getDouble("y"),
(Double)config.getDouble("z"));
Bukkit.getWorld(config.getString("world")),
config.getDouble("x"),
config.getDouble("y"),
config.getDouble("z"));
if(config.isString("yaw") && config.isString("pitch")) {
result.setPitch(Float.parseFloat(config.getString("pitch")));
result.setYaw(Float.parseFloat(config.getString("yaw")));
@ -84,7 +82,7 @@ public class Utils {
* @param input Collection of object which should be concatenated with comma's in between
* @return Innput object concatenated with comma's in between
*/
public static String createCommaSeparatedList(Collection<? extends Object> input) {
public static String createCommaSeparatedList(Collection<?> input) {
String result = "";
boolean first = true;
for(Object object : input) {
@ -108,9 +106,10 @@ public class Utils {
public static long millisToTicks(long milliseconds) {
return milliseconds/50;
}
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 };
/**
private 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
@ -128,7 +127,7 @@ public class Utils {
* @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>();
ArrayList<GeneralRegion> result = new ArrayList<>();
for(ProtectedRegion region : getWERegionsInSelection(selection)) {
GeneralRegion asRegion = AreaShop.getInstance().getFileManager().getRegion(region.getId());
if(asRegion != null) {
@ -156,7 +155,7 @@ public class Utils {
// 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>();
ArrayList<ProtectedRegion> result = new ArrayList<>();
Location selectionMin = selection.getMinimumPoint();
Location selectionMax = selection.getMaximumPoint();
for(ProtectedRegion region : regionManager.getRegions().values()) {
@ -193,7 +192,7 @@ public class Utils {
* @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>();
List<ProtectedRegion> result = new ArrayList<>();
Set<ProtectedRegion> regions = AreaShop.getInstance().getWorldGuardHandler().getApplicableRegionsSet(location);
if(regions != null) {
boolean first = true;
@ -219,14 +218,14 @@ public class Utils {
// 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>();
List<RentRegion> result = new ArrayList<>();
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>();
List<BuyRegion> result = new ArrayList<>();
for(GeneralRegion region : getApplicableASRegions(location, RegionType.BUY)) {
result.add((BuyRegion)region);
}
@ -236,10 +235,10 @@ public class Utils {
return getApplicableASRegions(location, null);
}
public static List<GeneralRegion> getApplicableASRegions(Location location, RegionType type) {
List<GeneralRegion> result = new ArrayList<GeneralRegion>();
List<GeneralRegion> result = new ArrayList<>();
Set<ProtectedRegion> regions = AreaShop.getInstance().getWorldGuardHandler().getApplicableRegionsSet(location);
if(regions != null) {
List<GeneralRegion> candidates = new ArrayList<GeneralRegion>();
List<GeneralRegion> candidates = new ArrayList<>();
for(ProtectedRegion pr : regions) {
GeneralRegion region = AreaShop.getInstance().getFileManager().getRegion(pr.getId());
if(region != null && (
@ -262,7 +261,7 @@ public class Utils {
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))) {
} else if(region.getRegion().getParent() != null && region.getRegion().getParent().equals(result.get(0).getRegion())) {
result.clear();
result.add(region);
} else {
@ -271,7 +270,7 @@ public class Utils {
}
}
}
return new ArrayList<GeneralRegion>(result);
return new ArrayList<>(result);
}
}

View File

@ -1,8 +1,7 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.managers.FileManager.AddResult;
@ -10,16 +9,14 @@ import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.ArrayList;
import java.util.List;
public class AddCommand extends CommandAreaShop {
@ -41,7 +38,7 @@ public class AddCommand extends CommandAreaShop {
}
@Override
public void execute(final CommandSender sender, Command command, final String[] args) {
public void execute(final CommandSender sender, final String[] args) {
if( !sender.hasPermission("areashop.createrent")
&& !sender.hasPermission("areashop.createrent.member")
&& !sender.hasPermission("areashop.createrent.owner")
@ -57,8 +54,8 @@ public class AddCommand extends CommandAreaShop {
plugin.message(sender, "add-help");
return;
}
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>();
World world = null;
List<ProtectedRegion> regions = new ArrayList<>();
World world;
Player player = null;
if(sender instanceof Player) {
player = (Player)sender;
@ -116,10 +113,10 @@ public class AddCommand extends CommandAreaShop {
AreaShop.debug("Starting add task with " + regions.size() + " regions");
new BukkitRunnable() {
private int current = 0;
private ArrayList<String> namesSuccess = new ArrayList<String>();
private ArrayList<String> namesAlready = new ArrayList<String>();
private ArrayList<String> namesBlacklisted = new ArrayList<String>();
private ArrayList<String> namesNoPermission = new ArrayList<String>();
private ArrayList<String> namesSuccess = new ArrayList<>();
private ArrayList<String> namesAlready = new ArrayList<>();
private ArrayList<String> namesBlacklisted = new ArrayList<>();
private ArrayList<String> namesNoPermission = new ArrayList<>();
@Override
public void run() {
@ -128,8 +125,8 @@ public class AddCommand extends CommandAreaShop {
ProtectedRegion region = finalRegions.get(current);
// Determine if the player is an owner or member of the region
boolean isMember = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
String type = null;
boolean isOwner = finalPlayer != null && plugin.getWorldGuardHandler().containsMember(region, finalPlayer.getUniqueId());
String type;
if(isRent) {
type = "rent";
} else {
@ -205,7 +202,7 @@ public class AddCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
if(sender.hasPermission("areashop.createrent")) {
result.add("rent");

View File

@ -1,20 +1,18 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class AddfriendCommand extends CommandAreaShop {
public AddfriendCommand(AreaShop plugin) {
@ -38,7 +36,7 @@ public class AddfriendCommand extends CommandAreaShop {
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.addfriend") && !sender.hasPermission("areashop.addfriendall")) {
plugin.message(sender, "addfriend-noPermission");
return;
@ -48,8 +46,8 @@ public class AddfriendCommand extends CommandAreaShop {
plugin.message(sender, "addfriend-help");
return;
}
GeneralRegion region = null;
GeneralRegion region;
if(args.length <= 2) {
if (sender instanceof Player) {
// get the region by location
@ -128,7 +126,7 @@ public class AddfriendCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Bukkit.getOnlinePlayers()) {
result.add(player.getName());

View File

@ -1,22 +1,19 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.material.Sign;
import org.bukkit.util.BlockIterator;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class AddsignCommand extends CommandAreaShop {
@ -38,7 +35,7 @@ public class AddsignCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.addsign")) {
plugin.message(sender, "addsign-noPermission");
return;
@ -63,7 +60,7 @@ public class AddsignCommand extends CommandAreaShop {
return;
}
GeneralRegion region = null;
GeneralRegion region;
if(args.length > 1) {
// Get region by argument
region = plugin.getFileManager().getRegion(args[1]);
@ -110,7 +107,7 @@ public class AddsignCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class BuyCommand extends CommandAreaShop {
public BuyCommand(AreaShop plugin) {
@ -31,7 +29,7 @@ public class BuyCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.buy")) {
plugin.message(sender, "buy-noPermission");
return;
@ -53,10 +51,8 @@ public class BuyCommand extends CommandAreaShop {
List<BuyRegion> regions = Utils.getApplicableBuyRegions(((Player) sender).getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
regions.get(0).buy(player);
}
@ -65,7 +61,7 @@ public class BuyCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(!region.isSold()) {

View File

@ -1,12 +1,12 @@
package nl.evolutioncoding.areashop.commands;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract class for generalising command classes
*/
@ -38,11 +38,13 @@ public abstract class CommandAreaShop {
* @param start The already given start of the command
* @return A collection with all the possibilities for argument to complete
*/
public abstract List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender);
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
return new ArrayList<>();
}
/**
* Get the argument that comes after the base command that this command reacts to
* @return
* @return The string that should be in front of the command for this class to act
*/
public abstract String getCommandStart();
@ -56,10 +58,9 @@ public abstract class CommandAreaShop {
/**
* Execute a (sub)command if the conditions are met
* @param sender The commandSender that executed the command
* @param commandAreaShop The command that has been executed
* @param args The arguments that are given
*/
public abstract void execute(CommandSender sender, Command command, String[] args);
public abstract void execute(CommandSender sender, String[] args);

View File

@ -1,19 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.bukkit.selections.Selection;
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;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.bukkit.selections.Selection;
import java.util.ArrayList;
import java.util.List;
public class DelCommand extends CommandAreaShop {
@ -35,7 +32,7 @@ public class DelCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if( !sender.hasPermission("areashop.destroybuy")
&& !sender.hasPermission("areashop.destroybuy.landlord")
@ -62,10 +59,10 @@ public class DelCommand extends CommandAreaShop {
return;
}
// Start removing the region that he has permission for
ArrayList<String> namesSuccess = new ArrayList<String>();
ArrayList<String> namesFailed = new ArrayList<String>();
ArrayList<String> namesSuccess = new ArrayList<>();
ArrayList<String> namesFailed = new ArrayList<>();
for(GeneralRegion region : regions) {
boolean isLandlord = sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId());
boolean isLandlord = region.isLandlord(((Player)sender).getUniqueId());
if(region.isRentRegion()) {
if(!sender.hasPermission("areashop.destroyrent") && !(isLandlord && sender.hasPermission("areashop.destroyrent.landlord"))) {
namesFailed.add(region.getName());
@ -118,7 +115,7 @@ public class DelCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getRegionNames();
}

View File

@ -1,20 +1,18 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class DelfriendCommand extends CommandAreaShop {
public DelfriendCommand(AreaShop plugin) {
@ -38,7 +36,7 @@ public class DelfriendCommand extends CommandAreaShop {
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
plugin.message(sender, "delfriend-noPermission");
return;
@ -46,8 +44,8 @@ public class DelfriendCommand extends CommandAreaShop {
if(args.length < 2) {
plugin.message(sender, "delfriend-help");
return;
}
GeneralRegion region = null;
}
GeneralRegion region;
if(args.length <= 2) {
if (sender instanceof Player) {
// get the region by location
@ -110,7 +108,7 @@ public class DelfriendCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Bukkit.getOnlinePlayers()) {
result.add(player.getName());

View File

@ -1,18 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import java.util.ArrayList;
import java.util.List;
public class DelsignCommand extends CommandAreaShop {
public DelsignCommand(AreaShop plugin) {
@ -33,7 +31,7 @@ public class DelsignCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.delsign")) {
plugin.message(sender, "delsign-noPermission");
return;
@ -69,7 +67,7 @@ public class DelsignCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
return new ArrayList<String>();
return new ArrayList<>();
}
}

View File

@ -1,18 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class FindCommand extends CommandAreaShop {
public FindCommand(AreaShop plugin) {
@ -33,7 +31,7 @@ public class FindCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.find")) {
plugin.message(sender, "find-noPermission");
return;
@ -74,7 +72,7 @@ public class FindCommand extends CommandAreaShop {
}
if(args[1].equalsIgnoreCase("buy")) {
List<BuyRegion> regions = plugin.getFileManager().getBuys();
List<BuyRegion> results = new ArrayList<BuyRegion>();
List<BuyRegion> results = new ArrayList<>();
for(BuyRegion region : regions) {
if(!region.isSold()
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
@ -108,7 +106,7 @@ public class FindCommand extends CommandAreaShop {
}
} else {
List<RentRegion> regions = plugin.getFileManager().getRents();
List<RentRegion> results = new ArrayList<RentRegion>();
List<RentRegion> results = new ArrayList<>();
for(RentRegion region : regions) {
if(!region.isRented()
&& ((region.getPrice() <= balance && !maxPriceSet) || (region.getPrice() <= maxPrice && maxPriceSet))
@ -146,7 +144,7 @@ public class FindCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
result.add("buy");
result.add("rent");

View File

@ -1,18 +1,15 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.bukkit.selections.Selection;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.bukkit.selections.Selection;
import java.util.ArrayList;
import java.util.List;
public class GroupaddCommand extends CommandAreaShop {
@ -34,7 +31,7 @@ public class GroupaddCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.groupadd")) {
plugin.message(sender, "groupadd-noPermission");
return;
@ -63,10 +60,10 @@ public class GroupaddCommand extends CommandAreaShop {
if(regions.size() == 0) {
plugin.message(player, "cmd-noRegionsFound");
return;
}
ArrayList<String> namesSuccess = new ArrayList<String>();
ArrayList<String> namesFailed = new ArrayList<String>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<GeneralRegion>();
}
ArrayList<String> namesSuccess = new ArrayList<>();
ArrayList<String> namesFailed = new ArrayList<>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<>();
for(GeneralRegion region : regions) {
if(group.addMember(region)) {
namesSuccess.add(region.getName());
@ -101,7 +98,7 @@ public class GroupaddCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getGroupNames();
} else if(toComplete == 3) {

View File

@ -1,18 +1,15 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.bukkit.selections.Selection;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.bukkit.selections.Selection;
import java.util.ArrayList;
import java.util.List;
public class GroupdelCommand extends CommandAreaShop {
@ -34,7 +31,7 @@ public class GroupdelCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.groupdel")) {
plugin.message(sender, "groupdel-noPermission");
return;
@ -63,10 +60,10 @@ public class GroupdelCommand extends CommandAreaShop {
if(regions.size() == 0) {
plugin.message(player, "cmd-noRegionsFound");
return;
}
ArrayList<String> namesSuccess = new ArrayList<String>();
ArrayList<String> namesFailed = new ArrayList<String>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<GeneralRegion>();
}
ArrayList<String> namesSuccess = new ArrayList<>();
ArrayList<String> namesFailed = new ArrayList<>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<>();
for(GeneralRegion region : regions) {
if(group.removeMember(region)) {
namesSuccess.add(region.getName());
@ -102,7 +99,7 @@ public class GroupdelCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getGroupNames();
} else if(toComplete == 3) {

View File

@ -1,15 +1,13 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
public class GroupinfoCommand extends CommandAreaShop {
public GroupinfoCommand(AreaShop plugin) {
@ -31,7 +29,7 @@ public class GroupinfoCommand extends CommandAreaShop {
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.groupinfo")) {
plugin.message(sender, "groupinfo-noPermission");
return;
@ -55,7 +53,7 @@ public class GroupinfoCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getGroupNames();
}

View File

@ -1,14 +1,12 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
public class GrouplistCommand extends CommandAreaShop {
public GrouplistCommand(AreaShop plugin) {
@ -29,7 +27,7 @@ public class GrouplistCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.grouplist")) {
plugin.message(sender, "grouplist-noPermission");
return;
@ -44,7 +42,7 @@ public class GrouplistCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
return new ArrayList<String>();
return new ArrayList<>();
}
}

View File

@ -1,11 +1,6 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class HelpCommand extends CommandAreaShop {
@ -28,14 +23,7 @@ public class HelpCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
plugin.getCommandManager().showHelp(sender);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
return result;
}
}

View File

@ -1,28 +1,19 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
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.RegionGroup;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
public class InfoCommand extends CommandAreaShop {
public InfoCommand(AreaShop plugin) {
@ -50,7 +41,7 @@ public class InfoCommand extends CommandAreaShop {
* @param keySomeFound The key of the message to display when some regions are found
* @param keyNoneFound The key of the message to display when no regions are found
*/
public void displayMessage(CommandSender sender, Set<? extends GeneralRegion> regions, RegionGroup filterGroup, String keySomeFound, String keyNoneFound) {
private void displayMessage(CommandSender sender, Set<? extends GeneralRegion> regions, RegionGroup filterGroup, String keySomeFound, String keyNoneFound) {
if(filterGroup != null) {
Iterator<? extends GeneralRegion> it = regions.iterator();
while(it.hasNext()) {
@ -68,7 +59,7 @@ public class InfoCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.info")) {
plugin.message(sender, "info-noPermission");
return;
@ -76,7 +67,7 @@ public class InfoCommand extends CommandAreaShop {
if(args.length > 1 && args[1] != null) {
// Get filter group (only used by some commands)
RegionGroup filterGroup = null;
Set<String> groupFilters = new HashSet<String>(Arrays.asList("all", "rented", "forrent", "sold", "forsale"));
Set<String> groupFilters = new HashSet<>(Arrays.asList("all", "rented", "forrent", "sold", "forsale"));
if(groupFilters.contains(args[0].toLowerCase())) {
filterGroup = plugin.getFileManager().getGroup(args[2]);
if(filterGroup == null) {
@ -96,7 +87,7 @@ public class InfoCommand extends CommandAreaShop {
// Rented regions
else if(args[1].equalsIgnoreCase("rented")) {
Set<GeneralRegion> regions = new TreeSet<GeneralRegion>();
Set<GeneralRegion> regions = new TreeSet<>();
for(RentRegion region : plugin.getFileManager().getRents()) {
if(region.isRented()) {
regions.add(region);
@ -106,7 +97,7 @@ public class InfoCommand extends CommandAreaShop {
}
// Forrent regions
else if(args[1].equalsIgnoreCase("forrent")) {
Set<GeneralRegion> regions = new TreeSet<GeneralRegion>();
Set<GeneralRegion> regions = new TreeSet<>();
for(RentRegion region : plugin.getFileManager().getRents()) {
if(!region.isRented()) {
regions.add(region);
@ -116,7 +107,7 @@ public class InfoCommand extends CommandAreaShop {
}
// Sold regions
else if(args[1].equalsIgnoreCase("sold")) {
Set<GeneralRegion> regions = new TreeSet<GeneralRegion>();
Set<GeneralRegion> regions = new TreeSet<>();
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isSold()) {
regions.add(region);
@ -126,7 +117,7 @@ public class InfoCommand extends CommandAreaShop {
}
// Forsale regions
else if(args[1].equalsIgnoreCase("forsale")) {
Set<GeneralRegion> regions = new TreeSet<GeneralRegion>();
Set<GeneralRegion> regions = new TreeSet<>();
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(!region.isSold()) {
regions.add(region);
@ -138,7 +129,7 @@ public class InfoCommand extends CommandAreaShop {
else if(args[1].equalsIgnoreCase("player")) {
if(args.length > 2 && args[2] != null) {
// Rents
Set<GeneralRegion> regions = new TreeSet<GeneralRegion>();
Set<GeneralRegion> regions = new TreeSet<>();
for(RentRegion region : plugin.getFileManager().getRents()) {
if(region.isRented() && region.getPlayerName().equalsIgnoreCase(args[2])) {
regions.add(region);
@ -150,7 +141,7 @@ public class InfoCommand extends CommandAreaShop {
plugin.message(sender, "info-playerRents", args[2], StringUtils.join(regions.iterator(), ", "));
}
// Buys
regions = new TreeSet<GeneralRegion>();
regions = new TreeSet<>();
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isSold() && region.getPlayerName().equalsIgnoreCase(args[2])) {
regions.add(region);
@ -243,7 +234,7 @@ public class InfoCommand extends CommandAreaShop {
plugin.messageNoPrefix(sender, "info-regionTeleportAt", rent, teleport.getWorld().getName(), teleport.getBlockX(), teleport.getBlockY(), teleport.getBlockZ(), (int)teleport.getPitch(), (int)teleport.getYaw());
}
}
List<String> signLocations = new ArrayList<String>();
List<String> signLocations = new ArrayList<>();
for(Location location : rent.getSignLocations()) {
signLocations.add(plugin.getLanguageManager().getLang("info-regionSignLocation", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
}
@ -302,7 +293,7 @@ public class InfoCommand extends CommandAreaShop {
plugin.messageNoPrefix(sender, "info-regionTeleportAt", buy, teleport.getWorld().getName(), teleport.getBlockX(), teleport.getBlockY(), teleport.getBlockZ(), (int)teleport.getPitch(), (int)teleport.getYaw());
}
}
List<String> signLocations = new ArrayList<String>();
List<String> signLocations = new ArrayList<>();
for(Location location : buy.getSignLocations()) {
signLocations.add(plugin.getLanguageManager().getLang("info-regionSignLocation", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
}
@ -336,7 +327,7 @@ public class InfoCommand extends CommandAreaShop {
/* List of regions without a group */
else if(args[1].equalsIgnoreCase("nogroup")) {
// Rental regions
Set<String> rents = new TreeSet<String>(plugin.getFileManager().getRentNames());
Set<String> rents = new TreeSet<>(plugin.getFileManager().getRentNames());
for(RegionGroup group : plugin.getFileManager().getGroups()) {
rents.removeAll(group.getMembers());
}
@ -348,7 +339,7 @@ public class InfoCommand extends CommandAreaShop {
}
// Buy regions
Set<String> buys = new TreeSet<String>(plugin.getFileManager().getBuyNames());
Set<String> buys = new TreeSet<>(plugin.getFileManager().getBuyNames());
for(RegionGroup group : plugin.getFileManager().getGroups()) {
buys.removeAll(group.getMembers());
}
@ -388,7 +379,7 @@ public class InfoCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(Arrays.asList("all", "rented", "forrent", "sold", "forsale", "player", "region", "nogroup"));
} else if(toComplete == 3) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LinksignsCommand extends CommandAreaShop {
public LinksignsCommand(AreaShop plugin) {
@ -31,7 +29,7 @@ public class LinksignsCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.linksigns")) {
plugin.message(sender, "linksigns-noPermission");
return;
@ -61,7 +59,7 @@ public class LinksignsCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {

View File

@ -1,19 +1,15 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
public class MeCommand extends CommandAreaShop {
public MeCommand(AreaShop plugin) {
@ -34,7 +30,7 @@ public class MeCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.me")) {
plugin.message(sender, "me-noPermission");
return;
@ -45,13 +41,13 @@ public class MeCommand extends CommandAreaShop {
}
Player player = (Player)sender;
// Get the regions owned by the player
Set<RentRegion> rentRegions = new HashSet<RentRegion>();
Set<RentRegion> rentRegions = new HashSet<>();
for(RentRegion region : plugin.getFileManager().getRents()) {
if(region.isOwner(player)) {
rentRegions.add(region);
}
}
Set<BuyRegion> buyRegions = new HashSet<BuyRegion>();
Set<BuyRegion> buyRegions = new HashSet<>();
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isOwner(player)) {
buyRegions.add(region);
@ -74,7 +70,7 @@ public class MeCommand extends CommandAreaShop {
plugin.messageNoPrefix(player, "me-buyLine", region);
}
}
Set<GeneralRegion> friendRegions = new HashSet<GeneralRegion>();
Set<GeneralRegion> friendRegions = new HashSet<>();
for(GeneralRegion region : plugin.getFileManager().getRegions()) {
if(region.getFriends() != null && region.getFriends().contains(player.getUniqueId())) {
friendRegions.add(region);
@ -90,13 +86,6 @@ public class MeCommand extends CommandAreaShop {
}
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
// Nothing to complete
return result;
}
}

View File

@ -1,11 +1,6 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class ReloadCommand extends CommandAreaShop {
@ -28,7 +23,7 @@ public class ReloadCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(sender.hasPermission("areashop.reload")) {
// Reload the configuration files and update all region flags/signs
plugin.reload(sender);
@ -36,11 +31,4 @@ public class ReloadCommand extends CommandAreaShop {
plugin.message(sender, "reload-noPermission");
}
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
return result;
}
}

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class RentCommand extends CommandAreaShop {
public RentCommand(AreaShop plugin) {
@ -31,7 +29,7 @@ public class RentCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.rent")) {
plugin.message(sender, "rent-noPermission");
return;
@ -53,10 +51,8 @@ public class RentCommand extends CommandAreaShop {
List<RentRegion> regions = Utils.getApplicableRentRegions(((Player) sender).getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
regions.get(0).rent(player);
}
@ -65,7 +61,7 @@ public class RentCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(RentRegion region : plugin.getFileManager().getRents()) {
if(!region.isRented()) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ResellCommand extends CommandAreaShop {
public ResellCommand(AreaShop plugin) {
@ -33,7 +31,7 @@ public class ResellCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.resell") && !sender.hasPermission("areashop.resellall")) {
plugin.message(sender, "resell-noPermissionOther");
return;
@ -43,14 +41,14 @@ public class ResellCommand extends CommandAreaShop {
plugin.message(sender, "resell-help");
return;
}
double price = 0.0;
double price;
try {
price = Double.parseDouble(args[1]);
} catch(NumberFormatException e) {
plugin.message(sender, "resell-wrongPrice", args[1]);
return;
}
BuyRegion buy = null;
BuyRegion buy;
if(args.length <= 2) {
if (sender instanceof Player) {
// get the region by location
@ -104,7 +102,7 @@ public class ResellCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 3) {
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isSold() && !region.isInResellingMode()) {

View File

@ -1,17 +1,15 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SchematiceventCommand extends CommandAreaShop {
public SchematiceventCommand(AreaShop plugin) {
@ -32,7 +30,7 @@ public class SchematiceventCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.schematicevents")) {
plugin.message(sender, "schemevent-noPermission");
return;
@ -60,7 +58,7 @@ public class SchematiceventCommand extends CommandAreaShop {
}
// Check for a totally wrong event or a non matching event
if(exception) {
ArrayList<String> values = new ArrayList<String>();
ArrayList<String> values = new ArrayList<>();
for(RegionEvent value : RegionEvent.values()) {
values.add(value.getValue().toLowerCase());
}
@ -74,7 +72,7 @@ public class SchematiceventCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SellCommand extends CommandAreaShop {
public SellCommand(AreaShop plugin) {
@ -33,12 +31,12 @@ public class SellCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.sell") && !sender.hasPermission("areashop.sellown")) {
plugin.message(sender, "sell-noPermission");
return;
}
BuyRegion buy = null;
BuyRegion buy;
if(args.length <= 1) {
if (sender instanceof Player) {
// get the region by location
@ -86,7 +84,7 @@ public class SellCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isSold()) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SetdurationCommand extends CommandAreaShop {
public SetdurationCommand(AreaShop plugin) {
@ -31,7 +29,7 @@ public class SetdurationCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setduration") && (!sender.hasPermission("areashop.setduration.landlord") && sender instanceof Player)) {
plugin.message(sender, "setduration-noPermission");
return;
@ -44,7 +42,7 @@ public class SetdurationCommand extends CommandAreaShop {
if(args.length >= 2 && ("default".equalsIgnoreCase(args[1]) || "reset".equalsIgnoreCase(args[1]))) {
regionArgument = 2;
}
RentRegion rent = null;
RentRegion rent;
if(args.length <= regionArgument) {
if (sender instanceof Player) {
// get the region by location
@ -69,7 +67,7 @@ public class SetdurationCommand extends CommandAreaShop {
plugin.message(sender, "setduration-notRegistered", args[regionArgument]);
return;
}
if(!sender.hasPermission("areashop.setduration") && !rent.isLandlord(((Player)sender).getUniqueId())) {
if(!sender.hasPermission("areashop.setduration") && !(sender instanceof Player && rent.isLandlord(((Player)sender).getUniqueId()))) {
plugin.message(sender, "setduration-noLandlord", rent);
return;
}
@ -98,7 +96,7 @@ public class SetdurationCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getRentNames();
} else if(toComplete == 4) {

View File

@ -1,18 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SetlandlordCommand extends CommandAreaShop {
public SetlandlordCommand(AreaShop plugin) {
@ -33,7 +31,7 @@ public class SetlandlordCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setlandlord")) {
plugin.message(sender, "setlandlord-noPermission");
return;
@ -43,8 +41,8 @@ public class SetlandlordCommand extends CommandAreaShop {
return;
}
@SuppressWarnings("deprecation")
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
GeneralRegion region = null;
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
GeneralRegion region;
if(args.length < 3) {
if (sender instanceof Player) {
// get the region by location
@ -79,7 +77,7 @@ public class SetlandlordCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Bukkit.getOnlinePlayers()) {
result.add(player.getName());

View File

@ -1,22 +1,20 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.Calendar;
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;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;
public class SetownerCommand extends CommandAreaShop {
public SetownerCommand(AreaShop plugin) {
@ -37,7 +35,7 @@ public class SetownerCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setownerrent") && !sender.hasPermission("areashop.setownerbuy")) {
plugin.message(sender, "setowner-noPermission");
return;
@ -131,7 +129,7 @@ public class SetownerCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(Player player : Bukkit.getOnlinePlayers()) {
result.add(player.getName());

View File

@ -1,18 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SetpriceCommand extends CommandAreaShop {
public SetpriceCommand(AreaShop plugin) {
@ -33,7 +31,7 @@ public class SetpriceCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setprice") && (!sender.hasPermission("areashop.setprice.landlord") && sender instanceof Player)) {
plugin.message(sender, "setprice-noPermission");
return;
@ -41,8 +39,8 @@ public class SetpriceCommand extends CommandAreaShop {
if(args.length < 2 || args[1] == null) {
plugin.message(sender, "setprice-help");
return;
}
GeneralRegion region = null;
}
GeneralRegion region;
if(args.length < 3) {
if (sender instanceof Player) {
// get the region by location
@ -67,7 +65,7 @@ public class SetpriceCommand extends CommandAreaShop {
plugin.message(sender, "setprice-notRegistered", args[2]);
return;
}
if(!sender.hasPermission("areashop.setprice") && !region.isLandlord(((Player)sender).getUniqueId())) {
if(!sender.hasPermission("areashop.setprice") && !(sender instanceof Player && region.isLandlord(((Player)sender).getUniqueId()))) {
plugin.message(sender, "setprice-noLandlord", region);
return;
}
@ -81,8 +79,8 @@ public class SetpriceCommand extends CommandAreaShop {
region.updateSigns();
region.updateRegionFlags();
return;
}
double price = 0.0;
}
double price;
try {
price = Double.parseDouble(args[1]);
} catch(NumberFormatException e) {
@ -103,7 +101,7 @@ public class SetpriceCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 3) {
result = plugin.getFileManager().getRegionNames();
}

View File

@ -1,14 +1,12 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
public class SetrestoreCommand extends CommandAreaShop {
public SetrestoreCommand(AreaShop plugin) {
@ -29,7 +27,7 @@ public class SetrestoreCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setrestore")) {
plugin.message(sender, "setrestore-noPermission");
return;
@ -64,7 +62,7 @@ public class SetrestoreCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 2) {
result = plugin.getFileManager().getRegionNames();
} else if(toComplete == 3) {

View File

@ -1,19 +1,16 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
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;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.ArrayList;
import java.util.List;
public class SetteleportCommand extends CommandAreaShop {
@ -37,7 +34,7 @@ public class SetteleportCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.setteleport") && !sender.hasPermission("areashop.setteleportall")) {
plugin.message(sender, "setteleport-noPermission");
return;
@ -47,29 +44,24 @@ public class SetteleportCommand extends CommandAreaShop {
return;
}
Player player = (Player)sender;
GeneralRegion region = null;
GeneralRegion region;
if(args.length < 2) {
if (sender instanceof Player) {
// get the region by location
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player) sender).getLocation());
if (regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
// get the region by location
List<GeneralRegion> regions = Utils.getAllApplicableRegions(((Player)sender).getLocation());
if(regions.isEmpty()) {
plugin.message(sender, "cmd-noRegionsAtLocation");
return;
}
} else if(regions.size() > 1) {
plugin.message(sender, "cmd-moreRegionsAtLocation");
return;
} else {
region = regions.get(0);
}
} else {
region = plugin.getFileManager().getRegion(args[1]);
}
boolean owner = false;
}
boolean owner;
if(region == null) {
plugin.message(player, "setteleport-noRentOrBuy", args[1]);
@ -104,7 +96,7 @@ public class SetteleportCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {

View File

@ -1,26 +1,23 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import java.util.ArrayList;
import java.util.List;
public class StackCommand extends CommandAreaShop {
@ -42,7 +39,7 @@ public class StackCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
// Check permission
if(!sender.hasPermission("areashop.stack")) {
plugin.message(sender, "stack-noPermission");
@ -63,13 +60,15 @@ public class StackCommand extends CommandAreaShop {
int tempAmount = -1;
try {
tempAmount = Integer.parseInt(args[1]);
} catch(NumberFormatException e) {}
} catch(NumberFormatException e) {
// Incorrect number
}
if(tempAmount <= 0) {
plugin.message(player, "stack-wrongAmount", args[1]);
return;
}
// Check gap
int gap = -1;
int gap;
try {
gap = Integer.parseInt(args[2]);
} catch(NumberFormatException e) {
@ -119,7 +118,7 @@ public class StackCommand extends CommandAreaShop {
final boolean rentRegions = "rent".equalsIgnoreCase(args[4]);
final int amount = tempAmount;
final RegionGroup finalGroup = group;
String type = null;
String type;
if(rentRegions) {
type = "rent";
} else {
@ -206,7 +205,7 @@ public class StackCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(toComplete == 5) {
result.add("rent");
result.add("buy");

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class StopresellCommand extends CommandAreaShop {
public StopresellCommand(AreaShop plugin) {
@ -33,13 +31,13 @@ public class StopresellCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.stopresell") && !sender.hasPermission("areashop.stopresellall")) {
plugin.message(sender, "stopresell-noPermissionOther");
return;
}
BuyRegion buy = null;
BuyRegion buy;
if(args.length <= 1) {
if (sender instanceof Player) {
// get the region by location
@ -93,7 +91,7 @@ public class StopresellCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(BuyRegion region : plugin.getFileManager().getBuys()) {
if(region.isSold() && region.isInResellingMode()) {

View File

@ -1,15 +1,13 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class TeleportCommand extends CommandAreaShop {
public TeleportCommand(AreaShop plugin) {
@ -32,7 +30,7 @@ public class TeleportCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.teleport") && !sender.hasPermission("areashop.teleportall") && !sender.hasPermission("areashop.teleportsign") && !sender.hasPermission("areashop.teleportsignall") && !sender.hasPermission("areashop.teleportfriend") && !sender.hasPermission("teleportfriendsign")) {
plugin.message(sender, "teleport-noPermission");
return;
@ -61,7 +59,7 @@ public class TeleportCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
result.addAll(plugin.getFileManager().getRegionNames());
} else if(toComplete == 3) {

View File

@ -1,16 +1,14 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class UnrentCommand extends CommandAreaShop {
public UnrentCommand(AreaShop plugin) {
@ -33,12 +31,12 @@ public class UnrentCommand extends CommandAreaShop {
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("areashop.unrent") && !sender.hasPermission("areashop.unrentown")) {
plugin.message(sender, "unrent-noPermission");
return;
}
RentRegion rent = null;
RentRegion rent;
if(args.length <= 1) {
if (sender instanceof Player) {
// get the region by location
@ -86,7 +84,7 @@ public class UnrentCommand extends CommandAreaShop {
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
if(toComplete == 2) {
for(RentRegion region : plugin.getFileManager().getRents()) {
if(region.isRented()) {

View File

@ -1,11 +0,0 @@
package nl.evolutioncoding.areashop.exceptions;
public class RegionCreateException extends Exception {
private static final long serialVersionUID = 1L;
public RegionCreateException(String message) {
super(message);
}
}

View File

@ -1,12 +1,8 @@
package nl.evolutioncoding.areashop.listeners;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -17,12 +13,15 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
/**
* Checks for placement of signs for this plugin
* @author NLThijs48
*/
public final class PlayerLoginLogoutListener implements Listener {
AreaShop plugin;
private AreaShop plugin;
/**
* Constructor
@ -76,7 +75,7 @@ public final class PlayerLoginLogoutListener implements Listener {
}
}.runTaskTimer(plugin, 25, 25);
// Check if the player has regions that use an old name of him and update them
final List<GeneralRegion> regions = new ArrayList<GeneralRegion>(plugin.getFileManager().getRegions());
final List<GeneralRegion> regions = new ArrayList<>(plugin.getFileManager().getRegions());
new BukkitRunnable() {
private int current = 0;
@ -130,7 +129,7 @@ public final class PlayerLoginLogoutListener implements Listener {
* Update the last active time for all regions the player is owner off
* @param player The player to update the active times for
*/
public void updateLastActive(Player player) {
private void updateLastActive(Player player) {
for(GeneralRegion region : plugin.getFileManager().getRegions()) {
if(region.isOwner(player)) {
region.updateLastActiveTime();

View File

@ -2,7 +2,6 @@ package nl.evolutioncoding.areashop.listeners;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
@ -17,7 +16,7 @@ import org.bukkit.event.block.BlockPhysicsEvent;
* @author NLThijs48
*/
public final class SignBreakListener implements Listener {
AreaShop plugin;
private AreaShop plugin;
/**
* Constructor
@ -38,18 +37,18 @@ public final class SignBreakListener implements Listener {
return;
}
Block block = event.getBlock();
/* Check if it is a sign */
// Check if it is a sign
if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
/* Check if the rent sign is really the same as a saved rent */
// Check if the rent sign is really the same as a saved rent
GeneralRegion region = plugin.getFileManager().getRegionBySignLocation(block.getLocation());
if(region == null) {
return;
}
/* Remove the sign of the rental region if the player has permission */
// Remove the sign of the rental region if the player has permission
if(event.getPlayer().hasPermission("areashop.delsign")) {
region.removeSign(block.getLocation());
plugin.message(event.getPlayer(), "delsign-success", region.getName());
} else { /* Cancel the breaking of the sign */
} else { // Cancel the breaking of the sign
event.setCancelled(true);
plugin.message(event.getPlayer(), "delsign-noPermission");
}
@ -70,7 +69,7 @@ public final class SignBreakListener implements Listener {
Sign sign = (Sign)block.getState();
Block attachedTo = block.getRelative(((org.bukkit.material.Sign)sign.getData()).getAttachedFace());
if(attachedTo.getType() == Material.AIR){
/* Check if the rent sign is really the same as a saved rent */
// Check if the rent sign is really the same as a saved rent
final GeneralRegion region = plugin.getFileManager().getRegionBySignLocation(block.getLocation());
if(region == null) {
return;

View File

@ -1,7 +1,9 @@
package nl.evolutioncoding.areashop.listeners;
import java.util.List;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.managers.FileManager.AddResult;
@ -10,7 +12,6 @@ import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -19,17 +20,14 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.material.Sign;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.List;
/**
* Checks for placement of signs for this plugin
* @author NLThijs48
*/
public final class SignChangeListener implements Listener {
AreaShop plugin;
private AreaShop plugin;
/**
* Constructor
@ -113,16 +111,12 @@ public final class SignChangeListener implements Listener {
AddResult addResult = plugin.getFileManager().checkRegionAdd(player, regionManager.getRegion(secondLine), RegionType.RENT);
if(addResult == AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
return;
} else if(addResult == AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
return;
} else if(addResult == AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
return;
} else if(thirdLine != null && thirdLine.length() != 0 && !plugin.checkTimeFormat(thirdLine)) {
plugin.message(player, "setup-wrongDuration");
return;
} else {
double price = 0.0;
if(priceSet) {
@ -137,8 +131,8 @@ public final class SignChangeListener implements Listener {
// Add rent to the FileManager
final RentRegion rent = new RentRegion(plugin, secondLine, event.getPlayer().getWorld());
boolean isMember = player != null && plugin.getWorldGuardHandler().containsMember(rent.getRegion(), player.getUniqueId());
boolean isOwner = player != null && plugin.getWorldGuardHandler().containsOwner(rent.getRegion(), player.getUniqueId());
boolean isMember = plugin.getWorldGuardHandler().containsMember(rent.getRegion(), player.getUniqueId());
boolean isOwner = plugin.getWorldGuardHandler().containsOwner(rent.getRegion(), player.getUniqueId());
boolean landlord = (!player.hasPermission("areashop.createrent")
&& ((player.hasPermission("areashop.createrent.owner") && isOwner)
|| (player.hasPermission("areashop.createrent.member") && isMember)));
@ -187,6 +181,9 @@ public final class SignChangeListener implements Listener {
// Get the regionManager for accessing regions
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
if(regionManager == null) {
return;
}
// If the secondLine does not contain a name try to find the region by location
if(secondLine == null || secondLine.length() == 0) {
@ -229,13 +226,10 @@ public final class SignChangeListener implements Listener {
AddResult addResult = plugin.getFileManager().checkRegionAdd(player, region, RegionType.BUY);
if(addResult == AddResult.BLACKLISTED) {
plugin.message(player, "setup-blacklisted", secondLine);
return;
} else if(addResult == AddResult.ALREADYADDED) {
plugin.message(player, "setup-alreadyRentSign");
return;
} else if(addResult == AddResult.NOPERMISSION) {
plugin.message(player, "setup-noPermission", secondLine);
return;
} else {
double price = 0.0;
if(priceSet) {
@ -250,8 +244,8 @@ public final class SignChangeListener implements Listener {
// Add buy to the FileManager
final BuyRegion buy = new BuyRegion(plugin, secondLine, event.getPlayer().getWorld());
boolean isMember = player != null && plugin.getWorldGuardHandler().containsMember(buy.getRegion(), player.getUniqueId());
boolean isOwner = player != null && plugin.getWorldGuardHandler().containsOwner(buy.getRegion(), player.getUniqueId());
boolean isMember = plugin.getWorldGuardHandler().containsMember(buy.getRegion(), player.getUniqueId());
boolean isOwner = plugin.getWorldGuardHandler().containsOwner(buy.getRegion(), player.getUniqueId());
boolean landlord = (!player.hasPermission("areashop.createbuy")
&& ((player.hasPermission("areashop.createbuy.owner") && isOwner)
|| (player.hasPermission("areashop.createbuy.member") && isMember)));
@ -278,8 +272,8 @@ public final class SignChangeListener implements Listener {
}.runTaskLater(plugin, 1);
// Set the flags for the region
buy.updateRegionFlags();
plugin.message(player, "setup-buySuccess", regionManager.getRegion(secondLine).getId());
buy.updateRegionFlags();
plugin.message(player, "setup-buySuccess", region.getId());
// Run commands
buy.runEventCommands(RegionEvent.CREATED, false);
@ -294,8 +288,8 @@ public final class SignChangeListener implements Listener {
// Get the other lines
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
GeneralRegion region = null;
GeneralRegion region;
if(secondLine != null && secondLine.length() != 0) {
// Get region by secondLine of the sign
region = plugin.getFileManager().getRegion(secondLine);

View File

@ -3,7 +3,6 @@ package nl.evolutioncoding.areashop.listeners;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion.ClickType;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -14,7 +13,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class SignClickListener implements Listener {
AreaShop plugin;
private AreaShop plugin;
/**
* Constructor
@ -34,10 +33,10 @@ public class SignClickListener implements Listener {
return;
}
Block block = event.getClickedBlock();
/* Check for clicking a sign and rightclicking */
// Check for clicking a sign and rightclicking
if((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)
&& (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
/* Check if the rent sign is really the same as a saved rent */
// Check if the rent sign is really the same as a saved rent
GeneralRegion result = plugin.getFileManager().getRegionBySignLocation(block.getLocation());
if(result == null) {
return;

View File

@ -1,44 +1,7 @@
package nl.evolutioncoding.areashop.managers;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.commands.AddCommand;
import nl.evolutioncoding.areashop.commands.AddfriendCommand;
import nl.evolutioncoding.areashop.commands.AddsignCommand;
import nl.evolutioncoding.areashop.commands.BuyCommand;
import nl.evolutioncoding.areashop.commands.CommandAreaShop;
import nl.evolutioncoding.areashop.commands.DelCommand;
import nl.evolutioncoding.areashop.commands.DelfriendCommand;
import nl.evolutioncoding.areashop.commands.DelsignCommand;
import nl.evolutioncoding.areashop.commands.FindCommand;
import nl.evolutioncoding.areashop.commands.GroupaddCommand;
import nl.evolutioncoding.areashop.commands.GroupdelCommand;
import nl.evolutioncoding.areashop.commands.GroupinfoCommand;
import nl.evolutioncoding.areashop.commands.GrouplistCommand;
import nl.evolutioncoding.areashop.commands.HelpCommand;
import nl.evolutioncoding.areashop.commands.InfoCommand;
import nl.evolutioncoding.areashop.commands.LinksignsCommand;
import nl.evolutioncoding.areashop.commands.MeCommand;
import nl.evolutioncoding.areashop.commands.ReloadCommand;
import nl.evolutioncoding.areashop.commands.RentCommand;
import nl.evolutioncoding.areashop.commands.ResellCommand;
import nl.evolutioncoding.areashop.commands.SchematiceventCommand;
import nl.evolutioncoding.areashop.commands.SellCommand;
import nl.evolutioncoding.areashop.commands.SetdurationCommand;
import nl.evolutioncoding.areashop.commands.SetlandlordCommand;
import nl.evolutioncoding.areashop.commands.SetownerCommand;
import nl.evolutioncoding.areashop.commands.SetpriceCommand;
import nl.evolutioncoding.areashop.commands.SetrestoreCommand;
import nl.evolutioncoding.areashop.commands.SetteleportCommand;
import nl.evolutioncoding.areashop.commands.StackCommand;
import nl.evolutioncoding.areashop.commands.StopresellCommand;
import nl.evolutioncoding.areashop.commands.TeleportCommand;
import nl.evolutioncoding.areashop.commands.UnrentCommand;
import nl.evolutioncoding.areashop.commands.*;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -46,9 +9,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
public class CommandManager implements CommandExecutor, TabCompleter {
AreaShop plugin;
ArrayList<CommandAreaShop> commands;
private AreaShop plugin;
private ArrayList<CommandAreaShop> commands;
/**
* Constructor
@ -56,7 +24,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
*/
public CommandManager(AreaShop plugin) {
this.plugin = plugin;
commands = new ArrayList<CommandAreaShop>();
commands = new ArrayList<>();
commands.add(new HelpCommand(plugin));
commands.add(new RentCommand(plugin));
commands.add(new UnrentCommand(plugin));
@ -108,7 +76,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
*/
public void showHelp(CommandSender target) {
/* Add all messages to a list */
ArrayList<String> messages = new ArrayList<String>();
ArrayList<String> messages = new ArrayList<>();
messages.add(plugin.getConfig().getString("chatPrefix") + plugin.getLanguageManager().getLang("help-header"));
messages.add(plugin.getConfig().getString("chatPrefix") + plugin.getLanguageManager().getLang("help-alias"));
for(CommandAreaShop command : commands) {
@ -137,7 +105,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
boolean executed = false;
for(int i=0; i<commands.size() && !executed; i++) {
if(commands.get(i).canExecute(command, args)) {
commands.get(i).execute(sender, command, args);
commands.get(i).execute(sender, args);
executed = true;
}
}
@ -156,7 +124,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if(!sender.hasPermission("areashop.tabcomplete")) {
return result;
}
@ -182,7 +150,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
}
// Filter and sort the results
if(result.size() > 0) {
SortedSet<String> set = new TreeSet<String>();
SortedSet<String> set = new TreeSet<>();
for(String suggestion : result) {
if(suggestion.toLowerCase().startsWith(toCompletePrefix)) {
set.add(suggestion);

View File

@ -1,24 +1,9 @@
package nl.evolutioncoding.areashop.managers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.BuyRegion;
@ -27,29 +12,22 @@ import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionEvent;
import nl.evolutioncoding.areashop.regions.GeneralRegion.RegionType;
import nl.evolutioncoding.areashop.regions.RegionGroup;
import nl.evolutioncoding.areashop.regions.RentRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FileManager {
private static FileManager instance = null;
private AreaShop plugin = null;
private ObjectInputStream input = null;
private ObjectOutputStream output = null;
private HashMap<String, GeneralRegion> regions = null;
private String regionsPath = null;
private HashMap<String, RegionGroup> groups = null;
@ -74,7 +52,8 @@ public class FileManager {
SUCCESS("success");
private final String value;
private AddResult(String value) {
AddResult(String value) {
this.value = value;
}
public String getValue() {
@ -84,22 +63,22 @@ public class FileManager {
/**
* Constructor, initialize variabeles
* @param plugin
* @param plugin AreaShop
*/
public FileManager(AreaShop plugin) {
this.plugin = plugin;
regions = new HashMap<String, GeneralRegion>();
regions = new HashMap<>();
regionsPath = plugin.getDataFolder() + File.separator + AreaShop.regionsFolder;
configPath = plugin.getDataFolder() + File.separator + "config.yml";
groups = new HashMap<String, RegionGroup>();
groups = new HashMap<>();
groupsPath = plugin.getDataFolder() + File.separator + AreaShop.groupsFile;
defaultPath = plugin.getDataFolder() + File.separator + AreaShop.defaultFile;
versionPath = plugin.getDataFolder().getPath() + File.separator + AreaShop.versionFile;
schemFolder = plugin.getDataFolder() + File.separator + AreaShop.schematicFolder;
worldRegionsRequireSaving = new HashSet<String>();
worldRegionsRequireSaving = new HashSet<>();
File schemFile = new File(schemFolder);
if(!schemFile.exists()) {
schemFile.mkdirs();
if(!schemFile.exists() & !schemFile.mkdirs()) {
plugin.getLogger().warning("Could not create schematic files directory: " + schemFile.getAbsolutePath());
}
loadVersions();
}
@ -161,7 +140,7 @@ public class FileManager {
}
public List<RentRegion> getRents() {
List<RentRegion> result = new ArrayList<RentRegion>();
List<RentRegion> result = new ArrayList<>();
for(GeneralRegion region : regions.values()) {
if(region.isRentRegion()) {
result.add((RentRegion)region);
@ -171,7 +150,7 @@ public class FileManager {
}
public List<BuyRegion> getBuys() {
List<BuyRegion> result = new ArrayList<BuyRegion>();
List<BuyRegion> result = new ArrayList<>();
for(GeneralRegion region : regions.values()) {
if(region.isBuyRegion()) {
result.add((BuyRegion)region);
@ -181,7 +160,7 @@ public class FileManager {
}
public List<GeneralRegion> getRegions() {
return new ArrayList<GeneralRegion>(regions.values());
return new ArrayList<>(regions.values());
}
/**
@ -189,28 +168,28 @@ public class FileManager {
* @return A String list with all the names
*/
public List<String> getBuyNames() {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
for(BuyRegion region : getBuys()) {
result.add(region.getName());
}
return result;
}
public List<String> getRentNames() {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
for(RentRegion region : getRents()) {
result.add(region.getName());
}
return result;
}
public List<String> getRegionNames() {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
for(GeneralRegion region : getRegions()) {
result.add(region.getName());
}
return result;
}
public List<String> getGroupNames() {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
for(RegionGroup group : getGroups()) {
result.add(group.getName());
}
@ -264,12 +243,8 @@ public class FileManager {
public void addGroup(RegionGroup group) {
groups.put(group.getName().toLowerCase(), group);
String lowGroup = group.getName().toLowerCase();
ConfigurationSection result = groupsConfig.getConfigurationSection(lowGroup);
if(result == null) {
result = groupsConfig.createSection(lowGroup);
groupsConfig.set(lowGroup + ".name", group.getName());
groupsConfig.set(lowGroup + ".priority", 0);
}
groupsConfig.set(lowGroup + ".name", group.getName());
groupsConfig.set(lowGroup + ".priority", 0);
saveGroupsIsRequired();
}
@ -289,7 +264,7 @@ public class FileManager {
boolean isMember = player != null && plugin.getWorldGuardHandler().containsMember(region, player.getUniqueId());
boolean isOwner = player != null && plugin.getWorldGuardHandler().containsOwner(region, player.getUniqueId());
AreaShop.debug("checkRegionAdd: isOwner=" + isOwner + ", isMember=" + isMember);
String typeString = null;
String typeString;
if(type == RegionType.RENT) {
typeString = "rent";
} else {
@ -341,7 +316,7 @@ public class FileManager {
rent.resetRegionFlags();
regions.remove(rent.getLowerCaseName());
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + rent.getLowerCaseName() + ".yml");
boolean deleted = true;
boolean deleted;
if(file.exists()) {
try {
deleted = file.delete();
@ -376,7 +351,8 @@ public class FileManager {
/**
* Remove a buy from the list
* @param regionName
* @param buy The BuyRegion to remove
* @param giveMoneyBack true if money should be given back to the player, otherwise false
*/
public boolean removeBuy(BuyRegion buy, boolean giveMoneyBack) {
boolean result = false;
@ -405,7 +381,7 @@ public class FileManager {
// Deleting the file
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + buy.getLowerCaseName() + ".yml");
boolean deleted = true;
boolean deleted;
if(file.exists()) {
try {
deleted = file.delete();
@ -439,7 +415,7 @@ public class FileManager {
* Update all signs that need periodic updating
*/
public void performPeriodicSignUpdate() {
final List<RentRegion> regions = new ArrayList<RentRegion>(getRents());
final List<RentRegion> regions = new ArrayList<>(getRents());
new BukkitRunnable() {
private int current = 0;
@ -464,7 +440,7 @@ public class FileManager {
* Send out rent expire warnings
*/
public void sendRentExpireWarnings() {
final List<RentRegion> regions = new ArrayList<RentRegion>(getRents());
final List<RentRegion> regions = new ArrayList<>(getRents());
new BukkitRunnable() {
private int current = 0;
@ -485,11 +461,10 @@ public class FileManager {
/**
* Update all rent signs
* @return true if all signs are updated, otherwise false
* @param confirmationReceiver who needs to get the confirmation message, null if nobody
*/
public void updateRentSignsAndFlags(final CommandSender confirmationReceiver) {
final List<RentRegion> regions = new ArrayList<RentRegion>(getRents());
final List<RentRegion> regions = new ArrayList<>(getRents());
new BukkitRunnable() {
private int current = 0;
private boolean result = true;
@ -518,11 +493,10 @@ public class FileManager {
/**
* Update all buy signs
* @return true if all signs are updated, otherwise false
* @param confirmationReceiver who needs to get the confirmation message, null if nobody
*/
public void updateBuySignsAndFlags(final CommandSender confirmationReceiver) {
final List<BuyRegion> regions = new ArrayList<BuyRegion>(getBuys());
final List<BuyRegion> regions = new ArrayList<>(getBuys());
new BukkitRunnable() {
private int current = 0;
private boolean result = true;
@ -622,8 +596,8 @@ public class FileManager {
saveGroupsNow();
}
this.saveWorldGuardRegions();
final List<GeneralRegion> regions = new ArrayList<GeneralRegion>(getRegions());
final List<GeneralRegion> regions = new ArrayList<>(getRegions());
new BukkitRunnable() {
private int current = 0;
@ -718,7 +692,7 @@ public class FileManager {
* Unrent regions that have no time left, regions to check per tick is in the config
*/
public void checkRents() {
final List<RentRegion> regions = new ArrayList<RentRegion>(getRents());
final List<RentRegion> regions = new ArrayList<>(getRents());
new BukkitRunnable() {
private int current = 0;
@ -741,7 +715,7 @@ public class FileManager {
* Check all regions and unrent/sell them if the player is inactive for too long
*/
public void checkForInactiveRegions() {
final List<GeneralRegion> regions = new ArrayList<GeneralRegion>(getRegions());
final List<GeneralRegion> regions = new ArrayList<>(getRegions());
new BukkitRunnable() {
private int current = 0;
@ -770,8 +744,8 @@ public class FileManager {
if(file.exists()) {
/* Load versions from the file */
try {
input = new ObjectInputStream(new FileInputStream(versionPath));
versions = (HashMap<String,Integer>)input.readObject();
ObjectInputStream input = new ObjectInputStream(new FileInputStream(versionPath));
versions = (HashMap<String,Integer>)input.readObject();
input.close();
} catch (IOException | ClassNotFoundException | ClassCastException e) {
plugin.getLogger().warning("Something went wrong reading file: " + versionPath);
@ -779,7 +753,7 @@ public class FileManager {
}
}
if(versions == null || versions.size() == 0) {
versions = new HashMap<String, Integer>();
versions = new HashMap<>();
versions.put(AreaShop.versionFiles, 0);
this.saveVersions();
}
@ -793,7 +767,7 @@ public class FileManager {
plugin.getLogger().info("versions file created, this should happen only after installing or upgrading the plugin");
}
try {
output = new ObjectOutputStream(new FileOutputStream(versionPath));
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(versionPath));
output.writeObject(versions);
output.close();
} catch (IOException e) {
@ -806,9 +780,8 @@ public class FileManager {
* @return true if the files are loaded correctly, otherwise false
*/
public boolean loadFiles() {
boolean result = true;
// Load config.yml + add defaults from .jar
result = result & loadConfigFile();
boolean result = loadConfigFile();
// Load default.yml + add defaults from .jar
result = result & loadDefaultFile();
// Convert old formats to the latest (object saving to .yml saving)
@ -832,13 +805,11 @@ public class FileManager {
File defaultFile = new File(defaultPath);
// Safe the file from the jar to disk if it does not exist
if(!defaultFile.exists()) {
InputStream input = null;
OutputStream output = null;
try {
input = plugin.getResource(AreaShop.defaultFile);
output = new FileOutputStream(defaultFile);
int read = 0;
try(
InputStream input = plugin.getResource(AreaShop.defaultFile);
OutputStream output = new FileOutputStream(defaultFile)
) {
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
output.write(bytes, 0, read);
@ -847,43 +818,23 @@ public class FileManager {
output.close();
plugin.getLogger().info("File with default region settings has been saved, should only happen on first startup");
} catch(IOException e) {
try {
input.close();
output.close();
} catch (IOException e1) {} catch (NullPointerException e2) {}
plugin.getLogger().warning("Something went wrong saving the default region settings: " + defaultFile.getPath());
plugin.getLogger().warning("Something went wrong saving the default region settings: " + defaultFile.getAbsolutePath());
}
}
// Load default.yml from the plugin folder
InputStreamReader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(defaultFile), Charsets.UTF_8);
} catch (FileNotFoundException e) {
result = false;
}
if(reader != null) {
defaultConfig = YamlConfiguration.loadConfiguration(reader);
// Load default.yml from the plugin folder, and as backup the default one
try(
InputStreamReader custom = new InputStreamReader(new FileInputStream(defaultFile), Charsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.defaultFile), Charsets.UTF_8)
) {
defaultConfig = YamlConfiguration.loadConfiguration(custom);
if(defaultConfig.getKeys(false).size() == 0) {
plugin.getLogger().warning("File 'default.yml' is empty, check for errors in the log.");
result = false;
} else {
defaultConfig.addDefaults(YamlConfiguration.loadConfiguration(normal));
}
try {
reader.close();
} catch (IOException e) {}
}
if(result) {
// Addding the defaults from the normal file that is inside the jar is disabled, not nice when removing lines for things you don't want
InputStream inputStream = plugin.getResource(AreaShop.defaultFile);
if(inputStream != null) {
reader = new InputStreamReader(inputStream, Charsets.UTF_8);
}
if(reader != null) {
defaultConfig.addDefaults(YamlConfiguration.loadConfiguration(reader));
try {
reader.close();
} catch (IOException e) {}
}
} catch(IOException e) {
result = false;
}
return result;
}
@ -897,61 +848,39 @@ public class FileManager {
File configFile = new File(configPath);
// Safe the file from the jar to disk if it does not exist
if(!configFile.exists()) {
InputStream input = null;
OutputStream output = null;
try {
input = plugin.getResource(AreaShop.configFile);
output = new FileOutputStream(configFile);
int read = 0;
try(
InputStream input = plugin.getResource(AreaShop.configFile);
OutputStream output = new FileOutputStream(configFile)
) {
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
output.write(bytes, 0, read);
}
input.close();
output.close();
}
plugin.getLogger().info("Default config file has been saved, should only happen on first startup");
} catch(IOException e) {
try {
input.close();
output.close();
} catch (IOException e1) {} catch (NullPointerException e2) {}
plugin.getLogger().warning("Something went wrong saving the config file: " + configFile.getPath());
plugin.getLogger().warning("Something went wrong saving the config file: " + configFile.getAbsolutePath());
}
}
// Load config.yml from the plugin folder
InputStreamReader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(configFile), Charsets.UTF_8);
} catch (FileNotFoundException e) {
result = false;
}
if(reader != null) {
config = YamlConfiguration.loadConfiguration(reader);
try(
InputStreamReader custom = new InputStreamReader(new FileInputStream(configFile), Charsets.UTF_8);
InputStreamReader normal = new InputStreamReader(plugin.getResource(AreaShop.configFile), Charsets.UTF_8)
) {
config = YamlConfiguration.loadConfiguration(custom);
if(config.getKeys(false).size() == 0) {
plugin.getLogger().warning("File 'config.yml' is empty, check for errors in the log.");
result = false;
} else {
config.addDefaults(YamlConfiguration.loadConfiguration(normal));
// Set the debug and chatprefix variables
plugin.setDebug(this.getConfig().getBoolean("debug"));
plugin.setChatprefix(this.getConfig().getString("chatPrefix"));
}
try {
reader.close();
} catch (IOException e) {}
} catch(IOException e) {
plugin.getLogger().warning("Something went wrong while reading the config.yml file: " + configFile.getAbsolutePath());
result = false;
}
if(result) {
// Add the values from the config.yml file inside of the .jar as defaults
InputStream inputStream = plugin.getResource(AreaShop.configFile);
if(inputStream != null) {
reader = new InputStreamReader(inputStream, Charsets.UTF_8);
}
if(reader != null) {
config.addDefaults(YamlConfiguration.loadConfiguration(reader));
try {
reader.close();
} catch (IOException e) {}
}
// Set the debug and chatprefix variables
plugin.setDebug(this.getConfig().getBoolean("debug"));
plugin.setChatprefix(this.getConfig().getString("chatPrefix"));
}
return result;
}
@ -960,16 +889,13 @@ public class FileManager {
*/
public void loadGroupsFile() {
File groupFile = new File(groupsPath);
InputStreamReader reader = null;
if(groupFile.exists() && groupFile.isFile()) {
try {
reader = new InputStreamReader(new FileInputStream(groupFile), Charsets.UTF_8);
} catch (FileNotFoundException e) {}
if(reader != null) {
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(groupFile), Charsets.UTF_8)
) {
groupsConfig = YamlConfiguration.loadConfiguration(reader);
try {
reader.close();
} catch (IOException e) {}
} catch(IOException e) {
plugin.getLogger().warning("Could not load groups.yml file: " + groupFile.getAbsolutePath());
}
}
if(groupsConfig == null) {
@ -988,23 +914,27 @@ public class FileManager {
regions.clear();
File file = new File(regionsPath);
if(!file.exists()) {
file.mkdirs();
if(!file.mkdirs()) {
plugin.getLogger().warning("Could not create region files directory: " + file.getAbsolutePath());
return;
}
plugin.setReady(true);
} else if(file.isDirectory()) {
File[] regionFiles = file.listFiles();
if(regionFiles == null) {
return;
}
for(File regionFile : regionFiles) {
if(regionFile.exists() && regionFile.isFile()) {
// Load the region file from disk in UTF8 mode
InputStreamReader reader = null;
YamlConfiguration config = null;
try {
reader = new InputStreamReader(new FileInputStream(regionFile), Charsets.UTF_8);
} catch (FileNotFoundException e) {}
if(reader != null) {
YamlConfiguration config;
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(regionFile), Charsets.UTF_8)
) {
config = YamlConfiguration.loadConfiguration(reader);
try {
reader.close();
} catch (IOException e) {}
} catch(IOException e) {
plugin.getLogger().warning("Something went wrong reading region file: " + regionFile.getAbsolutePath());
continue;
}
// Construct the correct type of region
if(RegionType.RENT.getValue().equals(config.getString("general.type"))) {
@ -1020,9 +950,9 @@ public class FileManager {
new BukkitRunnable() {
@Override
public void run() {
List<GeneralRegion> noWorld = new ArrayList<GeneralRegion>();
List<GeneralRegion> noRegion = new ArrayList<GeneralRegion>();
List<GeneralRegion> incorrectDuration = new ArrayList<GeneralRegion>();
List<GeneralRegion> noWorld = new ArrayList<>();
List<GeneralRegion> noRegion = new ArrayList<>();
List<GeneralRegion> incorrectDuration = new ArrayList<>();
for(GeneralRegion region : AreaShop.getInstance().getFileManager().getRegions()) {
// Add broken regions to a list
if(region != null) {
@ -1039,7 +969,7 @@ public class FileManager {
}
// All files are loaded, print possible problems to the console
if(!noRegion.isEmpty()) {
List<String> noRegionNames = new ArrayList<String>();
List<String> noRegionNames = new ArrayList<>();
for(GeneralRegion region : noRegion) {
noRegionNames.add(region.getName());
}
@ -1048,7 +978,7 @@ public class FileManager {
}
boolean noWorldRegions = !noWorld.isEmpty();
while(!noWorld.isEmpty()) {
List<GeneralRegion> toDisplay = new ArrayList<GeneralRegion>();
List<GeneralRegion> toDisplay = new ArrayList<>();
String missingWorld = noWorld.get(0).getWorldName();
toDisplay.add(noWorld.get(0));
for(int i=1; i<noWorld.size(); i++) {
@ -1056,7 +986,7 @@ public class FileManager {
toDisplay.add(noWorld.get(i));
}
}
List<String> noWorldNames = new ArrayList<String>();
List<String> noWorldNames = new ArrayList<>();
for(GeneralRegion region : noRegion) {
noWorldNames.add(region.getName());
}
@ -1067,7 +997,7 @@ public class FileManager {
plugin.getLogger().warning("Remove these regions from AreaShop with '/as del' or load the world(s) on the server again.");
}
if(!incorrectDuration.isEmpty()) {
List<String> incorrectDurationNames = new ArrayList<String>();
List<String> incorrectDurationNames = new ArrayList<>();
for(GeneralRegion region : incorrectDuration) {
incorrectDurationNames.add(region.getName());
}
@ -1105,8 +1035,8 @@ public class FileManager {
boolean buyFileFound = false, rentFileFound = false;
if(rentFile.exists()) {
rentFileFound = true;
if(!oldFolderFile.exists()) {
oldFolderFile.mkdirs();
if(!oldFolderFile.exists() & !oldFolderFile.mkdirs()) {
plugin.getLogger().warning("Could not create directory: " + oldFolderFile.getAbsolutePath());
}
if(versions.get("rents") == null) {
@ -1124,8 +1054,12 @@ public class FileManager {
// Delete the file if it is totally wrong
if(rents == null) {
try {
rentFile.delete();
} catch(Exception e) {}
if(!rentFile.delete()) {
plugin.getLogger().warning("Could not delete file: " + rentFile.getAbsolutePath());
}
} catch(Exception e) {
plugin.getLogger().warning("Could not delete file: " + rentFile.getAbsolutePath());
}
} else {
// Move old file
try {
@ -1134,26 +1068,26 @@ public class FileManager {
plugin.getLogger().warning(" Could not create a backup of '" + rentPath + "', check the file permissions (conversion to next version continues)");
}
// Check if conversion is needed
if(versions.get("rents") < 1) {
/* Upgrade the rent to the latest version */
if(versions.get("rents") < 1) {
// Upgrade the rent to the latest version
if(versions.get("rents") < 0) {
for(String rentName : rents.keySet()) {
HashMap<String,String> rent = rents.get(rentName);
/* Save the rentName in the hashmap and use a small caps rentName as key */
// Save the rentName in the hashmap and use a small caps rentName as key
if(rent.get("name") == null) {
rent.put("name", rentName);
rents.remove(rentName);
rents.put(rentName.toLowerCase(), rent);
}
/* Save the default setting for region restoring */
// Save the default setting for region restoring
if(rent.get("restore") == null) {
rent.put("restore", "general");
}
/* Save the default setting for the region restore profile */
// Save the default setting for the region restore profile
if(rent.get("profile") == null) {
rent.put("profile", "default");
}
/* Change to version 0 */
// Change to version 0
versions.put("rents", 0);
}
plugin.getLogger().info(" Updated version of '" + buyPath + "' from -1 to 0 (switch to using lowercase region names, adding default schematic enabling and profile)");
@ -1166,8 +1100,8 @@ public class FileManager {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(rent.get("player"));
rent.put("playeruuid", offlinePlayer.getUniqueId().toString());
rent.remove("player");
}
/* Change version to 1 */
}
// Change version to 1
versions.put("rents", 1);
}
plugin.getLogger().info(" Updated version of '" + rentPath + "' from 0 to 1 (switch to UUID's for player identification)");
@ -1175,8 +1109,9 @@ public class FileManager {
}
// Save rents to new format
File regionsFile = new File(regionsPath);
if(!regionsFile.exists()) {
regionsFile.mkdirs();
if(!regionsFile.exists() & !regionsFile.mkdirs()) {
plugin.getLogger().warning("Could not create directory: " + regionsFile.getAbsolutePath());
return;
}
for(HashMap<String, String> rent : rents.values()) {
YamlConfiguration config = new YamlConfiguration();
@ -1224,8 +1159,9 @@ public class FileManager {
}
if(buyFile.exists()) {
buyFileFound = true;
if(!oldFolderFile.exists()) {
oldFolderFile.mkdirs();
if(!oldFolderFile.exists() & !oldFolderFile.mkdirs()) {
plugin.getLogger().warning("Could not create directory: " + oldFolderFile.getAbsolutePath());
return;
}
if(versions.get("buys") == null) {
@ -1243,8 +1179,12 @@ public class FileManager {
// Delete the file if it is totally wrong
if(buys == null) {
try {
buyFile.delete();
} catch(Exception e) {}
if(!buyFile.delete()) {
plugin.getLogger().warning("Could not delete file: " + buyFile.getAbsolutePath());
}
} catch(Exception e) {
plugin.getLogger().warning("Could not delete file: " + buyFile.getAbsolutePath());
}
} else {
// Backup current file
try {
@ -1253,26 +1193,26 @@ public class FileManager {
plugin.getLogger().warning(" Could not create a backup of '" + buyPath + "', check the file permissions (conversion to next version continues)");
}
// Check if conversion is needed
if(versions.get("buys") < 1) {
/* Upgrade the buy to the latest version */
if(versions.get("buys") < 1) {
// Upgrade the buy to the latest version
if(versions.get("buys") < 0) {
for(String buyName : buys.keySet()) {
HashMap<String,String> buy = buys.get(buyName);
/* Save the buyName in the hashmap and use a small caps buyName as key */
// Save the buyName in the hashmap and use a small caps buyName as key
if(buy.get("name") == null) {
buy.put("name", buyName);
buys.remove(buyName);
buys.put(buyName.toLowerCase(), buy);
}
/* Save the default setting for region restoring */
// Save the default setting for region restoring
if(buy.get("restore") == null) {
buy.put("restore", "general");
}
/* Save the default setting for the region restore profile */
// Save the default setting for the region restore profile
if(buy.get("profile") == null) {
buy.put("profile", "default");
}
/* Change to version 0 */
// Change to version 0
versions.put("buys", 0);
}
plugin.getLogger().info(" Updated version of '" + buyPath + "' from -1 to 0 (switch to using lowercase region names, adding default schematic enabling and profile)");
@ -1285,8 +1225,8 @@ public class FileManager {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(buy.get("player"));
buy.put("playeruuid", offlinePlayer.getUniqueId().toString());
buy.remove("player");
}
/* Change version to 1 */
}
// Change version to 1
versions.put("buys", 1);
}
plugin.getLogger().info(" Updated version of '" + buyPath + "' from 0 to 1 (switch to UUID's for player identification)");
@ -1295,8 +1235,8 @@ public class FileManager {
// Save buys to new format
File regionsFile = new File(regionsPath);
if(!regionsFile.exists()) {
regionsFile.mkdirs();
if(!regionsFile.exists() & !regionsFile.mkdirs()) {
plugin.getLogger().warning("Could not create directory: " + regionsFile.getAbsolutePath());
}
for(HashMap<String, String> buy : buys.values()) {
YamlConfiguration config = new YamlConfiguration();
@ -1342,14 +1282,20 @@ public class FileManager {
// Separate try-catch blocks to try them all individually (don't stop after 1 has failed)
try {
Files.move(new File(rentPath + ".old"), new File(oldFolderPath + "rents.old"));
} catch (Exception e) {}
} catch(Exception e) {
// Ignore
}
try {
Files.move(new File(buyPath + ".old"), new File(oldFolderPath + "buys.old"));
} catch (Exception e) {}
} catch(Exception e) {
// Ignore
}
if(buyFileFound || rentFileFound) {
try {
Files.move(new File(plugin.getDataFolder() + File.separator + "config.yml"), new File(oldFolderPath + "config.yml"));
} catch (Exception e) {}
} catch(Exception e) {
// Ignore
}
}
// Update versions file to 2
versions.put(AreaShop.versionFiles, 2);

View File

@ -1,24 +1,15 @@
package nl.evolutioncoding.areashop.managers;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import com.google.common.base.Charsets;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.base.Charsets;
public class LanguageManager {
private AreaShop plugin = null;
private String languages[] = {"EN", "NL", "DE", "FR", "FI", "PL", "ZH_TW"};
@ -49,7 +40,10 @@ public class LanguageManager {
File langFolder;
langFolder = new File(plugin.getDataFolder() + File.separator + AreaShop.languageFolder);
if(!langFolder.exists()) {
langFolder.mkdirs();
if(!langFolder.mkdirs()) {
plugin.getLogger().warning("Could not create language directory: " + langFolder.getAbsolutePath());
return;
}
}
/* Create the language files, overwrites if a file already exists */
@ -57,19 +51,17 @@ public class LanguageManager {
/* files would not be used, when translating your own use another */
/* file name as the default */
File langFile;
for(int i=0; i<languages.length; i++) {
langFile = new File(plugin.getDataFolder() + File.separator + AreaShop.languageFolder + File.separator + languages[i] + ".yml");
InputStream input = null;
OutputStream output = null;
try {
input = plugin.getResource(AreaShop.languageFolder + "/" + languages[i] + ".yml");
for(String language : languages) {
langFile = new File(plugin.getDataFolder() + File.separator + AreaShop.languageFolder + File.separator + language + ".yml");
try(
InputStream input = plugin.getResource(AreaShop.languageFolder + "/" + language + ".yml");
OutputStream output = new FileOutputStream(langFile)
) {
if(input == null) {
plugin.getLogger().warning("Could not save default language to the '" + AreaShop.languageFolder + "' folder: " + languages[i] + ".yml");
plugin.getLogger().warning("Could not save default language to the '" + AreaShop.languageFolder + "' folder: " + language + ".yml");
continue;
}
output = new FileOutputStream(langFile);
int read = 0;
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
output.write(bytes, 0, read);
@ -77,11 +69,6 @@ public class LanguageManager {
input.close();
output.close();
} catch(IOException e) {
try {
input.close();
output.close();
} catch (IOException e1) {} catch (NullPointerException e2) {}
plugin.getLogger().warning("Something went wrong saving a default language file: " + langFile.getPath());
}
}
@ -95,41 +82,42 @@ public class LanguageManager {
Map<String, Object> map;
Set<String> set;
YamlConfiguration ymlFile;
/* Save the current language file to the HashMap */
currentLanguage = new HashMap<String, String>();
// Save the current language file to the HashMap
currentLanguage = new HashMap<>();
File file = new File(plugin.getDataFolder() + File.separator + AreaShop.languageFolder + File.separator + plugin.getConfig().getString("language") + ".yml");
InputStreamReader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
} catch (FileNotFoundException e1) {}
if(reader != null) {
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)
) {
ymlFile = YamlConfiguration.loadConfiguration(reader);
map = ymlFile.getValues(true);
set = map.keySet();
try {
for(String key : set) {
for(String key : set) {
if(map.get(key) instanceof String) {
currentLanguage.put(key, (String)map.get(key));
}
} catch(ClassCastException e) {}
}
} catch(IOException e) {
plugin.getLogger().warning("Could not load set language file: " + file.getAbsolutePath());
}
/* Save the default strings to the HashMap */
defaultLanguage = new HashMap<String, String>();
// Save the default strings to the HashMap
defaultLanguage = new HashMap<>();
File standard = new File(plugin.getDataFolder() + File.separator + AreaShop.languageFolder + "/" + languages[0]+ ".yml");
InputStreamReader reader2 = null;
try {
reader2 = new InputStreamReader(new FileInputStream(standard), Charsets.UTF_8);
} catch (FileNotFoundException e1) {}
if(reader2 != null) {
ymlFile = YamlConfiguration.loadConfiguration(reader2);
map = ymlFile.getValues(true);
try(
InputStreamReader reader = new InputStreamReader(new FileInputStream(standard), Charsets.UTF_8)
) {
ymlFile = YamlConfiguration.loadConfiguration(reader);
map = ymlFile.getValues(true);
set = map.keySet();
try {
for(String key : set) {
for(String key : set) {
if(map.get(key) instanceof String) {
defaultLanguage.put(key, (String)map.get(key));
}
} catch(ClassCastException e) {}
}
} catch(IOException e) {
plugin.getLogger().warning("Could not load default language file: " + file.getAbsolutePath());
}
}
@ -140,9 +128,9 @@ public class LanguageManager {
* @return String The language string specified with the key
*/
public String getLang(String key, Object... params) {
String result = null;
/* Get the language string */
String result;
// Get the language string
if(currentLanguage.containsKey(key)) {
result = currentLanguage.get(key);
} else {
@ -152,15 +140,15 @@ public class LanguageManager {
if(result == null) {
plugin.getLogger().info("Wrong key for getting translation: " + key + ", please contact the author about this");
} else {
/* Replace all tags like %0% and if given a GeneralRegion apply all replacements */
// Replace all tags like %0% and if given a GeneralRegion apply all replacements
int number=0;
for (int i=0; i<params.length; i++) {
if(params[i] != null) {
if(params[i] instanceof GeneralRegion) {
result = ((GeneralRegion)params[i]).applyAllReplacements(result);
} else {
result = result.replace("%" + number + "%", params[i].toString());
number++;
for(Object param : params) {
if(param != null) {
if(param instanceof GeneralRegion) {
result = ((GeneralRegion)param).applyAllReplacements(result);
} else {
result = result.replace("%" + number + "%", param.toString());
number++;
}
}
}

View File

@ -1,16 +1,8 @@
package nl.evolutioncoding.areashop.managers;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.Utils;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -26,6 +18,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.material.Sign;
import org.bukkit.util.BlockIterator;
import java.util.*;
public class SignLinkerManager implements Listener {
private AreaShop plugin = null;
private Map<UUID, SignLinker> signLinkers;
@ -33,7 +27,7 @@ public class SignLinkerManager implements Listener {
public SignLinkerManager(AreaShop plugin) {
this.plugin = plugin;
signLinkers = new HashMap<UUID, SignLinker>();
signLinkers = new HashMap<>();
eventsRegistered = false;
}
@ -91,7 +85,7 @@ public class SignLinkerManager implements Listener {
linker.setRegion(regions.get(0));
return;
} else if(regions.size() > 1) {
Set<String> names = new HashSet<String>();
Set<String> names = new HashSet<>();
for(GeneralRegion region : regions) {
names.add(region.getName());
}
@ -102,7 +96,6 @@ public class SignLinkerManager implements Listener {
}
// No regions found within the maximum range
plugin.message(player, "linksigns-noRegions");
return;
} else if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
@ -116,7 +109,7 @@ public class SignLinkerManager implements Listener {
plugin.message(player, "linksigns-noSign");
return;
}
GeneralRegion signRegion = plugin.getFileManager().getRegionBySignLocation(block.getLocation());
if(signRegion != null) {
plugin.message(player, "linksigns-alreadyRegistered", signRegion);
@ -124,9 +117,7 @@ public class SignLinkerManager implements Listener {
}
Sign sign = (Sign)block.getState().getData();
linker.setSign(block.getLocation(), block.getType(), sign.getFacing());
return;
}
}
}
@ -166,7 +157,7 @@ public class SignLinkerManager implements Listener {
if(!isComplete()) {
plugin.message(linker, "linksigns-regionFound", region);
}
finalize();
finish();
}
public void setSign(Location location, Material type, BlockFace facing) {
@ -177,10 +168,10 @@ public class SignLinkerManager implements Listener {
if(!isComplete()) {
plugin.message(linker, "linksigns-signFound", location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
finalize();
finish();
}
public void finalize() {
public void finish() {
if(isComplete()) {
region.addSign(location, type, facing, profile);
if(profile == null) {

View File

@ -1,18 +1,17 @@
package nl.evolutioncoding.areashop.regions;
import java.util.Calendar;
import java.util.HashMap;
import java.util.UUID;
import net.milkbowl.vault.economy.EconomyResponse;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.util.Calendar;
import java.util.HashMap;
import java.util.UUID;
public class BuyRegion extends GeneralRegion {
public BuyRegion(AreaShop plugin, YamlConfiguration config) {
@ -48,7 +47,9 @@ public class BuyRegion extends GeneralRegion {
if(buyer != null) {
try {
return UUID.fromString(buyer);
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// Incorrect UUID
}
}
return null;
}
@ -59,19 +60,11 @@ public class BuyRegion extends GeneralRegion {
* @return true if this player owns this region, otherwise false
*/
public boolean isBuyer(Player player) {
if(player == null) {
return false;
} else {
return isBuyer(player.getUniqueId());
}
return player != null && isBuyer(player.getUniqueId());
}
public boolean isBuyer(UUID player) {
UUID buyer = getBuyer();
if(buyer == null || player == null) {
return false;
} else {
return buyer.equals(player);
}
return !(buyer == null || player == null) && buyer.equals(player);
}
/**
@ -153,7 +146,7 @@ public class BuyRegion extends GeneralRegion {
/**
* Change the price of the region
* @param price
* @param price The price to set this region to
*/
public void setPrice(double price) {
setSetting("buy.price", price);
@ -210,7 +203,7 @@ public class BuyRegion extends GeneralRegion {
@Override
public HashMap<String, Object> getSpecificReplacements() {
// Fill the replacements map with things specific to a BuyRegion
HashMap<String, Object> result = new HashMap<String, Object>();
HashMap<String, Object> result = new HashMap<>();
result.put(AreaShop.tagPrice, getFormattedPrice());
result.put(AreaShop.tagRawPrice, getPrice());
result.put(AreaShop.tagPlayerName, getPlayerName());
@ -252,7 +245,7 @@ public class BuyRegion extends GeneralRegion {
*/
@SuppressWarnings("deprecation")
public boolean buy(Player player) {
/* Check if the player has permission */
// Check if the player has permission
if(player.hasPermission("areashop.buy")) {
if(plugin.getEconomy() == null) {
plugin.message(player, "general-noEconomy");
@ -276,7 +269,7 @@ public class BuyRegion extends GeneralRegion {
if(getRegion() == null) {
plugin.message(player, "general-noRegion", getName());
return false;
}
}
if(!isSold() || (isInResellingMode() && !isBuyer(player))) {
boolean isResell = isInResellingMode();
// Check if the players needs to be in the world or region for buying
@ -304,14 +297,14 @@ public class BuyRegion extends GeneralRegion {
// Should not be reached, but is safe like this
return false;
}
/* Check if the player has enough money */
// Check if the player has enough money
if((!isResell && plugin.getEconomy().has(player, getWorldName(), getPrice())) || (isResell && plugin.getEconomy().has(player, getWorldName(), getResellPrice()))) {
UUID oldOwner = getBuyer();
if(isResell && oldOwner != null) {
clearFriends();
double resellPrice = getResellPrice();
/* Transfer the money to the previous owner */
// Transfer the money to the previous owner
EconomyResponse r = plugin.getEconomy().withdrawPlayer(player, getWorldName(), getResellPrice());
if(!r.transactionSuccess()) {
plugin.message(player, "buy-payError");
@ -322,11 +315,12 @@ public class BuyRegion extends GeneralRegion {
String oldOwnerName = getPlayerName();
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
oldOwnerName = oldOwnerPlayer.getName();
} else if (oldOwnerName != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
}
if(r == null || !r.transactionSuccess()) {
plugin.getLogger().warning("Something went wrong with paying '" + oldOwnerPlayer.getName() + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + player.getName());
plugin.getLogger().warning("Something went wrong with paying '" + oldOwnerName + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + player.getName());
}
// Resell is done, disable that now
disableReselling();
@ -342,12 +336,12 @@ public class BuyRegion extends GeneralRegion {
updateRegionFlags();
// Send message to the player
plugin.message(player, "buy-successResale", getName(), oldOwnerPlayer.getName());
plugin.message(player, "buy-successResale", getName(), oldOwnerName);
Player seller = Bukkit.getPlayer(oldOwner);
if(seller != null) {
plugin.message(player, "buy-successSeller", getName(), getPlayerName(), resellPrice);
}
AreaShop.debug(player.getName() + " has bought region " + getName() + " for " + getFormattedPrice() + " from " + oldOwnerPlayer.getName());
}
AreaShop.debug(player.getName() + " has bought region " + getName() + " for " + getFormattedPrice() + " from " + oldOwnerName);
// Run commands
this.runEventCommands(RegionEvent.RESELL, false);
} else {
@ -363,7 +357,6 @@ public class BuyRegion extends GeneralRegion {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
r = null;
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
@ -394,8 +387,8 @@ public class BuyRegion extends GeneralRegion {
}
return true;
} else {
/* Player has not enough money */
String requiredMoney = "";
// Player has not enough money
String requiredMoney;
if(isResell) {
requiredMoney = getFormattedResellPrice();
} else {
@ -418,10 +411,13 @@ public class BuyRegion extends GeneralRegion {
/**
* Sell a buyed region, get part of the money back
* @param regionName
* @param giveMoneyBack true if the player should be given money back, otherwise false
*/
@SuppressWarnings("deprecation")
public void sell(boolean giveMoneyBack) {
if(plugin.getEconomy() == null) {
return;
}
// Run commands
this.runEventCommands(RegionEvent.SOLD, true);
@ -435,7 +431,7 @@ public class BuyRegion extends GeneralRegion {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
EconomyResponse r = null;
EconomyResponse r;
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().withdrawPlayer(landlordPlayer, getWorldName(), moneyBack);
@ -453,7 +449,7 @@ public class BuyRegion extends GeneralRegion {
EconomyResponse response = null;
boolean error = false;
try {
if(player != null && player.getName() != null) {
if(player.getName() != null) {
response = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
} else if(getPlayerName() != null) {
response = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
@ -471,13 +467,14 @@ public class BuyRegion extends GeneralRegion {
// Update everything
handleSchematicEvent(RegionEvent.SOLD);
updateRegionFlags(RegionState.FORSALE);
AreaShop.debug("friends before sell: " + getFriendNames().toString());
// Remove friends and the owner
clearFriends();
setBuyer(null);
removeLastActiveTime();
updateRegionFlags(RegionState.FORSALE);
updateSigns();
// Run commands
this.runEventCommands(RegionEvent.SOLD, false);

View File

@ -1,40 +1,5 @@
package nl.evolutioncoding.areashop.regions;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
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;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
@ -43,13 +8,35 @@ 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 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;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class GeneralRegion implements GeneralRegionInterface, Comparable<GeneralRegion> {
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));
private static ArrayList<Material> cannotSpawnBeside = new ArrayList<Material>(Arrays.asList(Material.LAVA, Material.STATIONARY_LAVA, Material.CACTUS));
protected AreaShop plugin = null;
YamlConfiguration config;
private static ArrayList<Material> canSpawnIn = new ArrayList<>(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<>(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));
private static ArrayList<Material> cannotSpawnBeside = new ArrayList<>(Arrays.asList(Material.LAVA, Material.STATIONARY_LAVA, Material.CACTUS));
AreaShop plugin = null;
private boolean saveRequired = false;
private boolean deleted = false;
@ -62,7 +49,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
BUY("buy");
private final String value;
private RegionType(String value) {
RegionType(String value) {
this.value = value;
}
public String getValue() {
@ -82,7 +70,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
RESELL("resell");
private final String value;
private RegionEvent(String value) {
RegionEvent(String value) {
this.value = value;
}
public String getValue() {
@ -99,7 +88,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
RESELL("resell");
private final String value;
private RegionState(String value) {
RegionState(String value) {
this.value = value;
}
public String getValue() {
@ -115,7 +105,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
SHIFTLEFTCLICK("shiftLeftClick");
private final String value;
private ClickType(String value) {
ClickType(String value) {
this.value = value;
}
public String getValue() {
@ -131,20 +122,21 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
EXTEND("extend");
private final String value;
private LimitType(String value) {
LimitType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public GeneralRegion(AreaShop plugin, YamlConfiguration config) {
}
GeneralRegion(AreaShop plugin, YamlConfiguration config) {
this.plugin = plugin;
this.config = config;
}
protected GeneralRegion(AreaShop plugin, String name, World world) {
GeneralRegion(AreaShop plugin, String name, World world) {
this.plugin = plugin;
config = new YamlConfiguration();
@ -161,8 +153,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
public abstract RegionType getType();
// Sorting by name
/**
* Compare this region to another region by name
* @param o The region to compare to
* @return 0 if the names are the same, below zero if this region is earlier in the alphabet, otherwise above zero
*/
@Override
public int compareTo(GeneralRegion o) {
public int compareTo(@Nonnull GeneralRegion o) {
return getName().compareTo(o.getName());
}
@ -226,7 +224,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return A List with all sign locations
*/
public List<Location> getSignLocations() {
List<Location> result = new ArrayList<Location>();
List<Location> result = new ArrayList<>();
if(config.getConfigurationSection("general.signs") == null) {
return result;
}
@ -241,14 +239,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return The teleport location, or null if not set
*/
public Location getTeleportLocation() {
Location result = null;
Location result;
result = Utils.configToLocation(config.getConfigurationSection("general.teleportLocation"));
return result;
}
/**
* Check if the region has been deleted
* @return
* @return true if the region has been deleted, otherwise false
*/
public boolean isDeleted() {
return deleted;
@ -383,7 +381,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(landlord != null) {
try {
return UUID.fromString(landlord);
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// Incorrect UUID
}
}
return null;
}
@ -413,8 +413,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
setSetting("general.landlord", landlord.toString());
}
String properName = plugin.toName(landlord);
if(properName != null) {
name = properName;
if(properName == null) {
properName = name;
}
setSetting("general.landlordName", properName);
}
@ -486,7 +486,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return A Set with all groups of this region
*/
public Set<RegionGroup> getGroups() {
Set<RegionGroup> result = new HashSet<RegionGroup>();
Set<RegionGroup> result = new HashSet<>();
for(RegionGroup group : plugin.getFileManager().getGroups()) {
if(group.isMember(this)) {
result.add(group);
@ -500,7 +500,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return A list of groups this region is part of
*/
public List<String> getGroupNames() {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
for(RegionGroup group : getGroups()) {
result.add(group.getName());
}
@ -634,9 +634,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @param player The UUID of the player to add
*/
public void addFriend(UUID player) {
Set<String> friends = new HashSet<String>(config.getStringList("general.friends"));
Set<String> friends = new HashSet<>(config.getStringList("general.friends"));
friends.add(player.toString());
List<String> list = new ArrayList<String>(friends);
List<String> list = new ArrayList<>(friends);
setSetting("general.friends", list);
}
@ -645,9 +645,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @param player The UUID of the player to delete
*/
public void deleteFriend(UUID player) {
Set<String> friends = new HashSet<String>(config.getStringList("general.friends"));
Set<String> friends = new HashSet<>(config.getStringList("general.friends"));
friends.remove(player.toString());
List<String> list = new ArrayList<String>(friends);
List<String> list = new ArrayList<>(friends);
if(list.isEmpty()) {
setSetting("general.friends", null);
} else {
@ -660,13 +660,11 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return Friends added to this region
*/
public Set<UUID> getFriends() {
HashSet<UUID> result = new HashSet<UUID>();
HashSet<UUID> result = new HashSet<>();
for(String friend : config.getStringList("general.friends")) {
try {
UUID id = UUID.fromString(friend);
if(id != null) {
result.add(id);
}
result.add(id);
} catch(IllegalArgumentException e) {
// Don't add it
}
@ -679,7 +677,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return Friends added to this region
*/
public Set<String> getFriendNames() {
HashSet<String> result = new HashSet<String>();
HashSet<String> result = new HashSet<>();
for(UUID friend : getFriends()) {
OfflinePlayer player = Bukkit.getOfflinePlayer(friend);
if(player != null) {
@ -765,7 +763,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
* @return true if this region has a sign at the location, otherwise false
*/
public boolean isSignOfRegion(Location location) {
Set<String> signs = null;
Set<String> signs;
if(config.getConfigurationSection("general.signs") == null) {
return false;
}
@ -785,14 +783,13 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Check if a sign needs periodic updating
* @param signName
* @return
* @return true if the signs of this region need periodic updating, otherwise false
*/
public boolean needsPeriodicUpdating() {
if(isDeleted() || !isRentRegion()) {
return false;
}
Set<String> signs = new HashSet<String>();
Set<String> signs = new HashSet<>();
if(config.getConfigurationSection("general.signs") != null) {
signs = config.getConfigurationSection("general.signs").getKeys(false);
}
@ -804,7 +801,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
// Get the prefix
String prefix = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + ".line";
String line = null;
String line;
// Get the lines
for(int i=1; i<5; i++) {
line = plugin.getConfig().getString(prefix + i);
@ -835,8 +832,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
for(String sign : signs) {
Location location = Utils.configToLocation(config.getConfigurationSection("general.signs." + sign + ".location"));
if(location == null) {
// TODO: Remove the sign if the location is wrong?
AreaShop.debug(" location null");
AreaShop.debug("Sign location incorrect region=" + getName() + ", signKey="+sign);
result = false;
} else {
// Get the profile set in the config
@ -845,7 +841,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
profile = getStringSetting("general.signProfile");
}
// Get the prefix
String prefix = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + ".";
String prefix = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + ".";
// Get the lines
String[] signLines = new String[4];
signLines[0] = plugin.getConfig().getString(prefix + "line1");
@ -854,16 +850,16 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
signLines[3] = plugin.getConfig().getString(prefix + "line4");
// Check if the sign should be present
Block block = location.getBlock();
if(!plugin.getConfig().isSet(prefix)
|| ( (signLines[0] == null || signLines[0].length() == 0)
&& (signLines[1] == null || signLines[1].length() == 0)
&& (signLines[2] == null || signLines[2].length() == 0)
if(!plugin.getConfig().isSet(prefix)
|| ((signLines[0] == null || signLines[0].length() == 0)
&& (signLines[1] == null || signLines[1].length() == 0)
&& (signLines[2] == null || signLines[2].length() == 0)
&& (signLines[3] == null || signLines[3].length() == 0) )) {
block.setType(Material.AIR);
} else {
} else {
Sign signState = null;
if(block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) {
Material signType = null;
Material signType;
try {
signType = Material.valueOf(config.getString("general.signs." + sign + ".signType"));
} catch(NullPointerException | IllegalArgumentException e) {
@ -902,14 +898,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(signLines[i] == null) {
signState.setLine(i, "");
continue;
}
signLines[i] = applyAllReplacements(signLines[i]);
signLines[i] = plugin.fixColors(signLines[i]);
}
signLines[i] = applyAllReplacements(signLines[i]);
signLines[i] = plugin.fixColors(signLines[i]);
signState.setLine(i, signLines[i]);
}
signState.update();
}
}
}
}
return result;
}
@ -932,10 +928,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Save all blocks in a region for restoring later
* @param regionName The name of the region
* @param world The world that it is in
* @param fileName The name of the file to save to (extension and folder will be added)
* @return
* @return true if the region has been saved properly, otherwise false
*/
public boolean saveRegionBlocks(String fileName) {
// Check if the region is correct
@ -963,10 +957,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Restore all blocks in a region for restoring later
* @param regionName The name of the region
* @param world The world that it is in
* @param fileName The name of the file to save to (extension and folder will be added)
* @return
* @return true if the region has been restored properly, otherwise false
*/
public boolean restoreRegionBlocks(String fileName) {
if(getRegion() == null) {
@ -1052,10 +1044,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Set the region flags/options to the values of a ConfigurationSection
* @param player The player that does it
* @param region The region
* @param flags
* @return
* @param flags The configuration settings to apply to the region
* @return true if the flags have been set correctly, otherwise false
*/
protected boolean setRegionFlags(ConfigurationSection flags) {
boolean result = true;
@ -1072,10 +1062,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
AreaShop.debug("Region '" + getName() + "' does not exist, setting flags failed");
return false;
}
Iterator<String> it = flagNames.iterator();
// Loop through all flags that are set in the config
while(it.hasNext()) {
String flagName = it.next();
for(String flagName : flagNames) {
String value = flags.getString(flagName);
value = applyAllReplacements(value);
// In the config normal Bukkit color codes are used, those only need to be translated on 5.X WorldGuard versions
@ -1129,7 +1117,6 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
region.setFlag(groupFlag, null);
}
//AreaShop.debug(" Flag " + flagName + " reset (+ possible group of flag)");
continue;
} else {
if(groupFlag == null) {
flagSetting = value;
@ -1176,9 +1163,9 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
plugin.getFileManager().saveIsRequiredForRegionWorld(getWorldName());
return result;
}
/**
* Translate the color codes you put in greeting/farwell messages to the weird color codes of WorldGuard
* Translate the color codes you put in greeting/farewell messages to the weird color codes of WorldGuard
* @param message The message where the color codes should be translated (this message has bukkit color codes)
* @return The string with the WorldGuard color codes
*/
@ -1241,8 +1228,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Set the teleport location of this region
* @param regionName
* @param location
* @param location The location to set as teleport location
*/
public void setTeleport(Location location) {
if(location == null) {
@ -1256,12 +1242,11 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
/**
* Teleport a player to the region
* @param player Player that should be teleported
* @param regionName The name of the region the player should be teleported to
* @param checkPermissions Set to true if teleport permissions should be checked, false otherwise
*/
public boolean teleportPlayer(Player player, boolean toSign, boolean checkPermissions) {
int checked = 1;
boolean owner = false;
boolean owner;
boolean friend = getFriends().contains(player.getUniqueId());
Location startLocation = null;
ProtectedRegion region = getRegion();
@ -1440,7 +1425,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
}
}
west = west || !west;
west = west || !track;
// Top side
track = false;
@ -1606,7 +1591,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
return false;
}
// Check all blocks around
ArrayList<Material> around = new ArrayList<Material>(Arrays.asList(
ArrayList<Material> around = new ArrayList<>(Arrays.asList(
feet.getRelative(BlockFace.NORTH).getType(),
feet.getRelative(BlockFace.NORTH_EAST).getType(),
feet.getRelative(BlockFace.EAST).getType(),
@ -1814,14 +1799,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(extend) {
exclude = this;
}
String typePath = null;
String typePath;
if(type == RegionType.RENT) {
typePath = "rents";
} else {
typePath = "buys";
}
// Check all limitgroups the player has
List<String> groups = new ArrayList<String>(plugin.getConfig().getConfigurationSection("limitGroups").getKeys(false));
List<String> groups = new ArrayList<>(plugin.getConfig().getConfigurationSection("limitGroups").getKeys(false));
while(!groups.isEmpty()) {
String group = groups.get(0);
if(player.hasPermission("areashop.limits." + group) && this.matchesLimitGroup(group)) {
@ -1829,7 +1814,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
int typeLimit = plugin.getConfig().getInt("limitGroups." + group + "."+typePath);
//AreaShop.debug("typeLimitOther="+typeLimit+", typePath="+typePath);
int totalCurrent = hasRegionsInLimitGroup(player, group, plugin.getFileManager().getRegions(), exclude);
int typeCurrent = 0;
int typeCurrent;
if(type == RegionType.RENT) {
typeCurrent = hasRegionsInLimitGroup(player, group, plugin.getFileManager().getRents(), exclude);
} else {
@ -1845,7 +1830,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
String typeHighestGroup = group;
groups.remove(group);
// Get the highest number from the groups of the same category
List<String> groupsCopy = new ArrayList<String>(groups);
List<String> groupsCopy = new ArrayList<>(groups);
for(String checkGroup : groupsCopy) {
if(player.hasPermission("areashop.limits." + checkGroup) && this.matchesLimitGroup(checkGroup)) {
if(limitGroupsOfSameCategory(group, checkGroup)) {
@ -1871,7 +1856,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
// Check if the limits stop the player from buying the region
if(typeCurrent >= typeLimit) {
LimitType limitType = null;
LimitType limitType;
if(type == RegionType.RENT) {
if(extend) {
limitType = LimitType.EXTEND;
@ -1944,17 +1929,15 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
List<String> firstWorlds = plugin.getConfig().getStringList("limitGroups." + firstGroup + ".worlds");
List<String> secondWorlds = plugin.getConfig().getStringList("limitGroups." + secondGroup + ".worlds");
if(!firstWorlds.containsAll(secondWorlds) || !secondWorlds.containsAll(firstWorlds)) {
return false;
}
return true;
return !(!firstWorlds.containsAll(secondWorlds) || !secondWorlds.containsAll(firstWorlds));
}
/**
* Get the amount of regions a player has matching a certain limits group (config.yml > limitGroups)
* @param player The player to check the amount for
* @param limitGroup The group to check
* @param buyRegions All the regions a player has bought or rented
* @param regions All the regions a player has bought or rented
* @param exclude Exclude this region from the count
* @return The number of regions that the player has bought or rented matching the limit group (worlds and groups filters)
*/
public int hasRegionsInLimitGroup(Player player, String limitGroup, List<? extends GeneralRegion> regions, GeneralRegion exclude) {
@ -2033,8 +2016,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
continue;
}
command = applyAllReplacements(command);
boolean result = false;
boolean result;
String error = null;
String stacktrace = null;
try {
@ -2059,7 +2042,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
if(error == null) {
AreaShop.debug("Command run, executor=" + sender.getName() + ", command=" + command + ", result=" + result);
} else {
AreaShop.debug("Command run, executor=" + sender.getName() + ", command=" + command + ", result=" + result + ", error=" + error + ", stacktrace:");
AreaShop.debug("Command run, executor=" + sender.getName() + ", command=" + command + ", error=" + error + ", stacktrace:");
AreaShop.debug(stacktrace);
AreaShop.debug("--- End of stacktrace ---");
}
@ -2105,7 +2088,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
}
// Run player commands if specified
String playerPath = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + "." + clickType.getValue() + "Player";
List<String> playerCommands = new ArrayList<String>();
List<String> playerCommands = new ArrayList<>();
for(String command : plugin.getConfig().getStringList(playerPath)) {
playerCommands.add(command.replace(AreaShop.tagClicker, clicker.getName()));
}
@ -2113,7 +2096,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface, Comparabl
// Run console commands if specified
String consolePath = "signProfiles." + profile + "." + getState().getValue().toLowerCase() + "." + clickType.getValue() + "Console";
List<String> consoleCommands = new ArrayList<String>();
List<String> consoleCommands = new ArrayList<>();
for(String command : plugin.getConfig().getStringList(consolePath)) {
consoleCommands.add(command.replace(AreaShop.tagClicker, clicker.getName()));
}

View File

@ -1,14 +1,13 @@
package nl.evolutioncoding.areashop.regions;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.configuration.ConfigurationSection;
public class RegionGroup {
private AreaShop plugin;
@ -26,7 +25,7 @@ public class RegionGroup {
// Delete duplicates
List<String> members = getMembers();
int previousCount = members.size();
List<String> newMembers = new ArrayList<String>();
List<String> newMembers = new ArrayList<>();
while(!members.isEmpty()) {
String member = members.remove(0);
// If the region has been deleted also clean it from the group
@ -90,7 +89,7 @@ public class RegionGroup {
*/
public List<String> getMembers() {
if(getSettings() == null || getSettings().getStringList("regions") == null) {
return new ArrayList<String>();
return new ArrayList<>();
}
return getSettings().getStringList("regions");
}
@ -100,7 +99,7 @@ public class RegionGroup {
* @return A Set with all group members
*/
public Set<GeneralRegion> getMemberRegions() {
Set<GeneralRegion> result = new HashSet<GeneralRegion>();
Set<GeneralRegion> result = new HashSet<>();
for(String name : getMembers()) {
result.add(plugin.getFileManager().getRegion(name));
}

View File

@ -1,15 +1,7 @@
package nl.evolutioncoding.areashop.regions;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import net.milkbowl.vault.economy.EconomyResponse;
import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.exceptions.RegionCreateException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
@ -17,14 +9,19 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
public class RentRegion extends GeneralRegion {
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
public class RentRegion extends GeneralRegion {
private long warningsDoneUntil = Calendar.getInstance().getTimeInMillis();
/**
* Constructor
* @param plugin The areashop plugin
* @param settings All settings of this region
* @throws RegionCreateException
* @param config All settings of this region
*/
public RentRegion(AreaShop plugin, YamlConfiguration config) {
super(plugin, config);
@ -63,7 +60,9 @@ public class RentRegion extends GeneralRegion {
if(renter != null) {
try {
return UUID.fromString(renter);
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// Incorrect UUID
}
}
return null;
}
@ -74,19 +73,11 @@ public class RentRegion extends GeneralRegion {
* @return true if this player rents this region, otherwise false
*/
public boolean isRenter(Player player) {
if(player == null) {
return false;
} else {
return isRenter(player.getUniqueId());
}
return player != null && isRenter(player.getUniqueId());
}
public boolean isRenter(UUID player) {
UUID renter = getRenter();
if(player == null || renter == null) {
return false;
} else {
return renter.equals(player);
}
return !(player == null || renter == null) && renter.equals(player);
}
/**
@ -134,7 +125,7 @@ public class RentRegion extends GeneralRegion {
@Override
public HashMap<String, Object> getSpecificReplacements() {
// Fill the replacements map with things specific to a RentRegion
HashMap<String, Object> result = new HashMap<String, Object>();
HashMap<String, Object> result = new HashMap<>();
result.put(AreaShop.tagPrice, getFormattedPrice());
result.put(AreaShop.tagRawPrice, getPrice());
result.put(AreaShop.tagDuration, getDurationString());
@ -187,7 +178,7 @@ public class RentRegion extends GeneralRegion {
/**
* Get the time until this region is rented (time from 1970 epoch)
* @return
* @return The epoch time until which this region is rented
*/
public long getRentedUntil() {
return getLongSetting("rent.rentedUntil");
@ -275,7 +266,7 @@ public class RentRegion extends GeneralRegion {
/**
* Change the price of the region
* @param price
* @param price The price of the region
*/
public void setPrice(double price) {
setSetting("rent.price", price);
@ -314,8 +305,7 @@ public class RentRegion extends GeneralRegion {
double percentage = (getMoneyBackPercentage()) / 100.0;
Double timePeriod = (double) (getDuration());
double periods = timeLeft / timePeriod;
double moneyBack = periods * getPrice() * percentage;
return moneyBack;
return periods * getPrice() * percentage;
}
/**
@ -391,17 +381,16 @@ public class RentRegion extends GeneralRegion {
/**
* Rent a region
* @param player The player that wants to rent the region
* @param regionName The name of the region you want to rent
* @return true if it succeeded and false if not
*/
@SuppressWarnings("deprecation")
public boolean rent(Player player) {
public boolean rent(Player player) {
if(plugin.getEconomy() == null) {
plugin.message(player, "general-noEconomy");
return false;
}
//Check if the player has permission
if(player.hasPermission("areashop.rent")) {
if(plugin.getEconomy() == null) {
plugin.message(player, "general-noEconomy");
return false;
}
if(getWorld() == null) {
plugin.message(player, "general-noWorld", getWorldName());
return false;
@ -428,10 +417,10 @@ public class RentRegion extends GeneralRegion {
}
// Check region limits if this is not extending
if(!(extend && config.getBoolean("allowRegionExtendsWhenAboveLimits"))) {
LimitResult limitResult = null;
LimitResult limitResult;
if(extend) {
limitResult = this.limitsAllow(RegionType.RENT, player, extend);
limitResult = this.limitsAllow(RegionType.RENT, player, true);
} else {
limitResult = this.limitsAllow(RegionType.RENT, player);
}
@ -482,7 +471,7 @@ public class RentRegion extends GeneralRegion {
long toRentPart = maxRentTime - timeRented;
price = ((double)toRentPart)/getDuration()*price;
}
} else {
} else {
plugin.message(player, "rent-maxRentTime", this.millisToHumanFormat(maxRentTime), this.millisToHumanFormat(timeRented));
return false;
}
@ -501,7 +490,6 @@ public class RentRegion extends GeneralRegion {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
r = null;
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), price);
@ -586,10 +574,13 @@ public class RentRegion extends GeneralRegion {
/**
* Unrent a region, reset to unrented
* @param regionName Region that should be unrented
* @param giveMoneyBack true if money should be given back to the player, false otherwise
*/
@SuppressWarnings("deprecation")
public void unRent(boolean giveMoneyBack) {
if(plugin.getEconomy() == null) {
return;
}
// Run commands
this.runEventCommands(RegionEvent.UNRENTED, true);
double moneyBack = getMoneyBackAmount();
@ -600,7 +591,7 @@ public class RentRegion extends GeneralRegion {
landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
}
String landlordName = getLandlordName();
EconomyResponse r = null;
EconomyResponse r;
if(landlordName != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().withdrawPlayer(landlordPlayer, getWorldName(), moneyBack);
@ -618,7 +609,7 @@ public class RentRegion extends GeneralRegion {
r = null;
boolean error = false;
try {
if(player != null && player.getName() != null) {
if(player.getName() != null) {
r = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
} else if(getPlayerName() != null) {
r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
@ -626,7 +617,7 @@ public class RentRegion extends GeneralRegion {
} catch(Exception e) {
error = true;
}
if(error || r == null || !r.transactionSuccess() || error) {
if(error || r == null || !r.transactionSuccess()) {
plugin.getLogger().warning("Something went wrong with paying back to " + getPlayerName() + " money while unrenting region " + getName());
}
}
@ -637,7 +628,6 @@ public class RentRegion extends GeneralRegion {
// Update the signs and region flags
handleSchematicEvent(RegionEvent.UNRENTED);
updateRegionFlags(RegionState.FORRENT);
// Remove friends, the owner and renteduntil values
clearFriends();
@ -645,7 +635,8 @@ public class RentRegion extends GeneralRegion {
setRentedUntil(null);
setTimesExtended(-1);
removeLastActiveTime();
updateRegionFlags(RegionState.FORRENT);
updateSigns();
// Run commands
this.runEventCommands(RegionEvent.UNRENTED, false);

View File

@ -1,16 +1,15 @@
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;
import org.bukkit.configuration.file.YamlConfiguration;
import java.util.logging.Logger;
public interface AreaShopInterface {
public void debugI(String message);
public YamlConfiguration getConfig();
public WorldGuardPlugin getWorldGuard();
public WorldEditPlugin getWorldEdit();
public Logger getLogger();
void debugI(String message);
YamlConfiguration getConfig();
WorldGuardPlugin getWorldGuard();
WorldEditPlugin getWorldEdit();
Logger getLogger();
}

View File

@ -1,15 +1,14 @@
package nl.evolutioncoding.areashop.interfaces;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
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();
ProtectedRegion getRegion();
String getName();
World getWorld();
String getWorldName();
int getWidth();
int getDepth();
int getHeight();
}

View File

@ -1,19 +1,17 @@
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;
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 java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class WorldGuardHandler5 extends WorldGuardInterface {
@ -111,11 +109,7 @@ public class WorldGuardHandler5 extends WorldGuardInterface {
return false;
} else {
String name = Bukkit.getOfflinePlayer(player).getName();
if(name != null) {
return region.getMembers().contains(name);
} else {
return false;
}
return name != null && region.getMembers().contains(name);
}
}
@ -125,11 +119,7 @@ public class WorldGuardHandler5 extends WorldGuardInterface {
return false;
} else {
String name = Bukkit.getOfflinePlayer(player).getName();
if(name != null) {
return region.getOwners().contains(name);
} else {
return false;
}
return name != null && region.getOwners().contains(name);
}
}