-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated "explosion_heal_delay" and "block_placement_delay" command …
…settings into their own sub-command category, named "delays"
- Loading branch information
1 parent
9a6769c
commit 0989904
Showing
3 changed files
with
102 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/xd/arkosammy/commands/categories/DelaysCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package xd.arkosammy.commands.categories; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.DoubleArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.tree.ArgumentCommandNode; | ||
import com.mojang.brigadier.tree.LiteralCommandNode; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import xd.arkosammy.configuration.tables.DelaysConfig; | ||
import xd.arkosammy.explosions.AffectedBlock; | ||
|
||
public final class DelaysCommands { | ||
|
||
private DelaysCommands(){} | ||
|
||
public static void register(LiteralCommandNode<ServerCommandSource> creeperHealingNode){ | ||
|
||
LiteralCommandNode<ServerCommandSource> delaysNode = CommandManager | ||
.literal("delays") | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4)) | ||
.build(); | ||
|
||
//Explosion Heal Delay node | ||
LiteralCommandNode<ServerCommandSource> explosionHealDelayNode = CommandManager | ||
.literal("explosion_heal_delay") | ||
.executes(DelaysCommands::getExplosionHealDelayCommand) | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4)) | ||
.build(); | ||
|
||
//Block Placement Delay node | ||
LiteralCommandNode<ServerCommandSource> blockPlacementDelayNode = CommandManager | ||
.literal("block_placement_delay") | ||
.executes(DelaysCommands::getBlockPlacementDelayCommand) | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4)) | ||
.build(); | ||
|
||
//Explosion heal delay argument node | ||
ArgumentCommandNode<ServerCommandSource, Double> explosionHealDelayArgumentNode = CommandManager | ||
.argument("seconds", DoubleArgumentType.doubleArg()) | ||
.executes(DelaysCommands::setExplosionHealDelayCommand) | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4)) | ||
.build(); | ||
|
||
//Block placement delay argument node | ||
ArgumentCommandNode<ServerCommandSource, Double> blockPlacementDelayArgumentNode = CommandManager | ||
.argument("seconds", DoubleArgumentType.doubleArg()) | ||
.executes(DelaysCommands::setBlockPlacementDelayCommand) | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4)) | ||
.build(); | ||
|
||
//Root node connection | ||
creeperHealingNode.addChild(delaysNode); | ||
|
||
//Delays command nodes | ||
delaysNode.addChild(explosionHealDelayNode); | ||
delaysNode.addChild(blockPlacementDelayNode); | ||
|
||
//Argument nodes | ||
explosionHealDelayNode.addChild(explosionHealDelayArgumentNode); | ||
blockPlacementDelayNode.addChild(blockPlacementDelayArgumentNode); | ||
|
||
} | ||
|
||
private static int setExplosionHealDelayCommand(CommandContext<ServerCommandSource> ctx) { | ||
if(Math.round(Math.max(DoubleArgumentType.getDouble(ctx, "seconds"), 0) * 20L) != 0) { | ||
DelaysConfig.setExplosionHealDelay(DoubleArgumentType.getDouble(ctx, "seconds")); | ||
ctx.getSource().sendMessage(Text.literal("Explosion heal delay has been set to: " + DoubleArgumentType.getDouble(ctx, "seconds") + " second(s)")); | ||
} else { | ||
ctx.getSource().sendMessage(Text.literal("Cannot set explosion heal delay to a very low value").formatted(Formatting.RED)); | ||
} | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int setBlockPlacementDelayCommand(CommandContext<ServerCommandSource> ctx) { | ||
if (Math.round(Math.max(DoubleArgumentType.getDouble(ctx, "seconds"), 0) * 20L) != 0) { | ||
DelaysConfig.setBlockPlacementDelay(DoubleArgumentType.getDouble(ctx, "seconds")); | ||
AffectedBlock.updateAffectedBlocksTimers(); | ||
ctx.getSource().sendMessage(Text.literal("Block placement delay has been set to: " + DoubleArgumentType.getDouble(ctx, "seconds") + " second(s)")); | ||
} else { | ||
ctx.getSource().sendMessage(Text.literal("Cannot set block placement delay to a very low value").formatted(Formatting.RED)); | ||
} | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int getExplosionHealDelayCommand(CommandContext<ServerCommandSource> ctx){ | ||
ctx.getSource().sendMessage(Text.literal("Explosion heal delay currently set to: " + ((double)DelaysConfig.getExplosionHealDelay() / 20) + " second(s)")); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
private static int getBlockPlacementDelayCommand(CommandContext<ServerCommandSource> ctx){ | ||
ctx.getSource().sendMessage(Text.literal("Block placement delay currently set to: " + ((double) DelaysConfig.getBlockPlacementDelay() / 20) + " second(s)")); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters