mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-09 20:26:07 +00:00
Beta 20220417-SNAPSHOT
Changelog: - Reorganized the listener registration method to register the listeners in alphabetical order - Added the IllOmen effect, which will apply a -25% debuff to a user's luck stat when they have the Bad Omen status effect. - Added the ability for Guardian lasers to inflict negative damage to a users luck stat. - Added a cache to the Luck class to store user values in the event that they have the Ill Omen debuff applied.
This commit is contained in:
parent
b424a83062
commit
5b1fb352bb
@ -58,15 +58,16 @@ public final class FeelingLucky extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
new PlayerListener(this);
|
|
||||||
new BlockDrops(this);
|
new BlockDrops(this);
|
||||||
new ItemDrops(this);
|
new BonemealFullCrop(this);
|
||||||
new TakeDamage(this);
|
new CheatDeath(this);
|
||||||
new RestoreHunger(this);
|
|
||||||
new EnchantmentBoost(this);
|
new EnchantmentBoost(this);
|
||||||
new ExpBoost(this);
|
new ExpBoost(this);
|
||||||
new CheatDeath(this);
|
new IllOmen(this);
|
||||||
new BonemealFullCrop(this);
|
new ItemDrops(this);
|
||||||
|
new PlayerListener(this);
|
||||||
|
new RestoreHunger(this);
|
||||||
|
new TakeDamage(this);
|
||||||
new UnbreakableTool(this);
|
new UnbreakableTool(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
82
src/main/java/io/github/simplex/luck/listener/IllOmen.java
Normal file
82
src/main/java/io/github/simplex/luck/listener/IllOmen.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package io.github.simplex.luck.listener;
|
||||||
|
|
||||||
|
import io.github.simplex.lib.MiniComponent;
|
||||||
|
import io.github.simplex.luck.FeelingLucky;
|
||||||
|
import io.github.simplex.luck.player.Luck;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
public record IllOmen(FeelingLucky plugin) implements Listener {
|
||||||
|
public IllOmen {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void reconnectCheck(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PotionEffectType type = PotionEffectType.BAD_OMEN;
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
|
|
||||||
|
if (player.hasPotionEffect(type)) {
|
||||||
|
luck.cache();
|
||||||
|
double maths = luck.getValue() - (luck.getValue() * 0.25);
|
||||||
|
luck.setValue(maths);
|
||||||
|
player.sendMessage(MiniComponent.info("A -25% debuff has been applied to your luck from the Bad Omen status effect."));
|
||||||
|
} else if (luck.cached(player) && !player.hasPotionEffect(type)) {
|
||||||
|
luck.restore();
|
||||||
|
player.sendMessage("The -25% debuff to your luck has been removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void effectApplyCheck(EntityPotionEffectEvent event) {
|
||||||
|
EntityPotionEffectEvent.Cause cause = EntityPotionEffectEvent.Cause.PATROL_CAPTAIN;
|
||||||
|
EntityPotionEffectEvent.Action added = EntityPotionEffectEvent.Action.ADDED;
|
||||||
|
EntityPotionEffectEvent.Action changed = EntityPotionEffectEvent.Action.CHANGED;
|
||||||
|
|
||||||
|
if (event.getCause().equals(cause) && (event.getAction().equals(added) || event.getAction().equals(changed))) {
|
||||||
|
if (event.getEntity() instanceof Player player) {
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
|
luck.cache();
|
||||||
|
double maths = luck.getValue() - (luck.getValue() * 0.25);
|
||||||
|
luck.setValue(maths);
|
||||||
|
player.sendMessage(MiniComponent.warn("A -25% debuff has been applied to your luck from the Bad Omen status effect."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void effectRemoveCheck(EntityPotionEffectEvent event) {
|
||||||
|
PotionEffect old = event.getOldEffect();
|
||||||
|
EntityPotionEffectEvent.Action cleared = EntityPotionEffectEvent.Action.CLEARED;
|
||||||
|
EntityPotionEffectEvent.Action removed = EntityPotionEffectEvent.Action.REMOVED;
|
||||||
|
|
||||||
|
if (old == null) return;
|
||||||
|
|
||||||
|
if (old.getType().equals(PotionEffectType.BAD_OMEN) && (event.getAction().equals(cleared) || event.getAction().equals(removed))) {
|
||||||
|
if ((event.getEntity() instanceof Player player)) {
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
|
if (luck.cached(player)) {
|
||||||
|
luck.restore();
|
||||||
|
player.sendMessage("The -25% debuff to your luck has been removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void disconnectCheck(PlayerQuitEvent event) {
|
||||||
|
if (event.getPlayer().hasPotionEffect(PotionEffectType.BAD_OMEN)) {
|
||||||
|
Luck luck = plugin.getHandler().getLuckContainer(event.getPlayer());
|
||||||
|
if (luck.cached(event.getPlayer())) {
|
||||||
|
luck.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.simplex.luck.listener;
|
package io.github.simplex.luck.listener;
|
||||||
|
|
||||||
|
import io.github.simplex.lib.MiniComponent;
|
||||||
import io.github.simplex.luck.FeelingLucky;
|
import io.github.simplex.luck.FeelingLucky;
|
||||||
import io.github.simplex.luck.player.Luck;
|
import io.github.simplex.luck.player.Luck;
|
||||||
import io.github.simplex.luck.util.SpecialFootItem;
|
import io.github.simplex.luck.util.SpecialFootItem;
|
||||||
@ -7,6 +8,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Guardian;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Witch;
|
import org.bukkit.entity.Witch;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -43,7 +45,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void witchesBrew(EntityDamageByEntityEvent event) {
|
public void luckDecrease(EntityDamageByEntityEvent event) {
|
||||||
Entity eTEMP = event.getDamager();
|
Entity eTEMP = event.getDamager();
|
||||||
Entity pTEMP = event.getEntity();
|
Entity pTEMP = event.getEntity();
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||||
@ -52,7 +54,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(eTEMP instanceof Witch)) {
|
if (!(eTEMP instanceof Witch) || !(eTEMP instanceof Guardian)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +63,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener {
|
|||||||
if (luck.quickRNG(33.0)) {
|
if (luck.quickRNG(33.0)) {
|
||||||
luck.takeFrom(5.0);
|
luck.takeFrom(5.0);
|
||||||
plugin.getHandler().updatePlayer(player, luck);
|
plugin.getHandler().updatePlayer(player, luck);
|
||||||
|
player.sendMessage(MiniComponent.warn("Your luck has been decreased by 5 points!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.SplittableRandom;
|
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public class Luck implements LuckContainer {
|
public class Luck implements LuckContainer {
|
||||||
@ -18,8 +16,10 @@ public class Luck implements LuckContainer {
|
|||||||
private final PlayerLuckChangeEvent event;
|
private final PlayerLuckChangeEvent event;
|
||||||
private final FeelingLucky plugin;
|
private final FeelingLucky plugin;
|
||||||
private final List<Player> markedPlayers = new ArrayList<>();
|
private final List<Player> markedPlayers = new ArrayList<>();
|
||||||
|
private final Map<Player, Double> cache = new HashMap<>();
|
||||||
private double BASE_VALUE;
|
private double BASE_VALUE;
|
||||||
private double multiplier;
|
private double multiplier;
|
||||||
|
private double tempSave;
|
||||||
|
|
||||||
public Luck(FeelingLucky plugin, Player player) {
|
public Luck(FeelingLucky plugin, Player player) {
|
||||||
this(plugin, player, 1.0);
|
this(plugin, player, 1.0);
|
||||||
@ -30,6 +30,7 @@ public class Luck implements LuckContainer {
|
|||||||
this.multiplier = multiplier;
|
this.multiplier = multiplier;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
BASE_VALUE = plugin.getConfigMap().get(player.getUniqueId()).getConfig().getDouble("luck");
|
BASE_VALUE = plugin.getConfigMap().get(player.getUniqueId()).getConfig().getDouble("luck");
|
||||||
|
tempSave = BASE_VALUE;
|
||||||
|
|
||||||
event = new PlayerLuckChangeEvent(this);
|
event = new PlayerLuckChangeEvent(this);
|
||||||
}
|
}
|
||||||
@ -137,6 +138,29 @@ public class Luck implements LuckContainer {
|
|||||||
plugin.getConfigMap().get(associatedPlayer().getUniqueId()).setMultiplier(multiplier);
|
plugin.getConfigMap().get(associatedPlayer().getUniqueId()).setMultiplier(multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cache() {
|
||||||
|
if (cache.containsKey(player)) {
|
||||||
|
cache.replace(player, getValue());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cache.put(player, getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean cached(Player player) {
|
||||||
|
return cache.containsKey(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restore() {
|
||||||
|
if (!cache.containsKey(player)) {
|
||||||
|
plugin.getLogger().info("Nothing to restore!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(cache.get(player));
|
||||||
|
cache.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
public double getDefaultValue() {
|
public double getDefaultValue() {
|
||||||
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
|
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user