Skip to content

Commit

Permalink
Merge pull request #116 from FTBTeam/bugfix/1.21/command-fixes
Browse files Browse the repository at this point in the history
[1.21] Fix command perms and weather command
  • Loading branch information
desht authored Aug 19, 2024
2 parents 6c7b2d8 + 911f19c commit 6968902
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftblibrary;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
Expand Down Expand Up @@ -39,29 +40,32 @@ public class FTBLibraryCommands {

public static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection type) {
var command = Commands.literal("ftblibrary")
.requires(commandSource -> commandSource.hasPermission(2))
.then(Commands.literal("gamemode")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
if (!context.getSource().getPlayerOrException().isCreative()) {
context.getSource().getPlayerOrException().setGameMode(GameType.CREATIVE);
} else {
context.getSource().getPlayerOrException().setGameMode(GameType.SURVIVAL);
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("rain")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
if (context.getSource().getLevel().isRaining()) {
context.getSource().getLevel().setWeatherParameters(6000, 0, false, false); // clear
//Use overworld as that controls the weather for the whole server
if (context.getSource().getServer().overworld().isRaining()) {
context.getSource().getServer().overworld().setWeatherParameters(6000, 0, false, false); // clear
} else {
context.getSource().getLevel().setWeatherParameters(0, 6000, true, false);// rain
context.getSource().getServer().overworld().setWeatherParameters(0, 6000, true, false);// rain
}
return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("day")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 6000L) % 24000L;

Expand All @@ -71,10 +75,11 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
}
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("night")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 18000L) % 24000L;

Expand All @@ -84,10 +89,11 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
}
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("nbtedit")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(Commands.literal("block")
.then(Commands.argument("pos", BlockPosArgument.blockPos())
.executes(context -> editNBT(context, (info, tag) -> editBlockNBT(context, info, tag)))
Expand All @@ -111,7 +117,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.requires(CommandSourceStack::isPlayer)
.executes(context -> {
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(true));
return 1;
return Command.SINGLE_SUCCESS;
})
);

Expand All @@ -123,7 +129,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
} else {
UITesting.openTestScreen();
}
return 1;
return Command.SINGLE_SUCCESS;
})
);
}
Expand All @@ -140,7 +146,7 @@ private static int editNBT(CommandContext<CommandSourceStack> context, NBTEditCa
if (!info.isEmpty()) {
EDITING_NBT.put(player.getUUID(), info);
NetworkManager.sendToPlayer(player, new EditNBTPacket(info, tag));
return 1;
return Command.SINGLE_SUCCESS;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ neoforge_version=21.1.13
neoforge_version_range=[21.1.0,)
neoforge_loader_version=4
fabric_loader_version=0.15.11
fabric_api_version=0.101.2+1.21
fabric_api_version=0.102.1+1.21.1
fabric_api_version_range=>=0.100.1+1.21
architectury_version=13.0.6
# There are too many of these now
Expand Down

0 comments on commit 6968902

Please sign in to comment.