diff --git a/pom.xml b/pom.xml
index 8e441d4..38fac82 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,10 +24,6 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
- shopchest-repo
- https://epicericee.github.io/ShopChest/maven/
-
vault-repo
http://nexus.hc.to/content/repositories/pub_releases/
@@ -41,25 +37,12 @@
1.10.2-R0.1-SNAPSHOT
provided
-
net.milkbowl.vault
VaultAPI
1.6
provided
-
- me.minebuilders
- clearlag
- 2.9.1
- provided
-
-
- com.griefcraft.lwc
- lwc-entity-locking
- 1.7.3
- provided
-
diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java
index b1c8618..073e1b9 100644
--- a/src/main/java/de/epiceric/shopchest/ShopChest.java
+++ b/src/main/java/de/epiceric/shopchest/ShopChest.java
@@ -22,9 +22,6 @@ import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
-import org.bukkit.World;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
@@ -41,7 +38,6 @@ public class ShopChest extends JavaPlugin {
private Config config = null;
private Economy econ = null;
private Permission perm = null;
- private boolean lwc = false;
private Database database;
private boolean isUpdateNeeded = false;
private String latestVersion = "";
@@ -238,8 +234,6 @@ public class ShopChest extends JavaPlugin {
}, config.auto_reload_time * 20, config.auto_reload_time * 20);
}
- lwc = getServer().getPluginManager().isPluginEnabled("LWC");
-
Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
@Override
public void run() {
@@ -254,7 +248,7 @@ public class ShopChest extends JavaPlugin {
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
for (Player p : getServer().getOnlinePlayers()) {
- if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
+ if (perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb = new JsonBuilder(ShopChest.this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
jb.sendJson(p);
}
@@ -287,16 +281,10 @@ public class ShopChest extends JavaPlugin {
debug("Registering listeners...");
getServer().getPluginManager().registerEvents(new HologramUpdateListener(this), this);
- getServer().getPluginManager().registerEvents(new ItemProtectListener(this), this);
+ getServer().getPluginManager().registerEvents(new ShopItemListener(this), this);
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdateOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(this), this);
- getServer().getPluginManager().registerEvents(new ItemCustomNameListener(), this);
-
- if (getServer().getPluginManager().isPluginEnabled("ClearLag"))
- getServer().getPluginManager().registerEvents(new ClearLagListener(), this);
-
- if (lwc) new LWCMagnetListener(this).initializeListener();
}
@Override
@@ -314,38 +302,6 @@ public class ShopChest extends JavaPlugin {
}
}
- for (World world : Bukkit.getWorlds()) {
- for (Entity entity : world.getEntities()) {
- if (entity instanceof Item) {
- Item item = (Item) entity;
- if (item.hasMetadata("shopItem")) {
- if (item.isValid()) {
- debug("Removing not removed shop item (#" +
- (item.hasMetadata("shopId") ? item.getMetadata("shopId").get(0).asString() : "?") + ")");
-
- item.remove();
- }
- }
- }
- }
- }
-
- if (config.enable_debug_log) {
- for (World world : Bukkit.getWorlds()) {
- for (Entity entity : world.getEntities()) {
- if (entity instanceof Item) {
- Item item = (Item) entity;
- if (item.hasMetadata("shopItem")) {
- if (item.isValid()) {
- debug("Shop item still valid (#" +
- (item.hasMetadata("shopId") ? item.getMetadata("shopId").get(0).asString() : "?") + ")");
- }
- }
- }
- }
- }
- }
-
database.disconnect();
if (fw != null && config.enable_debug_log) {
@@ -426,13 +382,6 @@ public class ShopChest extends JavaPlugin {
return database;
}
- /**
- * @return Whether LWC is available
- */
- public boolean hasLWC() {
- return lwc;
- }
-
/**
* @return Whether an update is needed (will return false if not checked)
*/
diff --git a/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java b/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java
deleted file mode 100644
index e46a76a..0000000
--- a/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package de.epiceric.shopchest.listeners;
-
-import me.minebuilders.clearlag.events.EntityRemoveEvent;
-import org.bukkit.entity.Entity;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-
-import java.util.ArrayList;
-
-public class ClearLagListener implements Listener {
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onEntityRemove(EntityRemoveEvent e) {
- ArrayList entityList = new ArrayList<>(e.getEntityList());
-
- for (Entity entity : entityList) {
- if (entity.hasMetadata("shopItem")) {
- e.getEntityList().remove(entity);
- }
- }
- }
-
-
-}
diff --git a/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java b/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java
deleted file mode 100644
index f548bfb..0000000
--- a/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package de.epiceric.shopchest.listeners;
-
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.entity.ItemSpawnEvent;
-
-public class ItemCustomNameListener implements Listener {
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onItemSpawn(ItemSpawnEvent e) {
- if (e.getEntity().hasMetadata("shopItem")) {
- e.getEntity().setCustomNameVisible(false);
- }
- }
-
-}
diff --git a/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java
deleted file mode 100644
index 26817ac..0000000
--- a/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package de.epiceric.shopchest.listeners;
-
-
-import de.epiceric.shopchest.ShopChest;
-import de.epiceric.shopchest.utils.ShopUtils;
-import de.epiceric.shopchest.utils.Utils;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.block.BlockState;
-import org.bukkit.entity.Item;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.*;
-import org.bukkit.event.entity.ItemDespawnEvent;
-import org.bukkit.event.inventory.InventoryPickupItemEvent;
-import org.bukkit.event.player.PlayerBucketEmptyEvent;
-import org.bukkit.event.player.PlayerFishEvent;
-import org.bukkit.event.player.PlayerPickupItemEvent;
-
-import java.lang.reflect.InvocationTargetException;
-
-public class ItemProtectListener implements Listener {
-
- private ShopUtils shopUtils;
- private ShopChest plugin;
-
- public ItemProtectListener(ShopChest plugin) {
- this.plugin = plugin;
- this.shopUtils = plugin.getShopUtils();
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onItemDespawn(ItemDespawnEvent e) {
- Item item = e.getEntity();
- if (item.hasMetadata("shopItem")) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onPlayerPickUpItem(PlayerPickupItemEvent e) {
- if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onItemPickup(InventoryPickupItemEvent e) {
- if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onBlockPlace(BlockPlaceEvent e) {
- Block b = e.getBlockPlaced();
- Block below = b.getRelative(BlockFace.DOWN);
-
- if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onMultiBlockPlace(BlockMultiPlaceEvent e) {
- for (BlockState blockState : e.getReplacedBlockStates()) {
- Block below = blockState.getBlock().getRelative(BlockFace.DOWN);
- if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onPistonExtend(BlockPistonExtendEvent e) {
- // If the piston would only move itself
- Block airAfterPiston = e.getBlock().getRelative(e.getDirection());
- Block belowAir = airAfterPiston.getRelative(BlockFace.DOWN);
- if (shopUtils.isShop(belowAir.getLocation())) {
- e.setCancelled(true);
- return;
- }
-
- for (Block b : e.getBlocks()) {
- Block newBlock = b.getRelative(e.getDirection());
- Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
- if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onPistonRetract(BlockPistonRetractEvent e) {
- for (Block b : e.getBlocks()) {
- Block newBlock = b.getRelative(e.getDirection());
- Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
- if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onLiquidFlow(BlockFromToEvent e) {
- Block b = e.getToBlock();
- Block below = b.getRelative(BlockFace.DOWN);
-
- if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onBucketEmpty(PlayerBucketEmptyEvent e) {
- Block b = e.getBlockClicked();
-
- if (shopUtils.isShop(b.getLocation())) e.setCancelled(true);
- }
-
- @EventHandler(priority = EventPriority.HIGH)
- public void onPlayerFish(PlayerFishEvent e) {
- if (e.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) {
- if (e.getCaught() instanceof Item) {
- Item item = (Item) e.getCaught();
- if (item.hasMetadata("shopItem")) {
- plugin.debug(e.getPlayer().getName() + " tried to fish a shop item");
- e.setCancelled(true);
-
- // Use some reflection to get the EntityFishingHook class so the hook can be removed...
- try {
- Class> craftFishClass = Class.forName("org.bukkit.craftbukkit." + Utils.getServerVersion() + ".entity.CraftFish");
- Object craftFish = craftFishClass.cast(e.getHook());
-
- Class> entityFishingHookClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".EntityFishingHook");
- Object entityFishingHook = craftFishClass.getDeclaredMethod("getHandle").invoke(craftFish);
-
- entityFishingHookClass.getDeclaredMethod("die").invoke(entityFishingHook);
- } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException ex) {
- plugin.debug("Failed to kill fishing hook with reflection");
- plugin.debug(ex);
- ex.printStackTrace();
- }
- }
- }
- }
- }
-
-}
diff --git a/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java b/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java
deleted file mode 100644
index 7960ef4..0000000
--- a/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package de.epiceric.shopchest.listeners;
-
-import com.griefcraft.lwc.LWC;
-import com.griefcraft.scripting.JavaModule;
-import com.griefcraft.scripting.event.LWCMagnetPullEvent;
-import de.epiceric.shopchest.ShopChest;
-
-public class LWCMagnetListener {
-
- private ShopChest plugin;
-
- public LWCMagnetListener(ShopChest plugin) {
- this.plugin = plugin;
- }
-
- public void initializeListener() {
- try {
- Class.forName("com.griefcraft.scripting.event.LWCMagnetPullEvent");
-
- LWC.getInstance().getModuleLoader().registerModule(ShopChest.getInstance(), new JavaModule() {
-
- @Override
- public void onMagnetPull(LWCMagnetPullEvent event) {
- if (event.getItem().hasMetadata("shopItem")) {
- event.setCancelled(true);
- }
- }
-
- });
-
- } catch (ClassNotFoundException ex) {
- plugin.debug("Using not recommended version of LWC");
- plugin.getLogger().warning("Shop items can be sucked up by the magnet flag of a protected chest of LWC.");
- plugin.getLogger().warning("Use 'LWC Unofficial - Entity locking' v1.7.3 or later by 'Me_Goes_RAWR' to prevent this.");
- }
- }
-
-
-}
diff --git a/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java b/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java
index a17770f..2dda50e 100644
--- a/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java
+++ b/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java
@@ -27,7 +27,7 @@ public class NotifyUpdateOnJoinListener implements Listener {
Player p = e.getPlayer();
if (plugin.isUpdateNeeded()) {
- if (p.isOp() || perm.has(p, "shopchest.notification.update")) {
+ if (perm.has(p, "shopchest.notification.update")) {
JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
jb.sendJson(p);
}
diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java
new file mode 100644
index 0000000..6977518
--- /dev/null
+++ b/src/main/java/de/epiceric/shopchest/listeners/ShopItemListener.java
@@ -0,0 +1,126 @@
+package de.epiceric.shopchest.listeners;
+
+import de.epiceric.shopchest.ShopChest;
+import de.epiceric.shopchest.shop.Shop;
+import de.epiceric.shopchest.utils.ShopUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.*;
+import org.bukkit.event.player.*;
+
+import java.lang.reflect.InvocationTargetException;
+
+public class ShopItemListener implements Listener {
+
+ private ShopUtils shopUtils;
+ private ShopChest plugin;
+
+ public ShopItemListener(ShopChest plugin) {
+ this.plugin = plugin;
+ this.shopUtils = plugin.getShopUtils();
+ }
+
+ @EventHandler
+ public void onPlayerJoin(PlayerJoinEvent e) {
+ for (Shop shop : plugin.getShopUtils().getShops()) {
+ shop.getItem().setVisible(e.getPlayer(), true);
+ }
+ }
+
+ @EventHandler
+ public void onPlayerLeave(PlayerQuitEvent e) {
+ for (Shop shop : plugin.getShopUtils().getShops()) {
+ shop.getItem().setVisible(e.getPlayer(), false);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onBlockPlace(BlockPlaceEvent e) {
+ Block b = e.getBlockPlaced();
+ Block below = b.getRelative(BlockFace.DOWN);
+
+ if (shopUtils.isShop(below.getLocation())) {
+ shopUtils.getShop(below.getLocation()).getItem().resetForPlayer(e.getPlayer());
+ e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onMultiBlockPlace(BlockMultiPlaceEvent e) {
+ for (BlockState blockState : e.getReplacedBlockStates()) {
+ Block below = blockState.getBlock().getRelative(BlockFace.DOWN);
+
+ if (shopUtils.isShop(below.getLocation())) {
+ shopUtils.getShop(below.getLocation()).getItem().resetForPlayer(e.getPlayer());
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onPistonExtend(BlockPistonExtendEvent e) {
+ // If the piston would only move itself
+ Block airAfterPiston = e.getBlock().getRelative(e.getDirection());
+ Block belowAir = airAfterPiston.getRelative(BlockFace.DOWN);
+ if (shopUtils.isShop(belowAir.getLocation())) {
+ e.setCancelled(true);
+ return;
+ }
+
+ for (Block b : e.getBlocks()) {
+ Block newBlock = b.getRelative(e.getDirection());
+ Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
+ if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onPistonRetract(BlockPistonRetractEvent e) {
+ for (Block b : e.getBlocks()) {
+ Block newBlock = b.getRelative(e.getDirection());
+ Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
+ if (shopUtils.isShop(belowNewBlock.getLocation())) {
+ e.setCancelled(true);
+ for (Player p : Bukkit.getOnlinePlayers()) {
+ shopUtils.getShop(belowNewBlock.getLocation()).getItem().resetForPlayer(p);
+ }
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onLiquidFlow(BlockFromToEvent e) {
+ Block b = e.getToBlock();
+ Block below = b.getRelative(BlockFace.DOWN);
+
+ if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH)
+ public void onBucketEmpty(PlayerBucketEmptyEvent e) {
+ Block clicked = e.getBlockClicked();
+ Block underWater = clicked.getRelative(BlockFace.DOWN).getRelative(e.getBlockFace());
+
+ if (shopUtils.isShop(clicked.getLocation())) {
+ if (e.getBucket() == Material.LAVA_BUCKET) {
+ shopUtils.getShop(clicked.getLocation()).getItem().resetForPlayer(e.getPlayer());
+ }
+ } else if (shopUtils.isShop(underWater.getLocation())) {
+ if (e.getBucket() == Material.LAVA_BUCKET) {
+ shopUtils.getShop(underWater.getLocation()).getItem().resetForPlayer(e.getPlayer());
+ }
+ } else {
+ return;
+ }
+
+ e.setCancelled(true);
+ }
+
+}
diff --git a/src/main/java/de/epiceric/shopchest/nms/Hologram.java b/src/main/java/de/epiceric/shopchest/nms/Hologram.java
index 1ef2858..e36d31f 100644
--- a/src/main/java/de/epiceric/shopchest/nms/Hologram.java
+++ b/src/main/java/de/epiceric/shopchest/nms/Hologram.java
@@ -13,7 +13,6 @@ import java.util.List;
public class Hologram {
- private Class> entityArmorStandClass;
private boolean exists = false;
private int count;
private List