diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock index c34f0c9..d20ec9f 100644 Binary files a/.gradle/7.3.3/checksums/checksums.lock and b/.gradle/7.3.3/checksums/checksums.lock differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index 1236caf..3e03862 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 9ccfd7a..8d6b8cb 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 021c243..bed1db5 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 0583cc9..9192703 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index 727b73d..a17e293 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 3b8bdd7..942ddbe 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 49f8cb1..8d31e07 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index ac28d78..bf9f547 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build.gradle b/build.gradle index 34c2519..f9f2c5a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'io.github.simplex' -version = '1.0-RC02' +version = 'Alpha-1.0-RC03' repositories { mavenCentral() diff --git a/build/resources/main/plugin.yml b/build/resources/main/plugin.yml index 748623a..b08b0d5 100644 --- a/build/resources/main/plugin.yml +++ b/build/resources/main/plugin.yml @@ -1,5 +1,5 @@ name: FeelingLucky -version: '1.0-RC02' +version: 'Alpha-1.0-RC03' author: SimplexDevelopment main: io.github.simplex.luck.FeelingLucky api-version: 1.18 diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 0e21c4a..1ab3c7d 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/io/github/simplex/luck/FeelingLucky.java b/src/main/java/io/github/simplex/luck/FeelingLucky.java index 7fa6f4a..16039e5 100644 --- a/src/main/java/io/github/simplex/luck/FeelingLucky.java +++ b/src/main/java/io/github/simplex/luck/FeelingLucky.java @@ -1,5 +1,6 @@ package io.github.simplex.luck; +import io.github.simplex.luck.listener.PlayerListener; import io.github.simplex.luck.player.PlayerConfig; import io.github.simplex.luck.player.PlayerHandler; import org.bukkit.Bukkit; @@ -15,6 +16,7 @@ public final class FeelingLucky extends JavaPlugin { private static final Map configMap = new HashMap<>(); public LuckCMD cmd; public PlayerHandler handler; + public PlayerListener playerListener; public static Map getConfigMap() { return configMap; @@ -24,8 +26,8 @@ public final class FeelingLucky extends JavaPlugin { public void onEnable() { Bukkit.getLogger().info("Initializing the PlayerHandler..."); handler = new PlayerHandler(this); - Bukkit.getLogger().info("Initialization complete! Attempting to register the handler..."); - this.getServer().getPluginManager().registerEvents(handler, this); + Bukkit.getLogger().info("Initialization complete! Attempting to register the Listeners..."); + playerListener = new PlayerListener(this); Bukkit.getLogger().info("Registration complete! Attempting to load all player configuration files..."); File[] files = getDataFolder().listFiles(); diff --git a/src/main/java/io/github/simplex/luck/listener/PlayerListener.java b/src/main/java/io/github/simplex/luck/listener/PlayerListener.java index ef71d0d..37434e9 100644 --- a/src/main/java/io/github/simplex/luck/listener/PlayerListener.java +++ b/src/main/java/io/github/simplex/luck/listener/PlayerListener.java @@ -7,6 +7,7 @@ import io.github.simplex.luck.SneakyWorker; import io.github.simplex.luck.player.Luck; import io.github.simplex.luck.player.PlayerHandler; import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -17,7 +18,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; @@ -31,9 +31,12 @@ import java.util.Map; import java.util.UUID; public record PlayerListener(FeelingLucky plugin) implements Listener { - private static final Map entityPlayerMap = new HashMap<>(); + public PlayerListener { + Bukkit.getServer().getPluginManager().registerEvents(this, plugin); + } + @EventHandler public void takeDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); @@ -187,7 +190,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener { public void witchesBrew(EntityDamageByEntityEvent event) { Entity eTEMP = event.getDamager(); Entity pTEMP = event.getEntity(); - DamageCause cause = event.getCause(); + EntityDamageEvent.DamageCause cause = event.getCause(); if (!(pTEMP instanceof Player player)) { return; @@ -198,7 +201,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener { } Luck luck = PlayerHandler.getLuckContainer(player); - if (cause.equals(DamageCause.MAGIC) || cause.equals(DamageCause.POISON)) { + if (cause.equals(EntityDamageEvent.DamageCause.MAGIC) || cause.equals(EntityDamageEvent.DamageCause.POISON)) { if (luck.quickRNG(33.0)) { luck.takeFrom(5.0); PlayerHandler.updatePlayer(player, luck); diff --git a/src/main/java/io/github/simplex/luck/player/Luck.java b/src/main/java/io/github/simplex/luck/player/Luck.java index d4598bb..466477e 100644 --- a/src/main/java/io/github/simplex/luck/player/Luck.java +++ b/src/main/java/io/github/simplex/luck/player/Luck.java @@ -1,6 +1,7 @@ package io.github.simplex.luck.player; import io.github.simplex.api.LuckContainer; +import io.github.simplex.luck.FeelingLucky; import org.bukkit.Bukkit; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; @@ -36,12 +37,14 @@ public class Luck implements LuckContainer { public static boolean quickRNG2(double percentage) { double rng; if (percentage >= 100.0) { - rng = 100.0; // 100% chance to trigger, obviously; + rng = 1024.0; // 100% chance to trigger, obviously; } else { - rng = RNG().nextDouble(0.0, 99.0); + rng = RNG().nextDouble(0.0, 1024.0); } - return (percentage >= rng); + double actual = (rng / 1024.0) * 100; + + return (percentage >= actual); } @Override @@ -77,16 +80,18 @@ public class Luck implements LuckContainer { public boolean quickRNG(double percentage) { double rng; if (percentage >= 100.0) { - rng = 100.0; // 100% chance to trigger, obviously; + rng = 1024.0; // 100% chance to trigger, obviously; } else { - rng = RNG().nextDouble(0.0, 99.0); + rng = RNG().nextDouble(0.0, 1024.0); } + double actual = (rng / 1024) * 100; + if (multiplier() > 1.0) { - return ((percentage * multiplier()) >= rng); + return ((percentage * multiplier()) >= actual); } - return (percentage >= rng); + return (percentage >= actual); } public void reset() { @@ -104,6 +109,7 @@ public class Luck implements LuckContainer { public void setValue(double value) { player.getAttribute(Attribute.GENERIC_LUCK).setBaseValue(value); + FeelingLucky.getConfigMap().get(associatedPlayer().getUniqueId()).setLuck(value); Bukkit.getPluginManager().callEvent(event); } diff --git a/src/main/java/io/github/simplex/luck/player/PlayerConfig.java b/src/main/java/io/github/simplex/luck/player/PlayerConfig.java index a3536f1..65ecf35 100644 --- a/src/main/java/io/github/simplex/luck/player/PlayerConfig.java +++ b/src/main/java/io/github/simplex/luck/player/PlayerConfig.java @@ -43,7 +43,7 @@ public class PlayerConfig { String tempUsername = config.getString("username"); - if (tempUsername != null && tempUsername.equalsIgnoreCase("replace")) { + if (tempUsername != null && !tempUsername.equalsIgnoreCase(player.getName())) { config.set("username", player.getName()); config.set("luck", PlayerHandler.getLuckContainer(player).defaultValue()); config.set("multiplier", "1.0"); diff --git a/src/main/java/io/github/simplex/luck/player/PlayerHandler.java b/src/main/java/io/github/simplex/luck/player/PlayerHandler.java index 92edb1c..4defb6e 100644 --- a/src/main/java/io/github/simplex/luck/player/PlayerHandler.java +++ b/src/main/java/io/github/simplex/luck/player/PlayerHandler.java @@ -1,6 +1,7 @@ package io.github.simplex.luck.player; import io.github.simplex.luck.FeelingLucky; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -12,6 +13,10 @@ import java.util.List; import java.util.Map; public record PlayerHandler(FeelingLucky plugin) implements Listener { + public PlayerHandler { + Bukkit.getServer().getPluginManager().registerEvents(this, plugin); + } + private static final Map playerLuckMap = new HashMap<>(); private static final List markedPlayers = new ArrayList<>(); diff --git a/src/main/java/io/github/simplex/luck/player/PlayerLuckChangeEvent.java b/src/main/java/io/github/simplex/luck/player/PlayerLuckChangeEvent.java index 77a4fee..2889962 100644 --- a/src/main/java/io/github/simplex/luck/player/PlayerLuckChangeEvent.java +++ b/src/main/java/io/github/simplex/luck/player/PlayerLuckChangeEvent.java @@ -1,5 +1,6 @@ package io.github.simplex.luck.player; +import io.github.simplex.luck.FeelingLucky; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent;