Merge pull request 'Update TinyProtocol API' (#127) from updateTinyApi into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #127 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
5a32b90499
@ -20,13 +20,13 @@
|
||||
package de.steamwar.bausystem.features.detonator;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage;
|
||||
import de.steamwar.bausystem.features.detonator.storage.ItemStorage;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -51,7 +51,7 @@ public class DetonatorListener implements Listener {
|
||||
private static final Set<Player> HAS_UPDATED = new HashSet<>();
|
||||
|
||||
public DetonatorListener() {
|
||||
ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> {
|
||||
TinyProtocol.instance.addFilter(useEntity, (player, o) -> {
|
||||
List<AbstractDetonatorEntity> entities = Detonator.getDetoEntities(player);
|
||||
if (entities.isEmpty()) {
|
||||
return o;
|
||||
|
@ -20,10 +20,10 @@
|
||||
package de.steamwar.bausystem.features.tpslimit;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -105,7 +105,7 @@ public class TPSLimitUtils {
|
||||
}
|
||||
return o;
|
||||
};
|
||||
ProtocolAPI.setIncomingHandler(position, positionSetter);
|
||||
ProtocolAPI.setIncomingHandler(positionLook, positionSetter);
|
||||
TinyProtocol.instance.addFilter(position, positionSetter);
|
||||
TinyProtocol.instance.addFilter(positionLook, positionSetter);
|
||||
}
|
||||
}
|
@ -20,11 +20,11 @@
|
||||
package de.steamwar.bausystem.features.tracer;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.tracer.show.TraceShowManager;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -41,7 +41,7 @@ public class TraceTNTClickListener {
|
||||
{
|
||||
Set<Player> playerSet = new HashSet<>();
|
||||
|
||||
ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> {
|
||||
TinyProtocol.instance.addFilter(useEntity, (player, o) -> {
|
||||
if (!playerSet.add(player)) return o;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
RayTraceResult rayTraceResult = RayTraceUtils.trace(player, player.getLocation(), TraceShowManager.getEntities(player));
|
||||
|
@ -27,7 +27,6 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import de.steamwar.bausystem.utils.ProtocolWrapper;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.Core;
|
||||
@ -84,8 +83,8 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
}
|
||||
return o;
|
||||
};
|
||||
ProtocolAPI.setIncomingHandler(position, first);
|
||||
ProtocolAPI.setIncomingHandler(positionLook, first);
|
||||
TinyProtocol.instance.addFilter(position, first);
|
||||
TinyProtocol.instance.addFilter(positionLook, first);
|
||||
|
||||
BiFunction<Player, Object, Object> second = (player, o) -> {
|
||||
if (NOCLIPS.contains(player)) {
|
||||
@ -94,9 +93,9 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
}
|
||||
return o;
|
||||
};
|
||||
ProtocolAPI.setIncomingHandler(useItem, second);
|
||||
ProtocolAPI.setIncomingHandler(blockDig, second);
|
||||
ProtocolAPI.setIncomingHandler(windowClick, second);
|
||||
TinyProtocol.instance.addFilter(useItem, second);
|
||||
TinyProtocol.instance.addFilter(blockDig, second);
|
||||
TinyProtocol.instance.addFilter(windowClick, second);
|
||||
|
||||
BiFunction<Player, Object, Object> third = (player, o) -> {
|
||||
if (NOCLIPS.contains(player)) {
|
||||
@ -104,7 +103,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
||||
}
|
||||
return o;
|
||||
};
|
||||
ProtocolAPI.setIncomingHandler(setSlotStack, third);
|
||||
TinyProtocol.instance.addFilter(setSlotStack, third);
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
|
@ -20,26 +20,19 @@
|
||||
package de.steamwar.bausystem.features.world;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Linked(LinkageType.PLAIN)
|
||||
public class NoCreativeKnockback {
|
||||
|
||||
private Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
||||
|
||||
{
|
||||
BiFunction<Player, Object, Object> knockbackResetter = (player, o) -> {
|
||||
public NoCreativeKnockback() {
|
||||
TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"), (player, o) -> {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) return o;
|
||||
return NMSWrapper.impl.resetExplosionKnockback(o);
|
||||
};
|
||||
|
||||
ProtocolAPI.setOutgoingHandler(explosionPacket, knockbackResetter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -34,7 +33,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
@Linked(LinkageType.LISTENER)
|
||||
@ -85,7 +83,7 @@ public class SignEdit implements Listener {
|
||||
}
|
||||
|
||||
{
|
||||
ProtocolAPI.setIncomingHandler(updateSign, (player, o) -> {
|
||||
TinyProtocol.instance.addFilter(updateSign, (player, o) -> {
|
||||
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
||||
String[] lines = stringFieldAccessor.get(o);
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.xray;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
@ -27,7 +28,6 @@ import de.steamwar.bausystem.linkage.Linked;
|
||||
import de.steamwar.bausystem.linkage.LinkedInstance;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
|
||||
import de.steamwar.bausystem.utils.ProtocolAPI;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import de.steamwar.techhider.TechHider;
|
||||
@ -123,8 +123,8 @@ public class XrayCommand extends SWCommand implements Listener {
|
||||
return o;
|
||||
};
|
||||
|
||||
ProtocolAPI.setIncomingHandler(position, positionSetter);
|
||||
ProtocolAPI.setIncomingHandler(positionLook, positionSetter);
|
||||
TinyProtocol.instance.addFilter(position, positionSetter);
|
||||
TinyProtocol.instance.addFilter(positionLook, positionSetter);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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 lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@UtilityClass
|
||||
public class ProtocolAPI {
|
||||
|
||||
private static final Map<Class<?>, Set<BiFunction<Player, Object, Object>>> outgoingHandler = new HashMap<>();
|
||||
private static final Map<Class<?>, Set<BiFunction<Player, Object, Object>>> incomingHandler = new HashMap<>();
|
||||
|
||||
static {
|
||||
TinyProtocol.instance.setOutFilter((receiver, channel, packet) -> {
|
||||
Set<BiFunction<Player, Object, Object>> handler = outgoingHandler.get(packet.getClass());
|
||||
if (handler == null || handler.isEmpty())
|
||||
return packet;
|
||||
for (BiFunction<Player, Object, Object> function : handler) {
|
||||
packet = function.apply(receiver, packet);
|
||||
if (packet == null) return null;
|
||||
}
|
||||
return packet;
|
||||
});
|
||||
TinyProtocol.instance.setInFilter((sender, channel, packet) -> {
|
||||
Set<BiFunction<Player, Object, Object>> handler = incomingHandler.get(packet.getClass());
|
||||
if (handler == null || handler.isEmpty())
|
||||
return packet;
|
||||
for (BiFunction<Player, Object, Object> function : handler) {
|
||||
packet = function.apply(sender, packet);
|
||||
if (packet == null) return null;
|
||||
}
|
||||
return packet;
|
||||
});
|
||||
}
|
||||
|
||||
public static void setOutgoingHandler
|
||||
(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||
outgoingHandler.computeIfAbsent(packetClass, i -> new HashSet<>()).add(handler);
|
||||
}
|
||||
|
||||
public static void setIncomingHandler
|
||||
(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||
incomingHandler.computeIfAbsent(packetClass, i -> new HashSet<>()).add(handler);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren