Split project
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
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;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ShopHandlerImpl implements ShopHandler {
|
||||
|
||||
private final PlayerShops plugin;
|
||||
@Getter
|
||||
private final Object2IntMap<UUID> shopBuildLimits;
|
||||
@Getter
|
||||
private final Map<Location, Shop> shopLocation;
|
||||
@Getter
|
||||
private final ArrayList<Material> shopMaterials;
|
||||
|
||||
public ShopHandlerImpl(PlayerShops instance) {
|
||||
plugin = instance;
|
||||
shopLocation = new ConcurrentHashMap<>();
|
||||
shopBuildLimits = new Object2IntOpenHashMap<>();
|
||||
shopBuildLimits.defaultReturnValue(Config.shopLimit);
|
||||
shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in.
|
||||
}
|
||||
|
||||
public Shop getShop(Location location) {
|
||||
Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
return shopLocation.get(newLocation);
|
||||
}
|
||||
|
||||
public boolean isShop(Location location) {
|
||||
return getShop(location) != null;
|
||||
}
|
||||
|
||||
public Collection<Shop> getShops() {
|
||||
return Collections.unmodifiableCollection(shopLocation.values());
|
||||
}
|
||||
|
||||
public void addPlayerLimit(UUID uuid, int limit) {
|
||||
shopBuildLimits.put(uuid, limit);
|
||||
}
|
||||
|
||||
public int getShopLimit(UUID uuid) {
|
||||
return shopBuildLimits.getInt(uuid);
|
||||
}
|
||||
|
||||
public void removeShops() {
|
||||
shopLocation.clear();
|
||||
}
|
||||
|
||||
public boolean isShopMaterial(Block block) {
|
||||
if (Tag.SHULKER_BOXES.isTagged(block.getType())) {
|
||||
return true;
|
||||
}
|
||||
return shopMaterials.contains(block.getType());
|
||||
}
|
||||
|
||||
public List<Shop> getShops(UUID uuid) {
|
||||
List<Shop> shops = new ArrayList<>();
|
||||
for (Shop shop : shopLocation.values()) {
|
||||
if (shop.getOwnerUUID().equals(uuid))
|
||||
shops.add(shop);
|
||||
}
|
||||
return shops;
|
||||
}
|
||||
|
||||
public Shop getShopBySignLocation(Location signLocation) {
|
||||
for (Shop shop : shopLocation.values()) {
|
||||
if (shop.getSignLocation().equals(signLocation))
|
||||
return shop;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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))) {
|
||||
Block blockRelative = block.getRelative(face);
|
||||
if (isShop(blockRelative.getLocation()))
|
||||
return getShop(blockRelative.getLocation());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user