diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index 8ed1e49..d83ac03 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -22,6 +22,7 @@ package de.steamwar.spectatesystem; import com.sk89q.worldedit.EditSession; import de.steamwar.spectatesystem.elements.*; import de.steamwar.spectatesystem.util.ColorConverter; +import de.steamwar.spectatesystem.util.Paster; import de.steamwar.spectatesystem.util.WorldLoader; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; @@ -35,11 +36,14 @@ import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; import java.io.EOFException; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Level; class PacketProcessor { private static final World world = Bukkit.getWorlds().get(0); + private Map packetCounter = new HashMap<>(); private final PacketSource source; @@ -142,7 +146,7 @@ class PacketProcessor { private void block() throws IOException { int x = source.rInt(); - byte y = source.rByte(); + int y = Byte.toUnsignedInt(source.rByte()); int z = source.rInt(); int blockState = source.rInt(); @@ -168,19 +172,6 @@ class PacketProcessor { }); } - private void scoreboardTitle() throws IOException { - String title = source.rString(); - - SpectateSystem.getScoreboard().setTitle(title); - } - - private void scoreboardData() throws IOException { - String key = source.rString(); - int value = source.rInt(); - - SpectateSystem.getScoreboard().addValue(key, value); - } - private void sound() throws IOException { int x = source.rInt(); int y = source.rInt(); @@ -200,6 +191,22 @@ class PacketProcessor { }); } + private void shortBlock() throws IOException { + int x = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinX; + int y = Byte.toUnsignedInt(source.rByte()); + int z = Byte.toUnsignedInt(source.rByte()) + Config.ArenaMinZ; + + int blockState = source.rShort(); + + if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + blockState = Config.ObfuscateWith; + } + CraftBlockData craftBlockData = CraftBlockData.fromData(Block.REGISTRY_ID.fromId(blockState)); + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + world.getBlockAt(x, y, z).setBlockData(craftBlockData); + }); + } + private void pasteSchem(int cornerX, int cornerY, int cornerZ, boolean rotate, String prefix) throws IOException { int schemId = source.rInt(); @@ -213,10 +220,25 @@ class PacketProcessor { } } + private void scoreboardTitle() throws IOException { + String title = source.rString(); + + SpectateSystem.getScoreboard().setTitle(title); + } + + private void scoreboardData() throws IOException { + String key = source.rString(); + int value = source.rInt(); + + SpectateSystem.getScoreboard().addValue(key, value); + } + private void process(){ try{ while(!source.isClosed()){ - switch(source.rByte()){ + byte packetType = source.rByte(); + packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1); + switch(packetType){ case 0x00: playerJoins(); break; @@ -256,6 +278,9 @@ class PacketProcessor { case 0x32: sound(); break; + case 0x33: + shortBlock(); + break; case (byte) 0xA0: send(ChatMessageType.CHAT); break; @@ -293,5 +318,9 @@ class PacketProcessor { Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); source.close(); } + + for(Map.Entry entry : packetCounter.entrySet()){ + System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue()); + } } } diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index c821f3c..2a221bc 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -54,6 +54,14 @@ public abstract class REntity { } } + protected static EntityLiving getShooter(){ + for(REntity entity : entities.values()){ + if(entity.entity instanceof EntityLiving) + return (EntityLiving) entity.entity; + } + return ((CraftPlayer)Bukkit.getOnlinePlayers().iterator().next()).getHandle(); + } + public static REntity getEntity(int internalId){ return entities.get(internalId); } diff --git a/src/de/steamwar/spectatesystem/elements/RFireball.java b/src/de/steamwar/spectatesystem/elements/RFireball.java index 7144f87..7e012bd 100644 --- a/src/de/steamwar/spectatesystem/elements/RFireball.java +++ b/src/de/steamwar/spectatesystem/elements/RFireball.java @@ -19,7 +19,8 @@ package de.steamwar.spectatesystem.elements; -import net.minecraft.server.v1_15_R1.*; +import net.minecraft.server.v1_15_R1.EntityFireball; +import net.minecraft.server.v1_15_R1.EntityLargeFireball; public class RFireball extends REntity{ public RFireball(int internalId) { @@ -27,6 +28,6 @@ public class RFireball extends REntity{ } private static EntityFireball createFireball() { - return new EntitySmallFireball(world, 0, 0, 0, 0, 0, 0); + return new EntityLargeFireball(world, getShooter(), 0, 0, 0); } } diff --git a/src/de/steamwar/spectatesystem/elements/RPlayer.java b/src/de/steamwar/spectatesystem/elements/RPlayer.java index 534a9c6..c447ba2 100644 --- a/src/de/steamwar/spectatesystem/elements/RPlayer.java +++ b/src/de/steamwar/spectatesystem/elements/RPlayer.java @@ -121,4 +121,8 @@ public class RPlayer extends REntity { connection.sendPacket(packet); } } + + public void recieveDamage(){ + //TODO + } } diff --git a/src/de/steamwar/spectatesystem/listener/ArenaListener.java b/src/de/steamwar/spectatesystem/listener/ArenaListener.java index f2c112c..695abc8 100644 --- a/src/de/steamwar/spectatesystem/listener/ArenaListener.java +++ b/src/de/steamwar/spectatesystem/listener/ArenaListener.java @@ -20,13 +20,16 @@ package de.steamwar.spectatesystem.listener; import de.steamwar.spectatesystem.Config; -import de.steamwar.spectatesystem.util.Region; import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.spectatesystem.util.Region; import de.steamwar.spectatesystem.util.WorldLoader; import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockExplodeEvent; @@ -34,6 +37,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.WorldLoadEvent; @@ -83,6 +87,7 @@ public class ArenaListener extends BasicListener { @EventHandler public void onWorldLoad(WorldLoadEvent e){ e.getWorld().setAutoSave(false); + ((CraftWorld)e.getWorld()).getHandle().savingDisabled = true; } @EventHandler @@ -97,6 +102,14 @@ public class ArenaListener extends BasicListener { @EventHandler public void onChat(AsyncPlayerChatEvent e){ + e.setCancelled(true); + BaseComponent[] message = TextComponent.fromLegacyText("§7" + e.getPlayer().getName() + "§8» §7" + e.getMessage()); + e.getRecipients().forEach(p -> p.spigot().sendMessage(ChatMessageType.CHAT, message)); WorldLoader.reloadWorld(); } + + @EventHandler + public void onChunkLoad(ChunkLoadEvent e){ + ((CraftChunk)e.getChunk()).getHandle().mustNotSave = true; + } } diff --git a/src/de/steamwar/spectatesystem/Paster.java b/src/de/steamwar/spectatesystem/util/Paster.java similarity index 98% rename from src/de/steamwar/spectatesystem/Paster.java rename to src/de/steamwar/spectatesystem/util/Paster.java index 502f7f2..ccbfb0d 100644 --- a/src/de/steamwar/spectatesystem/Paster.java +++ b/src/de/steamwar/spectatesystem/util/Paster.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package de.steamwar.spectatesystem; +package de.steamwar.spectatesystem.util; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; @@ -32,6 +32,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import de.steamwar.spectatesystem.Config; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index b1a74fa..6aefdbe 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -25,7 +25,6 @@ import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; public class WorldLoader { private WorldLoader(){} @@ -35,8 +34,6 @@ public class WorldLoader { public static void reloadWorld(){ Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { for(Chunk chunk: world.getLoadedChunks()){ - System.out.println(((CraftChunk)chunk).getHandle().mustNotSave); - ((CraftChunk)chunk).getHandle().mustNotSave = true; world.unloadChunk(chunk.getX(), chunk.getZ(), false); world.getChunkAt(chunk.getX(), chunk.getZ()); }