mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-12-26 07:38:49 +00:00
fix: 修复虚拟悬浮物 优化初始化流程
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
ec2498fc48
commit
dec12d75cb
8
pom.xml
8
pom.xml
@ -17,7 +17,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
@ -57,8 +57,8 @@
|
||||
§b1.9.5 - §a1.10+兼容虚拟悬浮物...;
|
||||
</update.changes>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
@ -78,7 +78,7 @@
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.6</version>
|
||||
<version>1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
|
||||
|
@ -12,7 +12,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
|
||||
import org.maxgamer.QuickShop.Shop.Item.DisplayItem;
|
||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_18;
|
||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_111;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
@ -92,26 +93,7 @@ public class ConfigManager {
|
||||
this.warnings = Collections.emptySet();
|
||||
this.prevent = config.getStringList("prevent");
|
||||
if (config.getBoolean("fakeitem", true)) {
|
||||
try {
|
||||
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
|
||||
FakeItem_19_111.register(plugin);
|
||||
new FakeItem_19_111(new Location(Bukkit.getWorlds().get(0), 0, 0, 0), new ItemStack(Material.STONE)).spawn();
|
||||
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.9-1.11.2)...");
|
||||
fakeItem = true;
|
||||
} catch (final Throwable e) {
|
||||
Log.d(e);
|
||||
try {
|
||||
FakeItem_17_18.register(plugin);
|
||||
new FakeItem_17_18(new Location(Bukkit.getWorlds().get(0), 0, 0, 0), new ItemStack(Material.STONE)).spawn();
|
||||
plugin.getLogger().info("虚拟悬浮物功能测试正常(1.7-1.8)...");
|
||||
fakeItem = true;
|
||||
} catch (final Throwable e2) {
|
||||
plugin.getLogger().warning("+=========================================");
|
||||
plugin.getLogger().warning("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
|
||||
plugin.getLogger().warning("+=========================================");
|
||||
Log.d(e2);
|
||||
}
|
||||
}
|
||||
DisplayItem.init();
|
||||
}
|
||||
if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) {
|
||||
Log.d("辣鸡 Paper 毁我异步命令!");
|
||||
|
@ -22,6 +22,8 @@ import org.maxgamer.QuickShop.Shop.ShopAction;
|
||||
import org.maxgamer.QuickShop.Util.MsgUtil;
|
||||
import org.maxgamer.QuickShop.Util.Util;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
private final QuickShop plugin;
|
||||
|
||||
@ -88,14 +90,13 @@ public class BlockListener implements Listener {
|
||||
public void onPlace(final BlockPlaceEvent e) {
|
||||
if (e.isCancelled()) { return; }
|
||||
final BlockState bs = e.getBlock().getState();
|
||||
if (!(bs instanceof DoubleChest)) { return; }
|
||||
final Block b = e.getBlock();
|
||||
final Player p = e.getPlayer();
|
||||
final Block chest = Util.getSecondHalf(b);
|
||||
if (chest != null) {
|
||||
Shop shop = plugin.getShopManager().getShop(chest.getLocation());
|
||||
if (shop != null) {
|
||||
if (!shop.getOwner().equals(p.getName())) {
|
||||
if (!p.getName().equals(shop.getOwner())) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(MsgUtil.p("no-double-chests"));
|
||||
return;
|
||||
|
@ -63,7 +63,7 @@ public class LockListener implements Listener {
|
||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||
// Make sure they're not using the non-shop half of a double chest.
|
||||
if (!hasSecondHalf(shop, b)) { return; }
|
||||
if (shop != null && !shop.getOwner().equals(p.getName())) {
|
||||
if (shop != null && !p.getName().equals(shop.getOwner())) {
|
||||
if (p.hasPermission("quickshop.other.open")) {
|
||||
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
||||
return;
|
||||
|
@ -1,36 +1,61 @@
|
||||
package org.maxgamer.QuickShop.Shop.Item;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
||||
|
||||
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
|
||||
* cannot be interacted with.
|
||||
*/
|
||||
public abstract class DisplayItem {
|
||||
public static QuickShop plugin = P.getPlugin();
|
||||
private static QuickShop plugin = P.getPlugin();
|
||||
|
||||
private static Class<? extends DisplayItem> displayItemClass;
|
||||
|
||||
private static Constructor<? extends DisplayItem> constructor;
|
||||
|
||||
public static void init() {
|
||||
List<Class<? extends DisplayItem>> fakeItems = Arrays.asList(FakeItem_19_111.class, FakeItem_18.class, FakeItem_17.class);
|
||||
Log.i("启用虚拟悬浮物 尝试启动中...");
|
||||
FakeItem.register(plugin);
|
||||
fakeItems.forEach(c -> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
if (displayItemClass == null) {
|
||||
displayItemClass = NormalItem.class;
|
||||
Log.w("+=========================================");
|
||||
Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
|
||||
Log.w("+=========================================");
|
||||
}
|
||||
try {
|
||||
constructor = displayItemClass.getConstructor(Location.class, ItemStack.class);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static DisplayItem create(final ContainerShop shop) {
|
||||
String ver = C.getNMSVersion();
|
||||
if (plugin.getConfigManager().isDisplay()) {
|
||||
if (plugin.getConfigManager().isFakeItem()) {
|
||||
try {
|
||||
if (Integer.parseInt(ver.split("_")[1]) > 8) {
|
||||
return new FakeItem_19_111(shop.getLocation(), shop.getItem());
|
||||
} else {
|
||||
return new FakeItem_17_18(shop.getLocation(), shop.getItem());
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
Log.d(e);
|
||||
}
|
||||
}
|
||||
return new NormalItem(shop, shop.getItem());
|
||||
if (plugin.getConfigManager().isDisplay()) try {
|
||||
return constructor.newInstance(shop.getLocation(), shop.getItem());
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
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
|
||||
*
|
||||
* @author 橙子(chengzi)
|
||||
* @version 1.0.1
|
||||
*/
|
||||
public class FakeItem_17_18 extends FakeItem {
|
||||
|
||||
public FakeItem_17_18(Location loc, final ItemStack item) {
|
||||
super(loc, item);
|
||||
}
|
||||
|
||||
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(10, itemStack);
|
||||
final List<WrappedWatchableObject> entityMetaList = new ArrayList<>(1);
|
||||
entityMetaList.add(itemMeta);
|
||||
fakePacket.getWatchableCollectionModifier().write(0, entityMetaList);
|
||||
return fakePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketContainer setSpawnPacket(PacketContainer fakePacket) {
|
||||
StructureModifier<Integer> 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;
|
||||
}
|
||||
}
|
||||
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
|
||||
*
|
||||
* @author 橙子(chengzi)
|
||||
* @version 1.0.1
|
||||
*/
|
||||
public class FakeItem_17 extends FakeItem {
|
||||
|
||||
public FakeItem_17(Location loc, final ItemStack item) {
|
||||
super(loc, item);
|
||||
}
|
||||
|
||||
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(10, itemStack);
|
||||
final List<WrappedWatchableObject> entityMetaList = new ArrayList<>(1);
|
||||
entityMetaList.add(itemMeta);
|
||||
fakePacket.getWatchableCollectionModifier().write(0, entityMetaList);
|
||||
return fakePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketContainer setSpawnPacket(PacketContainer fakePacket) {
|
||||
StructureModifier<Integer> 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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
|
||||
*
|
||||
* @author 橙子(chengzi)
|
||||
* @version 1.0.1
|
||||
*/
|
||||
public class FakeItem_18 extends FakeItem {
|
||||
|
||||
public FakeItem_18(Location loc, final ItemStack item) {
|
||||
super(loc, item);
|
||||
}
|
||||
|
||||
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(10, itemStack);
|
||||
final List<WrappedWatchableObject> entityMetaList = new ArrayList<>(1);
|
||||
entityMetaList.add(itemMeta);
|
||||
fakePacket.getWatchableCollectionModifier().write(0, entityMetaList);
|
||||
return fakePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketContainer setSpawnPacket(PacketContainer fakePacket) {
|
||||
StructureModifier<Integer> 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;
|
||||
}
|
||||
}
|
@ -16,21 +16,21 @@ import org.maxgamer.QuickShop.Util.NMS;
|
||||
public class NormalItem extends DisplayItem {
|
||||
private final ItemStack iStack;
|
||||
private Item item;
|
||||
private final Shop shop;
|
||||
private final Location location;
|
||||
|
||||
// private Location displayLoc;
|
||||
/**
|
||||
* Creates a new display item.
|
||||
*
|
||||
* @param shop
|
||||
* @param location
|
||||
* The shop (See Shop)
|
||||
* @param iStack
|
||||
* The item stack to clone properties of the display item from.
|
||||
*/
|
||||
public NormalItem(final Shop shop, final ItemStack iStack) {
|
||||
this.shop = shop;
|
||||
public NormalItem(final Location location, final ItemStack iStack) {
|
||||
this.location = location;
|
||||
this.iStack = iStack.clone();
|
||||
// this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||
// this.displayLoc = location().clone().add(0.5, 1.2, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ public class NormalItem extends DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public Location getDisplayLocation() {
|
||||
return this.shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||
return this.location.clone().add(0.5, 1.2, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,8 +65,8 @@ public class NormalItem extends DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public boolean removeDupe() {
|
||||
if (shop.getLocation().getWorld() == null) { return false; }
|
||||
final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
|
||||
if (location.getWorld() == null) { return false; }
|
||||
final Location displayLoc = location.getBlock().getRelative(0, 1, 0).getLocation();
|
||||
boolean removed = false;
|
||||
final Chunk c = displayLoc.getChunk();
|
||||
for (final Entity e : c.getEntities()) {
|
||||
@ -77,7 +77,7 @@ public class NormalItem extends DisplayItem {
|
||||
continue;
|
||||
}
|
||||
final Location eLoc = e.getLocation().getBlock().getLocation();
|
||||
if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) {
|
||||
if (eLoc.equals(displayLoc) || eLoc.equals(location)) {
|
||||
e.remove();
|
||||
removed = true;
|
||||
}
|
||||
@ -99,10 +99,10 @@ public class NormalItem extends DisplayItem {
|
||||
*/
|
||||
@Override
|
||||
public void spawn() {
|
||||
if (shop.getLocation().getWorld() == null) { return; }
|
||||
if (location.getWorld() == null) { return; }
|
||||
final Location dispLoc = this.getDisplayLocation();
|
||||
try {
|
||||
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
|
||||
this.item = location.getWorld().dropItem(dispLoc, this.iStack);
|
||||
this.item.setVelocity(new Vector(0, 0.1, 0));
|
||||
NMS.safeGuard(this.item);
|
||||
} catch (final Exception ignored) {
|
||||
|
@ -16,6 +16,8 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Sign;
|
||||
import org.maxgamer.QuickShop.QuickShop;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.global.L10N;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
@ -176,6 +178,7 @@ public class Util {
|
||||
* @return the block which is also a chest and connected to b.
|
||||
*/
|
||||
public static Block getSecondHalf(final Block b) {
|
||||
Log.d("%s", b);
|
||||
if (!b.getType().toString().contains("CHEST")) { return null; }
|
||||
final Block[] blocks = new Block[4];
|
||||
blocks[0] = b.getRelative(1, 0, 0);
|
||||
@ -483,7 +486,7 @@ public class Util {
|
||||
}
|
||||
if (book1) { // They are the same here (both true or both
|
||||
// false). So if one is true, the other is
|
||||
// true.
|
||||
// true.
|
||||
final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
|
||||
final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
|
||||
if (!ench1.equals(ench2)) { return false; // Enchants aren't the same.
|
||||
|
Loading…
Reference in New Issue
Block a user