diff --git a/pom.xml b/pom.xml index 49fb55a..5a7bd09 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.maxgamer QuickShop - 2.1 + 2.1.0 快捷商店重置版本... ${project.name} diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java index 81d92c8..9079ff0 100644 --- a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java @@ -10,6 +10,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.maxgamer.QuickShop.Listeners.ChunkListener; import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.Item.DisplayItem; @@ -89,11 +90,9 @@ public class ConfigManager { this.guiTitle = config.getMessage("guititle", guiTitle); this.warnings = Collections.emptySet(); this.prevent = config.getStringList("prevent"); - if (config.getBoolean("fakeitem", true)) { - DisplayItem.init(); - } - if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) { - Log.d("辣鸡 Paper 毁我异步命令!"); + if (display) { + Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(), plugin); + DisplayItem.init(config.getBoolean("fakeitem", true)); } if (config.getBoolean("usemagiclib", true)) { try { diff --git a/src/main/java/org/maxgamer/QuickShop/Listeners/ChunkListener.java b/src/main/java/org/maxgamer/QuickShop/Listeners/ChunkListener.java index f8cc181..b2f9267 100644 --- a/src/main/java/org/maxgamer/QuickShop/Listeners/ChunkListener.java +++ b/src/main/java/org/maxgamer/QuickShop/Listeners/ChunkListener.java @@ -12,21 +12,17 @@ import org.bukkit.event.world.ChunkUnloadEvent; import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.Shop; -public class ChunkListener implements Listener { - private QuickShop plugin; +import pw.yumc.YumCore.bukkit.P; - public ChunkListener(QuickShop plugin) { - this.plugin = plugin; - } +public class ChunkListener implements Listener { + private QuickShop plugin = P.getPlugin(); @EventHandler(priority = EventPriority.HIGHEST) public void onChunkLoad(ChunkLoadEvent e) { Chunk c = e.getChunk(); - if (plugin.getShopManager().getShops() == null) - return; + if (plugin.getShopManager().getShops() == null) return; HashMap inChunk = plugin.getShopManager().getShops(c); - if (inChunk == null) - return; + if (inChunk == null) return; for (Shop shop : inChunk.values()) { shop.onLoad(); } @@ -36,8 +32,7 @@ public class ChunkListener implements Listener { public void onChunkUnload(ChunkUnloadEvent e) { Chunk c = e.getChunk(); HashMap inChunk = plugin.getShopManager().getShops(c); - if (inChunk == null) - return; + if (inChunk == null) return; for (Shop shop : inChunk.values()) { shop.onUnload(); } diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index 06d24e8..db8b706 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -36,6 +36,7 @@ import org.maxgamer.QuickShop.Economy.EconomyCore; import org.maxgamer.QuickShop.Economy.Economy_Vault; import org.maxgamer.QuickShop.Listeners.BlockListener; import org.maxgamer.QuickShop.Listeners.ChatListener; +import org.maxgamer.QuickShop.Listeners.ChunkListener; import org.maxgamer.QuickShop.Listeners.LockListener; import org.maxgamer.QuickShop.Listeners.PlayerListener; import org.maxgamer.QuickShop.Listeners.ProtectListener; @@ -253,11 +254,11 @@ public class QuickShop extends JavaPlugin { @Override public void onEnable() { if (!loadEcon()) { return; } - configManager = new ConfigManager(this); - // Initialize Util Util.initialize(); // Create the shop manager. shopManager = new ShopManager(this); + configManager = new ConfigManager(this); + // Initialize Util if (configManager.isLogAction()) { // Logger Handler this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log")); diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java index 75fd066..5d38748 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java @@ -17,6 +17,7 @@ import org.maxgamer.QuickShop.Watcher.ItemWatcher; import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.P; +import pw.yumc.YumCore.bukkit.compatible.C; /** * @author Netherfoam A display item, that spawns a block above the chest and @@ -25,39 +26,53 @@ import pw.yumc.YumCore.bukkit.P; public abstract class DisplayItem { private static QuickShop plugin = P.getPlugin(); - private static Class displayItemClass; + private static Class displayItemClass = NormalItem.class; private static Constructor constructor; - public static void init() { - List> fakeItems = Arrays.asList(FakeItem_19_111.class, FakeItem_18.class, FakeItem_17.class); - Log.i("启用虚拟悬浮物 尝试启动中..."); - FakeItem.register(plugin); - for (Class c : fakeItems) { - try { - c.getConstructor(Location.class, ItemStack.class).newInstance(new Location(Bukkit.getWorlds().get(0), 0, 0, 0), new ItemStack(Material.STONE)).spawn(); - displayItemClass = c; - Log.i("虚拟悬浮物功能测试正常(%s)...", c.getSimpleName()); + public static void init(boolean fakeItem) { + if (fakeItem) { + Log.i("启用虚拟悬浮物 尝试启动中..."); + String nms = C.getNMSVersion(); + Class c = null; + switch (nms) { + case "v1_7_R4": + c = FakeItem_17.class; break; - } catch (Throwable e) { - Log.d(e); + case "v1_8_R3": + c = FakeItem_18.class; + break; + case "v1_9_R1": + case "v1_9_R2": + case "v1_10_R1": + case "v1_11_R1": + c = FakeItem_19_111.class; + break; + } + if (c != null) { + FakeItem.register(plugin); + try { + c.getConstructor(Location.class, ItemStack.class).newInstance(new Location(Bukkit.getWorlds().get(0), 0, 0, 0), new ItemStack(Material.STONE)).spawn(); + displayItemClass = c; + Log.i("虚拟悬浮物功能测试正常(%s)...", c.getSimpleName()); + } catch (Throwable e) { + Log.d(e); + Log.w("+========================================="); + Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品..."); + Log.w("+========================================="); + } + } else { + Log.i("没有可用的虚拟物品类 使用原版悬浮物品..."); } } - if (displayItemClass == null) { - displayItemClass = NormalItem.class; - if (plugin.getConfigManager().isDisplay()) { - Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(plugin), plugin); + try { + constructor = displayItemClass.getConstructor(Location.class, ItemStack.class); + if (displayItemClass == NormalItem.class) { // Display item handler thread Log.i("开启商店检查以及悬浮物刷新线程..."); final ItemWatcher itemWatcher = new ItemWatcher(plugin); plugin.itemWatcherTask = Bukkit.getScheduler().runTaskTimer(plugin, itemWatcher, 20, 1800); } - Log.w("+========================================="); - Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品..."); - Log.w("+========================================="); - } - try { - constructor = displayItemClass.getConstructor(Location.class, ItemStack.class); } catch (NoSuchMethodException ignored) { } } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java index 8f0f9f7..5e28f4e 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java @@ -37,14 +37,12 @@ public abstract class FakeItem extends DisplayItem { protected final ItemStack itemStack; protected final Location location; protected final int eid; - protected final UUID uuid; protected boolean created = false; public FakeItem(Location loc, final ItemStack item) { this.itemStack = item; this.location = loc.clone().add(0.5, 1, 0.5); this.eid = getFakeEntityId(); - this.uuid = UUID.randomUUID(); } public static boolean isRegistered() { @@ -183,13 +181,13 @@ public abstract class FakeItem extends DisplayItem { created = false; } - private PacketContainer getDestoryPacket() { + protected PacketContainer getDestoryPacket() { final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY, true); fakePacket.getIntegerArrays().write(0, new int[] { eid }); return fakePacket; } - private PacketContainer getVelocityPacket() { + protected PacketContainer getVelocityPacket() { final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY); fakePacket.getIntegers().write(0, eid); return fakePacket; diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_17.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_17.java index 6ad5053..d243883 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_17.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_17.java @@ -44,6 +44,17 @@ public class FakeItem_17 extends FakeItem { is.write(1, getNormalizedDistance(location.getX())); is.write(2, getNormalizedDistance(location.getY())); is.write(3, getNormalizedDistance(location.getZ())); + is.write(9, 2); return fakePacket; } + + @Override + protected PacketContainer getVelocityPacket() { + PacketContainer packet = super.getVelocityPacket(); + StructureModifier pint = packet.getIntegers(); + pint.write(1, 0); + pint.write(2, 0); + pint.write(3, 0); + return packet; + } } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_18.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_18.java index 690dfcc..e80910a 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_18.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_18.java @@ -1,15 +1,8 @@ package org.maxgamer.QuickShop.Shop.Item; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Location; import org.bukkit.inventory.ItemStack; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.WrappedWatchableObject; - /** * Minecraft 虚拟悬浮物品工具类 * 需要depend ProtocolLib @@ -17,7 +10,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject; * @author 橙子(chengzi) * @version 1.0.1 */ -public class FakeItem_18 extends FakeItem { +public class FakeItem_18 extends FakeItem_17 { public FakeItem_18(Location loc, final ItemStack item) { super(loc, item); @@ -26,24 +19,4 @@ public class FakeItem_18 extends FakeItem { private static int getNormalizedDistance(final double value) { return (int) Math.floor(value * 32.0D); } - - @Override - protected PacketContainer setMetadataPacket(PacketContainer fakePacket) { - fakePacket.getIntegers().write(0, eid); - final WrappedWatchableObject itemMeta = new WrappedWatchableObject(5, itemStack); - final List entityMetaList = new ArrayList<>(1); - entityMetaList.add(itemMeta); - fakePacket.getWatchableCollectionModifier().write(0, entityMetaList); - return fakePacket; - } - - @Override - protected PacketContainer setSpawnPacket(PacketContainer fakePacket) { - StructureModifier is = fakePacket.getIntegers(); - is.write(0, eid); - is.write(1, getNormalizedDistance(location.getX())); - is.write(2, getNormalizedDistance(location.getY())); - is.write(3, getNormalizedDistance(location.getZ())); - return fakePacket; - } } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_19_111.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_19_111.java index 41457b9..97f9e20 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_19_111.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem_19_111.java @@ -1,6 +1,6 @@ package org.maxgamer.QuickShop.Shop.Item; -import java.util.Optional; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; @@ -10,6 +10,7 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; +import com.google.common.base.Optional; /** * Minecraft 虚拟悬浮物品工具类 @@ -19,9 +20,11 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObje * @version 1.1.0 */ public class FakeItem_19_111 extends FakeItem { + protected final UUID uuid; public FakeItem_19_111(Location loc, final ItemStack item) { super(loc, item); + uuid = UUID.randomUUID(); } @Override