From 14423470ac11a06e152225bfdc05ec48f2e4a7a9 Mon Sep 17 00:00:00 2001 From: Zrips Date: Sun, 15 Jan 2017 20:43:56 +0200 Subject: [PATCH] Fix for boonus issue when bonus is null --- .classpath | 1 + .externalToolBuilders/Create jar file.launch | 38 +++---- com/gamingmesh/jobs/Jobs.java | 9 +- com/gamingmesh/jobs/PlayerManager.java | 23 ++-- com/gamingmesh/jobs/api/.gitignore | 1 + com/gamingmesh/jobs/commands/list/.gitignore | 1 + com/gamingmesh/jobs/commands/list/bonus.java | 2 - .../jobs/config/GeneralConfigManager.java | 7 ++ .../jobs/config/RestrictedAreaManager.java | 104 ++++++++++++++---- com/gamingmesh/jobs/container/.gitignore | 1 + com/gamingmesh/jobs/container/JobsPlayer.java | 1 + .../jobs/container/RestrictedArea.java | 68 +++++------- com/gamingmesh/jobs/dao/JobsDAO.java | 3 +- .../jobs/listeners/JobsListener.java | 47 ++++++++ plugin.yml | 2 +- 15 files changed, 213 insertions(+), 95 deletions(-) diff --git a/.classpath b/.classpath index 93f4b84c..a41020a9 100644 --- a/.classpath +++ b/.classpath @@ -8,5 +8,6 @@ + diff --git a/.externalToolBuilders/Create jar file.launch b/.externalToolBuilders/Create jar file.launch index e88582ef..ac0a196d 100644 --- a/.externalToolBuilders/Create jar file.launch +++ b/.externalToolBuilders/Create jar file.launch @@ -1,19 +1,19 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index d6a26112..6a54e3bb 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -79,6 +79,7 @@ import com.gamingmesh.jobs.listeners.JobsPaymentListener; import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.MythicMobsListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; +import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.Loging; @@ -139,6 +140,8 @@ public class Jobs extends JavaPlugin { private static ActionBar actionbar; private boolean running = false; + protected static SelectionManager smanager; + public void setMcMMOlistener() { McMMOlistener = new McMMOlistener(this); } @@ -514,7 +517,7 @@ public class Jobs extends JavaPlugin { paymentThread.shutdown(); paymentThread = null; } - + smanager = new SelectionManager(); if (dao != null) { dao.closeConnections(); } @@ -1148,4 +1151,8 @@ public class Jobs extends JavaPlugin { public static void consoleMsg(String msg) { Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); } + + public static SelectionManager getSelectionManager() { + return smanager; + } } diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index a1394e10..b4463d6b 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -53,9 +53,7 @@ import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.economy.PointsData; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.PerformCommands; -import com.gamingmesh.jobs.stuff.Perm; public class PlayerManager { // private Map players = Collections.synchronizedMap(new HashMap()); @@ -188,7 +186,6 @@ public class PlayerManager { } else { jPlayer.onDisconnect(); } - Jobs.getJobsDAO().updateSeen(jPlayer); } /** @@ -762,21 +759,25 @@ public class PlayerManager { if (ent != null && ent instanceof Tameable) { Tameable t = (Tameable) ent; if (t.isTamed() && t.getOwner() instanceof Player) { - boost.add(BoostOf.PetPay, new BoostMultiplier().add(Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"))); + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); + if (amount != null) + boost.add(BoostOf.PetPay, new BoostMultiplier().add(amount)); } } if (victim != null && victim.hasMetadata(this.getMobSpawnerMetadata())) { - boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner"))); + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner"); + if (amount != null) + boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount)); } if (getall) { - Double mount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force); - if (mount != null) - boost.add(BoostOf.PetPay, new BoostMultiplier().add(mount)); - mount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); - if (mount != null) - boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(mount)); + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force); + if (amount != null) + boost.add(BoostOf.PetPay, new BoostMultiplier().add(amount)); + amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); + if (amount != null) + boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount)); } boost.add(BoostOf.Permission, Jobs.getPlayerManager().getBoost(player, prog, force)); diff --git a/com/gamingmesh/jobs/api/.gitignore b/com/gamingmesh/jobs/api/.gitignore index de95662a..0d76e126 100644 --- a/com/gamingmesh/jobs/api/.gitignore +++ b/com/gamingmesh/jobs/api/.gitignore @@ -8,3 +8,4 @@ /JobsPaymentEvent.class /JobsChunkChangeEvent.class /JobsExpGainEvent.class +/JobsAreaSelectionEvent.class diff --git a/com/gamingmesh/jobs/commands/list/.gitignore b/com/gamingmesh/jobs/commands/list/.gitignore index 59626c70..3c2b66a3 100644 --- a/com/gamingmesh/jobs/commands/list/.gitignore +++ b/com/gamingmesh/jobs/commands/list/.gitignore @@ -54,3 +54,4 @@ /bp.class /entitylist.class /iteminfo.class +/area.class diff --git a/com/gamingmesh/jobs/commands/list/bonus.java b/com/gamingmesh/jobs/commands/list/bonus.java index 73ff9699..03f08a41 100644 --- a/com/gamingmesh/jobs/commands/list/bonus.java +++ b/com/gamingmesh/jobs/commands/list/bonus.java @@ -6,13 +6,11 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.PlayerManager.BoostOf; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; -import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.Boost; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; public class bonus implements Cmd { diff --git a/com/gamingmesh/jobs/config/GeneralConfigManager.java b/com/gamingmesh/jobs/config/GeneralConfigManager.java index 683291cb..e9f5865e 100644 --- a/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -69,6 +69,7 @@ public class GeneralConfigManager { public boolean PaymentMethodsMoney; public boolean PaymentMethodsPoints; public boolean PaymentMethodsExp; + public int getSelectionTooldID; // Limits public HashMap currencyLimitUse = new HashMap(); @@ -413,6 +414,8 @@ public class GeneralConfigManager { "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); saveOnDisconnect = c.get("save-on-disconnect", false); + getSelectionTooldID = c.get("selectionTool", 294); + c.getW().addComment("MultiServerCompatability", "Enable if you are using one data base for multiple servers across bungee network", "This will force to load players data every time he is logging in to have most up to date data instead of having preloaded data", "This will enable automaticaly save-on-disconnect feature"); @@ -859,4 +862,8 @@ public class GeneralConfigManager { public synchronized void startSqlite() { Jobs.setDAO(JobsDAOSQLite.initialize(plugin)); } + + public int getSelectionTooldID() { + return getSelectionTooldID; + } } diff --git a/com/gamingmesh/jobs/config/RestrictedAreaManager.java b/com/gamingmesh/jobs/config/RestrictedAreaManager.java index a0b7a26e..664bf963 100644 --- a/com/gamingmesh/jobs/config/RestrictedAreaManager.java +++ b/com/gamingmesh/jobs/config/RestrictedAreaManager.java @@ -3,6 +3,9 @@ package com.gamingmesh.jobs.config; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -12,12 +15,13 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.CuboidArea; import com.gamingmesh.jobs.container.RestrictedArea; import com.gamingmesh.jobs.stuff.ChatColor; public class RestrictedAreaManager { - protected ArrayList restrictedAreas = new ArrayList(); + protected HashMap restrictedAreas = new HashMap(); private Jobs plugin; @@ -25,32 +29,75 @@ public class RestrictedAreaManager { this.plugin = plugin; } + public boolean isExist(String name) { + for (Entry area : restrictedAreas.entrySet()) { + if (area.getKey().equalsIgnoreCase(name)) + return true; + } + return false; + } + + public void addNew(RestrictedArea ra) { + addNew(ra, false); + } + + public void addNew(RestrictedArea ra, boolean save) { + restrictedAreas.put(ra.getName(), ra); + if (save) + save(); + } + + private void save() { + File f = new File(plugin.getDataFolder(), "restrictedAreas.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + conf.options().indent(2); + conf.options().copyDefaults(true); + StringBuilder header = new StringBuilder(); + header = addHeader(header); + for (Entry area : restrictedAreas.entrySet()) { + String areaKey = area.getKey(); + CuboidArea cuboid = area.getValue().getCuboidArea(); + conf.set("restrictedareas." + areaKey + ".world", cuboid.getWorld().getName()); + conf.set("restrictedareas." + areaKey + ".multiplier", area.getValue().getMultiplier()); + conf.set("restrictedareas." + areaKey + ".point1.x", cuboid.getLowLoc().getBlockX()); + conf.set("restrictedareas." + areaKey + ".point1.y", cuboid.getLowLoc().getBlockY()); + conf.set("restrictedareas." + areaKey + ".point1.z", cuboid.getLowLoc().getBlockZ()); + conf.set("restrictedareas." + areaKey + ".point2.x", cuboid.getHighLoc().getBlockX()); + conf.set("restrictedareas." + areaKey + ".point2.y", cuboid.getHighLoc().getBlockY()); + conf.set("restrictedareas." + areaKey + ".point2.z", cuboid.getHighLoc().getBlockZ()); + } + try { + conf.save(f); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Gets the area multiplier for the player * @param player * @return - the multiplier */ public synchronized double getRestrictedMultiplier(Player player) { - for (RestrictedArea area : restrictedAreas) { - if (area.inRestrictedArea(player)) - return area.getMultiplier(); + if (player == null) + return 0D; + for (Entry area : restrictedAreas.entrySet()) { + if (area.getValue().inRestrictedArea(player.getLocation())) + return area.getValue().getMultiplier(); } return 0D; } - - /** - * Method to load the restricted areas configuration - * - * loads from Jobs/restrictedAreas.yml - */ - public synchronized void load() { - this.restrictedAreas.clear(); - File f = new File(plugin.getDataFolder(), "restrictedAreas.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - conf.options().indent(2); - conf.options().copyDefaults(true); - StringBuilder header = new StringBuilder(); + public synchronized List getRestrictedAreasByLoc(Location loc) { + List areas = new ArrayList(); + for (Entry area : restrictedAreas.entrySet()) { + if (area.getValue().inRestrictedArea(loc)) + areas.add(area.getValue()); + } + return areas; + } + + private StringBuilder addHeader(StringBuilder header) { header.append("Restricted area configuration"); header.append(System.getProperty("line.separator")) .append(System.getProperty("line.separator")) @@ -82,6 +129,24 @@ public class RestrictedAreaManager { .append(" x: -150").append(System.getProperty("line.separator")) .append(" y: 100").append(System.getProperty("line.separator")) .append(" z: -150"); + return header; + } + + /** + * Method to load the restricted areas configuration + * + * loads from Jobs/restrictedAreas.yml + */ + public synchronized void load() { + this.restrictedAreas.clear(); + File f = new File(plugin.getDataFolder(), "restrictedAreas.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + conf.options().indent(2); + conf.options().copyDefaults(true); + StringBuilder header = new StringBuilder(); + + header = addHeader(header); + conf.options().header(header.toString()); ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas"); if (areaSection != null) { @@ -96,13 +161,12 @@ public class RestrictedAreaManager { Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0)); - this.restrictedAreas.add(new RestrictedArea(point1, point2, multiplier)); + addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier)); } } - Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded " + restrictedAreas.size() + " restricted areas!"); - + try { conf.save(f); } catch (IOException e) { diff --git a/com/gamingmesh/jobs/container/.gitignore b/com/gamingmesh/jobs/container/.gitignore index 05455b4e..2e7a2f2f 100644 --- a/com/gamingmesh/jobs/container/.gitignore +++ b/com/gamingmesh/jobs/container/.gitignore @@ -44,3 +44,4 @@ /Boost.class /CurrencyType.class /CurrencyLimit.class +/CuboidArea.class diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java index bd3bd19c..c5faef04 100644 --- a/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/com/gamingmesh/jobs/container/JobsPlayer.java @@ -612,6 +612,7 @@ public class JobsPlayer { dao.saveLog(this); dao.savePoints(this); dao.recordPlayersLimits(this); + dao.updateSeen(this); setSaved(true); } // } diff --git a/com/gamingmesh/jobs/container/RestrictedArea.java b/com/gamingmesh/jobs/container/RestrictedArea.java index 0009da9f..3ce53b09 100644 --- a/com/gamingmesh/jobs/container/RestrictedArea.java +++ b/com/gamingmesh/jobs/container/RestrictedArea.java @@ -19,34 +19,30 @@ package com.gamingmesh.jobs.container; import org.bukkit.Location; -import org.bukkit.entity.Player; -/** - * Restricted Area Class - * - * Holds data pertaining to restricted areas on the server - * @author Zak Ford - * - */ public class RestrictedArea { - private Location location1; - private Location location2; + private CuboidArea area; private double multiplier; + private String name; - public RestrictedArea(Location location1, Location location2, double multiplier) { - this.location1 = location1; - this.location2 = location2; + public RestrictedArea(String name, CuboidArea area, double multiplier) { + this.name = name; + this.area = area; this.multiplier = multiplier; } + public CuboidArea getCuboidArea() { + return this.area; + } + /** * The multipler for the restricted area * @return - the multipler for this restricted area */ public double getMultiplier() { - return this.multiplier - 1; + return this.multiplier; } /** @@ -55,33 +51,27 @@ public class RestrictedArea { * @return true - the location is inside the restricted area * @return false - the location is outside the restricted area */ - public boolean inRestrictedArea(Player player) { - if (player == null) + public boolean inRestrictedArea(Location loc) { + if (loc == null) return false; - if (isBetween(player.getLocation().getX(), this.location1.getX(), this.location2.getX()) && - isBetween(player.getLocation().getY(), this.location1.getY(), this.location2.getY()) && - isBetween(player.getLocation().getZ(), this.location1.getZ(), this.location2.getZ()) && - this.location1.getWorld().equals(player.getLocation().getWorld()) && - this.location2.getWorld().equals(player.getLocation().getWorld())) { - return true; - } - return false; + if (!loc.getWorld().getName().equals(area.getWorld().getName())) + return false; + if (area.getLowLoc().getBlockX() > loc.getBlockX()) + return false; + if (area.getHighLoc().getBlockX() < loc.getBlockX()) + return false; + if (area.getLowLoc().getBlockZ() > loc.getBlockZ()) + return false; + if (area.getHighLoc().getBlockZ() < loc.getBlockZ()) + return false; + if (area.getLowLoc().getBlockY() > loc.getBlockY()) + return false; + if (area.getHighLoc().getBlockY() < loc.getBlockY()) + return false; + return true; } - /** - * Function check if number is between bounds - * @param number - the number to be checked - * @param bound1 - the first bound - * @param bound2 - the second bound - * @return true - number is between bounds - * @return false - number is out of bounds - */ - private static boolean isBetween(double number, double bound1, double bound2) { - if (bound1 < bound2 && number > bound1 && number < bound2) { - return true; - } else if (bound1 > bound2 && number < bound1 && number > bound2) { - return true; - } - return false; + public String getName() { + return name; } } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 7a60c14a..6625f8eb 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -928,8 +928,7 @@ public abstract class JobsDAO { return; PreparedStatement prest = null; try { - prest = conn.prepareStatement("UPDATE `" + prefix - + "jobs` SET `level` = ?, `experience` = ? WHERE `userid` = ? AND `job` = ?;"); + prest = conn.prepareStatement("UPDATE `" + prefix + "jobs` SET `level` = ?, `experience` = ? WHERE `userid` = ? AND `job` = ?;"); for (JobProgression progression : player.getJobProgression()) { prest.setInt(1, progression.getLevel()); prest.setInt(2, (int) progression.getExperience()); diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 8226a11b..9124d9b0 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -28,7 +28,9 @@ import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; +import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -60,6 +62,7 @@ import org.bukkit.plugin.PluginManager; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Gui.GuiInfoList; +import com.gamingmesh.jobs.api.JobsAreaSelectionEvent; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobLimitedItems; @@ -74,6 +77,50 @@ public class JobsListener implements Listener { this.plugin = plugin; } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onSelection(PlayerInteractEvent event) { + if (event.getPlayer() == null) + return; + //disabling plugin in world + if (event.getPlayer() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld())) + return; + if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + Player player = event.getPlayer(); + ItemStack iih = Jobs.getNms().getItemInMainHand(player); + if (iih == null || iih.getType() == Material.AIR) + return; + int heldItemId = iih.getTypeId(); + if (heldItemId != Jobs.getGCManager().getSelectionTooldID()) + return; + + if (!player.hasPermission("jobs.selectarea")) + return; + + if (player.getGameMode() == GameMode.CREATIVE) + event.setCancelled(true); + + Block block = event.getClickedBlock(); + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + Location loc = block.getLocation(); + Jobs.getSelectionManager().placeLoc1(player, loc); + player.sendMessage("Selected: " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ()); + event.setCancelled(true); + } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Location loc = block.getLocation(); + Jobs.getSelectionManager().placeLoc2(player, loc); + player.sendMessage("Selected: " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ()); + event.setCancelled(true); + } + + if (Jobs.getSelectionManager().hasPlacedBoth(player)) { + JobsAreaSelectionEvent jobsAreaSelectionEvent = new JobsAreaSelectionEvent(event.getPlayer(), Jobs.getSelectionManager().getSelectionCuboid(player)); + Bukkit.getServer().getPluginManager().callEvent(jobsAreaSelectionEvent); + } + + return; + } + @EventHandler(priority = EventPriority.LOWEST) public void onShopClick(InventoryClickEvent event) { if (Jobs.getShopManager().GuiList.isEmpty()) diff --git a/plugin.yml b/plugin.yml index 01ee6c06..fbded014 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.Jobs version: 3.7.7 author: phrstbrn -softdepend: [Vault, iConomy, MythicMobs, McMMO] +softdepend: [Vault, iConomy, MythicMobs, McMMO, WorldEdit] commands: jobs: description: Jobs