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
public void onImplementationChanged() {
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() {
contextClassLoader = Thread.currentThread().getContextClassLoader();
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) {
if (instance == null)
return;
instance.toRespawn.put(instance.toCoord(loc.getChunk()), id);
}
private static EventListen instance;
}

View File

@ -153,8 +153,11 @@ public class NPCCommands {
from.save(key);
copy.load(key);
if (copy.isSpawned() && sender instanceof Player)
copy.getBukkitEntity().teleport((Player) sender);
if (copy.isSpawned() && sender instanceof Player) {
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()));
}

View File

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

View File

@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class EquipmentEditor extends Editor {
private final NPC npc;
@ -44,7 +45,9 @@ public class EquipmentEditor extends Editor {
return;
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;
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
public CitizensEndermanNPC(int id, String name) {
super(id, name, EntityEndermanNPC.class);
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
public void equip(Player equipper, ItemStack hand) {
if (!hand.getType().isBlock()) {
Messaging.sendError(equipper, "Invalid block!");
return;
@ -47,11 +45,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
ItemStack set = hand;
if (set.getType() != Material.AIR) {
if (hand.getAmount() > 1) {
hand.setAmount(hand.getAmount() - 1);
} else
hand = null;
equipper.setItemInHand(hand);
hand.setAmount(hand.getAmount() - 1);
set.setAmount(1);
}
getTrait(Equipment.class).set(0, set);

View File

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

View File

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

View File

@ -29,8 +29,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
}
@Override
public void equip(Player equipper) {
ItemStack hand = equipper.getItemInHand();
public void equip(Player equipper, ItemStack hand) {
if (hand.getType() == Material.SHEARS) {
Messaging.send(equipper, StringHelper.wrap(getName()) + " is "
+ (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(color.name().toLowerCase().replace("_", " ")) + ".");
if (hand.getAmount() > 1)
hand.setAmount(hand.getAmount() - 1);
else
hand = null;
equipper.setItemInHand(hand);
hand.setAmount(hand.getAmount() - 1);
} else {
getTrait(WoolColor.class).setColor(DyeColor.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;
public static void attack(EntityLiving handle, EntityLiving target) {
handle.k(target);
}
public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
if (NMS.GOAL_FIELD == null || goalSelectors == null)
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) {
if (ENTITY_CLASS_TO_INT.containsKey(clazz))
return;
@ -160,12 +168,4 @@ public class NMS {
} 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());
}
}