mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2025-02-02 11:31:20 +01:00
Add support for all shulker colors, not just default
This commit is contained in:
parent
c0a0aa885e
commit
a550b9ea38
@ -2,6 +2,7 @@ package de.epiceric.shopchest.listeners;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.utils.ShopUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -22,7 +23,7 @@ public class BlockExplodeListener implements Listener {
|
|||||||
public void onBlockExplode(BlockExplodeEvent e) {
|
public void onBlockExplode(BlockExplodeEvent e) {
|
||||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||||
for (Block b : bl) {
|
for (Block b : bl) {
|
||||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST) || b.getType().equals(Material.SHULKER_BOX) || b.getType().equals(Material.BARREL)) {
|
if (ShopUtils.isShopMaterial(b.getType())) {
|
||||||
if (plugin.getShopUtils().isShop(b.getLocation())) e.blockList().remove(b);
|
if (plugin.getShopUtils().isShop(b.getLocation())) e.blockList().remove(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class ChestProtectListener implements Listener {
|
|||||||
public void onEntityExplode(EntityExplodeEvent e) {
|
public void onEntityExplode(EntityExplodeEvent e) {
|
||||||
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
ArrayList<Block> bl = new ArrayList<>(e.blockList());
|
||||||
for (Block b : bl) {
|
for (Block b : bl) {
|
||||||
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.SHULKER_BOX) || b.getType().equals(Material.BARREL) || b.getType().equals(Material.TRAPPED_CHEST)) {
|
if (ShopUtils.isShopMaterial(b.getType())) {
|
||||||
if (shopUtils.isShop(b.getLocation())) e.blockList().remove(b);
|
if (shopUtils.isShop(b.getLocation())) e.blockList().remove(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ public class ChestProtectListener implements Listener {
|
|||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final Block b = e.getBlockPlaced();
|
final Block b = e.getBlockPlaced();
|
||||||
|
|
||||||
if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.SHULKER_BOX) && !b.getType().equals(Material.BARREL) && !b.getType().equals(Material.TRAPPED_CHEST)) {
|
if (!ShopUtils.isShopMaterial(b.getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -117,7 +119,7 @@ public class ShopInteractListener implements Listener {
|
|||||||
if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType))
|
if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (b.getType() != Material.CHEST && b.getType() != Material.SHULKER_BOX && b.getType() != Material.BARREL && b.getType() != Material.TRAPPED_CHEST)
|
if (!ShopUtils.isShopMaterial(b.getType()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE)
|
if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE)
|
||||||
@ -162,7 +164,7 @@ public class ShopInteractListener implements Listener {
|
|||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_BLOCK)
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (b.getType() != Material.CHEST && b.getType() != Material.SHULKER_BOX && b.getType() != Material.BARREL && b.getType() != Material.TRAPPED_CHEST)
|
if (!ShopUtils.isShopMaterial(b.getType()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ClickType clickType = ClickType.getPlayerClickType(p);
|
ClickType clickType = ClickType.getPlayerClickType(p);
|
||||||
|
@ -2,6 +2,7 @@ package de.epiceric.shopchest.listeners;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.utils.ShopUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.*;
|
import org.bukkit.block.*;
|
||||||
@ -69,7 +70,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
Block block = event.getBlocks().get(0);
|
Block block = event.getBlocks().get(0);
|
||||||
Material type = block.getType();
|
Material type = block.getType();
|
||||||
|
|
||||||
if (type == Material.CHEST || type == Material.TRAPPED_CHEST || type == Material.SHULKER_BOX || type == Material.BARREL) {
|
if (ShopUtils.isShopMaterial(type)) {
|
||||||
if (isAllowed(player, block.getLocation())) {
|
if (isAllowed(player, block.getLocation())) {
|
||||||
event.setResult(Result.ALLOW);
|
event.setResult(Result.ALLOW);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.EnumMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.utils.ShopUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -111,7 +112,7 @@ public class Shop {
|
|||||||
plugin.debug("Creating shop (#" + id + ")");
|
plugin.debug("Creating shop (#" + id + ")");
|
||||||
|
|
||||||
Block b = location.getBlock();
|
Block b = location.getBlock();
|
||||||
if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST && b.getType() != Material.BARREL && b.getType() != Material.SHULKER_BOX) {
|
if (!ShopUtils.isShopMaterial(b.getType())) {
|
||||||
ChestNotFoundException ex = new ChestNotFoundException(String.format("No Chest found in world '%s' at location: %d; %d; %d",
|
ChestNotFoundException ex = new ChestNotFoundException(String.format("No Chest found in world '%s' at location: %d; %d; %d",
|
||||||
b.getWorld().getName(), b.getX(), b.getY(), b.getZ()));
|
b.getWorld().getName(), b.getX(), b.getY(), b.getZ()));
|
||||||
plugin.getShopUtils().removeShop(this, Config.removeShopOnError);
|
plugin.getShopUtils().removeShop(this, Config.removeShopOnError);
|
||||||
@ -477,19 +478,9 @@ public class Shop {
|
|||||||
public InventoryHolder getInventoryHolder() {
|
public InventoryHolder getInventoryHolder() {
|
||||||
Block b = getLocation().getBlock();
|
Block b = getLocation().getBlock();
|
||||||
|
|
||||||
if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
if (ShopUtils.isShopMaterial(b.getType())) {
|
||||||
Chest chest = (Chest) b.getState();
|
Container container = (Container) b.getState();
|
||||||
return chest.getInventory().getHolder();
|
return container.getInventory().getHolder();
|
||||||
}
|
|
||||||
|
|
||||||
if (b.getType() == Material.BARREL) {
|
|
||||||
Barrel barrel = (Barrel) b.getState();
|
|
||||||
return barrel.getInventory().getHolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b.getType() == Material.SHULKER_BOX) {
|
|
||||||
ShulkerBox shulkerBox = (ShulkerBox) b.getState();
|
|
||||||
return shulkerBox.getInventory().getHolder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -11,10 +11,7 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.DoubleChest;
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -320,6 +317,33 @@ public class ShopUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tells if the material given is a shop material
|
||||||
|
* @param material The material to test
|
||||||
|
*/
|
||||||
|
public static boolean isShopMaterial(Material material) {
|
||||||
|
return material.equals(Material.CHEST) ||
|
||||||
|
material.equals(Material.TRAPPED_CHEST) ||
|
||||||
|
material.equals(Material.BARREL) ||
|
||||||
|
material.equals(Material.SHULKER_BOX) ||
|
||||||
|
material.equals(Material.BLACK_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.BLUE_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.BROWN_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.CYAN_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.GRAY_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.GREEN_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.LIGHT_BLUE_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.LIGHT_GRAY_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.LIME_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.MAGENTA_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.ORANGE_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.PINK_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.PURPLE_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.RED_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.WHITE_SHULKER_BOX) ||
|
||||||
|
material.equals(Material.YELLOW_SHULKER_BOX);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the amount of shops for each player
|
* Loads the amount of shops for each player
|
||||||
* @param callback Callback that returns the amount of shops for each player
|
* @param callback Callback that returns the amount of shops for each player
|
||||||
@ -352,9 +376,9 @@ public class ShopUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all shops in the given chunks from the database and adds them to the server
|
* Gets all shops in the given chunks from the database and adds them to the server
|
||||||
* @param chunk The chunks to load shops from
|
* @param chunks The chunks to load shops from
|
||||||
* @param callback Callback that returns the amount of shops added if succeeded
|
* @param callback Callback that returns the amount of shops added if succeeded
|
||||||
* @see ShopUtils#loadShops(Chunk Callback)
|
* @see ShopUtils#loadShops(Chunk, Callback)
|
||||||
*/
|
*/
|
||||||
public void loadShops(final Chunk[] chunks, final Callback<Integer> callback) {
|
public void loadShops(final Chunk[] chunks, final Callback<Integer> callback) {
|
||||||
plugin.getShopDatabase().getShopsInChunks(chunks, new Callback<Collection<Shop>>(plugin) {
|
plugin.getShopDatabase().getShopsInChunks(chunks, new Callback<Collection<Shop>>(plugin) {
|
||||||
|
Loading…
Reference in New Issue
Block a user