Skip to content

Commit

Permalink
Add more Player Config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Dec 11, 2024
1 parent 274d681 commit ba96937
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand All @@ -121,7 +121,7 @@ private void planOffCooldownAlert(@NotNull final Player player, @NotNull final I

@Override
public List<PlayerConfigurationOption> getPCIOptions() {
final ArrayList<PlayerConfigurationOption> playerConfigurationOptions = new ArrayList<>(List.of(OFF_COOLDOWN_SOUND, OFF_COOLDOWN_NOTE, OFF_COOLDOWN_INSTRUMENT));
final ArrayList<PlayerConfigurationOption> playerConfigurationOptions = new ArrayList<>(List.of(OFF_COOLDOWN_ALERT, OFF_COOLDOWN_NOTE, OFF_COOLDOWN_INSTRUMENT));
playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName));
return playerConfigurationOptions;
}
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/de/flo56958/minetinker/modifiers/types/AutoSmelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Material, @NotNull Triplet> conversions = new EnumMap<>(Material.class);

private int percentagePerLevel;
private boolean hasSound;
private boolean hasParticles;
private boolean worksUnderWater;
private boolean toggleable;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<PlayerConfigurationOption> getPCIOptions() {
final ArrayList<PlayerConfigurationOption> playerConfigurationOptions = new ArrayList<>(List.of(PARTICLES, SOUND));
playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName));
return playerConfigurationOptions;
}
}
18 changes: 16 additions & 2 deletions src/main/java/de/flo56958/minetinker/modifiers/types/Homing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<PlayerConfigurationOption> getPCIOptions() {
return List.of(ENABLED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,15 +25,14 @@

import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

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());
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<PlayerConfigurationOption> getPCIOptions() {
List<PlayerConfigurationOption> playerConfigurationOptions = super.getPCIOptions();
playerConfigurationOptions.add(PARTICLES);
playerConfigurationOptions.add(SOUND);

playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName));
return playerConfigurationOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit ba96937

Please sign in to comment.