mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
BKCommonLib support for Advanced display-item protection.
Former-commit-id: c0684123ae1c7c4d065a0c6c192f4fec836096d6 [formerly 63482456f7d03fbe69be15961276f7a6bc363ceb] Former-commit-id: 87c0be8bbd839cef194a85f85de0ff0081ad0455
This commit is contained in:
1 parent
6dafdfba83
commit
0f00a1e452
10 files changed
+194
-17
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.maxgamer.quickshop.Shop.DisplayItem;
|
||||
import org.maxgamer.quickshop.Shop.DisplayItemStorage;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import com.bergerkiller.bukkit.common.events.EntityMoveEvent;
|
||||
|
||||
public class BKCommonLibListener implements Listener {
|
||||
public BKCommonLibListener() {
|
||||
Bukkit.getPluginManager().registerEvents(this,Bukkit.getPluginManager().getPlugin("BKCommonLib"));
|
||||
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityMove(EntityMoveEvent e) {
|
||||
if(e.getEntityType()!=EntityType.DROPPED_ITEM) { //Only check we need
|
||||
return;
|
||||
}
|
||||
Item item = (Item)e.getEntity();
|
||||
if(DisplayItem.checkShopItem(item.getItemStack())) {
|
||||
if((e.getFromX()==e.getToX())&&(e.getFromZ()==e.getToZ())) //Spam
|
||||
return;
|
||||
if(e.getEntity().getLocation().getBlock().getType()==Material.WATER) {
|
||||
e.getEntity().remove();
|
||||
return;
|
||||
}
|
||||
if(Util.canBeShop(e.getEntity().getLocation().clone().add(0, -1, 0).getBlock())) {
|
||||
e.getEntity().teleport(DisplayItemStorage.getDisplayLocation(e.getEntity().getUniqueId()));
|
||||
return;
|
||||
}else {
|
||||
e.getEntity().remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class DisplayProtectionListener implements Listener {
|
||||
public DisplayProtectionListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
for (int i = 0; i<event.getInventory().getContents().length; i++) {
|
||||
|
||||
@@ -101,6 +101,7 @@ public class QuickShop extends JavaPlugin {
|
||||
private boolean setupDBonEnableding = false;
|
||||
public String dbPrefix="";
|
||||
public ProtocolLib protocolLibPlugin = null;
|
||||
private Plugin BKCommonLibPlugin;
|
||||
public int getShopLimit(Player p) {
|
||||
int max = getConfig().getInt("limits.default");
|
||||
for (Entry<String, Integer> entry : limits.entrySet()) {
|
||||
@@ -168,11 +169,18 @@ public class QuickShop extends JavaPlugin {
|
||||
// added for compatibility reasons with OpenInv - see
|
||||
// https://github.com/KaiKikuchi/QuickShop/issues/139
|
||||
if(getConfig().getBoolean("plugin.OpenInv")) {
|
||||
|
||||
this.openInvPlugin = Bukkit.getPluginManager().getPlugin("OpenInv");
|
||||
if(this.openInvPlugin!=null)
|
||||
getLogger().info("Successfully loaded OpenInv support!");
|
||||
}
|
||||
if(getConfig().getBoolean("plugin.BKCommonLib")) {
|
||||
|
||||
this.BKCommonLibPlugin = Bukkit.getPluginManager().getPlugin("BKCommonLib");
|
||||
if(this.BKCommonLibPlugin!=null && Bukkit.getPluginManager().getPlugin("BKCommonLib").isEnabled()) {
|
||||
new BKCommonLibListener();
|
||||
getLogger().info("Successfully loaded BKCommonLib support!");
|
||||
}
|
||||
}
|
||||
if (getConfig().getBoolean("plugin.ProtocolLib")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||
protocolLibPlugin = (ProtocolLib) Bukkit.getPluginManager().getPlugin("ProtocolLib");
|
||||
|
||||
@@ -183,6 +183,7 @@ public class DisplayItem {
|
||||
return;
|
||||
}
|
||||
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
|
||||
DisplayItemStorage.addDisplayItemShop(item.getUniqueId(), shop);
|
||||
this.item.setVelocity(new Vector(0, 0.1, 0));
|
||||
try {
|
||||
this.safeGuard(this.item);
|
||||
@@ -210,7 +211,9 @@ public class DisplayItem {
|
||||
item.setCustomName("QuickShop");
|
||||
iMeta.setDisplayName("QuickShop");
|
||||
}
|
||||
|
||||
item.setPortalCooldown(Integer.MAX_VALUE);
|
||||
item.setSilent(true);
|
||||
item.setInvulnerable(true);
|
||||
java.util.List<String> lore = new ArrayList<String>();
|
||||
lore.add("QuickShop DisplayItem");
|
||||
iMeta.setLore(lore);
|
||||
@@ -260,7 +263,9 @@ public class DisplayItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
DisplayItemStorage.id2ShopMap.clear();
|
||||
return removed;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,6 +275,7 @@ public class DisplayItem {
|
||||
if (this.item == null)
|
||||
return;
|
||||
this.item.remove();
|
||||
DisplayItemStorage.removeDisplayItemByUUID(this.item.getUniqueId());
|
||||
this.item = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class DisplayItemStorage {
|
||||
static Map<UUID,Shop> id2ShopMap = new HashMap<>();
|
||||
public Shop getDisplayItemShop(UUID uuid) {
|
||||
return id2ShopMap.get(uuid);
|
||||
}
|
||||
public static void addDisplayItemShop(UUID uuid,Shop shop) {
|
||||
id2ShopMap.put(uuid, shop);
|
||||
}
|
||||
public static Location getDisplayLocation(UUID uuid) {
|
||||
Shop shop = id2ShopMap.get(uuid);
|
||||
if(shop==null)
|
||||
return null;
|
||||
return shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||
}
|
||||
public static UUID getShopDisplayItem(Shop shop) {
|
||||
Set<Entry<UUID,Shop>> set=id2ShopMap.entrySet();
|
||||
Iterator<Entry<UUID, Shop>> it=set.iterator();
|
||||
while(it.hasNext()) {
|
||||
Entry<UUID, Shop> entry =(Entry<UUID, Shop>)it.next();
|
||||
if(entry.getValue().equals(shop)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removeDisplayItemByShop(Shop shop) {
|
||||
try {
|
||||
Set<Entry<UUID, Shop>> set = id2ShopMap.entrySet();
|
||||
Iterator<Entry<UUID, Shop>> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Shop> entry = (Entry<UUID, Shop>) it.next();
|
||||
if (entry.getValue().equals(shop)) {
|
||||
id2ShopMap.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
public static void removeDisplayItemByUUID(UUID uuid) {
|
||||
try {
|
||||
id2ShopMap.remove(uuid);
|
||||
}catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
@@ -571,8 +572,8 @@ public class ShopManager {
|
||||
p.sendMessage(MsgUtil.getMessage("chest-was-removed"));
|
||||
return;
|
||||
}
|
||||
if (info.getLocation().getWorld().getBlockAt(info.getLocation()).getType()==Material.ENDER_CHEST) {
|
||||
if(!p.hasPermission("quickshop.create.enderchest"))
|
||||
if (info.getLocation().getWorld().getBlockAt(info.getLocation()).getType() == Material.ENDER_CHEST) {
|
||||
if (!p.hasPermission("quickshop.create.enderchest"))
|
||||
return;
|
||||
}
|
||||
// Price per item
|
||||
@@ -593,10 +594,8 @@ public class ShopManager {
|
||||
// p.sendMessage(ChatColor.RED+"Restricted prices for
|
||||
// "+info.getItem().getType()+": min "+priceRestriction.getKey()+", max
|
||||
// "+priceRestriction.getValue());
|
||||
p.sendMessage(
|
||||
MsgUtil.getMessage("restricted-prices", MsgUtil.getDisplayName(info.getItem()),
|
||||
String.valueOf(priceRestriction.getKey()),
|
||||
String.valueOf(priceRestriction.getValue())));
|
||||
p.sendMessage(MsgUtil.getMessage("restricted-prices", MsgUtil.getDisplayName(info.getItem()),
|
||||
String.valueOf(priceRestriction.getKey()), String.valueOf(priceRestriction.getValue())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,8 +640,7 @@ public class ShopManager {
|
||||
createShop(shop);
|
||||
Location loc = shop.getLocation();
|
||||
plugin.log(p.getName() + " created a " + MsgUtil.getDisplayName(shop.getItem()) + " shop at ("
|
||||
+ loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ()
|
||||
+ ")");
|
||||
+ loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ")");
|
||||
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
||||
// Warn them if they haven't been warned since
|
||||
// reboot
|
||||
@@ -658,11 +656,19 @@ public class ShopManager {
|
||||
* NOTICE: When player use /qs create command to create shop, sign will placed
|
||||
* to wrong facing.
|
||||
*/
|
||||
if (info.getSignBlock() != null && info.getSignBlock().getType() == Material.AIR
|
||||
&& plugin.getConfig().getBoolean("shop.auto-sign")) {
|
||||
if (info.getSignBlock() != null && plugin.getConfig().getBoolean("shop.auto-sign")) {
|
||||
if(info.getSignBlock().getType() != Material.AIR&&info.getSignBlock().getType() != Material.WATER)
|
||||
return;
|
||||
boolean isWaterLogged = false;
|
||||
if(info.getSignBlock().getType()==Material.WATER)
|
||||
isWaterLogged = true;
|
||||
final BlockState bs = info.getSignBlock().getState();
|
||||
final BlockFace bf = info.getLocation().getBlock().getFace(info.getSignBlock());
|
||||
bs.setType(Material.WALL_SIGN);
|
||||
if(isWaterLogged) {
|
||||
Waterlogged waterable = (Waterlogged)bs.getBlockData();
|
||||
waterable.setWaterlogged(true); //Looks like sign directly put in water
|
||||
}
|
||||
final Sign sign = (Sign) bs.getData();
|
||||
sign.setFacingDirection(bf);
|
||||
bs.setData(sign);
|
||||
|
||||
@@ -32,6 +32,8 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
@@ -50,6 +52,7 @@ public class Util {
|
||||
private static final EnumMap<Material, Entry<Double,Double>> restrictedPrices = new EnumMap<Material, Entry<Double,Double>>(Material.class);
|
||||
private static QuickShop plugin;
|
||||
private static Method storageContents;
|
||||
static Map<UUID, Long> timerMap = new HashMap<UUID, Long>();
|
||||
|
||||
public static void initialize() {
|
||||
blacklist.clear();
|
||||
@@ -753,10 +756,50 @@ public class Util {
|
||||
}
|
||||
|
||||
}
|
||||
private static Object serverInstance;
|
||||
private static Field tpsField;
|
||||
public static Double getTPS() {
|
||||
try {
|
||||
serverInstance = getNMSClass("MinecraftServer").getMethod("getServer").invoke(null);
|
||||
tpsField = serverInstance.getClass().getField("recentTps");
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
double[] tps = ((double[]) tpsField.get(serverInstance));
|
||||
return tps[0];
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
private static Class<?> getNMSClass(String className) {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String version = name.substring(name.lastIndexOf('.') + 1);
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + version + "." + className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static void debugLog(String logs) {
|
||||
if(plugin.getConfig().getBoolean("dev-mode")) {
|
||||
plugin.getLogger().info("[DEBUG]"+logs);
|
||||
}
|
||||
|
||||
}
|
||||
public static UUID setTimer() {
|
||||
UUID random = UUID.randomUUID();
|
||||
timerMap.put(random, System.currentTimeMillis());
|
||||
return random;
|
||||
}
|
||||
public static long getTimer(UUID uuid) {
|
||||
return timerMap.get(uuid);
|
||||
}
|
||||
public static long endTimer(UUID uuid) {
|
||||
long time =System.currentTimeMillis()-timerMap.get(uuid);
|
||||
timerMap.remove(uuid);
|
||||
return time;
|
||||
}
|
||||
}
|
||||
@@ -202,6 +202,11 @@ float:
|
||||
|
||||
# Enable or disable plugin support.
|
||||
plugin:
|
||||
#If you have ProtocolLib, QSRR will enable Sign Input GUI not normal chat
|
||||
ProtocolLib: true
|
||||
#If you have Multiverse-Core, QSRR will try load world when shop's world not exist and throw out exception auto repair the shop.
|
||||
Multiverse-Core: true
|
||||
OpenInv: true
|
||||
#If you have OpenInv, QSRR will enable EnderChest feature.
|
||||
OpenInv: true
|
||||
#If you have BKCommonLib, QSRR will enable advanced display-item protection.
|
||||
BKCommonLib: true
|
||||
@@ -5,7 +5,7 @@ authors: [Netherfoam, Timtower, KaiNoMood, Ghost_chu, Mgazul]
|
||||
|
||||
description: Economy Shops plugin
|
||||
#softdepend: [Herochat, Vault, Essentials, OpenInv] OLD Remove Herochat support.
|
||||
softdepend: [Vault, WorldGuard, Essentials, OpenInv, Multiverse-Core, ProtocolLib, CoreProtect]
|
||||
softdepend: [Vault, WorldGuard, Essentials, OpenInv, Multiverse-Core, ProtocolLib, CoreProtect, BKCommonLib]
|
||||
|
||||
api-version: 1.13
|
||||
|
||||
|
||||
Reference in new issue
Block a user