Skip to content

Commit

Permalink
Removed "drop_items_on_explosions" setting and its command, and added…
Browse files Browse the repository at this point in the history
… identical settings for each of the explosion sources, along with their commands.
  • Loading branch information
ArkoSammy12 committed Oct 30, 2023
1 parent 0989904 commit 779ff5f
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import xd.arkosammy.commands.categories.DelaysCommands;
import xd.arkosammy.commands.categories.ExplosionSourcesCommands;
import xd.arkosammy.commands.categories.ModeCommands;
import xd.arkosammy.commands.categories.PreferencesCommands;
import xd.arkosammy.commands.categories.*;
import xd.arkosammy.configuration.Config;

import java.io.IOException;
Expand Down Expand Up @@ -51,6 +48,7 @@ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispa
ModeCommands.register(creeperHealingNode);
PreferencesCommands.register(creeperHealingNode);
DelaysCommands.register(creeperHealingNode);
ExplosionItemDropCommands.register(creeperHealingNode);
}

private static void reload(CommandContext<ServerCommandSource> ctx) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package xd.arkosammy.commands.categories;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.BoolArgumentType;
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 xd.arkosammy.configuration.tables.ExplosionItemDropConfig;

public final class ExplosionItemDropCommands {

private ExplosionItemDropCommands(){}

public static void register(LiteralCommandNode<ServerCommandSource> creeperHealingNode){

//Explosion item drop node
LiteralCommandNode<ServerCommandSource> explosionItemDropNode = CommandManager
.literal("explosion_item_drops")
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on creeper explosions
LiteralCommandNode<ServerCommandSource> dropItemsOnCreeperExplosionsNode = CommandManager
.literal("drop_items_on_creeper_explosions")
.executes(ExplosionItemDropCommands::getDropItemsOnCreeperExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on ghast explosions
LiteralCommandNode<ServerCommandSource> dropItemsOnGhastExplosionsNode = CommandManager
.literal("drop_items_on_ghast_explosions")
.executes(ExplosionItemDropCommands::getDropItemsOnGhastExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on wither explosions
LiteralCommandNode<ServerCommandSource> dropItemsOnWitherExplosionsNode = CommandManager
.literal("drop_items_on_wither_explosions")
.executes(ExplosionItemDropCommands::getDropItemsOnWitherExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on tnt explosions
LiteralCommandNode<ServerCommandSource> dropItemsOnTNTExplosionsNode = CommandManager
.literal("drop_items_on_tnt_explosions")
.executes(ExplosionItemDropCommands::getDropItemsOnTNTExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on tnt minecart explosions
LiteralCommandNode<ServerCommandSource> dropItemsOnTNTMinecartExplosionsNode = CommandManager
.literal("drop_items_on_tnt_minecart_explosions")
.executes(ExplosionItemDropCommands::getDropItemsOnTNTMinecartExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on creeper explosions argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnCreeperExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(ExplosionItemDropCommands::setDropItemsOnCreeperExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on ghast explosions argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnGhastExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(ExplosionItemDropCommands::setDropItemsOnGhastExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on wither explosions argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnWitherExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(ExplosionItemDropCommands::setDropItemsOnWitherExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on tnt explosions argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnTNTExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(ExplosionItemDropCommands::setDropItemsOnTNTExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on tnt minecart explosions argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnTNTMinecartExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(ExplosionItemDropCommands::setDropItemsOnTNTMinecartExplosionsCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Root node connection
creeperHealingNode.addChild(explosionItemDropNode);

//Drop items on explosions command nodes
explosionItemDropNode.addChild(dropItemsOnCreeperExplosionsNode);
explosionItemDropNode.addChild(dropItemsOnGhastExplosionsNode);
explosionItemDropNode.addChild(dropItemsOnWitherExplosionsNode);
explosionItemDropNode.addChild(dropItemsOnTNTExplosionsNode);
explosionItemDropNode.addChild(dropItemsOnTNTMinecartExplosionsNode);

//Argument nodes
dropItemsOnCreeperExplosionsNode.addChild(dropItemsOnCreeperExplosionsArgumentNode);
dropItemsOnGhastExplosionsNode.addChild(dropItemsOnGhastExplosionsArgumentNode);
dropItemsOnWitherExplosionsNode.addChild(dropItemsOnWitherExplosionsArgumentNode);
dropItemsOnTNTExplosionsNode.addChild(dropItemsOnTNTExplosionsArgumentNode);
dropItemsOnTNTMinecartExplosionsNode.addChild(dropItemsOnTNTMinecartExplosionsArgumentNode);

}

private static int setDropItemsOnCreeperExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ExplosionItemDropConfig.setDropItemsOnCreeperExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on Creeper explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int setDropItemsOnGhastExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ExplosionItemDropConfig.setDropItemsOnGhastExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on Ghast explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int setDropItemsOnWitherExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ExplosionItemDropConfig.setDropItemsOnWitherExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on Wither explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int setDropItemsOnTNTExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ExplosionItemDropConfig.setDropItemsOnTNTExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on TNT explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int setDropItemsOnTNTMinecartExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ExplosionItemDropConfig.setDropItemsOnTNTMinecartExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on TNT minecart explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnCreeperExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on Creeper explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnCreeperExplosions()));
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnGhastExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on Ghast explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnGhastExplosions()));
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnWitherExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on Wither explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnWitherExplosions()));
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnTNTExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on TNT explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnTNTExplosions()));
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnTNTMinecartExplosionsCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on TNT minecart explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnTNTMinecartExplosions()));
return Command.SINGLE_SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ public static void register(LiteralCommandNode<ServerCommandSource> creeperHeali
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on creeper explosions node
LiteralCommandNode<ServerCommandSource> dropItemsOnCreeperExplosionsNode = CommandManager
.literal("drop_items_on_explosions")
.executes(PreferencesCommands::getDropItemsOnExplosionCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Heal on healing potion splash node
LiteralCommandNode<ServerCommandSource> healOnHealingPotionSplashNode = CommandManager
Expand Down Expand Up @@ -121,13 +115,6 @@ public static void register(LiteralCommandNode<ServerCommandSource> creeperHeali
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Drop items on creeper argument node
ArgumentCommandNode<ServerCommandSource, Boolean> dropItemsOnCreeperExplosionsArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
.executes(PreferencesCommands::setDropItemsOnExplosionCommand)
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(4))
.build();

//Heal on Healing potion splash argument node
ArgumentCommandNode<ServerCommandSource, Boolean> healOnHealingPotionSplashArgumentNode = CommandManager
.argument("value", BoolArgumentType.bool())
Expand All @@ -153,7 +140,6 @@ public static void register(LiteralCommandNode<ServerCommandSource> creeperHeali
creeperHealingNode.addChild(settingsNode);

//Preferences commands nodes
settingsNode.addChild(dropItemsOnCreeperExplosionsNode);
settingsNode.addChild(shouldHealOnFlowingWaterNode);
settingsNode.addChild(shouldHealOnSourceWaterNode);
settingsNode.addChild(shouldHealOnFlowingLavaNode);
Expand All @@ -169,7 +155,6 @@ public static void register(LiteralCommandNode<ServerCommandSource> creeperHeali
shouldHealOnFlowingLavaNode.addChild(healOnFlowingLavaArgumentNode);
shouldHealOnSourceLavaNode.addChild(healOnSourceLavaArgumentNode);
shouldPlaySoundOnBlockPlacementNode.addChild(playSoundOnBlockPlacementArgumentNode);
dropItemsOnCreeperExplosionsNode.addChild(dropItemsOnCreeperExplosionsArgumentNode);
healOnHealingPotionSplashNode.addChild(healOnHealingPotionSplashArgumentNode);
healOnRegenerationPotionSplash.addChild(healOnRegenerationPotionSplashArgumentNode);
enableWhitelistNode.addChild(enableWhitelistArgumentNode);
Expand Down Expand Up @@ -206,12 +191,6 @@ private static int setPlaySoundOnBlockPlacement(CommandContext<ServerCommandSour
return Command.SINGLE_SUCCESS;
}

private static int setDropItemsOnExplosionCommand(CommandContext<ServerCommandSource> ctx){
PreferencesConfig.setDropItemsOnExplosions(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Drop items on explosions has been set to: " + BoolArgumentType.getBool(ctx, "value")));
return Command.SINGLE_SUCCESS;
}

private static int setHealOnHealingPotionSplashCommand(CommandContext<ServerCommandSource> ctx){
PreferencesConfig.setHealOnHealingPotionSplash(BoolArgumentType.getBool(ctx, "value"));
ctx.getSource().sendMessage(Text.literal("Heal on Healing potion splash set to: " + BoolArgumentType.getBool(ctx, "value")));
Expand Down Expand Up @@ -255,11 +234,6 @@ private static int getShouldPlaySoundOnBlockPlacement(CommandContext<ServerComma
return Command.SINGLE_SUCCESS;
}

private static int getDropItemsOnExplosionCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Drop items on explosions currently set to: " + PreferencesConfig.getDropItemsOnExplosions()));
return Command.SINGLE_SUCCESS;
}

private static int getHealOnHealingPotionSplashCommand(CommandContext<ServerCommandSource> ctx){
ctx.getSource().sendMessage(Text.literal("Heal on Healing potion splash set to: " + PreferencesConfig.getHealOnHealingPotionSplash()));
return Command.SINGLE_SUCCESS;
Expand All @@ -275,5 +249,4 @@ private static int getEnableWhitelist(CommandContext<ServerCommandSource> ctx){
return Command.SINGLE_SUCCESS;
}


}
3 changes: 3 additions & 0 deletions src/main/java/xd/arkosammy/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static boolean reloadConfigSettingsInMemory(CommandContext<ServerCommandS
private static void saveDefaultConfigSettingsToFile(CommentedFileConfig fileConfig){
ModeConfig.saveToFileWithDefaultValues(fileConfig);
ExplosionSourceConfig.saveToFileWithDefaultValues(fileConfig);
ExplosionItemDropConfig.saveToFileWithDefaultValues(fileConfig);
DelaysConfig.saveToFileWithDefaultValues(fileConfig);
PreferencesConfig.saveToFileWithDefaultValues(fileConfig);
WhitelistConfig.saveToFileWithDefaultValues(fileConfig);
Expand All @@ -121,6 +122,7 @@ private static void saveDefaultConfigSettingsToFile(CommentedFileConfig fileConf
private static void saveConfigSettingsToFile(CommentedFileConfig fileConfig){
ModeConfig.saveSettingsToFile(fileConfig);
ExplosionSourceConfig.saveSettingsToFile(fileConfig);
ExplosionItemDropConfig.saveSettingsToFile(fileConfig);
DelaysConfig.saveSettingsToFile(fileConfig);
PreferencesConfig.saveSettingsToFile(fileConfig);
WhitelistConfig.saveWhitelistToFile(fileConfig);
Expand All @@ -130,6 +132,7 @@ private static void saveConfigSettingsToFile(CommentedFileConfig fileConfig){
private static void loadConfigSettingsToMemory(CommentedFileConfig fileConfig){
ModeConfig.loadSettingsToMemory(fileConfig);
ExplosionSourceConfig.loadSettingsToMemory(fileConfig);
ExplosionItemDropConfig.loadSettingsToMemory(fileConfig);
DelaysConfig.loadSettingsToMemory(fileConfig);
PreferencesConfig.loadSettingsToMemory(fileConfig);
WhitelistConfig.loadWhitelistToMemory(fileConfig);
Expand Down
Loading

0 comments on commit 779ff5f

Please sign in to comment.