From 2512678eb400cdeddd7c5c72437fc70760f94fca Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 4 Jul 2021 20:57:15 +0200 Subject: [PATCH] it did --- .../src/main/java/gearth/extensions/ExtensionBase.java | 4 ++-- .../src/main/java/gearth/extensions/ExtensionForm.java | 6 ++++++ .../blockreplacepackets/BlockAndReplacePackets.java | 10 +++++----- .../packetinfoexplorer/PacketInfoExplorer.java | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/G-Earth/src/main/java/gearth/extensions/ExtensionBase.java b/G-Earth/src/main/java/gearth/extensions/ExtensionBase.java index 92bc66c..0614606 100644 --- a/G-Earth/src/main/java/gearth/extensions/ExtensionBase.java +++ b/G-Earth/src/main/java/gearth/extensions/ExtensionBase.java @@ -22,7 +22,7 @@ public abstract class ExtensionBase extends IExtension { protected final Map> incomingMessageListeners = new HashMap<>(); protected final Map> outgoingMessageListeners = new HashMap<>(); - protected PacketInfoManager packetInfoManager = new PacketInfoManager(new ArrayList<>()); // empty + volatile PacketInfoManager packetInfoManager = PacketInfoManager.EMPTY; /** * Register a listener on a specific packet Type @@ -131,7 +131,7 @@ public abstract class ExtensionBase extends IExtension { return onConnectionObservable; } - protected void setPacketInfoManager(PacketInfoManager packetInfoManager) { + void setPacketInfoManager(PacketInfoManager packetInfoManager) { this.packetInfoManager = packetInfoManager; } diff --git a/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java b/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java index 5310cd0..9ac3447 100644 --- a/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java +++ b/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java @@ -1,5 +1,6 @@ package gearth.extensions; +import gearth.services.packet_info.PacketInfoManager; import javafx.application.Platform; import javafx.stage.Stage; import gearth.protocol.HMessage; @@ -47,6 +48,11 @@ public abstract class ExtensionForm extends ExtensionBase { extension.onConnect(listener); } + @Override + public PacketInfoManager getPacketInfoManager() { + return extension.getPacketInfoManager(); + } + protected void onShow(){}; protected void onHide(){}; diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/blockreplacepackets/BlockAndReplacePackets.java b/G-Earth/src/main/java/gearth/services/internal_extensions/blockreplacepackets/BlockAndReplacePackets.java index 9321bb0..a30e3fe 100644 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/blockreplacepackets/BlockAndReplacePackets.java +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/blockreplacepackets/BlockAndReplacePackets.java @@ -68,9 +68,7 @@ public class BlockAndReplacePackets extends ExtensionForm { txt_replacement.textProperty().addListener(event -> Platform.runLater(this::refreshOptions)); txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions)); - refreshOptions(); cmb_type.requestFocus(); - } private String getVal() { @@ -80,8 +78,8 @@ public class BlockAndReplacePackets extends ExtensionForm { if (type.endsWith("packet")) { HMessage.Direction dir = side.equals("Outgoing") ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT; - PacketInfo fromName = packetInfoManager.getPacketInfoFromName(dir, val); - PacketInfo fromHash = packetInfoManager.getPacketInfoFromHash(dir, val); + PacketInfo fromName = getPacketInfoManager().getPacketInfoFromName(dir, val); + PacketInfo fromHash = getPacketInfoManager().getPacketInfoFromHash(dir, val); if (fromName != null) { val = fromName.getHeaderId() +""; } @@ -208,6 +206,8 @@ public class BlockAndReplacePackets extends ExtensionForm { intercept(HMessage.Direction.TOSERVER, messageListener); intercept(HMessage.Direction.TOCLIENT, messageListener); + + refreshOptions(); } @Override @@ -231,7 +231,7 @@ public class BlockAndReplacePackets extends ExtensionForm { public void click_btnAddRule(ActionEvent actionEvent) { BlockReplaceRule rule = RuleFactory.getRule(cmb_type.getSelectionModel().getSelectedItem(), - cmb_side.getSelectionModel().getSelectedItem(), getVal(), txt_replacement.getText(), packetInfoManager); + cmb_side.getSelectionModel().getSelectedItem(), getVal(), txt_replacement.getText(), getPacketInfoManager()); rules.add(rule); rule.onDelete(observable -> rules.remove(rule)); new RuleContainer(rule, vbox); diff --git a/G-Earth/src/main/java/gearth/services/internal_extensions/packetinfoexplorer/PacketInfoExplorer.java b/G-Earth/src/main/java/gearth/services/internal_extensions/packetinfoexplorer/PacketInfoExplorer.java index 337fabf..4b70ca2 100644 --- a/G-Earth/src/main/java/gearth/services/internal_extensions/packetinfoexplorer/PacketInfoExplorer.java +++ b/G-Earth/src/main/java/gearth/services/internal_extensions/packetinfoexplorer/PacketInfoExplorer.java @@ -111,7 +111,7 @@ public class PacketInfoExplorer extends ExtensionForm { @Override protected void initExtension() { onConnect((host, port, hotelversion, clientIdentifier, clientType) -> { - init(packetInfoManager); + init(getPacketInfoManager()); }); }