I need help with a PlayerLoginEvent, I have been trying to hide the player that joined from any players that are in my hashset I am unable to figure it out can someone please help me that would be great!
You could maybe just remove the Join Message and just send every player thats online in your hash map the join message ?? Maybe something like this ... Code: @EventHandler public void onJoin(PlayerJoinEvent e){ e.setJoinMessage(null); Player playerjoined = e.getPlayer(); for(Player p: Bukkit.getOnlinePlayers()){ if(<arry list name>.contains(p.getName())){ p.sendMessage(ChatColor.GOLD + playerjoined.getName() + ChatColor.GREEN + " Has Joined The Game!"); } } }
HashMap<Player> players = new HashMap<Player>(); @EventHandler public void onPlayerLogin(final PlayerLoginEvent event){ for(Player p : players){ p.hidePlayer(e.getPlayer); } }
The only thing wrong with that is I don't want the player that logged in to become invisible I only want the players in he Hashset to be invisible
I know how to hide players I don't know how to make it so if a player is invisible and a differnt player logs in how to make the player who is invisible invisible to the player that just logged in.
When a player performs the command that makes the player visible, you have to add the player in a hashmap with "invisiblePlayers.add(player); HashMap<Player> invisiblePlayers = new HashMap<Player>(); then make a loop that checks the hashmap for all the players for(Player p : invisiblePlayers){ p is then all the players in the hashmap that is invisible. e.getPlayer().hidePlayer(p); will make the players in the hashmap invisible for the player that log in to the server.
Doesn't seem to work public ArrayList<Player> hidingPlayers = new ArrayList<Player>(); used this as the player where I store the player then I @EventHandler public void onPlayerLogin(PlayerLoginEvent event){ Player player = event.getPlayer(); for(Player p : hidingPlayers){ player.hidePlayer(p); } } and it still didnt seem to work :/ Also seem to be getting alot of error on login at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462) at net.minecraft.server.v1_6_R3.PlayerList.c(PlayerList.java:207) at net.minecraft.server.v1_6_R3.PlayerList.a(PlayerList.java:103) at net.minecraft.server.v1_6_R3.PendingConnection.e(PendingConnection.java:132) at net.minecraft.server.v1_6_R3.PendingConnection.d(PendingConnection.java:43) at net.minecraft.server.v1_6_R3.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41) at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:29) at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592) at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227) at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488) at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421) at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583) Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at me.boysnnoco.CustomBan.Main.onPlayerLogin(Main.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ... 14 more
That is the whole error and the code is: package me.boysnnoco.CustomBan; import java.util.ArrayList; import java.util.logging.Logger; import me.boysnnoco.CustomBan.Commands.CommandAdmin; import me.boysnnoco.CustomBan.Commands.CommandGBan; import me.boysnnoco.CustomBan.Commands.CommandIBan; import me.boysnnoco.CustomBan.Commands.CommandInvs; import me.boysnnoco.CustomBan.Commands.CommandIp; import me.boysnnoco.CustomBan.Commands.CommandReport; import me.boysnnoco.CustomBan.Commands.CommandVis; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ Logger logger = Logger.getLogger("Minecraft"); public Main plugin; public Main(){ plugin = this; } public void registerCommands(){ getCommand("ip").setExecutor(new CommandIp(this)); getCommand("gban").setExecutor(new CommandGBan(this)); getCommand("iban").setExecutor(new CommandIBan(this)); getCommand("invs").setExecutor(new CommandInvs(this)); getCommand("vis").setExecutor(new CommandVis(this)); getCommand("admin").setExecutor(new CommandAdmin(this)); getCommand("report").setExecutor(new CommandReport(this)); } //Array Lists public ArrayList<Player> hidingPlayers = new ArrayList<Player>(); @Override public void onEnable(){ PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled"); getServer().getPluginManager().registerEvents(this, this); registerCommands(); } //On ShutDown @Override public void onDisable(){ PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Version" + pdfFile.getVersion() + " Has Been Disabled!"); } @EventHandler public void onPlayerLogin(PlayerJoinEvent event){ Player player = event.getPlayer(); for(Player p : hidingPlayers){ player.hidePlayer(p); } } } This is my Main class it does not include any of the commands hollar if you want me to show you the commands
Yes it is Fixed! I forgot to remove the player when he left but thanks Tss1410 for all the help! EDIT by Moderator: merged posts, please use the edit button instead of double posting.