From 259e806d59f64ff96db27dacfa1b5082cef8e806 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Sat, 9 Jul 2022 12:44:20 +0200 Subject: [PATCH] Use API references --- .../alttd/playershops/api/ShopHandler.java | 7 +++---- .../playershops/handler/ShopHandlerImpl.java | 19 ++++++++++--------- .../playershops/listener/PlayerListener.java | 3 ++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/alttd/playershops/api/ShopHandler.java b/src/main/java/com/alttd/playershops/api/ShopHandler.java index e0d8685..92d1fcf 100644 --- a/src/main/java/com/alttd/playershops/api/ShopHandler.java +++ b/src/main/java/com/alttd/playershops/api/ShopHandler.java @@ -1,6 +1,5 @@ package com.alttd.playershops.api; -import com.alttd.playershops.shop.AbstractShop; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -18,7 +17,7 @@ public interface ShopHandler { // TODO finish docs * @param location Location of the shop * @return Shop at the given location or null if no shop is found there */ - AbstractShop getShop(Location location); + Shop getShop(Location location); /** * Checks whether there is a shop at a given location @@ -34,7 +33,7 @@ public interface ShopHandler { // TODO finish docs * * @return Read-only collection of all shops */ - Collection getShops(); + Collection getShops(); /** * Add a player's custom shop limit @@ -66,7 +65,7 @@ public interface ShopHandler { // TODO finish docs * @param uuid The uuid linked to this player * @return List of shops this player owns */ - List getShops(UUID uuid); + List getShops(UUID uuid); ArrayList getShopMaterials(); } diff --git a/src/main/java/com/alttd/playershops/handler/ShopHandlerImpl.java b/src/main/java/com/alttd/playershops/handler/ShopHandlerImpl.java index 56d93f3..0af76a7 100644 --- a/src/main/java/com/alttd/playershops/handler/ShopHandlerImpl.java +++ b/src/main/java/com/alttd/playershops/handler/ShopHandlerImpl.java @@ -1,6 +1,7 @@ package com.alttd.playershops.handler; import com.alttd.playershops.PlayerShops; +import com.alttd.playershops.api.Shop; import com.alttd.playershops.api.ShopHandler; import com.alttd.playershops.config.Config; import com.alttd.playershops.shop.AbstractShop; @@ -22,7 +23,7 @@ public class ShopHandlerImpl implements ShopHandler { @Getter private final Object2IntMap shopBuildLimits; @Getter - private final Map shopLocation; + private final Map shopLocation; @Getter private final ArrayList shopMaterials; @@ -34,7 +35,7 @@ public class ShopHandlerImpl implements ShopHandler { shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in. } - public AbstractShop getShop(Location location) { + public Shop getShop(Location location) { Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); return shopLocation.get(newLocation); @@ -44,7 +45,7 @@ public class ShopHandlerImpl implements ShopHandler { return getShop(location) != null; } - public Collection getShops() { + public Collection getShops() { return Collections.unmodifiableCollection(shopLocation.values()); } @@ -67,24 +68,24 @@ public class ShopHandlerImpl implements ShopHandler { return shopMaterials.contains(block.getType()); } - public List getShops(UUID uuid) { - List shops = new ArrayList<>(); - for (AbstractShop shop : shopLocation.values()) { + public List getShops(UUID uuid) { + List shops = new ArrayList<>(); + for (Shop shop : shopLocation.values()) { if (shop.getOwnerUUID().equals(uuid)) shops.add(shop); } return shops; } - public AbstractShop getShopBySignLocation(Location signLocation) { - for (AbstractShop shop : shopLocation.values()) { + public Shop getShopBySignLocation(Location signLocation) { + for (Shop shop : shopLocation.values()) { if (shop.getSignLocation().equals(signLocation)) return shop; } return null; } - public AbstractShop getShopNearBlock(Block block) { + public Shop getShopNearBlock(Block block) { BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}; for (BlockFace face : faces) { if (this.isShopMaterial(block.getRelative(face))) { diff --git a/src/main/java/com/alttd/playershops/listener/PlayerListener.java b/src/main/java/com/alttd/playershops/listener/PlayerListener.java index 6dea4c3..d123db3 100644 --- a/src/main/java/com/alttd/playershops/listener/PlayerListener.java +++ b/src/main/java/com/alttd/playershops/listener/PlayerListener.java @@ -1,6 +1,7 @@ package com.alttd.playershops.listener; import com.alttd.playershops.PlayerShops; +import com.alttd.playershops.api.Shop; import com.alttd.playershops.api.ShopHandler; import com.alttd.playershops.config.Config; import com.alttd.playershops.shop.AbstractShop; @@ -59,7 +60,7 @@ public class PlayerListener extends EventListener { if (!(block.getState() instanceof Sign)) return; - AbstractShop shop = plugin.getShopHandler().getShop(block.getLocation()); + Shop shop = plugin.getShopHandler().getShop(block.getLocation()); if(shop == null) return; if(shop.isInitialized()) event.setCancelled(true);