From 6b23f88ea0424ab7f246ee2ff9b975b644b7450b Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 27 Dec 2020 13:47:43 +0100 Subject: [PATCH] Optimize Packets in TraceEntity_12 and TraceEntity_15 Simplify messages in CommandTrace --- .../bausystem/tracer/TraceEntity_12.java | 8 +++-- .../bausystem/tracer/TraceEntity_15.java | 6 ++-- .../bausystem/commands/CommandTrace.java | 33 +++++-------------- .../bausystem/tracer/record/RecordStatus.java | 22 ++++++++++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index b1f76c3..18f3981 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -31,10 +31,12 @@ import java.lang.reflect.Field; class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { private Vector position; + private boolean tnt; public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) { super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData()); this.position = position; + this.tnt = tnt; this.setNoGravity(true); this.ticksLived = -12000; @@ -64,8 +66,10 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); playerConnection.sendPacket(packetPlayOutEntityTeleport); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); + if (tnt) { + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + playerConnection.sendPacket(packetPlayOutEntityMetadata); + } return this; } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 1087626..0c69184 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -54,8 +54,10 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; playerConnection.sendPacket(packetPlayOutSpawnEntity); - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); + if (tnt) { + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); + playerConnection.sendPacket(packetPlayOutEntityMetadata); + } return this; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index 880df14..cc59977 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,8 +22,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; -import de.steamwar.bausystem.tracer.record.RecordStatus; -import de.steamwar.bausystem.tracer.show.ShowMode; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.tracer.show.mode.Advanced; @@ -73,29 +71,16 @@ public class CommandTrace implements CommandExecutor { switch (args[0].toLowerCase()) { case "start": RecordStateMachine.commandStart(); - player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet"); + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); break; case "stop": RecordStateMachine.commandStop(); - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt"); + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getMessage()); break; case "toggleauto": case "auto": RecordStateMachine.commandAuto(); - switch (RecordStateMachine.getRecordStatus()) { - case IDLE: - player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); - break; - case IDLE_AUTO: - player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); - break; - case RECORD: - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss gestoppt werden"); - break; - case RECORD_AUTO: - player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss aus sein"); - break; - } + player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage()); break; case "clear": case "delete": @@ -103,31 +88,29 @@ public class CommandTrace implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht"); break; case "show": - ShowMode showMode; if (args.length < 2) { - showMode = new Basic(player); + TraceShowManager.show(player, new Basic(player)); } else { switch (args[1].toLowerCase()) { case "nowater": case "basic-nowater": case "basicnowater": - showMode = new BasicNoWater(player); + TraceShowManager.show(player, new BasicNoWater(player)); break; case "advanced": - showMode = new Advanced(player); + TraceShowManager.show(player, new Advanced(player)); break; case "advanced-nowater": case "advancednowater": - showMode = new AdvancedNoWater(player); + TraceShowManager.show(player, new AdvancedNoWater(player)); break; case "basic": case "default": default: - showMode = new Basic(player); + TraceShowManager.show(player, new Basic(player)); break; } } - TraceShowManager.show(player, showMode); player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt"); break; case "hide": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index 45cbec3..4e21971 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -21,17 +21,21 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { - RECORD("§aan", true), - RECORD_AUTO("§aan", true), - IDLE("§caus", false), - IDLE_AUTO("§eauto", false); + RECORD("§aan", true, "§aTNT-Tracer gestartet", "§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, "§cAuto-Tracer muss aus sein", "§cTNT-Tracer muss aus sein"), + IDLE("§caus", false, "§cTNT-Tracer gestoppt", "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, "§cTNT-Tracer muss gestoppt werden", "§aAuto-Tracer gestartet"); String name; boolean tracing; + String message; + String autoMessage; - RecordStatus(String value, boolean tracing) { + RecordStatus(String value, boolean tracing, String message, String autoMessage) { this.name = value; this.tracing = tracing; + this.message = message; + this.autoMessage = autoMessage; } public String getName() { @@ -42,4 +46,12 @@ public enum RecordStatus { return tracing; } + public String getMessage() { + return message; + } + + public String getAutoMessage() { + return autoMessage; + } + }