refactor: Deprecate IMP initializors in favor of builders

This commit is contained in:
NotMyFault
2021-12-22 20:58:23 +01:00
parent 34f971c729
commit 7da921e075
129 changed files with 750 additions and 677 deletions

View File

@ -860,8 +860,8 @@ public class BrushCommands {
}
String filenamePng = filename.endsWith(".png") ? filename : filename + ".png";
File file = new File(
Fawe.imp().getDirectory(),
Settings.IMP.PATHS.HEIGHTMAP + File.separator + filenamePng
Fawe.platform().getDirectory(),
Settings.settings().PATHS.HEIGHTMAP + File.separator + filenamePng
);
if (file.exists()) {
return new FileInputStream(file);
@ -936,7 +936,7 @@ public class BrushCommands {
if (tool != null) {
root |= name.startsWith("../");
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
File folder = MainUtil.getFile(Fawe.platform().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file;
if (root && player.hasPermission("worldedit.brush.save.other")) {
@ -971,7 +971,7 @@ public class BrushCommands {
public void loadBrush(Player player, LocalSession session, @Arg(desc = "String name") String name)
throws WorldEditException, IOException {
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
File folder = MainUtil.getFile(Fawe.platform().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file = new File(folder, player.getUniqueId() + File.separator + name);
if (!file.exists()) {
@ -1006,7 +1006,7 @@ public class BrushCommands {
int page
) throws WorldEditException {
String baseCmd = "/brush loadbrush";
File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
File dir = MainUtil.getFile(Fawe.platform().getDirectory(), "brushes");
// TODO NOT IMPLEMENTED
// UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
}
@ -1310,7 +1310,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(radius);
//FAWE start
FaweLimit limit = Settings.IMP.getLimit(player);
FaweLimit limit = Settings.settings().getLimit(player);
iterations = Math.min(limit.MAX_ITERATIONS, iterations);
//FAWE end
@ -1345,7 +1345,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(radius);
//FAWE start
FaweLimit limit = Settings.IMP.getLimit(player);
FaweLimit limit = Settings.settings().getLimit(player);
iterations = Math.min(limit.MAX_ITERATIONS, iterations);
//FAWE end

View File

@ -405,7 +405,7 @@ public class ClipboardCommands {
url = null;
}
} else {
if (Settings.IMP.WEB.URL.isEmpty()) {
if (Settings.settings().WEB.URL.isEmpty()) {
actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
return;
}

View File

@ -475,7 +475,7 @@ public class GeneralCommands {
String arg = arguments.get(0);
String argLower = arg.toLowerCase(Locale.ROOT);
TextureUtil util = Fawe.get().getTextureUtil();
TextureUtil util = Fawe.instance().getTextureUtil();
int randomIndex = 1;
boolean checkRandomization = true;
if (arguments.size() >= 2 && MathMan.isInteger(arguments.get(0)) && MathMan.isInteger(arguments.get(1))) {
@ -500,7 +500,7 @@ public class GeneralCommands {
Clipboard clipboard = session.getClipboard().getClipboard();
util = TextureUtil.fromClipboard(clipboard);
} else if (argLower.equals("*") || argLower.equals("true")) {
util = Fawe.get().getTextureUtil();
util = Fawe.instance().getTextureUtil();
} else {
ParserContext parserContext = new ParserContext();
parserContext.setActor(actor);

View File

@ -582,7 +582,7 @@ public class GenerationCommands {
@Arg(desc = "TODO", def = "100") int threshold,
@Arg(desc = "BlockVector2", def = "") BlockVector2 dimensions
) throws WorldEditException, IOException {
TextureUtil tu = Fawe.get().getCachedTextureUtil(randomize, 0, threshold);
TextureUtil tu = Fawe.instance().getCachedTextureUtil(randomize, 0, threshold);
URL url = new URL(imageURL);
if (!url.getHost().equalsIgnoreCase("i.imgur.com")) {
throw new IOException("Only i.imgur.com links are allowed!");

View File

@ -114,7 +114,7 @@ public class HistorySubCommands {
@Switch(name = 'f', desc = "Restore instead of rollback")
boolean restore
) throws WorldEditException {
if (!Settings.IMP.HISTORY.USE_DATABASE) {
if (!Settings.settings().HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with /history import )"));
return;
}
@ -168,7 +168,7 @@ public class HistorySubCommands {
@CommandPermissions("fawe.rollback.import")
@Confirm
public synchronized void importdb(Actor actor) throws WorldEditException {
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY);
File folder = MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HISTORY);
if (folder.exists()) {
for (File worldFolder : Objects.requireNonNull(folder.listFiles())) {
if (worldFolder != null && worldFolder.isDirectory()) {
@ -238,7 +238,7 @@ public class HistorySubCommands {
}
Location origin = player.getLocation();
String name = Fawe.imp().getName(edit.getUUID());
String name = Fawe.platform().getName(edit.getUUID());
String cmd = edit.getCommand();
BlockVector3 pos1 = edit.getMinimumPoint();
BlockVector3 pos2 = edit.getMaximumPoint();
@ -319,7 +319,7 @@ public class HistorySubCommands {
UUID uuid = rollback.getUUID();
int index = rollback.getIndex();
String name = Fawe.imp().getName(rollback.getUUID());
String name = Fawe.platform().getName(rollback.getUUID());
String cmd = rollback.getCommand();
BlockVector3 pos1 = rollback.getMinimumPoint();
@ -382,7 +382,7 @@ public class HistorySubCommands {
@ArgFlag(name = 'p', desc = "Page to view.", def = "")
Integer page
) throws WorldEditException {
if (!Settings.IMP.HISTORY.USE_DATABASE) {
if (!Settings.settings().HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with //history import )"));
return;
}

View File

@ -203,7 +203,7 @@ public class SchematicCommands {
} else {
final LocalConfiguration config = this.worldEdit.getConfiguration();
File working = this.worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File root = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
File root = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
uri = new File(root, fileName).toURI();
}
@ -238,13 +238,13 @@ public class SchematicCommands {
IOException {
LocalConfiguration config = worldEdit.getConfiguration();
File working = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
File destDir = new File(dir, directory);
if (!MainUtil.isInSubDirectory(working, destDir)) {
actor.print(Caption.of("worldedit.schematic.directory-does-not-exist", TextComponent.of(String.valueOf(destDir))));
return;
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, destDir) && !actor.hasPermission(
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, destDir) && !actor.hasPermission(
"worldedit.schematic.move.other")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.move.other"));
return;
@ -265,7 +265,7 @@ public class SchematicCommands {
actor.print(Caption.of("fawe.worldedit.schematic.schematic.move.exists", destFile));
continue;
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && (!MainUtil.isInSubDirectory(
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && (!MainUtil.isInSubDirectory(
dir,
destFile
) || !MainUtil.isInSubDirectory(dir, source)) && !actor.hasPermission("worldedit.schematic.delete.other")) {
@ -333,7 +333,7 @@ public class SchematicCommands {
return;
}
UUID uuid = UUID.fromString(filename.substring(4));
URL webUrl = new URL(Settings.IMP.WEB.URL);
URL webUrl = new URL(Settings.settings().WEB.URL);
format = ClipboardFormats.findByAlias(formatName);
URL url = new URL(webUrl, "uploads/" + uuid + "." + format.getPrimaryFileExtension());
ReadableByteChannel byteChannel = Channels.newChannel(url.openStream());
@ -341,7 +341,7 @@ public class SchematicCommands {
uri = url.toURI();
} else {
File saveDir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir;
File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir;
File file;
if (filename.startsWith("#")) {
format = ClipboardFormats.findByAlias(formatName);
@ -357,7 +357,7 @@ public class SchematicCommands {
return;
}
} else {
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !actor.hasPermission("worldedit.schematic.load.other") && Pattern
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && !actor.hasPermission("worldedit.schematic.load.other") && Pattern
.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
.matcher(filename)
.find()) {
@ -446,7 +446,7 @@ public class SchematicCommands {
File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
//FAWE start
if (!global && Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) {
if (!global && Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
dir = new File(dir, actor.getUniqueId().toString());
}
@ -580,7 +580,7 @@ public class SchematicCommands {
final boolean hasShow = false;
//If player forgot -p argument
boolean playerFolder = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
boolean playerFolder = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
UUID uuid = playerFolder ? actor.getUniqueId() : null;
List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
@ -670,14 +670,14 @@ public class SchematicCommands {
String headerBytesElem = String.format("%.1fkb", totalBytes / 1000.0);
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
headerBytesElem += String.format(
" / %dkb",
Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT
Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT
);
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS) {
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
String fullHeader = "| My Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
@ -704,7 +704,7 @@ public class SchematicCommands {
LocalConfiguration config = worldEdit.getConfiguration();
File working = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
//FAWE start
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
List<File> files = new ArrayList<>();
if (filename.equalsIgnoreCase("*")) {
@ -723,7 +723,7 @@ public class SchematicCommands {
actor.print(Caption.of("worldedit.schematic.delete.does-not-exist", TextComponent.of(filename)));
continue;
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, f) && !actor.hasPermission(
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, f) && !actor.hasPermission(
"worldedit.schematic.delete.other")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.delete.other"));
continue;
@ -806,8 +806,8 @@ public class SchematicCommands {
Clipboard target;
//FAWE start
boolean checkFilesize = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS
&& Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1;
boolean checkFilesize = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS
&& Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1;
double directorysizeKb = 0;
String curFilepath = file.getAbsolutePath();
@ -838,7 +838,7 @@ public class SchematicCommands {
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT > -1) {
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT > -1) {
if (numFiles == -1) {
numFiles = 0;
@ -851,7 +851,7 @@ public class SchematicCommands {
}
}
}
int limit = Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT;
int limit = Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT;
if (numFiles >= limit) {
TextComponent noSlotsErr = TextComponent.of( //TODO - to be moved into captions/translatablecomponents
@ -902,7 +902,7 @@ public class SchematicCommands {
if (checkFilesize) {
double curKb = filesizeKb + directorysizeKb;
int allocatedKb = Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT;
int allocatedKb = Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT;
if (overwrite) {
curKb -= oldKbOverwritten;
@ -937,11 +937,11 @@ public class SchematicCommands {
actor.print(kbRemainingNotif);
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT > -1) {
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT > -1) {
TextComponent slotsRemainingNotif = TextComponent.of(
//TODO - to be moved into captions/translatablecomponents
"You have " + (Settings.IMP.EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT - numFiles)
"You have " + (Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_NUM_LIMIT - numFiles)
+ " schematic file slots left.",
TextColor.GRAY
);

View File

@ -135,9 +135,9 @@ public class UtilityCommands {
@Arg(name = "max", desc = "int", def = "200") int max
) throws IOException {
actor.print(TextComponent.of("Please wait while we generate the minified heightmaps."));
File srcFolder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP);
File srcFolder = MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HEIGHTMAP);
File webSrc = new File(Fawe.imp().getDirectory(), "web" + File.separator + "heightmap");
File webSrc = new File(Fawe.platform().getDirectory(), "web" + File.separator + "heightmap");
File minImages = new File(webSrc, "images" + File.separator + "min");
File maxImages = new File(webSrc, "images" + File.separator + "max");
final int sub = srcFolder.getAbsolutePath().length();
@ -698,7 +698,7 @@ public class UtilityCommands {
//FAWE start - run this sync
int finalRadius = radius;
int killed = TaskManager.IMP.sync(() -> killMatchingEntities(finalRadius, actor, flags::createFunction));
int killed = TaskManager.taskManager().sync(() -> killMatchingEntities(finalRadius, actor, flags::createFunction));
//FAWE end
actor.print(Caption.of(
@ -730,7 +730,7 @@ public class UtilityCommands {
}
//FAWE start - run this sync
int removed = TaskManager.IMP.sync(() -> killMatchingEntities(radius, actor, remover::createFunction));
int removed = TaskManager.taskManager().sync(() -> killMatchingEntities(radius, actor, remover::createFunction));
//FAWE end
actor.print(Caption.of("worldedit.remove.removed", TextComponent.of(removed)));
return removed;
@ -953,7 +953,7 @@ public class UtilityCommands {
String dirFilter = File.separator;
boolean listMine = false;
boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
boolean listGlobal = !Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
if (len > 0) {
for (String arg : args) {
switch (arg.toLowerCase(Locale.ROOT)) {
@ -982,7 +982,7 @@ public class UtilityCommands {
if (!exists) {
arg = arg.substring(0, arg.length() - File.separator.length());
if (arg.length() > 3 && arg.length() <= 16) {
UUID fromName = Fawe.imp().getUUID(arg);
UUID fromName = Fawe.platform().getUUID(arg);
if (fromName != null) {
newDirFilter = dirFilter + fromName + File.separator;
listGlobal = true;
@ -1103,7 +1103,7 @@ public class UtilityCommands {
if (newList.isEmpty()) {
String checkName = filter.replace("\\", "/").split("/")[0];
if (checkName.length() > 3 && checkName.length() <= 16) {
UUID fromName = Fawe.imp().getUUID(checkName);
UUID fromName = Fawe.platform().getUUID(checkName);
if (fromName != null) {
lowerFilter = filter.replaceFirst(checkName, fromName.toString()).toLowerCase(Locale.ROOT);
for (int i = 0; i < normalizedNames.length; i++) {

View File

@ -81,7 +81,7 @@ public class WorldEditCommands {
@CommandPermissions(queued = false)
public void version(Actor actor) {
//FAWE start - use own, minimized message that doesn't print "Platforms" and "Capabilities"
FaweVersion fVer = Fawe.get().getVersion();
FaweVersion fVer = Fawe.instance().getVersion();
String fVerStr = fVer == null ? "unknown" : "-" + fVer.build;
actor.print(TextComponent.of("FastAsyncWorldEdit" + fVerStr));
actor.print(TextComponent.of("Authors: Empire92, MattBDev, IronApollo, dordsor21 and NotMyFault"));
@ -105,7 +105,7 @@ public class WorldEditCommands {
.queryCapability(Capability.CONFIGURATION)
.getConfiguration()));
//FAWE start
Fawe.get().setupConfigs();
Fawe.instance().setupConfigs();
//FAWE end
actor.print(Caption.of("worldedit.reload.config"));
}
@ -120,9 +120,9 @@ public class WorldEditCommands {
String dest;
try {
final File logFile = new File("logs/latest.log");
final File config = new File(Fawe.imp().getDirectory(), "config.yml");
final File worldeditConfig = new File(Fawe.imp().getDirectory(), "worldedit-config.yml");
dest = IncendoPaster.debugPaste(logFile, Fawe.imp().getDebugInfo(), config, worldeditConfig);
final File config = new File(Fawe.platform().getDirectory(), "config.yml");
final File worldeditConfig = new File(Fawe.platform().getDirectory(), "worldedit-config.yml");
dest = IncendoPaster.debugPaste(logFile, Fawe.platform().getDebugInfo(), config, worldeditConfig);
} catch (IOException e) {
actor.printInfo(TextComponent.of(e.getMessage()));
return;

View File

@ -56,7 +56,7 @@ public enum SelectionWand implements DoubleActionBlockTool {
if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
//FAWE start
if (Settings.IMP.EXPERIMENTAL.OTHER) {
if (Settings.settings().EXPERIMENTAL.OTHER) {
LOGGER.info("actSecondary Hit and about to explain with explainPrimarySelection");
}
//FAWE end
@ -79,7 +79,7 @@ public enum SelectionWand implements DoubleActionBlockTool {
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
//FAWE start
if (Settings.IMP.EXPERIMENTAL.OTHER) {
if (Settings.settings().EXPERIMENTAL.OTHER) {
LOGGER.info("actPrimary Hit and about to explain with explainSecondarySelection");
}
//FAWE end

View File

@ -148,7 +148,7 @@ public class EntityRemover {
if (registryType != null) {
if (type.matches(registryType)) {
//FAWE start - Calling this async violates thread safety
TaskManager.IMP.sync(entity::remove);
TaskManager.taskManager().sync(entity::remove);
//FAWE end
return true;
}

View File

@ -29,7 +29,7 @@ public class ConfirmHandler implements CommandCallListener {
}
Actor actor = actorOpt.get();
// don't check confirmation if actor doesn't need to confirm
if (!Settings.IMP.getLimit(actor).CONFIRM_LARGE) {
if (!Settings.settings().getLimit(actor).CONFIRM_LARGE) {
return;
}
if (!confirmAnnotation.value().passes(actor, parameters, 1)) {

View File

@ -32,7 +32,7 @@ public @interface Preload {
@Override
public void preload(Actor actor, InjectedValueAccess context) {
World world = context.injectedValue(Key.of(EditSession.class)).get().getWorld();
Preloader preloader = Fawe.imp().getPreloader(true);
Preloader preloader = Fawe.platform().getPreloader(true);
if (preloader != null) {
preloader.update(actor, world);
}

View File

@ -29,7 +29,7 @@ public class PreloadHandler implements CommandCallListener {
}
Actor actor = actorOpt.get();
// Don't attempt to preload if effectively disabled
if (Settings.IMP.QUEUE.PRELOAD_CHUNK_COUNT <= 1) {
if (Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT <= 1) {
return;
}
preloadAnnotation.value().preload(actor, parameters);