From ba96937496463e6a3b1f4477a6277806b46d44b2 Mon Sep 17 00:00:00 2001 From: Flo56958 Date: Thu, 12 Dec 2024 00:47:10 +0100 Subject: [PATCH] Add more Player Config options --- .../modifiers/CooldownModifier.java | 10 ++--- .../minetinker/modifiers/types/AutoSmelt.java | 34 ++++++++++------ .../minetinker/modifiers/types/Homing.java | 18 ++++++++- .../modifiers/types/Propelling.java | 39 +++++++++++++------ .../PlayerConfigurationManager.java | 2 +- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/main/java/de/flo56958/minetinker/modifiers/CooldownModifier.java b/src/main/java/de/flo56958/minetinker/modifiers/CooldownModifier.java index 85a1ff95..28015f42 100644 --- a/src/main/java/de/flo56958/minetinker/modifiers/CooldownModifier.java +++ b/src/main/java/de/flo56958/minetinker/modifiers/CooldownModifier.java @@ -64,7 +64,7 @@ protected final boolean onCooldown(@NotNull final Player player, @NotNull final protected final void setCooldown(@NotNull final Player player, @NotNull final ItemStack tool) { if (this.cooldownInSeconds > 1 / 20.0) DataHandler.setTag(tool, this.getKey() + "cooldown", System.currentTimeMillis(), PersistentDataType.LONG); - if (PlayerConfigurationManager.getInstance().getBoolean(player, OFF_COOLDOWN_SOUND)) + if (PlayerConfigurationManager.getInstance().getBoolean(player, OFF_COOLDOWN_ALERT)) planOffCooldownAlert(player, tool); } @@ -107,9 +107,9 @@ private void planOffCooldownAlert(@NotNull final Player player, @NotNull final I getCooldown(modManager.getModLevel(tool, this)) / 50); } - protected final PlayerConfigurationOption OFF_COOLDOWN_SOUND = - new PlayerConfigurationOption(this, "off-cooldown-sound", PlayerConfigurationOption.Type.BOOLEAN, - "off-cooldown-sound", false); + protected final PlayerConfigurationOption OFF_COOLDOWN_ALERT = + new PlayerConfigurationOption(this, "off-cooldown-alert", PlayerConfigurationOption.Type.BOOLEAN, + "off-cooldown-alert", false); protected final PlayerConfigurationOption OFF_COOLDOWN_NOTE = new PlayerConfigurationOption(this, "off-cooldown-note", PlayerConfigurationOption.Type.INTEGER, @@ -121,7 +121,7 @@ private void planOffCooldownAlert(@NotNull final Player player, @NotNull final I @Override public List getPCIOptions() { - final ArrayList playerConfigurationOptions = new ArrayList<>(List.of(OFF_COOLDOWN_SOUND, OFF_COOLDOWN_NOTE, OFF_COOLDOWN_INSTRUMENT)); + final ArrayList playerConfigurationOptions = new ArrayList<>(List.of(OFF_COOLDOWN_ALERT, OFF_COOLDOWN_NOTE, OFF_COOLDOWN_INSTRUMENT)); playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName)); return playerConfigurationOptions; } diff --git a/src/main/java/de/flo56958/minetinker/modifiers/types/AutoSmelt.java b/src/main/java/de/flo56958/minetinker/modifiers/types/AutoSmelt.java index 5b595e99..73fa4a3e 100644 --- a/src/main/java/de/flo56958/minetinker/modifiers/types/AutoSmelt.java +++ b/src/main/java/de/flo56958/minetinker/modifiers/types/AutoSmelt.java @@ -4,11 +4,13 @@ import de.flo56958.minetinker.MineTinker; import de.flo56958.minetinker.api.events.MTBlockBreakEvent; import de.flo56958.minetinker.data.ToolType; -import de.flo56958.minetinker.modifiers.Modifier; +import de.flo56958.minetinker.modifiers.PlayerConfigurableModifier; import de.flo56958.minetinker.utils.ChatWriter; import de.flo56958.minetinker.utils.ConfigurationManager; import de.flo56958.minetinker.utils.LanguageManager; import de.flo56958.minetinker.utils.data.DataHandler; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationManager; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationOption; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; @@ -27,14 +29,12 @@ import java.util.*; import java.util.regex.Pattern; -public class AutoSmelt extends Modifier implements Listener { +public class AutoSmelt extends PlayerConfigurableModifier implements Listener { private static AutoSmelt instance; private final EnumMap conversions = new EnumMap<>(Material.class); private int percentagePerLevel; - private boolean hasSound; - private boolean hasParticles; private boolean worksUnderWater; private boolean toggleable; @@ -73,8 +73,6 @@ public void reload() { config.addDefault("SlotCost", 1); config.addDefault("ModifierItemMaterial", Material.FURNACE.name()); config.addDefault("PercentagePerLevel", 100); - config.addDefault("Sound", true); //Auto-Smelt makes a sound - config.addDefault("Particles", true); //Auto-Smelt will create a particle effect when triggered config.addDefault("WorksUnderWater", true); config.addDefault("Toggleable", false); @@ -175,8 +173,6 @@ public void reload() { init(); this.percentagePerLevel = config.getInt("PercentagePerLevel", 100); - this.hasSound = config.getBoolean("Sound", true); - this.hasParticles = config.getBoolean("Particles", true); this.worksUnderWater = config.getBoolean("WorksUnderWater", true); this.toggleable = config.getBoolean("Toggleable", false); @@ -252,10 +248,11 @@ public void effect(@NotNull MTBlockBreakEvent event) { breakEvent.setDropItems(false); - if (this.hasParticles) block.getLocation().getWorld().spawnParticle(Particle.FLAME, block.getLocation(), 5); + if (PlayerConfigurationManager.getInstance().getBoolean(player, PARTICLES)) + block.getLocation().getWorld().spawnParticle(Particle.FLAME, block.getLocation(), 5); - if (this.hasSound) block.getLocation().getWorld().playSound(block.getLocation(), - Sound.ENTITY_GENERIC_BURN, 0.2F, 0.5F); + if (PlayerConfigurationManager.getInstance().getBoolean(player, SOUND)) + block.getLocation().getWorld().playSound(block.getLocation(), Sound.ENTITY_GENERIC_BURN, 0.2F, 0.5F); //Track stats final int stat = DataHandler.getTagOrDefault(tool, getKey() + "_stat_used", PersistentDataType.INTEGER, 0); @@ -322,4 +319,19 @@ public String toString() { return material.toString() + regex + amount + regex + luckable; } } + + private final PlayerConfigurationOption PARTICLES = + new PlayerConfigurationOption(this,"particles", PlayerConfigurationOption.Type.BOOLEAN, + "particles", true); + + private final PlayerConfigurationOption SOUND = + new PlayerConfigurationOption(this,"sound", PlayerConfigurationOption.Type.BOOLEAN, + "sound", true); + + @Override + public List getPCIOptions() { + final ArrayList playerConfigurationOptions = new ArrayList<>(List.of(PARTICLES, SOUND)); + playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName)); + return playerConfigurationOptions; + } } diff --git a/src/main/java/de/flo56958/minetinker/modifiers/types/Homing.java b/src/main/java/de/flo56958/minetinker/modifiers/types/Homing.java index aa727042..d58abc6c 100644 --- a/src/main/java/de/flo56958/minetinker/modifiers/types/Homing.java +++ b/src/main/java/de/flo56958/minetinker/modifiers/types/Homing.java @@ -3,9 +3,12 @@ import de.flo56958.minetinker.MineTinker; import de.flo56958.minetinker.api.events.MTProjectileLaunchEvent; import de.flo56958.minetinker.data.ToolType; -import de.flo56958.minetinker.modifiers.Modifier; +import de.flo56958.minetinker.modifiers.PlayerConfigurableModifier; import de.flo56958.minetinker.utils.ConfigurationManager; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationManager; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationOption; import org.bukkit.Bukkit; +import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.*; @@ -17,7 +20,7 @@ import java.io.File; import java.util.*; -public class Homing extends Modifier implements Listener { +public class Homing extends PlayerConfigurableModifier implements Listener { private static Homing instance; private int radius; @@ -108,6 +111,10 @@ public void onShoot(final MTProjectileLaunchEvent event) { final int modLevel = modManager.getModLevel(tool, this); if (modLevel <= 0) return; + if (!PlayerConfigurationManager.getInstance().getBoolean(player, ENABLED)) return; + + arrow.setColor(Color.BLACK); + final long start = System.currentTimeMillis(); final double accuracy = modLevel * this.accuracy; final Runnable runnable = new Runnable() { @@ -147,4 +154,11 @@ public void run() { Bukkit.getServer().getScheduler().runTaskLater(this.getSource(), runnable, 3); } + + private final PlayerConfigurationOption ENABLED = new PlayerConfigurationOption(this, "enabled", PlayerConfigurationOption.Type.BOOLEAN, "enabled", true); + + @Override + public List getPCIOptions() { + return List.of(ENABLED); + } } diff --git a/src/main/java/de/flo56958/minetinker/modifiers/types/Propelling.java b/src/main/java/de/flo56958/minetinker/modifiers/types/Propelling.java index 402d1475..a3b68f57 100644 --- a/src/main/java/de/flo56958/minetinker/modifiers/types/Propelling.java +++ b/src/main/java/de/flo56958/minetinker/modifiers/types/Propelling.java @@ -6,6 +6,8 @@ import de.flo56958.minetinker.utils.ChatWriter; import de.flo56958.minetinker.utils.ConfigurationManager; import de.flo56958.minetinker.utils.data.DataHandler; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationManager; +import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationOption; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -23,6 +25,7 @@ import java.io.File; import java.util.Arrays; +import java.util.Comparator; import java.util.List; public class Propelling extends CooldownModifier implements Listener { @@ -30,8 +33,6 @@ public class Propelling extends CooldownModifier implements Listener { private static Propelling instance; private int durabilityLoss; private double speedPerLevel; - private boolean sound; - private boolean particles; private Propelling() { super(MineTinker.getPlugin()); @@ -75,8 +76,6 @@ public void reload() { config.addDefault("CooldownInSeconds", 5.0); config.addDefault("Elytra.DurabilityLoss", 10); config.addDefault("Elytra.SpeedPerLevel", 0.15); - config.addDefault("Elytra.Sound", true); - config.addDefault("Elytra.Particles", true); config.addDefault("EnchantCost", 25); config.addDefault("Enchantable", true); @@ -92,9 +91,6 @@ public void reload() { this.durabilityLoss = config.getInt("Elytra.DurabilityLoss", 10); this.speedPerLevel = config.getDouble("Elytra.SpeedPerLevel", 0.05); this.cooldownInSeconds = config.getDouble("CooldownInSeconds", 5.0); - - this.sound = config.getBoolean("Elytra.Sound", true); - this.particles = config.getBoolean("Elytra.Particles", true); } @Override @@ -143,14 +139,33 @@ public void onElytraSneak(final PlayerToggleSneakEvent event) { player.setVelocity(player.getVelocity().add(dir)); } + if (loc.getWorld() != null) { + if (PlayerConfigurationManager.getInstance().getBoolean(player, PARTICLES)) + loc.getWorld().spawnParticle(Particle.CLOUD, loc, 30, 0.5F, 0.5F, 0.5F, 0.0F); - - if (particles && loc.getWorld() != null) - loc.getWorld().spawnParticle(Particle.CLOUD, loc, 30, 0.5F, 0.5F, 0.5F, 0.0F); - - if (sound) player.getWorld().playSound(loc, Sound.ENTITY_ENDER_DRAGON_FLAP, 0.5F, 0.5F); + if (PlayerConfigurationManager.getInstance().getBoolean(player, SOUND)) + loc.getWorld().playSound(loc, Sound.ENTITY_ENDER_DRAGON_FLAP, 0.5F, 0.5F); + } setCooldown(player, elytra); ChatWriter.logModifier(player, event, this, elytra); } + + private final PlayerConfigurationOption PARTICLES = + new PlayerConfigurationOption(this,"particles", PlayerConfigurationOption.Type.BOOLEAN, + "particles", true); + + private final PlayerConfigurationOption SOUND = + new PlayerConfigurationOption(this,"sound", PlayerConfigurationOption.Type.BOOLEAN, + "sound", true); + + @Override + public List getPCIOptions() { + List playerConfigurationOptions = super.getPCIOptions(); + playerConfigurationOptions.add(PARTICLES); + playerConfigurationOptions.add(SOUND); + + playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName)); + return playerConfigurationOptions; + } } diff --git a/src/main/java/de/flo56958/minetinker/utils/playerconfig/PlayerConfigurationManager.java b/src/main/java/de/flo56958/minetinker/utils/playerconfig/PlayerConfigurationManager.java index 86f77c76..22f8d9ae 100644 --- a/src/main/java/de/flo56958/minetinker/utils/playerconfig/PlayerConfigurationManager.java +++ b/src/main/java/de/flo56958/minetinker/utils/playerconfig/PlayerConfigurationManager.java @@ -181,7 +181,7 @@ void nextIndex() { final GUI.Window.Button currentButton = indexHelper.currentPage.addButton(indexHelper.xIndex, indexHelper.yIndex, buttonStack); buttonStack = currentButton.getItemStack(); //needs to be updated as it gets changed when added to the inventory final ItemMeta buttonMeta = buttonStack.getItemMeta(); - buttonMeta.setDisplayName(pci.getPCIDisplayColor() + pci.getPCIDisplayName() + ": " + option.displayName()); + buttonMeta.setDisplayName(pci.getPCIDisplayColor() + pci.getPCIDisplayName() + ": " + ChatColor.WHITE + option.displayName()); ItemStack buttonStackForRunnable = buttonStack; switch (option.type()) {