Tank plugin

Discussion in 'Plugin Development' started by Hex_27, Oct 25, 2014.

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

    Hex_27

    I'm trying to make a plugin where when a player places a minecart named "Tank" with the lore "Right click to place", a minecart spawns at the player's click location and when the player rides the minecart, 4 stone blocks appear around the "tank" minecart, and the stone blocks and minecart move with the player. This is my code so far:
    Show Spoiler

    package me.leothepro555.tank;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Minecart;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{

    public void onEnable(){
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveConfig();
    }

    @SuppressWarnings("unchecked")
    @EventHandler
    public void onTankPlace(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    ItemStack item = p.getItemInHand();
    @SuppressWarnings("rawtypes")
    ArrayList loreData = new ArrayList();
    ItemStack tankk = new ItemStack(Material.MINECART);
    Location blockie = event.getClickedBlock().getLocation();
    loreData.add("Right click to place");
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
    (item == tankk)&&
    item.hasItemMeta()&&
    item.getItemMeta().getDisplayName().equals("Tank")&&
    (item.getItemMeta().hasLore()) &&
    (item.getItemMeta().getLore().equals(loreData))){
    Minecart tank = (Minecart)p.getWorld().spawnEntity(blockie, EntityType.MINECART);
    Entity passenger = (Entity) tank.getPassenger();
    if(passenger == p){
    Location loc = tank.getLocation();
    Location loc1 = loc.add(1, 0, 0);
    Location loc2 = loc.add(0, 0, 1);
    Location loc3 = loc.add(-1, 0, 0);
    Location loc4 = loc.add(0, 0, -1);
    Material stone = (Material.STONE);
    Block b1 = loc1.getBlock();
    Block b2 = loc2.getBlock();
    Block b3 = loc3.getBlock();
    Block b4 = loc4.getBlock();
    b1.setType(stone);
    b2.setType(stone);
    b3.setType(stone);
    b4.setType(stone);

    }else{
    event.setCancelled(true);
    }
    }
    }
    }


    As you can see, I have still yet to program the player moving with the blocks part... mostly because I don't know how. I need help on this too. There is also another problem: When I run the plugin, I get this error:
    Show Spoiler

    [21:27:03] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_11]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:48] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:992) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInArmAnimation.a(SourceFile:43) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInArmAnimation.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:48] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:50] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:50] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:50] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:51] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:28:52] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:992) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInArmAnimation.a(SourceFile:43) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInArmAnimation.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:29:11] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Tank v2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:216) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:186) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:605) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
    at me.leothepro555.tank.Main.onTankPlace(Main.java:36) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 15 more
    [21:29:18]


    Any help is appreciated. Thanks
     
  2. Offline

    teej107

    You're getting a NullPointer on line 36 in onTankPlace. Don't know what line number that is though and I'm not going to count.
     
  3. Offline

    drpk

    Hex_27 check if getClickedBlock is not null first.
     
  4. Offline

    acer5999

    Code:java
    1. Location blockie = event.getClickedBlock().getLocation();

    It's that line, he isn't checking if it's null as drpk said
     
  5. Offline

    Hex_27

    So how do I fix this?
     
  6. Offline

    mythbusterma

    Hex_27
    ಠ_ಠ
     
  7. Offline

    RingOfStorms

    I'm just going to start off my saying all of the bad things that you did. Not to be mean, but so you can learn and hopefully never produce code like this again.

    Red = get rid of it
    orange = change it to the correct thing
    blue = suggested replacement
    pink = wtf moment?

    @SuppressWarnings("unchecked")
    @EventHandler
    public void onTankPlace(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    ItemStack item = p.getItemInHand();
    @SuppressWarnings("rawtypes") You don't need this... (better reasoning below)
    ArrayList loreData = new ArrayList(); or this...
    ItemStack tankk = new ItemStack(Material.MINECART); or this...
    Location blockie = event.getClickedBlock().getLocation(); <- rename a logical name like spawnLocation
    Also, you need to increase the y value of this location, or the minecart will spawn inside the block you clicked, rather than ontop of it. Also, you need to move this inside your if statement as you haven't check if they clicked a block at all yet.

    blockie.add(0.5, 1.2. 0.5);


    loreData.add("Right click to place"); or this

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
    (item == tankk)&& <- This here will NEVER work. You can't just do an equal to check on two DIFFERENT objects, it will never be true
    Instead you should use (item.getType() == Material.MINECART) &&
    item.hasItemMeta()&&
    item.getItemMeta().getDisplayName().equals("Tank")&&
    (item.getItemMeta().hasLore()) &&
    (item.getItemMeta().getLore().equals(loreData))) { <- Again you can't just expect two completely different objects to ever be equal to each other. Instead you need to check the lore itself
    (item.getItemMeta().getLore().size() > 0) && (item.getItemMeta().getLore().get(0).equals("Right click to place"))
    Minecart tank = (Minecart)p.getWorld().spawnEntity(blockie, EntityType.MINECART);
    Entity passenger = (Entity) tank.getPassenger(); <- I'm not sure what you're trying to accomplish with this line because you've literally said the equivalent to passenger = null. You just spawned the minecart, there will be NO passenger yet because it just spawned.
    if(passenger == p){ <- Because of what I said above, this block of code will NEVER get executed
    Location loc = tank.getLocation();
    Location loc1 = loc.add(1, 0, 0); <- This code is going to result in all of these locations being exactly the same, and somewhere off where you don't want it. You will need to clone the location, otherwise you're passing the object by reference all over the place.
    Location loc2 = loc.add(0, 0, 1);
    Location loc3 = loc.add(-1, 0, 0);
    Location loc4 = loc.add(0, 0, -1);
    Material stone = (Material.STONE);
    Block b1 = loc1.getBlock();
    Block b2 = loc2.getBlock();
    Block b3 = loc3.getBlock();
    Block b4 = loc4.getBlock();
    b1.setType(stone);
    b2.setType(stone);
    b3.setType(stone);
    b4.setType(stone);
    }else{
    event.setCancelled(true); <- This code is not needed here, it will not change any outcome of the code and if you want to cancel the event (which you should), you should do it at the beginning of the event. Along with normal cancel, you need to cancel the interaction of the items in hand and the block. I'm assuming with this line you want the player to maintain the item in their hand, otherwise this entire event doesn't make sense.
    }
    }
    }

    Ok so now that is out of the way, this would be some better written code that at least gets you to the last part of your code:
    Code:
    @EventHandler
    public void onTankPlace(PlayerInteractEvent event) {
        Player p = event.getPlayer();
        ItemStack item = p.getItemInHand();
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK && (item.getType() == Material.MINECART)&&
                item.hasItemMeta()&& item.getItemMeta().getDisplayName() != null &&
                item.getItemMeta().getDisplayName().equals("Tank")&& (item.getItemMeta().hasLore()) &&
                item.getItemMeta().getLore().size() > 0 && item.getItemMeta().getLore().get(0).equals("Right click to place")) {
            Location spawnLoc = event.getClickedBlock().getLocation().add(0.5, 1.2, 0.5);
            Minecart tank = (Minecart)p.getWorld().spawnEntity(spawnLoc, EntityType.MINECART);
            tank.setPassenger(p);
     
            Block tankBlock = tank.getLocation().getBlock();
            BlockFace[] directions = new BlockFace[] {
                    BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH
            };
            for(BlockFace direction : directions)
                tankBlock.getRelative(direction).setType(Material.STONE);
     
            event.setCancelled(true);
            event.setUseInteractedBlock(Result.DENY);
            event.setUseItemInHand(Result.DENY);
        }
    }
    
    I think it is pretty obvious that you have a lot of room to learn before you attempt much more in the Bukkit API. I suggest you watch more java tutorials and get a stronger footing before continuing. Do some simple CLI programs and learn the ropes.
     
  8. Offline

    mythbusterma

    RingOfStorms

    "Watching more tutorials"....how about not. Hex_27 Go read a book on Java, or go read the tutorials published online by Oracle, the most authoritative source on the Java language.

    Also, as far as your code:
    1. Use a variable name that is meaningful, not "p"
    2. That if-statement makes me want to cry, it's extremely difficult to read or debug, split it into multiple blocks.
     
  9. Offline

    RingOfStorms

    Using 'p' for player is a fairly accepted practice and used by quite a lot of people.

    Multiple blocks of if statements would be horrible, if you need more organization simply make it multiple lines. If you were to do a separate if statement block for each logical operation in the current one, you would have seven completely useless indentations that mean nothing in the code and offset the code off the right of the screen for no reason.
     
    TheMintyMate likes this.
  10. Offline

    mythbusterma

    RingOfStorms

    The offset from the left of screen is for readability, an essential part of code.
     
  11. Offline

    RingOfStorms

    Yes it is, but 7 extra offsets for no reason along with 14 new brackets and 7 new wasted lines with 1 character is not the best way to go about it ;]
     
  12. Offline

    Hex_27

    Ok I have changed my code according to RingOfStorms , and tweaked a few things, so the error is settled for now. I also changed my Main and added TankPlace class for another class file. Now I would like to ask how to link my class TankPlace.class to my other class TankMove.class
    TankPlace code:
    Show Spoiler

    package me.leothepro555.tank;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Minecart;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Event.Result;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;

    public class TankBuild implements Listener{
    @SuppressWarnings("unused")
    private Main plugin;

    public TankBuild(Main tankMove) {
    this.plugin = tankMove;
    }

    @EventHandler(priority=EventPriority.HIGH)
    public void onTankPlace(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    ItemStack item = p.getItemInHand();
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK && (item.getType() == Material.MINECART)&&
    item.hasItemMeta()&& item.getItemMeta().getDisplayName() != null &&
    item.getItemMeta().getDisplayName().equals("Tank")&&
    item.getItemMeta().hasLore() &&
    item.getItemMeta().getLore().size() > 0 &&
    item.getItemMeta().getLore().get(0).equals("Right click to place")) {
    Location spawnLoc = event.getClickedBlock().getLocation().add(0.5, 1.5, 0.5);
    Minecart tank = (Minecart)p.getWorld().spawnEntity(spawnLoc, EntityType.MINECART);
    tank.setPassenger(p);
    Block tankBlock = tank.getLocation().getBlock();
    Block ctankBlock = tankBlock.getRelative(0, 1, 0);
    Block tankBase = ctankBlock.getRelative(0, -1, 0);
    BlockFace[] directions = new BlockFace[] {
    BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH
    };
    for(BlockFace direction : directions)
    tankBase.getRelative(direction).setType(Material.STONE);
    p.getInventory().removeItem(item);
    event.setCancelled(true);
    event.setUseInteractedBlock(Result.DENY);
    event.setUseItemInHand(Result.DENY);
    }
    }
    }


    TankMove current code, incomplete:
    Show Spoiler

    package me.leothepro555.tank;

    import org.bukkit.entity.Entity;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.leothepro555.tank.TankBuild;

    @SuppressWarnings("unused")
    public class TankMove implements Listener {
    private Main plugin;
    public TankMove(Main plugin) {
    this.plugin = plugin;
    }


    }


    Lets say I want to check if the Minecart in TankPlace, "tank" has a player passenger in the class TankMove, how do I do this?

    I still need help with this

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  13. Offline

    mythbusterma

    Hex_27

    Please, just learn Java first, it will save you a lot of trouble.
     
  14. Offline

    Hex_27

    I tried. It didn't work out.
     
  15. Offline

    CraftCreeper6

    Hex_27
    You tried for a day? Well done. That'll get you to learning about Integers on thenewboston; you're not even trying...
     
  16. Offline

    Hex_27

    CraftCreeper6
    I didn't just join the forum. I've been trying for the past 3 weeks. 3 weeks. It didn't work. Will you not criticize everyone without even knowing the details! I want help in which you tell me how to with codes. Not "learn java". That is how I'm learning it. It is things like this that make me upset. I feel as if you are mocking my 3 weeks of work.
     
  17. Offline

    CraftCreeper6

    Hex_27
    Either way, 3 weeks is still not enough.

    EDIT: Learning Bukkit before Java is a bad idea. Trust me.
     
  18. Offline

    Hex_27

    I've mentioned what I posted this thread for. As I said, it didn't work out. I would like a solution to my plugin instead of random comments of go learn java
     
  19. Offline

    CraftCreeper6

    Hex_27
    No one is going to spoonfeed you, all spoonfeeding will do is make you get bad habits of copying & pasting, what if you are taking programming as a A Level at school? You are not getting any help then...
     
  20. Offline

    Hex_27

    This is spoonfeeding that actually helps me in java. It is not blind copying. In this way, I am getting help, the way that is somehow more efficient for me
     
  21. Offline

    CraftCreeper6

    Hex_27
    No way can spoonfeeding possibly help you. Take some advice from me, I went strait into Bukkit, it was a really really bad idea. I also used to copy and paste util I got two really awesome tutors :) N3rdFall & Konkz
     
    Konkz likes this.
  22. Offline

    Hex_27

    Where do I get help for this. All the help I've found so far is by grabbing bits of code, understanding them, then weaving a new code myself
     
  23. Offline

    CraftCreeper6

  24. Offline

    Hex_27

    Okay, I've somewhat made some progress on my plugin, now TankMove.class has this code:
    Show Spoiler

    package me.leothepro555.tank;

    import java.util.Collection;

    import org.bukkit.Location;
    import org.bukkit.entity.Damageable;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Minecart;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import me.leothepro555.tank.TankBuild;

    @SuppressWarnings("unused")
    public class TankMove implements Listener {
    private Main plugin;
    public TankMove(Main plugin) {
    this.plugin = plugin;
    }
    public void onTankMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    Entity tank = p.getVehicle();
    Location d = event.getTo();
    Collection<PotionEffect> pot = p.getActivePotionEffects();
    PotionEffect resist = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, 0);
    int health = (int) ((Damageable) p).getMaxHealth();
    if(health == 40 &&
    pot.contains(resist)&&
    tank instanceof Minecart){

    }
    }

    }


    I haven't tested this yet, but how do I allow the player to move the minecart with the commands Q,W,E,R?
    Just for more info, here's the new TankBuild.class too:
    Show Spoiler

    package me.leothepro555.tank;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Minecart;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Event.Result;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class TankBuild implements Listener{
    @SuppressWarnings("unused")
    private Main plugin;

    public TankBuild(Main tankMove) {
    this.plugin = tankMove;
    }

    @EventHandler(priority=EventPriority.HIGH)
    public void onTankPlace(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    ItemStack item = p.getItemInHand();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK && (item.getType() == Material.MINECART)&&
    item.hasItemMeta()&& item.getItemMeta().getDisplayName() != null &&
    item.getItemMeta().getDisplayName().equals("Tank")&&
    item.getItemMeta().hasLore() &&
    item.getItemMeta().getLore().size() > 0 &&
    item.getItemMeta().getLore().get(0).equals("Right click to place")) {
    Location spawnLoc = event.getClickedBlock().getLocation().add(0.5, 1.5, 0.5);
    Minecart tank = (Minecart)p.getWorld().spawnEntity(spawnLoc, EntityType.MINECART);
    tank.setPassenger(p);
    Double health = (double) 40;
    p.setHealth(health);
    p.getInventory().removeItem(item);
    PotionEffect resist = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, 0);
    p.addPotionEffect(resist);
    p.setMaxHealth(health);
    p.setHealth(health);
    event.setCancelled(true);
    event.setUseInteractedBlock(Result.DENY);
    event.setUseItemInHand(Result.DENY);
    }
    }

    }
     

  25. Ah, you're here too, telling people what to do. And being inconsiderate. And being ignorant, so many ands. And...
     
  26. Offline

    CraftCreeper6

    TheGamesHawk2001
    I would rather you mind your own business rather than popping up and tahging me for no reason. And why you telling just me? Got some grudge? I have done nothing wrong my friend. If you are not here to help. Go away.
     
  27. Offline

    Hex_27

    That's solved already..... Now I have another problem... Can I have help on that first?
     
  28. Offline

    RingOfStorms

    It would be impossible for a player to control your tank with the Q,W,E,R keys. Maybe you should reconsider those keys and use W,A,S,D?
     
  29. Offline

    Hex_27

    Lol yes... thats what i meant... I';m playing too much LoL.
     
Thread Status:
Not open for further replies.

Share This Page