Move file

This commit is contained in:
fullwall 2012-02-28 21:03:36 +08:00
parent 3a637dd234
commit cf5017644b
3 changed files with 19 additions and 48 deletions

View File

@ -48,7 +48,7 @@ public class EquipmentEditor extends Editor {
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!plugin.getNPCManager().isNPC(event.getRightClicked())
|| !plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|| !event.getPlayer().getName().equals(player.getName()))
|| !event.getPlayer().equals(player))
return;
ItemStack hand = player.getItemInHand();
@ -92,24 +92,28 @@ public class EquipmentEditor extends Editor {
break;
case AIR:
for (int i = 0; i < 4; i++) {
if (trait.getEquipment(i) != null && trait.getEquipment(i).getType() != Material.AIR) {
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.getEquipment(i));
trait.setEquipment(i, null);
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.get(i));
trait.set(i, null);
}
}
Messaging.send(player, "<e>" + npc.getName() + " <a>had all of its items removed.");
}
// Now edit the equipment based on the slot
if (trait.getEquipment(slot) != null && trait.getEquipment(slot).getType() != Material.AIR)
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.getEquipment(slot));
trait.setEquipment(slot, hand);
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
player.setItemInHand(hand);
if (set.getType() != Material.AIR)
if (trait.get(slot) != null) {
player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), trait.get(slot));
}
ItemStack set = hand;
if (set != null && set.getType() != Material.AIR) {
if (hand.getAmount() > 1) {
hand.setAmount(hand.getAmount() - 1);
} else {
hand = null;
}
player.setItemInHand(hand);
set.setAmount(1);
trait.setEquipment(slot, set);
}
trait.set(slot, set);
}
}

View File

@ -5,9 +5,9 @@ import java.util.List;
import net.citizensnpcs.api.ai.AI;
import net.citizensnpcs.api.ai.NavigationCallback;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.StorageUtils;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StorageUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

View File

@ -1,33 +0,0 @@
package net.citizensnpcs.util;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class StorageUtils {
public static Location loadLocation(DataKey root) {
root = root.getRelative("location");
return new Location(Bukkit.getWorld(root.getString("world")), root.getDouble("x"), root.getDouble("y"), root
.getDouble("z"), (float) root.getDouble("yaw", 0), (float) root.getDouble("pitch", 0));
}
public static ItemStack loadItemStack(DataKey root) {
root = root.getRelative("item");
return new ItemStack(Material.matchMaterial(root.getString("id")), root.getInt("amount"), (short) (root
.keyExists("data") ? root.getInt("data") : 0));
}
public static void saveLocation(DataKey key, Location location) {
key = key.getRelative("location");
key.setString("world", location.getWorld().getName());
key.setDouble("x", location.getX());
key.setDouble("y", location.getY());
key.setDouble("z", location.getZ());
key.setDouble("yaw", location.getYaw());
key.setDouble("pitch", location.getPitch());
}
}