From ace1f7abb97b579e2ab190681f139e9540f23d63 Mon Sep 17 00:00:00 2001 From: DevDrizzy Date: Sun, 11 Aug 2024 11:38:15 +0500 Subject: [PATCH] Cleaned up code and fixed error handling on refresh method Signed-off-by: DevDrizzy --- .../refinedev/api/tablist/TablistHandler.java | 5 +- .../refinedev/api/tablist/TablistPlugin.java | 5 +- .../tablist/adapter/impl/ExampleAdapter.java | 3 - .../tablist/listener/SkinCacheListener.java | 1 - .../api/tablist/listener/TabListener.java | 14 ++- .../tablist/listener/TeamsPacketListener.java | 14 +-- .../refinedev/api/tablist/setup/TabEntry.java | 1 - .../api/tablist/setup/TabEntryInfo.java | 2 - .../api/tablist/setup/TabLayout.java | 77 ++++++------ .../api/tablist/skin/CachedSkin.java | 2 - .../refinedev/api/tablist/skin/SkinCache.java | 5 +- .../api/tablist/thread/TablistThread.java | 6 - .../refinedev/api/tablist/util/BaseEvent.java | 28 ----- .../api/tablist/util/EntityUtils.java | 113 ------------------ .../api/tablist/util/GlitchFixEvent.java | 25 +++- .../api/tablist/util/PacketUtils.java | 3 - .../xyz/refinedev/api/tablist/util/Skin.java | 3 - 17 files changed, 80 insertions(+), 227 deletions(-) delete mode 100644 src/main/java/xyz/refinedev/api/tablist/util/BaseEvent.java delete mode 100644 src/main/java/xyz/refinedev/api/tablist/util/EntityUtils.java diff --git a/src/main/java/xyz/refinedev/api/tablist/TablistHandler.java b/src/main/java/xyz/refinedev/api/tablist/TablistHandler.java index 2bde2a0..4f17e4c 100644 --- a/src/main/java/xyz/refinedev/api/tablist/TablistHandler.java +++ b/src/main/java/xyz/refinedev/api/tablist/TablistHandler.java @@ -1,17 +1,14 @@ package xyz.refinedev.api.tablist; import com.github.retrooper.packetevents.PacketEventsAPI; - import lombok.Getter; import lombok.Setter; import lombok.extern.log4j.Log4j2; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.Team; - import xyz.refinedev.api.tablist.adapter.TabAdapter; import xyz.refinedev.api.tablist.adapter.impl.ExampleAdapter; import xyz.refinedev.api.tablist.listener.SkinCacheListener; @@ -126,7 +123,7 @@ public void unload() { } // Destroy main tablist team - Team team = player.getScoreboard().getTeam("ztab"); + Team team = player.getScoreboard().getTeam("rtab"); if (team != null) { team.unregister(); } diff --git a/src/main/java/xyz/refinedev/api/tablist/TablistPlugin.java b/src/main/java/xyz/refinedev/api/tablist/TablistPlugin.java index 3d345d6..4011b5a 100644 --- a/src/main/java/xyz/refinedev/api/tablist/TablistPlugin.java +++ b/src/main/java/xyz/refinedev/api/tablist/TablistPlugin.java @@ -3,11 +3,8 @@ import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEventsAPI; import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; - import lombok.Getter; - import org.bukkit.plugin.java.JavaPlugin; - import xyz.refinedev.api.tablist.adapter.impl.ExampleAdapter; import xyz.refinedev.api.tablist.listener.TeamsPacketListener; @@ -22,7 +19,7 @@ @Getter public class TablistPlugin extends JavaPlugin { - private TablistHandler tablistHandler; + private xyz.refinedev.api.tablist.TablistHandler tablistHandler; private PacketEventsAPI packetEventsAPI; @Override diff --git a/src/main/java/xyz/refinedev/api/tablist/adapter/impl/ExampleAdapter.java b/src/main/java/xyz/refinedev/api/tablist/adapter/impl/ExampleAdapter.java index 8e20604..952fca6 100644 --- a/src/main/java/xyz/refinedev/api/tablist/adapter/impl/ExampleAdapter.java +++ b/src/main/java/xyz/refinedev/api/tablist/adapter/impl/ExampleAdapter.java @@ -1,10 +1,7 @@ package xyz.refinedev.api.tablist.adapter.impl; import it.unimi.dsi.fastutil.objects.ObjectArrayList; - -import org.bukkit.ChatColor; import org.bukkit.entity.Player; - import xyz.refinedev.api.tablist.adapter.TabAdapter; import xyz.refinedev.api.tablist.setup.TabEntry; import xyz.refinedev.api.tablist.util.Skin; diff --git a/src/main/java/xyz/refinedev/api/tablist/listener/SkinCacheListener.java b/src/main/java/xyz/refinedev/api/tablist/listener/SkinCacheListener.java index a2925ec..84ee911 100644 --- a/src/main/java/xyz/refinedev/api/tablist/listener/SkinCacheListener.java +++ b/src/main/java/xyz/refinedev/api/tablist/listener/SkinCacheListener.java @@ -7,7 +7,6 @@ import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import xyz.refinedev.api.tablist.TablistHandler; -import xyz.refinedev.api.tablist.setup.TabLayout; import xyz.refinedev.api.tablist.skin.SkinCache; /** diff --git a/src/main/java/xyz/refinedev/api/tablist/listener/TabListener.java b/src/main/java/xyz/refinedev/api/tablist/listener/TabListener.java index 5ed7da7..6b157ff 100644 --- a/src/main/java/xyz/refinedev/api/tablist/listener/TabListener.java +++ b/src/main/java/xyz/refinedev/api/tablist/listener/TabListener.java @@ -1,14 +1,14 @@ package xyz.refinedev.api.tablist.listener; import lombok.RequiredArgsConstructor; - +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Team; - import xyz.refinedev.api.tablist.TablistHandler; import xyz.refinedev.api.tablist.setup.TabLayout; import xyz.refinedev.api.tablist.util.PacketUtils; @@ -37,9 +37,11 @@ public void onJoin(PlayerJoinEvent event) { public void onQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - Team team = player.getScoreboard().getTeam("ztab"); - if (team != null) { - team.removeEntry(player.getName()); + Team team = player.getScoreboard().getTeam("rtab"); + if (team != null && player.getScoreboard() != Bukkit.getScoreboardManager().getMainScoreboard()) { + if (team.hasEntry(player.getName())) { + team.removeEntry(player.getName()); + } team.unregister(); } diff --git a/src/main/java/xyz/refinedev/api/tablist/listener/TeamsPacketListener.java b/src/main/java/xyz/refinedev/api/tablist/listener/TeamsPacketListener.java index ba0e401..b61af13 100644 --- a/src/main/java/xyz/refinedev/api/tablist/listener/TeamsPacketListener.java +++ b/src/main/java/xyz/refinedev/api/tablist/listener/TeamsPacketListener.java @@ -9,22 +9,16 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfo; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate; - -import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTeams; import lombok.RequiredArgsConstructor; - -import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; - import xyz.refinedev.api.tablist.TablistHandler; import xyz.refinedev.api.tablist.util.GlitchFixEvent; import xyz.refinedev.api.tablist.util.PacketUtils; import java.util.EnumSet; -import java.util.Optional; /** *

