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 @@ -84,6 +84,12 @@ private static void appendHomeEntry(MutableComponent message, ServerPlayer playe
"commands.teleport_commands.common.rename",
ChatFormatting.BLUE,
new ClickEvent.SuggestCommand("/renamehome " + quotedName + " ")))
.append(" ")
.append(CommandUiSupport.translatedButton(
player,
"commands.teleport_commands.common.update",
ChatFormatting.YELLOW,
new ClickEvent.RunCommand("updatehome " + quotedName)))
.append(" ");

if (!currentHome.getUuid().equals(playerStorage.getDefaultHomeUuid())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.server.level.ServerPlayer;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -115,4 +116,36 @@ static void setDefaultHome(ServerPlayer player, String homeName) throws Exceptio
});
}

static void updateHome(ServerPlayer player, String homeName) throws Exception {
String worldString = WorldResolver.getDimensionId(player.level().dimension());

HomeCommandSupport.withPlayerStorage(player, playerStorage -> {
Optional<NamedLocation> optionalHome = HomeCommandSupport.resolveHomeForCommand(
playerStorage,
homeName,
player,
ChatFormatting.RED);
if (optionalHome.isEmpty()) {
return;
}

if (isSameLocation(player, optionalHome.get(), worldString)) {
HomeMessages.send(player, "commands.teleport_commands.home.updateSame", ChatFormatting.AQUA);
return;
}

optionalHome.get().setCoordinates(
player.getBlockX(),
player.getY(),
player.getBlockZ(),
worldString);
HomeMessages.send(player, "commands.teleport_commands.home.update");
});
}

private static boolean isSameLocation(ServerPlayer player, NamedLocation location, String worldString) {
return player.blockPosition().equals(location.getBlockPos())
&& Objects.equals(worldString, location.getWorldString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class home {
public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher) {
commandDispatcher.register(buildSetNode());
commandDispatcher.register(buildUpdateNode());
commandDispatcher.register(buildTeleportNode());
commandDispatcher.register(buildDeleteNode());
commandDispatcher.register(buildRenameNode());
Expand Down Expand Up @@ -177,6 +178,27 @@ private static LiteralArgumentBuilder<CommandSourceStack> buildListNode() {
}));
}

private static LiteralArgumentBuilder<CommandSourceStack> buildUpdateNode() {
return Commands.literal("updatehome")
.requires(source -> source.getPlayer() != null)
.then(Commands.argument("name", StringArgumentType.string())
.suggests(new HomeSuggestionProvider())
.executes(context -> {
final String name = StringArgumentType.getString(context, "name");
final ServerPlayer player = context.getSource().getPlayerOrException();

if (!HomeMessages.ensureEnabled(player)) {
return 1;
}

return HomeMessages.execute(
player,
"Error while updating a home location! => ",
"commands.teleport_commands.home.updateError",
() -> HomeMutationActions.updateHome(player, name));
}));
}

