From 247a2fafc0cfd24a523d17e357db6aaf19baeb64 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sat, 2 Apr 2022 09:00:40 -0500 Subject: [PATCH] Bug Fix 0001 **Changelog**: - Fixed a bug where the PlayerListener was not being initialized - Included the registration for the listener inside the constructor - Dropped static import in favor of class parent access - Added to the Luck method "setValue(double)" to automatically update the configuration file when called. - Adjusted Luck to utilize all 1024 units when calculating the boolean for rng percentage. --- .gradle/7.3.3/checksums/checksums.lock | Bin 17 -> 17 bytes .../executionHistory/executionHistory.bin | Bin 65334 -> 78800 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/7.3.3/fileHashes/fileHashes.bin | Bin 20697 -> 22597 bytes .gradle/7.3.3/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../7.3.3/fileHashes/resourceHashesCache.bin | Bin 19109 -> 19313 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/outputFiles.bin | Bin 19055 -> 19433 bytes .gradle/file-system.probe | Bin 8 -> 8 bytes build.gradle | 2 +- build/resources/main/plugin.yml | 2 +- .../compileJava/previous-compilation-data.bin | Bin 31296 -> 31255 bytes .../io/github/simplex/luck/FeelingLucky.java | 6 ++++-- .../simplex/luck/listener/PlayerListener.java | 11 ++++++---- .../io/github/simplex/luck/player/Luck.java | 20 ++++++++++++------ .../simplex/luck/player/PlayerConfig.java | 2 +- .../simplex/luck/player/PlayerHandler.java | 5 +++++ .../luck/player/PlayerLuckChangeEvent.java | 1 + 18 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock index c34f0c9d74fb2acf80d5ae295fbfda4637cb7189..d20ec9f65f612933c8bcdaeea0a6fa93650dade0 100644 GIT binary patch literal 17 UcmZQJ47>Jfmhh~81_&qw05f?6k^lez literal 17 UcmZQJ47>Jfmhh~81_+1+05fF-egFUf diff --git a/.gradle/7.3.3/executionHistory/execut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MLEfd_p*&Y&as-bO7Ggj&~)Dh~}=oeA)hifhQnhl*k>ch2x@U1G3(9!DA_|Na``A z*s8itss_>s%t>^{-K%|x65KDPbJ7xY-}o>;&`svqJehRD$K3YHf%f_5*L82Ya{nx~ Liti1O@4e?gu-xU2 delta 679 zcmcccoMqcT<_RL2%nV>q_M3r$IS9h8@?~J)w1KdTq$IQCWV1Bm zGy{t?GgA|bw3MVoBTEa*RD?!dutvSC#3E*adnWH354QxjzP$fXyov4QR;CL~&Q>v@ zlb2$ Mv{*JTuj_9B0K10gX#fBK diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 9ccfd7a0df12a6e8b769ccf660ac91a973795eed..8d6b8cb8390618d8faf976a79809b540f5ded192 100644 GIT binary patch literal 17 UcmZRcB;nt8QAKht0|e*-04P`kV*mgE literal 17 UcmZRcB;nt8QAKht0|Y1o04PoaSpWb4 diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 021c243413e49200b04886a446780bd21ea5d517..bed1db525fa013d6d37ba07c8c6dd6d938fa2f2f 100644 GIT binary patch delta 1770 zcmZvcdr%Ws6vj705DWzah$I`3O$AJ3M2ewMYy^Q)f&l`O2UaT@A|Ou1M=1ytlyoSd zh~DxtA_SF(GbkXBV#PKsA|;|&tyIy9FC2M|5S#|BLwC8m{R2HSclXTie&;*)-hJHF z(ylbp8U-wVl$!RYUR2m_kIY5*vsp6KmKOh3dQMwI9;E@Fv9g)RCh5t1Znp-)=*^&$ z<>Oy6SdbmtaC#kt@=VI1lySqs*Q#@b6uVJeV|aRT`qm^0dE_lH&cc}5JxyZc^{8GF zS^!fv#;akeg}ZAu2}lPW<#4v8(R)IkTSjsNaAcQdT}lr)Y?%IB0impw692N1hl<{e z*+4FT^gmBnZY(U?(+;_GoZ`Q7g6*=(g>fX8Q@pDv@((t$QwjM7CB?fd&mGjh?c=V3 z6VXSgiJrZx+56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Uluf^w)Tjuoyl=iL7+MVqhHGgGnl4W^22w_PVS9HSQ$=9+xu2;M1om@3f>&j||8t!I47`>9LqT_PUD388zl#uYkH;|a=?Au1luS(C z4-xlTI@whsKw#aIy!TF9ytSZ$lPC8|G-&Kn`}!r&t852E(AyMd!d|JCw@)-Sn?M!c zp3Ew#AaEc`L(22_8zHFT&68y%0|YK}NQWDrEtZF>Y@D15RQcietfD7NyrB;B?w?#M zX`#XBGo_%pioF}ET@Yp$OSMK{sQk@Fs0k-0ua#7Aket(Zrs&(jdr-x-FvZf9hZcEG zkv{_!KME6<-O0JFPtEcfRNQ^?QJ^z49=QJSnaKzXhy2NRB?I|$CSDV|-gFXb+yBX` zQWhFcc3eg#`<=U>x);Js^;ofF(fQb??NIUT$)Qpi8i^@ePp{~9I|~)O4pW@*{mtcF zob%(LCU2j-RZ2l1M^w%7;8exgP{omx&q`VHH)%1}8n0l5DttTnuap)O%g2q1Kg2g0 hXb5k1^w49Pyx)U&@&^y0$q61FXtWBH51|FTtO1vI+PMG# delta 87 zcmaDko$>t?#tkMCjPjFxB_t--N_b4ZD^W4IRZ?Q|R!NV^qEZr*U8M{rF9p)9(h`$R rr9CH4lh&X7RXSmEs|-+$jN#;eGKx%0KQ}7=5Z`E^AiCMnLyrjnQr8}K diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index ac28d78c33f7d21e425da14accfd8f22e5ad666c..bf9f547312ddd0ac2b63576fc6cdfab1c5739705 100644 GIT binary patch literal 8 PcmZQzV61;tRy79z2_pjc literal 8 PcmZQzV61m{9#t8=nv||+|lZlDVexWYdq9^%F1Z2|UqUw&%6P@`K&+_wDyNi_D(P z&*HnXvdGqSMg8JSF0;P3=VZO-P% zFJR=Ee7i!6+0@T}GDoFiz0Y$#w>x|WhVvL17=Wg|;M04_7ygPb_zs`84p@vyQ|&dM z-Wxujw|x5V`1J4cDRC=96q~%~)BC{Z`jOB16Q9p#zJRxUQpzf-5ILDIe0pE`oWAk7 ze&-AL!KeR|PyZgD9k;!MBg9ZkuU~w6zxjNVfAIN2bol(?)BDTk^pDTy4j&IMSd5iX zSdgFLKc8L$zsF}jV~9GVMt;2}e&=R>pB8@oR(_zd9^A^F5IL7Ne!X^n=g)l35WW-0 GQw#w0KZ|Do delta 485 zcmbRKh4H`_#t8=nHuab#OazE6K7a@j;{SLA%NP zjGj)s``;fq5@}ofP4Kzd`lBAdj6CFx8QK%`QgTv@1U^kup5{^;Z@XjZw!ORlG>Vw` zC@2doxprDEZ-airWb3s*p597Oo;-`OLZE6w-&LREZ~w2?^)OF3adpLHC8qg|j*|~D zX-@vgl)=cbIhxs=nTbhn@>I5RCRV-80_@_9%*=X5leIZKfx?^1Ir0k_c_%-w&|>!U zH=Qg}saWs)oKOD+pZ-0*mwXIu$wj5PN!+ja7+OJ$d5jDU42-Y&oZs;2z2(zmeaQ!u zddH{tp3mn4pW7Wi14D=ky^nl)pZLN*^9A4G)7AltF{x>O;nVxd=ktwE|2v=lT|Oml zWr$*vAAEX0`J8_7x&G!0_`_GP{}*Jr9k;!MBSfdA*FQeJ|9q|u{LYR1K27`q-}t1I zRa7CmWt#c*TKIkc@cBacKCS$EZTwE{{62U1czD5LtPK2u!i*jKdY$|pP5j0Xbw*wM sdfoiaJ^Vhs{Q7 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;