Skip to content

Commit

Permalink
Merge pull request #324 from FTBTeam/feature/1.21.1/misc-features-and…
Browse files Browse the repository at this point in the history
…-bugs
  • Loading branch information
UnRealDinnerbone authored Oct 16, 2024
2 parents fc1603c + f8e83fb commit 98712d9
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 45 deletions.
144 changes: 100 additions & 44 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunksCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dev.ftb.mods.ftbchunks.api.ChunkTeamData;
import dev.ftb.mods.ftbchunks.api.ClaimResult;
import dev.ftb.mods.ftbchunks.api.ClaimedChunk;
import dev.ftb.mods.ftbchunks.api.FTBChunksProperties;
import dev.ftb.mods.ftbchunks.client.gui.EntityIconSettingsScreen;
import dev.ftb.mods.ftbchunks.data.ChunkTeamDataImpl;
import dev.ftb.mods.ftbchunks.data.ClaimedChunkImpl;
Expand Down Expand Up @@ -100,7 +101,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
)
)
.then(Commands.literal("admin")
.requires(source -> source.hasPermission(2))
.requires(source -> source.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(Commands.literal("bypass_protection")
.executes(context -> bypassProtection(context.getSource()))
)
Expand Down Expand Up @@ -169,6 +170,12 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.then(Commands.literal("unclaim_everything")
.executes(context -> unclaimEverything(context.getSource()))
)
.then(Commands.literal("unclaim_dimension")
.executes(context -> unclaimDimension(context.getSource()))
.then(Commands.argument("dimension", DimensionArgument.dimension())
.executes(context -> unclaimDimension(context.getSource(), DimensionArgument.getDimension(context, "dimension").dimension()))
)
)
.then(Commands.literal("unload_everything")
.executes(context -> unloadEverything(context.getSource()))
)
Expand All @@ -194,7 +201,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
// .requires(source -> source.getServer().isSingleplayer())
.executes(context -> {
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new RequestBlockColorPacket());
return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("waypoint")
Expand Down Expand Up @@ -234,8 +241,9 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
private static int addWaypoint(CommandSourceStack source, String name, ServerLevel level, BlockPos position, ChatFormatting color, boolean useGui) throws CommandSyntaxException {
if (color.getColor() != null) {
NetworkManager.sendToPlayer(source.getPlayerOrException(), new AddWaypointPacket(name, new GlobalPos(level.dimension(), position), color.getColor(), useGui));
source.sendSuccess(() -> Component.translatable("ftbchunks.command.waypoint_added", name), true);
}
return 1;
return Command.SINGLE_SUCCESS;
}

private static int addWaypoint(CommandSourceStack source, String name, ServerLevel level, BlockPos position, ChatFormatting color) throws CommandSyntaxException {
Expand All @@ -256,8 +264,11 @@ private static int bypassProtection(CommandSourceStack source) throws CommandSyn
ServerPlayer player = source.getPlayerOrException();
ClaimedChunkManagerImpl manager = claimManager();
manager.setBypassProtection(player.getUUID(), !manager.getBypassProtection(player.getUUID()));
source.sendSuccess(() -> Component.literal("bypass_protection = " + manager.getBypassProtection(player.getUUID())), true);
return 1;
source.sendSuccess(() -> {
boolean bypassProtection = manager.getBypassProtection(player.getUUID());
return Component.translatable("ftbchunks.command.bypass_protection_" + (bypassProtection ? "enabled" : "disabled"));
}, true);
return Command.SINGLE_SUCCESS;
}

private static int openClaimGuiAs(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Expand Down Expand Up @@ -311,7 +322,7 @@ private static int claim(CommandSourceStack source, Team team, int r, ColumnPos
}
});

source.sendSuccess(() -> Component.literal("Claimed " + success[0] + " chunks!"), false);
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.claimed", success[0]), false);

ChunkDimPos origin = new ChunkDimPos(level.dimension(), anchor.x() >> 4, anchor.z() >> 4);
FTBChunks.LOGGER.info(source.getTextName() + " claimed " + success[0] + " chunks around " + origin + "for team " + team.getShortName());
Expand All @@ -332,7 +343,7 @@ private static int unclaim(CommandSourceStack source, Team team, int r, ColumnPo
}
});

source.sendSuccess(() -> Component.literal("Unclaimed " + success[0] + " chunks!"), false);
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.unclaimed", success[0]), false);

