setTypeId(0); and setType(Material.AIR); don't work!

Discussion in 'Plugin Development' started by Theodossis, Feb 28, 2013.

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

    Theodossis

    I got this code:
    Code:
        @EventHandler
        public void onQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            int ax = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.x");
            int ay = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.y");
            int az = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.z");
            int sx = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.x");
            int sy = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.y");
            int sz = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.z");
            Location ammodis = new Location(Bukkit.getWorld(p.getWorld().getName()), ax, ay, az);
            Location supplyt = new Location(Bukkit.getWorld(p.getWorld().getName()), sx, sy, sz);
            p.getWorld().getBlockAt(ammodis).setTypeId(AIR);
            p.getWorld().getBlockAt(supplyt).setTypeId(AIR);
            BaseWars.tempFile.set(p.getName() + ".AmmoDispenser.Ammount", 0);
            BaseWars.tempFile.set(p.getName() + ".SupplyTable.Ammount", 0);
            ConfigHandler.
    saveFile(BaseWars.tempFile, BaseWars.temp);
        }
    and when the player disconnects it does nothing. Please help! I get no errors too!
    Also I did it logs when the player disconnects and it does it.
    Thanks,
    Theodossis
     
  2. Offline

    Neodork

  3. Offline

    DomIsAmazing27

    Theodossis Try some other things with it like broadcasting a message to test if the event is being fired correctly.
     
  4. Offline

    juampi_92

    try to print those coordinates
     
  5. Offline

    Theodossis

    Tried it.

    Tried it.

    It shows the right coordinates ;)
    Any idea?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    Lolmewn

    Silly idea, but perhaps the event is not registered?
     
    MrBluebear3 likes this.
  7. Offline

    bleachisback

    You keep using the most redundant code with your locations. I doubt this will fix anything, but try using this instead:
    Code:java
    1. Location ammodis = new Location(p.getWorld(), ax, ay, az);
    2. Location supplyt = new Location(p.getWorld(), sx, sy, sz);
    3. ammodis.getBlock().setType(Material.AIR);
    4. supplyt.getBlock().setType(Material.AIR);
     
  8. Offline

    Theodossis

    ^^ It's registered :)
     
  9. Offline

    Tirelessly

    If nothing is happening when the event is fired then no it isnt. Make sure you put EventHandler and if possible show more code.
     
  10. Offline

    juampi_92

    Try also this... but i cant see anything wrong with that code...

    new Location(p.getWorld(), x , y , z).getBlock().setTypeId(0);
     
  11. Offline

    Theodossis

    Doesn't work!

    What code do you want?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  12. Offline

    Netizen

    Print out ax,ay, and az using System.out.println("ax:"+ax+" ay:"+ay+" az:"+az); and verify that the location is what you expect.
     
  13. Offline

    Theodossis

    Printed in console right :)
    It still doesn't work :(
     
  14. Offline

    f14_tomcat

    You should use double variables for the coordinates.
    PHP:
    Location ammodis = new Location(Bukkit.getWorld(p.getWorld().getName()), Double.valueOf(ax), Double.valueOf(ay), Double.valueOf(az));
    Location supplyt = new Location(Bukkit.getWorld(p.getWorld().getName()), Double.valueOf(sx), Double.valueOf(sy), Double.valueOf(sz));
    This should work.
     
  15. f14_tomcat
    No, he shouldn't.
    Location accepts integers just fine and blocks don't even use double, the double is for entities.

    He should instead remove that redundancy... Bukkit.getWorld(p.getWorld().getName())... that's a big waste of resources looping around to get an object you ALREADY have: p.getWorld().

    Theodossis
    You should post your newly tested code along with the messages you got and the config.
     
  16. sometimes its useful to spawn an item entity on the location you hoping to edit, maybe you are 1 block to high to edit or some other small error
     
  17. Offline

    Theodossis

    Whole class:
    Code:
    package me.Theodossis.BaseWars.Events;
     
    import me.Theodossis.BaseWars.BaseWars;
    import me.Theodossis.BaseWars.ConfigHandler;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerQuitEvent;
     
    public class QuitDestroyer implements Listener {
        public static int AIR = 0;
        public static Material MaterAIR = Material.AIR;
       
        @EventHandler
        public void onQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            int ax = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.x");
            int ay = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.y");
            int az = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.z");
            int sx = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.x");
            int sy = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.y");
            int sz = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.z");
            new Location(Bukkit.getWorld(p.getWorld().getName()), ax, ay, az).getBlock().setTypeId(AIR);
            new Location(Bukkit.getWorld(p.getWorld().getName()), sx, sy, sz).getBlock().setTypeId(AIR);
            BaseWars.tempFile.set(p.getName() + ".AmmoDispenser.Ammount", 0);
            BaseWars.tempFile.set(p.getName() + ".SupplyTable.Ammount", 0);
            ConfigHandler.saveFile(BaseWars.tempFile, BaseWars.temp);
            BaseWars.logger.info("COORDS: " + ax + ay + az);
            BaseWars.logger.info("ANOTHER COORDS: " + sx + sy + sz);
        }
    }
     
  18. And how can you tell they're correct ? :)

    The message prints, yes, but you must get a mashup of numbers like:
    COORDS: 5960-132
    ANOTHER COORDS: 5372-178
     
  19. Offline

    Tirelessly

    Try turning
    new Location(Bukkit.getWorld(p.getWorld().getName()), sx, sy, sz).getBlock().setTypeId(AIR);

    To
    p.getWorld().getBlockAt(sx,sy,sz).setTypeId(0);
     
  20. Offline

    the_merciless

    Code:
     @EventHandler
        public void onQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            int ax = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.x");
            int ay = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.y");
            int az = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.z");
            int sx = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.x");
            int sy = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.y");
            int sz = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.z");
            Block ammodis = Bukkit.getWorld(p.getWorld().getName()).getBlockAt(ax, ay, az);
            Block supplyt = Bukkit.getWorld(p.getWorld().getName()).getBlockAt(sx, sy, sz);
            ammodis.setTypeId(0);
            supplyt.setTypeId(0);
            BaseWars.tempFile.set(p.getName() + ".AmmoDispenser.Ammount", 0);
            BaseWars.tempFile.set(p.getName() + ".SupplyTable.Ammount", 0);
            ConfigHandler.
    saveFile(BaseWars.tempFile, BaseWars.temp);
        }
     
  21. Offline

    MinerPiggeh

    Maybe .setType(null);?
     
  22. Offline

    the_merciless

    null works for setting items in inventories and such, not sure about actual blocks in the world though!
     
  23. Offline

    MinerPiggeh

    Well try it then.
     
  24. Offline

    the_merciless

    Edited previous post, this will definately work ^^^
     
  25. Offline

    Theodossis

    Didn't work

    Didn't work

    Already tested

    The error with null:
    Code:
    2013-03-03 14:51:29 [SEVERE] Could not pass event PlayerQuitEvent to BaseWars v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.v1_4_R1.PlayerList.disconnect(PlayerList.java:209)
        at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:717)
        at net.minecraft.server.v1_4_R1.NetworkManager.b(NetworkManager.java:295)
        at net.minecraft.server.v1_4_R1.PlayerConnection.d(PlayerConnection.java:113)
        at net.minecraft.server.v1_4_R1.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_4_R1.block.CraftBlock.setType(CraftBlock.java:103)
        at me.Theodossis.BaseWars.Events.QuitDestroyer.onQuit(QuitDestroyer.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 14 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  26. Offline

    minoneer

    Setting a BlockType to null can't work.

    The only thing I noticed is, you never check if the players loggout location is in the same world as the blocks you are trying to edit. Did you make sure it actually is the same world?
     
  27. Offline

    Dragonphase

    Code:java
    1. @EventHandler
    2. public void onQuit(PlayerQuitEvent e) {
    3. Player p = e.getPlayer();
    4. int ax = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.x");
    5. int ay = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.y");
    6. int az = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.z");
    7. int sx = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.x");
    8. int sy = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.y");
    9. int sz = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.z");
    10. p.getWorld().getBlockAt(ax, ay, az).setTypeId(0);
    11. p.getWorld().getBlockAt(sx, sy, sz).setTypeId(0);
    12. BaseWars.tempFile.set(p.getName() + ".AmmoDispenser.Ammount", 0);
    13. BaseWars.tempFile.set(p.getName() + ".SupplyTable.Ammount", 0);
    14. ConfigHandler.saveFile(BaseWars.tempFile, BaseWars.temp);
    15. }


    If this does not work, try:

    Code:java
    1. @EventHandler
    2. public void onQuit(PlayerQuitEvent e) {
    3. Player p = e.getPlayer();
    4. int ax = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.x");
    5. int ay = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.y");
    6. int az = BaseWars.tempFile.getInt(p.getName() + ".AmmoDispenser.z");
    7. int sx = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.x");
    8. int sy = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.y");
    9. int sz = BaseWars.tempFile.getInt(p.getName() + ".SupplyTable.z");
    10. p.getWorld().getBlockAt(new Location(ax, ay, az)).setTypeId(0);
    11. p.getWorld().getBlockAt(new Location(sx, sy, sz)).setTypeId(0);
    12. BaseWars.tempFile.set(p.getName() + ".AmmoDispenser.Ammount", 0);
    13. BaseWars.tempFile.set(p.getName() + ".SupplyTable.Ammount", 0);
    14. ConfigHandler.saveFile(BaseWars.tempFile, BaseWars.temp);
    15. }


    These both work for me, however if neither of these work, it's safe to say you've exhausted all of the resources we've all provided you with. You should try updating the version of craftbukkit you are using and making sure the event is registered and is being called.

    If it still does not work, make sure that the block at the location you are editing is not air, so that you can check if it actually changes.
     
  28. Offline

    the_merciless

    Have you tried this......?
     
  29. Offline

    Theodossis

    They are in the same world ;)

    No they didn't work

    Yes and it didn't work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  30. Offline

    the_merciless

    Oh yeah, i can see why now. The 'getName()' was not neccessary.
     
Thread Status:
Not open for further replies.

Share This Page