Change falling block to store the combined block id to fix older versions with blockdata
This commit is contained in:
parent
c3783b9bf0
commit
1e68eeb74d
@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType;
|
|||||||
import com.comphenix.protocol.ProtocolLibrary;
|
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.reflect.StructureModifier;
|
||||||
|
import lombok.Getter;
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
@ -21,8 +22,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public class FallingBlockWatcher extends FlagWatcher {
|
public class FallingBlockWatcher extends FlagWatcher {
|
||||||
private ItemStack block = new ItemStack(Material.STONE);
|
private int blockCombinedId = 1;
|
||||||
private BlockData blockData;
|
|
||||||
private boolean gridLocked;
|
private boolean gridLocked;
|
||||||
|
|
||||||
public FallingBlockWatcher(Disguise disguise) {
|
public FallingBlockWatcher(Disguise disguise) {
|
||||||
@ -60,8 +60,7 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
relMove.getModifier().write(0, getDisguise().getEntity().getEntityId());
|
relMove.getModifier().write(0, getDisguise().getEntity().getEntityId());
|
||||||
shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5));
|
shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5));
|
||||||
shorts.write(1, conRel(loc.getY(),
|
shorts.write(1, conRel(loc.getY(), loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
|
||||||
loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0)));
|
|
||||||
shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5));
|
shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -86,7 +85,7 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getBlock() {
|
public ItemStack getBlock() {
|
||||||
return block;
|
return ReflectionManager.getItemStackByCombinedId(getBlockCombinedId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlock(ItemStack block) {
|
public void setBlock(ItemStack block) {
|
||||||
@ -94,12 +93,11 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
block = new ItemStack(Material.STONE);
|
block = new ItemStack(Material.STONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.block = block;
|
this.blockCombinedId = ReflectionManager.getCombinedIdByItemStack(block);
|
||||||
|
|
||||||
if (!getDisguise().isCustomDisguiseName()) {
|
if (!getDisguise().isCustomDisguiseName()) {
|
||||||
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
||||||
TranslateType.DISGUISE_OPTIONS_PARAMETERS
|
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager.toReadable(block.getType().name(), " ")));
|
||||||
.get(ReflectionManager.toReadable(block.getType().name(), " ")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||||
@ -109,11 +107,7 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
@NmsAddedIn(NmsVersion.v1_13)
|
@NmsAddedIn(NmsVersion.v1_13)
|
||||||
public BlockData getBlockData() {
|
public BlockData getBlockData() {
|
||||||
if (block != null && blockData == null) {
|
return ReflectionManager.getBlockDataByCombinedId(getBlockCombinedId());
|
||||||
return block.getType().createBlockData();
|
|
||||||
}
|
|
||||||
|
|
||||||
return blockData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NmsAddedIn(NmsVersion.v1_13)
|
@NmsAddedIn(NmsVersion.v1_13)
|
||||||
@ -123,17 +117,23 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.block = new ItemStack(data.getMaterial());
|
this.blockCombinedId = ReflectionManager.getCombinedIdByBlockData(data);
|
||||||
this.blockData = data;
|
|
||||||
|
|
||||||
if (!getDisguise().isCustomDisguiseName()) {
|
if (!getDisguise().isCustomDisguiseName()) {
|
||||||
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
|
||||||
TranslateType.DISGUISE_OPTIONS_PARAMETERS
|
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager.toReadable(data.getMaterial().name(), " ")));
|
||||||
.get(ReflectionManager.toReadable(block.getType().name(), " ")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||||
DisguiseUtilities.refreshTrackers(getDisguise());
|
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBlockCombinedId() {
|
||||||
|
if (blockCombinedId < 1) {
|
||||||
|
blockCombinedId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return blockCombinedId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,14 +292,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
|||||||
double z = loc.getZ();
|
double z = loc.getZ();
|
||||||
|
|
||||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||||
if (NmsVersion.v1_13.isSupported()) {
|
data = ((FallingBlockWatcher) disguise.getWatcher()).getBlockCombinedId();
|
||||||
BlockData block = ((FallingBlockWatcher) disguise.getWatcher()).getBlockData();
|
|
||||||
|
|
||||||
data = ReflectionManager.getCombinedIdByBlockData(block);
|
|
||||||
} else {
|
|
||||||
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
|
|
||||||
data = ReflectionManager.getCombinedIdByItemStack(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
||||||
double yMod = disguise.getWatcher().getYModifier();
|
double yMod = disguise.getWatcher().getYModifier();
|
||||||
|
@ -26,6 +26,7 @@ import org.bukkit.entity.*;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.plugin.SimplePluginManager;
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -94,6 +95,7 @@ public class ReflectionManager {
|
|||||||
private static Method craftBlockDataGetState;
|
private static Method craftBlockDataGetState;
|
||||||
private static Method getOldItemAsBlock;
|
private static Method getOldItemAsBlock;
|
||||||
private static Method magicGetBlock;
|
private static Method magicGetBlock;
|
||||||
|
private static Method magicGetMaterial;
|
||||||
private static Method getNmsItem;
|
private static Method getNmsItem;
|
||||||
private static Method getBlockData;
|
private static Method getBlockData;
|
||||||
private static Method getBlockDataAsId;
|
private static Method getBlockDataAsId;
|
||||||
@ -160,6 +162,7 @@ public class ReflectionManager {
|
|||||||
if (NmsVersion.v1_13.isSupported()) {
|
if (NmsVersion.v1_13.isSupported()) {
|
||||||
craftBlockDataGetState = getCraftMethod("block.data.CraftBlockData", "getState");
|
craftBlockDataGetState = getCraftMethod("block.data.CraftBlockData", "getState");
|
||||||
magicGetBlock = getCraftMethod("util.CraftMagicNumbers", "getBlock", Material.class);
|
magicGetBlock = getCraftMethod("util.CraftMagicNumbers", "getBlock", Material.class);
|
||||||
|
magicGetMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Block"));
|
||||||
entityTypesAMethod = getNmsMethod("EntityTypes", "a", String.class);
|
entityTypesAMethod = getNmsMethod("EntityTypes", "a", String.class);
|
||||||
|
|
||||||
if (NmsVersion.v1_14.isSupported()) {
|
if (NmsVersion.v1_14.isSupported()) {
|
||||||
@ -1566,12 +1569,17 @@ public class ReflectionManager {
|
|||||||
try {
|
try {
|
||||||
Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class);
|
Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class);
|
||||||
Object iBlockData = idMethod.invoke(null, id);
|
Object iBlockData = idMethod.invoke(null, id);
|
||||||
|
|
||||||
Class iBlockClass = getNmsClass("IBlockData");
|
Class iBlockClass = getNmsClass("IBlockData");
|
||||||
|
|
||||||
Method getBlock = getNmsMethod(iBlockClass, "getBlock");
|
Method getBlock = getNmsMethod(NmsVersion.v1_16.isSupported() ? iBlockClass.getSuperclass() : iBlockClass, "getBlock");
|
||||||
Object block = getBlock.invoke(iBlockData);
|
Object block = getBlock.invoke(iBlockData);
|
||||||
|
|
||||||
Method getItem = getNmsMethod("Block", "t", iBlockClass);
|
if (NmsVersion.v1_13.isSupported()) {
|
||||||
|
return new ItemStack((Material) magicGetMaterial.invoke(null, block));
|
||||||
|
}
|
||||||
|
|
||||||
|
Method getItem = getNmsMethod("Block", "u", iBlockClass);
|
||||||
|
|
||||||
return getBukkitItem(getItem.invoke(block, iBlockData));
|
return getBukkitItem(getItem.invoke(block, iBlockData));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user