Solved Projectile not getting launched when right clicking "Gun"!

Discussion in 'Spigot Plugin Development' started by Orangemaster123, May 28, 2017.

  1. I am trying to make a gun where it fires a snowball but the snowball isn't getting fired. I can't find anything I done wrong in the code. But maybe someone can help?
    Heres my code.
    Code (Text):

    @EventHandler

    public void onPlayerInteract(PlayerInteractEvent e) {

    if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;

    if (!(e.getItem().getType() == Material.IRON_BARDING)) return;


    e.getPlayer().launchProjectile(Snowball.class);

    }


    @EventHandler

    public void onEntityDamage(EntityDamageByEntityEvent e) {


    if(e.getDamager() instanceof Snowball) {

    Snowball s = (Snowball) e.getDamager();

    if (s.getShooter() instanceof Player) {

    Player shooter = (Player) s.getShooter();

    if (shooter.getItemInHand().getType() == Material.IRON_BARDING) {

    e.setDamage(0.0);

    }

    }


    }


    }
     
     
    #1 Orangemaster123, May 28, 2017
    Last edited: May 28, 2017
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Is it getting past the first two ifs?
     
  3. Yes, well atlas I think so. When I am testing I right click the air with iron horse armour. So yes it is getting past the ifs.
     
  4. I just looked in console and i get this error.
    Code (Text):


    Error occurred while enabling EazyHub v1.0 (Is it up to date?)

    java.lang.IllegalArgumentException: Plugin already initialized!

    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at me.orangemaster123.eazyhub.HubSpecials.guns.<init>(guns.java:13) ~[?:?]

    at me.orangemaster123.eazyhub.EazyHub.registerEvents(EazyHub.java:44) ~[?:?]

    at me.orangemaster123.eazyhub.EazyHub.onEnable(EazyHub.java:19) ~[?:?]

    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_131]

    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]

    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]

    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]

    Caused by: java.lang.IllegalStateException: Initial initialization

    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at me.orangemaster123.eazyhub.EazyHub.<init>(EazyHub.java:15) ~[?:?]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_131]

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_131]

    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_131]

    at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_131]

    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:739) ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    ... 17 more
     
     
  5. Your guns class extends JavaPlugin, which it shouldn't.
     
  6. Thank you :)