ChunkDimPos origin = new ChunkDimPos(level.dimension(), anchor.x() >> 4, anchor.z() >> 4);
FTBChunks.LOGGER.info(source.getTextName() + " unclaimed " + success[0] + " chunks around " + origin + "for team " + team.getShortName());
Expand All @@ -350,7 +361,7 @@ private static int load(CommandSourceStack source, int r) throws CommandSyntaxEx
}
});

source.sendSuccess(() -> Component.literal("Loaded " + success[0] + " chunks!"), false);
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.force_loaded", success[0]), false);
FTBChunks.LOGGER.info(source.getTextName() + " loaded " + success[0] + " chunks at " + new ChunkDimPos(source.getPlayerOrException()));
return success[0];
}
Expand All @@ -364,68 +375,89 @@ private static int unload(CommandSourceStack source, int r) throws CommandSyntax
}
});

source.sendSuccess(() -> Component.literal("Unloaded " + success[0] + " chunks!"), false);
source.sendSuccess(() -> Component.translatable("ftbchunks.command.unloaded", success[0]), false);
FTBChunks.LOGGER.info(source.getTextName() + " unloaded " + success[0] + " chunks at " + new ChunkDimPos(source.getPlayerOrException()));
return success[0];
}

private static int unclaimAll(CommandSourceStack source, Team team) {
ChunkTeamDataImpl data = claimManager().getOrCreateData(team);

int unclaimed = 0;
for (ClaimedChunkImpl c : new ArrayList<>(data.getClaimedChunks())) {
data.unclaim(source, c.getPos(), false);
ClaimResult unclaim = data.unclaim(source, c.getPos(), false);
if (unclaim.isSuccess()) {
unclaimed++;
}
}
data.markDirty();

return 1;
int finalUnclaimed = unclaimed;
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.unclaimed", finalUnclaimed), true);
return Command.SINGLE_SUCCESS;
}

private static int unloadAll(CommandSourceStack source, Team team) {
ChunkTeamDataImpl data = claimManager().getOrCreateData(team);

int unloaded = 0;
for (ClaimedChunk c : new ArrayList<>(data.getClaimedChunks())) {
data.unForceLoad(source, c.getPos(), false);
ClaimResult claimResult = data.unForceLoad(source, c.getPos(), false);
if (claimResult.isSuccess()) {
unloaded++;
}
}
data.markDirty();

return 1;
int finalUnloaded = unloaded;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.unloaded", finalUnloaded), true);
return Command.SINGLE_SUCCESS;
}

