[SOLVED]Someone please help me (vectors)

Discussion in 'Spigot Plugin Development' started by 1999kingbirdy, Jun 24, 2015.

  1. hello everybody,

    I'm working on quite a big project but now I'm stuck, getting all kind of weird errors.
    The main problem is when i click an item in my inventory it doesn't do what i want it to do.

    Code (Text):

    24.06 19:38:49 [Server] INFO ... 15 more
    24.06 19:38:49 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at me.kingbirdy.soulcity.EventHandling.onInventoryClick(EventHandling.java:260) ~[?:?]
    24.06 19:38:49 [Server] INFO Caused by: java.lang.NullPointerException
    24.06 19:38:49 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_72]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1603) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-6a6b839-b0e81a4]
    24.06 19:38:49 [Server] INFO org.bukkit.event.EventException
    24.06 19:38:49 [Server] ERROR Could not pass event InventoryClickEvent to MilkyNations v1.0
    Here are my codes:
    Code (Java):
    switch (event.getCurrentItem().getType())
            case WHEAT:
              player.sendMessage(MainNations.prefix + "You picked the wheat farm!");
    //untill here everything goes fine
              Vector WheatFarmLocWest1 = new Vector(PlayerLocation.getX(), PlayerLocation.getY() - 1.0, PlayerLocation.getZ() - 13.0);
              this.pasting.BuildingPaste(player, "WheatFarmLvl1.schematic", WheatFarmLocWest1, Side.LEFT, BuildingType.WHEAT_FARM);
    Code (Java):
     public void BuildingPaste(Player p, String schem, Vector loc, Side s, BuildingType t){
              if(hasEnoughItems(p, t)){
              System.out.println("works 2");
              case LEFT:
                  System.out.println("works 3");
                  BuildingPasteLeft(p, schem, loc);
              case RIGHT:
                  BuildingPasteRight(p, schem, loc);
              case SOUTH:
                  BuildingPasteSouth(p, schem, loc);
    The console doesn't say:"works"
    Hope you guys can help me!

    Thanks in advance
  2. One of your variables at line 260 is null.
    • Agree Agree x 1
    • Informative Informative x 1
  3. @CoderJohn
    this is it: Vector StorageRoomLocWest1 = new Vector(PlayerLocation.getX(), PlayerLocation.getY() - 1.0D, PlayerLocation.getZ() - 5.0D);
  4. Have you checked to see if your player location variables are null?
    • Useful Useful x 1
  5. I checked if (player != null) and then i sent a message with the location, that gives the right location
  6. PlayerLocation is most likely null. Also, a little tip, when using variables, make sure the first letter is lowercase. Example: PlayerLocation becomes playerLocation. It's not really necessary but it's good practice and it makes your code easier to navigate through and understand.
    • Agree Agree x 2
  7. @ReadySetPawn
    Not sure but I don't think it is null, I sent the player a message with the location and that gives the right location (where I'm standing)
    Is there another way to check? Or how could I solve this?
  8. Can you give a little bit more of the sourroundings of your code?
    Also: Try to implement some more Debug messages, at best one message for every variable or .get<Something> you are using, to see where exactly the null pointer exception occurs.
    • Informative Informative x 1
  9. @Noxyro
    When i click a block it opens an inventory, in that inventory you can select the building you want.
    But there are 3 sides i have to ckeck (West East and South).
    When you pick a building it takes money and items. Then it should paste a schematic relative to a player.
  10. Well turns out that this.pasting is null
    Code (Text):
    private SchematicPasting pasting;
        public EventHandling(SchematicPasting pasting){
            this.pasting = pasting;
  11. I don't like to bump but I really need an answer
  12. Is not the code you posted. I'm worried we are discussing different parts of your code.
  13. Well turns out there's a problem with the Event class linking to the Method class.
    I did this in the method class:
    Code (Text):
    public void test(Player p){
            p.sendMessage("This works");
    and this in the event class:

    Code (Text):
        public void test(PlayerBedEnterEvent event){
            Player p = event.getPlayer();
    it doesn't send a message.

    Here is the start of the method class:
    public class SchematicPasting{

    And this is the event class:
    public class EventHandling implements Listener{

    private SchematicPasting pasting;
    public EventHandling(SchematicPasting pasting){
    this.pasting = pasting;
  14. Well thanks everybody for your help but it turned out to be very simple ... :)
    I just had to make the methods static
  15. BLARGH

    Oh, sorry... what did you say? Static? Ew.
  16. I know they aren't good to use but it works