Player Login Help

Discussion in 'Plugin Development' started by boysnnoco, Nov 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    boysnnoco

    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!
     
  2. Offline

    ChronicNinjaz

    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!");
            }
            }
        }
     
  3. Offline

    CraftBang

    you could create a for loop, go through all you hashsets players and than hide the player.
     
  4. Offline

    boysnnoco

  5. Offline

    Tss1410

    HashMap<Player> players = new HashMap<Player>();

    @EventHandler
    public void onPlayerLogin(final PlayerLoginEvent event){
    for(Player p : players){
    p.hidePlayer(e.getPlayer);
    }
    }
     
  6. Offline

    boysnnoco

    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 :(
     
  7. Offline

    Tss1410

    e.getPlayer().hidePlayer(p);
     
  8. Offline

    boysnnoco

    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.
     
  9. Offline

    Tss1410

    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.
     
  10. Offline

    SaintSypher

  11. Offline

    boysnnoco

    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
     
  12. Offline

    Tss1410

    can i see the whole code?
    and the error?
     
  13. Offline

    boysnnoco

    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 :)
     
  14. Offline

    Tss1410

    at me.boysnnoco.CustomBan.Main.onPlayerLogin(Main.java:73)
    line 73 in your main class?
     
  15. Offline

    boysnnoco

    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.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page