Basic pipeline setup

This commit is contained in:
Alexander Söderberg 2020-05-18 00:22:34 +02:00
parent a47527857c
commit 31c84ab18f
3 changed files with 57 additions and 0 deletions

View File

@ -55,6 +55,10 @@ import com.plotsquared.bukkit.util.uuid.FileUUIDHandler;
import com.plotsquared.bukkit.util.uuid.LowerOfflineUUIDWrapper;
import com.plotsquared.bukkit.util.uuid.OfflineUUIDWrapper;
import com.plotsquared.bukkit.util.uuid.SQLUUIDHandler;
import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
import com.plotsquared.bukkit.uuid.PaperUUIDService;
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
import com.plotsquared.core.IPlotMain;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager;
@ -101,6 +105,9 @@ import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
import com.plotsquared.core.util.uuid.UUIDWrapper;
import com.plotsquared.core.uuid.CacheUUIDService;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Actor;
@ -221,6 +228,43 @@ 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);
}
final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
impromptuPipeline.registerService(offlinePlayerUUIDService);
backgroundPipeline.registerService(offlinePlayerUUIDService);
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);
}
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService();
impromptuPipeline.registerService(sqLiteUUIDService);
backgroundPipeline.registerService(sqLiteUUIDService);
impromptuPipeline.registerConsumer(sqLiteUUIDService);
backgroundPipeline.registerConsumer(sqLiteUUIDService);
final SquirrelIdUUIDService impromptuMojangService = new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
impromptuPipeline.registerService(impromptuMojangService);
final SquirrelIdUUIDService backgroundMojangService = new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
backgroundPipeline.registerService(backgroundMojangService);
}
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new Placeholders().register();
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {

View File

@ -84,6 +84,7 @@ import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -123,6 +124,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -140,6 +142,11 @@ public class PlotSquared {
public final IPlotMain IMP;
// Current thread
private final Thread thread;
// UUID pipelines
@Getter private final UUIDPipeline impromptuUUIDPipeline =
new UUIDPipeline(Executors.newCachedThreadPool());
@Getter private final UUIDPipeline backgroundUUIDPipeline =
new UUIDPipeline(Executors.newSingleThreadExecutor());
// WorldEdit instance
public WorldEdit worldedit;
public File styleFile;

View File

@ -239,6 +239,12 @@ public class Settings extends Config {
@Comment("Use a database to store UUID/name info") public static boolean
USE_SQLUUIDHANDLER = false;
@Ignore public static boolean NATIVE_UUID_PROVIDER = false;
@Comment("How many UUIDs that may be stored in the cache")
public static int UUID_CACHE_SIZE = 100000;
@Comment("Rate limit (per 10 minutes) for background UUID fetching from the Mojang API")
public static int BACKGROUND_LIMIT = 200;
@Comment("Rate limit (per 10 minutes) for random UUID fetching from the Mojang API")
public static int IMPROMPTU_LIMIT = 300;
}