Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.region;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import com.sk89q.worldguard.domains.DefaultDomain;
- import com.sk89q.worldguard.protection.managers.RegionManager;
- import com.sk89q.worldguard.protection.regions.ProtectedRegion;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.concurrent.ConcurrentHashMap;
- import net.milkbowl.vault.economy.Economy;
- import net.milkbowl.vault.economy.EconomyResponse;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.Sign;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.SignChangeEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class BuyRegion extends JavaPlugin implements Listener {
- static final String dataLoc;
- static final String signDataLoc;
- static final String rentedRE = "RentedRegionExpirations";
- static final String rentedRC = "RentedRegionCounts";
- static final String autoRenewsFileName = "AutoRenews";
- static long tickRate;
- public static Economy econ;
- public int buyRegionMax = 0;
- public int rentRegionMax = 0;
- public boolean requireBuyMode = true;
- public boolean requireBuyPerms = false;
- public boolean requireRentPerms = false;
- public String dateFormatString = "yy/MM/dd h:mma";
- public HashMap<String, Boolean> BuyMode = new HashMap<String, Boolean>();
- public HashMap<String, Integer> RegionCounts = new HashMap<String, Integer>();
- public ConcurrentHashMap<String, Integer> RentedRegionCounts = new ConcurrentHashMap<String, Integer>();
- public ConcurrentHashMap<String, Long> RentedRegionExpirations = new ConcurrentHashMap<String, Long>();
- public ConcurrentHashMap<String, Boolean> AutoRenews = new ConcurrentHashMap<String, Boolean>();
- public ConcurrentHashMap<String, String> Messages = new ConcurrentHashMap<String, String>();
- static {
- dataLoc = "plugins" + File.separator + "BuyRegion" + File.separator;
- signDataLoc = "plugins" + File.separator + "BuyRegion" + File.separator + "rent" + File.separator;
- tickRate = 60L;
- econ = null;
- }
- public void onEnable() {
- try {
- (new File(dataLoc)).mkdirs();
- (new File(signDataLoc)).mkdirs();
- this.getServer().getPluginManager().registerEvents(this, this);
- this.getLogger().info("BuyRegion - Maintained by Luke199");
- if (!this.setupEconomy()) {
- this.getLogger().info("Disabled due to no Vault dependency found!");
- this.getServer().getPluginManager().disablePlugin(this);
- return;
- }
- this.Messages = this.getDefaultMessages();
- this.getConfig().options().copyDefaults(true);
- this.loadRegionCounts();
- this.loadRentedRegionExpirations();
- this.loadRentedRegionCounts();
- this.loadAutoRenews();
- try {
- this.buyRegionMax = this.getConfig().getInt("BuyRegionMax", 0);
- } catch (Exception var10) {
- this.buyRegionMax = 0;
- }
- try {
- this.rentRegionMax = this.getConfig().getInt("RentRegionMax", 0);
- } catch (Exception var9) {
- this.rentRegionMax = 0;
- }
- try {
- this.requireBuyMode = this.getConfig().getBoolean("RequireBuyMode", true);
- } catch (Exception var8) {
- this.requireBuyMode = true;
- }
- try {
- tickRate = this.getConfig().getLong("CheckExpirationsInMins");
- tickRate = tickRate * 60L * 20L;
- } catch (Exception var7) {
- tickRate = 6000L;
- }
- try {
- this.requireBuyPerms = this.getConfig().getBoolean("RequireBuyPerms", false);
- } catch (Exception var6) {
- this.requireBuyPerms = false;
- }
- try {
- this.requireRentPerms = this.getConfig().getBoolean("RequireRentPerms", false);
- } catch (Exception var5) {
- this.requireRentPerms = false;
- }
- try {
- this.setFormatString(this.getConfig().getString("DateFormat", "Default"));
- } catch (Exception var4) {
- this.dateFormatString = "yy/MM/dd h:mma";
- }
- this.loadMessageConfig();
- this.saveConfig();
- this.scheduleRenterTask();
- File e = new File(dataLoc + "RegionActivityLog.txt");
- if (!e.exists()) {
- try {
- e.createNewFile();
- } catch (IOException var3) {
- this.getLogger().info("Error creating log file");
- }
- }
- } catch (Exception var11) {
- var11.printStackTrace();
- }
- }
- private void loadMessageConfig() {
- this.Messages.put("InvalidPriceTime",
- this.getConfig().getString("Messages.InvalidPriceTime", "Invalid sign. Invalid price or timespan!"));
- this.Messages.put("RegionNoExist",
- this.getConfig().getString("Messages.RegionNoExist", "Invalid sign. Region doesn\'t exist!"));
- this.Messages.put("EvictedFrom",
- this.getConfig().getString("Messages.EvictedFrom", "You have been evicted from"));
- this.Messages.put("InvalidArg", this.getConfig().getString("Messages.InvalidArg",
- "Invalid argument. Accepted values: true, false, yes, no, off, on"));
- this.Messages.put("RenewTurnOff",
- this.getConfig().getString("Messages.RenewTurnOff", "Auto-Renew has been turned OFF for you."));
- this.Messages.put("RenewTurnOn",
- this.getConfig().getString("Messages.RenewTurnOn", "Auto-Renew has been turned ON for you."));
- this.Messages.put("RenewOff", this.getConfig().getString("Messages.RenewOff", "Auto-Renew is off!"));
- this.Messages.put("RenewOn", this.getConfig().getString("Messages.RenewOn", "Auto-Renew is on!"));
- this.Messages.put("InvalidRenewArgs",
- this.getConfig().getString("Messages.InvalidRenewArgs", "Invalid args: /buyregion renew <region>"));
- this.Messages.put("BuyModeExit",
- this.getConfig().getString("Messages.BuyModeExit", "You have exited Buy Mode."));
- this.Messages.put("BuyModeEnter", this.getConfig().getString("Messages.BuyModeEnter",
- "You are now in Buy Mode - right-click the BuyRegion sign!"));
- this.Messages.put("ToEnterBuyMode",
- this.getConfig().getString("Messages.ToEnterBuyMode", "To enter Buy Mode type: /buyregion"));
- this.Messages.put("BuyModeRent",
- this.getConfig().getString("Messages.BuyModeRent", "You must be in Buy Mode to rent this region!"));
- this.Messages.put("BuyModeBuy",
- this.getConfig().getString("Messages.BuyModeBuy", "You must be in Buy Mode to buy this region!"));
- this.Messages.put("NotEnoughRent",
- this.getConfig().getString("Messages.NotEnoughRent", "Not enough money to rent this region!"));
- this.Messages.put("NotEnoughBuy",
- this.getConfig().getString("Messages.NotEnoughBuy", "Not enough money to buy this region!"));
- this.Messages.put("TransFailed", this.getConfig().getString("Messages.TransFailed", "Transaction Failed!"));
- this.Messages.put("Rented", this.getConfig().getString("Messages.Rented", "Congrats! You have rented"));
- this.Messages.put("NewBalance", this.getConfig().getString("Messages.NewBalance", "Your new balance is"));
- this.Messages.put("RentMax",
- this.getConfig().getString("Messages.RentMax", "You are not allowed to rent more regions. Max"));
- this.Messages.put("RentPerms",
- this.getConfig().getString("Messages.RentPerms", "You do not have permission to rent regions."));
- this.Messages.put("Balance", this.getConfig().getString("Messages.Balance", "Your balance is"));
- this.Messages.put("Purchased",
- this.getConfig().getString("Messages.Purchased", "Congrats! You have purchased"));
- this.Messages.put("BuyMax",
- this.getConfig().getString("Messages.BuyMax", "You are not allowed to buy more regions. Max"));
- this.Messages.put("BuyPerms",
- this.getConfig().getString("Messages.BuyPerms", "You do not have permission to buy regions."));
- this.Messages.put("NotRented", this.getConfig().getString("Messages.NotRented", "is not currently rented."));
- this.Messages.put("NotRenting", this.getConfig().getString("Messages.NotRenting",
- "You are not renting this region. You cannot renew it!"));
- this.Messages.put("NotEnoughRenew", this.getConfig().getString("Messages.NotEnoughRenew",
- "Not enough money to renew rental for this region!"));
- this.Messages.put("Renewed", this.getConfig().getString("Messages.Renewed", "Congrats! You have renewed"));
- this.Messages.put("Expired",
- this.getConfig().getString("Messages.Expired", "Your rental has expired for region"));
- this.Messages.put("Help1", this.getConfig().getString("Messages.Help1", "BuyRegion Commands"));
- this.Messages.put("Help2", this.getConfig().getString("Messages.Help2", "/buyregion - toggles buy mode"));
- this.Messages.put("Help3",
- this.getConfig().getString("Messages.Help3", "/buyregion renew <region> - renews rental of <region>"));
- this.Messages.put("Help4", this.getConfig().getString("Messages.Help4",
- "/buyregion autorenew <true/false> - sets auto-renew for all rented regions"));
- }
- public void onDisable() {
- try {
- this.saveRegionCounts();
- this.saveRentedRegionExpirations();
- this.saveRentedRegionCounts();
- this.saveAutoRenews();
- this.getServer().getScheduler().cancelTasks(this);
- } catch (Exception var2) {
- this.getLogger().info("An error occured during shutdown.");
- }
- }
- private ConcurrentHashMap<String, String> getDefaultMessages() {
- ConcurrentHashMap<String, String> msgs = new ConcurrentHashMap<String, String>();
- msgs.put("InvalidPriceTime", "Invalid sign. Invalid price or timespan!");
- msgs.put("RegionNoExist", "Invalid sign. Region doesn\'t exist!");
- msgs.put("EvictedFrom", "You have been evicted from");
- msgs.put("InvalidArg", "Invalid argument. Accepted values: true, false, yes, no, off, on");
- msgs.put("RenewTurnOff", "Auto-Renew has been turned OFF for you.");
- msgs.put("RenewTurnOn", "Auto-Renew has been turned ON for you.");
- msgs.put("RenewOff", "Auto-Renew is off!");
- msgs.put("RenewOn", "Auto-Renew is on!");
- msgs.put("InvalidRenewArgs", "Invalid args: /buyregion renew <region>");
- msgs.put("BuyModeExit", "You have exited Buy Mode.");
- msgs.put("BuyModeEnter", "You are now in Buy Mode - right-click the BuyRegion sign!");
- msgs.put("ToEnterBuyMode", "To enter Buy Mode type: /buyregion");
- msgs.put("BuyModeRent", "You must be in Buy Mode to rent this region!");
- msgs.put("BuyModeBuy", "You must be in Buy Mode to buy this region!");
- msgs.put("NotEnoughRent", "Not enough money to rent this region!");
- msgs.put("NotEnoughBuy", "Not enough money to buy this region!");
- msgs.put("TransFailed", "Transaction Failed!");
- msgs.put("Rented", "Congrats! You have rented");
- msgs.put("NewBalance", "Your new balance is");
- msgs.put("RentMax", "You are not allowed to rent more regions. Max");
- msgs.put("RentPerms", "You do not have permission to rent regions.");
- msgs.put("Balance", "Your balance is");
- msgs.put("Purchased", "Congrats! You have purchased");
- msgs.put("BuyMax", "You are not allowed to buy more regions. Max");
- msgs.put("BuyPerms", "You do not have permission to buy regions.");
- msgs.put("NotRented", "is not currently rented.");
- msgs.put("NotRenting", "You are not renting this region. You cannot renew it!");
- msgs.put("NotEnoughRenew", "Not enough money to renew rental for this region!");
- msgs.put("Renewed", "Congrats! You have renewed");
- msgs.put("Expired", "Your rental has expired for region");
- msgs.put("Help1", "BuyRegion Commands");
- msgs.put("Help2", "/buyregion - toggles buy mode");
- msgs.put("Help3", "/buyregion renew <region> - renews rental of <region>");
- msgs.put("Help4", "/buyregion autorenew <true/false> - sets auto-renew for all rented regions");
- return msgs;
- }
- private String getMessage(String key) {
- return (String) this.Messages.get(key);
- }
- public void scheduleRenterTask() {
- this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @SuppressWarnings("deprecation")
- public void run() {
- try {
- long e = (new Date()).getTime();
- Iterator<String> var4 = BuyRegion.this.RentedRegionExpirations.keySet().iterator();
- while (true) {
- String regionName;
- boolean renewed;
- BuyRegion.RentableRegion rentedRegion;
- do {
- long regionExp;
- do {
- do {
- if (!var4.hasNext()) {
- return;
- }
- regionName = (String) var4.next();
- } while (!BuyRegion.this.RentedRegionExpirations.containsKey(regionName));
- regionExp = ((Long) BuyRegion.this.RentedRegionExpirations.get(regionName)).longValue();
- } while (regionExp > e);
- renewed = false;
- rentedRegion = BuyRegion.this.loadRegion(regionName);
- if (BuyRegion.this.AutoRenews.containsKey(rentedRegion.renter)
- && ((Boolean) BuyRegion.this.AutoRenews.get(rentedRegion.renter)).booleanValue()) {
- Player world = BuyRegion.this.getServer().getPlayer(rentedRegion.renter);
- Double rm = Double.valueOf(Double.parseDouble(rentedRegion.signLine3));
- if (BuyRegion.econ.getBalance(rentedRegion.renter) >= rm.doubleValue()) {
- EconomyResponse region = BuyRegion.econ.withdrawPlayer(rentedRegion.renter,
- rm.doubleValue());
- if (region.transactionSuccess()) {
- renewed = true;
- String[] dd = rentedRegion.signLine4.split(" ");
- long x = ((Long) BuyRegion.this.RentedRegionExpirations.get(regionName))
- .longValue();
- BuyRegion.DateResult y = BuyRegion.this.parseDateString(Integer.parseInt(dd[0]),
- dd[1], x);
- BuyRegion.this.RentedRegionExpirations.put(regionName, Long.valueOf(y.Time));
- BuyRegion.this.saveRentedRegionExpirations();
- BuyRegion.this.logActivity(rentedRegion.renter, " AUTORENEW " + regionName);
- SimpleDateFormat sdf = new SimpleDateFormat(BuyRegion.this.dateFormatString);
- if (world instanceof Player) {
- world.sendMessage(BuyRegion.this.Notice(BuyRegion.this.getMessage("Renewed")
- + " " + regionName + " -> " + sdf.format(new Date(y.Time))));
- world.sendMessage(
- BuyRegion.this.Notice(BuyRegion.this.getMessage("NewBalance") + " "
- + BuyRegion.econ.getBalance(rentedRegion.renter)));
- }
- World z = BuyRegion.this.getServer().getWorld(rentedRegion.worldName);
- double x1 = Double.parseDouble(rentedRegion.signLocationX);
- double yaw = Double.parseDouble(rentedRegion.signLocationY);
- double currentBlock = Double.parseDouble(rentedRegion.signLocationZ);
- float player = Float.parseFloat(rentedRegion.signLocationPitch);
- float yaw1 = Float.parseFloat(rentedRegion.signLocationYaw);
- Location signLoc1 = new Location(z, x1, yaw, currentBlock, player, yaw1);
- Block currentBlock1 = z.getBlockAt(signLoc1);
- if (currentBlock1.getType() == Material.SIGN_POST
- || currentBlock1.getType() == Material.WALL_SIGN) {
- Sign theSign = (Sign) currentBlock1.getState();
- theSign.setLine(0, regionName);
- theSign.setLine(1, rentedRegion.renter);
- theSign.setLine(2, ChatColor.WHITE + "Until:");
- theSign.setLine(3, sdf.format(new Date(y.Time)));
- theSign.update();
- theSign.update();
- }
- }
- } else if (world instanceof Player) {
- world.sendMessage(BuyRegion.this.Notice(
- BuyRegion.this.getMessage("NotEnoughRenew") + " " + regionName + "!"));
- world.sendMessage(BuyRegion.this.Notice(BuyRegion.this.getMessage("Balance") + " "
- + BuyRegion.econ.getBalance(rentedRegion.renter)));
- }
- }
- } while (renewed);
- BuyRegion.this.RentedRegionExpirations.remove(regionName);
- BuyRegion.this.saveRentedRegionExpirations();
- World world1 = BuyRegion.this.getServer().getWorld(rentedRegion.worldName);
- RegionManager rm1 = BuyRegion.this.getWorldGuard().getRegionManager(world1);
- ProtectedRegion region1 = rm1.getRegion(regionName);
- new DefaultDomain();
- DefaultDomain dd1 = region1.getMembers();
- dd1.removePlayer(rentedRegion.renter);
- region1.setMembers(dd1);
- BuyRegion.this.removeRentedRegionFromCount(rentedRegion.renter);
- double x2 = Double.parseDouble(rentedRegion.signLocationX);
- double y1 = Double.parseDouble(rentedRegion.signLocationY);
- double z1 = Double.parseDouble(rentedRegion.signLocationZ);
- float pitch = Float.parseFloat(rentedRegion.signLocationPitch);
- float yaw2 = Float.parseFloat(rentedRegion.signLocationYaw);
- Location signLoc = new Location(world1, x2, y1, z1, pitch, yaw2);
- Block currentBlock2 = world1.getBlockAt(signLoc);
- Sign regionFile;
- if (currentBlock2.getType() != Material.SIGN_POST
- && currentBlock2.getType() != Material.WALL_SIGN) {
- try {
- if (rentedRegion.signType == "WALL_SIGN") {
- currentBlock2.setType(Material.WALL_SIGN);
- } else {
- currentBlock2.setType(Material.SIGN_POST);
- }
- regionFile = (Sign) currentBlock2.getState();
- regionFile.setLine(0, rentedRegion.signLine1);
- regionFile.setLine(1, rentedRegion.signLine2);
- regionFile.setLine(2, rentedRegion.signLine3);
- regionFile.setLine(3, rentedRegion.signLine4);
- regionFile.update();
- } catch (Exception var29) {
- BuyRegion.this.getLogger().info("RentRegion automatic sign creation failed for region "
- + rentedRegion.regionName);
- }
- } else {
- regionFile = (Sign) currentBlock2.getState();
- regionFile.setLine(0, rentedRegion.signLine1);
- regionFile.setLine(1, rentedRegion.signLine2);
- regionFile.setLine(2, rentedRegion.signLine3);
- regionFile.setLine(3, rentedRegion.signLine4);
- regionFile.update();
- }
- File regionFile1 = new File(BuyRegion.signDataLoc + regionName + ".digi");
- if (regionFile1.exists()) {
- regionFile1.delete();
- }
- Player player1 = BuyRegion.this.getServer().getPlayer(rentedRegion.renter);
- if (player1 instanceof Player) {
- player1.sendMessage(
- BuyRegion.this.Notice(BuyRegion.this.getMessage("Expired") + " " + regionName));
- }
- BuyRegion.this.logActivity(rentedRegion.renter, " EXPIRED " + rentedRegion.regionName);
- }
- } catch (Exception var30) {
- var30.printStackTrace();
- }
- }
- }, tickRate, tickRate);
- }
- @SuppressWarnings("deprecation")
- public void renewRental(String regionName, String playerName, CommandSender sender) {
- try {
- if ((new File(signDataLoc + regionName + ".digi")).exists()
- && this.RentedRegionExpirations.containsKey(regionName)) {
- BuyRegion.RentableRegion e = this.loadRegion(regionName);
- if (sender.getName().equalsIgnoreCase(e.renter)) {
- Double regionPrice = Double.valueOf(Double.parseDouble(e.signLine3));
- if (econ.getBalance(playerName) >= regionPrice.doubleValue()) {
- EconomyResponse response = econ.withdrawPlayer(playerName, regionPrice.doubleValue());
- if (response.transactionSuccess()) {
- String[] timeSpan = e.signLine4.split(" ");
- long currentExpiration = ((Long) this.RentedRegionExpirations.get(regionName)).longValue();
- BuyRegion.DateResult timeData = this.parseDateString(Integer.parseInt(timeSpan[0]),
- timeSpan[1], currentExpiration);
- this.RentedRegionExpirations.put(regionName, Long.valueOf(timeData.Time));
- this.saveRentedRegionExpirations();
- this.logActivity(playerName, " RENEW " + regionName);
- SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormatString);
- sender.sendMessage(this.Notice(this.getMessage("Renewed") + " " + regionName + " until "
- + sdf.format(new Date(timeData.Time))));
- sender.sendMessage(
- this.Notice(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
- World world = this.getServer().getWorld(e.worldName);
- double x = Double.parseDouble(e.signLocationX);
- double y = Double.parseDouble(e.signLocationY);
- double z = Double.parseDouble(e.signLocationZ);
- float pitch = Float.parseFloat(e.signLocationPitch);
- float yaw = Float.parseFloat(e.signLocationYaw);
- Location signLoc = new Location(world, x, y, z, pitch, yaw);
- Block currentBlock = world.getBlockAt(signLoc);
- if (currentBlock.getType() == Material.SIGN_POST
- || currentBlock.getType() == Material.WALL_SIGN) {
- Sign theSign = (Sign) currentBlock.getState();
- theSign.setLine(0, regionName);
- theSign.setLine(1, playerName);
- theSign.setLine(2, ChatColor.WHITE + "Until:");
- theSign.setLine(3, sdf.format(new Date(timeData.Time)));
- theSign.update();
- theSign.update();
- }
- } else {
- sender.sendMessage(this.Notice(this.getMessage("TransFailed")));
- }
- } else {
- sender.sendMessage(this.Notice(this.getMessage("NotEnoughRenew")));
- sender.sendMessage(this.Notice(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
- }
- } else {
- sender.sendMessage(this.Notice(this.getMessage("NotRenting")));
- }
- } else {
- sender.sendMessage(this.Notice(regionName + " " + this.getMessage("NotRented")));
- }
- } catch (Exception var24) {
- this.getLogger().info("An error has occured while renewing rental for: " + regionName);
- }
- }
- private void logActivity(String player, String action) {
- try {
- Date e = new Date();
- File file = new File(dataLoc + "RegionActivityLog.txt");
- FileWriter out = new FileWriter(file, true);
- out.write(e.toString() + " [" + player + "] " + action + "\r\n");
- out.flush();
- out.close();
- } catch (IOException var6) {
- this.getLogger().info("An error occured while trying to log activity.");
- }
- }
- private void setFormatString(String input) {
- try {
- if (input.equalsIgnoreCase("US")) {
- this.dateFormatString = "MM/dd/yy h:mma";
- } else if (input.equalsIgnoreCase("EU")) {
- this.dateFormatString = "dd/MM/yy h:mma";
- } else {
- this.dateFormatString = "yy/MM/dd h:mma";
- }
- } catch (Exception var3) {
- this.dateFormatString = "yy/MM/dd h:mma";
- }
- }
- @SuppressWarnings("unchecked")
- private void loadRegionCounts() {
- try {
- if ((new File(dataLoc + "RegionCounts.digi")).exists()) {
- this.RegionCounts = (HashMap<String, Integer>) load(dataLoc, "RegionCounts");
- } else {
- save(this.RegionCounts, dataLoc, "RegionCounts");
- }
- } catch (Exception var2) {
- this.getLogger().info("Error occured loading RegionCounts.digi");
- }
- }
- @SuppressWarnings("unchecked")
- private void loadAutoRenews() {
- try {
- if ((new File(dataLoc + "AutoRenews" + ".digi")).exists()) {
- this.AutoRenews = (ConcurrentHashMap<String, Boolean>) load(dataLoc, "AutoRenews");
- } else {
- save(this.AutoRenews, dataLoc, "AutoRenews");
- }
- } catch (Exception var2) {
- this.getLogger().info("Error occured loading AutoRenews");
- }
- }
- @SuppressWarnings("unchecked")
- private void loadRentedRegionCounts() {
- try {
- if ((new File(dataLoc + "RentedRegionCounts" + ".digi")).exists()) {
- this.RentedRegionCounts = (ConcurrentHashMap<String, Integer>) load(dataLoc, "RentedRegionCounts");
- } else {
- save(this.RentedRegionCounts, dataLoc, "RentedRegionCounts");
- }
- } catch (Exception var2) {
- this.getLogger().info("Error occured loading RentedRegionCounts");
- }
- }
- @SuppressWarnings("unchecked")
- private void loadRentedRegionExpirations() {
- try {
- if ((new File(dataLoc + "RentedRegionExpirations" + ".digi")).exists()) {
- this.RentedRegionExpirations = (ConcurrentHashMap<String, Long>) load(dataLoc,
- "RentedRegionExpirations");
- } else {
- save(this.RentedRegionExpirations, dataLoc, "RentedRegionExpirations");
- }
- } catch (Exception var2) {
- this.getLogger().info("Error occured loading RentedRegionExpirations");
- }
- }
- private int getBoughtRegionsCount(String playerName) {
- return this.RegionCounts.containsKey(playerName) ? ((Integer) this.RegionCounts.get(playerName)).intValue() : 0;
- }
- private void removeRentedRegionFromCount(String playerName) {
- try {
- if (this.RentedRegionCounts.containsKey(playerName)) {
- int e = this.getRentedRegionsCount(playerName);
- if (e > 0) {
- --e;
- }
- if (e >= 0) {
- this.RentedRegionCounts.put(playerName, Integer.valueOf(e));
- } else {
- this.RentedRegionCounts.put(playerName, Integer.valueOf(0));
- }
- this.saveRentedRegionCounts();
- }
- } catch (Exception var3) {
- this.getLogger().info("An error occured while removing a rented region from a player\'s count.");
- }
- }
- private int getRentedRegionsCount(String playerName) {
- return this.RentedRegionCounts.containsKey(playerName)
- ? ((Integer) this.RentedRegionCounts.get(playerName)).intValue() : 0;
- }
- private void setBoughtRegionsCount(String playerName, int amount, CommandSender sender) {
- try {
- this.RegionCounts.put(playerName, Integer.valueOf(amount));
- this.saveRegionCounts();
- sender.sendMessage(this.Notice(playerName + " bought regions set to " + amount));
- } catch (Exception var5) {
- this.getLogger().info("An error occured in setBoughtRegions");
- }
- }
- private void setRentedRegionsCount(String playerName, int amount, CommandSender sender) {
- try {
- this.RentedRegionCounts.put(playerName, Integer.valueOf(amount));
- this.saveRentedRegionCounts();
- sender.sendMessage(this.Notice(playerName + " rented regions set to " + amount));
- } catch (Exception var5) {
- this.getLogger().info("An error occured in setRentedRegionsCount");
- }
- }
- private void addRentedRegionFile(String playerName, String regionName, Sign sign) {
- BuyRegion.RentableRegion region = new BuyRegion.RentableRegion();
- Location tmpLoc = sign.getLocation();
- region.regionName = regionName;
- region.signLine1 = sign.getLine(0);
- region.signLine2 = sign.getLine(1);
- region.signLine3 = sign.getLine(2);
- region.signLine4 = sign.getLine(3);
- region.renter = playerName;
- region.signLocationX = String.valueOf(tmpLoc.getBlockX());
- region.signLocationY = String.valueOf(tmpLoc.getBlockY());
- region.signLocationZ = String.valueOf(tmpLoc.getBlockZ());
- region.signLocationPitch = String.valueOf(tmpLoc.getPitch());
- region.signLocationYaw = String.valueOf(tmpLoc.getYaw());
- region.signDirection = tmpLoc.getDirection().toString();
- region.worldName = sign.getWorld().getName();
- if (sign.getType() == Material.WALL_SIGN) {
- region.signType = "WALL_SIGN";
- } else {
- region.signType = "SIGN_POST";
- }
- this.saveRentableRegion(region);
- }
- private void addBoughtRegionToCounts(String playerName) {
- if (this.RegionCounts.containsKey(playerName)) {
- this.RegionCounts.put(playerName, Integer.valueOf(this.getBoughtRegionsCount(playerName) + 1));
- } else {
- this.RegionCounts.put(playerName, Integer.valueOf(1));
- }
- this.saveRegionCounts();
- }
- private void addRentedRegionToCounts(String playerName) {
- if (this.RentedRegionCounts.containsKey(playerName)) {
- this.RentedRegionCounts.put(playerName, Integer.valueOf(this.getRentedRegionsCount(playerName) + 1));
- } else {
- this.RentedRegionCounts.put(playerName, Integer.valueOf(1));
- }
- this.saveRentedRegionCounts();
- }
- private void saveAutoRenews() {
- try {
- save(this.AutoRenews, dataLoc, "AutoRenews");
- } catch (Exception var2) {
- this.getLogger().info("An error has occured saving AutoRenews");
- }
- }
- private void saveRentedRegionCounts() {
- try {
- save(this.RentedRegionCounts, dataLoc, "RentedRegionCounts");
- } catch (Exception var2) {
- this.getLogger().info("An error has occured saving Rented Region Counts");
- }
- }
- private void saveRegionCounts() {
- try {
- save(this.RegionCounts, dataLoc, "RegionCounts");
- } catch (Exception var2) {
- this.getLogger().info("An error has occured saving Region counts.");
- }
- }
- private void saveRentedRegionExpirations() {
- try {
- save(this.RentedRegionExpirations, dataLoc, "RentedRegionExpirations");
- } catch (Exception var2) {
- this.getLogger().info("An error has occured saving RentedRegionExpirations");
- }
- }
- private void checkPlayerRentedRegionCount(String playerName, CommandSender sender) {
- if (this.RentedRegionCounts.containsKey(playerName)) {
- sender.sendMessage(
- this.Notice(playerName + " a " + this.getRentedRegionsCount(playerName) + " régions loués."));
- } else {
- sender.sendMessage(this.Notice(playerName + " n'a pas de régions loués."));
- }
- }
- private void checkPlayerRegionCount(String playerName, CommandSender sender) {
- if (this.RegionCounts.containsKey(playerName)) {
- sender.sendMessage(
- this.Notice(playerName + " a " + this.getBoughtRegionsCount(playerName) + " régions achetés."));
- } else {
- sender.sendMessage(this.Notice(playerName + " n'a pas acheté de régions."));
- }
- }
- public static void saveRegion(BuyRegion.RentableRegion region) {
- save(region.toString(), signDataLoc, region.regionName);
- }
- public BuyRegion.RentableRegion loadRegion(String regionName) {
- String tmp = (String) load(signDataLoc, regionName);
- return new BuyRegion.RentableRegion(tmp);
- }
- public static void save(Object obj, String dataLoc, String file) {
- try {
- ObjectOutputStream e = new ObjectOutputStream(new FileOutputStream(dataLoc + file + ".digi"));
- e.writeObject(obj);
- e.flush();
- e.close();
- } catch (Exception var4) {
- var4.printStackTrace();
- }
- }
- public static Object load(String dataLoc, String file) {
- try {
- ObjectInputStream e = new ObjectInputStream(new FileInputStream(dataLoc + file + ".digi"));
- Object rv = e.readObject();
- e.close();
- return rv;
- } catch (Exception var4) {
- var4.printStackTrace();
- return null;
- }
- }
- private String Notice(String msg) {
- return ChatColor.AQUA + "[HcRegion] " + ChatColor.YELLOW + msg;
- }
- private String Warning(String msg) {
- return ChatColor.RED + "[HcRegion] " + ChatColor.YELLOW + msg;
- }
- private void setAutoRenew(String playerName, boolean autoRenew) {
- if (autoRenew) {
- this.AutoRenews.put(playerName, Boolean.valueOf(true));
- this.saveAutoRenews();
- } else {
- this.AutoRenews.remove(playerName);
- this.saveAutoRenews();
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onPunchSign(PlayerInteractEvent event) {
- try {
- if (event.getAction().name() == "RIGHT_CLICK_BLOCK") {
- Material e = event.getClickedBlock().getType();
- if (e == Material.SIGN_POST || e == Material.WALL_SIGN) {
- Sign sign = (Sign) event.getClickedBlock().getState();
- String topLine = sign.getLine(0);
- Player sender;
- String regionName;
- if (topLine.length() > 0
- && (topLine.equalsIgnoreCase("[BuyRegion]") || topLine.equalsIgnoreCase("[WGRSA]"))) {
- sender = event.getPlayer();
- regionName = sender.getName();
- if (topLine.equalsIgnoreCase("[WGRSA]")) {
- sign.setLine(0, "[BuyRegion]");
- sign.update();
- }
- if (this.requireBuyPerms && !sender.hasPermission("hcregion.buy") && !sender.isOp()) {
- sender.sendMessage(this.Notice(this.getMessage("BuyPerms")));
- return;
- }
- if (this.buyRegionMax > 0 && this.getBoughtRegionsCount(regionName) >= this.buyRegionMax
- && !sender.isOp() && !sender.hasPermission("hcregion.exempt")) {
- sender.sendMessage(this.Notice(this.getMessage("BuyMax") + " " + this.buyRegionMax));
- return;
- }
- if (!this.BuyMode.containsKey(regionName) && this.requireBuyMode) {
- sender.sendMessage(this.Warning(this.getMessage("BuyModeBuy")));
- sender.sendMessage(this.Warning(this.getMessage("ToEnterBuyMode")));
- } else {
- double playerName1 = Double.parseDouble(sign.getLine(2));
- String regionName1 = sign.getLine(1);
- World dateString1 = sender.getWorld();
- RegionManager expiration1 = this.getWorldGuard().getRegionManager(dateString1);
- DefaultDomain dateResult1 = new DefaultDomain();
- dateResult1.addPlayer(regionName);
- ProtectedRegion world2 = expiration1.getRegion(regionName1);
- if (world2 == null) {
- sender.sendMessage(this.Notice(this.getMessage("RegionNoExist")));
- return;
- }
- if (econ.getBalance(regionName) >= playerName1) {
- EconomyResponse rm1 = econ.withdrawPlayer(regionName, playerName1);
- if (rm1.transactionSuccess()) {
- world2.setOwners(dateResult1);
- expiration1.save();
- this.addBoughtRegionToCounts(regionName);
- sender.sendMessage(
- this.Notice(this.getMessage("Purchased") + " " + regionName1 + "!"));
- sender.sendMessage(this
- .Notice(this.getMessage("NewBalance") + " " + econ.getBalance(regionName)));
- this.logActivity(regionName, " BUY " + regionName1);
- sign.setLine(0, ChatColor.DARK_PURPLE + "** HcRegion **");
- sign.setLine(1, ChatColor.GREEN + "Maison de:");
- sign.setLine(2, ChatColor.GOLD + regionName);
- sign.setLine(3, ChatColor.DARK_PURPLE + "** HcRegion **");
- sign.update();
- this.BuyMode.remove(regionName);
- } else {
- sender.sendMessage(this.Notice(this.getMessage("TransFailed")));
- }
- } else {
- sender.sendMessage(this.Warning(this.getMessage("NotEnoughBuy")));
- sender.sendMessage(
- this.Warning(this.getMessage("Balance") + " " + econ.getBalance(regionName)));
- }
- }
- } else if (topLine.length() > 0 && topLine.equalsIgnoreCase("[RentRegion]")) {
- sender = event.getPlayer();
- regionName = sign.getLine(1);
- String playerName = sender.getName();
- if (this.requireRentPerms && !sender.hasPermission("hcregion.rent") && !sender.isOp()) {
- sender.sendMessage(this.Warning(this.getMessage("RentPerms")));
- return;
- }
- if (this.rentRegionMax > 0 && this.getRentedRegionsCount(playerName) >= this.rentRegionMax
- && !sender.isOp() && !sender.hasPermission("hcregion.exempt")) {
- sender.sendMessage(this.Notice(this.getMessage("RentMax") + " " + this.rentRegionMax));
- return;
- }
- if (!this.BuyMode.containsKey(playerName) && this.requireBuyMode) {
- sender.sendMessage(this.Warning(this.getMessage("BuyModeRent")));
- sender.sendMessage(this.Warning(this.getMessage("ToEnterBuyMode")));
- } else if (regionName.length() > 0) {
- String dateString = sign.getLine(3);
- double regionPrice;
- BuyRegion.DateResult dateResult;
- try {
- regionPrice = Double.parseDouble(sign.getLine(2));
- String[] expiration = dateString.split("\\s");
- int world = Integer.parseInt(expiration[0]);
- dateResult = this.parseDateString(world, expiration[1]);
- if (dateResult.IsError) {
- throw new Exception();
- }
- } catch (Exception var19) {
- this.getLogger().info("Region price or expiration");
- sign.setLine(0, "-invalide-");
- sign.setLine(1, "<région ici>");
- sign.setLine(2, "<prix ici>");
- sign.setLine(3, "<laps de temps>");
- sign.update();
- this.getLogger()
- .info("Invalid [RentRegion] sign cleared at " + sign.getLocation().toString());
- return;
- }
- World world1 = sender.getWorld();
- RegionManager rm = this.getWorldGuard().getRegionManager(world1);
- DefaultDomain dd = new DefaultDomain();
- dd.addPlayer(playerName);
- ProtectedRegion region = rm.getRegion(regionName);
- if (region == null) {
- sender.sendMessage(this.Notice(this.getMessage("RegionNoExist")));
- sign.setLine(0, "-invalide-");
- sign.setLine(1, "<région ici>");
- sign.setLine(2, "<prix ici>");
- sign.setLine(3, "<laps de temps>");
- sign.update();
- this.getLogger()
- .info("Invalid [RentRegion] sign cleared at " + sign.getLocation().toString());
- return;
- }
- if (econ.getBalance(playerName) >= regionPrice) {
- EconomyResponse response = econ.withdrawPlayer(playerName, regionPrice);
- if (response.transactionSuccess()) {
- region.setMembers(dd);
- rm.save();
- this.addRentedRegionFile(playerName, regionName, sign);
- this.addRentedRegionToCounts(playerName);
- this.logActivity(playerName, " RENT " + regionName);
- SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormatString);
- sign.setLine(0, regionName);
- sign.setLine(1, playerName);
- sign.setLine(2, ChatColor.WHITE + "Until:");
- sign.setLine(3, sdf.format(new Date(dateResult.Time)));
- sign.update();
- sender.sendMessage(this.Notice(this.getMessage("Rented") + " " + regionName + " -> "
- + sdf.format(new Date(dateResult.Time))));
- sender.sendMessage(this
- .Notice(this.getMessage("NewBalance") + " " + econ.getBalance(playerName)));
- this.RentedRegionExpirations.put(regionName, Long.valueOf(dateResult.Time));
- this.saveRentedRegionExpirations();
- this.BuyMode.remove(playerName);
- } else {
- sender.sendMessage(this.Warning(this.getMessage("TransFailed")));
- }
- } else {
- sender.sendMessage(this.Warning(this.getMessage("NotEnoughRent")));
- sender.sendMessage(
- this.Warning(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
- }
- }
- }
- }
- }
- } catch (Exception var20) {
- this.getLogger().info(var20.getMessage());
- }
- }
- private BuyRegion.DateResult parseDateString(int val, String type) {
- try {
- Date e = new Date();
- if (!type.equalsIgnoreCase("d") && !type.equalsIgnoreCase("day") && !type.equalsIgnoreCase("days")) {
- return !type.equalsIgnoreCase("h") && !type.equalsIgnoreCase("hour") && !type.equalsIgnoreCase("hours")
- ? (!type.equalsIgnoreCase("m") && !type.equalsIgnoreCase("mins")
- && !type.equalsIgnoreCase("min") && !type.equalsIgnoreCase("minutes")
- && !type.equalsIgnoreCase("minute")
- ? (!type.equalsIgnoreCase("s") && !type.equalsIgnoreCase("sec")
- && !type.equalsIgnoreCase("secs") && !type.equalsIgnoreCase("seconds")
- && !type.equalsIgnoreCase("second")
- ? new BuyRegion.DateResult(-1L, "ERROR", true)
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 1000),
- val + " seconds", false))
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 1000),
- val + " minutes", false))
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 60 * 1000), val + " hours", false);
- } else {
- Calendar cal = Calendar.getInstance();
- cal.setTime(e);
- cal.add(5, val);
- return new BuyRegion.DateResult(cal.getTime().getTime(), val + " days", false);
- }
- } catch (Exception var5) {
- return new BuyRegion.DateResult(-1L, "ERROR", true);
- }
- }
- private BuyRegion.DateResult parseDateString(int val, String type, long start) {
- try {
- Date e = new Date(start);
- if (!type.equalsIgnoreCase("d") && !type.equalsIgnoreCase("day") && !type.equalsIgnoreCase("days")) {
- return !type.equalsIgnoreCase("h") && !type.equalsIgnoreCase("hour") && !type.equalsIgnoreCase("hours")
- ? (!type.equalsIgnoreCase("m") && !type.equalsIgnoreCase("mins")
- && !type.equalsIgnoreCase("min") && !type.equalsIgnoreCase("minutes")
- && !type.equalsIgnoreCase("minute")
- ? (!type.equalsIgnoreCase("s") && !type.equalsIgnoreCase("sec")
- && !type.equalsIgnoreCase("secs") && !type.equalsIgnoreCase("seconds")
- && !type.equalsIgnoreCase("second")
- ? new BuyRegion.DateResult(-1L, "ERROR", true)
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 1000),
- val + " seconds", false))
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 1000),
- val + " minutes", false))
- : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 60 * 1000), val + " hours", false);
- } else {
- Calendar cal = Calendar.getInstance();
- cal.setTime(e);
- cal.add(5, val);
- return new BuyRegion.DateResult(cal.getTime().getTime(), val + " days", false);
- }
- } catch (Exception var7) {
- return new BuyRegion.DateResult(-1L, "ERROR", true);
- }
- }
- private WorldGuardPlugin getWorldGuard() {
- Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard");
- return plugin != null && plugin instanceof WorldGuardPlugin ? (WorldGuardPlugin) plugin : null;
- }
- private boolean setupEconomy() {
- try {
- if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
- } else {
- RegisteredServiceProvider<Economy> e = this.getServer().getServicesManager()
- .getRegistration(Economy.class);
- if (e == null) {
- return false;
- } else {
- econ = (Economy) e.getProvider();
- return econ != null;
- }
- }
- } catch (Exception var2) {
- this.getLogger().info("Error loading Vault! Plugin shutting down.");
- return false;
- }
- }
- private void toggleBuyMode(CommandSender sender) {
- try {
- String e = sender.getName();
- if (!this.BuyMode.containsKey(e)) {
- this.BuyMode.put(sender.getName(), Boolean.valueOf(true));
- sender.sendMessage(this.Notice("BuyModeEnter"));
- } else {
- this.BuyMode.remove(e);
- sender.sendMessage(this.Notice(this.getMessage("BuyModeExit")));
- }
- } catch (Exception var3) {
- this.getLogger().info("An error occured in toggleBuyMode");
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (cmd.getName().equalsIgnoreCase("buyregion")) {
- if (args.length == 0) {
- this.toggleBuyMode(sender);
- } else {
- if (args[0].equalsIgnoreCase("renew")) {
- if (args.length < 2) {
- sender.sendMessage(this.Notice(this.getMessage("InvalidRenewArgs")));
- } else {
- this.renewRental(args[1], sender.getName(), sender);
- }
- return false;
- }
- if (args[0].equalsIgnoreCase("autorenew")) {
- if (args.length < 2) {
- if (this.AutoRenews.containsKey(sender.getName())) {
- if (((Boolean) this.AutoRenews.get(sender.getName())).booleanValue()) {
- sender.sendMessage(this.Notice(this.getMessage("RenewOn")));
- } else {
- sender.sendMessage(this.Notice(this.getMessage("RenewOff")));
- }
- } else {
- sender.sendMessage(this.Notice(this.getMessage("RenewOff")));
- }
- } else if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("yes")
- && !args[1].equalsIgnoreCase("on")) {
- if (!args[1].equalsIgnoreCase("false") && !args[1].equalsIgnoreCase("no")
- && !args[1].equalsIgnoreCase("off")) {
- sender.sendMessage(this.Notice(this.getMessage("InvalidArg")));
- } else {
- this.setAutoRenew(sender.getName(), false);
- sender.sendMessage(this.Notice(this.getMessage("RenewTurnOff")));
- }
- } else {
- this.setAutoRenew(sender.getName(), true);
- sender.sendMessage(this.Notice(this.getMessage("RenewTurnOn")));
- }
- return false;
- }
- String[] help;
- if (args[0].equalsIgnoreCase("help")) {
- help = new String[] { this.Notice(this.getMessage("Help1")), this.Notice(this.getMessage("Help2")),
- this.Notice(this.getMessage("Help3")), this.Notice(this.getMessage("Help4")) };
- sender.sendMessage(help);
- }
- if (sender.isOp() || sender.hasPermission("hcregion.admin")) {
- if (args[0].equalsIgnoreCase("buycheck")) {
- if (args.length < 1) {
- sender.sendMessage(this.Warning("Arguments invalides - /buyregion buycheck <joueur>"));
- } else {
- this.checkPlayerRegionCount(args[1], sender);
- }
- } else if (args[0].equalsIgnoreCase("rentcheck")) {
- if (args.length < 1) {
- sender.sendMessage(this.Warning("Arguments invalides - /buyregion rentcheck <joueur>"));
- } else {
- this.checkPlayerRentedRegionCount(args[1], sender);
- }
- } else {
- int help1;
- if (args[0].equalsIgnoreCase("buyset")) {
- if (args.length < 3) {
- sender.sendMessage(
- this.Warning("Arguments invalides - /buyregion buyset <joueur> <montant>"));
- } else {
- try {
- help1 = Integer.parseInt(args[2]);
- if (help1 < 0) {
- help1 = 0;
- }
- } catch (Exception var15) {
- sender.sendMessage(
- this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
- return false;
- }
- this.setBoughtRegionsCount(args[1], help1, sender);
- }
- } else if (args[0].equalsIgnoreCase("rentset")) {
- if (args.length < 3) {
- sender.sendMessage(
- this.Warning("Arguments invalides - /buyregion rentset <joueur> <montant>"));
- } else {
- try {
- help1 = Integer.parseInt(args[2]);
- if (help1 < 0) {
- help1 = 0;
- }
- } catch (Exception var14) {
- sender.sendMessage(
- this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
- return false;
- }
- this.setRentedRegionsCount(args[1], help1, sender);
- }
- } else if (args[0].equalsIgnoreCase("buymax")) {
- try {
- if (args.length < 2) {
- sender.sendMessage(this.Notice("BuyRegionMax actuel: " + this.buyRegionMax));
- } else {
- try {
- help1 = Integer.parseInt(args[1]);
- if (help1 < 0) {
- help1 = 0;
- }
- } catch (Exception var12) {
- sender.sendMessage(
- this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
- return false;
- }
- this.buyRegionMax = help1;
- this.getConfig().set("BuyRegionMax", Integer.valueOf(help1));
- this.saveConfig();
- sender.sendMessage(this.Notice("BuyRegionMax a été mis à jour à " + help1));
- }
- } catch (Exception var13) {
- sender.sendMessage(
- "Une erreur est survenue ... vérifier toutes les valeurs et essayer à nouveau.");
- }
- } else if (args[0].equalsIgnoreCase("rentmax")) {
- try {
- if (args.length < 2) {
- sender.sendMessage(this.Notice("RentRegionMax actuel: " + this.rentRegionMax));
- } else {
- try {
- help1 = Integer.parseInt(args[1]);
- if (help1 < 0) {
- help1 = 0;
- }
- } catch (Exception var10) {
- sender.sendMessage(
- this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
- return false;
- }
- this.rentRegionMax = help1;
- this.getConfig().set("RentRegionMax", Integer.valueOf(help1));
- this.saveConfig();
- sender.sendMessage(this.Warning("RentRegionMax a été mis à jour à " + help1));
- }
- } catch (Exception var11) {
- sender.sendMessage(this.Warning(
- "Une erreur est survenue ... vérifier toutes les valeurs et essayer à nouveau."));
- }
- } else {
- boolean help2;
- if (args[0].equalsIgnoreCase("buyperms")) {
- try {
- if (args.length > 1) {
- if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
- sender.sendMessage(
- this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
- } else {
- help2 = Boolean.parseBoolean(args[1]);
- if (help2) {
- this.requireBuyPerms = true;
- this.getConfig().set("RequireBuyPerms", Boolean.valueOf(true));
- } else {
- this.requireBuyPerms = false;
- this.getConfig().set("RequireBuyPerms", Boolean.valueOf(false));
- }
- sender.sendMessage(this.Notice("RequireBuyPerms réglé."));
- this.saveConfig();
- }
- } else {
- sender.sendMessage(this.Notice(
- "RequireBuyPerms: " + this.getConfig().getBoolean("RequireBuyPerms")));
- }
- } catch (Exception var9) {
- sender.sendMessage(this.Warning(
- "Une erreur est survenue... Syntaxe: /buyregion buyperms true/false"));
- return false;
- }
- } else if (args[0].equalsIgnoreCase("rentperms")) {
- try {
- if (args.length > 1) {
- if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
- sender.sendMessage(
- this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
- } else {
- help2 = Boolean.parseBoolean(args[1]);
- if (help2) {
- this.requireRentPerms = true;
- this.getConfig().set("RequireRentPerms", Boolean.valueOf(true));
- } else {
- this.requireRentPerms = false;
- this.getConfig().set("RequireRentPerms", Boolean.valueOf(false));
- }
- sender.sendMessage(this.Notice("RequireRentPerms réglé."));
- this.saveConfig();
- }
- } else {
- sender.sendMessage(this.Notice("RequireRentPerms: "
- + this.getConfig().getBoolean("RequireRentPerms")));
- }
- } catch (Exception var8) {
- sender.sendMessage(this.Warning(
- "Une erreur est survenue... Syntaxe: /buyregion rentperms true/false"));
- return false;
- }
- } else if (args[0].equalsIgnoreCase("buymode")) {
- try {
- if (args.length > 1) {
- if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
- sender.sendMessage(
- this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
- } else {
- help2 = Boolean.parseBoolean(args[1]);
- if (help2) {
- this.requireBuyMode = true;
- this.getConfig().set("RequireBuyMode", Boolean.valueOf(true));
- } else {
- this.requireBuyMode = false;
- this.getConfig().set("RequireBuyMode", Boolean.valueOf(false));
- }
- sender.sendMessage(this.Notice("RequireBuyMode réglé."));
- this.saveConfig();
- }
- } else {
- sender.sendMessage(this.Notice(
- "RequireBuyMode: " + this.getConfig().getBoolean("RequireBuyMode")));
- }
- } catch (Exception var7) {
- sender.sendMessage(this.Warning(
- "Une erreur est survenue ... Syntaxe: /buyregion buymode true/false"));
- return false;
- }
- } else if (args[0].equalsIgnoreCase("evict")) {
- if (args.length <= 1) {
- sender.sendMessage(this.Warning("Syntaxe invalide: /buyregion evict <region>"));
- return false;
- }
- String help3 = args[1];
- if ((new File(signDataLoc + help3 + ".digi")).exists()) {
- if (this.evictRegion(help3)) {
- sender.sendMessage(this.Notice("Expulsion de la région terminée!"));
- } else {
- sender.sendMessage(this.Warning("L'expulsion de la région a échoué."));
- }
- } else {
- sender.sendMessage(this.Warning("La région n'est actuellement pas loué!"));
- }
- } else {
- help = new String[] { this.Notice("Commandes Administrateur:"),
- this.Notice("/buyregion buymode <true/false> - définit RequireBuyMode"),
- this.Notice(
- "/buyregion buycheck <joueur> - vérifier les régions achetés pour <joueur>"),
- this.Notice(
- "/buyregion rentcheck <player> - vérifier les régions loués pour <joueur>"),
- this.Notice(
- "/buyregion buyset <joueur> <montant> - définit les régions totales achetées pour <joueur>"),
- this.Notice(
- "/buyregion rentset <player> <amount> - définit les régions totales loués pour <joueur>"),
- this.Notice("/buyregion buymax - Afficher BuyRegionMax actuel"),
- this.Notice("/buyregion buymax <montant> - définit BuyRegionMax"),
- this.Notice("/buyregion rentmax - Afficher RentRegionMax actuel"),
- this.Notice("/buyregion rentmax <montant> - définit RentRegionMax"),
- this.Notice("/buyregion evict <region> - Expulsé les locataires <region>") };
- sender.sendMessage(help);
- }
- }
- }
- }
- }
- }
- return false;
- }
- private boolean evictRegion(String regionName) {
- try {
- BuyRegion.RentableRegion e = this.loadRegion(regionName);
- this.RentedRegionExpirations.remove(regionName);
- this.saveRentedRegionExpirations();
- World world = this.getServer().getWorld(e.worldName);
- RegionManager rm = this.getWorldGuard().getRegionManager(world);
- ProtectedRegion region = rm.getRegion(regionName);
- new DefaultDomain();
- DefaultDomain dd = region.getMembers();
- dd.removePlayer(e.renter);
- region.setMembers(dd);
- this.removeRentedRegionFromCount(e.renter);
- double x = Double.parseDouble(e.signLocationX);
- double y = Double.parseDouble(e.signLocationY);
- double z = Double.parseDouble(e.signLocationZ);
- float pitch = Float.parseFloat(e.signLocationPitch);
- float yaw = Float.parseFloat(e.signLocationYaw);
- Location signLoc = new Location(world, x, y, z, pitch, yaw);
- Block currentBlock = world.getBlockAt(signLoc);
- Sign regionFile;
- if (currentBlock.getType() != Material.SIGN_POST && currentBlock.getType() != Material.WALL_SIGN) {
- try {
- if (e.signType == "WALL_SIGN") {
- currentBlock.setType(Material.WALL_SIGN);
- } else {
- currentBlock.setType(Material.SIGN_POST);
- }
- regionFile = (Sign) currentBlock.getState();
- regionFile.setLine(0, e.signLine1);
- regionFile.setLine(1, e.signLine2);
- regionFile.setLine(2, e.signLine3);
- regionFile.setLine(3, e.signLine4);
- regionFile.update();
- } catch (Exception var19) {
- this.getLogger().info("RentRegion automatic sign creation failed for region " + e.regionName);
- }
- } else {
- regionFile = (Sign) currentBlock.getState();
- regionFile.setLine(0, e.signLine1);
- regionFile.setLine(1, e.signLine2);
- regionFile.setLine(2, e.signLine3);
- regionFile.setLine(3, e.signLine4);
- regionFile.update();
- }
- File regionFile1 = new File(signDataLoc + regionName + ".digi");
- if (regionFile1.exists()) {
- regionFile1.delete();
- }
- Player player = this.getServer().getPlayer(e.renter);
- if (player instanceof Player) {
- player.sendMessage(this.Notice(this.getMessage("EvictedFrom") + " " + regionName));
- }
- this.logActivity(e.renter, " EVICTED " + e.regionName);
- return true;
- } catch (Exception var20) {
- this.getLogger().info("An error occured during an eviction.");
- return false;
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST)
- public void signChangeMonitor(SignChangeEvent event) {
- try {
- Player e = event.getPlayer();
- if (event.getLine(0).equalsIgnoreCase("[WGRSA]") || event.getLine(0).equalsIgnoreCase("[BuyRegion]")
- || event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
- if (!e.hasPermission("hcregion.create") && !e.isOp()) {
- event.setLine(0, "-limité-");
- } else {
- String regionName = event.getLine(1);
- World world = event.getBlock().getWorld();
- RegionManager rm = this.getWorldGuard().getRegionManager(world);
- ProtectedRegion region = rm.getRegion(regionName);
- if (region == null) {
- event.getPlayer().sendMessage(this.Warning(this.getMessage("RegionNoExist")));
- event.setLine(0, "-invalide-");
- return;
- }
- try {
- String dateString = event.getLine(3);
- try {
- double e1 = Double.parseDouble(event.getLine(2));
- if (e1 <= 0.0D) {
- throw new Exception();
- }
- if (event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
- String[] expiration = dateString.split("\\s");
- int e2 = Integer.parseInt(expiration[0]);
- BuyRegion.DateResult dateResult = this.parseDateString(e2, expiration[1]);
- if (dateResult.IsError) {
- throw new Exception();
- }
- }
- } catch (Exception var13) {
- event.getPlayer().sendMessage(this.Notice(this.getMessage("InvalidPriceTime")));
- event.setLine(0, "-invalide-");
- return;
- }
- } catch (Exception var14) {
- event.getPlayer().sendMessage(this.Notice("Invalid amount!"));
- event.setLine(0, "-invalide-");
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
- event.setLine(0, "[RentRegion]");
- } else {
- event.setLine(0, "[BuyRegion]");
- }
- event.getPlayer().sendMessage(this.Notice("La pancarte HcRegion a été créé!"));
- }
- }
- } catch (Exception var15) {
- this.getLogger().info("An error occured in signChangeMonitor");
- }
- }
- private void saveRentableRegion(BuyRegion.RentableRegion region) {
- try {
- saveRegion(region);
- } catch (Exception var3) {
- this.getLogger().info("An error has occured saving a RentableRegion.");
- }
- }
- public class DateResult {
- public long Time;
- public String Text;
- boolean IsError;
- public DateResult(long time, String text, boolean isError) {
- this.Time = time;
- this.Text = text;
- this.IsError = isError;
- }
- }
- public class RentableRegion {
- public String worldName;
- public String regionName;
- public String renter;
- public String signLocationX;
- public String signLocationY;
- public String signLocationZ;
- public String signLocationPitch;
- public String signLocationYaw;
- public String signDirection;
- public String signLine1;
- public String signLine2;
- public String signLine3;
- public String signLine4;
- public String signType;
- public RentableRegion() {
- this.worldName = "";
- this.regionName = "";
- this.renter = "";
- this.signLocationX = "";
- this.signLocationY = "";
- this.signLocationZ = "";
- this.signLocationPitch = "";
- this.signLocationYaw = "";
- this.signDirection = "";
- this.signLine1 = "";
- this.signLine2 = "";
- this.signLine3 = "";
- this.signLine4 = "";
- this.signType = "";
- }
- public RentableRegion(String input) {
- try {
- String[] e = input.split("%%%");
- this.worldName = e[0];
- this.regionName = e[1];
- this.renter = e[2];
- this.signLocationX = e[3];
- this.signLocationY = e[4];
- this.signLocationZ = e[5];
- this.signLocationPitch = e[6];
- this.signLocationYaw = e[7];
- this.signDirection = e[8];
- this.signLine1 = e[9];
- this.signLine2 = e[10];
- this.signLine3 = e[11];
- this.signLine4 = e[12];
- this.signType = e[13];
- } catch (Exception var4) {
- BuyRegion.this.getLogger().info("An error occured while instantiating a RentableRegion.");
- }
- }
- public String toString() {
- return this.worldName + "%%%" + this.regionName + "%%%" + this.renter + "%%%" + this.signLocationX + "%%%"
- + this.signLocationY + "%%%" + this.signLocationZ + "%%%" + this.signLocationPitch + "%%%"
- + this.signLocationYaw + "%%%" + this.signDirection + "%%%" + this.signLine1 + "%%%"
- + this.signLine2 + "%%%" + this.signLine3 + "%%%" + this.signLine4 + "%%%" + this.signType;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement