mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-24 10:55:01 +00:00
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.
This commit is contained in:
parent
ffdafda69c
commit
247a2fafc0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'io.github.simplex'
|
||||
version = '1.0-RC02'
|
||||
version = 'Alpha-1.0-RC03'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -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<UUID, PlayerConfig> configMap = new HashMap<>();
|
||||
public LuckCMD cmd;
|
||||
public PlayerHandler handler;
|
||||
public PlayerListener playerListener;
|
||||
|
||||
public static Map<UUID, PlayerConfig> 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();
|
||||
|
@ -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<UUID, Player> 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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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<Player, Luck> playerLuckMap = new HashMap<>();
|
||||
private static final List<Player> markedPlayers = new ArrayList<>();
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user