1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-22 01:58:54 +00:00

feat: 调整虚拟悬浮物

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-03-17 17:40:09 +08:00
parent 36dd2ac988
commit ec2498fc48
3 changed files with 32 additions and 41 deletions

View File

@ -46,23 +46,20 @@ public abstract class FakeItem extends DisplayItem {
this.eid = getFakeEntityId(); this.eid = getFakeEntityId();
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
} }
public static boolean isRegistered() { public static boolean isRegistered() {
return registered; return registered;
} }
public static void register(final Plugin plugin) { public static void register(final Plugin plugin) {
if (registered) { if (registered) { return; }
return;
}
final PluginManager pm = Bukkit.getPluginManager(); final PluginManager pm = Bukkit.getPluginManager();
final Plugin p = pm.getPlugin("ProtocolLib"); final Plugin p = pm.getPlugin("ProtocolLib");
if (p != null) { if (p != null) {
if (!p.isEnabled()) { if (!p.isEnabled()) {
pm.enablePlugin(p); pm.enablePlugin(p);
} }
if (!p.isEnabled()) { if (!p.isEnabled()) { throw new IllegalStateException("前置插件ProtocolLib启动失败 请检查版本."); }
throw new IllegalStateException("前置插件ProtocolLib启动失败 请检查版本.");
}
} else { } else {
throw new IllegalStateException("服务器未找到前置插件ProtocolLib."); throw new IllegalStateException("服务器未找到前置插件ProtocolLib.");
} }
@ -154,12 +151,8 @@ public abstract class FakeItem extends DisplayItem {
} }
private void create() { private void create() {
if (!registered) { if (!registered) { throw new IllegalStateException("You have to call the register method first."); }
throw new IllegalStateException("You have to call the register method first."); if (created) { return; }
}
if (created) {
return;
}
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnPacket()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnPacket());
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getVelocityPacket()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getVelocityPacket());
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getMetadataPacket()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getMetadataPacket());
@ -175,9 +168,7 @@ public abstract class FakeItem extends DisplayItem {
} }
private void destory() { private void destory() {
if (!created) { if (!created) { return; }
return;
}
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDestoryPacket()); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDestoryPacket());
final String chunkId = getChunkIdentifyString(location.getChunk()); final String chunkId = getChunkIdentifyString(location.getChunk());
@ -204,8 +195,15 @@ public abstract class FakeItem extends DisplayItem {
return fakePacket; return fakePacket;
} }
protected abstract PacketContainer getMetadataPacket(); protected PacketContainer getMetadataPacket() {
return setMetadataPacket(ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA));
}
protected abstract PacketContainer getSpawnPacket(); protected abstract PacketContainer setMetadataPacket(PacketContainer fakePacket);
protected PacketContainer getSpawnPacket() {
return setSpawnPacket(ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY));
}
protected abstract PacketContainer setSpawnPacket(PacketContainer fakePacket);
} }

View File

@ -6,9 +6,8 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
/** /**
@ -29,8 +28,7 @@ public class FakeItem_17_18 extends FakeItem {
} }
@Override @Override
protected PacketContainer getMetadataPacket() { protected PacketContainer setMetadataPacket(PacketContainer fakePacket) {
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
fakePacket.getIntegers().write(0, eid); fakePacket.getIntegers().write(0, eid);
final WrappedWatchableObject itemMeta = new WrappedWatchableObject(10, itemStack); final WrappedWatchableObject itemMeta = new WrappedWatchableObject(10, itemStack);
final List<WrappedWatchableObject> entityMetaList = new ArrayList<>(1); final List<WrappedWatchableObject> entityMetaList = new ArrayList<>(1);
@ -40,14 +38,12 @@ public class FakeItem_17_18 extends FakeItem {
} }
@Override @Override
protected PacketContainer getSpawnPacket() { protected PacketContainer setSpawnPacket(PacketContainer fakePacket) {
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY); StructureModifier<Integer> is = fakePacket.getIntegers();
fakePacket.getIntegers().write(0, eid); is.write(0, eid);
fakePacket.getIntegers().write(1, getNormalizedDistance(location.getX())); is.write(1, getNormalizedDistance(location.getX()));
fakePacket.getIntegers().write(2, getNormalizedDistance(location.getY())); is.write(2, getNormalizedDistance(location.getY()));
fakePacket.getIntegers().write(3, getNormalizedDistance(location.getZ())); is.write(3, getNormalizedDistance(location.getZ()));
fakePacket.getIntegers().write(9, 2);
return fakePacket; return fakePacket;
} }
} }

View File

@ -3,9 +3,8 @@ package org.maxgamer.QuickShop.Shop.Item;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
@ -25,8 +24,7 @@ public class FakeItem_19_111 extends FakeItem {
} }
@Override @Override
protected PacketContainer getMetadataPacket() { protected PacketContainer setMetadataPacket(PacketContainer fakePacket) {
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
fakePacket.getIntegers().write(0, eid); fakePacket.getIntegers().write(0, eid);
final WrappedDataWatcher wr = new WrappedDataWatcher(); final WrappedDataWatcher wr = new WrappedDataWatcher();
final Serializer serializer = WrappedDataWatcher.Registry.getItemStackSerializer(true); final Serializer serializer = WrappedDataWatcher.Registry.getItemStackSerializer(true);
@ -37,14 +35,13 @@ public class FakeItem_19_111 extends FakeItem {
} }
@Override @Override
protected PacketContainer getSpawnPacket() { protected PacketContainer setSpawnPacket(PacketContainer fakePacket) {
final PacketContainer fakePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY); StructureModifier<Object> mdf = fakePacket.getModifier();
fakePacket.getIntegers().write(0, eid); mdf.write(0, eid);
fakePacket.getModifier().write(1, uuid); mdf.write(1, uuid);
fakePacket.getDoubles().write(0, location.getX()); mdf.write(2, location.getX());
fakePacket.getDoubles().write(1, location.getY()); mdf.write(3, location.getY());
fakePacket.getDoubles().write(2, location.getZ()); mdf.write(4, location.getZ());
fakePacket.getIntegers().write(6, 2);
return fakePacket; return fakePacket;
} }
} }