From e6fe9e904ec7e4d00d2cb3c3c4812d1a511a394c Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sun, 12 Jun 2022 00:10:56 -0500 Subject: [PATCH] FeelingLucky v1.0 RC01 Added some more features, this will be now the full official release; this commit is release candidate 1. Changelog: - Added HideCheck, which will break the tracking of any mobs targeting the player. - Added JumpBoost, which adds a little extra height to your jumps. - Modified OreVein as it previously scanned for all ore types rather than the relative mined ore type. --- .../simplex/luck/listener/HideCheck.java | 59 +++++++++++++++++++ .../simplex/luck/listener/JumpBoost.java | 26 ++++++++ .../github/simplex/luck/listener/OreVein.java | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/simplex/luck/listener/HideCheck.java create mode 100644 src/main/java/io/github/simplex/luck/listener/JumpBoost.java diff --git a/src/main/java/io/github/simplex/luck/listener/HideCheck.java b/src/main/java/io/github/simplex/luck/listener/HideCheck.java new file mode 100644 index 0000000..ec5de2c --- /dev/null +++ b/src/main/java/io/github/simplex/luck/listener/HideCheck.java @@ -0,0 +1,59 @@ +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.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; + +import java.util.*; + +public class HideCheck extends AbstractListener { + public Map> entityMapList = new HashMap<>(); + + public HideCheck(FeelingLucky plugin) { + super(plugin); + } + + @EventHandler + public void initPlayerMaps(PlayerJoinEvent event) { + entityMapList.put(event.getPlayer(), List.of()); + } + + @EventHandler + public void checkTargeting(EntityTargetLivingEntityEvent event) { + if (event.getTarget() instanceof Player player) { + if (event.getEntity() instanceof LivingEntity entity) { + List buffer = entityMapList.get(player).isEmpty() ? + new ArrayList<>() : entityMapList.get(player); + buffer.add(entity); + entityMapList.replace(player, buffer); + } + } + } + + @EventHandler + public void checkForSneak(PlayerToggleSneakEvent event) { + Player player = event.getPlayer(); + if (!player.isSneaking()) return; + + Luck luck = plugin.getHandler().getLuckContainer(player); + if (luck.quickRNG(luck.getValue()) && !luck.isMarked(player)) { + entityMapList.get(player).forEach(e -> { + e.getTrackedPlayers().remove(player); + }); + player.sendMessage(MiniComponent.info("Your luck has hidden you from sight.")); + } + } + + @EventHandler + public void removePlayerOnLeave(PlayerQuitEvent event) { + entityMapList.remove(event.getPlayer()); + } +} diff --git a/src/main/java/io/github/simplex/luck/listener/JumpBoost.java b/src/main/java/io/github/simplex/luck/listener/JumpBoost.java new file mode 100644 index 0000000..c9fdd79 --- /dev/null +++ b/src/main/java/io/github/simplex/luck/listener/JumpBoost.java @@ -0,0 +1,26 @@ +package io.github.simplex.luck.listener; + +import com.destroystokyo.paper.event.player.PlayerJumpEvent; +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.util.Vector; + +public class JumpBoost extends AbstractListener { + public JumpBoost(FeelingLucky plugin) { + super(plugin); + } + + @EventHandler + public void detectJumping(PlayerJumpEvent event) { + Player player = event.getPlayer(); // Player is never null; they're in game and jumping. + Luck luck = plugin.getHandler().getLuckContainer(player); + + if (luck.quickRNG(luck.getValue()) && !luck.isMarked(player)) { + player.setVelocity(new Vector(0, 2, 0)); + player.sendMessage(MiniComponent.info("Your luck has boosted your jump height!")); + } + } +} diff --git a/src/main/java/io/github/simplex/luck/listener/OreVein.java b/src/main/java/io/github/simplex/luck/listener/OreVein.java index d6f6fbd..e361c3d 100644 --- a/src/main/java/io/github/simplex/luck/listener/OreVein.java +++ b/src/main/java/io/github/simplex/luck/listener/OreVein.java @@ -46,6 +46,6 @@ public class OreVein extends AbstractListener { } } } - return streamBuilder.build(); + return streamBuilder.build().filter(b -> b.getType().equals(block.getType())); } }