diff --git a/src/main/java/xd/arkosammy/commands/categories/DelaysCommands.java b/src/main/java/xd/arkosammy/commands/categories/DelaysCommands.java index 43e53ca..0c03491 100644 --- a/src/main/java/xd/arkosammy/commands/categories/DelaysCommands.java +++ b/src/main/java/xd/arkosammy/commands/categories/DelaysCommands.java @@ -66,7 +66,7 @@ public static void register(LiteralCommandNode creeperHeali private static int setExplosionHealDelayCommand(CommandContext ctx) { if(Math.round(Math.max(DoubleArgumentType.getDouble(ctx, "seconds"), 0) * 20L) != 0) { - DelaysConfig.setExplosionHealDelay(DoubleArgumentType.getDouble(ctx, "seconds")); + DelaysConfig.EXPLOSION_HEAL_DELAY.getEntry().setValue(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)); @@ -76,7 +76,7 @@ private static int setExplosionHealDelayCommand(CommandContext ctx) { if (Math.round(Math.max(DoubleArgumentType.getDouble(ctx, "seconds"), 0) * 20L) != 0) { - DelaysConfig.setBlockPlacementDelay(DoubleArgumentType.getDouble(ctx, "seconds")); + DelaysConfig.BLOCK_PLACEMENT_DELAY.getEntry().setValue(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 { diff --git a/src/main/java/xd/arkosammy/commands/categories/ExplosionItemDropCommands.java b/src/main/java/xd/arkosammy/commands/categories/ExplosionItemDropCommands.java index a3aa4f0..b523269 100644 --- a/src/main/java/xd/arkosammy/commands/categories/ExplosionItemDropCommands.java +++ b/src/main/java/xd/arkosammy/commands/categories/ExplosionItemDropCommands.java @@ -144,79 +144,79 @@ public static void register(LiteralCommandNode creeperHeali } private static int setDropItemsOnCreeperExplosionsCommand(CommandContext ctx){ - ExplosionItemDropConfig.setDropItemsOnCreeperExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_CREEPER_EXPLOSIONS.getEntry().setValue(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 ctx){ - ExplosionItemDropConfig.setDropItemsOnGhastExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_GHAST_EXPLOSIONS.getEntry().setValue(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 ctx){ - ExplosionItemDropConfig.setDropItemsOnWitherExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_WITHER_EXPLOSIONS.getEntry().setValue(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 ctx){ - ExplosionItemDropConfig.setDropItemsOnTNTExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_EXPLOSIONS.getEntry().setValue(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 ctx){ - ExplosionItemDropConfig.setDropItemsOnTNTMinecartExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_MINECART_EXPLOSIONS.getEntry().setValue(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 setDropItemsOnBedAndRespawnAnchorExplosionsCommand(CommandContext ctx){ - ExplosionItemDropConfig.setDropItemsOnBedAndRespawnAnchorExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Drop items on bed and respawn anchor explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setDropItemsOnEndCrystalExplosionsCommand(CommandContext ctx){ - ExplosionItemDropConfig.setDropItemsOnEndCrystalExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionItemDropConfig.DROP_ITEMS_ON_END_CRYSTAL_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Drop items on end crystal explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnCreeperExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on Creeper explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnCreeperExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on Creeper explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_CREEPER_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnGhastExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on Ghast explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnGhastExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on Ghast explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_GHAST_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnWitherExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on Wither explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnWitherExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on Wither explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_WITHER_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnTNTExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on TNT explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnTNTExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on TNT explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnTNTMinecartExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on TNT minecart explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnTNTMinecartExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on TNT minecart explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_MINECART_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnBedAndRespawnAnchorExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on bed and respawn anchor explosions currently set to: " + ExplosionItemDropConfig.getDropItemsOnBedAndRespawnAnchorExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on bed and respawn anchor explosions currently set to: " + ExplosionItemDropConfig.DROP_ITEMS_ON_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getDropItemsOnEndCrystalExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Drop items on end crystal explosions currently set to: "+ ExplosionItemDropConfig.getDropItemsOnEndCrystalExplosions())); + ctx.getSource().sendMessage(Text.literal("Drop items on end crystal explosions currently set to: "+ ExplosionItemDropConfig.DROP_ITEMS_ON_END_CRYSTAL_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/xd/arkosammy/commands/categories/ExplosionSourcesCommands.java b/src/main/java/xd/arkosammy/commands/categories/ExplosionSourcesCommands.java index d7a518e..a4759d1 100644 --- a/src/main/java/xd/arkosammy/commands/categories/ExplosionSourcesCommands.java +++ b/src/main/java/xd/arkosammy/commands/categories/ExplosionSourcesCommands.java @@ -144,79 +144,79 @@ public static void register(LiteralCommandNode creeperHeali } private static int setHealCreeperExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealCreeperExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_CREEPER_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal Creeper explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealGhastExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealGhastExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_GHAST_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal Ghast explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealWitherExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealWitherExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_WITHER_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal Wither explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealTNTExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealTNTExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_TNT_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal TNT explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealTNTMinecartExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealTNTMinecartExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_TNT_MINECART_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal TNT Minecart explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealBedAndRespawnAnchorExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealBedAndRespawnAnchorExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal bed and respawn anchor explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealEndCrystalExplosionsCommand(CommandContext ctx){ - ExplosionSourceConfig.setHealEndCrystalExplosions(BoolArgumentType.getBool(ctx, "value")); + ExplosionSourceConfig.HEAL_END_CRYSTAL_EXPLOSIONS.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal end crystal explosions has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int getHealCreeperExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal Creeper explosions currently set to: " + ExplosionSourceConfig.getHealCreeperExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal Creeper explosions currently set to: " + ExplosionSourceConfig.HEAL_CREEPER_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealGhastExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal Ghast explosions currently set to: " + ExplosionSourceConfig.getHealGhastExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal Ghast explosions currently set to: " + ExplosionSourceConfig.HEAL_GHAST_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealWitherExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal Wither explosions currently set to: " + ExplosionSourceConfig.getHealWitherExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal Wither explosions currently set to: " + ExplosionSourceConfig.HEAL_WITHER_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealTNTExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal TNT explosions currently set to: " + ExplosionSourceConfig.getHealTNTExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal TNT explosions currently set to: " + ExplosionSourceConfig.HEAL_TNT_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealTNTMinecartExplosionCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal TNT minecart explosions currently set to: " + ExplosionSourceConfig.getHealTNTMinecartExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal TNT minecart explosions currently set to: " + ExplosionSourceConfig.HEAL_TNT_MINECART_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealBedAndRespawnAnchorExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal bed and respawn anchor explosions currently set to: " + ExplosionSourceConfig.getHealBedAndRespawnAnchorExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal bed and respawn anchor explosions currently set to: " + ExplosionSourceConfig.HEAL_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealEndCrystalExplosionsCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal end crystal explosions currently set to: " + ExplosionSourceConfig.getHealEndCrystalExplosions())); + ctx.getSource().sendMessage(Text.literal("Heal end crystal explosions currently set to: " + ExplosionSourceConfig.HEAL_END_CRYSTAL_EXPLOSIONS.getEntry().getValue())); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/xd/arkosammy/commands/categories/ModeCommands.java b/src/main/java/xd/arkosammy/commands/categories/ModeCommands.java index 65f4f25..185118e 100644 --- a/src/main/java/xd/arkosammy/commands/categories/ModeCommands.java +++ b/src/main/java/xd/arkosammy/commands/categories/ModeCommands.java @@ -62,31 +62,31 @@ public static void register(LiteralCommandNode creeperHeali } private static int setDefaultHealingModeCommand(CommandContext ctx){ - ModeConfig.setHealingMode(ExplosionHealingMode.DEFAULT_MODE.getName()); + ModeConfig.MODE.getEntry().setValue(ExplosionHealingMode.DEFAULT_MODE.getName()); ctx.getSource().sendMessage(Text.literal("Explosion healing mode has been set to: " + ExplosionHealingMode.DEFAULT_MODE.getDisplayName())); return Command.SINGLE_SUCCESS; } private static int setDaytimeHealingModeCommand(CommandContext ctx){ - ModeConfig.setHealingMode(ExplosionHealingMode.DAYTIME_HEALING_MODE.getName()); + ModeConfig.MODE.getEntry().setValue(ExplosionHealingMode.DAYTIME_HEALING_MODE.getName()); ctx.getSource().sendMessage(Text.literal("Explosion healing mode has been set to: " + ExplosionHealingMode.DAYTIME_HEALING_MODE.getDisplayName())); return Command.SINGLE_SUCCESS; } private static int setDifficultyBasedModeCommand(CommandContext ctx){ - ModeConfig.setHealingMode(ExplosionHealingMode.DIFFICULTY_BASED_HEALING_MODE.getName()); + ModeConfig.MODE.getEntry().setValue(ExplosionHealingMode.DIFFICULTY_BASED_HEALING_MODE.getName()); ctx.getSource().sendMessage(Text.literal("Explosion healing mode has been set to: " + ExplosionHealingMode.DIFFICULTY_BASED_HEALING_MODE.getDisplayName())); return Command.SINGLE_SUCCESS; } private static int setBlastResistanceBasedHealingModeCommand(CommandContext ctx){ - ModeConfig.setHealingMode(ExplosionHealingMode.BLAST_RESISTANCE_BASED_HEALING_MODE.getName()); + ModeConfig.MODE.getEntry().setValue(ExplosionHealingMode.BLAST_RESISTANCE_BASED_HEALING_MODE.getName()); ctx.getSource().sendMessage(Text.literal("Explosion healing mode has been set to: " + ExplosionHealingMode.BLAST_RESISTANCE_BASED_HEALING_MODE.getDisplayName())); return Command.SINGLE_SUCCESS; } private static int getHealingModeCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Explosion healing mode currently has been set to: " + ExplosionHealingMode.getFromName(ModeConfig.getHealingMode()).getDisplayName())); + ctx.getSource().sendMessage(Text.literal("Explosion healing mode currently has been set to: " + ExplosionHealingMode.getFromName(ModeConfig.MODE.getEntry().getValue()).getDisplayName())); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/xd/arkosammy/commands/categories/PreferencesCommands.java b/src/main/java/xd/arkosammy/commands/categories/PreferencesCommands.java index e323967..38ebece 100644 --- a/src/main/java/xd/arkosammy/commands/categories/PreferencesCommands.java +++ b/src/main/java/xd/arkosammy/commands/categories/PreferencesCommands.java @@ -162,90 +162,90 @@ public static void register(LiteralCommandNode creeperHeali } private static int setHealOnFlowingWaterCommand(CommandContext ctx) { - PreferencesConfig.setHealOnFlowingWater(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_FLOWING_WATER.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on flowing water has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealOnSourceWaterCommand(CommandContext ctx){ - PreferencesConfig.setHealOnSourceWater(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_SOURCE_WATER.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on source water has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealOnFlowingLavaCommand(CommandContext ctx) { - PreferencesConfig.setHealOnFlowingLava(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_FLOWING_LAVA.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on flowing lava has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealOnSourceLavaCommand(CommandContext ctx){ - PreferencesConfig.setHealOnSourceLava(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_SOURCE_LAVA.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on source lava has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setPlaySoundOnBlockPlacement(CommandContext ctx) { - PreferencesConfig.setBlockPlacementSoundEffect(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.BLOCK_PLACEMENT_SOUND_EFFECT.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Play sound on block placement has been set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealOnHealingPotionSplashCommand(CommandContext ctx){ - PreferencesConfig.setHealOnHealingPotionSplash(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_HEALING_POTION_SPLASH.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on Healing potion splash set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setHealOnRegenerationPotionSplashCommand(CommandContext ctx){ - PreferencesConfig.setHealOnRegenerationPotionSplash(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.HEAL_ON_REGENERATION_POTION_SPLASH.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("Heal on Regeneration potion splash set to: " + BoolArgumentType.getBool(ctx, "value"))); return Command.SINGLE_SUCCESS; } private static int setEnableWhitelist(CommandContext ctx){ - PreferencesConfig.setEnableWhitelist(BoolArgumentType.getBool(ctx, "value")); + PreferencesConfig.ENABLE_WHITELIST.getEntry().setValue(BoolArgumentType.getBool(ctx, "value")); ctx.getSource().sendMessage(Text.literal("The whitelist has been " + (BoolArgumentType.getBool(ctx, "value") ? "enabled" : "disabled"))); return Command.SINGLE_SUCCESS; } private static int getShouldHealOnFlowingWaterCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on flowing water currently set to: " + PreferencesConfig.getHealOnFlowingWater())); + ctx.getSource().sendMessage(Text.literal("Heal on flowing water currently set to: " + PreferencesConfig.HEAL_ON_FLOWING_WATER.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getShouldHealOnSourceWaterCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on source water currently set to: " + PreferencesConfig.getHealOnSourceWater())); + ctx.getSource().sendMessage(Text.literal("Heal on source water currently set to: " + PreferencesConfig.HEAL_ON_SOURCE_WATER.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getShouldHealOnFlowingLavaCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on flowing lava currently set to: " + PreferencesConfig.getHealOnFlowingLava())); + ctx.getSource().sendMessage(Text.literal("Heal on flowing lava currently set to: " + PreferencesConfig.HEAL_ON_FLOWING_LAVA.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getShouldHealOnSourceLavaCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on source lava currently set to: " + PreferencesConfig.getHealOnSourceLava())); + ctx.getSource().sendMessage(Text.literal("Heal on source lava currently set to: " + PreferencesConfig.HEAL_ON_SOURCE_LAVA.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getShouldPlaySoundOnBlockPlacement(CommandContext ctx) { - ctx.getSource().sendMessage(Text.literal("Play sound on block placement currently set to: " + PreferencesConfig.getBlockPlacementSoundEffect())); + ctx.getSource().sendMessage(Text.literal("Play sound on block placement currently set to: " + PreferencesConfig.BLOCK_PLACEMENT_SOUND_EFFECT.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealOnHealingPotionSplashCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on Healing potion splash set to: " + PreferencesConfig.getHealOnHealingPotionSplash())); + ctx.getSource().sendMessage(Text.literal("Heal on Healing potion splash set to: " + PreferencesConfig.HEAL_ON_HEALING_POTION_SPLASH.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getHealOnRegenerationPotionSplashCommand(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("Heal on Regeneration potion splash set to: " + PreferencesConfig.getHealOnRegenerationPotionSplash())); + ctx.getSource().sendMessage(Text.literal("Heal on Regeneration potion splash set to: " + PreferencesConfig.HEAL_ON_REGENERATION_POTION_SPLASH.getEntry().getValue())); return Command.SINGLE_SUCCESS; } private static int getEnableWhitelist(CommandContext ctx){ - ctx.getSource().sendMessage(Text.literal("The whitelist is currently " + (PreferencesConfig.getEnableWhitelist() ? "enabled" : "disabled"))); + ctx.getSource().sendMessage(Text.literal("The whitelist is currently " + (PreferencesConfig.ENABLE_WHITELIST.getEntry().getValue() ? "enabled" : "disabled"))); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/xd/arkosammy/configuration/Config.java b/src/main/java/xd/arkosammy/configuration/Config.java index 5146bed..64f9e41 100644 --- a/src/main/java/xd/arkosammy/configuration/Config.java +++ b/src/main/java/xd/arkosammy/configuration/Config.java @@ -24,7 +24,6 @@ private Config(){} private static final GenericBuilder CONFIG_BUILDER; static { - System.setProperty("nightconfig.preserveInsertionOrder", "true"); GenericBuilder builder; @@ -55,8 +54,8 @@ public static void initializeConfig(){ updateConfigFile(); //Warn the user if these delays were set to 0 or fewer seconds - if(Math.round(Math.max(DelaysConfig.getExplosionHealDelayRaw(), 0) * 20L) == 0) CreeperHealing.LOGGER.warn("Explosion heal delay set to a very low value in the config file. A value of 1 second will be used instead. Please set a valid value in the config file"); - if(Math.round(Math.max(DelaysConfig.getBlockPlacementDelayRaw(), 0) * 20L) == 0) CreeperHealing.LOGGER.warn("Block placement delay set to a very low value in the config file. A value of 1 second will be used instead. Please set a valid value in the config file"); + if(Math.round(Math.max(DelaysConfig.EXPLOSION_HEAL_DELAY.getEntry().getValue(), 0) * 20L) == 0) CreeperHealing.LOGGER.warn("Explosion heal delay set to a very low value in the config file. A value of 1 second will be used instead. Please set a valid value in the config file"); + if(Math.round(Math.max(DelaysConfig.BLOCK_PLACEMENT_DELAY.getEntry().getValue(), 0) * 20L) == 0) CreeperHealing.LOGGER.warn("Block placement delay set to a very low value in the config file. A value of 1 second will be used instead. Please set a valid value in the config file"); CreeperHealing.LOGGER.info("Applied custom config settings"); } } @@ -88,17 +87,14 @@ public static boolean reloadConfigSettingsInMemory(CommandContext { private T value; @@ -47,13 +45,4 @@ public void resetValue(){ this.value = this.defaultValue; } - public static S getValueForNameFromMemory(String entryName, List> entries){ - for(ConfigEntry entry : entries){ - if(entry.getName().equals(entryName)){ - return entry.getValue(); - } - } - return null; - } - } diff --git a/src/main/java/xd/arkosammy/configuration/tables/DelaysConfig.java b/src/main/java/xd/arkosammy/configuration/tables/DelaysConfig.java index 5b87a81..72696dd 100644 --- a/src/main/java/xd/arkosammy/configuration/tables/DelaysConfig.java +++ b/src/main/java/xd/arkosammy/configuration/tables/DelaysConfig.java @@ -3,82 +3,49 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig; import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.ConfigEntry; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; -public final class DelaysConfig { +public enum DelaysConfig { - private DelaysConfig(){} - private static final List> delaysEntryList = new ArrayList<>(); - private static final String TABLE_NAME = "delays"; - private static final String TABLE_COMMENT = """ - Configure the delays related to the healing of explosions."""; - - static { - - delaysEntryList.add(new ConfigEntry<>("explosion_heal_delay", 3.0, """ - (Default = 3) Change the delay in seconds between each explosion and its corresponding healing process.""")); - - delaysEntryList.add(new ConfigEntry<>("block_placement_delay", 1.0, """ + EXPLOSION_HEAL_DELAY(new ConfigEntry<>("explosion_heal_delay", 3.0, """ + (Default = 3) Change the delay in seconds between each explosion and its corresponding healing process.""")), + BLOCK_PLACEMENT_DELAY(new ConfigEntry<>("block_placement_delay", 1.0, """ (Default = 1) Change the delay in seconds between each block placement during the explosion healing process.""")); - } + private final ConfigEntry entry; - private static List> getDelayEntryList(){ - return delaysEntryList; + DelaysConfig(ConfigEntry entry){ + this.entry = entry; } - public static void setExplosionHealDelay(double delay){ - for(ConfigEntry configEntry : getDelayEntryList()){ - if(configEntry.getName().equals("explosion_heal_delay")){ - configEntry.setValue(delay); - } - } + public ConfigEntry getEntry(){ + return this.entry; } - public static void setBlockPlacementDelay(double delay){ - for(ConfigEntry configEntry : getDelayEntryList()){ - if(configEntry.getName().equals("block_placement_delay")){ - configEntry.setValue(delay); - } - } - } + private static final String TABLE_NAME = "delays"; + private static final String TABLE_COMMENT = """ + Configure the delays related to the healing of explosions."""; public static long getExplosionHealDelay(){ - Double explosionHealDelayToReturn = ConfigEntry.getValueForNameFromMemory("explosion_heal_delay", getDelayEntryList()); - if(explosionHealDelayToReturn == null) return 60; - long rounded = Math.round(Math.max(explosionHealDelayToReturn, 0) * 20L); + long rounded = Math.round(Math.max(EXPLOSION_HEAL_DELAY.getEntry().getValue(), 0) * 20L); return rounded == 0 ? 20L : rounded; } public static long getBlockPlacementDelay(){ - Double blockPlacementDelayToReturn = ConfigEntry.getValueForNameFromMemory("block_placement_delay", getDelayEntryList()); - if(blockPlacementDelayToReturn == null) return 20; - long rounded = Math.round(Math.max(blockPlacementDelayToReturn, 0) * 20L); + long rounded = Math.round(Math.max(BLOCK_PLACEMENT_DELAY.getEntry().getValue(), 0) * 20L); return rounded == 0 ? 20L : rounded; } - public static double getExplosionHealDelayRaw(){ - Double explosionHealDelayToReturn = ConfigEntry.getValueForNameFromMemory("explosion_heal_delay", getDelayEntryList()); - if(explosionHealDelayToReturn == null) return 3; - return explosionHealDelayToReturn; - } - - public static double getBlockPlacementDelayRaw(){ - Double blockPlacementDelayToReturn = ConfigEntry.getValueForNameFromMemory("block_placement_delay", getDelayEntryList()); - if(blockPlacementDelayToReturn == null) return 1; - return blockPlacementDelayToReturn; - } public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getDelayEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(DelaysConfig.values()).map(DelaysConfig::getEntry).toList()){ configEntry.resetValue(); } saveSettingsToFile(fileConfig); } public static void saveSettingsToFile(CommentedFileConfig fileConfig){ - for(ConfigEntry entry : getDelayEntryList()){ + for(ConfigEntry entry : Arrays.stream(DelaysConfig.values()).map(DelaysConfig::getEntry).toList()){ fileConfig.set(TABLE_NAME + "." + entry.getName(), entry.getValue()); String entryComment = entry.getComment(); if(entryComment != null) fileConfig.setComment(TABLE_NAME + "." + entry.getName(), entryComment); @@ -87,7 +54,7 @@ public static void saveSettingsToFile(CommentedFileConfig fileConfig){ } public static void loadSettingsToMemory(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getDelayEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(DelaysConfig.values()).map(DelaysConfig::getEntry).toList()){ Object value = fileConfig.getOrElse(TABLE_NAME + "." + configEntry.getName(), configEntry.getDefaultValue()); if(value instanceof Number numberValue){ configEntry.setValue(numberValue.doubleValue()); diff --git a/src/main/java/xd/arkosammy/configuration/tables/ExplosionItemDropConfig.java b/src/main/java/xd/arkosammy/configuration/tables/ExplosionItemDropConfig.java index 707c8fa..d5dc0bd 100644 --- a/src/main/java/xd/arkosammy/configuration/tables/ExplosionItemDropConfig.java +++ b/src/main/java/xd/arkosammy/configuration/tables/ExplosionItemDropConfig.java @@ -3,154 +3,47 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig; import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.ConfigEntry; - -import java.util.ArrayList; -import java.util.List; - -public final class ExplosionItemDropConfig{ - - private ExplosionItemDropConfig(){} - private static final List> explosionItemDropEntries = new ArrayList<>(); - private static final String TABLE_NAME = "explosion_item_drops"; - private static final String TABLE_COMMENT = """ - These settings allow you to configure whether explosions from specific sources are allowed to drop items or not."""; - - static { - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_creeper_explosions", true, """ - (Default = true) Explosions caused by Creepers will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_ghast_explosions", true, """ - (Default = true) Explosions caused by Ghasts will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_wither_explosions", true, """ - (Default = true) Explosions caused by Withers will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_tnt_explosions", true, """ - (Default = true) Explosions caused by TNT will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_tnt_minecart_explosions", true, """ - (Default = true) Explosions caused by TNT minecarts will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_bed_and_respawn_anchor_explosions", true, """ - (Default = true) Explosions caused by beds and respawn anchors will drop items.""")); - - explosionItemDropEntries.add(new ConfigEntry<>("drop_items_on_end_crystal_explosions", true, """ +import java.util.Arrays; + +public enum ExplosionItemDropConfig{ + + DROP_ITEMS_ON_CREEPER_EXPLOSIONS(new ConfigEntry<>("drop_items_on_creeper_explosions", true, """ + (Default = true) Explosions caused by Creepers will drop items.""")), + DROP_ITEMS_ON_GHAST_EXPLOSIONS(new ConfigEntry<>("drop_items_on_ghast_explosions", true, """ + (Default = true) Explosions caused by Ghasts will drop items.""")), + DROP_ITEMS_ON_WITHER_EXPLOSIONS(new ConfigEntry<>("drop_items_on_wither_explosions", true, """ + (Default = true) Explosions caused by Withers will drop items.""")), + DROP_ITEMS_ON_TNT_EXPLOSIONS(new ConfigEntry<>("drop_items_on_tnt_explosions", true, """ + (Default = true) Explosions caused by TNT will drop items.""")), + DROP_ITEMS_ON_TNT_MINECART_EXPLOSIONS(new ConfigEntry<>("drop_items_on_tnt_minecart_explosions", true, """ + (Default = true) Explosions caused by TNT minecarts will drop items.""")), + DROP_ITEMS_ON_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS(new ConfigEntry<>("drop_items_on_bed_and_respawn_anchor_explosions", true, """ + (Default = true) Explosions caused by beds and respawn anchors will drop items.""")), + DROP_ITEMS_ON_END_CRYSTAL_EXPLOSIONS(new ConfigEntry<>("drop_items_on_end_crystal_explosions", true, """ (Default = true) Explosions caused by end crystals will drop items.""")); - } - - private static List> getExplosionItemDropEntries(){ - return explosionItemDropEntries; - } - - public static void setDropItemsOnCreeperExplosions(boolean dropItemsOnCreeperExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_creeper_explosions")){ - configEntry.setValue(dropItemsOnCreeperExplosions); - } - } - } - - public static void setDropItemsOnGhastExplosions(boolean dropItemsOnGhastExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_ghast_explosions")){ - configEntry.setValue(dropItemsOnGhastExplosions); - } - } - } - - public static void setDropItemsOnWitherExplosions(boolean dropItemsOnWitherExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_wither_explosions")){ - configEntry.setValue(dropItemsOnWitherExplosions); - } - } - } - - public static void setDropItemsOnTNTExplosions(boolean dropItemsOnTNTExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_tnt_explosions")){ - configEntry.setValue(dropItemsOnTNTExplosions); - } - } - } + private final ConfigEntry entry; - public static void setDropItemsOnTNTMinecartExplosions(boolean dropItemsOnTNTMinecartExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_tnt_minecart_explosions")){ - configEntry.setValue(dropItemsOnTNTMinecartExplosions); - } - } + ExplosionItemDropConfig(ConfigEntry entry){ + this.entry = entry; } - public static void setDropItemsOnBedAndRespawnAnchorExplosions(boolean dropItemsOnBedAndRespawnAnchorExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_bed_and_respawn_anchor_explosions")){ - configEntry.setValue(dropItemsOnBedAndRespawnAnchorExplosions); - } - } - } - - public static void setDropItemsOnEndCrystalExplosions(boolean dropItemsOnEndCrystalExplosions){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ - if(configEntry.getName().equals("drop_items_on_end_crystal_explosions")){ - configEntry.setValue(dropItemsOnEndCrystalExplosions); - } - } - } - - public static Boolean getDropItemsOnCreeperExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_creeper_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnGhastExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_ghast_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnWitherExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_wither_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnTNTExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_tnt_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnTNTMinecartExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_tnt_minecart_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnBedAndRespawnAnchorExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_bed_and_respawn_anchor_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getDropItemsOnEndCrystalExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("drop_items_on_end_crystal_explosions", getExplosionItemDropEntries()); - if(boolToReturn == null) return true; - return boolToReturn; + public ConfigEntry getEntry(){ + return this.entry; } + private static final String TABLE_NAME = "explosion_item_drops"; + private static final String TABLE_COMMENT = """ + These settings allow you to configure whether explosions from specific sources are allowed to drop items or not."""; public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ + for(ConfigEntry configEntry : Arrays.stream(ExplosionItemDropConfig.values()).map(ExplosionItemDropConfig::getEntry).toList()){ configEntry.resetValue(); } saveSettingsToFile(fileConfig); } public static void saveSettingsToFile(CommentedFileConfig fileConfig){ - for(ConfigEntry entry : getExplosionItemDropEntries()){ + for(ConfigEntry entry : Arrays.stream(ExplosionItemDropConfig.values()).map(ExplosionItemDropConfig::getEntry).toList()){ fileConfig.set(TABLE_NAME + "." + entry.getName(), entry.getValue()); String entryComment = entry.getComment(); if(entryComment != null) fileConfig.setComment(TABLE_NAME + "." + entry.getName(), entryComment); @@ -159,7 +52,7 @@ public static void saveSettingsToFile(CommentedFileConfig fileConfig){ } public static void loadSettingsToMemory(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getExplosionItemDropEntries()){ + for(ConfigEntry configEntry : Arrays.stream(ExplosionItemDropConfig.values()).map(ExplosionItemDropConfig::getEntry).toList()){ Object value = fileConfig.getOrElse(TABLE_NAME + "." + configEntry.getName(), configEntry.getDefaultValue()); if(value instanceof Boolean boolValue){ configEntry.setValue(boolValue); diff --git a/src/main/java/xd/arkosammy/configuration/tables/ExplosionSourceConfig.java b/src/main/java/xd/arkosammy/configuration/tables/ExplosionSourceConfig.java index 9599356..ea7b752 100644 --- a/src/main/java/xd/arkosammy/configuration/tables/ExplosionSourceConfig.java +++ b/src/main/java/xd/arkosammy/configuration/tables/ExplosionSourceConfig.java @@ -4,154 +4,48 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig; import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.ConfigEntry; - -import java.util.ArrayList; -import java.util.List; - -public final class ExplosionSourceConfig { - - private ExplosionSourceConfig(){} - private static final List> explosionSourceEntryList = new ArrayList<>(); - private static final String TABLE_NAME = "explosion_sources"; - private static final String TABLE_COMMENT = """ - Configure which explosions are allowed to heal."""; - - static { - - explosionSourceEntryList.add(new ConfigEntry<>("heal_creeper_explosions", true, """ - (Default = true) Heal explosions caused by Creepers.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_ghast_explosions", false, """ - (Default = false) Heal explosions caused by Ghasts.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_wither_explosions", false, """ - (Default = false) Heal explosions caused by Withers.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_tnt_explosions", false, """ - (Default = false) Heal explosions caused by TNT blocks.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_tnt_minecart_explosions", false, """ - (Default = false) Heal explosions caused by TNT minecarts.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_bed_and_respawn_anchor_explosions", false, """ - (Default = false) Heal explosions caused by beds and respawn anchors.""")); - - explosionSourceEntryList.add(new ConfigEntry<>("heal_end_crystal_explosions", false, """ +import java.util.Arrays; + +public enum ExplosionSourceConfig { + + HEAL_CREEPER_EXPLOSIONS(new ConfigEntry<>("heal_creeper_explosions", true, """ + (Default = true) Heal explosions caused by Creepers.""")), + HEAL_GHAST_EXPLOSIONS(new ConfigEntry<>("heal_ghast_explosions", false, """ + (Default = false) Heal explosions caused by Ghasts.""")), + HEAL_WITHER_EXPLOSIONS(new ConfigEntry<>("heal_wither_explosions", false, """ + (Default = false) Heal explosions caused by Withers.""")), + HEAL_TNT_EXPLOSIONS(new ConfigEntry<>("heal_tnt_explosions", false, """ + (Default = false) Heal explosions caused by TNT blocks.""")), + HEAL_TNT_MINECART_EXPLOSIONS(new ConfigEntry<>("heal_tnt_minecart_explosions", false, """ + (Default = false) Heal explosions caused by TNT minecarts.""")), + HEAL_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS(new ConfigEntry<>("heal_bed_and_respawn_anchor_explosions", false, """ + (Default = false) Heal explosions caused by beds and respawn anchors.""")), + HEAL_END_CRYSTAL_EXPLOSIONS(new ConfigEntry<>("heal_end_crystal_explosions", false, """ (Default = false) Heal explosions caused by end crystals.""")); - } + private final ConfigEntry entry; - private static List> getExplosionSourceEntryList(){ - return explosionSourceEntryList; + ExplosionSourceConfig(ConfigEntry entry){ + this.entry = entry; } - public static void setHealCreeperExplosions(boolean healCreeperExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_creeper_explosions")){ - configEntry.setValue(healCreeperExplosions); - } - } - } - - public static void setHealGhastExplosions(boolean healGhastExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_ghast_explosions")){ - configEntry.setValue(healGhastExplosions); - } - } - } - - public static void setHealWitherExplosions(boolean healWitherExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_wither_explosions")){ - configEntry.setValue(healWitherExplosions); - } - } - } - - public static void setHealTNTExplosions(boolean healTNTExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_tnt_explosions")){ - configEntry.setValue(healTNTExplosions); - } - } + public ConfigEntry getEntry(){ + return this.entry; } - public static void setHealTNTMinecartExplosions(boolean healTNTMinecartExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_tnt_minecart_explosions")){ - configEntry.setValue(healTNTMinecartExplosions); - } - } - } - - public static void setHealBedAndRespawnAnchorExplosions(boolean healBedAndRespawnAnchorExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_bed_and_respawn_anchor_explosions")){ - configEntry.setValue(healBedAndRespawnAnchorExplosions); - } - } - } - - public static void setHealEndCrystalExplosions(boolean healEndCrystalExplosions){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ - if(configEntry.getName().equals("heal_end_crystal_explosions")) { - configEntry.setValue(healEndCrystalExplosions); - } - } - } - - public static Boolean getHealCreeperExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_creeper_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getHealGhastExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_ghast_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } - - public static Boolean getHealWitherExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_wither_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } - - public static Boolean getHealTNTExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_tnt_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } - - public static Boolean getHealTNTMinecartExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_tnt_minecart_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } - - public static Boolean getHealBedAndRespawnAnchorExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_bed_and_respawn_anchor_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } - - public static Boolean getHealEndCrystalExplosions(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_end_crystal_explosions", getExplosionSourceEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } + private static final String TABLE_NAME = "explosion_sources"; + private static final String TABLE_COMMENT = """ + Configure which explosions are allowed to heal."""; public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(ExplosionSourceConfig.values()).map(ExplosionSourceConfig::getEntry).toList()){ configEntry.resetValue(); } saveSettingsToFile(fileConfig); } public static void saveSettingsToFile(CommentedFileConfig fileConfig){ - for(ConfigEntry entry : getExplosionSourceEntryList()){ + for(ConfigEntry entry : Arrays.stream(ExplosionSourceConfig.values()).map(ExplosionSourceConfig::getEntry).toList()){ fileConfig.set(TABLE_NAME + "." + entry.getName(), entry.getValue()); String entryComment = entry.getComment(); if(entryComment != null) fileConfig.setComment(TABLE_NAME + "." + entry.getName(), entryComment); @@ -160,7 +54,7 @@ public static void saveSettingsToFile(CommentedFileConfig fileConfig){ } public static void loadSettingsToMemory(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getExplosionSourceEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(ExplosionSourceConfig.values()).map(ExplosionSourceConfig::getEntry).toList()){ Object value = fileConfig.getOrElse(TABLE_NAME + "." + configEntry.getName(), configEntry.getDefaultValue()); if(value instanceof Boolean boolValue){ configEntry.setValue(boolValue); diff --git a/src/main/java/xd/arkosammy/configuration/tables/ModeConfig.java b/src/main/java/xd/arkosammy/configuration/tables/ModeConfig.java index 5be2705..77f266d 100644 --- a/src/main/java/xd/arkosammy/configuration/tables/ModeConfig.java +++ b/src/main/java/xd/arkosammy/configuration/tables/ModeConfig.java @@ -4,54 +4,36 @@ import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.ConfigEntry; import xd.arkosammy.explosions.ExplosionHealingMode; +import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; - -public final class ModeConfig { - - private ModeConfig(){} - private static final List> modeEntryList = new ArrayList<>(); - private static final String TABLE_NAME = "explosion_healing_mode"; - private static final String TABLE_COMMENT = """ - Choose between different special modes for explosion healing."""; - - static { - - modeEntryList.add(new ConfigEntry<>("mode", ExplosionHealingMode.DEFAULT_MODE.getName(), """ +public enum ModeConfig { + MODE(new ConfigEntry<>("mode", ExplosionHealingMode.DEFAULT_MODE.getName(), """ (Default = "default_mode") Select between any of the following healing modes by copying the string (the text enclosed by the double quotes along with the double quotes) and pasting it into the value of the "mode" setting below: ["default_mode", "daytime_healing_mode", "difficulty_based_healing_mode", "blast_resistance_based_healing_mode"]\s""")); - } + private final ConfigEntry entry; - private static List> getModeEntryList(){ - return modeEntryList; + ModeConfig(ConfigEntry entry){ + this.entry = entry; } - public static void setHealingMode(String explosionModeName){ - for(ConfigEntry configEntry : getModeEntryList()){ - if(configEntry.getName().equals("mode")){ - configEntry.setValue(explosionModeName); - } - } - } - - public static String getHealingMode(){ - String stringToReturn = ConfigEntry.getValueForNameFromMemory("mode", getModeEntryList()); - if(stringToReturn == null) return ExplosionHealingMode.DEFAULT_MODE.getName(); - return stringToReturn; + public ConfigEntry getEntry(){ + return this.entry; } + private static final String TABLE_NAME = "explosion_healing_mode"; + private static final String TABLE_COMMENT = """ + Choose between different special modes for explosion healing."""; public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getModeEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(ModeConfig.values()).map(ModeConfig::getEntry).toList()){ configEntry.resetValue(); } saveSettingsToFile(fileConfig); } public static void saveSettingsToFile(CommentedFileConfig fileConfig){ - for(ConfigEntry entry : getModeEntryList()){ + for(ConfigEntry entry : Arrays.stream(ModeConfig.values()).map(ModeConfig::getEntry).toList()){ fileConfig.set(TABLE_NAME + "." + entry.getName(), entry.getValue()); String entryComment = entry.getComment(); if(entryComment != null) fileConfig.setComment(TABLE_NAME + "." + entry.getName(), entryComment); @@ -60,7 +42,7 @@ public static void saveSettingsToFile(CommentedFileConfig fileConfig){ } public static void loadSettingsToMemory(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getModeEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(ModeConfig.values()).map(ModeConfig::getEntry).toList()){ Object value = fileConfig.getOrElse(TABLE_NAME + "." + configEntry.getName(), configEntry.getDefaultValue()); if(value instanceof String stringValue){ configEntry.setValue(stringValue); diff --git a/src/main/java/xd/arkosammy/configuration/tables/PreferencesConfig.java b/src/main/java/xd/arkosammy/configuration/tables/PreferencesConfig.java index ee80835..b714e5a 100644 --- a/src/main/java/xd/arkosammy/configuration/tables/PreferencesConfig.java +++ b/src/main/java/xd/arkosammy/configuration/tables/PreferencesConfig.java @@ -3,167 +3,45 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig; import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.ConfigEntry; -import java.util.ArrayList; -import java.util.List; - -public final class PreferencesConfig { - - private PreferencesConfig(){} - private static final List> preferencesEntryList = new ArrayList<>(); - private static final String TABLE_NAME = "preferences"; - private static final String TABLE_COMMENT = """ - Toggleable settings to customize the healing of explosions."""; - - static { - - preferencesEntryList.add(new ConfigEntry<>("heal_on_flowing_water", true, """ - (Default = true) Whether or not blocks should be healed where there is currently flowing water.""")); - - preferencesEntryList.add(new ConfigEntry<>("heal_on_source_water", false, """ - (Default = false) Whether or not blocks should healed where there is currently a source water block.""")); - - preferencesEntryList.add(new ConfigEntry<>("heal_on_flowing_lava", true, """ - (Default = true) Whether or not blocks should be healed where there is currently flowing lava.""")); - - preferencesEntryList.add(new ConfigEntry<>("heal_on_source_lava", false, """ - (Default = false) Whether or not blocks should be healed where there is currently a source lava block.""")); - - preferencesEntryList.add(new ConfigEntry<>("block_placement_sound_effect", true, """ - (Default = true) Whether or not a block heal should play a sound effect.""")); - - preferencesEntryList.add(new ConfigEntry<>("heal_on_healing_potion_splash", true, """ - (Default = true) Makes explosion heal immediately upon throwing a splash potion of Healing on them.""")); - - preferencesEntryList.add(new ConfigEntry<>("heal_on_regeneration_potion_splash", true, """ +import java.util.Arrays; + +public enum PreferencesConfig { + + HEAL_ON_FLOWING_WATER(new ConfigEntry<>("heal_on_flowing_water", true, """ + (Default = true) Whether or not blocks should be healed where there is currently flowing water.""")), + HEAL_ON_SOURCE_WATER(new ConfigEntry<>("heal_on_source_water", false, """ + (Default = false) Whether or not blocks should healed where there is currently a source water block.""")), + HEAL_ON_FLOWING_LAVA(new ConfigEntry<>("heal_on_flowing_lava", true, """ + (Default = true) Whether or not blocks should be healed where there is currently flowing lava.""")), + HEAL_ON_SOURCE_LAVA(new ConfigEntry<>("heal_on_source_lava", false, """ + (Default = false) Whether or not blocks should be healed where there is currently a source lava block.""")), + BLOCK_PLACEMENT_SOUND_EFFECT(new ConfigEntry<>("block_placement_sound_effect", true, """ + (Default = true) Whether or not a block heal should play a sound effect.""")), + HEAL_ON_HEALING_POTION_SPLASH(new ConfigEntry<>("heal_on_healing_potion_splash", true, """ + (Default = true) Makes explosion heal immediately upon throwing a splash potion of Healing on them.""")), + HEAL_ON_REGENERATION_POTION_SPLASH(new ConfigEntry<>("heal_on_regeneration_potion_splash", true, """ (Default = true) Makes explosion start their healing process upon throwing a splash potion of Regeneration of them. - This option only modifies the heal delay of the explosion and only affects explosions created with the default healing mode.""")); - - preferencesEntryList.add(new ConfigEntry<>("enable_whitelist", false, """ + This option only modifies the heal delay of the explosion and only affects explosions created with the default healing mode.""")), + ENABLE_WHITELIST(new ConfigEntry<>("enable_whitelist", false, """ (Default = false) Enable or disable the usage of the whitelist""")); - } - - private static List> getPreferencesEntryList(){ - return preferencesEntryList; - } - - public static void setHealOnFlowingWater(boolean healOnFlowingWater){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_flowing_water")){ - configEntry.setValue(healOnFlowingWater); - } - } - } - - public static void setHealOnSourceWater(boolean healOnSourceWater){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_source_water")){ - configEntry.setValue(healOnSourceWater); - } - } - } - - public static void setHealOnFlowingLava(boolean healOnFlowingLava){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_flowing_lava")){ - configEntry.setValue(healOnFlowingLava); - } - } - } - - public static void setHealOnSourceLava(boolean healOnSourceLava){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_source_lava")){ - configEntry.setValue(healOnSourceLava); - } - } - } - - public static void setBlockPlacementSoundEffect(boolean blockPlacementSoundEffect){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("block_placement_sound_effect")){ - configEntry.setValue(blockPlacementSoundEffect); - } - } - } - - public static void setHealOnHealingPotionSplash(boolean healOnHealingPotionSplash){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_healing_potion_splash")){ - configEntry.setValue(healOnHealingPotionSplash); - } - } - } - - public static void setHealOnRegenerationPotionSplash(boolean healOnRegenerationPotionSplash){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("heal_on_regeneration_potion_splash")){ - configEntry.setValue(healOnRegenerationPotionSplash); - } - } - } - - public static void setEnableWhitelist(boolean enableWhitelist){ - CreeperHealing.LOGGER.info("Incoming value: " + enableWhitelist); - for(ConfigEntry configEntry : getPreferencesEntryList()){ - if(configEntry.getName().equals("enable_whitelist")){ - configEntry.setValue(enableWhitelist); - CreeperHealing.LOGGER.info("Set " + configEntry.getValue() + " for " + configEntry.getName()); - } - } - } - - public static Boolean getHealOnFlowingWater(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_flowing_water", getPreferencesEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getHealOnSourceWater(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_source_water", getPreferencesEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } + private final ConfigEntry entry; - public static Boolean getHealOnFlowingLava(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_flowing_lava", getPreferencesEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; + PreferencesConfig(ConfigEntry entry){ + this.entry = entry; } - public static Boolean getHealOnSourceLava(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_source_lava", getPreferencesEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; + public ConfigEntry getEntry(){ + return this.entry; } - public static Boolean getBlockPlacementSoundEffect(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("block_placement_sound_effect", getPreferencesEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getHealOnHealingPotionSplash(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_healing_potion_splash", getPreferencesEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getHealOnRegenerationPotionSplash(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("heal_on_regeneration_potion_splash", getPreferencesEntryList()); - if(boolToReturn == null) return true; - return boolToReturn; - } - - public static Boolean getEnableWhitelist(){ - Boolean boolToReturn = ConfigEntry.getValueForNameFromMemory("enable_whitelist", getPreferencesEntryList()); - if(boolToReturn == null) return false; - return boolToReturn; - } + private static final String TABLE_NAME = "preferences"; + private static final String TABLE_COMMENT = """ + Toggleable settings to customize the healing of explosions."""; public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(PreferencesConfig.values()).map(PreferencesConfig::getEntry).toList()){ configEntry.resetValue(); } @@ -172,30 +50,16 @@ public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){ } public static void saveSettingsToFile(CommentedFileConfig fileConfig){ - - for(ConfigEntry entry : getPreferencesEntryList()){ - - fileConfig.set( - TABLE_NAME + "." + entry.getName(), - entry.getValue() - ); - + for(ConfigEntry entry : Arrays.stream(PreferencesConfig.values()).map(PreferencesConfig::getEntry).toList()){ + fileConfig.set(TABLE_NAME + "." + entry.getName(), entry.getValue()); String entryComment = entry.getComment(); - - if(entryComment != null) - fileConfig.setComment( - TABLE_NAME + "." + entry.getName(), - entryComment - ); - + if(entryComment != null) fileConfig.setComment(TABLE_NAME + "." + entry.getName(), entryComment); } - fileConfig.setComment(TABLE_NAME, TABLE_COMMENT); - } public static void loadSettingsToMemory(CommentedFileConfig fileConfig){ - for(ConfigEntry configEntry : getPreferencesEntryList()){ + for(ConfigEntry configEntry : Arrays.stream(PreferencesConfig.values()).map(PreferencesConfig::getEntry).toList()){ Object value = fileConfig.getOrElse(TABLE_NAME + "." + configEntry.getName(), configEntry.getDefaultValue()); if(value instanceof Boolean boolValue){ configEntry.setValue(boolValue); diff --git a/src/main/java/xd/arkosammy/explosions/AffectedBlock.java b/src/main/java/xd/arkosammy/explosions/AffectedBlock.java index 8f3f987..828d7cd 100644 --- a/src/main/java/xd/arkosammy/explosions/AffectedBlock.java +++ b/src/main/java/xd/arkosammy/explosions/AffectedBlock.java @@ -3,6 +3,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.block.BlockState; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKey; import net.minecraft.server.MinecraftServer; @@ -13,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import xd.arkosammy.CreeperHealing; import xd.arkosammy.configuration.tables.DelaysConfig; +import xd.arkosammy.configuration.tables.PreferencesConfig; import xd.arkosammy.configuration.tables.ReplaceMapConfig; import xd.arkosammy.handlers.DoubleBlockHandler; import xd.arkosammy.handlers.ExplosionListHandler; @@ -26,13 +29,13 @@ public class AffectedBlock { private boolean placed; // Codec to serialize and deserialize AffectedBlock instances. - private static final Codec AFFECTED_BLOCK_CODEC = RecordCodecBuilder.create(blockInfoInstance -> blockInfoInstance.group( + private static final Codec AFFECTED_BLOCK_CODEC = RecordCodecBuilder.create(affectedBlockInstance -> affectedBlockInstance.group( BlockPos.CODEC.fieldOf("Block_Position").forGetter(AffectedBlock::getPos), BlockState.CODEC.fieldOf("Block_State").forGetter(AffectedBlock::getState), World.CODEC.fieldOf("World").forGetter(AffectedBlock::getWorldRegistryKey), Codec.LONG.fieldOf("Block_Timer").forGetter(AffectedBlock::getAffectedBlockTimer), Codec.BOOL.fieldOf("Placed").forGetter(AffectedBlock::isAlreadyPlaced) - ).apply(blockInfoInstance, AffectedBlock::new)); + ).apply(affectedBlockInstance, AffectedBlock::new)); private AffectedBlock(BlockPos pos, BlockState state, RegistryKey registryKey, long affectedBlockTimer, boolean placed){ this.pos = pos; @@ -109,7 +112,7 @@ public void tryHealing(MinecraftServer server, ExplosionEvent currentExplosionEv return; } - if(ExplosionUtils.shouldHealBlock(world, pos)) { + if(this.shouldHealBlock(server)) { if(state.isSolidBlock(world, pos)) ExplosionUtils.pushEntitiesUpwards(world, pos, false); @@ -123,6 +126,19 @@ public void tryHealing(MinecraftServer server, ExplosionEvent currentExplosionEv } + private boolean shouldHealBlock(MinecraftServer server) { + BlockState blockState = this.getWorld(server).getBlockState(this.pos); + FluidState fluidState = blockState.getFluidState(); + + if (ExplosionUtils.isStateAirOrFire(blockState)) { + return true; + } else if ((fluidState.getFluid().equals(Fluids.FLOWING_WATER) && PreferencesConfig.HEAL_ON_FLOWING_WATER.getEntry().getValue()) || + (fluidState.getFluid().equals(Fluids.WATER) && PreferencesConfig.HEAL_ON_SOURCE_WATER.getEntry().getValue())) { + return true; + } else return (fluidState.getFluid().equals(Fluids.FLOWING_LAVA) && PreferencesConfig.HEAL_ON_FLOWING_LAVA.getEntry().getValue()) || + (fluidState.getFluid().equals(Fluids.LAVA) && PreferencesConfig.HEAL_ON_SOURCE_LAVA.getEntry().getValue()); + } + //Called whenever the config is reloaded and when the server/world starts public static void updateAffectedBlocksTimers(){ CreeperHealing.setHealerHandlerLock(false); diff --git a/src/main/java/xd/arkosammy/explosions/ExplosionEvent.java b/src/main/java/xd/arkosammy/explosions/ExplosionEvent.java index 22d3628..5c76ac5 100644 --- a/src/main/java/xd/arkosammy/explosions/ExplosionEvent.java +++ b/src/main/java/xd/arkosammy/explosions/ExplosionEvent.java @@ -42,10 +42,10 @@ private ExplosionEvent(List affectedBlocksList, String explosionM } public static ExplosionEvent newExplosionEvent(List affectedBlocksList, World world) { - ExplosionEvent explosionEvent = new ExplosionEvent(ExplosionUtils.sortAffectedBlocksList(affectedBlocksList, world.getServer()), ModeConfig.getHealingMode(), DelaysConfig.getExplosionHealDelay(), 0); + ExplosionEvent explosionEvent = new ExplosionEvent(ExplosionUtils.sortAffectedBlocksList(affectedBlocksList, world.getServer()), ModeConfig.MODE.getEntry().getValue(), DelaysConfig.getExplosionHealDelay(), 0); explosionEvent.setUpExplosionHealingMode(world); - Set collidingExplosions = ExplosionUtils.getCollidingWaitingExplosions(affectedBlocksList.stream().map(AffectedBlock::getPos).collect(Collectors.toList())); + Set collidingExplosions = ExplosionUtils.getCollidingWaitingExplosions(affectedBlocksList.stream().map(AffectedBlock::getPos).toList()); if(collidingExplosions.isEmpty()){ return explosionEvent; } else { diff --git a/src/main/java/xd/arkosammy/explosions/ExplosionUtils.java b/src/main/java/xd/arkosammy/explosions/ExplosionUtils.java index eda69e9..9c3b1f5 100644 --- a/src/main/java/xd/arkosammy/explosions/ExplosionUtils.java +++ b/src/main/java/xd/arkosammy/explosions/ExplosionUtils.java @@ -4,8 +4,6 @@ import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; @@ -52,8 +50,8 @@ public static Set getCollidingWaitingExplosions(List a for(ExplosionEvent explosionEvent : ExplosionListHandler.getExplosionEventList()){ if(explosionEvent.getExplosionTimer() > 0){ - BlockPos centerOfCurrentExplosion = new BlockPos(getCenterXCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).collect(Collectors.toList())), getCenterYCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).collect(Collectors.toList())), getCenterZCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).collect(Collectors.toList()))); - int currentExplosionAverageRadius = getMaxExplosionRadius(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).collect(Collectors.toList())); + BlockPos centerOfCurrentExplosion = new BlockPos(getCenterXCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList()), getCenterYCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList()), getCenterZCoordinate(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList())); + int currentExplosionAverageRadius = getMaxExplosionRadius(explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList()); if(Math.floor(Math.sqrt(centerOfNewExplosion.getSquaredDistance(centerOfCurrentExplosion))) <= newExplosionAverageRadius + currentExplosionAverageRadius){ collidingExplosions.add(explosionEvent); } @@ -157,54 +155,10 @@ private static int getMaxExplosionRadius(List affectedCoordinates){ } public static boolean shouldPlaySoundOnBlockHeal(World world, BlockState state) { - return !world.isClient && !state.isAir() && PreferencesConfig.getBlockPlacementSoundEffect(); + return !world.isClient && !state.isAir() && PreferencesConfig.BLOCK_PLACEMENT_SOUND_EFFECT.getEntry().getValue(); } - public static boolean shouldHealBlock(@NotNull World world, BlockPos pos) { - BlockState blockState = world.getBlockState(pos); - FluidState fluidState = blockState.getFluidState(); - - if (isStateAirOrFire(blockState)) { - return true; - } else if ((fluidState.getFluid().equals(Fluids.FLOWING_WATER) && PreferencesConfig.getHealOnFlowingWater()) || - (fluidState.getFluid().equals(Fluids.WATER) && PreferencesConfig.getHealOnSourceWater())) { - return true; - } else return (fluidState.getFluid().equals(Fluids.FLOWING_LAVA) && PreferencesConfig.getHealOnFlowingLava()) || - (fluidState.getFluid().equals(Fluids.LAVA) && PreferencesConfig.getHealOnSourceLava()); - } - - public static boolean shouldHealDoubleBlock(@NotNull World world, BlockPos firstHalfPos, BlockPos secondHalfPos) { - BlockState firstHalfState = world.getBlockState(firstHalfPos); - BlockState secondHalfState = world.getBlockState(secondHalfPos); - FluidState firstHalfFluidState = firstHalfState.getFluidState(); - FluidState secondHalfFluidState = secondHalfState.getFluidState(); - - if (isStateAirOrFire(firstHalfState) && isStateAirOrFire(secondHalfState)) { - return true; - } else if (((firstHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER) && isStateAirOrFire(secondHalfState)) || - (isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER)) || - (firstHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER))) - && PreferencesConfig.getHealOnFlowingWater()) { - return true; - } else if (((firstHalfFluidState.getFluid().equals(Fluids.WATER) && isStateAirOrFire(secondHalfState)) || - (isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.WATER)) || - (firstHalfFluidState.getFluid().equals(Fluids.WATER) && secondHalfFluidState.getFluid().equals(Fluids.WATER))) - && PreferencesConfig.getHealOnSourceWater()) { - return true; - } else if (((firstHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA) && isStateAirOrFire(secondHalfState)) || - (isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA)) || - (firstHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA))) - && PreferencesConfig.getHealOnFlowingLava()) { - return true; - } else { - return ((firstHalfFluidState.getFluid().equals(Fluids.LAVA) && isStateAirOrFire(secondHalfState)) || - (isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.LAVA)) || - (firstHalfFluidState.getFluid().equals(Fluids.LAVA) && secondHalfFluidState.getFluid().equals(Fluids.LAVA))) - && PreferencesConfig.getHealOnSourceLava(); - } - } - - private static boolean isStateAirOrFire(BlockState state) { + public static boolean isStateAirOrFire(BlockState state) { return state.isAir() || state.getBlock().equals(Blocks.FIRE) || state.getBlock().equals(Blocks.SOUL_FIRE); } diff --git a/src/main/java/xd/arkosammy/handlers/DoubleBlockHandler.java b/src/main/java/xd/arkosammy/handlers/DoubleBlockHandler.java index ff26ded..d431707 100644 --- a/src/main/java/xd/arkosammy/handlers/DoubleBlockHandler.java +++ b/src/main/java/xd/arkosammy/handlers/DoubleBlockHandler.java @@ -3,11 +3,15 @@ import net.minecraft.block.*; import net.minecraft.block.enums.BedPart; import net.minecraft.block.enums.DoubleBlockHalf; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.sound.SoundCategory; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; +import xd.arkosammy.configuration.tables.PreferencesConfig; import xd.arkosammy.explosions.ExplosionUtils; import xd.arkosammy.explosions.ExplosionEvent; @@ -33,7 +37,7 @@ private static void handleDoubleBlocks(World world, BlockState firstHalfState, B BlockState secondHalfState = firstHalfState.getBlock().getStateWithProperties(firstHalfState).with(Properties.DOUBLE_BLOCK_HALF, secondHalf); BlockPos secondHalfPos = secondHalfState.get(Properties.DOUBLE_BLOCK_HALF).equals(DoubleBlockHalf.UPPER) ? firstHalfPos.offset(Direction.Axis.Y, 1) : firstHalfPos.offset(Direction.Axis.Y, -1); - if(ExplosionUtils.shouldHealDoubleBlock(world, firstHalfPos, secondHalfPos)) { + if(shouldHealDoubleBlock(world, firstHalfPos, secondHalfPos)) { BlockState stateToPushFrom = firstHalfState.get(Properties.DOUBLE_BLOCK_HALF).equals(DoubleBlockHalf.LOWER) ? firstHalfState : secondHalfState; BlockPos posToPushFrom = firstHalfState.get(Properties.DOUBLE_BLOCK_HALF).equals(DoubleBlockHalf.LOWER) ? firstHalfPos : firstHalfPos.offset(Direction.Axis.Y, -1); @@ -71,7 +75,7 @@ private static void handleBedPart(World world, BlockState firstHalfState, BlockP } } - if (ExplosionUtils.shouldHealDoubleBlock(world, firstHalfPos, secondHalfPos)) { + if (shouldHealDoubleBlock(world, firstHalfPos, secondHalfPos)) { if(firstHalfState.isSolidBlock(world, firstHalfPos)) ExplosionUtils.pushEntitiesUpwards(world, firstHalfPos, false); @@ -88,4 +92,35 @@ private static void handleBedPart(World world, BlockState firstHalfState, BlockP currentExplosionEvent.markAffectedBlockAsPlaced(secondHalfState, secondHalfPos, world); } + private static boolean shouldHealDoubleBlock(@NotNull World world, BlockPos firstHalfPos, BlockPos secondHalfPos) { + BlockState firstHalfState = world.getBlockState(firstHalfPos); + BlockState secondHalfState = world.getBlockState(secondHalfPos); + FluidState firstHalfFluidState = firstHalfState.getFluidState(); + FluidState secondHalfFluidState = secondHalfState.getFluidState(); + + if (ExplosionUtils.isStateAirOrFire(firstHalfState) && ExplosionUtils.isStateAirOrFire(secondHalfState)) { + return true; + } else if (((firstHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER) && ExplosionUtils.isStateAirOrFire(secondHalfState)) || + (ExplosionUtils.isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER)) || + (firstHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_WATER))) + && PreferencesConfig.HEAL_ON_FLOWING_WATER.getEntry().getValue()) { + return true; + } else if (((firstHalfFluidState.getFluid().equals(Fluids.WATER) && ExplosionUtils.isStateAirOrFire(secondHalfState)) || + (ExplosionUtils.isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.WATER)) || + (firstHalfFluidState.getFluid().equals(Fluids.WATER) && secondHalfFluidState.getFluid().equals(Fluids.WATER))) + && PreferencesConfig.HEAL_ON_SOURCE_WATER.getEntry().getValue()) { + return true; + } else if (((firstHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA) && ExplosionUtils.isStateAirOrFire(secondHalfState)) || + (ExplosionUtils.isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA)) || + (firstHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA) && secondHalfFluidState.getFluid().equals(Fluids.FLOWING_LAVA))) + && PreferencesConfig.HEAL_ON_FLOWING_LAVA.getEntry().getValue()) { + return true; + } else { + return ((firstHalfFluidState.getFluid().equals(Fluids.LAVA) && ExplosionUtils.isStateAirOrFire(secondHalfState)) || + (ExplosionUtils.isStateAirOrFire(firstHalfState) && secondHalfFluidState.getFluid().equals(Fluids.LAVA)) || + (firstHalfFluidState.getFluid().equals(Fluids.LAVA) && secondHalfFluidState.getFluid().equals(Fluids.LAVA))) + && PreferencesConfig.HEAL_ON_SOURCE_LAVA.getEntry().getValue(); + } + } + } diff --git a/src/main/java/xd/arkosammy/handlers/ExplosionListHandler.java b/src/main/java/xd/arkosammy/handlers/ExplosionListHandler.java index 4d72612..83da11e 100644 --- a/src/main/java/xd/arkosammy/handlers/ExplosionListHandler.java +++ b/src/main/java/xd/arkosammy/handlers/ExplosionListHandler.java @@ -12,6 +12,7 @@ public final class ExplosionListHandler { private ExplosionListHandler(){} + private static final List explosionEventList = new CopyOnWriteArrayList<>(); public static List getExplosionEventList(){ diff --git a/src/main/java/xd/arkosammy/mixin/ExplosionItemDropMixin.java b/src/main/java/xd/arkosammy/mixin/ExplosionItemDropMixin.java index 60d719e..e2af002 100644 --- a/src/main/java/xd/arkosammy/mixin/ExplosionItemDropMixin.java +++ b/src/main/java/xd/arkosammy/mixin/ExplosionItemDropMixin.java @@ -26,13 +26,13 @@ private boolean shouldExplosionDropItems(boolean dropItems, @Local Explosion exp Entity causingEntity = explosion.getEntity(); Entity causingLivingEntity = explosion.getCausingEntity(); DamageSource damageSource = explosion.getDamageSource(); - boolean shouldNotDropItems = (causingLivingEntity instanceof CreeperEntity && !ExplosionItemDropConfig.getDropItemsOnCreeperExplosions()) - || (causingLivingEntity instanceof GhastEntity && !ExplosionItemDropConfig.getDropItemsOnGhastExplosions()) - || (causingLivingEntity instanceof WitherEntity && !ExplosionItemDropConfig.getDropItemsOnWitherExplosions()) - || (causingEntity instanceof TntEntity && !ExplosionItemDropConfig.getDropItemsOnTNTExplosions()) - || (causingEntity instanceof TntMinecartEntity && !ExplosionItemDropConfig.getDropItemsOnTNTMinecartExplosions()) - || (damageSource.isOf(DamageTypes.BAD_RESPAWN_POINT) && !ExplosionItemDropConfig.getDropItemsOnBedAndRespawnAnchorExplosions()) - || (causingEntity instanceof EndCrystalEntity && !ExplosionItemDropConfig.getDropItemsOnEndCrystalExplosions()); + boolean shouldNotDropItems = (causingLivingEntity instanceof CreeperEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_CREEPER_EXPLOSIONS.getEntry().getValue()) + || (causingLivingEntity instanceof GhastEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_GHAST_EXPLOSIONS.getEntry().getValue()) + || (causingLivingEntity instanceof WitherEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_WITHER_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof TntEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof TntMinecartEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_TNT_MINECART_EXPLOSIONS.getEntry().getValue()) + || (damageSource.isOf(DamageTypes.BAD_RESPAWN_POINT) && !ExplosionItemDropConfig.DROP_ITEMS_ON_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof EndCrystalEntity && !ExplosionItemDropConfig.DROP_ITEMS_ON_END_CRYSTAL_EXPLOSIONS.getEntry().getValue()); if (shouldNotDropItems) { ExplosionUtils.SHOULD_NOT_DROP_ITEMS.set(true); } diff --git a/src/main/java/xd/arkosammy/mixin/ExplosionListenerMixin.java b/src/main/java/xd/arkosammy/mixin/ExplosionListenerMixin.java index d4a6bd5..67e643f 100644 --- a/src/main/java/xd/arkosammy/mixin/ExplosionListenerMixin.java +++ b/src/main/java/xd/arkosammy/mixin/ExplosionListenerMixin.java @@ -41,7 +41,6 @@ public abstract class ExplosionListenerMixin { @Shadow @Nullable public abstract LivingEntity getCausingEntity(); @Shadow public abstract List getAffectedBlocks(); @Shadow @Nullable public abstract Entity getEntity(); - @Shadow public abstract DamageSource getDamageSource(); @Inject(method = "collectBlocksAndDamageEntities", at = @At("RETURN")) @@ -52,34 +51,30 @@ private void storeCurrentExplosionIfNeeded(CallbackInfo ci){ @Unique private void storeExplosion(List affectedBlocksPos){ - if(affectedBlocksPos.isEmpty()) return; ArrayList affectedBlocks = new ArrayList<>(); - for (BlockPos pos : affectedBlocksPos) { if (world.getBlockState(pos).isAir() || world.getBlockState(pos).getBlock().equals(Blocks.TNT) || world.getBlockState(pos).getBlock().equals(Blocks.FIRE) || world.getBlockState(pos).getBlock().equals(Blocks.SOUL_FIRE)) { continue; // Skip the current iteration if the block state is air, TNT, or fire } String blockIdentifier = Registries.BLOCK.getId(world.getBlockState(pos).getBlock()).toString(); - if (!PreferencesConfig.getEnableWhitelist() || WhitelistConfig.getWhitelist().contains(blockIdentifier)) { + if (!PreferencesConfig.ENABLE_WHITELIST.getEntry().getValue() || WhitelistConfig.getWhitelist().contains(blockIdentifier)) { affectedBlocks.add(AffectedBlock.newAffectedBlock(pos, world)); } } - if(affectedBlocks.isEmpty()) return; ExplosionListHandler.getExplosionEventList().add(ExplosionEvent.newExplosionEvent(affectedBlocks, world)); } @Unique private boolean shouldStoreExplosionFromSourceType(LivingEntity causingLivingEntity, Entity causingEntity, DamageSource damageSource){ - return (causingLivingEntity instanceof CreeperEntity && ExplosionSourceConfig.getHealCreeperExplosions()) - || (causingLivingEntity instanceof GhastEntity && ExplosionSourceConfig.getHealGhastExplosions()) - || (causingLivingEntity instanceof WitherEntity && ExplosionSourceConfig.getHealWitherExplosions()) - || (causingEntity instanceof TntEntity && ExplosionSourceConfig.getHealTNTExplosions()) - || (causingEntity instanceof TntMinecartEntity && ExplosionSourceConfig.getHealTNTMinecartExplosions()) - || (damageSource.isOf(DamageTypes.BAD_RESPAWN_POINT) && ExplosionSourceConfig.getHealBedAndRespawnAnchorExplosions()) - || (causingEntity instanceof EndCrystalEntity && ExplosionSourceConfig.getHealEndCrystalExplosions()); - + return (causingLivingEntity instanceof CreeperEntity && ExplosionSourceConfig.HEAL_CREEPER_EXPLOSIONS.getEntry().getValue()) + || (causingLivingEntity instanceof GhastEntity && ExplosionSourceConfig.HEAL_GHAST_EXPLOSIONS.getEntry().getValue()) + || (causingLivingEntity instanceof WitherEntity && ExplosionSourceConfig.HEAL_WITHER_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof TntEntity && ExplosionSourceConfig.HEAL_TNT_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof TntMinecartEntity && ExplosionSourceConfig.HEAL_TNT_MINECART_EXPLOSIONS.getEntry().getValue()) + || (damageSource.isOf(DamageTypes.BAD_RESPAWN_POINT) && ExplosionSourceConfig.HEAL_BED_AND_RESPAWN_ANCHOR_EXPLOSIONS.getEntry().getValue()) + || (causingEntity instanceof EndCrystalEntity && ExplosionSourceConfig.HEAL_END_CRYSTAL_EXPLOSIONS.getEntry().getValue()); } diff --git a/src/main/java/xd/arkosammy/mixin/HealingPotionMixin.java b/src/main/java/xd/arkosammy/mixin/HealingPotionMixin.java index 390f258..307b53a 100644 --- a/src/main/java/xd/arkosammy/mixin/HealingPotionMixin.java +++ b/src/main/java/xd/arkosammy/mixin/HealingPotionMixin.java @@ -37,7 +37,7 @@ private void affectExplosionOnSplashPotionHit(HitResult hitResult, CallbackInfo } else { return; } - if(statusEffects.contains(StatusEffects.INSTANT_HEALTH) && PreferencesConfig.getHealOnHealingPotionSplash()) { + if(statusEffects.contains(StatusEffects.INSTANT_HEALTH) && PreferencesConfig.HEAL_ON_HEALING_POTION_SPLASH.getEntry().getValue()) { ExplosionListHandler.getExplosionEventList().forEach(explosionEvent -> { List affectedBlockPositions = explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList(); if(affectedBlockPositions.contains(potionHitPosition)){ @@ -45,7 +45,7 @@ private void affectExplosionOnSplashPotionHit(HitResult hitResult, CallbackInfo explosionEvent.getAffectedBlocksList().forEach(affectedBlock -> affectedBlock.setAffectedBlockTimer(1)); } }); - } else if (statusEffects.contains(StatusEffects.REGENERATION) && PreferencesConfig.getHealOnRegenerationPotionSplash()){ + } else if (statusEffects.contains(StatusEffects.REGENERATION) && PreferencesConfig.HEAL_ON_REGENERATION_POTION_SPLASH.getEntry().getValue()){ ExplosionListHandler.getExplosionEventList().forEach(explosionEvent -> { List affectedBlockPositions = explosionEvent.getAffectedBlocksList().stream().map(AffectedBlock::getPos).toList(); if(affectedBlockPositions.contains(potionHitPosition) && explosionEvent.getExplosionMode() == ExplosionHealingMode.DEFAULT_MODE){