@@ -66,14 +60,14 @@ public void onPacketSend(PacketSendEvent event) { WrapperPlayServerTeams teams = new WrapperPlayServerTeams(event); if (teams.getTeamMode() != WrapperPlayServerTeams.TeamMode.REMOVE_ENTITIES) return; - if (!teams.getTeamName().equals("ztab")) { + if (!teams.getTeamName().equals("rtab")) { teams.setTeamMode(WrapperPlayServerTeams.TeamMode.ADD_ENTITIES); teams.setTeamName("tab"); Optional teamInfo = teams.getTeamInfo(); if (teamInfo.isPresent()) { WrapperPlayServerTeams.ScoreBoardTeamInfo info = teamInfo.get(); - info.setDisplayName(Component.text("ztab")); + info.setDisplayName(Component.text("rtab")); } } } else */if (isClientNew && event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_UPDATE) { @@ -118,10 +112,10 @@ private void preventGlitch(Player player, UserProfile userProfile) { } Scoreboard scoreboard = player.getScoreboard(); - Team team = scoreboard.getTeam("ztab"); + Team team = scoreboard.getTeam("rtab"); if (team == null) { - team = scoreboard.registerNewTeam("ztab"); + team = scoreboard.registerNewTeam("rtab"); } if (!team.hasEntry(online.getName())) { diff --git a/src/main/java/xyz/refinedev/api/tablist/setup/TabEntry.java b/src/main/java/xyz/refinedev/api/tablist/setup/TabEntry.java index 7bc5dd1..44c51e2 100644 --- a/src/main/java/xyz/refinedev/api/tablist/setup/TabEntry.java +++ b/src/main/java/xyz/refinedev/api/tablist/setup/TabEntry.java @@ -4,7 +4,6 @@ import lombok.Setter; import lombok.experimental.Accessors; import xyz.refinedev.api.tablist.util.Skin; -import xyz.refinedev.api.tablist.util.TabLatency; @Getter @Setter diff --git a/src/main/java/xyz/refinedev/api/tablist/setup/TabEntryInfo.java b/src/main/java/xyz/refinedev/api/tablist/setup/TabEntryInfo.java index 10bd243..a93d44c 100644 --- a/src/main/java/xyz/refinedev/api/tablist/setup/TabEntryInfo.java +++ b/src/main/java/xyz/refinedev/api/tablist/setup/TabEntryInfo.java @@ -2,11 +2,9 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTeams; - import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; - import xyz.refinedev.api.tablist.util.Skin; /** diff --git a/src/main/java/xyz/refinedev/api/tablist/setup/TabLayout.java b/src/main/java/xyz/refinedev/api/tablist/setup/TabLayout.java index f2e1dbf..bb70b2e 100644 --- a/src/main/java/xyz/refinedev/api/tablist/setup/TabLayout.java +++ b/src/main/java/xyz/refinedev/api/tablist/setup/TabLayout.java @@ -9,19 +9,18 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; import com.github.retrooper.packetevents.wrapper.PacketWrapper; -import com.github.retrooper.packetevents.wrapper.play.server.*; - +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfo; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerListHeaderAndFooter; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; - import lombok.Getter; import lombok.extern.log4j.Log4j2; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; - import xyz.refinedev.api.tablist.TablistHandler; import xyz.refinedev.api.tablist.adapter.TabAdapter; import xyz.refinedev.api.tablist.util.PacketUtils; @@ -39,7 +38,7 @@ public class TabLayout { /** * {@link Integer Mod} is the modification integer - * used to determine rows/columns from index of the {@link TabEntry}. + * used to determine rows/columns from index of the {@link xyz.refinedev.api.tablist.setup.TabEntry}. */ @Getter private final int mod; /** @@ -145,9 +144,9 @@ public void create() { // Add everyone to the "Tab" team // These aren't really used for 1.17+ except for hiding our own name - Team bukkitTeam = scoreboard.getTeam("ztab"); + Team bukkitTeam = scoreboard.getTeam("rtab"); if (bukkitTeam == null) { - bukkitTeam = scoreboard.registerNewTeam("ztab"); + bukkitTeam = scoreboard.registerNewTeam("rtab"); } for (Player target : Bukkit.getOnlinePlayers()) { @@ -177,7 +176,7 @@ public void create() { for ( Player target : Bukkit.getOnlinePlayers() ) { - Team team = target.getScoreboard().getTeam("ztab"); + Team team = target.getScoreboard().getTeam("rtab"); if (team == null) continue; if (team.hasEntry(player.getName())) continue; @@ -187,42 +186,46 @@ public void create() { public void refresh() { TablistHandler tablistHandler = TablistHandler.getInstance(); - List entries = tablistHandler.getAdapter().getLines(player); - if (entries.isEmpty()) { - for ( int i = 0; i < 80; i++ ) { - this.update(i, "", 0, Skin.DEFAULT_SKIN); - } - return; - } - - for ( int i = 0; i < 80; i++ ) { - TabEntry entry = i < entries.size() ? entries.get(i) : null; - if (entry == null) { - this.update(i, "", 0, Skin.DEFAULT_SKIN); - continue; + try { + List entries = tablistHandler.getAdapter().getLines(player); + if (entries.isEmpty()) { + for ( int i = 0; i < 80; i++ ) { + this.update(i, "", 0, Skin.DEFAULT_SKIN); + } + return; } - final int x = entry.getX(); - final int y = entry.getY(); + for ( int i = 0; i < 80; i++ ) { + xyz.refinedev.api.tablist.setup.TabEntry entry = i < entries.size() ? entries.get(i) : null; + if (entry == null) { + this.update(i, "", 0, Skin.DEFAULT_SKIN); + continue; + } - if (x >= 3 && PacketUtils.isLegacyClient(player)) continue; + final int x = entry.getX(); + final int y = entry.getY(); - final int index = y * mod + x; + if (x >= 3 && PacketUtils.isLegacyClient(player)) continue; - try { - this.update(index, entry.getText(), entry.getPing(), entry.getSkin()); - } catch (NullPointerException e) { - if (tablistHandler.getPlugin().getName().equals("Bolt") && !tablistHandler.isDebug()) { - continue; + final int index = y * mod + x; + try { + this.update(index, entry.getText(), entry.getPing(), entry.getSkin()); + } catch (Exception e) { + log.fatal("[{}] There was an error updating tablist for {}", tablistHandler.getPlugin().getName(), player.getName()); + log.error(e); + e.printStackTrace(); } - log.fatal("[{}] There was an error updating tablist for {}", tablistHandler.getPlugin().getName(), player.getName()); - log.error(e); - e.printStackTrace(); - } catch (Exception e) { + } + } catch (NullPointerException e) { + if (!tablistHandler.getPlugin().getName().equals("Bolt") || tablistHandler.isDebug()) { log.fatal("[{}] There was an error updating tablist for {}", tablistHandler.getPlugin().getName(), player.getName()); log.error(e); e.printStackTrace(); } + } catch (Exception e) { + log.fatal("[{}] There was an error updating tablist for {}", tablistHandler.getPlugin().getName(), player.getName()); + log.error(e); + e.printStackTrace(); } this.setHeaderAndFooter(); @@ -363,7 +366,7 @@ public void update(int index, String text, int ping, Skin skin) { } /** - * Update the {@link TabEntry}'s ping + * Update the {@link xyz.refinedev.api.tablist.setup.TabEntry}'s ping * * @param info {@link TabEntryInfo info} * @param ping {@link Integer ping} @@ -563,4 +566,4 @@ public String getTeamAt(int index) { } } -} +} \ No newline at end of file diff --git a/src/main/java/xyz/refinedev/api/tablist/skin/CachedSkin.java b/src/main/java/xyz/refinedev/api/tablist/skin/CachedSkin.java index 61f5761..8c7095b 100644 --- a/src/main/java/xyz/refinedev/api/tablist/skin/CachedSkin.java +++ b/src/main/java/xyz/refinedev/api/tablist/skin/CachedSkin.java @@ -4,8 +4,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; -import java.util.UUID; - /** * This Project is property of Refine Development © 2021 - 2023 * Redistribution of this Project is not allowed diff --git a/src/main/java/xyz/refinedev/api/tablist/skin/SkinCache.java b/src/main/java/xyz/refinedev/api/tablist/skin/SkinCache.java index da45f00..7e17ea0 100644 --- a/src/main/java/xyz/refinedev/api/tablist/skin/SkinCache.java +++ b/src/main/java/xyz/refinedev/api/tablist/skin/SkinCache.java @@ -6,9 +6,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import lombok.extern.log4j.Log4j2; - import org.bukkit.entity.Player; import xyz.refinedev.api.tablist.util.Skin; @@ -17,7 +15,8 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; -import java.util.*; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/xyz/refinedev/api/tablist/thread/TablistThread.java b/src/main/java/xyz/refinedev/api/tablist/thread/TablistThread.java index cf03254..74a93fd 100644 --- a/src/main/java/xyz/refinedev/api/tablist/thread/TablistThread.java +++ b/src/main/java/xyz/refinedev/api/tablist/thread/TablistThread.java @@ -2,13 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - import xyz.refinedev.api.tablist.TablistHandler; -import xyz.refinedev.api.tablist.setup.TabEntry; import xyz.refinedev.api.tablist.setup.TabLayout; /** diff --git a/src/main/java/xyz/refinedev/api/tablist/util/BaseEvent.java b/src/main/java/xyz/refinedev/api/tablist/util/BaseEvent.java deleted file mode 100644 index e7f1456..0000000 --- a/src/main/java/xyz/refinedev/api/tablist/util/BaseEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package xyz.refinedev.api.tablist.util; - -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class BaseEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - public HandlerList getHandlers() { - return handlers; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public void setCancelled(boolean b) { - - } -} diff --git a/src/main/java/xyz/refinedev/api/tablist/util/EntityUtils.java b/src/main/java/xyz/refinedev/api/tablist/util/EntityUtils.java deleted file mode 100644 index b1f4b1a..0000000 --- a/src/main/java/xyz/refinedev/api/tablist/util/EntityUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -package xyz.refinedev.api.tablist.util; - -import lombok.experimental.UtilityClass; -import org.bukkit.entity.EntityType; - -import java.util.EnumMap; -import java.util.Map; - -/** - * This Project is the property of Refine Development © 2021 - * Redistribution of this Project is not allowed - * - * @author Drizzy - * Created at 4/15/2021 - * @version Bolt - */ - -@UtilityClass -public class EntityUtils { - - private final Map displayNames = new EnumMap<>(EntityType.class); - private int currentFakeEntityId = -1; - - public int getFakeEntityId() { - return currentFakeEntityId--; - } - - static { - displayNames.put(EntityType.ARROW, "Arrow"); - displayNames.put(EntityType.BAT, "Bat"); - displayNames.put(EntityType.BLAZE, "Blaze"); - displayNames.put(EntityType.BOAT, "Boat"); - displayNames.put(EntityType.CAVE_SPIDER, "Cave Spider"); - displayNames.put(EntityType.CHICKEN, "Chicken"); - displayNames.put(EntityType.COW, "Cow"); - displayNames.put(EntityType.CREEPER, "Creeper"); - displayNames.put(EntityType.DROPPED_ITEM, "Item"); - displayNames.put(EntityType.EGG, "Egg"); - displayNames.put(EntityType.ENDER_CRYSTAL, "Ender Crystal"); - displayNames.put(EntityType.ENDER_DRAGON, "Ender Dragon"); - displayNames.put(EntityType.ENDER_PEARL, "Ender Pearl"); - displayNames.put(EntityType.ENDER_SIGNAL, "Ender Signal"); - displayNames.put(EntityType.ENDERMAN, "Enderman"); - displayNames.put(EntityType.EXPERIENCE_ORB, "Experience Orb"); - displayNames.put(EntityType.FALLING_BLOCK, "Falling Block"); - displayNames.put(EntityType.FIREBALL, "Fireball"); - displayNames.put(EntityType.FIREWORK, "Firework"); - displayNames.put(EntityType.FISHING_HOOK, "Fishing Rod Hook"); - displayNames.put(EntityType.GHAST, "Ghast"); - displayNames.put(EntityType.GIANT, "Giant"); - displayNames.put(EntityType.HORSE, "Horse"); - displayNames.put(EntityType.IRON_GOLEM, "Iron Golem"); - displayNames.put(EntityType.ITEM_FRAME, "Item Frame"); - displayNames.put(EntityType.LEASH_HITCH, "Lead Hitch"); - displayNames.put(EntityType.LIGHTNING, "Lightning"); - displayNames.put(EntityType.MAGMA_CUBE, "Magma Cube"); - displayNames.put(EntityType.MINECART, "Minecart"); - displayNames.put(EntityType.MINECART_CHEST, "Chest Minecart"); - displayNames.put(EntityType.MINECART_FURNACE, "Furnace Minecart"); - displayNames.put(EntityType.MINECART_HOPPER, "Hopper Minecart"); - displayNames.put(EntityType.MINECART_MOB_SPAWNER, "Spawner Minecart"); - displayNames.put(EntityType.MINECART_TNT, "TNT Minecart"); - displayNames.put(EntityType.OCELOT, "Ocelot"); - displayNames.put(EntityType.PAINTING, "Painting"); - displayNames.put(EntityType.PIG, "Pig"); - displayNames.put(EntityType.PLAYER, "Player"); - displayNames.put(EntityType.PRIMED_TNT, "TNT"); - displayNames.put(EntityType.SHEEP, "Sheep"); - displayNames.put(EntityType.SILVERFISH, "Silverfish"); - displayNames.put(EntityType.SKELETON, "Skeleton"); - displayNames.put(EntityType.SLIME, "Slime"); - displayNames.put(EntityType.SMALL_FIREBALL, "Fireball"); - displayNames.put(EntityType.SNOWBALL, "Snowball"); - displayNames.put(EntityType.SNOWMAN, "Snowman"); - displayNames.put(EntityType.SPIDER, "Spider"); - displayNames.put(EntityType.SPLASH_POTION, "Potion"); - displayNames.put(EntityType.SQUID, "Squid"); - displayNames.put(EntityType.THROWN_EXP_BOTTLE, "Experience Bottle"); - displayNames.put(EntityType.UNKNOWN, "Custom"); - displayNames.put(EntityType.VILLAGER, "Villager"); - displayNames.put(EntityType.WITCH, "Witch"); - displayNames.put(EntityType.WITHER, "Wither"); - displayNames.put(EntityType.WITHER_SKULL, "Wither Skull"); - displayNames.put(EntityType.WOLF, "Wolf"); - displayNames.put(EntityType.ZOMBIE, "Zombie"); - } - - /** - * Gets the display name of a given entity type. - * - * @param type The entity type to lookup. - * @return The display name of the provided entity type. - */ - public String getName(EntityType type) { - return (displayNames.get(type)); - } - - public EntityType parse(String input) { - for (Map.Entry entry : displayNames.entrySet()) { - if (entry.getValue().replace(" ", "").equalsIgnoreCase(input)) { - return entry.getKey(); - } - } - - for (EntityType type : EntityType.values()) { - if (input.equalsIgnoreCase(type.toString())) { - return type; - } - } - - return null; - } -} diff --git a/src/main/java/xyz/refinedev/api/tablist/util/GlitchFixEvent.java b/src/main/java/xyz/refinedev/api/tablist/util/GlitchFixEvent.java index bdc7890..a21e1ca 100644 --- a/src/main/java/xyz/refinedev/api/tablist/util/GlitchFixEvent.java +++ b/src/main/java/xyz/refinedev/api/tablist/util/GlitchFixEvent.java @@ -3,6 +3,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** *

@@ -18,8 +21,28 @@ @Getter @RequiredArgsConstructor -public class GlitchFixEvent extends BaseEvent { +public class GlitchFixEvent extends Event implements Cancellable { private final Player player; + private boolean cancelled; + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } } diff --git a/src/main/java/xyz/refinedev/api/tablist/util/PacketUtils.java b/src/main/java/xyz/refinedev/api/tablist/util/PacketUtils.java index a8fa1f8..5de809f 100644 --- a/src/main/java/xyz/refinedev/api/tablist/util/PacketUtils.java +++ b/src/main/java/xyz/refinedev/api/tablist/util/PacketUtils.java @@ -5,11 +5,8 @@ import com.github.retrooper.packetevents.manager.player.PlayerManager; import com.github.retrooper.packetevents.protocol.player.ClientVersion; import com.github.retrooper.packetevents.wrapper.PacketWrapper; - import lombok.experimental.UtilityClass; - import org.bukkit.entity.Player; - import xyz.refinedev.api.tablist.TablistHandler; /** diff --git a/src/main/java/xyz/refinedev/api/tablist/util/Skin.java b/src/main/java/xyz/refinedev/api/tablist/util/Skin.java index 1a61836..ce1bb13 100644 --- a/src/main/java/xyz/refinedev/api/tablist/util/Skin.java +++ b/src/main/java/xyz/refinedev/api/tablist/util/Skin.java @@ -2,9 +2,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Lists; - -import lombok.Data; - import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter;