From 8cd3f4fbbe3efe39cba8e1f3eb41bd178016df6f Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 26 Oct 2021 14:05:09 +0300 Subject: [PATCH] Optimizing block ownership removal --- src/main/java/com/gamingmesh/jobs/Jobs.java | 4 ++-- .../jobs/container/blockOwnerShip/BlockOwnerShip.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 46304bd0..802e80c6 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -234,9 +234,9 @@ public final class Jobs extends JavaPlugin { } public void removeBlockOwnerShip(org.bukkit.block.Block block) { - for (BlockOwnerShip ship : blockOwnerShipsMaterial.values()) { + BlockOwnerShip ship = blockOwnerShipsMaterial.get(CMIMaterial.get(block)); + if (ship != null) ship.remove(block); - } } /** diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 7e61adf2..07f80b06 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -170,24 +170,25 @@ public class BlockOwnerShip { } } } - if (uuid == null) { return false; } + return remove(uuid, block); + } + public boolean remove(UUID uuid, Block block) { + if (uuid == null) { + return false; + } HashMap ls = blockOwnerShips.getOrDefault(uuid, new HashMap()); String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true); - com.gamingmesh.jobs.stuff.blockLoc removed = ls.remove(blockLoc); if (removed != null) { block.removeMetadata(metadataName, plugin); - Map oldRecord = ownerMapByLocation.get(block.getLocation().getWorld().getName()); if (oldRecord != null) oldRecord.remove(block.getLocation().getBlockX() + ":" + block.getLocation().getBlockY() + ":" + block.getLocation().getBlockZ()); - } - return removed != null; }