i have a problem with my plugin

Discussion in 'Plugin Development' started by reboxer, Apr 7, 2016.

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

    reboxer

    hi, today after a long time, i decide to continue with my plugin, VipJoin, adding fireworks, but i have a problem when i run the plugin in my localhost server, this is the code and the error:

    Error:
    Code:
    [17:59:46] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [17:59:46] [Server thread/INFO]: Loading properties
    [17:59:46] [Server thread/INFO]: Default game type: SURVIVAL
    [17:59:46] [Server thread/INFO]: Generating keypair
    [17:59:47] [Server thread/INFO]: Starting Minecraft server on *:25565
    [17:59:47] [Server thread/INFO]: Using default channel type
    [17:59:47] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-07c3001 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [17:59:47] [Server thread/INFO]: [VipJoin] Loading VipJoin v3.0
    [17:59:47] [Server thread/INFO]: Preparing level "world"
    [17:59:47] [Server thread/INFO]: Preparing start region for level 0 (Seed: -6511906199006298714)
    [17:59:48] [Server thread/INFO]: Preparing spawn area: 66%
    [17:59:48] [Server thread/INFO]: Preparing start region for level 1 (Seed: -6511906199006298714)
    [17:59:49] [Server thread/INFO]: Preparing start region for level 2 (Seed: -6511906199006298714)
    [17:59:49] [Server thread/INFO]: [VipJoin] Enabling VipJoin v3.0
    [17:59:49] [Server thread/ERROR]: Error occurred while enabling VipJoin v3.0 (Is it up to date?)
    java.lang.NullPointerException
        at main.Main.onEnable(Main.java:30) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-07c3001]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [craftbukkit.jar:git-Bukkit-07c3001]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-07c3001]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:342) [craftbukkit.jar:git-Bukkit-07c3001]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:314) [craftbukkit.jar:git-Bukkit-07c3001]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:406) [craftbukkit.jar:git-Bukkit-07c3001]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:370) [craftbukkit.jar:git-Bukkit-07c3001]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:325) [craftbukkit.jar:git-Bukkit-07c3001]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:235) [craftbukkit.jar:git-Bukkit-07c3001]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:504) [craftbukkit.jar:git-Bukkit-07c3001]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    [17:59:49] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [17:59:49] [Server thread/INFO]: Done (2,493s)! For help, type "help" or "?"
    [18:02:24] [Server thread/INFO]: Stopping the server
    [18:02:24] [Server thread/INFO]: Stopping server
    [18:02:24] [Server thread/INFO]: [VipJoin] Disabling VipJoin v3.0
    [18:02:24] [Server thread/INFO]: Saving players
    [18:02:24] [Server thread/INFO]: Saving worlds
    [18:02:24] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [18:02:24] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [18:02:24] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    
    My code:
    Code:
    package main;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
        public class Main
         extends JavaPlugin
         implements Listener
    {
            String fire = "fireworks";
            Logger logger = getLogger();
            private String login = this.fire + ".login";
            public Logger log = Bukkit.getLogger();
            public JoinEvent eventos = new JoinEvent(this);
    
            public void onEnable()
    {
      loadConfiguration();
      Bukkit.getServer().getPluginManager().registerEvents(this, this);
      getCommand("firework").setExecutor(this);
      System.out.println("VipJoin Fireworks is now enabled!");
    }
    
            public void loadConfiguration()
    {
      getConfig().addDefault("Every Login", Boolean.valueOf(true));
      getConfig().options().copyDefaults(true);
      saveConfig();
    }
    
    @EventHandler
        public void onPlayerJoin(final PlayerJoinEvent pje)
    {
      Player player = pje.getPlayer();
      if ((getConfig().getBoolean("Every Login")) && (
        (player.hasPermission(this.login)) || (player.isOp()))) {
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
        {
          public void run()
          {
            Firework f = (Firework)pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
            FireworkMeta fm = f.getFireworkMeta();
            fm.addEffect(FireworkEffect.builder()
              .flicker(true).trail(true)
              .with(FireworkEffect.Type.STAR).with(FireworkEffect.Type.CREEPER)
              .with(FireworkEffect.Type.BURST).with(FireworkEffect.Type.BALL)
              .with(FireworkEffect.Type.BALL_LARGE)
              .withColor(Color.AQUA)
              .withColor(Color.YELLOW)
              .withColor(Color.LIME)
              .withColor(Color.TEAL)
              .withColor(Color.RED)
              .withColor(Color.WHITE).build());
            fm.setPower(0);
            f.setFireworkMeta(fm);
          }
        }, 20L);
      }
    }
    }
     
  2. Offline

    Gonmarte

    Try to troubleshot the problem by your own - https://bukkit.org/threads/how-to-r...ubleshoot-your-own-plugins-by-yourself.32457/
    Anyway i think the problem is in line 30 of onEnable method, you are setting the executer as your own class and your class does not implement the CommandExecuter, so you need to create a new instence of the class that implements CommandExecuter and add it to setExecuter();
    Also, you may wanna add a constructor with your main class as a param, in your command executer class.
     
    Last edited: Apr 7, 2016
  3. Offline

    reboxer

    Well, i remove this line from my code and this work fine, but now the most important (for me) part of the plugin dont work, i dong get any errors in console.

    i leave all my code:

    Code:
    package main;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
        public class Main
         extends JavaPlugin
         implements Listener
    {
            String fire = "fireworks";
            Logger logger = getLogger();
            private String login = this.fire + ".login";
            public Logger log = Bukkit.getLogger();
            public JoinEvent eventos = new JoinEvent(this);
    
            public void onEnable()
    {
      loadConfiguration();
      Bukkit.getServer().getPluginManager().registerEvents(this, this);
      System.out.println("VipJoin Fireworks is now enabled!");
    }
    
            public void loadConfiguration()
    {
      getConfig().addDefault("Every Login", Boolean.valueOf(true));
      getConfig().options().copyDefaults(true);
      saveConfig();
    }
    
    @EventHandler
        public void onPlayerJoin(final PlayerJoinEvent pje)
    {
      Player player = pje.getPlayer();
      if ((getConfig().getBoolean("Every Login")) && (
        (player.hasPermission(this.login)) || (player.isOp()))) {
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
        {
          public void run()
          {
            Firework f = (Firework)pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
            FireworkMeta fm = f.getFireworkMeta();
            fm.addEffect(FireworkEffect.builder()
              .flicker(true).trail(true)
              .with(FireworkEffect.Type.STAR).with(FireworkEffect.Type.CREEPER)
              .with(FireworkEffect.Type.BURST).with(FireworkEffect.Type.BALL)
              .with(FireworkEffect.Type.BALL_LARGE)
              .withColor(Color.AQUA)
              .withColor(Color.YELLOW)
              .withColor(Color.LIME)
              .withColor(Color.TEAL)
              .withColor(Color.RED)
              .withColor(Color.WHITE).build());
            fm.setPower(0);
            f.setFireworkMeta(fm);
          }
        }, 20L);
      }
    }
    }
    Code:
    package main;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class JoinEvent
      implements Listener
    {
      private Main plugin;
    
      public JoinEvent(Main plugin)
      {
        this.plugin = plugin;
      }
    
      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent ev)
      {
        Player player = ev.getPlayer();
        if (ev.getPlayer().hasPermission("vipjoin.join")) {
          Bukkit.broadcastMessage(this.plugin.getConfig().getString("joinmessage").replace("&", "§").replace("%player%", player.getDisplayName()));
        }
      }
    
      @EventHandler
      public void onPlayerLeave(PlayerQuitEvent ev)
      {
        Player player = ev.getPlayer();
        if (ev.getPlayer().hasPermission("vipjoin.quit")) {
          Bukkit.broadcastMessage(this.plugin.getConfig().getString("leavemessage").replace("&", "§").replace("%player%", player.getName()));
        }
      }
    }
    
    plugin.yml

    Code:
    name: VipJoin
    main: main.Main
    version: 3.0
    description: Warn you when a player with the permission join or leave the server and launch a firework if the player have the permission
    permissions:
      vipjoin.join:
        default: false
        description: Warn in join
      vipjoin.quit:
        default: false
        description: Warn in quit
      firework.login:
        default: false
        description: Spawn a firework when a player with the permission join to the server
    

    if you can help me with this, thanks :D
     
  4. Offline

    Zombie_Striker

    Stick to Java naming conventions : use the package name me.NAME.PROJECT

    Please do not use this format. Instead, use K&R as listed on the WikiPage.
    https://en.wikipedia.org/wiki/Indent_style

    Please, if you write in a new laungage, use it's formatting.

    1. "fire" should not have to be a field.
    2. Logger should not have to be a fueld
    3. login should not have to be a field
    4. You have two Loggers! They are exactly the same, any they are never even used!

    Use logger instead of Sys out. It's there for a reason.

    This should not be final.


    The error you got was because something was null. It's not that you have to remove lines, it's that you have to make sure nothing is null.
     
    D00py likes this.
  5. Offline

    RenditionsRule

    From what it looks like, you create a new instance of JoinEvent, but you never register that class in your onEnable.
     
  6. Offline

    mcdorli

    When you check for permissions, you use the suffix "firework", but your yml only has "vipjoin"
     
Thread Status:
Not open for further replies.

Share This Page