Solved Bridge Egg error

Discussion in 'Spigot Plugin Development' started by Francy1978, Jun 29, 2018.

  1. I tried to do the bridge egg but when I use it and then change the world, I get this error in the console:

    https://pastebin.com/raw/VWWQDQiX

    Can you help me please ??
    Here is my code:

    Code (Java):
    package other;

    import com.fabietto03.luckywarsaddon.Main;
    import java.util.HashMap;
    import java.util.List;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Egg;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.scheduler.BukkitRunnable;

    public class Pathway
    {
      public static HashMap<Projectile, Material> pathways = new HashMap();
     
      public Pathway()
      {
        new BukkitRunnable()
        {
          public void run()
          {
            if (!Pathway.pathways.isEmpty()) {
              for (Projectile proj : Pathway.pathways.keySet())
              {
                byte data;
                byte data;
                if ((proj instanceof Egg)) {
                  data = 14;
                } else {
                  data = 5;
                }
                Player pl = (Player)proj.getShooter();
                Location loc = proj.getLocation().clone();
                if ((pl.getLocation().distance(loc) > 4.0D) && (!Main.worlds.contains(pl.getWorld().getName())))
                {
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).getBlock().setType((Material)Pathway.pathways.get(proj));
                 
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).getBlock().setData(data);
                 
                  pl.playEffect(loc.clone().add(0.0D, 2.0D, 0.0D), Effect.MOBSPAWNER_FLAMES, 5);
                 
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).subtract(0.0D, 0.0D, 1.0D).getBlock().setType((Material)Pathway.pathways.get(proj));
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).subtract(1.0D, 0.0D, 0.0D).getBlock().setType((Material)Pathway.pathways.get(proj));
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).add(0.0D, 0.0D, 1.0D).getBlock().setType((Material)Pathway.pathways.get(proj));
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).add(1.0D, 0.0D, 0.0D).getBlock().setType((Material)Pathway.pathways.get(proj));
                 
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).subtract(0.0D, 0.0D, 1.0D).getBlock().setData(data);
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).subtract(1.0D, 0.0D, 0.0D).getBlock().setData(data);
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).add(0.0D, 0.0D, 1.0D).getBlock().setData(data);
                  loc.clone().subtract(0.0D, 2.0D, 0.0D).add(1.0D, 0.0D, 0.0D).getBlock().setData(data);
                }
              }
            }
          }
        }.runTaskTimer(Main.getInstance(), 0L, 1L);
      }
    }
     

    Code (Java):
    package listeners;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.UUID;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Egg;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.entity.ProjectileLaunchEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import other.Pathway;

    public class Projectile
      implements Listener
    {
      public ArrayList<UUID> thrownEggs = new ArrayList();
     
      @EventHandler
      public void onThrow(PlayerInteractEvent event)
      {
        if (event.getPlayer().getItemInHand() == null) {
          return;
        }
        ItemStack stack = event.getPlayer().getItemInHand();
        if (stack.getType().equals(Material.EGG))
        {
          if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
            return;
          }
          if (!stack.hasItemMeta()) {
            return;
          }
          if (!stack.getItemMeta().hasDisplayName()) {
            return;
          }
          if (!stack.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Bridge Egg")) {
            return;
          }
          this.thrownEggs.add(event.getPlayer().getUniqueId());
          return;
        }
      }
     
      @EventHandler
      public void onHit(ProjectileHitEvent event)
      {
        if (((event.getEntity() instanceof Egg)) &&
          ((event.getEntity() instanceof Egg)))
        {
          Egg egg = (Egg)event.getEntity();
          if (Pathway.pathways.containsKey(egg))
          {
            Pathway.pathways.remove(egg);
            return;
          }
          return;
        }
      }
     
      @EventHandler
      public void onLaunch(ProjectileLaunchEvent event)
      {
        if ((((event.getEntity() instanceof Egg)) || ((event.getEntity() instanceof Snowball))) &&
          ((event.getEntity() instanceof Egg)))
        {
          Egg egg = (Egg)event.getEntity();
          if ((egg.getShooter() instanceof Player))
          {
            Player player = (Player)egg.getShooter();
            if (this.thrownEggs.contains(player.getUniqueId()))
            {
              this.thrownEggs.remove(player.getUniqueId());
              Pathway.pathways.put(egg, Material.WOOL);
              return;
            }
            return;
          }
          return;
        }
      }
    }

    Code (Java):
    package com.fabietto03.luckywarsaddon;

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.logging.Logger;
    import listeners.Damage;
    import listeners.Interact;
    import listeners.Projectile;
    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Wolf;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import other.MyWolf;
    import other.Pathway;

    public class Main
      extends JavaPlugin
    {
      public static Main instance;
      private Pathway pH;
      public static HashMap<String, ArrayList<Wolf>> wolfs = new HashMap();
      public static List<String> worlds = new ArrayList();
     
      public void onEnable()
      {
        instance = this;
        this.pH = new Pathway();
        Bukkit.getServer().getPluginManager().registerEvents(new Damage(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new Interact(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new MyWolf(), this);
        Bukkit.getServer().getPluginManager().registerEvents(new Projectile(), this);
        saveDefaultConfig();
        Iterator localIterator2;
        for (Iterator localIterator1 = getServer().getWorlds().iterator(); localIterator1.hasNext(); localIterator2.hasNext())
        {
          World world = (World)localIterator1.next();
          localIterator2 = world.getEntitiesByClass(Wolf.class).iterator();
        }
        for (String world : getConfig().getStringList("worlds")) {
          if (Bukkit.getWorld(world) == null) {
            getLogger().info("Invalid world in config: " + world);
          } else {
            worlds.add(world);
          }
        }
      }
     
      public Pathway getPathwayHandler()
      {
        return this.pH;
      }
     
      public static Main getInstance()
      {
        return instance;
      }
     
      public void onDisable() {}
    }
     
     
  2. Did you even read the error? You cannot perform .distance() on different worlds...
     
  3. I read it but I do not know how to fix it.
     
  4. Check if the worlds are the same before checking distance.
     
    • Winner Winner x 1
  5. how can I do? I never did it.
     
  6. This is basic Java 101. pl.getWorld().equals(loc.getWorld()) should suffice.
     
  7. Where should I put it? and how it could fix the error, I'm using a MultiArena minigame I have more than one world.
     
  8. We don't spoonfeed here. I think I've said more than enough for any programmer at any experience level to figure this out. Saying any more will not help you at all, but hinder your learning ability.
     
    • Agree Agree x 4
  9. if(pl.getLocation() == null)
    {
    return;
    }
     
  10. NO. IT WILL NOT.

    As he now has no brain cells left, as he said. Learn a little bit of Java and common sense. It's pretty much common sense.
     
  11. It's actually funny that there are just few Italian programmers on this forums that really know what their doing, (I'm Italian)
     
  12. Sono riuscita a fixare il bug.
     
  13. Well, the forum states somewhere that you should try to keep the forums as english as possible. IF everyone started speaking their "native langauge" then no one would understand each other.
    edit: sorry for bumping thread.. I just had to get my point through