TinyProtocol #51
@ -61,6 +61,5 @@ dependencies {
|
|||||||
|
|
||||||
compileOnly files("${projectDir}/../lib/Spigot-1.15.jar")
|
compileOnly files("${projectDir}/../lib/Spigot-1.15.jar")
|
||||||
compileOnly files("${projectDir}/../lib/WorldEdit-1.15.jar")
|
compileOnly files("${projectDir}/../lib/WorldEdit-1.15.jar")
|
||||||
compileOnly files("${projectDir}/../lib/ProtocolLib.jar")
|
|
||||||
compileOnly files("${projectDir}/../lib/SpigotCore.jar")
|
compileOnly files("${projectDir}/../lib/SpigotCore.jar")
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.detonator;
|
package de.steamwar.bausystem.features.detonator;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -49,30 +46,29 @@ import java.util.Set;
|
|||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class DetonatorListener implements Listener {
|
public class DetonatorListener implements Listener {
|
||||||
|
|
||||||
|
public static final Class<?> useEntity = Reflection.getClass("{nms}.PacketPlayInUseEntity");
|
||||||
|
private static final Reflection.FieldAccessor<Integer> entityIdFieldAccessor = Reflection.getField(useEntity, int.class, 0);
|
||||||
|
|
||||||
private static final Set<Player> HAS_UPDATED = new HashSet<>();
|
private static final Set<Player> HAS_UPDATED = new HashSet<>();
|
||||||
|
|
||||||
public DetonatorListener() {
|
public DetonatorListener() {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ENTITY) {
|
ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> {
|
||||||
@Override
|
List<AbstractDetonatorEntity> entities = new ArrayList<>(Detonator.getDetoEntities(player));
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
List<AbstractDetonatorEntity> entities = new ArrayList<>(Detonator.getDetoEntities(event.getPlayer()));
|
|
||||||
if (entities.isEmpty()) {
|
if (entities.isEmpty()) {
|
||||||
return;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer container = event.getPacket();
|
int entityId = entityIdFieldAccessor.get(o);
|
||||||
int entityId = container.getIntegers().read(0);
|
|
||||||
entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId);
|
entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId);
|
||||||
|
|
||||||
if (entities.isEmpty()) {
|
if (entities.isEmpty()) {
|
||||||
return;
|
return o;
|
||||||
}
|
}
|
||||||
AbstractDetonatorEntity entity = entities.get(0);
|
AbstractDetonatorEntity entity = entities.get(0);
|
||||||
Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation();
|
Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation();
|
||||||
addLocationToDetonator(location, event.getPlayer());
|
addLocationToDetonator(location, player);
|
||||||
HAS_UPDATED.add(event.getPlayer());
|
HAS_UPDATED.add(player);
|
||||||
event.setCancelled(true);
|
return null;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.other;
|
package de.steamwar.bausystem.features.other;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
|
||||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
@ -32,6 +29,8 @@ import de.steamwar.bausystem.utils.ProtocolAPI;
|
|||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.minecraft.server.v1_15_R1.EnumGamemode;
|
||||||
|
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
@ -109,9 +108,11 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
Object playerInfoObject = Reflection.newInstance(playerInfo);
|
Object playerInfoObject = Reflection.newInstance(playerInfo);
|
||||||
playerInfoAction.set(playerInfoObject, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE);
|
playerInfoAction.set(playerInfoObject, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE);
|
||||||
List<PlayerInfoData> playerInfoActions = new ArrayList<>();
|
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = (PacketPlayOutPlayerInfo) playerInfoObject;
|
||||||
playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName())));
|
|
||||||
playerInfoDataList.set(playerInfoObject, playerInfoActions);
|
List<PacketPlayOutPlayerInfo.PlayerInfoData> playerInfoData = new ArrayList<>();
|
||||||
|
playerInfoData.add(packetPlayOutPlayerInfo.new PlayerInfoData(new GameProfile(player.getUniqueId(), player.getName()), 1, EnumGamemode.SPECTATOR, IChatBaseComponent.ChatSerializer.b(player.getDisplayName())));
|
||||||
|
playerInfoDataList.set(playerInfoObject, playerInfoData);
|
||||||
|
|
||||||
Object gameStateChangeObject = Reflection.newInstance(gameStateChange);
|
Object gameStateChangeObject = Reflection.newInstance(gameStateChange);
|
||||||
integerFieldAccessor.set(gameStateChangeObject, 3);
|
integerFieldAccessor.set(gameStateChangeObject, 3);
|
||||||
|
@ -81,33 +81,6 @@ public class ProtocolAPI {
|
|||||||
Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet));
|
Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BiFunction<Object, UnaryOperator<Object>, Object> arrayCloneGenerator(Class<?> elementClass) {
|
|
||||||
return (array, worker) -> {
|
|
||||||
int length = Array.getLength(array);
|
|
||||||
Object result = Array.newInstance(elementClass, length);
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
Array.set(result, i, worker.apply(Array.get(array, i)));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UnaryOperator<Object> shallowCloneGenerator(Class<?> clazz) {
|
|
||||||
BiConsumer<Object, Object> filler = shallowFill(clazz);
|
|
||||||
|
|
||||||
return source -> {
|
|
||||||
Object clone;
|
|
||||||
try {
|
|
||||||
clone = clazz.newInstance();
|
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
|
||||||
throw new IllegalStateException("Could not clone " + clazz.getName(), e);
|
|
||||||
}
|
|
||||||
filler.accept(source, clone);
|
|
||||||
return clone;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BiConsumer<Object, Object> shallowFill(Class<?> clazz) {
|
private static BiConsumer<Object, Object> shallowFill(Class<?> clazz) {
|
||||||
if (clazz == null)
|
if (clazz == null)
|
||||||
return (source, clone) -> {
|
return (source, clone) -> {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren