1010import com .funniray .minimap .common .jm .data .JMWorldConfig ;
1111import com .funniray .minimap .common .jm .data .ServerPropType ;
1212import com .funniray .minimap .common .network .NetworkUtils ;
13+ import com .funniray .minimap .common .version .Version ;
1314import com .google .common .io .ByteArrayDataInput ;
1415import com .google .common .io .ByteArrayDataOutput ;
1516import com .google .common .io .ByteStreams ;
1617import com .google .gson .Gson ;
1718import net .kyori .adventure .text .minimessage .MiniMessage ;
1819
19- import java .awt .print .Pageable ;
2020import java .util .*;
2121
2222public class JMHandler implements MessageHandler {
2323 private final JavaMinimapPlugin plugin ;
24- // JM for 1.21 and above no longer has a leading 0 byte at the start of packets.
25- // We need to note who is on a modern version and not send them (or parse) leading 0 bytes
26- private final Map <UUID , Boolean > modernList = new HashMap <>();
2724
2825 public JMHandler (JavaMinimapPlugin plugin ) {
2926 this .plugin = plugin ;
@@ -42,7 +39,7 @@ public void handleTeleport(MinimapPlayer player, byte[] message, String replyCha
4239 player .sendMessage (MiniMessage .miniMessage ().deserialize ("<red>You don't have permission to teleport." ));
4340 return ;
4441 }
45- String teleport = getEffectiveConfig (player ).teleportEnabled ;
42+ String teleport = plugin . getEffectiveJMConfig (player ).teleportEnabled ;
4643 if (teleport .equalsIgnoreCase ("none" ) || (teleport .equalsIgnoreCase ("ops" ) && !player .hasPermission ("minimap.jm.admin" ))) {
4744 player .sendMessage (MiniMessage .miniMessage ().deserialize ("<red>Teleport packet was sent, but teleporting isn't enabled." ));
4845 return ;
@@ -144,7 +141,6 @@ public void handleAdminSave(MinimapPlayer player, byte[] message, String replyCh
144141 }
145142
146143 public void handleVersion (MinimapPlayer player , byte [] message , String replyChannel ) {
147- modernList .put (player .getUniqueId (), message .length > 0 && message [0 ] != 0 );
148144 Gson gson = new Gson ();
149145 JMVersion serverVersion = new JMVersion ();
150146 ByteArrayDataInput in = ByteStreams .newDataInput (message );
@@ -163,18 +159,8 @@ public void handleVersion(MinimapPlayer player, byte[] message, String replyChan
163159 player .sendPluginMessage (out .toByteArray (), replyChannel );
164160 }
165161
166- public JMConfig getEffectiveConfig (MinimapPlayer player ) {
167- JMWorldConfig worldConfig = plugin .getConfig ().getWorldConfig (player .getLocation ().getWorld ().getName ()).journeymapConfig ;
168- JMConfig config = plugin .getConfig ().globalJourneymapConfig ;
169- if (worldConfig != null ) {
170- return worldConfig .applyToConfig (config );
171- }
172- return config ;
173- }
174-
175162 public void handlePerm (MinimapPlayer player , byte [] message , String replyChannel , int replyByte ) {
176- modernList .putIfAbsent (player .getUniqueId (), message .length > 0 && message [0 ] == 42 );
177- JMConfig config = getEffectiveConfig (player );
163+ JMConfig config = plugin .getEffectiveJMConfig (player );
178164
179165 Gson gson = new Gson ();
180166 String payload = gson .toJson (config );
@@ -187,14 +173,12 @@ public void handlePerm(MinimapPlayer player, byte[] message, String replyChannel
187173 player .sendPluginMessage (out .toByteArray (), replyChannel );
188174 }
189175
190- private boolean modern (MinimapPlayer player ) {
191- Boolean modern = modernList .get (player .getUniqueId ());
192- if (modern == null ) return false ;
193- return modern ;
176+ public boolean modern (MinimapPlayer player ) {
177+ return player .getVersion ().greaterThanEqual (new Version (1 ,21 ,0 ));
194178 }
195179
196- public void playerLeft (MinimapPlayer player ) {
197- modernList . remove ( player . getUniqueId ( ));
180+ public boolean isLegacy (MinimapPlayer player ) {
181+ return ! player . getVersion (). greaterThanEqual ( new Version ( 1 , 18 , 0 ));
198182 }
199183
200184 @ Override
0 commit comments