Fix offline mode UUIDs

This commit is contained in:
Alexander Söderberg 2020-05-24 04:27:20 +02:00
parent 2875b050c5
commit 75dbc2db98
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
5 changed files with 60 additions and 15 deletions

View File

@ -140,6 +140,18 @@
<version>2.10.4</version> <version>2.10.4</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.16.1</version>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -274,7 +274,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
essentialsUUIDService = null; essentialsUUIDService = null;
} }
if (!Settings.UUID.OFFLINE) {
// If running Paper we'll also try to use their profiles // If running Paper we'll also try to use their profiles
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
final PaperUUIDService paperUUIDService = new PaperUUIDService(); final PaperUUIDService paperUUIDService = new PaperUUIDService();
@ -283,6 +282,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
PlotSquared.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service"); PlotSquared.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
} }
if (!Settings.UUID.OFFLINE) {
impromptuPipeline.registerService(sqLiteUUIDService); impromptuPipeline.registerService(sqLiteUUIDService);
backgroundPipeline.registerService(sqLiteUUIDService); backgroundPipeline.registerService(sqLiteUUIDService);
impromptuPipeline.registerConsumer(sqLiteUUIDService); impromptuPipeline.registerConsumer(sqLiteUUIDService);

View File

@ -26,6 +26,7 @@
package com.plotsquared.bukkit.listener; package com.plotsquared.bukkit.listener;
import com.destroystokyo.paper.MaterialTags; import com.destroystokyo.paper.MaterialTags;
import com.google.common.base.Charsets;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.UpdateUtility; import com.plotsquared.bukkit.util.UpdateUtility;
@ -629,7 +630,19 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPreLoin(final AsyncPlayerPreLoginEvent event) { public void onPreLoin(final AsyncPlayerPreLoginEvent event) {
PlotSquared.get().getImpromptuUUIDPipeline().storeImmediately(event.getName(), event.getUniqueId()); final UUID uuid;
if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) {
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" +
event.getName().toLowerCase()).getBytes(Charsets.UTF_8));
} else {
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" +
event.getName()).getBytes(Charsets.UTF_8));
}
} else {
uuid = event.getUniqueId();
}
PlotSquared.get().getImpromptuUUIDPipeline().storeImmediately(event.getName(), uuid);
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)

View File

@ -25,9 +25,11 @@
*/ */
package com.plotsquared.bukkit.player; package com.plotsquared.bukkit.player;
import com.google.common.base.Charsets;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -96,7 +98,16 @@ public class BukkitPlayer extends PlotPlayer {
} }
@NotNull @Override public UUID getUUID() { @NotNull @Override public UUID getUUID() {
return this.player.getUniqueId(); if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
getName().toLowerCase()).getBytes(Charsets.UTF_8));
} else {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
getName()).getBytes(Charsets.UTF_8));
}
}
return player.getUniqueId();
} }
@Override public long getLastPlayed() { @Override public long getLastPlayed() {

View File

@ -25,6 +25,8 @@
*/ */
package com.plotsquared.bukkit.uuid; package com.plotsquared.bukkit.uuid;
import com.google.common.base.Charsets;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.uuid.UUIDMapping; import com.plotsquared.core.uuid.UUIDMapping;
import com.plotsquared.core.uuid.UUIDService; import com.plotsquared.core.uuid.UUIDService;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -32,6 +34,7 @@ import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -40,7 +43,10 @@ import java.util.UUID;
*/ */
public class OfflinePlayerUUIDService implements UUIDService { public class OfflinePlayerUUIDService implements UUIDService {
@Override public @NotNull List<UUIDMapping> getNames(@NotNull List<UUID> uuids) { @Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
if (Settings.UUID.FORCE_LOWERCASE) {
return Collections.emptyList(); // This is useless now
}
final List<UUIDMapping> wrappers = new ArrayList<>(uuids.size()); final List<UUIDMapping> wrappers = new ArrayList<>(uuids.size());
for (final UUID uuid : uuids) { for (final UUID uuid : uuids) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
@ -51,12 +57,15 @@ public class OfflinePlayerUUIDService implements UUIDService {
return wrappers; return wrappers;
} }
@Override public @NotNull List<UUIDMapping> getUUIDs(@NotNull List<String> usernames) { @Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size()); final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
for (final String username : usernames) { for (final String username : usernames) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); if (Settings.UUID.FORCE_LOWERCASE) {
if (offlinePlayer.hasPlayedBefore()) { wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName())); username.toLowerCase()).getBytes(Charsets.UTF_8)), username));
} else {
wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
username).getBytes(Charsets.UTF_8)), username));
} }
} }
return wrappers; return wrappers;