private static int info(CommandSourceStack source, ChunkDimPos pos) {
source.sendSuccess(() -> Component.literal("Location: " + pos), true);
private static int info(CommandSourceStack source, ChunkDimPos pos) throws CommandSyntaxException {

ClaimedChunk chunk = claimManager().getChunk(pos);

if (chunk == null) {
source.sendSuccess(() -> Component.literal("Chunk not claimed!"), true);
return 0;
}
boolean canKnowChunkStatus = source.hasPermission(Commands.LEVEL_GAMEMASTERS) || (source.isPlayer() || (chunk != null && chunk.getTeamData().canPlayerUse(source.getPlayerOrException(), FTBChunksProperties.CLAIM_VISIBILITY)));

source.sendSuccess(() -> Component.literal("Owner: ").append(chunk.getTeamData().getTeam().getColoredName()).append(" / " + UndashedUuid.toString(chunk.getTeamData().getTeam().getId())), true);
if (canKnowChunkStatus) {
if (chunk == null) {
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.not_claimed"), false);
return Command.SINGLE_SUCCESS;
}

if (source.hasPermission(2)) {
source.sendSuccess(() -> Component.literal("Force Loaded: " + chunk.isForceLoaded()), true);
source.sendSuccess(() -> {
Component owner = chunk.getTeamData().getTeam().getColoredName().copy().append(" / " + UndashedUuid.toString(chunk.getTeamData().getTeam().getId()));
String location = pos.dimension().location().toString() + " [" + pos.x() + ", " + pos.z() + "]";
return Component.translatable("ftbchunks.commands.location", location)
.append(Component.literal("\n"))
.append(Component.translatable("ftbchunks.commands.owner").append(owner.getString()))
.append(Component.literal("\n"))
.append(Component.translatable("ftbchunks.commands.is_force_loaded", chunk.isForceLoaded()));
}, true);

return Command.SINGLE_SUCCESS;
}

return 1;
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.cant_determined"), false);

return Command.SINGLE_SUCCESS;
}

private static int getExtraClaimChunks(CommandSourceStack source, ServerPlayer player) {
ChunkTeamData personalData = claimManager().getPersonalData(player.getUUID());
if (personalData == null) {
source.sendFailure(Component.literal("can't get personal team data for ").append(player.getDisplayName()));
source.sendFailure(Component.translatable("ftbchunks.commands.no_personal_info", player.getDisplayName()));
return 0;
}

source.sendSuccess(() -> player.getDisplayName().copy().append("/extra_claim_chunks = " + personalData.getExtraClaimChunks()), false);
return 1;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.extra_chunks_claimed", player.getDisplayName(), personalData.getExtraClaimChunks()), true);
return personalData.getExtraClaimChunks();
}

private static int setExtraClaimChunks(CommandSourceStack source, ServerPlayer player, int extra, boolean adding) {
// limit is added to player's *personal* data, even if they're in a party
ChunkTeamDataImpl personalData = claimManager().getPersonalData(player.getUUID());
if (personalData == null) {
source.sendFailure(Component.literal("can't get personal team data for ").append(player.getDisplayName()));
source.sendFailure(Component.translatable("ftbchunks.commands.no_personal_info", player.getDisplayName()));
return 0;
}
personalData.setExtraClaimChunks(Math.max(0, extra + (adding ? personalData.getExtraClaimChunks() : 0)));
Expand All @@ -436,26 +468,26 @@ private static int setExtraClaimChunks(CommandSourceStack source, ServerPlayer p
teamData.updateLimits();
SendGeneralDataPacket.send(teamData, player);

source.sendSuccess(() -> player.getDisplayName().copy().append("/extra_claim_chunks = " + personalData.getExtraClaimChunks()), false);
return 1;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.set_extra_chunks_claimed", personalData.getExtraClaimChunks(), player.getDisplayName()), true);
return personalData.getExtraClaimChunks();
}

private static int getExtraForceLoadChunks(CommandSourceStack source, ServerPlayer player) {
ChunkTeamData personalData = claimManager().getPersonalData(player.getUUID());
if (personalData == null) {
source.sendFailure(Component.literal("can't get personal team data for ").append(player.getDisplayName()));
source.sendFailure(Component.translatable("ftbchunks.commands.no_personal_info", player.getDisplayName()));
return 0;
}

source.sendSuccess(() -> player.getDisplayName().copy().append("/extra_force_load_chunks = " + personalData.getExtraForceLoadChunks()), false);
return 1;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.extra_forceload_chunks", player.getDisplayName(), personalData.getExtraForceLoadChunks()), true);
return personalData.getExtraForceLoadChunks();
}

private static int setExtraForceLoadChunks(CommandSourceStack source, ServerPlayer player, int extra, boolean adding) {
// limit is added to player's *personal* data, even if they're in a party
ChunkTeamDataImpl personalData = claimManager().getPersonalData(player.getUUID());
if (personalData == null) {
source.sendFailure(Component.literal("can't get personal team data for ").append(player.getDisplayName()));
source.sendFailure(Component.translatable("ftbchunks.commands.no_personal_info", player.getDisplayName()));
return 0;
}
personalData.setExtraForceLoadChunks(Math.max(0, extra + (adding ? personalData.getExtraForceLoadChunks() : 0)));
Expand All @@ -466,26 +498,50 @@ private static int setExtraForceLoadChunks(CommandSourceStack source, ServerPlay
teamData.updateLimits();
SendGeneralDataPacket.send(teamData, player);

source.sendSuccess(() -> player.getDisplayName().copy().append("/extra_force_load_chunks = " + personalData.getExtraForceLoadChunks()), false);
return 1;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.set_extra_forceload_chunks", personalData.getExtraForceLoadChunks(), player.getDisplayName()), true);
return personalData.getExtraForceLoadChunks();
}

private static int unclaimEverything(CommandSourceStack source) {
int claimedChunks = 0;
for (ClaimedChunkImpl c : new ArrayList<>(claimManager().getAllClaimedChunks())) {
c.getTeamData().unclaim(source, c.getPos(), false);
c.getTeamData().markDirty();
claimedChunks++;
}
int finalClaimedChunks = claimedChunks;
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.unclaimed", finalClaimedChunks), true);
return Command.SINGLE_SUCCESS;
}

private static int unclaimDimension(CommandSourceStack source, ResourceKey<Level> dim) {
int claimedChunks = 0;
for (ClaimedChunkImpl c : new ArrayList<>(claimManager().getAllClaimedChunks())) {
if (source.getLevel().dimension().equals(dim)) {
c.getTeamData().unclaim(source, c.getPos(), false);
c.getTeamData().markDirty();
claimedChunks++;
}
}
int finalClaimedChunks = claimedChunks;
source.sendSuccess(() -> Component.translatable("ftbchunks.commands.unclaimed", finalClaimedChunks), true);
return Command.SINGLE_SUCCESS;
}

return 1;
private static int unclaimDimension(CommandSourceStack source) {
return unclaimDimension(source, source.getLevel().dimension());
}

private static int unloadEverything(CommandSourceStack source) {
int unloadedChunks = 0;
for (ClaimedChunkImpl c : new ArrayList<>(claimManager().getAllClaimedChunks())) {
c.getTeamData().unForceLoad(source, c.getPos(), false);
c.getTeamData().markDirty();
unloadedChunks++;
}

return 1;
int finalUnloadedChunks = unloadedChunks;
source.sendSuccess(() -> Component.translatable("ftbchunks.command.unloaded", finalUnloadedChunks), true);
return Command.SINGLE_SUCCESS;
}

private static int viewLoadedChunks(CommandSourceStack source, ServerLevel level) throws CommandSyntaxException {
Expand All @@ -508,15 +564,15 @@ private static int viewLoadedChunks(CommandSourceStack source, ServerLevel level
}
}

source.sendSuccess(() -> Component.literal(String.format("Chunks Loaded: %d. Check the map to see loaded chunks", chunks.size())), false);
source.sendSuccess(() -> Component.translatable("ftbchunks.command.view_loaded", chunks.size()), false);
NetworkManager.sendToPlayer(source.getPlayerOrException(), new LoadedChunkViewPacket(level.dimension(), chunks));

return 1;
return Command.SINGLE_SUCCESS;
}

private static int resetLoadedChunks(CommandSourceStack source, ServerLevel level) throws CommandSyntaxException {
NetworkManager.sendToPlayer(source.getPlayerOrException(), new LoadedChunkViewPacket(level.dimension(), Long2IntMaps.EMPTY_MAP));
return 1;
return Command.SINGLE_SUCCESS;
}

private static RequiredArgumentBuilder<CommandSourceStack, Integer> radiusArg() {
Expand Down Expand Up @@ -545,7 +601,7 @@ private static ServerLevel getDimArg(CommandContext<CommandSourceStack> context)

private static RequiredArgumentBuilder<CommandSourceStack, TeamArgumentProvider> forTeam(ToIntBiFunction<CommandSourceStack, Team> callback) {
return Commands.argument("team", TeamArgument.create())
.requires(source -> source.hasPermission(2))
.requires(source -> source.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> callback.applyAsInt(context.getSource(), TeamArgument.get(context, "team")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ protected Panel createTopPanel() {

@Override
public void addButtons(Panel panel) {
if (waypoints.isEmpty()) {
panel.add(new NoWayPoints(panel, Component.empty(), Icons.REMOVE));
}

waypoints.forEach((key, value) -> {
boolean startCollapsed = collapsed.get(key);
GroupButton groupButton = new GroupButton(panel, key, startCollapsed, value);
Expand All @@ -147,6 +151,28 @@ public void addButtons(Panel panel) {
});
}

protected static class NoWayPoints extends Button {

private static final Component NO_WAYPOINTS = Component.translatable("ftbchunks.gui.no_waypoints");

public NoWayPoints(Panel panel, Component t, Icon i) {
super(panel);
}

@Override
public void onClicked(MouseButton button) {

}

@Override
public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
super.drawBackground(graphics, theme, x, y, w, h);

int stringWidth = theme.getStringWidth(NO_WAYPOINTS.getString());
theme.drawString(graphics, NO_WAYPOINTS, x + (w - stringWidth) / 2, y + (h - theme.getFontHeight()) / 2 + 1);
}
}

protected class CustomTopPanel extends TopPanel {
private final TextField titleLabel = new TextField(this);

Expand Down
Loading

0 comments on commit 98712d9

Please sign in to comment.