Skip to content

Commit

Permalink
WorldEdit goes on an adventure
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Aug 11, 2020
1 parent ffaf8e0 commit a872c37
Show file tree
Hide file tree
Showing 47 changed files with 182 additions and 167 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/LibsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fun Project.applyLibrariesConfiguration() {
group = "${rootProject.group}.worldedit-libs"

val relocations = mapOf(
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
"net.kyori.adventure.text" to "com.sk89q.worldedit.util.formatting.text",
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori"
)

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.gradle.api.Project

object Versions {
const val TEXT = "3.0.4"
const val TEXT_EXTRAS = "3.0.6"
const val ADVENTURE = "4.0.0-SNAPSHOT"
const val ADVENTURE_EXTRAS = "4.0.0-SNAPSHOT"
const val PISTON = "0.5.6"
const val AUTO_VALUE = "1.7"
const val JUNIT = "5.6.1"
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ listOf("bukkit", "core", "forge", "sponge", "fabric", "cli").forEach {
include("worldedit-libs:core:ap")

include("worldedit-core:doctools")

includeBuild("../Piston") {
dependencySubstitution {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import com.sk89q.worldedit.util.formatting.WorldEditText;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -46,6 +47,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements

private static final String UUID_PREFIX = "CMD";

private final Audience audience;
private final BlockCommandSender sender;
private final WorldEditPlugin plugin;
private final Location location;
Expand All @@ -55,6 +57,7 @@ public BukkitBlockCommandSender(WorldEditPlugin plugin, BlockCommandSender sende
checkNotNull(plugin);
checkNotNull(sender);

this.audience = BukkitAudiences.create(plugin).audience(sender);
this.plugin = plugin;
this.sender = sender;
this.location = BukkitAdapter.adapt(sender.getBlock().getLocation());
Expand All @@ -78,29 +81,29 @@ public void printRaw(String msg) {
@Deprecated
public void print(String msg) {
for (String part : msg.split("\n")) {
print(TextComponent.of(part, TextColor.LIGHT_PURPLE));
print(TextComponent.of(part, NamedTextColor.LIGHT_PURPLE));
}
}

@Override
@Deprecated
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
print(TextComponent.of(part, TextColor.GRAY));
print(TextComponent.of(part, NamedTextColor.GRAY));
}
}

@Override
@Deprecated
public void printError(String msg) {
for (String part : msg.split("\n")) {
print(TextComponent.of(part, TextColor.RED));
print(TextComponent.of(part, NamedTextColor.RED));
}
}

@Override
public void print(Component component) {
TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale()));
audience.sendMessage(WorldEditText.format(component, getLocale()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.formatting.WorldEditText;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Locale;
import java.util.UUID;
import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
Expand All @@ -42,15 +42,15 @@ public class BukkitCommandSender extends AbstractNonPlayerActor {
*/
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");

private final Audience audience;
private final CommandSender sender;
private final WorldEditPlugin plugin;

public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
checkNotNull(plugin);
checkNotNull(sender);
checkArgument(!(sender instanceof Player), "Cannot wrap a player");

this.plugin = plugin;
this.audience = BukkitAudiences.create(plugin).audience(sender);
this.sender = sender;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale()));
audience.sendMessage(WorldEditText.format(component, getLocale()));
}

@Override
Expand Down Expand Up @@ -127,7 +127,6 @@ public CommandSender getSender() {
@Override
public SessionKey getSessionKey() {
return new SessionKey() {
@Nullable
@Override
public String getName() {
return sender.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand All @@ -58,6 +59,7 @@ public class BukkitPlayer extends AbstractPlayerActor {

private final Player player;
private final WorldEditPlugin plugin;
private final Audience audience;

public BukkitPlayer(Player player) {
this(WorldEditPlugin.getInstance(), player);
Expand All @@ -66,6 +68,7 @@ public BukkitPlayer(Player player) {
public BukkitPlayer(WorldEditPlugin plugin, Player player) {
this.plugin = plugin;
this.player = player;
this.audience = BukkitAudiences.create(plugin).player(player);
}

@Override
Expand Down Expand Up @@ -138,7 +141,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale()));
audience.sendMessage(WorldEditText.format(component, getLocale()));
}

@Override
Expand Down Expand Up @@ -233,7 +236,7 @@ public Locale getLocale() {
public void sendAnnouncements() {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() == null) {
printError(TranslatableComponent.of("worldedit.version.bukkit.unsupported-adapter",
TextComponent.of("https://enginehub.org/worldedit/#downloads", TextColor.AQUA)
TextComponent.of("https://enginehub.org/worldedit/#downloads", NamedTextColor.AQUA)
.clickEvent(ClickEvent.openUrl("https://enginehub.org/worldedit/#downloads"))));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
print(PlainComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())));
print(PlainComponentSerializer.plain().serialize(WorldEditText.format(component, getLocale())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
Expand Down Expand Up @@ -736,14 +736,14 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce
} catch (ScriptException e) {
// non-exceptional return check
if (!(Throwables.getRootCause(e) instanceof ReturnException)) {
player.printError(TranslatableComponent.of("worldedit.script.failed", TextComponent.of(e.getMessage(), TextColor.WHITE)));
player.printError(TranslatableComponent.of("worldedit.script.failed", TextComponent.of(e.getMessage(), NamedTextColor.WHITE)));
logger.warn("Failed to execute script", e);
}
} catch (NumberFormatException | WorldEditException e) {
throw e;
} catch (Throwable e) {
player.printError(TranslatableComponent.of("worldedit.script.failed-console", TextComponent.of(e.getClass().getCanonicalName(),
TextColor.WHITE)));
NamedTextColor.WHITE)));
logger.warn("Failed to execute script", e);
} finally {
for (EditSession editSession : scriptContext.getEditSessions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void item(CommandParameters parameters,
@Arg(desc = "The direction in which the item will be applied", def = "up")
@Direction(includeDiagonals = true)
com.sk89q.worldedit.util.Direction direction) throws WorldEditException {
player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD)
player.print(TextComponent.builder().append("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD)
.append(TranslatableComponent.of("worldedit.brush.apply.item.warning")).build());
setApplyBrush(parameters, player, localSession, new ItemUseFactory(item, direction));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.LegacyChunkStore;
import com.sk89q.worldedit.world.storage.McRegionChunkStore;
Expand Down Expand Up @@ -175,8 +175,8 @@ public void deleteChunks(Actor actor, World world, LocalSession session,
currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum())
));
}
actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE)
.append(TextComponent.of("/stop", TextColor.AQUA)
actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", NamedTextColor.LIGHT_PURPLE)
.append(TextComponent.of("/stop", NamedTextColor.AQUA)
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop"))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.CommandManager;
Expand Down Expand Up @@ -163,7 +163,7 @@ public void limit(Actor actor, LocalSession session,
session.setBlockChangeLimit(limit);
Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.limit.set", TextComponent.of(limit)));
if (limit != config.defaultChangeLimit) {
component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", TextColor.GRAY));
component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", NamedTextColor.GRAY));
}
actor.printInfo(component);
}
Expand All @@ -190,7 +190,7 @@ public void timeout(Actor actor, LocalSession session,
session.setTimeout(limit);
Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.timeout.set", TextComponent.of(limit)));
if (limit != config.calculationTimeout) {
component.append(TranslatableComponent.of("worldedit.timeout.return-to-default", TextColor.GRAY));
component.append(TranslatableComponent.of("worldedit.timeout.return-to-default", NamedTextColor.GRAY));
}
actor.printInfo(component);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
Expand Down Expand Up @@ -189,8 +189,8 @@ private static class SnapshotListBox extends PaginationBox {
@Override
public Component getComponent(int number) {
final Snapshot snapshot = snapshots.get(number);
return TextComponent.of(number + 1 + ". ", TextColor.GOLD)
.append(TextComponent.of(snapshot.getName(), TextColor.LIGHT_PURPLE)
return TextComponent.of(number + 1 + ". ", NamedTextColor.GOLD)
.append(TextComponent.of(snapshot.getName(), NamedTextColor.LIGHT_PURPLE)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to use")))
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/snap use " + snapshot.getName())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
Expand Down Expand Up @@ -130,7 +130,7 @@ public void item(CommandParameters parameters,
@Arg(desc = "The direction in which the item will be applied", def = "up")
@Direction(includeDiagonals = true)
com.sk89q.worldedit.util.Direction direction) throws WorldEditException {
player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD)
player.print(TextComponent.builder().append("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD)
.append(TranslatableComponent.of("worldedit.brush.paint.item.warning")).build());
setPaintBrush(parameters, player, localSession, new ItemUseFactory(item, direction));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor;
import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldedit.util.io.file.FilenameException;
import org.enginehub.piston.annotation.Command;
Expand Down Expand Up @@ -133,8 +133,8 @@ public void load(Actor actor, LocalSession session,
AsyncCommandBuilder.wrap(task, actor)
.registerWithSupervisor(worldEdit.getSupervisor(), "Loading schematic " + filename)
.sendMessageAfterDelay(TranslatableComponent.of("worldedit.schematic.load.loading"))
.onSuccess(TextComponent.of(filename, TextColor.GOLD)
.append(TextComponent.of(" loaded. Paste it with ", TextColor.LIGHT_PURPLE))
.onSuccess(TextComponent.of(filename, NamedTextColor.GOLD)
.append(TextComponent.of(" loaded. Paste it with ", NamedTextColor.LIGHT_PURPLE))
.append(CodeFormat.wrap("//paste").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "//paste"))),
session::setClipboard)
.onFailure("Failed to load schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter())
Expand Down Expand Up @@ -446,12 +446,12 @@ public Component getComponent(int number) {
return TextComponent.builder()
.content("")
.append(TextComponent.of("[L]")
.color(TextColor.GOLD)
.color(NamedTextColor.GOLD)
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/schem load \"" + path + "\""))
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to load"))))
.append(TextComponent.space())
.append(TextComponent.of(path)
.color(TextColor.DARK_GREEN)
.color(NamedTextColor.DARK_GREEN)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(format))))
.build();
}
Expand Down
Loading

0 comments on commit a872c37

Please sign in to comment.