private static LiteralArgumentBuilder<CommandSourceStack> buildPagePickerNode() {
return Commands.literal("teleportcommandsfabric:homespages")
.requires(source -> source.getPlayer() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ private static void appendWarpEntry(MutableComponent message, ServerPlayer playe
: "commands.teleport_commands.gwarpmap.showOnMap",
visible ? ChatFormatting.GRAY : ChatFormatting.GOLD,
new ClickEvent.RunCommand("gwarpmap " + quotedName + " " + (visible ? "false" : "true")));
MutableComponent resetButton = CommandUiSupport.translatedButton(
player,
"commands.teleport_commands.common.update",
ChatFormatting.YELLOW,
new ClickEvent.RunCommand("updatewarp " + quotedName));

CommandUiSupport.appendNameLine(message, currentWarp.getName(), visibilityState, toggleButton);
CommandUiSupport.appendNameLine(message, currentWarp.getName(), visibilityState, toggleButton, resetButton);
Comment on lines +49 to +55
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable resetButton is wired to the updatewarp command and uses the translated label common.update, so the name is misleading. Renaming it to updateButton (or similar) will reduce confusion when maintaining the formatter.

Copilot uses AI. Check for mistakes.
CommandUiSupport.appendLocationLine(message, player, currentWarp);

message.append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ private static void appendWarpEntry(MutableComponent message, CommandSourceStack
ChatFormatting.BLUE,
new ClickEvent.SuggestCommand("/renamewarp " + quotedName + " ")))
.append(" ")
.append(CommandUiSupport.translatedButton(
player,
"commands.teleport_commands.common.update",
ChatFormatting.YELLOW,
new ClickEvent.RunCommand("updatewarp " + quotedName)))
.append(" ")
.append(CommandUiSupport.translatedButton(
player,
"commands.teleport_commands.common.delete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.server.level.ServerPlayer;

import java.util.Objects;
import java.util.Optional;

import static org.AndrewElizabeth.teleportcommandsfabric.storage.StorageManager.STORAGE;
Expand Down Expand Up @@ -63,4 +64,28 @@ static void renameWarp(ServerPlayer player, String warpName, String newWarpName)
WarpMessages.send(player, "commands.teleport_commands.warp.rename");
}
}

static void updateWarp(ServerPlayer player, String warpName) throws Exception {
String worldString = WorldResolver.getDimensionId(player.level().dimension());

Optional<NamedLocation> warpToReset = WarpCommandSupport.resolveWarpForCommand(warpName, player, false);
if (warpToReset.isPresent()) {
if (isSameLocation(player, warpToReset.get(), worldString)) {
WarpMessages.send(player, "commands.teleport_commands.warp.updateSame", ChatFormatting.AQUA);
return;
}

warpToReset.get().setCoordinates(
Comment on lines +71 to +78
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local variable name warpToReset reads like a reset operation, but this method is performing an update. Renaming it (e.g., warpToUpdate / warpToMove) would make the intent clearer and align with the command name updatewarp.

Suggested change
Optional<NamedLocation> warpToReset = WarpCommandSupport.resolveWarpForCommand(warpName, player, false);
if (warpToReset.isPresent()) {
if (isSameLocation(player, warpToReset.get(), worldString)) {
WarpMessages.send(player, "commands.teleport_commands.warp.updateSame", ChatFormatting.AQUA);
return;
}
warpToReset.get().setCoordinates(
Optional<NamedLocation> warpToUpdate = WarpCommandSupport.resolveWarpForCommand(warpName, player, false);
if (warpToUpdate.isPresent()) {
if (isSameLocation(player, warpToUpdate.get(), worldString)) {
WarpMessages.send(player, "commands.teleport_commands.warp.updateSame", ChatFormatting.AQUA);
return;
}
warpToUpdate.get().setCoordinates(

Copilot uses AI. Check for mistakes.
player.getBlockX(),
player.getY(),
player.getBlockZ(),
worldString);
WarpMessages.send(player, "commands.teleport_commands.warp.update");
}
}

private static boolean isSameLocation(ServerPlayer player, NamedLocation location, String worldString) {
return player.blockPosition().equals(location.getBlockPos())
&& Objects.equals(worldString, location.getWorldString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class warp {
public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher) {
commandDispatcher.register(buildSetNode());
commandDispatcher.register(buildUpdateNode());
commandDispatcher.register(buildTeleportNode());
commandDispatcher.register(buildDeleteNode());
commandDispatcher.register(buildRenameNode());
Expand Down Expand Up @@ -142,6 +143,27 @@ private static LiteralArgumentBuilder<CommandSourceStack> buildListNode() {
}));
}

private static LiteralArgumentBuilder<CommandSourceStack> buildUpdateNode() {
return Commands.literal("updatewarp")
.requires(source -> source.permissions().hasPermission(Permissions.COMMANDS_ADMIN))
.then(Commands.argument("name", StringArgumentType.string())
.suggests(new WarpSuggestionProvider())
.executes(context -> {
final String name = StringArgumentType.getString(context, "name");
final ServerPlayer player = context.getSource().getPlayerOrException();

if (!WarpMessages.ensureEnabled(player)) {
return 1;
}

return WarpMessages.execute(
player,
"Error while updating the warp location!",
"commands.teleport_commands.warp.updateError",
() -> WarpMutationActions.updateWarp(player, name));
}));
}

private static LiteralArgumentBuilder<CommandSourceStack> buildPagePickerNode() {
return Commands.literal("teleportcommandsfabric:warpspages")
.requires(source -> source.getPlayer() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
public class NamedLocation {
private UUID uuid;
private String name;
private final int x;
private final double y;
private final int z;
private final String world;
private int x;
private double y;
private int z;
private String world;
private boolean xaeroVisible;

public NamedLocation(UUID uuid, String name, int x, double y, int z, String world, boolean xaeroVisible) {
Expand Down Expand Up @@ -77,22 +77,28 @@ public void setName(String name) throws Exception {
StorageManager.markDirty();
}

public void setCoordinates(int x, double y, int z, String world) throws Exception {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
StorageManager.markDirty();
}

public void setXaeroVisible(boolean xaeroVisible) throws Exception {
this.xaeroVisible = xaeroVisible;
StorageManager.markDirty();
}

public boolean ensureUuid() {
UUID normalized = normalizeUuid(uuid);
if (normalized.equals(uuid)) {
if (uuid != null) {
return false;
}
uuid = normalized;
uuid = UUID.randomUUID();
return true;
}

private static UUID normalizeUuid(UUID uuid) {
return uuid == null ? UUID.randomUUID() : uuid;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ private static boolean isTrustedTeleportCommand(String command) {
|| normalized.startsWith("homes ")
|| normalized.startsWith("home ")
|| normalized.startsWith("maphome ")
|| normalized.startsWith("updatehome ")
|| normalized.startsWith("defaulthome ")
|| normalized.equals("warps")
|| normalized.startsWith("warps ")
|| normalized.startsWith("warp ")
|| normalized.startsWith("mapwarp ")
|| normalized.startsWith("updatewarp ")
|| normalized.startsWith("gwarpmap ")
|| normalized.equals("back")
|| normalized.startsWith("back ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"commands.teleport_commands.home.deleteError": "An error occurred while deleting the Home!",
"commands.teleport_commands.home.rename": "Home has been renamed",
"commands.teleport_commands.home.renameError": "An error occurred while renaming the Home!",
"commands.teleport_commands.home.update": "Home location has been updated",
"commands.teleport_commands.home.updateError": "An error occurred while updating the Home location!",
"commands.teleport_commands.home.updateSame": "Home is already at this location.",
"commands.teleport_commands.home.default": "Default Home has been set",
"commands.teleport_commands.home.defaultNone": "No default Home has been set!",
"commands.teleport_commands.home.defaultError": "An error occurred while changing the default Home!",
Expand Down Expand Up @@ -54,6 +57,9 @@
"commands.teleport_commands.warp.deleteError": "Error while deleting the Warp!",
"commands.teleport_commands.warp.rename": "Warp has been renamed",
"commands.teleport_commands.warp.renameError": "Error while renaming the Warp!",
"commands.teleport_commands.warp.update": "Warp location has been updated",
"commands.teleport_commands.warp.updateError": "Error while updating the Warp location!",
"commands.teleport_commands.warp.updateSame": "Warp is already at this location.",
"commands.teleport_commands.warp.notFound": "Warp was not found!",
"commands.teleport_commands.warp.deletedInvalid": "Invalid warp deleted.",
"commands.teleport_commands.warp.max": "The maximum number of warps (%0%) has been reached!",
Expand Down Expand Up @@ -135,6 +141,7 @@
"commands.teleport_commands.common.forceTeleport": "[Force teleport]",
"commands.teleport_commands.common.tp": "[Tp]",
"commands.teleport_commands.common.rename": "[Rename]",
"commands.teleport_commands.common.update": "[Update]",
"commands.teleport_commands.common.delete": "[Delete]",
"commands.teleport_commands.common.showOnMap": "[Show On Map]",
"commands.teleport_commands.common.hideFromMap": "[Hide From Map]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"commands.teleport_commands.home.deleteError": "删除家时发生错误!",
"commands.teleport_commands.home.rename": "家已重命名",
"commands.teleport_commands.home.renameError": "重命名家时发生错误!",
"commands.teleport_commands.home.update": "家的位置已更新",
"commands.teleport_commands.home.updateError": "更新家的位置时发生错误!",
"commands.teleport_commands.home.updateSame": "家的位置未变化,无需更新。",
"commands.teleport_commands.home.default": "默认的家设置",
"commands.teleport_commands.home.defaultNone": "没有设置默认的家!",
"commands.teleport_commands.home.defaultError": "变更默认家时发生错误!",
Expand Down Expand Up @@ -55,6 +58,9 @@
"commands.teleport_commands.warp.deleteError": "删除传送点时发生错误!",
"commands.teleport_commands.warp.rename": "传送点已重命名",
"commands.teleport_commands.warp.renameError": "传送点命名时出错!",
"commands.teleport_commands.warp.update": "传送点位置已更新",
"commands.teleport_commands.warp.updateError": "更新传送点位置时发生错误!",
"commands.teleport_commands.warp.updateSame": "传送点位置未变化,无需更新。",
"commands.teleport_commands.warp.notFound": "没找到传送点!",
"commands.teleport_commands.warp.deletedInvalid": "已删除无效的传送点。",
"commands.teleport_commands.warp.homeless": "没有传送点!",
Expand Down Expand Up @@ -135,6 +141,7 @@
"commands.teleport_commands.common.forceTeleport": "[强制传送]",
"commands.teleport_commands.common.tp": "[传送]",
"commands.teleport_commands.common.rename": "[重命名]",
"commands.teleport_commands.common.update": "[更新位置]",
"commands.teleport_commands.common.delete": "[删除]",
"commands.teleport_commands.common.showOnMap": "[地图显示]",
"commands.teleport_commands.common.hideFromMap": "[地图隐藏]",
Expand Down
Loading