diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index 68e49c901..57d06b615 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -140,6 +140,18 @@ 2.10.4 runtime + + net.luckperms + api + 5.0 + runtime + + + net.ess3 + EssentialsX + 2.16.1 + runtime + junit junit diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 588813d5f..f75d9ce57 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -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); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index ddcc15320..70d3c6d6b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -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) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index d2e7930fa..23d856860 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -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() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java index 403832f38..9c9f02344 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java @@ -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 getNames(@NotNull List uuids) { + @Override @NotNull public List getNames(@NotNull final List uuids) { + if (Settings.UUID.FORCE_LOWERCASE) { + return Collections.emptyList(); // This is useless now + } final List 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 getUUIDs(@NotNull List usernames) { + @Override @NotNull public List getUUIDs(@NotNull final List usernames) { final List 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;