Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ public interface WorldService {
*
* @param buildWorld The world to unimport
* @param save Whether to save the world before unloading
* @return A future that completes when the unimport operation is finished
*/
CompletableFuture<Void> unimportWorld(BuildWorld buildWorld, boolean save);

/**
* Delete an existing {@link BuildWorld}. In comparison to {@link #unimportWorld(BuildWorld, boolean)}, deleting a world deletes the world's directory.
*
* @param buildWorld The world to be deleted
* @return A future that completes when the delete operation is finished
*/
CompletableFuture<Void> deleteWorld(BuildWorld buildWorld);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@
@NullMarked
public interface CustomGenerator {

/**
* Gets the name plugin providing the chunk generator.
*
* @return The name of the plugin
*/
String pluginName();

/**
* Gets the name of the chunk generator.
*
* @return The name
* @return The name of the chunk generator
*/
String name();
String chunkGeneratorName();

/**
* Gets the chunk generator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import de.eintosti.buildsystem.world.display.CustomizableIcons;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
import org.bstats.bukkit.Metrics;
Expand Down Expand Up @@ -169,10 +168,9 @@ public void onEnable() {

Bukkit.getScheduler().runTaskTimer(this, this::saveBuildConfig, 6000L, 6000L);

Bukkit.getConsoleSender().sendMessage(String.format(Locale.ROOT,
"%sBuildSystem » Plugin %senabled%s!",
ChatColor.RESET, ChatColor.GREEN, ChatColor.RESET
));
Bukkit.getConsoleSender().sendMessage(
"%sBuildSystem » Plugin %senabled%s!".formatted(ChatColor.RESET, ChatColor.GREEN, ChatColor.RESET)
);
}

@Override
Expand All @@ -196,10 +194,9 @@ public void onDisable() {
unregisterExpansions();
this.api.unregister();

Bukkit.getConsoleSender().sendMessage(String.format(Locale.ROOT,
"%sBuildSystem » Plugin %sdisabled%s!",
ChatColor.RESET, ChatColor.RED, ChatColor.RESET
));
Bukkit.getConsoleSender().sendMessage(
"%sBuildSystem » Plugin %sdisabled%s!".formatted(ChatColor.RESET, ChatColor.RED, ChatColor.RESET)
);
}

private void initClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void sendUsageMessage(Player player) {
}

private void setPlayerGamemode(Player player, GameMode gameMode, String gameModeName) {
if (!player.hasPermission(String.format("buildsystem.gamemode.%s", gameMode.name().toLowerCase(Locale.ROOT)))) {
if (!player.hasPermission("buildsystem.gamemode.%s".formatted(gameMode.name().toLowerCase(Locale.ROOT)))) {
Messages.sendPermissionError(player);
return;
}
Expand All @@ -103,7 +103,7 @@ private void setPlayerGamemode(Player player, GameMode gameMode, String gameMode
}

private void setTargetGamemode(Player player, String[] args, GameMode gameMode, String gameModeName) {
if (!player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameMode.name().toLowerCase(Locale.ROOT)))) {
if (!player.hasPermission("buildsystem.gamemode.%s.other".formatted(gameMode.name().toLowerCase(Locale.ROOT)))) {
Messages.sendPermissionError(player);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void execute(Player player, String[] args) {
}

Location playerLocation = player.getLocation();
buildWorld.getData().customSpawn().set(String.format("%s;%s;%s;%s;%s",
buildWorld.getData().customSpawn().set("%s;%s;%s;%s;%s".formatted(
playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), playerLocation.getYaw(), playerLocation.getPitch()
));
Messages.sendMessage(player, "worlds_setspawn_world_spawn_set",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Map<String, Object> serializeWorld(BuildWorld buildWorld) {
world.put("date", buildWorld.getCreation());
world.put("builders", serializeBuilders(builders.getAllBuilders()));
if (buildWorld.getCustomGenerator() != null) {
world.put("chunk-generator", buildWorld.getCustomGenerator().name());
world.put("chunk-generator", buildWorld.getCustomGenerator().toString());
}

return world;
Expand Down Expand Up @@ -170,7 +170,7 @@ private BuildWorldImpl loadWorld(String worldName) {
List<Builder> builders = parseBuilders(worldName);
String generatorName = config.getString("worlds." + worldName + ".chunk-generator");
CustomGeneratorImpl customGenerator = generatorName != null
? new CustomGeneratorImpl(generatorName, parseChunkGenerator(worldName, generatorName))
? CustomGeneratorImpl.of(generatorName, worldName)
: null;

return new BuildWorldImpl(
Expand Down Expand Up @@ -284,19 +284,6 @@ private List<Builder> parseBuilders(String worldName) {
return builders;
}

/**
* @author Ein_Jojo, einTosti
*/
@Nullable
private ChunkGenerator parseChunkGenerator(String worldName, String generatorName) {
String[] generatorInfo = generatorName.split(":");
if (generatorInfo.length == 1) {
generatorInfo = new String[]{generatorInfo[0], generatorInfo[0]};
}

return getChunkGenerator(generatorInfo[0], generatorInfo[1], worldName);
}

/**
* Gets the {@link ChunkGenerator} for the generation of a {@link BuildWorld} with {@link BuildWorldType#CUSTOM}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
if (args.length == 1) {
Arrays.stream(GameMode.values())
.map(gameMode -> gameMode.name().toLowerCase(Locale.ROOT))
.filter(gameModeName -> player.hasPermission(String.format("buildsystem.gamemode.%s", gameModeName)))
.filter(gameModeName -> player.hasPermission("buildsystem.gamemode.%s".formatted(gameModeName)))
.forEach(gameModeName -> addArgument(args[0], gameModeName, arrayList));
} else if (args.length == 2) {
String gameModeName = switch (args[0].toLowerCase(Locale.ROOT)) {
Expand All @@ -58,7 +58,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
default -> null;
};

if (gameModeName != null && player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameModeName))) {
if (gameModeName != null && player.hasPermission("buildsystem.gamemode.%s.other".formatted(gameModeName))) {
Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[1], pl.getName(), arrayList));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static UUID getUUID(String name) {
}

try {
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(Locale.ROOT, UUID_URL, name)).openConnection();
HttpURLConnection connection = (HttpURLConnection) new URL(UUID_URL.formatted(name)).openConnection();
connection.setReadTimeout(5000);

JsonObject jsonObject;
Expand Down Expand Up @@ -110,7 +110,7 @@ public static String getName(UUID uuid) {
}

try {
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(Locale.ROOT, NAME_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
HttpURLConnection connection = (HttpURLConnection) new URL(NAME_URL.formatted(UUIDTypeAdapter.fromUUID(uuid))).openConnection();
connection.setReadTimeout(5000);

JsonArray nameHistory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -153,7 +152,7 @@ public CompletableFuture<UpdateResult> requestUpdateCheck() {
int responseCode;

try {
URL url = URI.create(String.format(Locale.ROOT, UPDATE_URL, pluginID)).toURL();
URL url = URI.create(UPDATE_URL.formatted(pluginID)).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("User-Agent", USER_AGENT);
responseCode = connection.getResponseCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.eintosti.buildsystem.api.world.BuildWorld;
import de.eintosti.buildsystem.api.world.WorldService;
import de.eintosti.buildsystem.api.world.builder.Builder;
import de.eintosti.buildsystem.api.world.creation.generator.CustomGenerator;
import de.eintosti.buildsystem.api.world.creation.generator.Generator;
import de.eintosti.buildsystem.api.world.data.BuildWorldType;
import de.eintosti.buildsystem.api.world.display.Folder;
Expand Down Expand Up @@ -55,8 +56,6 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -124,19 +123,13 @@ public void startWorldNameInput(Player player, BuildWorldType worldType, @Nullab

private void startCustomGeneratorInput(Player player, String worldName, @Nullable String template, boolean privateWorld, @Nullable Folder folder) {
new PlayerChatInput(plugin, player, "enter_generator_name", input -> {
String[] generatorInfo = input.split(":");
if (generatorInfo.length == 1) {
generatorInfo = new String[]{generatorInfo[0], generatorInfo[0]};
}

ChunkGenerator chunkGenerator = getChunkGenerator(generatorInfo[0], generatorInfo[1], worldName);
if (chunkGenerator == null) {
CustomGenerator customGenerator = CustomGeneratorImpl.of(input, worldName);
if (customGenerator == null) {
Messages.sendMessage(player, "worlds_import_unknown_generator");
XSound.ENTITY_ITEM_BREAK.play(player);
return;
}

CustomGeneratorImpl customGenerator = new CustomGeneratorImpl(generatorInfo[0], chunkGenerator);
createWorld(worldName)
.setType(BuildWorldType.CUSTOM)
.setTemplate(template)
Expand All @@ -147,30 +140,11 @@ private void startCustomGeneratorInput(Player player, String worldName, @Nullabl
});
}

@Nullable
public ChunkGenerator getChunkGenerator(@Nullable String generator, String generatorId, String worldName) {
if (generator == null) {
return null;
}

Plugin plugin = Bukkit.getPluginManager().getPlugin(generator);
if (plugin == null) {
return null;
}

return plugin.getDefaultWorldGenerator(worldName, generatorId);
}

public boolean importWorld(Player player, String worldName, @Nullable Builder creator, BuildWorldType worldType, Generator generator, String generatorName, boolean single) {
ChunkGenerator chunkGenerator = null;
public boolean importWorld(Player player, String worldName, @Nullable Builder creator, BuildWorldType worldType, Generator generator, String generatorData, boolean single) {
CustomGenerator customGenerator = null;
if (generator == Generator.CUSTOM) {
String[] generatorInfo = generatorName.split(":");
if (generatorInfo.length == 1) {
generatorInfo = new String[]{generatorInfo[0], generatorInfo[0]};
}

chunkGenerator = getChunkGenerator(generatorInfo[0], generatorInfo[1], worldName);
if (chunkGenerator == null) {
customGenerator = CustomGeneratorImpl.of(generatorData, worldName);
if (customGenerator == null) {
Messages.sendMessage(player, "worlds_import_unknown_generator");
return false;
}
Expand All @@ -179,7 +153,7 @@ public boolean importWorld(Player player, String worldName, @Nullable Builder cr
BuildWorldCreatorImpl worldCreator = createWorld(worldName)
.setType(worldType)
.setCreator(creator)
.setCustomGenerator(new CustomGeneratorImpl(generatorName, chunkGenerator))
.setCustomGenerator(customGenerator != null ? customGenerator : new CustomGeneratorImpl("BuildSystem", generatorData, null))
.setPrivate(false)
.setCreationDate(FileUtils.getDirectoryCreation(new File(Bukkit.getWorldContainer(), worldName)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public CompletableFuture<Backup> storeBackup(BuildWorld buildWorld) {
throw new RuntimeException("Failed to complete the backup for " + buildWorld.getName());
}

plugin.getLogger().info(String.format("Backed up world '%s'. Took %sms", buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
plugin.getLogger().info("Backed up world '%s'. Took %sms".formatted(buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
return new BackupImpl(
plugin.getBackupService().getProfile(buildWorld),
timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public CompletableFuture<Backup> storeBackup(BuildWorld buildWorld) {
.build(),
RequestBody.fromBytes(zipBytes)
);
plugin.getLogger().info(String.format("Backed up world '%s'. Took %sms", buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
plugin.getLogger().info("Backed up world '%s'. Took %sms".formatted(buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
return new BackupImpl(plugin.getBackupService().getProfile(buildWorld), timestamp, key);
} catch (S3Exception | SdkClientException e) {
throw new RuntimeException("Failed to upload backup for " + buildWorld.getName(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public synchronized CompletableFuture<Backup> storeBackup(BuildWorld buildWorld)
bufferedOut.flush();
}

plugin.getLogger().info(String.format("Backed up world '%s'. Took %sms", buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
plugin.getLogger().info("Backed up world '%s'. Took %sms".formatted(buildWorld.getName(), (System.currentTimeMillis() - timestamp)));
return new BackupImpl(plugin.getBackupService().getProfile(buildWorld), timestamp, remotePath);
} catch (IOException e) {
disconnectAll();
Expand Down
Loading