From f4eb32c35f08d2bbbc067c927e0ccd986ffee9c1 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Aug 2016 16:17:09 +0200 Subject: [PATCH] Fixes --- .../thebuttonmcchat/ChatPlayer.java | 18 +++-- .../thebuttonmcchat/PlayerListener.java | 66 ++++++------------- 2 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java index e7935ba..76814ba 100644 --- a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java +++ b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java @@ -39,9 +39,18 @@ public class ChatPlayer extends TBMCPlayer { @SuppressWarnings("deprecation") public static ChatPlayer GetFromName(String name) { OfflinePlayer p = Bukkit.getOfflinePlayer(name); - if (p != null) - return OnlinePlayers.get(p.getUniqueId()); - else + if (p != null) { + if (!ChatPlayer.OnlinePlayers.containsKey(p.getUniqueId())) { + TBMCPlayer player = TBMCPlayer.LoadPlayer(p); + if (player == null) { + Bukkit.getServer().getLogger() + .warning("Can't load player " + p.getUniqueId() + " - " + p.getName()); + return null; + } + ChatPlayer.OnlinePlayers.get(player.UUID); + } + return ChatPlayer.OnlinePlayers.get(p.getUniqueId()); + } else return null; } @@ -71,7 +80,8 @@ public class ChatPlayer extends TBMCPlayer { // Flairs from Command Block The Button - Teams // PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add() Player p = Bukkit.getPlayer(UUID); - p.setPlayerListName(String.format("%s%s", p.getName(), GetFormattedFlair())); + if (p != null) + p.setPlayerListName(String.format("%s%s", p.getName(), GetFormattedFlair())); } public short GetFlairColor() { diff --git a/src/buttondevteam/thebuttonmcchat/PlayerListener.java b/src/buttondevteam/thebuttonmcchat/PlayerListener.java index 90df075..eb789e0 100644 --- a/src/buttondevteam/thebuttonmcchat/PlayerListener.java +++ b/src/buttondevteam/thebuttonmcchat/PlayerListener.java @@ -41,6 +41,7 @@ import au.com.mineauz.minigames.MinigamePlayer; import au.com.mineauz.minigames.Minigames; import buttondevteam.core.TBMCPlayer; import buttondevteam.core.TBMCPlayerAddEvent; +import buttondevteam.core.TBMCPlayerJoinEvent; import buttondevteam.core.TBMCPlayerLoadEvent; import buttondevteam.core.TBMCPlayerSaveEvent; import buttondevteam.thebuttonmcchat.commands.ucmds.KittycannonCommand; @@ -63,12 +64,6 @@ public class PlayerListener implements Listener { public static int LoginWarningCountTotal = 5; - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - if (essentials == null) - essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")); - } - @EventHandler public void onPlayerLoad(TBMCPlayerLoadEvent e) { YamlConfiguration yc = e.GetPlayerConfig(); @@ -86,7 +81,13 @@ public class PlayerListener implements Listener { cp.FDeaths = yc.getInt("fdeaths"); cp.FlairCheater = yc.getBoolean("flaircheater"); ChatPlayer.OnlinePlayers.put(cp.UUID, cp); + } + @EventHandler + public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) { + if (essentials == null) + essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")); + ChatPlayer cp = ChatPlayer.OnlinePlayers.get(e.GetPlayer().UUID); Player p = Bukkit.getPlayer(cp.UUID); if (!cp.FlairState.equals(FlairStates.NoComment)) { @@ -283,50 +284,29 @@ public class PlayerListener implements Listener { } } /* - * boolean tping = false; boolean tphering = false; if - * (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") || - * cmd.equalsIgnoreCase("ecall") || cmd.equalsIgnoreCase("etpa") || - * cmd.equalsIgnoreCase("tpask") || cmd.equalsIgnoreCase("etpask")) - * tping = true; if (cmd.equalsIgnoreCase("tpahere") || - * cmd.equalsIgnoreCase("etpahere")) tphering = true; + * boolean tping = false; boolean tphering = false; if (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") || cmd.equalsIgnoreCase("ecall") || cmd.equalsIgnoreCase("etpa") || + * cmd.equalsIgnoreCase("tpask") || cmd.equalsIgnoreCase("etpask")) tping = true; if (cmd.equalsIgnoreCase("tpahere") || cmd.equalsIgnoreCase("etpahere")) tphering = true; */ /* - * for (HelpTopic ht : PluginMain.Instance.getServer() - * .getHelpMap().getHelpTopics()) { if - * (ht.getName().equalsIgnoreCase("/tpa")) { tping = true; break; } - * } + * for (HelpTopic ht : PluginMain.Instance.getServer() .getHelpMap().getHelpTopics()) { if (ht.getName().equalsIgnoreCase("/tpa")) { tping = true; break; } } */ /* - * for (HelpTopic ht : PluginMain.Instance.getServer() - * .getHelpMap().getHelpTopics()) { if - * (ht.getName().equalsIgnoreCase("/tpahere")) tphering = true; - * break; } + * for (HelpTopic ht : PluginMain.Instance.getServer() .getHelpMap().getHelpTopics()) { if (ht.getName().equalsIgnoreCase("/tpahere")) tphering = true; break; } */ /* - * if (tphering) { Player target = - * Bukkit.getPlayer(event.getMessage() .substring(index + - * 1).split(" ")[0]); if (target != null && BoardColl.get() - * .getFactionAt(PS.valueOf(target.getLocation())) - * .getId().equalsIgnoreCase("tower")) { event.getPlayer() - * .sendMessage( - * "§cYou are not allowed to teleport players out from the Tower"); + * if (tphering) { Player target = Bukkit.getPlayer(event.getMessage() .substring(index + 1).split(" ")[0]); if (target != null && BoardColl.get() + * .getFactionAt(PS.valueOf(target.getLocation())) .getId().equalsIgnoreCase("tower")) { event.getPlayer() .sendMessage( "§cYou are not allowed to teleport players out from the Tower"); * event.setCancelled(true); } } */ /* - * for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if - * (cmd.equalsIgnoreCase(s)) { tping = true; break; } } + * for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if (cmd.equalsIgnoreCase(s)) { tping = true; break; } } */ /* - * if (tping) { if ( // - * MPlayer.get(event.getPlayer()).getFaction().getId - * ().equalsIgnoreCase("nomansland")) // { BoardColl .get() - * .getFactionAt( PS.valueOf(event.getPlayer().getLocation())) - * .getId().equalsIgnoreCase("tower")) { - * event.getPlayer().sendMessage( - * "§cYou are not allowed to teleport to the Tower"); + * if (tping) { if ( // MPlayer.get(event.getPlayer()).getFaction().getId ().equalsIgnoreCase("nomansland")) // { BoardColl .get() .getFactionAt( + * PS.valueOf(event.getPlayer().getLocation())) .getId().equalsIgnoreCase("tower")) { event.getPlayer().sendMessage( "§cYou are not allowed to teleport to the Tower"); * event.setCancelled(true); } } */ } @@ -488,9 +468,7 @@ public class PlayerListener implements Listener { // System.out.println("B"); /* - * if (!e.getPlayer().isOp() && (!mp.isInMinigame() || - * mp.getMinigame().getName(false) - * .equalsIgnoreCase(Commands.KittyCannonMinigame))) return; + * if (!e.getPlayer().isOp() && (!mp.isInMinigame() || mp.getMinigame().getName(false) .equalsIgnoreCase(Commands.KittyCannonMinigame))) return; */ if (!(mp.isInMinigame() && mp.getMinigame().getName(false).equalsIgnoreCase(KittycannonCommand.KittyCannonMinigame))) @@ -558,20 +536,16 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerTeleport(PlayerTeleportEvent e) { /* - * if (BoardColl.get().getFactionAt(PS.valueOf(e.getFrom())).getId() - * .equalsIgnoreCase("nomansland") || - * BoardColl.get().getFactionAt(PS.valueOf(e.getTo())).getId() + * if (BoardColl.get().getFactionAt(PS.valueOf(e.getFrom())).getId() .equalsIgnoreCase("nomansland") || BoardColl.get().getFactionAt(PS.valueOf(e.getTo())).getId() * .equalsIgnoreCase("nomansland")) { */ // e.setTo(e.getFrom()); // e.setCancelled(true); // Relative coordinates mess it up /* - * System.out.println("From: " + e.getFrom()); System.out.println("To: " - * + e.getTo()); System.out.println("Cause: "+e.getCause()); + * System.out.println("From: " + e.getFrom()); System.out.println("To: " + e.getTo()); System.out.println("Cause: "+e.getCause()); */ /* - * e.getPlayer().sendMessage( - * "§cYou are not allowed to teleport to/from No Mans Land."); } + * e.getPlayer().sendMessage( "§cYou are not allowed to teleport to/from No Mans Land."); } */ if (ChatPlayer.GetFromPlayer(e.getPlayer()).ChatOnly) {