SteamWar/SpigotCore
Archiviert
13
0

Fix REntity Metadata
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-03-03 17:31:35 +01:00
Ursprung 8982c0af29
Commit 413abd5f66
5 geänderte Dateien mit 41 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,10 @@ package de.steamwar.core;
import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.IChatMutableComponent;
import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
import net.minecraft.network.syncher.DataWatcher;
import java.util.ArrayList;
public class ChatWrapper19 implements ChatWrapper { public class ChatWrapper19 implements ChatWrapper {
@ -28,4 +32,14 @@ public class ChatWrapper19 implements ChatWrapper {
public Object stringToChatComponent(String text) { public Object stringToChatComponent(String text) {
return IChatMutableComponent.a(new LiteralContents(text)); return IChatMutableComponent.a(new LiteralContents(text));
} }
@Override
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
ArrayList<DataWatcher.b<?>> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add((DataWatcher.b<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1]));
}
return new PacketPlayOutEntityMetadata(entityId, nativeWatchers);
}
} }

Datei anzeigen

@ -21,6 +21,9 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import java.util.ArrayList;
import java.util.List;
public class ChatWrapper8 implements ChatWrapper { public class ChatWrapper8 implements ChatWrapper {
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
@ -28,4 +31,20 @@ public class ChatWrapper8 implements ChatWrapper {
public Object stringToChatComponent(String text) { public Object stringToChatComponent(String text) {
return chatComponentConstructor.invoke(text); return chatComponentConstructor.invoke(text);
} }
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
@Override
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
Object packet = Reflection.newInstance(metadataPacket);
metadataEntity.set(packet, entityId);
ArrayList<Object> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add(BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1]));
}
metadataMetadata.set(packet, nativeWatchers);
return packet;
}
} }

Datei anzeigen

@ -63,7 +63,6 @@ public final class Reflection {
* @param value - the new value of the field. * @param value - the new value of the field.
*/ */
void set(Object target, Object value); void set(Object target, Object value);
void setInt(Object target, int value);
/** /**
* Determine if the given object has this field. * Determine if the given object has this field.
@ -163,15 +162,6 @@ public final class Reflection {
} }
} }
@Override
public void setInt(Object target, int value) {
try {
field.setInt(target, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Cannot access reflection.", e);
}
}
@Override @Override
public boolean hasField(Object target) { public boolean hasField(Object target) {
// target instanceof DeclaringClass // target instanceof DeclaringClass

Datei anzeigen

@ -19,8 +19,14 @@
package de.steamwar.core; package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
public interface ChatWrapper { public interface ChatWrapper {
ChatWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); ChatWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
Object stringToChatComponent(String text); Object stringToChatComponent(String text);
Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues);
} }

Datei anzeigen

@ -20,10 +20,7 @@
package de.steamwar.entity; package de.steamwar.entity;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.*;
import de.steamwar.core.Core;
import de.steamwar.core.FlatteningWrapper;
import de.steamwar.core.ProtocolWrapper;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter; import lombok.Getter;
@ -349,21 +346,8 @@ public class REntity {
return status; return status;
} }
private static final Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) { protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) {
Object packet = Reflection.newInstance(metadataPacket); return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues);
metadataEntity.setInt(packet, entityId);
ArrayList<Object> nativeWatchers = new ArrayList<>(1);
for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
nativeWatchers.add(BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1]));
}
metadataMetadata.set(packet, nativeWatchers);
return packet;
} }
private static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); private static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");