@@ -266,6 +266,7 @@ public class APIHandler {
266266 private String authenticatedUsername = null ;
267267 private boolean stopChanges = false ;
268268 private boolean verifiedUser = false ;
269+ private Map <Integer ,UUID > idToUUID = new HashMap <Integer ,UUID >();
269270
270271 public APIHandler (MCEventHandler eventHandler , PrintWriter writer ) throws IOException {
271272 this (eventHandler , writer , true );
@@ -342,18 +343,7 @@ synchronized private void updatePlayerMP() {
342343 if (playerMP != null )
343344 return ;
344345
345- if (RaspberryJamMod .integrated ) {
346- playerMP = mc .getIntegratedServer ().getPlayerList ().getPlayerByUUID (playerUniqueId );
347- playerId = playerMP .getEntityId ();
348- }
349-
350- for (World w : serverWorlds ) {
351- Entity e = w .getEntityByID (playerId );
352- if (e != null ) {
353- playerMP = (EntityPlayerMP )e ;
354- return ;
355- }
356- }
346+ playerMP = RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerByUUID (playerUniqueId );
357347 }
358348
359349 public static String tohex (byte [] array ) {
@@ -385,7 +375,7 @@ protected boolean setup() {
385375 return false ;
386376 }
387377 playerUniqueId = mc .thePlayer .getUniqueID ();
388- playerMP = mc . getIntegratedServer () .getPlayerList ().getPlayerByUUID (playerUniqueId );
378+ playerMP = RaspberryJamMod . minecraftServer .getPlayerList ().getPlayerByUUID (playerUniqueId );
389379 playerId = playerMP .getEntityId ();
390380 }
391381 else {
@@ -396,22 +386,23 @@ protected boolean setup() {
396386
397387 if (playerMP != null ) {
398388 verifiedUser = true ;
399- playerId = playerMP .getEntityId ();
400389 }
401390 else {
402391 int firstId = 0 ;
403392
404- for (World w : serverWorlds ) {
405- for (EntityPlayer p : w .playerEntities ) {
406- int id = p .getEntityId ();
407- if (playerMP == null || id < firstId ) {
408- firstId = id ;
409- playerMP = (EntityPlayerMP )p ;
410- playerId = id ;
411- }
393+ for (EntityPlayer p : RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerList ()) {
394+ int id = p .getEntityId ();
395+ if (playerMP == null || id < firstId ) {
396+ firstId = id ;
397+ playerMP = (EntityPlayerMP )p ;
412398 }
413399 }
414400 }
401+
402+ if (playerMP != null ) {
403+ playerId = playerMP .getEntityId ();
404+ playerUniqueId = playerMP .getUniqueID ();
405+ }
415406 }
416407
417408 if (playerMP == null ) {
@@ -885,18 +876,14 @@ else if (arg.startsWith(EVENTSSETTING+".")) {
885876 }
886877
887878 protected EntityPlayer getPlayerByNameOrUUID (String name ) {
888- for (World w : serverWorlds ) {
889- for (EntityPlayer p : (List <EntityPlayer >)w .playerEntities ) {
890- if (p .getName ().equals (name )) {
891- return p ;
892- }
879+ for (EntityPlayer p : RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerList ()) {
880+ if (p .getName ().equals (name )) {
881+ return p ;
893882 }
894883 }
895- for (World w : serverWorlds ) {
896- for (EntityPlayer p : (List <EntityPlayer >)w .playerEntities ) {
897- if (p .getUniqueID ().toString ().equals (name )) {
898- return p ;
899- }
884+ for (EntityPlayer p : RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerList ()) {
885+ if (p .getUniqueID ().toString ().equals (name )) {
886+ return p ;
900887 }
901888 }
902889 return null ;
@@ -1437,26 +1424,33 @@ protected Location getBlockLocation(Scanner scan) {
14371424
14381425 protected Entity getServerEntityByID (int id ) {
14391426 if (id == playerId ) {
1440- //updatePlayerMP();
14411427 return playerMP ;
14421428 }
1429+
1430+ UUID uuid = idToUUID .get (id );
1431+
1432+ if (uuid != null ) {
1433+ return RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerByUUID (uuid );
1434+ }
1435+
1436+ for (EntityPlayerMP player : RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerList ())
1437+ if (player .getEntityId () == id ) {
1438+ idToUUID .put (id , player .getUniqueID ());
1439+ return player ;
1440+ }
1441+
14431442 for (World w : serverWorlds ) {
14441443 Entity e = w .getEntityByID (id );
14451444 if (e != null )
14461445 return e ;
14471446 }
1447+
14481448 return null ;
14491449 }
14501450
14511451 static void globalMessage (String message ) {
1452- Set <EntityPlayer > done = new HashSet <EntityPlayer >();
1453- for (World w : RaspberryJamMod .minecraftServer .worldServers ) {
1454- for (EntityPlayer p : (List <EntityPlayer >)w .playerEntities ) {
1455- if (!done .contains (p )) {
1456- p .addChatComponentMessage (new TextComponentString (message ));
1457- done .add (p );
1458- }
1459- }
1452+ for (EntityPlayerMP player : RaspberryJamMod .minecraftServer .getPlayerList ().getPlayerList ()) {
1453+ player .addChatComponentMessage (new TextComponentString (message ));
14601454 }
14611455 }
14621456
0 commit comments