mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
Add plugin UUID services. They probably work.
This commit is contained in:
parent
6c6c2b57a1
commit
2875b050c5
4 changed files with 193 additions and 1 deletions
|
@ -11,6 +11,7 @@ repositories {
|
|||
name = "papermc"
|
||||
url = "https://papermc.io/repo/repository/maven-public/"
|
||||
}
|
||||
maven { url = "https://ci.ender.zone/plugin/repository/everything/" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
mavenLocal()
|
||||
}
|
||||
|
@ -30,6 +31,8 @@ dependencies {
|
|||
exclude(module: "bukkit")
|
||||
}
|
||||
implementation("me.clip:placeholderapi:2.10.4")
|
||||
implementation("net.luckperms:api:5.0")
|
||||
implementation("net.ess3:EssentialsX:2.16.1")
|
||||
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
|
||||
compile 'com.github.pavog:SquirrelID:0.6.1'
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ import com.plotsquared.bukkit.util.BukkitTaskManager;
|
|||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.plotsquared.bukkit.util.UpdateUtility;
|
||||
import com.plotsquared.bukkit.uuid.EssentialsUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.LuckPermsUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.PaperUUIDService;
|
||||
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
|
||||
|
@ -231,38 +233,71 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||
PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :(");
|
||||
}
|
||||
|
||||
// TODO: Do we respect the UUID settings?
|
||||
final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline();
|
||||
final UUIDPipeline backgroundPipeline = PlotSquared.get().getBackgroundUUIDPipeline();
|
||||
|
||||
// Services are accessed in order
|
||||
final CacheUUIDService cacheUUIDService = new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE);
|
||||
impromptuPipeline.registerService(cacheUUIDService);
|
||||
backgroundPipeline.registerService(cacheUUIDService);
|
||||
impromptuPipeline.registerConsumer(cacheUUIDService);
|
||||
backgroundPipeline.registerConsumer(cacheUUIDService);
|
||||
|
||||
// Now, if the server is in offline mode we can only use profiles and direct UUID
|
||||
// access, and so we skip the player profile stuff as well as SquirrelID (Mojang lookups)
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService();
|
||||
impromptuPipeline.registerService(offlineModeUUIDService);
|
||||
backgroundPipeline.registerService(offlineModeUUIDService);
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service");
|
||||
}
|
||||
|
||||
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
|
||||
impromptuPipeline.registerService(offlinePlayerUUIDService);
|
||||
backgroundPipeline.registerService(offlinePlayerUUIDService);
|
||||
|
||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService();
|
||||
|
||||
final LuckPermsUUIDService luckPermsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
luckPermsUUIDService = new LuckPermsUUIDService();
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service");
|
||||
} else {
|
||||
luckPermsUUIDService = null;
|
||||
}
|
||||
|
||||
final EssentialsUUIDService essentialsUUIDService;
|
||||
if (Bukkit.getPluginManager().getPlugin("Essentials") != null) {
|
||||
essentialsUUIDService = new EssentialsUUIDService();
|
||||
PlotSquared.log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service");
|
||||
} else {
|
||||
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");
|
||||
}
|
||||
|
||||
impromptuPipeline.registerService(sqLiteUUIDService);
|
||||
backgroundPipeline.registerService(sqLiteUUIDService);
|
||||
impromptuPipeline.registerConsumer(sqLiteUUIDService);
|
||||
backgroundPipeline.registerConsumer(sqLiteUUIDService);
|
||||
|
||||
// Plugin providers
|
||||
if (luckPermsUUIDService != null) {
|
||||
impromptuPipeline.registerService(luckPermsUUIDService);
|
||||
backgroundPipeline.registerService(luckPermsUUIDService);
|
||||
}
|
||||
if (essentialsUUIDService != null) {
|
||||
impromptuPipeline.registerService(essentialsUUIDService);
|
||||
backgroundPipeline.registerService(essentialsUUIDService);
|
||||
}
|
||||
|
||||
final SquirrelIdUUIDService impromptuMojangService = new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
|
||||
impromptuPipeline.registerService(impromptuMojangService);
|
||||
final SquirrelIdUUIDService backgroundMojangService = new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.uuid;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service using the EssentialsX API
|
||||
*/
|
||||
public class EssentialsUUIDService implements UUIDService {
|
||||
|
||||
private final Essentials essentials;
|
||||
|
||||
public EssentialsUUIDService() {
|
||||
this.essentials = Essentials.getPlugin(Essentials.class);
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
final User user = essentials.getUser(username);
|
||||
if (user != null) {
|
||||
final UUID uuid = user.getConfigUUID();
|
||||
if (uuid != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
}
|
||||
} catch (final Exception ignored){}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.uuid;
|
||||
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* UUID service that uses the LuckPerms API
|
||||
*/
|
||||
public class LuckPermsUUIDService implements UUIDService {
|
||||
|
||||
private final LuckPerms luckPerms;
|
||||
|
||||
public LuckPermsUUIDService() {
|
||||
final RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
|
||||
if (provider != null) {
|
||||
this.luckPerms = provider.getProvider();
|
||||
} else {
|
||||
throw new IllegalStateException("LuckPerms not available");
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final UUID uuid : uuids) {
|
||||
try {
|
||||
final String username = userManager.lookupUsername(uuid).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @NotNull public List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
final UUID uuid = userManager.lookupUniqueId(username).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue