Exemple #1
0
  /** Called when saving data. If overriding, remember to call this version */
  public void writeToNBT(NBTTagCompound root) {
    root.setString("World", mLocation.getWorld().getName());
    root.setDouble("X", mLocation.getX());
    root.setDouble("Y", mLocation.getY());
    root.setDouble("Z", mLocation.getZ());

    Util.writeItemStackToNBT(mHoverItemTemplate, root);
  }
Exemple #2
0
  /** Called when loading data. If overriding, remember to call this version */
  public void readFromNBT(NBTTagCompound root) {
    mLocation =
        new Location(
            Bukkit.getWorld(root.getString("World")),
            root.getDouble("X"),
            root.getDouble("Y"),
            root.getDouble("Z"));

    mHoverItemTemplate = Util.readItemStackFromNBT(root);

    // Check for existing item
    Collection<Item> items = mLocation.getWorld().getEntitiesByClass(Item.class);
    Location loc = mLocation.clone().add(0, 1, 0);

    for (Item item : items) {
      if (item.getItemStack().equals(mHoverItemTemplate)
          && item.getLocation().distanceSquared(loc) < 1D
          && !item.isDead()) {
        SkyQuestPlugin.instance.getLogger().fine("Attaching old item");
        // Reattach the item
        mHoveringItem = item;
        break;
      }
    }
    // Spawn a new item if needed
    if (mHoveringItem == null) {
      SkyQuestPlugin.instance.getLogger().fine("Spawning new item");
      mHoveringItem =
          mLocation.getWorld().dropItem(mLocation.clone().add(0.5, 1, 0.5), mHoverItemTemplate);
      mHoveringItem.setVelocity(new Vector(0, 0, 0));
    }

    // Register the event listener
    mEventListener = new PedestalListener();
    SkyQuestPlugin.instance
        .getServer()
        .getPluginManager()
        .registerEvents(mEventListener, SkyQuestPlugin.instance);
  }