rework some stuff

This commit is contained in:
Len
2022-08-13 15:22:00 +02:00
parent d33a0db545
commit cf4431326e
36 changed files with 1080 additions and 597 deletions
@@ -2,9 +2,7 @@ package com.alttd.playershops.handler;
import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.config.Config;
import com.alttd.playershops.events.PlayerCreateShopEvent;
import com.alttd.playershops.shop.AbstractShop;
import com.alttd.playershops.shop.ShopType;
import com.alttd.playershops.shop.PlayerShop;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.Getter;
@@ -12,7 +10,6 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.*;
@@ -24,7 +21,7 @@ public class ShopHandler {
@Getter
private final Object2IntMap<UUID> shopBuildLimits;
@Getter
private final Map<Location, AbstractShop> shopLocation;
private final Map<Location, PlayerShop> shopLocation;
@Getter
private final ArrayList<Material> shopMaterials;
@@ -34,9 +31,10 @@ public class ShopHandler {
shopBuildLimits = new Object2IntOpenHashMap<>();
shopBuildLimits.defaultReturnValue(Config.shopLimit);
shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in.
shopMaterials.add(Material.BARREL);
}
public AbstractShop getShop(Location location) {
public PlayerShop getShop(Location location) {
Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
return shopLocation.get(newLocation);
@@ -46,7 +44,7 @@ public class ShopHandler {
return getShop(location) != null;
}
public Collection<AbstractShop> getShops() {
public Collection<PlayerShop> getShops() {
return Collections.unmodifiableCollection(shopLocation.values());
}
@@ -69,44 +67,34 @@ public class ShopHandler {
return shopMaterials.contains(block.getType());
}
public List<AbstractShop> getShops(UUID uuid) {
List<AbstractShop> shops = new ArrayList<>();
for (AbstractShop shop : shopLocation.values()) {
public List<PlayerShop> getShops(UUID uuid) {
List<PlayerShop> shops = new ArrayList<>();
for (PlayerShop shop : shopLocation.values()) {
if (shop.getOwnerUUID().equals(uuid))
shops.add(shop);
}
return shops;
}
public AbstractShop getShopBySignLocation(Location signLocation) {
for (AbstractShop shop : shopLocation.values()) {
public PlayerShop getShopBySignLocation(Location signLocation) {
for (PlayerShop shop : shopLocation.values()) {
if (shop.getSignLocation().equals(signLocation))
return shop;
}
return null;
}
public AbstractShop getShopNearBlock(Block block) {
BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
for (BlockFace face : faces) {
if (this.isShopMaterial(block.getRelative(face))) {
Block blockRelative = block.getRelative(face);
if (isShop(blockRelative.getLocation()))
return getShop(blockRelative.getLocation());
}
}
return null;
public void addShop(PlayerShop shop) {
shopLocation.put(shop.getShopLocation(), shop);
}
public AbstractShop createShop(Location signLocation, Player player, double price, int amount, ShopType shopType) {
AbstractShop shop = AbstractShop.create(signLocation, player.getUniqueId(), price, amount, shopType);
public boolean canPlayerBreakShop(Player player, PlayerShop shop) {
if (player.getUniqueId().equals(shop.getOwnerUUID()) && player.hasPermission("playershops.shop.break"))
return true;
PlayerCreateShopEvent playerCreateShopEvent = new PlayerCreateShopEvent(player, shop);
plugin.getServer().getPluginManager().callEvent(playerCreateShopEvent);
if (player.hasPermission("playershops.shop.break.other"))
return true;
if(playerCreateShopEvent.isCancelled())
return null;
return shop;
return false;
}
}