From 637ec69a8fbf5a0eb2bed4c22186228e439696d6 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Tue, 25 Aug 2020 16:49:32 -0400 Subject: [PATCH] Moving MoveUtil to Facecore> --- pom.xml | 4 +- .../java/land/face/strife/StrifePlugin.java | 2 - .../data/conditions/GroundedCondition.java | 4 +- .../data/conditions/MovingCondition.java | 2 +- .../land/face/strife/events/LandEvent.java | 38 ---------- .../land/face/strife/events/LaunchEvent.java | 38 ---------- .../strife/listeners/DoubleJumpListener.java | 28 ++++--- .../face/strife/listeners/FallListener.java | 6 +- .../listeners/LaunchAndLandListener.java | 18 ++--- .../face/strife/listeners/MoveListener.java | 37 --------- .../face/strife/managers/StealthManager.java | 2 +- .../face/strife/tasks/EnergyRegenTask.java | 2 +- .../land/face/strife/tasks/EveryTickTask.java | 9 --- .../java/land/face/strife/util/JumpUtil.java | 41 ++++++++++ .../java/land/face/strife/util/MoveUtil.java | 76 ------------------- 15 files changed, 75 insertions(+), 232 deletions(-) delete mode 100644 src/main/java/land/face/strife/events/LandEvent.java delete mode 100644 src/main/java/land/face/strife/events/LaunchEvent.java delete mode 100644 src/main/java/land/face/strife/listeners/MoveListener.java create mode 100644 src/main/java/land/face/strife/util/JumpUtil.java delete mode 100644 src/main/java/land/face/strife/util/MoveUtil.java diff --git a/pom.xml b/pom.xml index c88c0a60..193161b1 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ strife - 3.2.2 + 3.2.3 jar strife @@ -81,7 +81,7 @@ io.pixeloutlaw facecore - 1.16.2.8 + 1.16.2.10 provided diff --git a/src/main/java/land/face/strife/StrifePlugin.java b/src/main/java/land/face/strife/StrifePlugin.java index 1a9599e3..0c19238e 100644 --- a/src/main/java/land/face/strife/StrifePlugin.java +++ b/src/main/java/land/face/strife/StrifePlugin.java @@ -79,7 +79,6 @@ The MIT License Copyright (c) 2015 Teal Cube Games import land.face.strife.listeners.LoreAbilityListener; import land.face.strife.listeners.MinionListener; import land.face.strife.listeners.MoneyDropListener; -import land.face.strife.listeners.MoveListener; import land.face.strife.listeners.ShootListener; import land.face.strife.listeners.SkillLevelUpListener; import land.face.strife.listeners.SpawnListener; @@ -502,7 +501,6 @@ public void enable() { Bukkit.getPluginManager().registerEvents(new SwingListener(this), this); Bukkit.getPluginManager().registerEvents(new ShootListener(this), this); Bukkit.getPluginManager().registerEvents(new ChatListener(), this); - Bukkit.getPluginManager().registerEvents(new MoveListener(), this); Bukkit.getPluginManager().registerEvents(new DataListener(this), this); Bukkit.getPluginManager().registerEvents(new DeathListener(this), this); Bukkit.getPluginManager().registerEvents(new SkillLevelUpListener(settings), this); diff --git a/src/main/java/land/face/strife/data/conditions/GroundedCondition.java b/src/main/java/land/face/strife/data/conditions/GroundedCondition.java index e987bdc1..f2f1385e 100644 --- a/src/main/java/land/face/strife/data/conditions/GroundedCondition.java +++ b/src/main/java/land/face/strife/data/conditions/GroundedCondition.java @@ -1,13 +1,13 @@ package land.face.strife.data.conditions; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import land.face.strife.data.StrifeMob; -import land.face.strife.util.MoveUtil; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class GroundedCondition extends Condition { - private boolean strict; + private final boolean strict; public GroundedCondition(boolean strict) { this.strict = strict; diff --git a/src/main/java/land/face/strife/data/conditions/MovingCondition.java b/src/main/java/land/face/strife/data/conditions/MovingCondition.java index e94b9363..d2713737 100644 --- a/src/main/java/land/face/strife/data/conditions/MovingCondition.java +++ b/src/main/java/land/face/strife/data/conditions/MovingCondition.java @@ -1,7 +1,7 @@ package land.face.strife.data.conditions; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import land.face.strife.data.StrifeMob; -import land.face.strife.util.MoveUtil; import org.bukkit.entity.Player; public class MovingCondition extends Condition { diff --git a/src/main/java/land/face/strife/events/LandEvent.java b/src/main/java/land/face/strife/events/LandEvent.java deleted file mode 100644 index 5182cb99..00000000 --- a/src/main/java/land/face/strife/events/LandEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package land.face.strife.events; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -public class LandEvent extends Event { - - private static final HandlerList HANDLER_LIST = new HandlerList(); - - public static HandlerList getHandlerList() { - return HANDLER_LIST; - } - - private final Player player; - private final Location location; - - public LandEvent(Player player, Location location) { - this.player = player; - this.location = location; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return HANDLER_LIST; - } - - public Player getPlayer() { - return player; - } - - public Location getLocation() { - return location; - } -} diff --git a/src/main/java/land/face/strife/events/LaunchEvent.java b/src/main/java/land/face/strife/events/LaunchEvent.java deleted file mode 100644 index 83dbae3a..00000000 --- a/src/main/java/land/face/strife/events/LaunchEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package land.face.strife.events; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; - -public class LaunchEvent extends Event { - - private static final HandlerList HANDLER_LIST = new HandlerList(); - - public static HandlerList getHandlerList() { - return HANDLER_LIST; - } - - private final Player player; - private final Location location; - - public LaunchEvent(Player player, Location location) { - this.player = player; - this.location = location; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return HANDLER_LIST; - } - - public Player getPlayer() { - return player; - } - - public Location getLocation() { - return location; - } -} diff --git a/src/main/java/land/face/strife/listeners/DoubleJumpListener.java b/src/main/java/land/face/strife/listeners/DoubleJumpListener.java index 297d3ddd..23a97045 100644 --- a/src/main/java/land/face/strife/listeners/DoubleJumpListener.java +++ b/src/main/java/land/face/strife/listeners/DoubleJumpListener.java @@ -2,8 +2,10 @@ import static land.face.strife.data.champion.LifeSkillType.AGILITY; -import com.tealcube.minecraft.bukkit.TextUtils; -import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; +import com.tealcube.minecraft.bukkit.facecore.event.LandEvent; +import com.tealcube.minecraft.bukkit.facecore.utilities.AdvancedActionBarUtil; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; +import io.pixeloutlaw.minecraft.spigot.garbage.StringExtensionsKt; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -11,8 +13,7 @@ import land.face.strife.StrifePlugin; import land.face.strife.data.StrifeMob; import land.face.strife.data.champion.LifeSkillType; -import land.face.strife.events.LandEvent; -import land.face.strife.util.MoveUtil; +import land.face.strife.util.JumpUtil; import land.face.strife.util.PlayerDataUtil; import org.bukkit.GameMode; import org.bukkit.Particle; @@ -29,6 +30,7 @@ public class DoubleJumpListener implements Listener { private final StrifePlugin plugin; private final Map cachedJumpAnimation = new HashMap<>(); + private final String JUMP_AB_KEY = "air-jump"; public DoubleJumpListener(StrifePlugin plugin) { this.plugin = plugin; @@ -55,12 +57,13 @@ private void resetJumps(Player player) { StrifeMob mob = plugin.getStrifeMobManager().getStatMob(player); int agilityLevel = mob.getChampion().getLifeSkillLevel(AGILITY); if (agilityLevel > 39) { - int jumps = MoveUtil.getJumps(player); - int maxJumps = MoveUtil.getMaxJumps(mob); + int jumps = JumpUtil.getJumps(player); + int maxJumps = JumpUtil.getMaxJumps(mob); if (jumps != maxJumps) { - MessageUtils.sendActionBar(player, TextUtils.color("&bJumps Recharged!")); + String message = StringExtensionsKt.chatColorize("&bJumps Recharged!"); + AdvancedActionBarUtil.addMessage(player, JUMP_AB_KEY, message, 10, 0); } - MoveUtil.setJumps(player, maxJumps); + JumpUtil.setJumps(player, maxJumps); } } @@ -74,7 +77,7 @@ public void airJump(PlayerToggleSneakEvent event) { return; } - int jumps = MoveUtil.getJumps(event.getPlayer()); + int jumps = JumpUtil.getJumps(event.getPlayer()); if (event.getPlayer().getFoodLevel() < 6 || jumps < 1) { return; } @@ -105,13 +108,14 @@ public void airJump(PlayerToggleSneakEvent event) { event.getPlayer().setVelocity(velocity.add(bonusVelocity)); jumps--; - MoveUtil.setJumps(event.getPlayer(), jumps); + JumpUtil.setJumps(event.getPlayer(), jumps); - int maxJumps = MoveUtil.getMaxJumps(mob); + int maxJumps = JumpUtil.getMaxJumps(mob); String bars = IntStream.range(0, maxJumps).mapToObj(i -> "▌").collect(Collectors.joining("")); bars = insert(bars, "&0", Math.min(jumps, maxJumps)); - MessageUtils.sendActionBar(event.getPlayer(), TextUtils.color("&3&lAir Jumps: &b" + bars)); + String message = StringExtensionsKt.chatColorize("&3&lAir Jumps: &b" + bars); + AdvancedActionBarUtil.addMessage(event.getPlayer(), JUMP_AB_KEY, message, 40, 0); plugin.getSkillExperienceManager().addExperience(mob, LifeSkillType.AGILITY, 3, false, false); flingParticle(event.getPlayer()); diff --git a/src/main/java/land/face/strife/listeners/FallListener.java b/src/main/java/land/face/strife/listeners/FallListener.java index 5c28ed36..ccb0aebe 100644 --- a/src/main/java/land/face/strife/listeners/FallListener.java +++ b/src/main/java/land/face/strife/listeners/FallListener.java @@ -6,11 +6,11 @@ import com.tealcube.minecraft.bukkit.TextUtils; import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import land.face.strife.StrifePlugin; import land.face.strife.data.champion.Champion; import land.face.strife.data.champion.LifeSkillType; import land.face.strife.util.DamageUtil; -import land.face.strife.util.MoveUtil; import land.face.strife.util.SpecialStatusUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -23,8 +23,8 @@ public class FallListener implements Listener { - private StrifePlugin plugin; - private int fallMs; + private final StrifePlugin plugin; + private final int fallMs; public FallListener(StrifePlugin plugin) { this.plugin = plugin; diff --git a/src/main/java/land/face/strife/listeners/LaunchAndLandListener.java b/src/main/java/land/face/strife/listeners/LaunchAndLandListener.java index 1910325b..bbf2e7b6 100644 --- a/src/main/java/land/face/strife/listeners/LaunchAndLandListener.java +++ b/src/main/java/land/face/strife/listeners/LaunchAndLandListener.java @@ -2,15 +2,15 @@ import static land.face.strife.data.champion.LifeSkillType.AGILITY; +import com.tealcube.minecraft.bukkit.facecore.event.LandEvent; +import com.tealcube.minecraft.bukkit.facecore.event.LaunchEvent; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import land.face.strife.StrifePlugin; import land.face.strife.data.AgilityLocationContainer; import land.face.strife.data.StrifeMob; import land.face.strife.data.champion.Champion; import land.face.strife.data.champion.LifeSkillType; -import land.face.strife.events.LandEvent; -import land.face.strife.events.LaunchEvent; import land.face.strife.stats.StrifeStat; -import land.face.strife.util.MoveUtil; import land.face.strife.util.PlayerDataUtil; import org.bukkit.GameMode; import org.bukkit.Particle; @@ -22,7 +22,7 @@ public class LaunchAndLandListener implements Listener { - private StrifePlugin plugin; + private final StrifePlugin plugin; public LaunchAndLandListener(StrifePlugin plugin) { this.plugin = plugin; @@ -74,17 +74,15 @@ public void onLaunch(LaunchEvent event) { @EventHandler public void onLand(LandEvent event) { - for (AgilityLocationContainer cont : plugin.getAgilityManager().getInWorld(event.getLocation() - .getWorld().getName())) { - boolean success = AgilityLocationContainer - .setProgress(cont, event.getPlayer(), event.getLocation()); + for (AgilityLocationContainer cont : plugin.getAgilityManager() + .getInWorld(event.getLocation().getWorld().getName())) { + boolean success = AgilityLocationContainer.setProgress(cont, event.getPlayer(), event.getLocation()); if (success) { Champion champion = plugin.getChampionManager().getChampion(event.getPlayer()); float xp = cont.getExp(); xp *= PlayerDataUtil.getLifeSkillLevel(champion, AGILITY) / cont.getDifficulty(); xp = Math.min(cont.getExp(), xp); - plugin.getSkillExperienceManager() - .addExperience(event.getPlayer(), AGILITY, xp, false, false); + plugin.getSkillExperienceManager().addExperience(event.getPlayer(), AGILITY, xp, false, false); } } } diff --git a/src/main/java/land/face/strife/listeners/MoveListener.java b/src/main/java/land/face/strife/listeners/MoveListener.java deleted file mode 100644 index 546f5e70..00000000 --- a/src/main/java/land/face/strife/listeners/MoveListener.java +++ /dev/null @@ -1,37 +0,0 @@ -package land.face.strife.listeners; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import land.face.strife.events.LandEvent; -import land.face.strife.events.LaunchEvent; -import land.face.strife.util.MoveUtil; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -public class MoveListener implements Listener { - - private Map groundedLastTick = new HashMap<>(); - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerMoveHorizontally(PlayerMoveEvent event) { - if (groundedLastTick.getOrDefault(event.getPlayer().getUniqueId(), true) != event.getPlayer() - .isOnGround()) { - if (event.getPlayer().isOnGround()) { - LandEvent ev = new LandEvent(event.getPlayer(), event.getPlayer().getLocation()); - Bukkit.getPluginManager().callEvent(ev); - } else { - LaunchEvent ev = new LaunchEvent(event.getPlayer(), event.getPlayer().getLocation()); - Bukkit.getPluginManager().callEvent(ev); - } - } - groundedLastTick.put(event.getPlayer().getUniqueId(), event.getPlayer().isOnGround()); - if (event.getFrom().getX() != event.getTo().getX() - || event.getFrom().getZ() != event.getTo().getZ()) { - MoveUtil.setLastMoved(event.getPlayer()); - } - } -} diff --git a/src/main/java/land/face/strife/managers/StealthManager.java b/src/main/java/land/face/strife/managers/StealthManager.java index 44c80476..82cf77f7 100644 --- a/src/main/java/land/face/strife/managers/StealthManager.java +++ b/src/main/java/land/face/strife/managers/StealthManager.java @@ -18,13 +18,13 @@ */ package land.face.strife.managers; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import java.util.HashSet; import java.util.Set; import java.util.UUID; import land.face.strife.StrifePlugin; import land.face.strife.data.champion.LifeSkillType; import land.face.strife.managers.IndicatorManager.IndicatorStyle; -import land.face.strife.util.MoveUtil; import land.face.strife.util.PlayerDataUtil; import land.face.strife.util.StatUtil; import org.bukkit.Bukkit; diff --git a/src/main/java/land/face/strife/tasks/EnergyRegenTask.java b/src/main/java/land/face/strife/tasks/EnergyRegenTask.java index 4c6f7321..7e9c051f 100644 --- a/src/main/java/land/face/strife/tasks/EnergyRegenTask.java +++ b/src/main/java/land/face/strife/tasks/EnergyRegenTask.java @@ -16,6 +16,7 @@ */ package land.face.strife.tasks; +import com.tealcube.minecraft.bukkit.facecore.utilities.MoveUtil; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,7 +28,6 @@ import land.face.strife.data.champion.LifeSkillType; import land.face.strife.stats.StrifeStat; import land.face.strife.stats.StrifeTrait; -import land.face.strife.util.MoveUtil; import land.face.strife.util.PlayerDataUtil; import org.bukkit.Bukkit; import org.bukkit.GameMode; diff --git a/src/main/java/land/face/strife/tasks/EveryTickTask.java b/src/main/java/land/face/strife/tasks/EveryTickTask.java index 0e367f6b..3062d542 100644 --- a/src/main/java/land/face/strife/tasks/EveryTickTask.java +++ b/src/main/java/land/face/strife/tasks/EveryTickTask.java @@ -19,21 +19,12 @@ package land.face.strife.tasks; import land.face.strife.StrifePlugin; -import land.face.strife.util.MoveUtil; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; public class EveryTickTask extends BukkitRunnable { @Override public void run() { - for (Player player : Bukkit.getOnlinePlayers()) { - MoveUtil.setSneak(player); - if (player.isOnGround()) { - MoveUtil.setLastGrounded(player); - } - } StrifePlugin.getInstance().getBlockManager().tickHolograms(); } } diff --git a/src/main/java/land/face/strife/util/JumpUtil.java b/src/main/java/land/face/strife/util/JumpUtil.java new file mode 100644 index 00000000..9825907e --- /dev/null +++ b/src/main/java/land/face/strife/util/JumpUtil.java @@ -0,0 +1,41 @@ +package land.face.strife.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import land.face.strife.data.StrifeMob; +import land.face.strife.data.champion.LifeSkillType; +import land.face.strife.stats.StrifeStat; +import org.bukkit.entity.Player; + +public class JumpUtil { + + private final static Map JUMP_MAP = new HashMap<>(); + + public static int getMaxJumps(StrifeMob mob) { + return getMaxJumps(mob.getChampion().getLifeSkillLevel(LifeSkillType.AGILITY)) + + (int) mob.getStat(StrifeStat.AIR_JUMPS); + } + + public static int getMaxJumps(int agilityLevel) { + if (agilityLevel > 59) { + return 2; + } + if (agilityLevel > 39) { + return 1; + } + return 0; + } + + public static void setJumps(Player player, int amount) { + if (amount == 0) { + JUMP_MAP.remove(player.getUniqueId()); + } + JUMP_MAP.put(player.getUniqueId(), amount); + } + + public static int getJumps(Player player) { + return JUMP_MAP.getOrDefault(player.getUniqueId(), 0); + } + +} diff --git a/src/main/java/land/face/strife/util/MoveUtil.java b/src/main/java/land/face/strife/util/MoveUtil.java deleted file mode 100644 index 86ed49f5..00000000 --- a/src/main/java/land/face/strife/util/MoveUtil.java +++ /dev/null @@ -1,76 +0,0 @@ -package land.face.strife.util; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import land.face.strife.data.StrifeMob; -import land.face.strife.data.champion.LifeSkillType; -import land.face.strife.stats.StrifeStat; -import org.bukkit.entity.Player; - -public class MoveUtil { - - private final static Map LAST_MOVED = new HashMap<>(); - private final static Map LAST_GROUNDED = new HashMap<>(); - private final static Map SNEAK_START = new HashMap<>(); - private final static Map JUMP_MAP = new HashMap<>(); - - public static int getMaxJumps(StrifeMob mob) { - return getMaxJumps(mob.getChampion().getLifeSkillLevel(LifeSkillType.AGILITY)) + - (int) mob.getStat(StrifeStat.AIR_JUMPS); - } - - public static int getMaxJumps(int agilityLevel) { - if (agilityLevel > 59) { - return 2; - } - if (agilityLevel > 39) { - return 1; - } - return 0; - } - - public static void setJumps(Player player, int amount) { - if (amount == 0) { - JUMP_MAP.remove(player.getUniqueId()); - } - JUMP_MAP.put(player.getUniqueId(), amount); - } - - public static int getJumps(Player player) { - return JUMP_MAP.getOrDefault(player.getUniqueId(), 0); - } - - public static void setLastMoved(Player player) { - LAST_MOVED.put(player.getUniqueId(), System.currentTimeMillis()); - } - - public static void setLastGrounded(Player player) { - LAST_GROUNDED.put(player.getUniqueId(), System.currentTimeMillis()); - } - - public static boolean hasMoved(Player player) { - return System.currentTimeMillis() - LAST_MOVED.getOrDefault(player.getUniqueId(), 0L) < 100; - } - - public static long timeOffGround(Player player) { - return System.currentTimeMillis() - LAST_GROUNDED.getOrDefault(player.getUniqueId(), 1L); - } - - public static void setSneak(Player player) { - if (player.isSneaking()) { - if (!SNEAK_START.containsKey(player.getUniqueId())) { - SNEAK_START.put(player.getUniqueId(), System.currentTimeMillis()); - } - } else { - SNEAK_START.remove(player.getUniqueId()); - } - } - - public static int getLastSneak(UUID uuid) { - if (!SNEAK_START.containsKey(uuid)) { - return -1; - } - return Math.toIntExact(System.currentTimeMillis() - SNEAK_START.get(uuid)); - } -}