Code not setting blocks

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, May 21, 2016.

Thread Status:
Not open for further replies.
  1. So the code is not even broadcasting the message when i try to set the blocks at flag(). Anyone see why?

    Code (Text):

    package FlagPvP.Listeners;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.DyeColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBurnEvent;
    import org.bukkit.material.Wool;
    import org.bukkit.scheduler.BukkitRunnable;

    import FlagPvP.Main;
    import FlagPvP.dataManager;

    public class BlockBurn implements Listener{
        private Main pl;
        public BlockBurn(Main pl){
           this.pl = pl;
        }
        public HashMap<String, Long> cdTimeSW = new HashMap<String, Long>();
        public long ServerTime;
        public long ServerTimeMin;
        @EventHandler
        public void onBlockBurn(BlockBurnEvent event){
            dataManager dm = new dataManager(pl);
            FileConfiguration data = dm.getData();
            Block b = event.getBlock();
            if(event.getBlock().getType().equals(Material.valueOf(data.getString("Block").toUpperCase())) ||
                    event.getBlock().getWorld().equals(data.get("World"))){
                Location loc = b.getLocation();
              double X = loc.getX() + .5;
              double Y = loc.getY() + .5;
                double Z = loc.getZ() + .5;
                if(X == data.getDouble("BlockLocation.X") || Y == data.getDouble("BlockLocation.Y")
                          || Z == data.getDouble("BlockLocation.Z")){
                    dm.saveData();
                  for(Player player : Bukkit.getWorld(data.getString("World")).getPlayers()){
                      player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "FlagPvP" + ChatColor.DARK_RED + "] "
                              + ChatColor.RED + pl.getConfig().getString("RedWinMessage"));
                  }
                  HashMap<String, Integer> map = new HashMap<String, Integer>();
                  HashMap<String, BukkitRunnable> task = new HashMap<String, BukkitRunnable>();
                  String cd = "cooldown";
                  map.put(cd, 5);
                  task.put(cd, new BukkitRunnable() {
                      public void run(){
                          map.put(cd, map.get(cd) - 1);
                          if(map.get(cd) == 0){
                              double Xb = data.getDouble("BTP.X");
                                  double Yb = data.getDouble("BTP.Y");
                              double Zb = data.getDouble("BTP.Z");
                              Location loc_ = new Location(Bukkit.getWorld(data.getString("World")), Xb, Yb, Zb);
                                  for(Player players : Bukkit.getWorld(data.getString("World")).getPlayers()){
                                      players.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "FlagPvP" + ChatColor.DARK_RED + "] "
                                              + ChatColor.GOLD + "Teleporting...");
                                      players.teleport(loc_);
                                  }
                                  flag();
                                  cancel();
                          }
                      }
                  }); task.get(cd).runTaskTimer(pl, 20, 20);
                }
            }
        }
        public void flag(){
                   dataManager dm = new dataManager(pl);
                    FileConfiguration data = dm.getData();
                    Bukkit.broadcastMessage("done!");
                    Location loc_0 = new Location((World) data.get("World"), 0, 82, 14);
                    Location loc1 = new Location((World) data.get("World"), -1, 82, 14);
                    Location loc2 = new Location((World) data.get("World"), -2, 82, 14);
                    Location loc3 = new Location((World) data.get("World"), -3, 82, 14);
                    Location loc4 = new Location((World) data.get("World"), 0, 81, 14);
                    Location loc5 = new Location((World) data.get("World"), 0, 80, 14);
                    Location loc6 = new Location((World) data.get("World"), 0, 79, 14);
                    Location loc7 = new Location((World) data.get("World"), 0, 78, 14);
                    Location loc8 = new Location((World) data.get("World"), -1, 81, 14);
                    Location loc9 = new Location((World) data.get("World"), -2, 81, 14);
                    Location loc0 = new Location((World) data.get("World"), -3, 81, 14);
                    Block a = Bukkit.getWorld(data.getString("World")).getBlockAt(loc_0);
                        a.setType(Material.SPRUCE_FENCE);
                    Block b1 = Bukkit.getWorld(data.getString("World")).getBlockAt(loc1);
                        b1.setType(Material.WOOL);
                        Wool woolb = (Wool) b1;
                        woolb.setColor(DyeColor.BLUE);
                    Block c = Bukkit.getWorld(data.getString("World")).getBlockAt(loc2);
                        c.setType(Material.WOOL);
                        Wool woolc = (Wool) c;
                        woolc.setColor(DyeColor.BLUE);
                    Block d = Bukkit.getWorld(data.getString("World")).getBlockAt(loc3);
                        d.setType(Material.WOOL);
                        Wool woold = (Wool) d;
                        woold.setColor(DyeColor.BLUE);
                    Block e = Bukkit.getWorld(data.getString("World")).getBlockAt(loc4);
                        e.setType(Material.SPRUCE_FENCE);
                    Block f = Bukkit.getWorld(data.getString("World")).getBlockAt(loc5);
                        f.setType(Material.SPRUCE_FENCE);
                    Block g = Bukkit.getWorld(data.getString("World")).getBlockAt(loc6);
                        g.setType(Material.SPRUCE_FENCE);
                    Block h = Bukkit.getWorld(data.getString("World")).getBlockAt(loc7);
                        h.setType(Material.SPRUCE_FENCE);
                    Block i = Bukkit.getWorld(data.getString("World")).getBlockAt(loc8);
                        i.setType(Material.WOOL);
                        Wool wooli = (Wool) i;
                        wooli.setColor(DyeColor.BLUE);
                    Block j = Bukkit.getWorld(data.getString("World")).getBlockAt(loc9);
                        j.setType(Material.WOOL);
                        Wool woolj = (Wool) j;
                        woolj.setColor(DyeColor.BLUE);
                    Block k = Bukkit.getWorld(data.getString("World")).getBlockAt(loc0);
                        k.setType(Material.WOOL);
                        Wool woolk = (Wool) k;
                        woolk.setColor(DyeColor.BLUE);
        }
    }
     
     
  2. Register your events.
     
  3. It is activating the event, but it is not placing the blocks in flag()
     
  4. Those are absolute positions, not relative ones, you realize that? Are you checking the correct spot in the world and making sure those chunks are loaded first?
    Also, nowhere are you setting the blocks (at least from what i remember of bukkit API, i only use NMS for block stuff).. It looks like you are just getting a Block object, modifying it, and then doing nothing with it.
    I do not think that changes to a block will work if you typecast the block reference to another object first. Worth debugging, at least.

    Also, you should not get the world a dozen times.. get it once and use a reference (much faster in the code).
     
  5. Ok i get what you're saying, so how should i set the block? And even so its not getting to that part of the code anyways
     
    #5 TheGamerPlayz, May 21, 2016
    Last edited: May 21, 2016
Thread Status:
Not open for further replies.