Merge pull request 'TinyProtocol' (#51) from TinyProtocol into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #51 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
1450629e8a
@ -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;
|
||||||
@ -41,7 +38,6 @@ import org.bukkit.event.player.PlayerItemHeldEvent;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -49,30 +45,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 = Detonator.getDetoEntities(player);
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
if (entities.isEmpty()) {
|
||||||
List<AbstractDetonatorEntity> entities = new ArrayList<>(Detonator.getDetoEntities(event.getPlayer()));
|
return o;
|
||||||
if (entities.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketContainer container = event.getPacket();
|
|
||||||
int entityId = container.getIntegers().read(0);
|
|
||||||
entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId);
|
|
||||||
|
|
||||||
if (entities.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AbstractDetonatorEntity entity = entities.get(0);
|
|
||||||
Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation();
|
|
||||||
addLocationToDetonator(location, event.getPlayer());
|
|
||||||
HAS_UPDATED.add(event.getPlayer());
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int entityId = entityIdFieldAccessor.get(o);
|
||||||
|
AbstractDetonatorEntity entity = entities.stream().filter(abstractDetonatorEntity -> abstractDetonatorEntity.getId() == entityId).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (entity == null) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation();
|
||||||
|
addLocationToDetonator(location, player);
|
||||||
|
HAS_UPDATED.add(player);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,23 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.other;
|
package de.steamwar.bausystem.features.other;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
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 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;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
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;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -46,42 +40,64 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
import java.util.function.BiFunction;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@Linked(LinkageType.COMMAND)
|
@Linked(LinkageType.COMMAND)
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class NoClipCommand extends SWCommand implements Listener {
|
public class NoClipCommand extends SWCommand implements Listener {
|
||||||
|
|
||||||
|
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo");
|
||||||
|
private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket);
|
||||||
|
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
|
||||||
|
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
|
||||||
|
private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1];
|
||||||
|
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
|
||||||
|
private static final Class<?> playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData");
|
||||||
|
private static final Class<?> enumGamemode = Reflection.getClass("{nms}.EnumGamemode");
|
||||||
|
private static final Object spectator = enumGamemode.getEnumConstants()[4];
|
||||||
|
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent");
|
||||||
|
|
||||||
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
|
||||||
|
|
||||||
|
private static final Class<?> gameStateChange = Reflection.getClass("{nms}.PacketPlayOutGameStateChange");
|
||||||
|
private static final Reflection.FieldAccessor<Integer> integerFieldAccessor = Reflection.getField(gameStateChange, int.class, 0);
|
||||||
|
private static final Reflection.FieldAccessor<Float> floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0);
|
||||||
|
|
||||||
|
private static final Class<?> position = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPosition");
|
||||||
|
private static final Class<?> positionLook = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPositionLook");
|
||||||
|
private static final Class<?> useItem = Reflection.getClass("{nms}.PacketPlayInUseItem");
|
||||||
|
private static final Class<?> blockDig = Reflection.getClass("{nms}.PacketPlayInBlockDig");
|
||||||
|
private static final Class<?> windowClick = Reflection.getClass("{nms}.PacketPlayInWindowClick");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final List<Player> NOCLIPS = new ArrayList<>();
|
private static final List<Player> NOCLIPS = new ArrayList<>();
|
||||||
private static final Map<Player, Long> LAST_TICKS = new HashMap<>();
|
private static final Map<Player, Long> LAST_TICKS = new HashMap<>();
|
||||||
|
|
||||||
protected NoClipCommand() {
|
protected NoClipCommand() {
|
||||||
super("noclip", "nc");
|
super("noclip", "nc");
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK) {
|
|
||||||
@Override
|
BiFunction<Player, Object, Object> first = (player, o) -> {
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
if (NOCLIPS.contains(player)) {
|
||||||
if (NOCLIPS.contains(event.getPlayer())) {
|
if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o;
|
||||||
if (LAST_TICKS.getOrDefault(event.getPlayer(), -1L).equals(TPSUtils.currentTick.get())) return;
|
VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.SPECTATOR), 15));
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.SPECTATOR), 15));
|
LAST_TICKS.put(player, TPSUtils.currentTick.get());
|
||||||
LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
return o;
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK) {
|
};
|
||||||
@Override
|
ProtocolAPI.setIncomingHandler(position, first);
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
ProtocolAPI.setIncomingHandler(positionLook, first);
|
||||||
if (NOCLIPS.contains(event.getPlayer())) {
|
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.CREATIVE), 15));
|
BiFunction<Player, Object, Object> second = (player, o) -> {
|
||||||
LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get());
|
if (NOCLIPS.contains(player)) {
|
||||||
}
|
VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.CREATIVE), 15));
|
||||||
|
LAST_TICKS.put(player, TPSUtils.currentTick.get());
|
||||||
}
|
}
|
||||||
});
|
return o;
|
||||||
|
};
|
||||||
|
ProtocolAPI.setIncomingHandler(useItem, second);
|
||||||
|
ProtocolAPI.setIncomingHandler(blockDig, second);
|
||||||
|
ProtocolAPI.setIncomingHandler(windowClick, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(help = true)
|
@Register(help = true)
|
||||||
@ -93,23 +109,15 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
((CraftPlayer) player).getHandle().abilities.mayBuild = true;
|
((CraftPlayer) player).getHandle().abilities.mayBuild = true;
|
||||||
((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true;
|
((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true;
|
||||||
PacketContainer gm3packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
|
||||||
gm3packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
|
Object gameStateChangeObject = Reflection.newInstance(gameStateChange);
|
||||||
List<PlayerInfoData> playerInfoActions = new ArrayList<>();
|
integerFieldAccessor.set(gameStateChangeObject, 3);
|
||||||
playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName())));
|
floatFieldAccessor.set(gameStateChangeObject, 1F);
|
||||||
gm3packet.getPlayerInfoDataLists().write(0, playerInfoActions);
|
|
||||||
PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE);
|
|
||||||
gm1packet.getIntegers().write(0, 3);
|
|
||||||
gm1packet.getFloat().write(0, 1F);
|
|
||||||
NOCLIPS.add(player);
|
NOCLIPS.add(player);
|
||||||
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
||||||
try {
|
ProtocolAPI.tinyProtocol.sendPacket(player, gameStateChangeObject);
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet);
|
pseudoSpectator(player);
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
|
||||||
player.performCommand("noclip");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,4 +153,15 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void pseudoSpectator(Player player) {
|
||||||
|
ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), spectator));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
|
||||||
|
Object packet = playerInfoConstructor.invoke();
|
||||||
|
playerInfoAction.set(packet, action);
|
||||||
|
playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null)));
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,17 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.world;
|
package de.steamwar.bausystem.features.world;
|
||||||
|
|
||||||
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 com.comphenix.protocol.wrappers.BlockPosition;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
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 net.minecraft.server.v1_15_R1.BlockPosition;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@ -38,13 +36,18 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class SignEdit implements Listener {
|
public class SignEdit implements Listener {
|
||||||
|
|
||||||
|
public static final Class<?> openSign = Reflection.getClass("{nms}.PacketPlayOutOpenSignEditor");
|
||||||
|
private static final Reflection.FieldAccessor<net.minecraft.server.v1_15_R1.BlockPosition> blockPositionFieldAccessor = Reflection.getField(openSign, net.minecraft.server.v1_15_R1.BlockPosition.class, 0);
|
||||||
|
|
||||||
|
public static final Class<?> updateSign = Reflection.getClass("{nms}.PacketPlayInUpdateSign");
|
||||||
|
private static final Reflection.FieldAccessor<BlockPosition> getBlockPositionFieldAccessor = Reflection.getField(updateSign, BlockPosition.class, 0);
|
||||||
|
private static final Reflection.FieldAccessor<String[]> stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0);
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void editSign(PlayerInteractEvent event) {
|
public void editSign(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
||||||
@ -62,38 +65,29 @@ public class SignEdit implements Listener {
|
|||||||
}
|
}
|
||||||
sign.update();
|
sign.update();
|
||||||
|
|
||||||
PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
|
Object openSignObject = Reflection.newInstance(openSign);
|
||||||
signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector()));
|
Vector vector = event.getClickedBlock().getLocation().toVector();
|
||||||
try {
|
blockPositionFieldAccessor.set(openSignObject, new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()));
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen);
|
ProtocolAPI.tinyProtocol.sendPacket(player, openSignObject);
|
||||||
} catch (InvocationTargetException e) {
|
}
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.UPDATE_SIGN) {
|
{
|
||||||
@Override
|
ProtocolAPI.setIncomingHandler(updateSign, (player, o) -> {
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
||||||
if (!event.getPlayer().equals(player))
|
BlockPosition position = getBlockPositionFieldAccessor.get(o);
|
||||||
|
String[] lines = stringFieldAccessor.get(o);
|
||||||
|
|
||||||
|
Block signLoc = new Location(player.getWorld(), position.getX(), position.getY(), position.getZ()).getBlock();
|
||||||
|
if (!signLoc.getType().name().contains("SIGN"))
|
||||||
return;
|
return;
|
||||||
event.setCancelled(true);
|
|
||||||
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
|
||||||
PacketContainer packetContainer = event.getPacket();
|
|
||||||
BlockPosition position = packetContainer.getBlockPositionModifier().read(0);
|
|
||||||
String[] lines = packetContainer.getStringArrays().read(0);
|
|
||||||
|
|
||||||
Block signLoc = position.toLocation(player.getWorld()).getBlock();
|
org.bukkit.block.Sign sign = ((Sign) signLoc.getState());
|
||||||
if (!signLoc.getType().name().contains("SIGN"))
|
for (int i = 0; i < lines.length; i++) {
|
||||||
return;
|
sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i]));
|
||||||
|
}
|
||||||
org.bukkit.block.Sign sign = ((Sign) signLoc.getState());
|
sign.update();
|
||||||
for (int i = 0; i < lines.length; i++) {
|
});
|
||||||
sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i]));
|
return o;
|
||||||
}
|
|
||||||
sign.update();
|
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
76
BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java
Normale Datei
76
BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java
Normale Datei
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class ProtocolAPI {
|
||||||
|
|
||||||
|
private static final Map<Class<?>, BiFunction<Player, Object, Object>> outgoingHandler = new HashMap<>();
|
||||||
|
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
|
||||||
|
|
||||||
|
public static final TinyProtocol tinyProtocol = new TinyProtocol(BauSystem.getInstance()) {
|
||||||
|
@Override
|
||||||
|
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
||||||
|
BiFunction<Player, Object, Object> handler = outgoingHandler.get(packet.getClass());
|
||||||
|
if (handler == null)
|
||||||
|
return packet;
|
||||||
|
return handler.apply(receiver, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
||||||
|
BiFunction<Player, Object, Object> handler = incomingHandler.get(packet.getClass());
|
||||||
|
if (handler == null)
|
||||||
|
return packet;
|
||||||
|
return handler.apply(sender, packet);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||||
|
outgoingHandler.put(packetClass, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeOutgoingHandler(Class<?> packetClass) {
|
||||||
|
outgoingHandler.remove(packetClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setIncomingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||||
|
incomingHandler.put(packetClass, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeIncomingHandler(Class<?> packetClass) {
|
||||||
|
incomingHandler.remove(packetClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastPacket(Object packet) {
|
||||||
|
Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet));
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
name: BauSystem
|
name: BauSystem
|
||||||
authors: [Lixfel, YoyoNow, Chaoscaot, Zeanon]
|
authors: [Lixfel, YoyoNow, Chaoscaot, Zeanon]
|
||||||
version: "2.0"
|
version: "2.0"
|
||||||
depend: [WorldEdit, SpigotCore, ProtocolLib]
|
depend: [WorldEdit, SpigotCore]
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
main: de.steamwar.bausystem.BauSystem
|
main: de.steamwar.bausystem.BauSystem
|
||||||
api-version: "1.13"
|
api-version: "1.13"
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren