This commit is contained in:
fullwall 2012-09-14 16:20:22 +08:00
parent 9d34a6b4f2
commit b14b4173b9
10 changed files with 47 additions and 60 deletions

View File

@ -236,19 +236,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
} }
} }
private void setupEconomy() {
try {
RegisteredServiceProvider<Economy> provider = Bukkit.getServicesManager().getRegistration(
Economy.class);
if (provider != null && provider.getProvider() != null) {
Economy economy = provider.getProvider();
Bukkit.getPluginManager().registerEvents(new PaymentListener(economy), this);
}
} catch (NoClassDefFoundError e) {
Messaging.log("Unable to use economy handling. Has Vault been enabled?");
}
}
@Override @Override
public void onImplementationChanged() { public void onImplementationChanged() {
Messaging.severe("Citizens implementation changed, disabling plugin."); Messaging.severe("Citizens implementation changed, disabling plugin.");
@ -293,6 +280,19 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
}); });
} }
private void setupEconomy() {
try {
RegisteredServiceProvider<Economy> provider = Bukkit.getServicesManager().getRegistration(
Economy.class);
if (provider != null && provider.getProvider() != null) {
Economy economy = provider.getProvider();
Bukkit.getPluginManager().registerEvents(new PaymentListener(economy), this);
}
} catch (NoClassDefFoundError e) {
Messaging.log("Unable to use economy handling. Has Vault been enabled?");
}
}
private void setupScripting() { private void setupScripting() {
contextClassLoader = Thread.currentThread().getContextClassLoader(); contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader()); Thread.currentThread().setContextClassLoader(getClassLoader());

View File

@ -288,11 +288,11 @@ public class EventListen implements Listener {
} }
} }
private static EventListen instance;
public static void add(Location loc, int id) { public static void add(Location loc, int id) {
if (instance == null) if (instance == null)
return; return;
instance.toRespawn.put(instance.toCoord(loc.getChunk()), id); instance.toRespawn.put(instance.toCoord(loc.getChunk()), id);
} }
private static EventListen instance;
} }

View File

@ -153,8 +153,11 @@ public class NPCCommands {
from.save(key); from.save(key);
copy.load(key); copy.load(key);
if (copy.isSpawned() && sender instanceof Player) if (copy.isSpawned() && sender instanceof Player) {
copy.getBukkitEntity().teleport((Player) sender); Player player = (Player) sender;
copy.getBukkitEntity().teleport(player);
copy.getTrait(CurrentLocation.class).setLocation(player.getLocation());
}
Messaging.sendF(sender, ChatColor.GREEN + "%s has been copied.", StringHelper.wrap(npc.getName())); Messaging.sendF(sender, ChatColor.GREEN + "%s has been copied.", StringHelper.wrap(npc.getName()));
} }

View File

@ -1,8 +1,8 @@
package net.citizensnpcs.editor; package net.citizensnpcs.editor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public interface Equipable { public interface Equipable {
public void equip(Player equipper, ItemStack toEquip);
public void equip(Player equipper);
} }

View File

@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class EquipmentEditor extends Editor { public class EquipmentEditor extends Editor {
private final NPC npc; private final NPC npc;
@ -44,7 +45,9 @@ public class EquipmentEditor extends Editor {
return; return;
if (npc instanceof Equipable) { if (npc instanceof Equipable) {
((Equipable) npc).equip(event.getPlayer()); ItemStack hand = event.getPlayer().getItemInHand();
((Equipable) npc).equip(event.getPlayer(), hand);
event.getPlayer().setItemInHand(hand.getAmount() > 0 ? hand : null);
} }
} }
} }

View File

@ -21,14 +21,12 @@ import org.bukkit.material.MaterialData;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
public CitizensEndermanNPC(int id, String name) { public CitizensEndermanNPC(int id, String name) {
super(id, name, EntityEndermanNPC.class); super(id, name, EntityEndermanNPC.class);
} }
@Override @Override
public void equip(Player equipper) { public void equip(Player equipper, ItemStack hand) {
ItemStack hand = equipper.getItemInHand();
if (!hand.getType().isBlock()) { if (!hand.getType().isBlock()) {
Messaging.sendError(equipper, "Invalid block!"); Messaging.sendError(equipper, "Invalid block!");
return; return;
@ -47,11 +45,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
ItemStack set = hand; ItemStack set = hand;
if (set.getType() != Material.AIR) { if (set.getType() != Material.AIR) {
if (hand.getAmount() > 1) {
hand.setAmount(hand.getAmount() - 1); hand.setAmount(hand.getAmount() - 1);
} else
hand = null;
equipper.setItemInHand(hand);
set.setAmount(1); set.setAmount(1);
} }
getTrait(Equipment.class).set(0, set); getTrait(Equipment.class).set(0, set);

View File

@ -41,8 +41,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
} }
@Override @Override
public void equip(Player equipper) { public void equip(Player equipper, ItemStack hand) {
ItemStack hand = equipper.getItemInHand();
Equipment trait = getTrait(Equipment.class); Equipment trait = getTrait(Equipment.class);
int slot = 0; int slot = 0;
Material type = hand == null ? Material.AIR : hand.getType(); Material type = hand == null ? Material.AIR : hand.getType();
@ -105,11 +104,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
clone.setAmount(1); clone.setAmount(1);
trait.set(slot, clone); trait.set(slot, clone);
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1); hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
} }
} }

View File

@ -28,23 +28,20 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
} }
@Override @Override
public void equip(Player equipper) { public void equip(Player equipper, ItemStack hand) {
ItemStack hand = equipper.getItemInHand();
if (hand.getType() == Material.SADDLE) { if (hand.getType() == Material.SADDLE) {
if (!getBukkitEntity().hasSaddle()) { if (!getBukkitEntity().hasSaddle()) {
getTrait(Saddle.class).toggle(); getTrait(Saddle.class).toggle();
equipper.setItemInHand(null); hand.setAmount(0);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled."); Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled.");
} }
} else { } else if (getBukkitEntity().hasSaddle()) {
if (getBukkitEntity().hasSaddle()) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(), equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(),
new ItemStack(Material.SADDLE, 1)); new ItemStack(Material.SADDLE, 1));
getTrait(Saddle.class).toggle(); getTrait(Saddle.class).toggle();
Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled."); Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled.");
} }
} }
}
@Override @Override
public Pig getBukkitEntity() { public Pig getBukkitEntity() {

View File

@ -29,8 +29,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
} }
@Override @Override
public void equip(Player equipper) { public void equip(Player equipper, ItemStack hand) {
ItemStack hand = equipper.getItemInHand();
if (hand.getType() == Material.SHEARS) { if (hand.getType() == Material.SHEARS) {
Messaging.send(equipper, StringHelper.wrap(getName()) + " is " Messaging.send(equipper, StringHelper.wrap(getName()) + " is "
+ (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared."); + (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared.");
@ -45,11 +44,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
StringHelper.wrap(getName()) + " is now " StringHelper.wrap(getName()) + " is now "
+ StringHelper.wrap(color.name().toLowerCase().replace("_", " ")) + "."); + StringHelper.wrap(color.name().toLowerCase().replace("_", " ")) + ".");
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1); hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
} else { } else {
getTrait(WoolColor.class).setColor(DyeColor.WHITE); getTrait(WoolColor.class).setColor(DyeColor.WHITE);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now " + StringHelper.wrap("white") Messaging.send(equipper, StringHelper.wrap(getName()) + " is now " + StringHelper.wrap("white")

View File

@ -35,6 +35,10 @@ public class NMS {
private static Field THREAD_STOPPER; private static Field THREAD_STOPPER;
public static void attack(EntityLiving handle, EntityLiving target) {
handle.k(target);
}
public static void clearGoals(PathfinderGoalSelector... goalSelectors) { public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
if (NMS.GOAL_FIELD == null || goalSelectors == null) if (NMS.GOAL_FIELD == null || goalSelectors == null)
return; return;
@ -76,6 +80,10 @@ public class NMS {
} }
} }
public static void look(ControllerLook controllerLook, EntityLiving handle, EntityLiving target) {
controllerLook.a(target, 10.0F, handle.bf());
}
public static void registerEntityClass(Class<? extends Entity> clazz) { public static void registerEntityClass(Class<? extends Entity> clazz) {
if (ENTITY_CLASS_TO_INT.containsKey(clazz)) if (ENTITY_CLASS_TO_INT.containsKey(clazz))
return; return;
@ -160,12 +168,4 @@ public class NMS {
} catch (Exception e) { } catch (Exception e) {
} }
} }
public static void attack(EntityLiving handle, EntityLiving target) {
handle.k(target);
}
public static void look(ControllerLook controllerLook, EntityLiving handle, EntityLiving target) {
controllerLook.a(target, 10.0F, handle.bf());
}
} }