Techhider (except for Full chunks)
Dieser Commit ist enthalten in:
Ursprung
579d5bebf7
Commit
4ba8e49735
@ -51,6 +51,8 @@ Money:
|
||||
Kits:
|
||||
MemberDefault: default
|
||||
LeaderDefault: default
|
||||
Techhider:
|
||||
ObfuscateWith: 1
|
||||
HiddenBlocks:
|
||||
- 7
|
||||
- 8
|
||||
|
@ -16,9 +16,9 @@ public class BlockPlaceListener implements Listener {
|
||||
|
||||
if(Fight.getPlayerTeam(player) == null)
|
||||
event.setCancelled(true);
|
||||
else if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) {
|
||||
else if(FightSystem.getFightState() != FightState.RUNNING) {
|
||||
event.setCancelled(true);
|
||||
if(FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) {
|
||||
if(FightSystem.getFightState() == FightState.PRE_RUNNING || FightSystem.getFightState() == FightState.SETUP) {
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!");
|
||||
} else
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!");
|
||||
|
@ -81,6 +81,7 @@ public class Config {
|
||||
|
||||
public static List<Integer> HiddenBlocks;
|
||||
public static List<String> HiddenBlockEntities;
|
||||
public static int ObfuscateWith;
|
||||
|
||||
public static void load(){
|
||||
if(!new File("plugins/" + FightSystem.getPlugin().getName() + "/config.yml").exists()) {
|
||||
@ -139,8 +140,9 @@ public class Config {
|
||||
MemberDefault = config.getString("Kits.MemberDefault");
|
||||
LeaderDefault = config.getString("Kits.LeaderDefault");
|
||||
|
||||
HiddenBlocks = config.getIntegerList("HiddenBlocks");
|
||||
HiddenBlockEntities = config.getStringList("HiddenBlockEntities");
|
||||
HiddenBlocks = config.getIntegerList("Techhider.HiddenBlocks");
|
||||
HiddenBlockEntities = config.getStringList("Techhider.HiddenBlockEntities");
|
||||
ObfuscateWith = config.getInt("Techhider.ObfuscateWith");
|
||||
|
||||
if(SchemsizeX < 0){
|
||||
SchemsizeX = -SchemsizeX;
|
||||
|
@ -6,12 +6,17 @@ import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
||||
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import me.yaruma.fightsystem.FightSystem;
|
||||
import me.yaruma.fightsystem.fight.Fight;
|
||||
import me.yaruma.fightsystem.fight.FightTeam;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -20,14 +25,45 @@ import java.util.List;
|
||||
|
||||
public class TechHider {
|
||||
|
||||
private static int arenaMinX;
|
||||
private static int arenaMaxX;
|
||||
private static int arenaMinZ;
|
||||
private static int arenaMaxZ;
|
||||
private static int blueMinX;
|
||||
private static int blueMaxX;
|
||||
private static int blueMinZ;
|
||||
private static int blueMaxZ;
|
||||
private static int redMinX;
|
||||
private static int redMaxX;
|
||||
private static int redMinZ;
|
||||
private static int redMaxZ;
|
||||
private static int obfuscateShift4;
|
||||
private static Material obfuscateMaterial;
|
||||
|
||||
public static void init(){
|
||||
arenaMinX = Config.ArenaMinX / 16 - (Config.ArenaMinX % 16 < 0 ? 1 : 0);
|
||||
arenaMinZ = Config.ArenaMinZ / 16 - (Config.ArenaMinZ % 16 < 0 ? 1 : 0);
|
||||
arenaMaxX = Config.ArenaMaxX / 16 + (Config.ArenaMaxX % 16 > 0 ? 1 : 0);
|
||||
arenaMaxZ = Config.ArenaMaxZ / 16 + (Config.ArenaMaxZ % 16 > 0 ? 1 : 0);
|
||||
blueMinX = Config.TeamBlueCornerX / 16 - (Config.TeamBlueCornerX % 16 < 0 ? 1 : 0);
|
||||
blueMinZ = Config.TeamBlueCornerZ / 16 - (Config.TeamBlueCornerZ % 16 < 0 ? 1 : 0);
|
||||
int max = Config.TeamBlueCornerX + Config.SchemsizeX;
|
||||
blueMaxX = max / 16 + (max % 16 > 0 ? 1 : 0);
|
||||
max = Config.TeamBlueCornerZ + Config.SchemsizeZ;
|
||||
blueMaxZ = max / 16 + (max % 16 > 0 ? 1 : 0);
|
||||
redMinX = Config.TeamRedCornerX / 16 - (Config.TeamRedCornerX % 16 < 0 ? 1 : 0);
|
||||
redMinZ = Config.TeamRedCornerZ / 16 - (Config.TeamRedCornerZ % 16 < 0 ? 1 : 0);
|
||||
max = Config.TeamRedCornerX + Config.SchemsizeX;
|
||||
redMaxX = max / 16 + (max % 16 > 0 ? 1 : 0);
|
||||
max = Config.TeamRedCornerZ + Config.SchemsizeZ;
|
||||
redMaxZ = max / 16 + (max % 16 > 0 ? 1 : 0);
|
||||
obfuscateShift4 = Config.ObfuscateWith << 4;
|
||||
//noinspection deprecation
|
||||
obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
//TODO: Check for Which chunks to hide
|
||||
|
||||
PacketContainer packet = e.getPacket();
|
||||
StructureModifier<Integer> ints = packet.getIntegers();
|
||||
StructureModifier<byte[]> byteArray = packet.getByteArrays();
|
||||
@ -36,11 +72,15 @@ public class TechHider {
|
||||
|
||||
int chunkX = ints.read(0);
|
||||
int chunkZ = ints.read(1);
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, chunkX, chunkZ))
|
||||
return;
|
||||
|
||||
|
||||
boolean changed = false;
|
||||
for(int i = nmsTags.size() - 1; i >= 0; i--){
|
||||
NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i));
|
||||
if(nbt.getString("id").equals("minecraft:sign")){
|
||||
if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){
|
||||
nmsTags.remove(i);
|
||||
changed = true;
|
||||
}
|
||||
@ -72,7 +112,7 @@ public class TechHider {
|
||||
|
||||
int blockId = actPalette >> 4;
|
||||
if(Config.HiddenBlocks.contains(blockId)){
|
||||
byte[] a = writeVarInt(16);
|
||||
byte[] a = writeVarInt(obfuscateShift4);
|
||||
for(int j = 0; j < actPaletteLength; j++){
|
||||
newData.remove(i);
|
||||
}
|
||||
@ -119,42 +159,45 @@ public class TechHider {
|
||||
}
|
||||
});
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
//TODO: Check for Which chunks to hide
|
||||
|
||||
PacketContainer packet = e.getPacket();
|
||||
StructureModifier<WrappedBlockData> blockStructure = packet.getBlockData();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
|
||||
WrappedBlockData block = packet.getBlockData().read(0);
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, pos.getX() / 16, pos.getZ() / 16))
|
||||
return;
|
||||
|
||||
WrappedBlockData block = blockStructure.read(0);
|
||||
if(Config.HiddenBlocks.contains(block.getType().getId())){
|
||||
block.setType(Material.STONE);
|
||||
block.setType(obfuscateMaterial);
|
||||
blockStructure.write(0, block);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
//TODO: Check for Which chunks to hide
|
||||
|
||||
PacketContainer packet = e.getPacket();
|
||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = packet.getMultiBlockChangeInfoArrays();
|
||||
MultiBlockChangeInfo[] changes = blockStructure.read(0);
|
||||
boolean changed = false;
|
||||
|
||||
int i = 0;
|
||||
Player p = e.getPlayer();
|
||||
ChunkCoordIntPair pos = changes[0].getChunk();
|
||||
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
||||
return;
|
||||
|
||||
boolean changed = false;
|
||||
for(MultiBlockChangeInfo mbci : changes){
|
||||
WrappedBlockData block = mbci.getData();
|
||||
if(Config.HiddenBlocks.contains(block.getType().getId())){
|
||||
changed = true;
|
||||
block.setType(Material.STONE);
|
||||
block.setType(obfuscateMaterial);
|
||||
mbci.setData(block);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(changed){
|
||||
@ -165,10 +208,11 @@ public class TechHider {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
//TODO: Check for Which chunks to hide
|
||||
|
||||
PacketContainer packet = e.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, pos.getX() / 16, pos.getZ() / 16))
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -177,17 +221,41 @@ public class TechHider {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
//TODO: Check for Which chunks to hide
|
||||
|
||||
PacketContainer packet = e.getPacket();
|
||||
|
||||
System.out.println("EntityUse!");
|
||||
if(p.getGameMode() == GameMode.SPECTATOR){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if(p.getGameMode() == GameMode.SPECTATOR){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static int readVarInt(byte[] array, int startPos) {
|
||||
private static boolean bypass(Player p, int chunkX, int chunkZ){
|
||||
if( ! (arenaMinX <= chunkX && chunkX <= arenaMaxX && arenaMinZ <= chunkZ && chunkZ <= arenaMaxZ)){
|
||||
//Außerhalb der Arena
|
||||
return true;
|
||||
}
|
||||
|
||||
FightTeam ft = Fight.getPlayerTeam(p);
|
||||
if(ft == null){
|
||||
return false;
|
||||
}else if(ft == Fight.getBlueTeam()){
|
||||
return Config.Entern || ! (redMinX <= chunkX && chunkX <= redMaxX && redMinZ <= chunkZ && chunkZ <= redMaxZ);
|
||||
}else{
|
||||
return Config.Entern || ! (blueMinX <= chunkX && chunkX <= blueMaxX && blueMinZ <= chunkZ && chunkZ <= blueMaxZ);
|
||||
}
|
||||
}
|
||||
|
||||
private static int readVarInt(byte[] array, int startPos) {
|
||||
int numRead = 0;
|
||||
int result = 0;
|
||||
byte read;
|
||||
@ -205,7 +273,7 @@ public class TechHider {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int readVarIntLength(byte[] array, int startPos) {
|
||||
private static int readVarIntLength(byte[] array, int startPos) {
|
||||
int numRead = 0;
|
||||
byte read;
|
||||
do {
|
||||
@ -219,25 +287,7 @@ public class TechHider {
|
||||
return numRead;
|
||||
}
|
||||
|
||||
public static long readVarLong() {
|
||||
int numRead = 0;
|
||||
long result = 0;
|
||||
byte read = 0;
|
||||
do {
|
||||
//read = readByte();
|
||||
int value = (read & 0b01111111);
|
||||
result |= (value << (7 * numRead));
|
||||
|
||||
numRead++;
|
||||
if (numRead > 10) {
|
||||
break;
|
||||
}
|
||||
} while ((read & 0b10000000) != 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] writeVarInt(int value) {
|
||||
private static byte[] writeVarInt(int value) {
|
||||
ArrayList<Byte> buffer = new ArrayList<>();
|
||||
do {
|
||||
byte temp = (byte)(value & 0b01111111);
|
||||
@ -250,16 +300,4 @@ public class TechHider {
|
||||
} while (value != 0);
|
||||
return Bytes.toArray(buffer);
|
||||
}
|
||||
|
||||
public static void writeVarLong(long value) {
|
||||
do {
|
||||
byte temp = (byte)(value & 0b01111111);
|
||||
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
|
||||
value >>>= 7;
|
||||
if (value != 0) {
|
||||
temp |= 0b10000000;
|
||||
}
|
||||
//writeByte(temp);
|
||||
} while (value != 0);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren