Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.40 KB | None | 0 0
  1. package com.region;
  2.  
  3. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  4. import com.sk89q.worldguard.domains.DefaultDomain;
  5. import com.sk89q.worldguard.protection.managers.RegionManager;
  6. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.FileOutputStream;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.io.ObjectInputStream;
  13. import java.io.ObjectOutputStream;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Calendar;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.Iterator;
  19. import java.util.concurrent.ConcurrentHashMap;
  20. import net.milkbowl.vault.economy.Economy;
  21. import net.milkbowl.vault.economy.EconomyResponse;
  22. import org.bukkit.ChatColor;
  23. import org.bukkit.Location;
  24. import org.bukkit.Material;
  25. import org.bukkit.World;
  26. import org.bukkit.block.Block;
  27. import org.bukkit.block.Sign;
  28. import org.bukkit.command.Command;
  29. import org.bukkit.command.CommandSender;
  30. import org.bukkit.entity.Player;
  31. import org.bukkit.event.EventHandler;
  32. import org.bukkit.event.EventPriority;
  33. import org.bukkit.event.Listener;
  34. import org.bukkit.event.block.SignChangeEvent;
  35. import org.bukkit.event.player.PlayerInteractEvent;
  36. import org.bukkit.plugin.Plugin;
  37. import org.bukkit.plugin.RegisteredServiceProvider;
  38. import org.bukkit.plugin.java.JavaPlugin;
  39.  
  40. public class BuyRegion extends JavaPlugin implements Listener {
  41. static final String dataLoc;
  42. static final String signDataLoc;
  43. static final String rentedRE = "RentedRegionExpirations";
  44. static final String rentedRC = "RentedRegionCounts";
  45. static final String autoRenewsFileName = "AutoRenews";
  46. static long tickRate;
  47. public static Economy econ;
  48. public int buyRegionMax = 0;
  49. public int rentRegionMax = 0;
  50. public boolean requireBuyMode = true;
  51. public boolean requireBuyPerms = false;
  52. public boolean requireRentPerms = false;
  53. public String dateFormatString = "yy/MM/dd h:mma";
  54. public HashMap<String, Boolean> BuyMode = new HashMap<String, Boolean>();
  55. public HashMap<String, Integer> RegionCounts = new HashMap<String, Integer>();
  56. public ConcurrentHashMap<String, Integer> RentedRegionCounts = new ConcurrentHashMap<String, Integer>();
  57. public ConcurrentHashMap<String, Long> RentedRegionExpirations = new ConcurrentHashMap<String, Long>();
  58. public ConcurrentHashMap<String, Boolean> AutoRenews = new ConcurrentHashMap<String, Boolean>();
  59. public ConcurrentHashMap<String, String> Messages = new ConcurrentHashMap<String, String>();
  60.  
  61. static {
  62. dataLoc = "plugins" + File.separator + "BuyRegion" + File.separator;
  63. signDataLoc = "plugins" + File.separator + "BuyRegion" + File.separator + "rent" + File.separator;
  64. tickRate = 60L;
  65. econ = null;
  66. }
  67.  
  68. public void onEnable() {
  69. try {
  70. (new File(dataLoc)).mkdirs();
  71. (new File(signDataLoc)).mkdirs();
  72. this.getServer().getPluginManager().registerEvents(this, this);
  73. this.getLogger().info("BuyRegion - Maintained by Luke199");
  74. if (!this.setupEconomy()) {
  75. this.getLogger().info("Disabled due to no Vault dependency found!");
  76. this.getServer().getPluginManager().disablePlugin(this);
  77. return;
  78. }
  79.  
  80. this.Messages = this.getDefaultMessages();
  81. this.getConfig().options().copyDefaults(true);
  82. this.loadRegionCounts();
  83. this.loadRentedRegionExpirations();
  84. this.loadRentedRegionCounts();
  85. this.loadAutoRenews();
  86.  
  87. try {
  88. this.buyRegionMax = this.getConfig().getInt("BuyRegionMax", 0);
  89. } catch (Exception var10) {
  90. this.buyRegionMax = 0;
  91. }
  92.  
  93. try {
  94. this.rentRegionMax = this.getConfig().getInt("RentRegionMax", 0);
  95. } catch (Exception var9) {
  96. this.rentRegionMax = 0;
  97. }
  98.  
  99. try {
  100. this.requireBuyMode = this.getConfig().getBoolean("RequireBuyMode", true);
  101. } catch (Exception var8) {
  102. this.requireBuyMode = true;
  103. }
  104.  
  105. try {
  106. tickRate = this.getConfig().getLong("CheckExpirationsInMins");
  107. tickRate = tickRate * 60L * 20L;
  108. } catch (Exception var7) {
  109. tickRate = 6000L;
  110. }
  111.  
  112. try {
  113. this.requireBuyPerms = this.getConfig().getBoolean("RequireBuyPerms", false);
  114. } catch (Exception var6) {
  115. this.requireBuyPerms = false;
  116. }
  117.  
  118. try {
  119. this.requireRentPerms = this.getConfig().getBoolean("RequireRentPerms", false);
  120. } catch (Exception var5) {
  121. this.requireRentPerms = false;
  122. }
  123.  
  124. try {
  125. this.setFormatString(this.getConfig().getString("DateFormat", "Default"));
  126. } catch (Exception var4) {
  127. this.dateFormatString = "yy/MM/dd h:mma";
  128. }
  129.  
  130. this.loadMessageConfig();
  131. this.saveConfig();
  132. this.scheduleRenterTask();
  133. File e = new File(dataLoc + "RegionActivityLog.txt");
  134. if (!e.exists()) {
  135. try {
  136. e.createNewFile();
  137. } catch (IOException var3) {
  138. this.getLogger().info("Error creating log file");
  139. }
  140. }
  141. } catch (Exception var11) {
  142. var11.printStackTrace();
  143. }
  144.  
  145. }
  146.  
  147. private void loadMessageConfig() {
  148. this.Messages.put("InvalidPriceTime",
  149. this.getConfig().getString("Messages.InvalidPriceTime", "Invalid sign. Invalid price or timespan!"));
  150. this.Messages.put("RegionNoExist",
  151. this.getConfig().getString("Messages.RegionNoExist", "Invalid sign. Region doesn\'t exist!"));
  152. this.Messages.put("EvictedFrom",
  153. this.getConfig().getString("Messages.EvictedFrom", "You have been evicted from"));
  154. this.Messages.put("InvalidArg", this.getConfig().getString("Messages.InvalidArg",
  155. "Invalid argument. Accepted values: true, false, yes, no, off, on"));
  156. this.Messages.put("RenewTurnOff",
  157. this.getConfig().getString("Messages.RenewTurnOff", "Auto-Renew has been turned OFF for you."));
  158. this.Messages.put("RenewTurnOn",
  159. this.getConfig().getString("Messages.RenewTurnOn", "Auto-Renew has been turned ON for you."));
  160. this.Messages.put("RenewOff", this.getConfig().getString("Messages.RenewOff", "Auto-Renew is off!"));
  161. this.Messages.put("RenewOn", this.getConfig().getString("Messages.RenewOn", "Auto-Renew is on!"));
  162. this.Messages.put("InvalidRenewArgs",
  163. this.getConfig().getString("Messages.InvalidRenewArgs", "Invalid args: /buyregion renew <region>"));
  164. this.Messages.put("BuyModeExit",
  165. this.getConfig().getString("Messages.BuyModeExit", "You have exited Buy Mode."));
  166. this.Messages.put("BuyModeEnter", this.getConfig().getString("Messages.BuyModeEnter",
  167. "You are now in Buy Mode - right-click the BuyRegion sign!"));
  168. this.Messages.put("ToEnterBuyMode",
  169. this.getConfig().getString("Messages.ToEnterBuyMode", "To enter Buy Mode type: /buyregion"));
  170. this.Messages.put("BuyModeRent",
  171. this.getConfig().getString("Messages.BuyModeRent", "You must be in Buy Mode to rent this region!"));
  172. this.Messages.put("BuyModeBuy",
  173. this.getConfig().getString("Messages.BuyModeBuy", "You must be in Buy Mode to buy this region!"));
  174. this.Messages.put("NotEnoughRent",
  175. this.getConfig().getString("Messages.NotEnoughRent", "Not enough money to rent this region!"));
  176. this.Messages.put("NotEnoughBuy",
  177. this.getConfig().getString("Messages.NotEnoughBuy", "Not enough money to buy this region!"));
  178. this.Messages.put("TransFailed", this.getConfig().getString("Messages.TransFailed", "Transaction Failed!"));
  179. this.Messages.put("Rented", this.getConfig().getString("Messages.Rented", "Congrats! You have rented"));
  180. this.Messages.put("NewBalance", this.getConfig().getString("Messages.NewBalance", "Your new balance is"));
  181. this.Messages.put("RentMax",
  182. this.getConfig().getString("Messages.RentMax", "You are not allowed to rent more regions. Max"));
  183. this.Messages.put("RentPerms",
  184. this.getConfig().getString("Messages.RentPerms", "You do not have permission to rent regions."));
  185. this.Messages.put("Balance", this.getConfig().getString("Messages.Balance", "Your balance is"));
  186. this.Messages.put("Purchased",
  187. this.getConfig().getString("Messages.Purchased", "Congrats! You have purchased"));
  188. this.Messages.put("BuyMax",
  189. this.getConfig().getString("Messages.BuyMax", "You are not allowed to buy more regions. Max"));
  190. this.Messages.put("BuyPerms",
  191. this.getConfig().getString("Messages.BuyPerms", "You do not have permission to buy regions."));
  192. this.Messages.put("NotRented", this.getConfig().getString("Messages.NotRented", "is not currently rented."));
  193. this.Messages.put("NotRenting", this.getConfig().getString("Messages.NotRenting",
  194. "You are not renting this region. You cannot renew it!"));
  195. this.Messages.put("NotEnoughRenew", this.getConfig().getString("Messages.NotEnoughRenew",
  196. "Not enough money to renew rental for this region!"));
  197. this.Messages.put("Renewed", this.getConfig().getString("Messages.Renewed", "Congrats! You have renewed"));
  198. this.Messages.put("Expired",
  199. this.getConfig().getString("Messages.Expired", "Your rental has expired for region"));
  200. this.Messages.put("Help1", this.getConfig().getString("Messages.Help1", "BuyRegion Commands"));
  201. this.Messages.put("Help2", this.getConfig().getString("Messages.Help2", "/buyregion - toggles buy mode"));
  202. this.Messages.put("Help3",
  203. this.getConfig().getString("Messages.Help3", "/buyregion renew <region> - renews rental of <region>"));
  204. this.Messages.put("Help4", this.getConfig().getString("Messages.Help4",
  205. "/buyregion autorenew <true/false> - sets auto-renew for all rented regions"));
  206. }
  207.  
  208. public void onDisable() {
  209. try {
  210. this.saveRegionCounts();
  211. this.saveRentedRegionExpirations();
  212. this.saveRentedRegionCounts();
  213. this.saveAutoRenews();
  214. this.getServer().getScheduler().cancelTasks(this);
  215. } catch (Exception var2) {
  216. this.getLogger().info("An error occured during shutdown.");
  217. }
  218.  
  219. }
  220.  
  221. private ConcurrentHashMap<String, String> getDefaultMessages() {
  222. ConcurrentHashMap<String, String> msgs = new ConcurrentHashMap<String, String>();
  223. msgs.put("InvalidPriceTime", "Invalid sign. Invalid price or timespan!");
  224. msgs.put("RegionNoExist", "Invalid sign. Region doesn\'t exist!");
  225. msgs.put("EvictedFrom", "You have been evicted from");
  226. msgs.put("InvalidArg", "Invalid argument. Accepted values: true, false, yes, no, off, on");
  227. msgs.put("RenewTurnOff", "Auto-Renew has been turned OFF for you.");
  228. msgs.put("RenewTurnOn", "Auto-Renew has been turned ON for you.");
  229. msgs.put("RenewOff", "Auto-Renew is off!");
  230. msgs.put("RenewOn", "Auto-Renew is on!");
  231. msgs.put("InvalidRenewArgs", "Invalid args: /buyregion renew <region>");
  232. msgs.put("BuyModeExit", "You have exited Buy Mode.");
  233. msgs.put("BuyModeEnter", "You are now in Buy Mode - right-click the BuyRegion sign!");
  234. msgs.put("ToEnterBuyMode", "To enter Buy Mode type: /buyregion");
  235. msgs.put("BuyModeRent", "You must be in Buy Mode to rent this region!");
  236. msgs.put("BuyModeBuy", "You must be in Buy Mode to buy this region!");
  237. msgs.put("NotEnoughRent", "Not enough money to rent this region!");
  238. msgs.put("NotEnoughBuy", "Not enough money to buy this region!");
  239. msgs.put("TransFailed", "Transaction Failed!");
  240. msgs.put("Rented", "Congrats! You have rented");
  241. msgs.put("NewBalance", "Your new balance is");
  242. msgs.put("RentMax", "You are not allowed to rent more regions. Max");
  243. msgs.put("RentPerms", "You do not have permission to rent regions.");
  244. msgs.put("Balance", "Your balance is");
  245. msgs.put("Purchased", "Congrats! You have purchased");
  246. msgs.put("BuyMax", "You are not allowed to buy more regions. Max");
  247. msgs.put("BuyPerms", "You do not have permission to buy regions.");
  248. msgs.put("NotRented", "is not currently rented.");
  249. msgs.put("NotRenting", "You are not renting this region. You cannot renew it!");
  250. msgs.put("NotEnoughRenew", "Not enough money to renew rental for this region!");
  251. msgs.put("Renewed", "Congrats! You have renewed");
  252. msgs.put("Expired", "Your rental has expired for region");
  253. msgs.put("Help1", "BuyRegion Commands");
  254. msgs.put("Help2", "/buyregion - toggles buy mode");
  255. msgs.put("Help3", "/buyregion renew <region> - renews rental of <region>");
  256. msgs.put("Help4", "/buyregion autorenew <true/false> - sets auto-renew for all rented regions");
  257. return msgs;
  258. }
  259.  
  260. private String getMessage(String key) {
  261. return (String) this.Messages.get(key);
  262. }
  263.  
  264. public void scheduleRenterTask() {
  265. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  266. @SuppressWarnings("deprecation")
  267. public void run() {
  268. try {
  269. long e = (new Date()).getTime();
  270. Iterator<String> var4 = BuyRegion.this.RentedRegionExpirations.keySet().iterator();
  271.  
  272. while (true) {
  273. String regionName;
  274. boolean renewed;
  275. BuyRegion.RentableRegion rentedRegion;
  276. do {
  277. long regionExp;
  278. do {
  279. do {
  280. if (!var4.hasNext()) {
  281. return;
  282. }
  283.  
  284. regionName = (String) var4.next();
  285. } while (!BuyRegion.this.RentedRegionExpirations.containsKey(regionName));
  286.  
  287. regionExp = ((Long) BuyRegion.this.RentedRegionExpirations.get(regionName)).longValue();
  288. } while (regionExp > e);
  289.  
  290. renewed = false;
  291. rentedRegion = BuyRegion.this.loadRegion(regionName);
  292. if (BuyRegion.this.AutoRenews.containsKey(rentedRegion.renter)
  293. && ((Boolean) BuyRegion.this.AutoRenews.get(rentedRegion.renter)).booleanValue()) {
  294. Player world = BuyRegion.this.getServer().getPlayer(rentedRegion.renter);
  295. Double rm = Double.valueOf(Double.parseDouble(rentedRegion.signLine3));
  296. if (BuyRegion.econ.getBalance(rentedRegion.renter) >= rm.doubleValue()) {
  297. EconomyResponse region = BuyRegion.econ.withdrawPlayer(rentedRegion.renter,
  298. rm.doubleValue());
  299. if (region.transactionSuccess()) {
  300. renewed = true;
  301. String[] dd = rentedRegion.signLine4.split(" ");
  302. long x = ((Long) BuyRegion.this.RentedRegionExpirations.get(regionName))
  303. .longValue();
  304. BuyRegion.DateResult y = BuyRegion.this.parseDateString(Integer.parseInt(dd[0]),
  305. dd[1], x);
  306. BuyRegion.this.RentedRegionExpirations.put(regionName, Long.valueOf(y.Time));
  307. BuyRegion.this.saveRentedRegionExpirations();
  308. BuyRegion.this.logActivity(rentedRegion.renter, " AUTORENEW " + regionName);
  309. SimpleDateFormat sdf = new SimpleDateFormat(BuyRegion.this.dateFormatString);
  310. if (world instanceof Player) {
  311. world.sendMessage(BuyRegion.this.Notice(BuyRegion.this.getMessage("Renewed")
  312. + " " + regionName + " -> " + sdf.format(new Date(y.Time))));
  313. world.sendMessage(
  314. BuyRegion.this.Notice(BuyRegion.this.getMessage("NewBalance") + " "
  315. + BuyRegion.econ.getBalance(rentedRegion.renter)));
  316. }
  317.  
  318. World z = BuyRegion.this.getServer().getWorld(rentedRegion.worldName);
  319. double x1 = Double.parseDouble(rentedRegion.signLocationX);
  320. double yaw = Double.parseDouble(rentedRegion.signLocationY);
  321. double currentBlock = Double.parseDouble(rentedRegion.signLocationZ);
  322. float player = Float.parseFloat(rentedRegion.signLocationPitch);
  323. float yaw1 = Float.parseFloat(rentedRegion.signLocationYaw);
  324. Location signLoc1 = new Location(z, x1, yaw, currentBlock, player, yaw1);
  325. Block currentBlock1 = z.getBlockAt(signLoc1);
  326. if (currentBlock1.getType() == Material.SIGN_POST
  327. || currentBlock1.getType() == Material.WALL_SIGN) {
  328. Sign theSign = (Sign) currentBlock1.getState();
  329. theSign.setLine(0, regionName);
  330. theSign.setLine(1, rentedRegion.renter);
  331. theSign.setLine(2, ChatColor.WHITE + "Until:");
  332. theSign.setLine(3, sdf.format(new Date(y.Time)));
  333. theSign.update();
  334. theSign.update();
  335. }
  336. }
  337. } else if (world instanceof Player) {
  338. world.sendMessage(BuyRegion.this.Notice(
  339. BuyRegion.this.getMessage("NotEnoughRenew") + " " + regionName + "!"));
  340. world.sendMessage(BuyRegion.this.Notice(BuyRegion.this.getMessage("Balance") + " "
  341. + BuyRegion.econ.getBalance(rentedRegion.renter)));
  342. }
  343. }
  344. } while (renewed);
  345.  
  346. BuyRegion.this.RentedRegionExpirations.remove(regionName);
  347. BuyRegion.this.saveRentedRegionExpirations();
  348. World world1 = BuyRegion.this.getServer().getWorld(rentedRegion.worldName);
  349. RegionManager rm1 = BuyRegion.this.getWorldGuard().getRegionManager(world1);
  350. ProtectedRegion region1 = rm1.getRegion(regionName);
  351. new DefaultDomain();
  352. DefaultDomain dd1 = region1.getMembers();
  353. dd1.removePlayer(rentedRegion.renter);
  354. region1.setMembers(dd1);
  355. BuyRegion.this.removeRentedRegionFromCount(rentedRegion.renter);
  356. double x2 = Double.parseDouble(rentedRegion.signLocationX);
  357. double y1 = Double.parseDouble(rentedRegion.signLocationY);
  358. double z1 = Double.parseDouble(rentedRegion.signLocationZ);
  359. float pitch = Float.parseFloat(rentedRegion.signLocationPitch);
  360. float yaw2 = Float.parseFloat(rentedRegion.signLocationYaw);
  361. Location signLoc = new Location(world1, x2, y1, z1, pitch, yaw2);
  362. Block currentBlock2 = world1.getBlockAt(signLoc);
  363. Sign regionFile;
  364. if (currentBlock2.getType() != Material.SIGN_POST
  365. && currentBlock2.getType() != Material.WALL_SIGN) {
  366. try {
  367. if (rentedRegion.signType == "WALL_SIGN") {
  368. currentBlock2.setType(Material.WALL_SIGN);
  369. } else {
  370. currentBlock2.setType(Material.SIGN_POST);
  371. }
  372.  
  373. regionFile = (Sign) currentBlock2.getState();
  374. regionFile.setLine(0, rentedRegion.signLine1);
  375. regionFile.setLine(1, rentedRegion.signLine2);
  376. regionFile.setLine(2, rentedRegion.signLine3);
  377. regionFile.setLine(3, rentedRegion.signLine4);
  378. regionFile.update();
  379. } catch (Exception var29) {
  380. BuyRegion.this.getLogger().info("RentRegion automatic sign creation failed for region "
  381. + rentedRegion.regionName);
  382. }
  383. } else {
  384. regionFile = (Sign) currentBlock2.getState();
  385. regionFile.setLine(0, rentedRegion.signLine1);
  386. regionFile.setLine(1, rentedRegion.signLine2);
  387. regionFile.setLine(2, rentedRegion.signLine3);
  388. regionFile.setLine(3, rentedRegion.signLine4);
  389. regionFile.update();
  390. }
  391.  
  392. File regionFile1 = new File(BuyRegion.signDataLoc + regionName + ".digi");
  393. if (regionFile1.exists()) {
  394. regionFile1.delete();
  395. }
  396.  
  397. Player player1 = BuyRegion.this.getServer().getPlayer(rentedRegion.renter);
  398. if (player1 instanceof Player) {
  399. player1.sendMessage(
  400. BuyRegion.this.Notice(BuyRegion.this.getMessage("Expired") + " " + regionName));
  401. }
  402.  
  403. BuyRegion.this.logActivity(rentedRegion.renter, " EXPIRED " + rentedRegion.regionName);
  404. }
  405. } catch (Exception var30) {
  406. var30.printStackTrace();
  407. }
  408. }
  409. }, tickRate, tickRate);
  410. }
  411.  
  412. @SuppressWarnings("deprecation")
  413. public void renewRental(String regionName, String playerName, CommandSender sender) {
  414. try {
  415. if ((new File(signDataLoc + regionName + ".digi")).exists()
  416. && this.RentedRegionExpirations.containsKey(regionName)) {
  417. BuyRegion.RentableRegion e = this.loadRegion(regionName);
  418. if (sender.getName().equalsIgnoreCase(e.renter)) {
  419. Double regionPrice = Double.valueOf(Double.parseDouble(e.signLine3));
  420. if (econ.getBalance(playerName) >= regionPrice.doubleValue()) {
  421. EconomyResponse response = econ.withdrawPlayer(playerName, regionPrice.doubleValue());
  422. if (response.transactionSuccess()) {
  423. String[] timeSpan = e.signLine4.split(" ");
  424. long currentExpiration = ((Long) this.RentedRegionExpirations.get(regionName)).longValue();
  425. BuyRegion.DateResult timeData = this.parseDateString(Integer.parseInt(timeSpan[0]),
  426. timeSpan[1], currentExpiration);
  427. this.RentedRegionExpirations.put(regionName, Long.valueOf(timeData.Time));
  428. this.saveRentedRegionExpirations();
  429. this.logActivity(playerName, " RENEW " + regionName);
  430. SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormatString);
  431. sender.sendMessage(this.Notice(this.getMessage("Renewed") + " " + regionName + " until "
  432. + sdf.format(new Date(timeData.Time))));
  433. sender.sendMessage(
  434. this.Notice(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
  435. World world = this.getServer().getWorld(e.worldName);
  436. double x = Double.parseDouble(e.signLocationX);
  437. double y = Double.parseDouble(e.signLocationY);
  438. double z = Double.parseDouble(e.signLocationZ);
  439. float pitch = Float.parseFloat(e.signLocationPitch);
  440. float yaw = Float.parseFloat(e.signLocationYaw);
  441. Location signLoc = new Location(world, x, y, z, pitch, yaw);
  442. Block currentBlock = world.getBlockAt(signLoc);
  443. if (currentBlock.getType() == Material.SIGN_POST
  444. || currentBlock.getType() == Material.WALL_SIGN) {
  445. Sign theSign = (Sign) currentBlock.getState();
  446. theSign.setLine(0, regionName);
  447. theSign.setLine(1, playerName);
  448. theSign.setLine(2, ChatColor.WHITE + "Until:");
  449. theSign.setLine(3, sdf.format(new Date(timeData.Time)));
  450. theSign.update();
  451. theSign.update();
  452. }
  453. } else {
  454. sender.sendMessage(this.Notice(this.getMessage("TransFailed")));
  455. }
  456. } else {
  457. sender.sendMessage(this.Notice(this.getMessage("NotEnoughRenew")));
  458. sender.sendMessage(this.Notice(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
  459. }
  460. } else {
  461. sender.sendMessage(this.Notice(this.getMessage("NotRenting")));
  462. }
  463. } else {
  464. sender.sendMessage(this.Notice(regionName + " " + this.getMessage("NotRented")));
  465. }
  466. } catch (Exception var24) {
  467. this.getLogger().info("An error has occured while renewing rental for: " + regionName);
  468. }
  469.  
  470. }
  471.  
  472. private void logActivity(String player, String action) {
  473. try {
  474. Date e = new Date();
  475. File file = new File(dataLoc + "RegionActivityLog.txt");
  476. FileWriter out = new FileWriter(file, true);
  477. out.write(e.toString() + " [" + player + "] " + action + "\r\n");
  478. out.flush();
  479. out.close();
  480. } catch (IOException var6) {
  481. this.getLogger().info("An error occured while trying to log activity.");
  482. }
  483.  
  484. }
  485.  
  486. private void setFormatString(String input) {
  487. try {
  488. if (input.equalsIgnoreCase("US")) {
  489. this.dateFormatString = "MM/dd/yy h:mma";
  490. } else if (input.equalsIgnoreCase("EU")) {
  491. this.dateFormatString = "dd/MM/yy h:mma";
  492. } else {
  493. this.dateFormatString = "yy/MM/dd h:mma";
  494. }
  495. } catch (Exception var3) {
  496. this.dateFormatString = "yy/MM/dd h:mma";
  497. }
  498.  
  499. }
  500.  
  501. @SuppressWarnings("unchecked")
  502. private void loadRegionCounts() {
  503. try {
  504. if ((new File(dataLoc + "RegionCounts.digi")).exists()) {
  505. this.RegionCounts = (HashMap<String, Integer>) load(dataLoc, "RegionCounts");
  506. } else {
  507. save(this.RegionCounts, dataLoc, "RegionCounts");
  508. }
  509.  
  510. } catch (Exception var2) {
  511. this.getLogger().info("Error occured loading RegionCounts.digi");
  512. }
  513. }
  514.  
  515. @SuppressWarnings("unchecked")
  516. private void loadAutoRenews() {
  517. try {
  518. if ((new File(dataLoc + "AutoRenews" + ".digi")).exists()) {
  519. this.AutoRenews = (ConcurrentHashMap<String, Boolean>) load(dataLoc, "AutoRenews");
  520. } else {
  521. save(this.AutoRenews, dataLoc, "AutoRenews");
  522. }
  523.  
  524. } catch (Exception var2) {
  525. this.getLogger().info("Error occured loading AutoRenews");
  526. }
  527. }
  528.  
  529. @SuppressWarnings("unchecked")
  530. private void loadRentedRegionCounts() {
  531. try {
  532. if ((new File(dataLoc + "RentedRegionCounts" + ".digi")).exists()) {
  533. this.RentedRegionCounts = (ConcurrentHashMap<String, Integer>) load(dataLoc, "RentedRegionCounts");
  534. } else {
  535. save(this.RentedRegionCounts, dataLoc, "RentedRegionCounts");
  536. }
  537.  
  538. } catch (Exception var2) {
  539. this.getLogger().info("Error occured loading RentedRegionCounts");
  540. }
  541. }
  542.  
  543. @SuppressWarnings("unchecked")
  544. private void loadRentedRegionExpirations() {
  545. try {
  546. if ((new File(dataLoc + "RentedRegionExpirations" + ".digi")).exists()) {
  547. this.RentedRegionExpirations = (ConcurrentHashMap<String, Long>) load(dataLoc,
  548. "RentedRegionExpirations");
  549. } else {
  550. save(this.RentedRegionExpirations, dataLoc, "RentedRegionExpirations");
  551. }
  552.  
  553. } catch (Exception var2) {
  554. this.getLogger().info("Error occured loading RentedRegionExpirations");
  555. }
  556. }
  557.  
  558. private int getBoughtRegionsCount(String playerName) {
  559. return this.RegionCounts.containsKey(playerName) ? ((Integer) this.RegionCounts.get(playerName)).intValue() : 0;
  560. }
  561.  
  562. private void removeRentedRegionFromCount(String playerName) {
  563. try {
  564. if (this.RentedRegionCounts.containsKey(playerName)) {
  565. int e = this.getRentedRegionsCount(playerName);
  566. if (e > 0) {
  567. --e;
  568. }
  569.  
  570. if (e >= 0) {
  571. this.RentedRegionCounts.put(playerName, Integer.valueOf(e));
  572. } else {
  573. this.RentedRegionCounts.put(playerName, Integer.valueOf(0));
  574. }
  575.  
  576. this.saveRentedRegionCounts();
  577. }
  578. } catch (Exception var3) {
  579. this.getLogger().info("An error occured while removing a rented region from a player\'s count.");
  580. }
  581.  
  582. }
  583.  
  584. private int getRentedRegionsCount(String playerName) {
  585. return this.RentedRegionCounts.containsKey(playerName)
  586. ? ((Integer) this.RentedRegionCounts.get(playerName)).intValue() : 0;
  587. }
  588.  
  589. private void setBoughtRegionsCount(String playerName, int amount, CommandSender sender) {
  590. try {
  591. this.RegionCounts.put(playerName, Integer.valueOf(amount));
  592. this.saveRegionCounts();
  593. sender.sendMessage(this.Notice(playerName + " bought regions set to " + amount));
  594. } catch (Exception var5) {
  595. this.getLogger().info("An error occured in setBoughtRegions");
  596. }
  597.  
  598. }
  599.  
  600. private void setRentedRegionsCount(String playerName, int amount, CommandSender sender) {
  601. try {
  602. this.RentedRegionCounts.put(playerName, Integer.valueOf(amount));
  603. this.saveRentedRegionCounts();
  604. sender.sendMessage(this.Notice(playerName + " rented regions set to " + amount));
  605. } catch (Exception var5) {
  606. this.getLogger().info("An error occured in setRentedRegionsCount");
  607. }
  608.  
  609. }
  610.  
  611. private void addRentedRegionFile(String playerName, String regionName, Sign sign) {
  612. BuyRegion.RentableRegion region = new BuyRegion.RentableRegion();
  613. Location tmpLoc = sign.getLocation();
  614. region.regionName = regionName;
  615. region.signLine1 = sign.getLine(0);
  616. region.signLine2 = sign.getLine(1);
  617. region.signLine3 = sign.getLine(2);
  618. region.signLine4 = sign.getLine(3);
  619. region.renter = playerName;
  620. region.signLocationX = String.valueOf(tmpLoc.getBlockX());
  621. region.signLocationY = String.valueOf(tmpLoc.getBlockY());
  622. region.signLocationZ = String.valueOf(tmpLoc.getBlockZ());
  623. region.signLocationPitch = String.valueOf(tmpLoc.getPitch());
  624. region.signLocationYaw = String.valueOf(tmpLoc.getYaw());
  625. region.signDirection = tmpLoc.getDirection().toString();
  626. region.worldName = sign.getWorld().getName();
  627. if (sign.getType() == Material.WALL_SIGN) {
  628. region.signType = "WALL_SIGN";
  629. } else {
  630. region.signType = "SIGN_POST";
  631. }
  632.  
  633. this.saveRentableRegion(region);
  634. }
  635.  
  636. private void addBoughtRegionToCounts(String playerName) {
  637. if (this.RegionCounts.containsKey(playerName)) {
  638. this.RegionCounts.put(playerName, Integer.valueOf(this.getBoughtRegionsCount(playerName) + 1));
  639. } else {
  640. this.RegionCounts.put(playerName, Integer.valueOf(1));
  641. }
  642.  
  643. this.saveRegionCounts();
  644. }
  645.  
  646. private void addRentedRegionToCounts(String playerName) {
  647. if (this.RentedRegionCounts.containsKey(playerName)) {
  648. this.RentedRegionCounts.put(playerName, Integer.valueOf(this.getRentedRegionsCount(playerName) + 1));
  649. } else {
  650. this.RentedRegionCounts.put(playerName, Integer.valueOf(1));
  651. }
  652.  
  653. this.saveRentedRegionCounts();
  654. }
  655.  
  656. private void saveAutoRenews() {
  657. try {
  658. save(this.AutoRenews, dataLoc, "AutoRenews");
  659. } catch (Exception var2) {
  660. this.getLogger().info("An error has occured saving AutoRenews");
  661. }
  662.  
  663. }
  664.  
  665. private void saveRentedRegionCounts() {
  666. try {
  667. save(this.RentedRegionCounts, dataLoc, "RentedRegionCounts");
  668. } catch (Exception var2) {
  669. this.getLogger().info("An error has occured saving Rented Region Counts");
  670. }
  671.  
  672. }
  673.  
  674. private void saveRegionCounts() {
  675. try {
  676. save(this.RegionCounts, dataLoc, "RegionCounts");
  677. } catch (Exception var2) {
  678. this.getLogger().info("An error has occured saving Region counts.");
  679. }
  680.  
  681. }
  682.  
  683. private void saveRentedRegionExpirations() {
  684. try {
  685. save(this.RentedRegionExpirations, dataLoc, "RentedRegionExpirations");
  686. } catch (Exception var2) {
  687. this.getLogger().info("An error has occured saving RentedRegionExpirations");
  688. }
  689.  
  690. }
  691.  
  692. private void checkPlayerRentedRegionCount(String playerName, CommandSender sender) {
  693. if (this.RentedRegionCounts.containsKey(playerName)) {
  694. sender.sendMessage(
  695. this.Notice(playerName + " a " + this.getRentedRegionsCount(playerName) + " régions loués."));
  696. } else {
  697. sender.sendMessage(this.Notice(playerName + " n'a pas de régions loués."));
  698. }
  699.  
  700. }
  701.  
  702. private void checkPlayerRegionCount(String playerName, CommandSender sender) {
  703. if (this.RegionCounts.containsKey(playerName)) {
  704. sender.sendMessage(
  705. this.Notice(playerName + " a " + this.getBoughtRegionsCount(playerName) + " régions achetés."));
  706. } else {
  707. sender.sendMessage(this.Notice(playerName + " n'a pas acheté de régions."));
  708. }
  709.  
  710. }
  711.  
  712. public static void saveRegion(BuyRegion.RentableRegion region) {
  713. save(region.toString(), signDataLoc, region.regionName);
  714. }
  715.  
  716. public BuyRegion.RentableRegion loadRegion(String regionName) {
  717. String tmp = (String) load(signDataLoc, regionName);
  718. return new BuyRegion.RentableRegion(tmp);
  719. }
  720.  
  721. public static void save(Object obj, String dataLoc, String file) {
  722. try {
  723. ObjectOutputStream e = new ObjectOutputStream(new FileOutputStream(dataLoc + file + ".digi"));
  724. e.writeObject(obj);
  725. e.flush();
  726. e.close();
  727. } catch (Exception var4) {
  728. var4.printStackTrace();
  729. }
  730.  
  731. }
  732.  
  733. public static Object load(String dataLoc, String file) {
  734. try {
  735. ObjectInputStream e = new ObjectInputStream(new FileInputStream(dataLoc + file + ".digi"));
  736. Object rv = e.readObject();
  737. e.close();
  738. return rv;
  739. } catch (Exception var4) {
  740. var4.printStackTrace();
  741. return null;
  742. }
  743. }
  744.  
  745. private String Notice(String msg) {
  746. return ChatColor.AQUA + "[HcRegion] " + ChatColor.YELLOW + msg;
  747. }
  748.  
  749. private String Warning(String msg) {
  750. return ChatColor.RED + "[HcRegion] " + ChatColor.YELLOW + msg;
  751. }
  752.  
  753. private void setAutoRenew(String playerName, boolean autoRenew) {
  754. if (autoRenew) {
  755. this.AutoRenews.put(playerName, Boolean.valueOf(true));
  756. this.saveAutoRenews();
  757. } else {
  758. this.AutoRenews.remove(playerName);
  759. this.saveAutoRenews();
  760. }
  761.  
  762. }
  763.  
  764. @SuppressWarnings("deprecation")
  765. @EventHandler
  766. public void onPunchSign(PlayerInteractEvent event) {
  767. try {
  768. if (event.getAction().name() == "RIGHT_CLICK_BLOCK") {
  769. Material e = event.getClickedBlock().getType();
  770. if (e == Material.SIGN_POST || e == Material.WALL_SIGN) {
  771. Sign sign = (Sign) event.getClickedBlock().getState();
  772. String topLine = sign.getLine(0);
  773. Player sender;
  774. String regionName;
  775. if (topLine.length() > 0
  776. && (topLine.equalsIgnoreCase("[BuyRegion]") || topLine.equalsIgnoreCase("[WGRSA]"))) {
  777. sender = event.getPlayer();
  778. regionName = sender.getName();
  779. if (topLine.equalsIgnoreCase("[WGRSA]")) {
  780. sign.setLine(0, "[BuyRegion]");
  781. sign.update();
  782. }
  783.  
  784. if (this.requireBuyPerms && !sender.hasPermission("hcregion.buy") && !sender.isOp()) {
  785. sender.sendMessage(this.Notice(this.getMessage("BuyPerms")));
  786. return;
  787. }
  788.  
  789. if (this.buyRegionMax > 0 && this.getBoughtRegionsCount(regionName) >= this.buyRegionMax
  790. && !sender.isOp() && !sender.hasPermission("hcregion.exempt")) {
  791. sender.sendMessage(this.Notice(this.getMessage("BuyMax") + " " + this.buyRegionMax));
  792. return;
  793. }
  794.  
  795. if (!this.BuyMode.containsKey(regionName) && this.requireBuyMode) {
  796. sender.sendMessage(this.Warning(this.getMessage("BuyModeBuy")));
  797. sender.sendMessage(this.Warning(this.getMessage("ToEnterBuyMode")));
  798. } else {
  799. double playerName1 = Double.parseDouble(sign.getLine(2));
  800. String regionName1 = sign.getLine(1);
  801. World dateString1 = sender.getWorld();
  802. RegionManager expiration1 = this.getWorldGuard().getRegionManager(dateString1);
  803. DefaultDomain dateResult1 = new DefaultDomain();
  804. dateResult1.addPlayer(regionName);
  805. ProtectedRegion world2 = expiration1.getRegion(regionName1);
  806. if (world2 == null) {
  807. sender.sendMessage(this.Notice(this.getMessage("RegionNoExist")));
  808. return;
  809. }
  810.  
  811. if (econ.getBalance(regionName) >= playerName1) {
  812. EconomyResponse rm1 = econ.withdrawPlayer(regionName, playerName1);
  813. if (rm1.transactionSuccess()) {
  814. world2.setOwners(dateResult1);
  815. expiration1.save();
  816. this.addBoughtRegionToCounts(regionName);
  817. sender.sendMessage(
  818. this.Notice(this.getMessage("Purchased") + " " + regionName1 + "!"));
  819. sender.sendMessage(this
  820. .Notice(this.getMessage("NewBalance") + " " + econ.getBalance(regionName)));
  821. this.logActivity(regionName, " BUY " + regionName1);
  822. sign.setLine(0, ChatColor.DARK_PURPLE + "** HcRegion **");
  823. sign.setLine(1, ChatColor.GREEN + "Maison de:");
  824. sign.setLine(2, ChatColor.GOLD + regionName);
  825. sign.setLine(3, ChatColor.DARK_PURPLE + "** HcRegion **");
  826. sign.update();
  827. this.BuyMode.remove(regionName);
  828. } else {
  829. sender.sendMessage(this.Notice(this.getMessage("TransFailed")));
  830. }
  831. } else {
  832. sender.sendMessage(this.Warning(this.getMessage("NotEnoughBuy")));
  833. sender.sendMessage(
  834. this.Warning(this.getMessage("Balance") + " " + econ.getBalance(regionName)));
  835. }
  836. }
  837. } else if (topLine.length() > 0 && topLine.equalsIgnoreCase("[RentRegion]")) {
  838. sender = event.getPlayer();
  839. regionName = sign.getLine(1);
  840. String playerName = sender.getName();
  841. if (this.requireRentPerms && !sender.hasPermission("hcregion.rent") && !sender.isOp()) {
  842. sender.sendMessage(this.Warning(this.getMessage("RentPerms")));
  843. return;
  844. }
  845.  
  846. if (this.rentRegionMax > 0 && this.getRentedRegionsCount(playerName) >= this.rentRegionMax
  847. && !sender.isOp() && !sender.hasPermission("hcregion.exempt")) {
  848. sender.sendMessage(this.Notice(this.getMessage("RentMax") + " " + this.rentRegionMax));
  849. return;
  850. }
  851.  
  852. if (!this.BuyMode.containsKey(playerName) && this.requireBuyMode) {
  853. sender.sendMessage(this.Warning(this.getMessage("BuyModeRent")));
  854. sender.sendMessage(this.Warning(this.getMessage("ToEnterBuyMode")));
  855. } else if (regionName.length() > 0) {
  856. String dateString = sign.getLine(3);
  857.  
  858. double regionPrice;
  859. BuyRegion.DateResult dateResult;
  860. try {
  861. regionPrice = Double.parseDouble(sign.getLine(2));
  862. String[] expiration = dateString.split("\\s");
  863. int world = Integer.parseInt(expiration[0]);
  864. dateResult = this.parseDateString(world, expiration[1]);
  865. if (dateResult.IsError) {
  866. throw new Exception();
  867. }
  868. } catch (Exception var19) {
  869. this.getLogger().info("Region price or expiration");
  870. sign.setLine(0, "-invalide-");
  871. sign.setLine(1, "<région ici>");
  872. sign.setLine(2, "<prix ici>");
  873. sign.setLine(3, "<laps de temps>");
  874. sign.update();
  875. this.getLogger()
  876. .info("Invalid [RentRegion] sign cleared at " + sign.getLocation().toString());
  877. return;
  878. }
  879.  
  880. World world1 = sender.getWorld();
  881. RegionManager rm = this.getWorldGuard().getRegionManager(world1);
  882. DefaultDomain dd = new DefaultDomain();
  883. dd.addPlayer(playerName);
  884. ProtectedRegion region = rm.getRegion(regionName);
  885. if (region == null) {
  886. sender.sendMessage(this.Notice(this.getMessage("RegionNoExist")));
  887. sign.setLine(0, "-invalide-");
  888. sign.setLine(1, "<région ici>");
  889. sign.setLine(2, "<prix ici>");
  890. sign.setLine(3, "<laps de temps>");
  891. sign.update();
  892. this.getLogger()
  893. .info("Invalid [RentRegion] sign cleared at " + sign.getLocation().toString());
  894. return;
  895. }
  896.  
  897. if (econ.getBalance(playerName) >= regionPrice) {
  898. EconomyResponse response = econ.withdrawPlayer(playerName, regionPrice);
  899. if (response.transactionSuccess()) {
  900. region.setMembers(dd);
  901. rm.save();
  902. this.addRentedRegionFile(playerName, regionName, sign);
  903. this.addRentedRegionToCounts(playerName);
  904. this.logActivity(playerName, " RENT " + regionName);
  905. SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormatString);
  906. sign.setLine(0, regionName);
  907. sign.setLine(1, playerName);
  908. sign.setLine(2, ChatColor.WHITE + "Until:");
  909. sign.setLine(3, sdf.format(new Date(dateResult.Time)));
  910. sign.update();
  911. sender.sendMessage(this.Notice(this.getMessage("Rented") + " " + regionName + " -> "
  912. + sdf.format(new Date(dateResult.Time))));
  913. sender.sendMessage(this
  914. .Notice(this.getMessage("NewBalance") + " " + econ.getBalance(playerName)));
  915. this.RentedRegionExpirations.put(regionName, Long.valueOf(dateResult.Time));
  916. this.saveRentedRegionExpirations();
  917. this.BuyMode.remove(playerName);
  918. } else {
  919. sender.sendMessage(this.Warning(this.getMessage("TransFailed")));
  920. }
  921. } else {
  922. sender.sendMessage(this.Warning(this.getMessage("NotEnoughRent")));
  923. sender.sendMessage(
  924. this.Warning(this.getMessage("Balance") + " " + econ.getBalance(playerName)));
  925. }
  926. }
  927. }
  928. }
  929. }
  930. } catch (Exception var20) {
  931. this.getLogger().info(var20.getMessage());
  932. }
  933.  
  934. }
  935.  
  936. private BuyRegion.DateResult parseDateString(int val, String type) {
  937. try {
  938. Date e = new Date();
  939. if (!type.equalsIgnoreCase("d") && !type.equalsIgnoreCase("day") && !type.equalsIgnoreCase("days")) {
  940. return !type.equalsIgnoreCase("h") && !type.equalsIgnoreCase("hour") && !type.equalsIgnoreCase("hours")
  941. ? (!type.equalsIgnoreCase("m") && !type.equalsIgnoreCase("mins")
  942. && !type.equalsIgnoreCase("min") && !type.equalsIgnoreCase("minutes")
  943. && !type.equalsIgnoreCase("minute")
  944. ? (!type.equalsIgnoreCase("s") && !type.equalsIgnoreCase("sec")
  945. && !type.equalsIgnoreCase("secs") && !type.equalsIgnoreCase("seconds")
  946. && !type.equalsIgnoreCase("second")
  947. ? new BuyRegion.DateResult(-1L, "ERROR", true)
  948. : new BuyRegion.DateResult(e.getTime() + (long) (val * 1000),
  949. val + " seconds", false))
  950. : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 1000),
  951. val + " minutes", false))
  952. : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 60 * 1000), val + " hours", false);
  953. } else {
  954. Calendar cal = Calendar.getInstance();
  955. cal.setTime(e);
  956. cal.add(5, val);
  957. return new BuyRegion.DateResult(cal.getTime().getTime(), val + " days", false);
  958. }
  959. } catch (Exception var5) {
  960. return new BuyRegion.DateResult(-1L, "ERROR", true);
  961. }
  962. }
  963.  
  964. private BuyRegion.DateResult parseDateString(int val, String type, long start) {
  965. try {
  966. Date e = new Date(start);
  967. if (!type.equalsIgnoreCase("d") && !type.equalsIgnoreCase("day") && !type.equalsIgnoreCase("days")) {
  968. return !type.equalsIgnoreCase("h") && !type.equalsIgnoreCase("hour") && !type.equalsIgnoreCase("hours")
  969. ? (!type.equalsIgnoreCase("m") && !type.equalsIgnoreCase("mins")
  970. && !type.equalsIgnoreCase("min") && !type.equalsIgnoreCase("minutes")
  971. && !type.equalsIgnoreCase("minute")
  972. ? (!type.equalsIgnoreCase("s") && !type.equalsIgnoreCase("sec")
  973. && !type.equalsIgnoreCase("secs") && !type.equalsIgnoreCase("seconds")
  974. && !type.equalsIgnoreCase("second")
  975. ? new BuyRegion.DateResult(-1L, "ERROR", true)
  976. : new BuyRegion.DateResult(e.getTime() + (long) (val * 1000),
  977. val + " seconds", false))
  978. : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 1000),
  979. val + " minutes", false))
  980. : new BuyRegion.DateResult(e.getTime() + (long) (val * 60 * 60 * 1000), val + " hours", false);
  981. } else {
  982. Calendar cal = Calendar.getInstance();
  983. cal.setTime(e);
  984. cal.add(5, val);
  985. return new BuyRegion.DateResult(cal.getTime().getTime(), val + " days", false);
  986. }
  987. } catch (Exception var7) {
  988. return new BuyRegion.DateResult(-1L, "ERROR", true);
  989. }
  990. }
  991.  
  992. private WorldGuardPlugin getWorldGuard() {
  993. Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard");
  994. return plugin != null && plugin instanceof WorldGuardPlugin ? (WorldGuardPlugin) plugin : null;
  995. }
  996.  
  997. private boolean setupEconomy() {
  998. try {
  999. if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
  1000. return false;
  1001. } else {
  1002. RegisteredServiceProvider<Economy> e = this.getServer().getServicesManager()
  1003. .getRegistration(Economy.class);
  1004. if (e == null) {
  1005. return false;
  1006. } else {
  1007. econ = (Economy) e.getProvider();
  1008. return econ != null;
  1009. }
  1010. }
  1011. } catch (Exception var2) {
  1012. this.getLogger().info("Error loading Vault! Plugin shutting down.");
  1013. return false;
  1014. }
  1015. }
  1016.  
  1017. private void toggleBuyMode(CommandSender sender) {
  1018. try {
  1019. String e = sender.getName();
  1020. if (!this.BuyMode.containsKey(e)) {
  1021. this.BuyMode.put(sender.getName(), Boolean.valueOf(true));
  1022. sender.sendMessage(this.Notice("BuyModeEnter"));
  1023. } else {
  1024. this.BuyMode.remove(e);
  1025. sender.sendMessage(this.Notice(this.getMessage("BuyModeExit")));
  1026. }
  1027. } catch (Exception var3) {
  1028. this.getLogger().info("An error occured in toggleBuyMode");
  1029. }
  1030.  
  1031. }
  1032.  
  1033. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  1034. if (cmd.getName().equalsIgnoreCase("buyregion")) {
  1035. if (args.length == 0) {
  1036. this.toggleBuyMode(sender);
  1037. } else {
  1038. if (args[0].equalsIgnoreCase("renew")) {
  1039. if (args.length < 2) {
  1040. sender.sendMessage(this.Notice(this.getMessage("InvalidRenewArgs")));
  1041. } else {
  1042. this.renewRental(args[1], sender.getName(), sender);
  1043. }
  1044.  
  1045. return false;
  1046. }
  1047.  
  1048. if (args[0].equalsIgnoreCase("autorenew")) {
  1049. if (args.length < 2) {
  1050. if (this.AutoRenews.containsKey(sender.getName())) {
  1051. if (((Boolean) this.AutoRenews.get(sender.getName())).booleanValue()) {
  1052. sender.sendMessage(this.Notice(this.getMessage("RenewOn")));
  1053. } else {
  1054. sender.sendMessage(this.Notice(this.getMessage("RenewOff")));
  1055. }
  1056. } else {
  1057. sender.sendMessage(this.Notice(this.getMessage("RenewOff")));
  1058. }
  1059. } else if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("yes")
  1060. && !args[1].equalsIgnoreCase("on")) {
  1061. if (!args[1].equalsIgnoreCase("false") && !args[1].equalsIgnoreCase("no")
  1062. && !args[1].equalsIgnoreCase("off")) {
  1063. sender.sendMessage(this.Notice(this.getMessage("InvalidArg")));
  1064. } else {
  1065. this.setAutoRenew(sender.getName(), false);
  1066. sender.sendMessage(this.Notice(this.getMessage("RenewTurnOff")));
  1067. }
  1068. } else {
  1069. this.setAutoRenew(sender.getName(), true);
  1070. sender.sendMessage(this.Notice(this.getMessage("RenewTurnOn")));
  1071. }
  1072.  
  1073. return false;
  1074. }
  1075.  
  1076. String[] help;
  1077. if (args[0].equalsIgnoreCase("help")) {
  1078. help = new String[] { this.Notice(this.getMessage("Help1")), this.Notice(this.getMessage("Help2")),
  1079. this.Notice(this.getMessage("Help3")), this.Notice(this.getMessage("Help4")) };
  1080. sender.sendMessage(help);
  1081. }
  1082.  
  1083. if (sender.isOp() || sender.hasPermission("hcregion.admin")) {
  1084. if (args[0].equalsIgnoreCase("buycheck")) {
  1085. if (args.length < 1) {
  1086. sender.sendMessage(this.Warning("Arguments invalides - /buyregion buycheck <joueur>"));
  1087. } else {
  1088. this.checkPlayerRegionCount(args[1], sender);
  1089. }
  1090. } else if (args[0].equalsIgnoreCase("rentcheck")) {
  1091. if (args.length < 1) {
  1092. sender.sendMessage(this.Warning("Arguments invalides - /buyregion rentcheck <joueur>"));
  1093. } else {
  1094. this.checkPlayerRentedRegionCount(args[1], sender);
  1095. }
  1096. } else {
  1097. int help1;
  1098. if (args[0].equalsIgnoreCase("buyset")) {
  1099. if (args.length < 3) {
  1100. sender.sendMessage(
  1101. this.Warning("Arguments invalides - /buyregion buyset <joueur> <montant>"));
  1102. } else {
  1103. try {
  1104. help1 = Integer.parseInt(args[2]);
  1105. if (help1 < 0) {
  1106. help1 = 0;
  1107. }
  1108. } catch (Exception var15) {
  1109. sender.sendMessage(
  1110. this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
  1111. return false;
  1112. }
  1113.  
  1114. this.setBoughtRegionsCount(args[1], help1, sender);
  1115. }
  1116. } else if (args[0].equalsIgnoreCase("rentset")) {
  1117. if (args.length < 3) {
  1118. sender.sendMessage(
  1119. this.Warning("Arguments invalides - /buyregion rentset <joueur> <montant>"));
  1120. } else {
  1121. try {
  1122. help1 = Integer.parseInt(args[2]);
  1123. if (help1 < 0) {
  1124. help1 = 0;
  1125. }
  1126. } catch (Exception var14) {
  1127. sender.sendMessage(
  1128. this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
  1129. return false;
  1130. }
  1131.  
  1132. this.setRentedRegionsCount(args[1], help1, sender);
  1133. }
  1134. } else if (args[0].equalsIgnoreCase("buymax")) {
  1135. try {
  1136. if (args.length < 2) {
  1137. sender.sendMessage(this.Notice("BuyRegionMax actuel: " + this.buyRegionMax));
  1138. } else {
  1139. try {
  1140. help1 = Integer.parseInt(args[1]);
  1141. if (help1 < 0) {
  1142. help1 = 0;
  1143. }
  1144. } catch (Exception var12) {
  1145. sender.sendMessage(
  1146. this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
  1147. return false;
  1148. }
  1149.  
  1150. this.buyRegionMax = help1;
  1151. this.getConfig().set("BuyRegionMax", Integer.valueOf(help1));
  1152. this.saveConfig();
  1153. sender.sendMessage(this.Notice("BuyRegionMax a été mis à jour à " + help1));
  1154. }
  1155. } catch (Exception var13) {
  1156. sender.sendMessage(
  1157. "Une erreur est survenue ... vérifier toutes les valeurs et essayer à nouveau.");
  1158. }
  1159. } else if (args[0].equalsIgnoreCase("rentmax")) {
  1160. try {
  1161. if (args.length < 2) {
  1162. sender.sendMessage(this.Notice("RentRegionMax actuel: " + this.rentRegionMax));
  1163. } else {
  1164. try {
  1165. help1 = Integer.parseInt(args[1]);
  1166. if (help1 < 0) {
  1167. help1 = 0;
  1168. }
  1169. } catch (Exception var10) {
  1170. sender.sendMessage(
  1171. this.Warning("Montant invalide. Saisissez un numéro pour le montant."));
  1172. return false;
  1173. }
  1174.  
  1175. this.rentRegionMax = help1;
  1176. this.getConfig().set("RentRegionMax", Integer.valueOf(help1));
  1177. this.saveConfig();
  1178. sender.sendMessage(this.Warning("RentRegionMax a été mis à jour à " + help1));
  1179. }
  1180. } catch (Exception var11) {
  1181. sender.sendMessage(this.Warning(
  1182. "Une erreur est survenue ... vérifier toutes les valeurs et essayer à nouveau."));
  1183. }
  1184. } else {
  1185. boolean help2;
  1186. if (args[0].equalsIgnoreCase("buyperms")) {
  1187. try {
  1188. if (args.length > 1) {
  1189. if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
  1190. sender.sendMessage(
  1191. this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
  1192. } else {
  1193. help2 = Boolean.parseBoolean(args[1]);
  1194. if (help2) {
  1195. this.requireBuyPerms = true;
  1196. this.getConfig().set("RequireBuyPerms", Boolean.valueOf(true));
  1197. } else {
  1198. this.requireBuyPerms = false;
  1199. this.getConfig().set("RequireBuyPerms", Boolean.valueOf(false));
  1200. }
  1201.  
  1202. sender.sendMessage(this.Notice("RequireBuyPerms réglé."));
  1203. this.saveConfig();
  1204. }
  1205. } else {
  1206. sender.sendMessage(this.Notice(
  1207. "RequireBuyPerms: " + this.getConfig().getBoolean("RequireBuyPerms")));
  1208. }
  1209. } catch (Exception var9) {
  1210. sender.sendMessage(this.Warning(
  1211. "Une erreur est survenue... Syntaxe: /buyregion buyperms true/false"));
  1212. return false;
  1213. }
  1214. } else if (args[0].equalsIgnoreCase("rentperms")) {
  1215. try {
  1216. if (args.length > 1) {
  1217. if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
  1218. sender.sendMessage(
  1219. this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
  1220. } else {
  1221. help2 = Boolean.parseBoolean(args[1]);
  1222. if (help2) {
  1223. this.requireRentPerms = true;
  1224. this.getConfig().set("RequireRentPerms", Boolean.valueOf(true));
  1225. } else {
  1226. this.requireRentPerms = false;
  1227. this.getConfig().set("RequireRentPerms", Boolean.valueOf(false));
  1228. }
  1229.  
  1230. sender.sendMessage(this.Notice("RequireRentPerms réglé."));
  1231. this.saveConfig();
  1232. }
  1233. } else {
  1234. sender.sendMessage(this.Notice("RequireRentPerms: "
  1235. + this.getConfig().getBoolean("RequireRentPerms")));
  1236. }
  1237. } catch (Exception var8) {
  1238. sender.sendMessage(this.Warning(
  1239. "Une erreur est survenue... Syntaxe: /buyregion rentperms true/false"));
  1240. return false;
  1241. }
  1242. } else if (args[0].equalsIgnoreCase("buymode")) {
  1243. try {
  1244. if (args.length > 1) {
  1245. if (!args[1].equalsIgnoreCase("true") && !args[1].equalsIgnoreCase("false")) {
  1246. sender.sendMessage(
  1247. this.Warning("Valeur invalide. Entrer \'true\' ou \'false\'"));
  1248. } else {
  1249. help2 = Boolean.parseBoolean(args[1]);
  1250. if (help2) {
  1251. this.requireBuyMode = true;
  1252. this.getConfig().set("RequireBuyMode", Boolean.valueOf(true));
  1253. } else {
  1254. this.requireBuyMode = false;
  1255. this.getConfig().set("RequireBuyMode", Boolean.valueOf(false));
  1256. }
  1257.  
  1258. sender.sendMessage(this.Notice("RequireBuyMode réglé."));
  1259. this.saveConfig();
  1260. }
  1261. } else {
  1262. sender.sendMessage(this.Notice(
  1263. "RequireBuyMode: " + this.getConfig().getBoolean("RequireBuyMode")));
  1264. }
  1265. } catch (Exception var7) {
  1266. sender.sendMessage(this.Warning(
  1267. "Une erreur est survenue ... Syntaxe: /buyregion buymode true/false"));
  1268. return false;
  1269. }
  1270. } else if (args[0].equalsIgnoreCase("evict")) {
  1271. if (args.length <= 1) {
  1272. sender.sendMessage(this.Warning("Syntaxe invalide: /buyregion evict <region>"));
  1273. return false;
  1274. }
  1275.  
  1276. String help3 = args[1];
  1277. if ((new File(signDataLoc + help3 + ".digi")).exists()) {
  1278. if (this.evictRegion(help3)) {
  1279. sender.sendMessage(this.Notice("Expulsion de la région terminée!"));
  1280. } else {
  1281. sender.sendMessage(this.Warning("L'expulsion de la région a échoué."));
  1282. }
  1283. } else {
  1284. sender.sendMessage(this.Warning("La région n'est actuellement pas loué!"));
  1285. }
  1286. } else {
  1287. help = new String[] { this.Notice("Commandes Administrateur:"),
  1288. this.Notice("/buyregion buymode <true/false> - définit RequireBuyMode"),
  1289. this.Notice(
  1290. "/buyregion buycheck <joueur> - vérifier les régions achetés pour <joueur>"),
  1291. this.Notice(
  1292. "/buyregion rentcheck <player> - vérifier les régions loués pour <joueur>"),
  1293. this.Notice(
  1294. "/buyregion buyset <joueur> <montant> - définit les régions totales achetées pour <joueur>"),
  1295. this.Notice(
  1296. "/buyregion rentset <player> <amount> - définit les régions totales loués pour <joueur>"),
  1297. this.Notice("/buyregion buymax - Afficher BuyRegionMax actuel"),
  1298. this.Notice("/buyregion buymax <montant> - définit BuyRegionMax"),
  1299. this.Notice("/buyregion rentmax - Afficher RentRegionMax actuel"),
  1300. this.Notice("/buyregion rentmax <montant> - définit RentRegionMax"),
  1301. this.Notice("/buyregion evict <region> - Expulsé les locataires <region>") };
  1302. sender.sendMessage(help);
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309.  
  1310. return false;
  1311. }
  1312.  
  1313. private boolean evictRegion(String regionName) {
  1314. try {
  1315. BuyRegion.RentableRegion e = this.loadRegion(regionName);
  1316. this.RentedRegionExpirations.remove(regionName);
  1317. this.saveRentedRegionExpirations();
  1318. World world = this.getServer().getWorld(e.worldName);
  1319. RegionManager rm = this.getWorldGuard().getRegionManager(world);
  1320. ProtectedRegion region = rm.getRegion(regionName);
  1321. new DefaultDomain();
  1322. DefaultDomain dd = region.getMembers();
  1323. dd.removePlayer(e.renter);
  1324. region.setMembers(dd);
  1325. this.removeRentedRegionFromCount(e.renter);
  1326. double x = Double.parseDouble(e.signLocationX);
  1327. double y = Double.parseDouble(e.signLocationY);
  1328. double z = Double.parseDouble(e.signLocationZ);
  1329. float pitch = Float.parseFloat(e.signLocationPitch);
  1330. float yaw = Float.parseFloat(e.signLocationYaw);
  1331. Location signLoc = new Location(world, x, y, z, pitch, yaw);
  1332. Block currentBlock = world.getBlockAt(signLoc);
  1333. Sign regionFile;
  1334. if (currentBlock.getType() != Material.SIGN_POST && currentBlock.getType() != Material.WALL_SIGN) {
  1335. try {
  1336. if (e.signType == "WALL_SIGN") {
  1337. currentBlock.setType(Material.WALL_SIGN);
  1338. } else {
  1339. currentBlock.setType(Material.SIGN_POST);
  1340. }
  1341.  
  1342. regionFile = (Sign) currentBlock.getState();
  1343. regionFile.setLine(0, e.signLine1);
  1344. regionFile.setLine(1, e.signLine2);
  1345. regionFile.setLine(2, e.signLine3);
  1346. regionFile.setLine(3, e.signLine4);
  1347. regionFile.update();
  1348. } catch (Exception var19) {
  1349. this.getLogger().info("RentRegion automatic sign creation failed for region " + e.regionName);
  1350. }
  1351. } else {
  1352. regionFile = (Sign) currentBlock.getState();
  1353. regionFile.setLine(0, e.signLine1);
  1354. regionFile.setLine(1, e.signLine2);
  1355. regionFile.setLine(2, e.signLine3);
  1356. regionFile.setLine(3, e.signLine4);
  1357. regionFile.update();
  1358. }
  1359.  
  1360. File regionFile1 = new File(signDataLoc + regionName + ".digi");
  1361. if (regionFile1.exists()) {
  1362. regionFile1.delete();
  1363. }
  1364.  
  1365. Player player = this.getServer().getPlayer(e.renter);
  1366. if (player instanceof Player) {
  1367. player.sendMessage(this.Notice(this.getMessage("EvictedFrom") + " " + regionName));
  1368. }
  1369.  
  1370. this.logActivity(e.renter, " EVICTED " + e.regionName);
  1371. return true;
  1372. } catch (Exception var20) {
  1373. this.getLogger().info("An error occured during an eviction.");
  1374. return false;
  1375. }
  1376. }
  1377.  
  1378. @EventHandler(priority = EventPriority.HIGHEST)
  1379. public void signChangeMonitor(SignChangeEvent event) {
  1380. try {
  1381. Player e = event.getPlayer();
  1382. if (event.getLine(0).equalsIgnoreCase("[WGRSA]") || event.getLine(0).equalsIgnoreCase("[BuyRegion]")
  1383. || event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
  1384. if (!e.hasPermission("hcregion.create") && !e.isOp()) {
  1385. event.setLine(0, "-limité-");
  1386. } else {
  1387. String regionName = event.getLine(1);
  1388. World world = event.getBlock().getWorld();
  1389. RegionManager rm = this.getWorldGuard().getRegionManager(world);
  1390. ProtectedRegion region = rm.getRegion(regionName);
  1391. if (region == null) {
  1392. event.getPlayer().sendMessage(this.Warning(this.getMessage("RegionNoExist")));
  1393. event.setLine(0, "-invalide-");
  1394. return;
  1395. }
  1396.  
  1397. try {
  1398. String dateString = event.getLine(3);
  1399.  
  1400. try {
  1401. double e1 = Double.parseDouble(event.getLine(2));
  1402. if (e1 <= 0.0D) {
  1403. throw new Exception();
  1404. }
  1405.  
  1406. if (event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
  1407. String[] expiration = dateString.split("\\s");
  1408. int e2 = Integer.parseInt(expiration[0]);
  1409. BuyRegion.DateResult dateResult = this.parseDateString(e2, expiration[1]);
  1410. if (dateResult.IsError) {
  1411. throw new Exception();
  1412. }
  1413. }
  1414. } catch (Exception var13) {
  1415. event.getPlayer().sendMessage(this.Notice(this.getMessage("InvalidPriceTime")));
  1416. event.setLine(0, "-invalide-");
  1417. return;
  1418. }
  1419. } catch (Exception var14) {
  1420. event.getPlayer().sendMessage(this.Notice("Invalid amount!"));
  1421. event.setLine(0, "-invalide-");
  1422. return;
  1423. }
  1424.  
  1425. if (event.getLine(0).equalsIgnoreCase("[RentRegion]")) {
  1426. event.setLine(0, "[RentRegion]");
  1427. } else {
  1428. event.setLine(0, "[BuyRegion]");
  1429. }
  1430.  
  1431. event.getPlayer().sendMessage(this.Notice("La pancarte HcRegion a été créé!"));
  1432. }
  1433. }
  1434. } catch (Exception var15) {
  1435. this.getLogger().info("An error occured in signChangeMonitor");
  1436. }
  1437.  
  1438. }
  1439.  
  1440. private void saveRentableRegion(BuyRegion.RentableRegion region) {
  1441. try {
  1442. saveRegion(region);
  1443. } catch (Exception var3) {
  1444. this.getLogger().info("An error has occured saving a RentableRegion.");
  1445. }
  1446.  
  1447. }
  1448.  
  1449. public class DateResult {
  1450. public long Time;
  1451. public String Text;
  1452. boolean IsError;
  1453.  
  1454. public DateResult(long time, String text, boolean isError) {
  1455. this.Time = time;
  1456. this.Text = text;
  1457. this.IsError = isError;
  1458. }
  1459. }
  1460.  
  1461. public class RentableRegion {
  1462. public String worldName;
  1463. public String regionName;
  1464. public String renter;
  1465. public String signLocationX;
  1466. public String signLocationY;
  1467. public String signLocationZ;
  1468. public String signLocationPitch;
  1469. public String signLocationYaw;
  1470. public String signDirection;
  1471. public String signLine1;
  1472. public String signLine2;
  1473. public String signLine3;
  1474. public String signLine4;
  1475. public String signType;
  1476.  
  1477. public RentableRegion() {
  1478. this.worldName = "";
  1479. this.regionName = "";
  1480. this.renter = "";
  1481. this.signLocationX = "";
  1482. this.signLocationY = "";
  1483. this.signLocationZ = "";
  1484. this.signLocationPitch = "";
  1485. this.signLocationYaw = "";
  1486. this.signDirection = "";
  1487. this.signLine1 = "";
  1488. this.signLine2 = "";
  1489. this.signLine3 = "";
  1490. this.signLine4 = "";
  1491. this.signType = "";
  1492. }
  1493.  
  1494. public RentableRegion(String input) {
  1495. try {
  1496. String[] e = input.split("%%%");
  1497. this.worldName = e[0];
  1498. this.regionName = e[1];
  1499. this.renter = e[2];
  1500. this.signLocationX = e[3];
  1501. this.signLocationY = e[4];
  1502. this.signLocationZ = e[5];
  1503. this.signLocationPitch = e[6];
  1504. this.signLocationYaw = e[7];
  1505. this.signDirection = e[8];
  1506. this.signLine1 = e[9];
  1507. this.signLine2 = e[10];
  1508. this.signLine3 = e[11];
  1509. this.signLine4 = e[12];
  1510. this.signType = e[13];
  1511. } catch (Exception var4) {
  1512. BuyRegion.this.getLogger().info("An error occured while instantiating a RentableRegion.");
  1513. }
  1514.  
  1515. }
  1516.  
  1517. public String toString() {
  1518. return this.worldName + "%%%" + this.regionName + "%%%" + this.renter + "%%%" + this.signLocationX + "%%%"
  1519. + this.signLocationY + "%%%" + this.signLocationZ + "%%%" + this.signLocationPitch + "%%%"
  1520. + this.signLocationYaw + "%%%" + this.signDirection + "%%%" + this.signLine1 + "%%%"
  1521. + this.signLine2 + "%%%" + this.signLine3 + "%%%" + this.signLine4 + "%%%" + this.signType;
  1522. }
  1523. }
  1524. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement