Skip to content
Open
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
5 changes: 3 additions & 2 deletions plugins/fancyworlds/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("java-library")
id("maven-publish")

id("io.papermc.paperweight.userdev")
id("xyz.jpenilla.run-paper")
id("com.gradleup.shadow")
}
Expand Down Expand Up @@ -30,7 +31,7 @@ allprojects {
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
paperweight.foliaDevBundle("1.21.11-R0.1-SNAPSHOT")

implementation(project(":plugins:fancyworlds:fw-api"))

Expand Down Expand Up @@ -119,4 +120,4 @@ val gitCommitMessage: Provider<String> = providers.exec {

fun getFWVersion(): String {
return file("VERSION").readText()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fancyinnovations.fancyworlds.api.worlds.WorldService;
import com.fancyinnovations.fancyworlds.utils.FancyContext;
import com.fancyinnovations.fancyworlds.utils.WorldFileUtils;
import com.fancyinnovations.fancyworlds.worlds.FWorldImpl;
import com.fancyinnovations.fancyworlds.worlds.FWorldSettingsImpl;
import com.fancyinnovations.fancyworlds.utils.WorldFileUtils;
import org.bukkit.World;
import revxrsal.commands.annotation.*;
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
Expand Down Expand Up @@ -59,20 +59,20 @@ public void create(
.replace("worldName", name)
.send(actor.sender());

World world = fworld.toWorldCreator().createWorld();
if (world == null) {
service.registerWorld(fworld);
plugin.getWorldPlatformView().createWorld(fworld).thenAccept(world -> {
fworld.setBukkitWorld(world);
translator.translate("commands.world.create.success")
.withPrefix()
.replace("worldName", name)
.send(actor.sender());
}).exceptionally(throwable -> {
service.unregisterWorld(fworld);
translator.translate("commands.world.create.failed")
.withPrefix()
.replace("worldName", name)
.send(actor.sender());
return;
}

fworld.setBukkitWorld(world);
service.registerWorld(fworld);
translator.translate("commands.world.create.success")
.withPrefix()
.replace("worldName", name)
.send(actor.sender());
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;

public class WorldDeleteCMD extends FancyContext {

Expand All @@ -37,30 +39,29 @@ public void delete(
SimpleMessage question = (SimpleMessage) translator.translate("commands.world.delete.confirmation")
.replace("worldName", world.getName());

new ConfirmationDialog(question.getMessage())
.withTitle("Confirm deletion")
.withOnConfirm(() -> Bukkit.getScheduler().runTask(plugin, () -> deleteImpl(actor, world)))
.withOnCancel(
() -> translator.translate("commands.world.delete.cancelled")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender())
)
.ask(actor.asPlayer());
if (actor.isPlayer()) {
new ConfirmationDialog(question.getMessage())
.withTitle("Confirm deletion")
.withOnConfirm(() -> deleteImpl(actor, world))
.withOnCancel(
() -> translator.translate("commands.world.delete.cancelled")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender())
)
.ask(actor.asPlayer());
} else {
deleteImpl(actor, world);
}
}

private void deleteImpl(
final BukkitCommandActor actor,
final FWorld world
) {
plugin.getWorldService().unregisterWorld(world);

File worldDir = Bukkit.getWorldContainer().toPath().resolve(world.getName()).toFile();
try {
Files.walk(worldDir.toPath())
.map(Path::toFile)
.sorted((o1, o2) -> -o1.compareTo(o2)) // Delete children before parents
.forEach(File::delete);
deleteWorldDirectory(worldDir.toPath());
} catch (IOException e) {
translator.translate("commands.world.delete.failed")
.withPrefix()
Expand All @@ -69,9 +70,23 @@ private void deleteImpl(
return;
}

plugin.getWorldService().unregisterWorld(world);

translator.translate("commands.world.delete.success")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender());
}

private void deleteWorldDirectory(Path worldPath) throws IOException {
if (!Files.exists(worldPath)) {
return;
}

try (Stream<Path> walk = Files.walk(worldPath)) {
for (Path path : walk.sorted(Comparator.reverseOrder()).toList()) {
Files.delete(path);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ public void setSpawn(
}
}

world.getBukkitWorld().setDifficulty(difficulty);
if (!world.isWorldLoaded()) {
translator.translate("common.world_not_loaded")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender());
return;
}

final FWorld finalWorld = world;
plugin.runGlobalTask(() -> {
finalWorld.getBukkitWorld().setDifficulty(difficulty);

translator.translate("commands.world.difficulty.set.success")
.withPrefix()
.replace("worldName", world.getName())
.replace("difficulty", difficulty.name())
.send(actor.sender());
translator.translate("commands.world.difficulty.set.success")
.withPrefix()
.replace("worldName", finalWorld.getName())
.replace("difficulty", difficulty.name())
.send(actor.sender());
});
}

@Command({"world difficulty current", "difficulty current"})
Expand All @@ -60,12 +71,23 @@ public void current(
}
}

Difficulty difficulty = world.getBukkitWorld().getDifficulty();
if (!world.isWorldLoaded()) {
translator.translate("common.world_not_loaded")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender());
return;
}

final FWorld finalWorld = world;
plugin.runGlobalTask(() -> {
Difficulty difficulty = finalWorld.getBukkitWorld().getDifficulty();

translator.translate("commands.world.difficulty.current")
.withPrefix()
.replace("worldName", world.getName())
.replace("difficulty", difficulty.name())
.send(actor.sender());
translator.translate("commands.world.difficulty.current")
.withPrefix()
.replace("worldName", finalWorld.getName())
.replace("difficulty", difficulty.name())
.send(actor.sender());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,38 @@ public void list(
return;
}

translator.translate("commands.world.gamerules.list.header")
.withPrefix()
.replace("worldName", world.getName())
.send(actor.sender());

FWorld finalWorld = world;
Registry.GAME_RULE.stream().forEach(gameRule -> {
if (!finalWorld.getBukkitWorld().isGameRule(gameRule.key().value())) {
return;
}
plugin.runGlobalTask(() -> {
translator.translate("commands.world.gamerules.list.header")
.withPrefix()
.replace("worldName", finalWorld.getName())
.send(actor.sender());

Object value = finalWorld.getBukkitWorld().getGameRuleValue(gameRule);
if (value == null) {
value = "null";
}
Registry.GAME_RULE.stream().forEach(gameRule -> {
if (!finalWorld.getBukkitWorld().isGameRule(gameRule.key().value())) {
return;
}

Object defaultValue = finalWorld.getBukkitWorld().getGameRuleDefault(gameRule);
if (defaultValue == null) {
defaultValue = "null";
}
Object value = finalWorld.getBukkitWorld().getGameRuleValue(gameRule);
if (value == null) {
value = "null";
}

if (changedOnly && value.equals(defaultValue)) {
return;
}
Object defaultValue = finalWorld.getBukkitWorld().getGameRuleDefault(gameRule);
if (defaultValue == null) {
defaultValue = "null";
}

translator.translate("commands.world.gamerules.list.entry")
.replace("gamerule", gameRule.getKey().getKey())
.replace("value", value.toString())
.replace("defaultValue", defaultValue.toString())
.send(actor.sender());
if (changedOnly && value.equals(defaultValue)) {
return;
}

translator.translate("commands.world.gamerules.list.entry")
.replace("gamerule", gameRule.getKey().getKey())
.replace("value", value.toString())
.replace("defaultValue", defaultValue.toString())
.send(actor.sender());
});
});
}

Expand Down Expand Up @@ -110,24 +112,27 @@ public void set(
return;
}

final FWorld finalWorldForSet = world;
if (value.equalsIgnoreCase("@default")) {
Object defaultValue = world.getBukkitWorld().getGameRuleDefault(gamerule);
if (defaultValue == null) {
translator.translate("commands.world.gamerules.set.failed")
plugin.runGlobalTask(() -> {
Object defaultValue = finalWorldForSet.getBukkitWorld().getGameRuleDefault(gamerule);
if (defaultValue == null) {
translator.translate("commands.world.gamerules.set.failed")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("worldName", finalWorldForSet.getName())
.send(actor.sender());
return;
}

finalWorldForSet.getBukkitWorld().setGameRule(gamerule, defaultValue);
translator.translate("commands.world.gamerules.set.success")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("worldName", world.getName())
.replace("value", defaultValue.toString())
.replace("worldName", finalWorldForSet.getName())
.send(actor.sender());
return;
}

world.getBukkitWorld().setGameRule(gamerule, defaultValue);
translator.translate("commands.world.gamerules.set.success")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("value", defaultValue.toString())
.replace("worldName", world.getName())
.send(actor.sender());
});
return;
}

Expand All @@ -147,7 +152,15 @@ public void set(
.send(actor.sender());
return;
}
world.getBukkitWorld().setGameRule(gamerule, booleanValue);
plugin.runGlobalTask(() -> {
finalWorldForSet.getBukkitWorld().setGameRule(gamerule, booleanValue);
translator.translate("commands.world.gamerules.set.success")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("value", value)
.replace("worldName", finalWorldForSet.getName())
.send(actor.sender());
});
}
case "Integer" -> {
int intValue;
Expand All @@ -162,23 +175,24 @@ public void set(
.send(actor.sender());
return;
}
world.getBukkitWorld().setGameRule(gamerule, intValue);
plugin.runGlobalTask(() -> {
finalWorldForSet.getBukkitWorld().setGameRule(gamerule, intValue);
translator.translate("commands.world.gamerules.set.success")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("value", value)
.replace("worldName", finalWorldForSet.getName())
.send(actor.sender());
});
}
default -> {
translator.translate("commands.world.gamerules.set.failed")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("worldName", world.getName())
.replace("worldName", finalWorldForSet.getName())
.send(actor.sender());
throw new UnsupportedOperationException("Unsupported gamerule type: " + gamerule.getType().getSimpleName());
}
}

translator.translate("commands.world.gamerules.set.success")
.withPrefix()
.replace("gameruleName", gamerule.getKey().getKey())
.replace("value", value)
.replace("worldName", world.getName())
.send(actor.sender());
}
}
Loading