From ade5fcc4f1cbdbdbdc87a800e0413913c07c1e65 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 29 Sep 2020 12:24:53 +0300 Subject: [PATCH] JobsWorld by id more faster --- .../com/gamingmesh/jobs/PlayerManager.java | 20 +++++++++---------- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 16 ++++++++++----- .../java/com/gamingmesh/jobs/stuff/Util.java | 10 ++++------ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 8aaa770f..2a0aac5c 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -958,37 +958,37 @@ public class PlayerManager { if (HookManager.getMcMMOManager().mcMMOPresent || HookManager.getMcMMOManager().mcMMOOverHaul) boost.add(BoostOf.McMMO, new BoostMultiplier().add(HookManager.getMcMMOManager().getMultiplier(player.getPlayer()))); - double petPay = 0D; + Double petPay = null; if (ent instanceof Tameable) { Tameable t = (Tameable) ent; if (t.isTamed() && t.getOwner() instanceof Player) { petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); - if (petPay != 0D) + if (petPay != null) boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); } } if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent)) { - if (petPay == 0D) + if (petPay == null) petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); - if (petPay != 0D) + if (petPay != null) boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); } if (victim != null && victim.hasMetadata(getMobSpawnerMetadata())) { - double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner"); - if (amount != 0D) + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner"); + if (amount != null) boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount)); } if (getall) { - if (petPay == 0D) + if (petPay == null) petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay", force); - if (petPay != 0D) + if (petPay != null) boost.add(BoostOf.PetPay, new BoostMultiplier().add(petPay)); - double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); - if (amount != 0D) + Double amount = Jobs.getPermissionManager().getMaxPermission(player, "jobs.nearspawner", force); + if (amount != null) boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(amount)); } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 38aeb041..be1ccf92 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1754,7 +1754,7 @@ public abstract class JobsDAO { for (String u : uuids) { PreparedStatement ps = conn.prepareStatement("DELETE FROM `" + DBTables.UsersTable.getTableName() - + "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;"); + + "` WHERE `" + UserTableFields.player_uuid.getCollumn() + "` = ?;"); ps.setString(1, u); ps.execute(); close(ps); @@ -2416,10 +2416,16 @@ public abstract class JobsDAO { for (Integer one : missingWorlds) { PreparedStatement prest2 = null; - prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;"); - prest2.setInt(1, one); - prest2.execute(); - close(prest2); + try { + prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;"); + prest2.setInt(1, one); + prest2.execute(); + } catch (Throwable e) { + e.printStackTrace(); + } finally { + close(prest2); + } + } } catch (SQLException e) { diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 4578f9e2..e702334f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -34,6 +34,7 @@ public class Util { private static HashMap questsEditorMap = new HashMap<>(); private static HashMap jobsWorlds = new HashMap<>(); + private static HashMap jobsWorldsId = new HashMap<>(); public static final List LEAVECONFIRM = new ArrayList<>(); @@ -178,11 +179,7 @@ public class Util { } public static JobsWorld getJobsWorld(int id) { - for (JobsWorld one : jobsWorlds.values()) { - if (one.getId() == id) - return one; - } - return null; + return jobsWorldsId.get(id); } public static HashMap getJobsWorlds() { @@ -192,7 +189,8 @@ public class Util { public static void addJobsWorld(JobsWorld jobsWorld) { if (jobsWorld == null || jobsWorld.getId() == 0) return; - Util.jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld); + jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld); + jobsWorldsId.put(jobsWorld.getId(), jobsWorld); } public static List getFilesFromPackage(String pckgname) throws ClassNotFoundException {