mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>2.3</version>
|
<version>2.4.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<minimizeJar>true</minimizeJar>
|
<minimizeJar>true</minimizeJar>
|
||||||
@ -57,8 +57,8 @@
|
|||||||
§b1.9.5 - §a1.10+兼容虚拟悬浮物...;
|
§b1.9.5 - §a1.10+兼容虚拟悬浮物...;
|
||||||
</update.changes>
|
</update.changes>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@ -78,7 +78,7 @@
|
|||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>YumCore</artifactId>
|
<artifactId>YumCore</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.6</version>
|
<version>1.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
|
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
|
||||||
|
@ -12,7 +12,8 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
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 org.maxgamer.QuickShop.Shop.Item.FakeItem_19_111;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
@ -92,26 +93,7 @@ public class ConfigManager {
|
|||||||
this.warnings = Collections.emptySet();
|
this.warnings = Collections.emptySet();
|
||||||
this.prevent = config.getStringList("prevent");
|
this.prevent = config.getStringList("prevent");
|
||||||
if (config.getBoolean("fakeitem", true)) {
|
if (config.getBoolean("fakeitem", true)) {
|
||||||
try {
|
DisplayItem.init();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) {
|
if (Bukkit.getVersion().contains("Paper") || Bukkit.getVersion().contains("Torch")) {
|
||||||
Log.d("辣鸡 Paper 毁我异步命令!");
|
Log.d("辣鸡 Paper 毁我异步命令!");
|
||||||
|
@ -22,6 +22,8 @@ import org.maxgamer.QuickShop.Shop.ShopAction;
|
|||||||
import org.maxgamer.QuickShop.Util.MsgUtil;
|
import org.maxgamer.QuickShop.Util.MsgUtil;
|
||||||
import org.maxgamer.QuickShop.Util.Util;
|
import org.maxgamer.QuickShop.Util.Util;
|
||||||
|
|
||||||
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
|
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
private final QuickShop plugin;
|
private final QuickShop plugin;
|
||||||
|
|
||||||
@ -88,14 +90,13 @@ public class BlockListener implements Listener {
|
|||||||
public void onPlace(final BlockPlaceEvent e) {
|
public void onPlace(final BlockPlaceEvent e) {
|
||||||
if (e.isCancelled()) { return; }
|
if (e.isCancelled()) { return; }
|
||||||
final BlockState bs = e.getBlock().getState();
|
final BlockState bs = e.getBlock().getState();
|
||||||
if (!(bs instanceof DoubleChest)) { return; }
|
|
||||||
final Block b = e.getBlock();
|
final Block b = e.getBlock();
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final Block chest = Util.getSecondHalf(b);
|
final Block chest = Util.getSecondHalf(b);
|
||||||
if (chest != null) {
|
if (chest != null) {
|
||||||
Shop shop = plugin.getShopManager().getShop(chest.getLocation());
|
Shop shop = plugin.getShopManager().getShop(chest.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
if (!shop.getOwner().equals(p.getName())) {
|
if (!p.getName().equals(shop.getOwner())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MsgUtil.p("no-double-chests"));
|
p.sendMessage(MsgUtil.p("no-double-chests"));
|
||||||
return;
|
return;
|
||||||
|
@ -63,7 +63,7 @@ public class LockListener implements Listener {
|
|||||||
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
// Make sure they're not using the non-shop half of a double chest.
|
// Make sure they're not using the non-shop half of a double chest.
|
||||||
if (!hasSecondHalf(shop, b)) { return; }
|
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")) {
|
if (p.hasPermission("quickshop.other.open")) {
|
||||||
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
p.sendMessage(MsgUtil.p("bypassing-lock"));
|
||||||
return;
|
return;
|
||||||
|
@ -1,36 +1,61 @@
|
|||||||
package org.maxgamer.QuickShop.Shop.Item;
|
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.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
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
|
* @author Netherfoam A display item, that spawns a block above the chest and
|
||||||
* cannot be interacted with.
|
* cannot be interacted with.
|
||||||
*/
|
*/
|
||||||
public abstract class DisplayItem {
|
public abstract class DisplayItem {
|
||||||
public static QuickShop plugin = P.getPlugin();
|
private static QuickShop plugin = P.getPlugin();
|
||||||
|
|
||||||
public static DisplayItem create(final ContainerShop shop) {
|
private static Class<? extends DisplayItem> displayItemClass;
|
||||||
String ver = C.getNMSVersion();
|
|
||||||
if (plugin.getConfigManager().isDisplay()) {
|
private static Constructor<? extends DisplayItem> constructor;
|
||||||
if (plugin.getConfigManager().isFakeItem()) {
|
|
||||||
|
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 {
|
try {
|
||||||
if (Integer.parseInt(ver.split("_")[1]) > 8) {
|
c.getConstructor(Location.class, ItemStack.class).newInstance(new Location(Bukkit.getWorlds().get(0), 0, 0, 0), new ItemStack(Material.STONE)).spawn();
|
||||||
return new FakeItem_19_111(shop.getLocation(), shop.getItem());
|
displayItemClass = c;
|
||||||
} else {
|
Log.i("虚拟悬浮物功能测试正常(%s)...", c.getSimpleName());
|
||||||
return new FakeItem_17_18(shop.getLocation(), shop.getItem());
|
} catch (Throwable e) {
|
||||||
}
|
|
||||||
} catch (final Throwable e) {
|
|
||||||
Log.d(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if (displayItemClass == null) {
|
||||||
|
displayItemClass = NormalItem.class;
|
||||||
|
Log.w("+=========================================");
|
||||||
|
Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
|
||||||
|
Log.w("+=========================================");
|
||||||
}
|
}
|
||||||
return new NormalItem(shop, shop.getItem());
|
try {
|
||||||
|
constructor = displayItemClass.getConstructor(Location.class, ItemStack.class);
|
||||||
|
} catch (NoSuchMethodException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DisplayItem create(final ContainerShop shop) {
|
||||||
|
if (plugin.getConfigManager().isDisplay()) try {
|
||||||
|
return constructor.newInstance(shop.getLocation(), shop.getItem());
|
||||||
|
} catch (InstantiationException | InvocationTargetException | IllegalAccessException ignored) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
|||||||
* @author 橙子(chengzi)
|
* @author 橙子(chengzi)
|
||||||
* @version 1.0.1
|
* @version 1.0.1
|
||||||
*/
|
*/
|
||||||
public class FakeItem_17_18 extends FakeItem {
|
public class FakeItem_17 extends FakeItem {
|
||||||
|
|
||||||
public FakeItem_17_18(Location loc, final ItemStack item) {
|
public FakeItem_17(Location loc, final ItemStack item) {
|
||||||
super(loc, item);
|
super(loc, item);
|
||||||
}
|
}
|
||||||
|
|
@ -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 {
|
public class NormalItem extends DisplayItem {
|
||||||
private final ItemStack iStack;
|
private final ItemStack iStack;
|
||||||
private Item item;
|
private Item item;
|
||||||
private final Shop shop;
|
private final Location location;
|
||||||
|
|
||||||
// private Location displayLoc;
|
// private Location displayLoc;
|
||||||
/**
|
/**
|
||||||
* Creates a new display item.
|
* Creates a new display item.
|
||||||
*
|
*
|
||||||
* @param shop
|
* @param location
|
||||||
* The shop (See Shop)
|
* The shop (See Shop)
|
||||||
* @param iStack
|
* @param iStack
|
||||||
* The item stack to clone properties of the display item from.
|
* The item stack to clone properties of the display item from.
|
||||||
*/
|
*/
|
||||||
public NormalItem(final Shop shop, final ItemStack iStack) {
|
public NormalItem(final Location location, final ItemStack iStack) {
|
||||||
this.shop = shop;
|
this.location = location;
|
||||||
this.iStack = iStack.clone();
|
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
|
@Override
|
||||||
public Location getDisplayLocation() {
|
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
|
@Override
|
||||||
public boolean removeDupe() {
|
public boolean removeDupe() {
|
||||||
if (shop.getLocation().getWorld() == null) { return false; }
|
if (location.getWorld() == null) { return false; }
|
||||||
final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation();
|
final Location displayLoc = location.getBlock().getRelative(0, 1, 0).getLocation();
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
final Chunk c = displayLoc.getChunk();
|
final Chunk c = displayLoc.getChunk();
|
||||||
for (final Entity e : c.getEntities()) {
|
for (final Entity e : c.getEntities()) {
|
||||||
@ -77,7 +77,7 @@ public class NormalItem extends DisplayItem {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Location eLoc = e.getLocation().getBlock().getLocation();
|
final Location eLoc = e.getLocation().getBlock().getLocation();
|
||||||
if (eLoc.equals(displayLoc) || eLoc.equals(shop.getLocation())) {
|
if (eLoc.equals(displayLoc) || eLoc.equals(location)) {
|
||||||
e.remove();
|
e.remove();
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
@ -99,10 +99,10 @@ public class NormalItem extends DisplayItem {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void spawn() {
|
public void spawn() {
|
||||||
if (shop.getLocation().getWorld() == null) { return; }
|
if (location.getWorld() == null) { return; }
|
||||||
final Location dispLoc = this.getDisplayLocation();
|
final Location dispLoc = this.getDisplayLocation();
|
||||||
try {
|
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));
|
this.item.setVelocity(new Vector(0, 0.1, 0));
|
||||||
NMS.safeGuard(this.item);
|
NMS.safeGuard(this.item);
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
|
@ -16,6 +16,8 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
|||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.material.Sign;
|
import org.bukkit.material.Sign;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
|
|
||||||
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.global.L10N;
|
import pw.yumc.YumCore.global.L10N;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -176,6 +178,7 @@ public class Util {
|
|||||||
* @return the block which is also a chest and connected to b.
|
* @return the block which is also a chest and connected to b.
|
||||||
*/
|
*/
|
||||||
public static Block getSecondHalf(final Block b) {
|
public static Block getSecondHalf(final Block b) {
|
||||||
|
Log.d("%s", b);
|
||||||
if (!b.getType().toString().contains("CHEST")) { return null; }
|
if (!b.getType().toString().contains("CHEST")) { return null; }
|
||||||
final Block[] blocks = new Block[4];
|
final Block[] blocks = new Block[4];
|
||||||
blocks[0] = b.getRelative(1, 0, 0);
|
blocks[0] = b.getRelative(1, 0, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user