Skip to content

Commit

Permalink
Improve world guesser
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Feb 17, 2024
1 parent 2d2040f commit 1f511d6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void loadOfflineMarkers() {

private static void loadOfflineMarker(Path playerDataFile, BlueMapAPI api) {
final String fileName = playerDataFile.getFileName().toString();
Singletons.getLogger().fine("Loading playerdata file: " + fileName);
Singletons.getLogger().info("Loading playerdata file: " + fileName);

final String uuidString = fileName.replace(".dat", "");
final UUID playerUUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.destroystokyo.paper.profile.PlayerProfile;
import com.technicjelle.bluemapofflineplayermarkers.common.Server;
import com.technicjelle.bluemapofflineplayermarkers.core.Singletons;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
Expand Down Expand Up @@ -72,16 +71,33 @@ public String getPlayerName(UUID playerUUID) {
public Optional<UUID> guessWorldUUID(Object object) {
if (object instanceof String) {
String dimensionString = (String) object;
@Nullable World world = server.getWorld(dimensionString);
if (world == null) return Optional.empty();
return Optional.of(world.getUID());

//Try to get world by name
{
@Nullable World world = server.getWorld(dimensionString);
if (world != null) {
return Optional.of(world.getUID());
}
}

//Try to get world by dimension
for (World world : server.getWorlds()) {
switch (world.getEnvironment()) {
case NORMAL:
if (dimensionString.contains("overworld")) return Optional.of(world.getUID());
case NETHER:
if (dimensionString.contains("the_nether")) return Optional.of(world.getUID());
case THE_END:
if (dimensionString.contains("the_end")) return Optional.of(world.getUID());
}
}
}

if (object instanceof Integer) {
int dimensionInt = (Integer) object;
for (World world : server.getWorlds()) {
@SuppressWarnings("deprecation") int worldID = world.getEnvironment().getId();
if (worldID == dimensionInt) return Optional.ofNullable(world.getUID());
if (worldID == dimensionInt) return Optional.of(world.getUID());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public Vector3d getPosition() {

@Override
public Optional<UUID> getWorldUUID() {
return Optional.ofNullable(player.getWorld().getUID());
return Optional.of(player.getWorld().getUID());
}
}
2 changes: 1 addition & 1 deletion src/test/java/mockery/MockMarkerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void add(Player player, BlueMapAPI __) {
if (worldUUID.isEmpty())
Singletons.getLogger().warning("World UUID: null");
else
Singletons.getLogger().finer("World UUID: " + worldUUID);
Singletons.getLogger().finer("World UUID: " + worldUUID.get());
}

@Override
Expand Down

0 comments on commit 1f511d6

Please sign in to comment.