mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 12:25:46 +01:00
Fix offline mode UUIDs
This commit is contained in:
parent
2875b050c5
commit
75dbc2db98
@ -140,6 +140,18 @@
|
||||
<version>2.10.4</version>
|
||||
<scope>runtime</scope>
|
||||
</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>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -274,15 +274,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
essentialsUUIDService = null;
|
||||
}
|
||||
|
||||
if (!Settings.UUID.OFFLINE) {
|
||||
// If running Paper we'll also try to use their profiles
|
||||
if (PaperLib.isPaper()) {
|
||||
final PaperUUIDService paperUUIDService = new PaperUUIDService();
|
||||
impromptuPipeline.registerService(paperUUIDService);
|
||||
backgroundPipeline.registerService(paperUUIDService);
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
|
||||
}
|
||||
// If running Paper we'll also try to use their profiles
|
||||
if (PaperLib.isPaper()) {
|
||||
final PaperUUIDService paperUUIDService = new PaperUUIDService();
|
||||
impromptuPipeline.registerService(paperUUIDService);
|
||||
backgroundPipeline.registerService(paperUUIDService);
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
|
||||
}
|
||||
|
||||
if (!Settings.UUID.OFFLINE) {
|
||||
impromptuPipeline.registerService(sqLiteUUIDService);
|
||||
backgroundPipeline.registerService(sqLiteUUIDService);
|
||||
impromptuPipeline.registerConsumer(sqLiteUUIDService);
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.destroystokyo.paper.MaterialTags;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
@ -629,7 +630,19 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
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)
|
||||
|
@ -25,9 +25,11 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -96,7 +98,16 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
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.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -32,6 +34,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -40,7 +43,10 @@ import java.util.UUID;
|
||||
*/
|
||||
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());
|
||||
for (final UUID uuid : uuids) {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
@ -51,12 +57,15 @@ public class OfflinePlayerUUIDService implements UUIDService {
|
||||
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());
|
||||
for (final String username : usernames) {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
username.toLowerCase()).getBytes(Charsets.UTF_8)), username));
|
||||
} else {
|
||||
wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||
username).getBytes(Charsets.UTF_8)), username));
|
||||
}
|
||||
}
|
||||
return wrappers;
|
||||
|
Loading…
Reference in New Issue
Block a user