Setting display name to team prefix

Discussion in 'Plugin Help/Development/Requests' started by JpPlugins, Apr 9, 2015.

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

    JpPlugins

    I am making a plugin that gets a players display name, creates a scoreboard team, and sets their display name as the team prefix. From what I believe, that would make their chat prefix and all that appear above them. The plugin loads fine, till I join I get an EventException error.

    Here is main class:
    Code:
    package com.gmail.ubtuub;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    
    public class Main extends JavaPlugin{
       
        public Scoreboard sb;
       
        @Override
        public void onEnable(){
            getLogger().info("Enabled!");
            getServer().getPluginManager().registerEvents(new Join(), this);
            sb = Bukkit.getScoreboardManager().getMainScoreboard();
        }
       
        @Override
        public void onDisable(){
            getLogger().info("Disabled!");
        }
       
    
    }

    Here is Event class:
    Code:
    package com.gmail.ubtuub;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scoreboard.Team;
    
    public class Join implements Listener{
       
        public Main plugin;
       
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onJoin(PlayerJoinEvent e){
            Team t = plugin.sb.registerNewTeam(e.getPlayer().getName());
            t.setPrefix(e.getPlayer().getDisplayName());
            t.addPlayer(e.getPlayer());
        }
       
    }
    Please help ASAP. Thank you!
     
  2. Offline

    mythbusterma

    @JpPlugins

    The only thing that will help is the error itself.
     
  3. Offline

    JpPlugins

    Right, here it is @mythbusterma
    Code:
    [23:22:36 ERROR]: Could not pass event PlayerJoinEvent to MineQuarters-NameTag v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[bukkit.jar:git-Spigot-c136710-350cb99]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[bukkit.jar:git-Spigot-c136710-350cb99]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [bukkit.jar:git-Spigot-c136710-350cb99]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.PlayerList.onPlayerJoin(PlayerList.java:296) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.PlayerList.a(PlayerList.java:156) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.LoginListener.b(LoginListener.java:144) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.LoginListener.c(LoginListener.java:54) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.NetworkManager.a(NetworkManager.java:231) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.ServerConnection.c(ServerConnection.java:148) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:809) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [bukkit.jar:git-Spigot-c136710-350cb99]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [bukkit.jar:git-Spigot-c136710-350cb99]
        at java.lang.Thread.run(Thread.java:695) [?:1.6.0_65]
    Caused by: java.lang.NullPointerException
        at com.gmail.ubtuub.Join.onJoin(Join.java:15) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0_65]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[?:1.6.0_65]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[bukkit.jar:git-Spigot-c136710-350cb99]
        ... 14 more
     
  4. Offline

    Msrules123

    This throws a null because you haven't set the MainScoreboard yet. Just make sure you initialize the MainScoreboard before you try to grab it ;)
     
  5. Offline

    pie_flavor

    @JpPlugins That's not how this works either. The prefix is shown before the name. Useful for colors or prefixes/suffixes. Not useful for custom chat name formatting because the original name is still shown. Look into TagAPI.
     
  6. Offline

    MexMaster

    @JpPlugins
    'plugin' is not initialized in your listener class. Therefore its null.
     
  7. Offline

    JpPlugins

    Thanks you guys @MexMaster @pie_flavor @Msrules123
    I have recoded the entire plugin so that you can add players to configured groups with prefixes and it seems to work perfect ;)
     
Thread Status:
Not open for further replies.

Share This Page