mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 12:46:04 +01:00
Change mob classes to static inner, add rudimentary pathfinder
This commit is contained in:
parent
6bb38d534e
commit
ad65534ac5
@ -2,11 +2,8 @@ package net.citizensnpcs;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -51,9 +48,16 @@ import org.bukkit.permissions.Permission;
|
|||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
public class Citizens extends JavaPlugin {
|
public class Citizens extends JavaPlugin {
|
||||||
private static final String COMPATIBLE_MC_VERSION = "1.1";
|
private static final String COMPATIBLE_MC_VERSION = "1.1";
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final List<Class<? extends Trait>> traits = Lists.newArrayList(Owner.class, Spawned.class,
|
||||||
|
LookClose.class, SpawnLocation.class);
|
||||||
|
// TODO: automatically register trait classes in CitizensNPC?
|
||||||
|
|
||||||
private volatile CitizensNPCManager npcManager;
|
private volatile CitizensNPCManager npcManager;
|
||||||
private final InstanceFactory<Character> characterManager = new DefaultInstanceFactory<Character>();
|
private final InstanceFactory<Character> characterManager = new DefaultInstanceFactory<Character>();
|
||||||
private final InstanceFactory<Trait> traitManager = new DefaultInstanceFactory<Trait>();
|
private final InstanceFactory<Trait> traitManager = new DefaultInstanceFactory<Trait>();
|
||||||
@ -62,6 +66,24 @@ public class Citizens extends JavaPlugin {
|
|||||||
private Storage saves;
|
private Storage saves;
|
||||||
private boolean compatible;
|
private boolean compatible;
|
||||||
|
|
||||||
|
private boolean handleMistake(CommandSender sender, String command, String modifier) {
|
||||||
|
int minDist = Integer.MAX_VALUE;
|
||||||
|
String closest = "";
|
||||||
|
for (String string : cmdManager.getAllCommandModifiers(command)) {
|
||||||
|
int distance = StringHelper.getLevenshteinDistance(modifier, string);
|
||||||
|
if (minDist > distance) {
|
||||||
|
minDist = distance;
|
||||||
|
closest = string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!closest.isEmpty()) {
|
||||||
|
sender.sendMessage(ChatColor.GRAY + "Unknown command. Did you mean:");
|
||||||
|
sender.sendMessage(StringHelper.wrap(" /") + command + " " + StringHelper.wrap(closest));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
|
||||||
Player player = null;
|
Player player = null;
|
||||||
@ -149,10 +171,11 @@ public class Citizens extends JavaPlugin {
|
|||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
// NPC storage
|
// NPC storage
|
||||||
if (Setting.USE_DATABASE.asBoolean())
|
if (Setting.USE_DATABASE.asBoolean()) {
|
||||||
saves = new DatabaseStorage();
|
saves = new DatabaseStorage();
|
||||||
else
|
} else {
|
||||||
saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml");
|
saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml");
|
||||||
|
}
|
||||||
|
|
||||||
// Register API managers
|
// Register API managers
|
||||||
npcManager = new CitizensNPCManager(saves);
|
npcManager = new CitizensNPCManager(saves);
|
||||||
@ -167,10 +190,7 @@ public class Citizens extends JavaPlugin {
|
|||||||
registerCommands();
|
registerCommands();
|
||||||
registerPermissions();
|
registerPermissions();
|
||||||
|
|
||||||
traitManager.register(SpawnLocation.class);
|
traitManager.registerAll(traits);
|
||||||
traitManager.register(Owner.class);
|
|
||||||
traitManager.register(Spawned.class);
|
|
||||||
traitManager.register(LookClose.class);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new NPCUpdater(npcManager), 0, 1);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new NPCUpdater(npcManager), 0, 1);
|
||||||
|
|
||||||
@ -193,6 +213,29 @@ public class Citizens extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerCommands() {
|
||||||
|
cmdManager = new CommandManager();
|
||||||
|
cmdManager.setInjector(new Injector(npcManager, characterManager));
|
||||||
|
|
||||||
|
// cmdManager.register(AdminCommands.class);
|
||||||
|
cmdManager.register(NPCCommands.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPermissions() {
|
||||||
|
// TODO There has to be a better way than this (maybe use Permission
|
||||||
|
// annotation to register permissions?)
|
||||||
|
Map<String, Boolean> children = new HashMap<String, Boolean>();
|
||||||
|
children.put("citizens.npc.create", true);
|
||||||
|
children.put("citizens.npc.spawn", true);
|
||||||
|
children.put("citizens.npc.despawn", true);
|
||||||
|
children.put("citizens.npc.select", true);
|
||||||
|
children.put("citizens.npc.tp", true);
|
||||||
|
children.put("citizens.npc.tphere", true);
|
||||||
|
|
||||||
|
Permission perm = new Permission("citizens.*", PermissionDefault.OP, children);
|
||||||
|
getServer().getPluginManager().addPermission(perm);
|
||||||
|
}
|
||||||
|
|
||||||
private void saveNPCs() {
|
private void saveNPCs() {
|
||||||
for (NPC npc : npcManager)
|
for (NPC npc : npcManager)
|
||||||
npc.save(saves.getKey("npc." + npc.getId()));
|
npc.save(saves.getKey("npc." + npc.getId()));
|
||||||
@ -221,55 +264,4 @@ public class Citizens extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
Messaging.log("Loaded " + created + " NPCs (" + spawned + " spawned).");
|
Messaging.log("Loaded " + created + " NPCs (" + spawned + " spawned).");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPermissions() {
|
|
||||||
// TODO There has to be a better way than this (maybe use Permission
|
|
||||||
// annotation to register permissions?)
|
|
||||||
Map<String, Boolean> children = new HashMap<String, Boolean>();
|
|
||||||
children.put("citizens.npc.create", true);
|
|
||||||
children.put("citizens.npc.spawn", true);
|
|
||||||
children.put("citizens.npc.despawn", true);
|
|
||||||
children.put("citizens.npc.select", true);
|
|
||||||
children.put("citizens.npc.tp", true);
|
|
||||||
children.put("citizens.npc.tphere", true);
|
|
||||||
|
|
||||||
Permission perm = new Permission("citizens.*", PermissionDefault.OP, children);
|
|
||||||
getServer().getPluginManager().addPermission(perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerCommands() {
|
|
||||||
cmdManager = new CommandManager();
|
|
||||||
cmdManager.setInjector(new Injector(npcManager, characterManager));
|
|
||||||
|
|
||||||
// cmdManager.register(AdminCommands.class);
|
|
||||||
cmdManager.register(NPCCommands.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean handleMistake(CommandSender sender, String command, String modifier) {
|
|
||||||
String[] modifiers = cmdManager.getAllCommandModifiers(command);
|
|
||||||
Map<Integer, String> values = new TreeMap<Integer, String>();
|
|
||||||
int i = 0;
|
|
||||||
for (String string : modifiers) {
|
|
||||||
values.put(StringHelper.getLevenshteinDistance(modifier, string), modifiers[i]);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
int best = 0;
|
|
||||||
boolean stop = false;
|
|
||||||
Set<String> possible = new HashSet<String>();
|
|
||||||
for (Entry<Integer, String> entry : values.entrySet()) {
|
|
||||||
if (!stop) {
|
|
||||||
best = entry.getKey();
|
|
||||||
stop = true;
|
|
||||||
} else if (entry.getKey() > best)
|
|
||||||
break;
|
|
||||||
possible.add(entry.getValue());
|
|
||||||
}
|
|
||||||
if (possible.size() > 0) {
|
|
||||||
sender.sendMessage(ChatColor.GRAY + "Unknown command. Did you mean:");
|
|
||||||
for (String string : possible)
|
|
||||||
sender.sendMessage(StringHelper.wrap(" /") + command + " " + StringHelper.wrap(string));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package net.citizensnpcs;
|
package net.citizensnpcs;
|
||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.npc.entity.CitizensHumanNPC;
|
import net.citizensnpcs.npc.entity.CitizensHumanNPC;
|
||||||
|
|
||||||
public class NPCUpdater implements Runnable {
|
public class NPCUpdater implements Runnable {
|
||||||
private CitizensNPCManager npcManager;
|
private final CitizensNPCManager npcManager;
|
||||||
|
|
||||||
public NPCUpdater(CitizensNPCManager npcManager) {
|
public NPCUpdater(CitizensNPCManager npcManager) {
|
||||||
this.npcManager = npcManager;
|
this.npcManager = npcManager;
|
||||||
@ -16,7 +15,8 @@ public class NPCUpdater implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (NPC npc : npcManager)
|
for (NPC npc : npcManager)
|
||||||
// For now only do this for human NPCs
|
// For now only do this for human NPCs
|
||||||
if (((CitizensNPC) npc) instanceof CitizensHumanNPC)
|
if (npc instanceof CitizensHumanNPC) {
|
||||||
((CitizensHumanNPC) npc).tick();
|
((CitizensHumanNPC) npc).tick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -44,10 +44,6 @@ public class Settings {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object get() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean asBoolean() {
|
public boolean asBoolean() {
|
||||||
return (Boolean) value;
|
return (Boolean) value;
|
||||||
}
|
}
|
||||||
@ -68,6 +64,10 @@ public class Settings {
|
|||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
private void set(Object value) {
|
private void set(Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -48,38 +48,14 @@ public class CommandContext {
|
|||||||
String.class);
|
String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int argsLength() {
|
||||||
|
return args.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCommand() {
|
public String getCommand() {
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(String command) {
|
|
||||||
return args[0].equalsIgnoreCase(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(int index) {
|
|
||||||
return args[index + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(int index, String def) {
|
|
||||||
return index + 1 < args.length ? args[index + 1] : def;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getJoinedStrings(int initialIndex) {
|
|
||||||
initialIndex = initialIndex + 1;
|
|
||||||
StringBuilder buffer = new StringBuilder(args[initialIndex]);
|
|
||||||
for (int i = initialIndex + 1; i < args.length; i++)
|
|
||||||
buffer.append(" ").append(args[i]);
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInteger(int index) throws NumberFormatException {
|
|
||||||
return Integer.parseInt(args[index + 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInteger(int index, int def) throws NumberFormatException {
|
|
||||||
return index + 1 < args.length ? Integer.parseInt(args[index + 1]) : def;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDouble(int index) throws NumberFormatException {
|
public double getDouble(int index) throws NumberFormatException {
|
||||||
return Double.parseDouble(args[index + 1]);
|
return Double.parseDouble(args[index + 1]);
|
||||||
}
|
}
|
||||||
@ -88,10 +64,24 @@ public class CommandContext {
|
|||||||
return index + 1 < args.length ? Double.parseDouble(args[index + 1]) : def;
|
return index + 1 < args.length ? Double.parseDouble(args[index + 1]) : def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getSlice(int index) {
|
public Set<Character> getFlags() {
|
||||||
String[] slice = new String[args.length - index];
|
return flags;
|
||||||
System.arraycopy(args, index, slice, 0, args.length - index);
|
}
|
||||||
return slice;
|
|
||||||
|
public int getInteger(int index) throws NumberFormatException {
|
||||||
|
return Integer.parseInt(args[index + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInteger(int index, int def) throws NumberFormatException {
|
||||||
|
return index + 1 < args.length ? Integer.parseInt(args[index + 1]) : def;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJoinedStrings(int initialIndex) {
|
||||||
|
initialIndex = initialIndex + 1;
|
||||||
|
StringBuilder buffer = new StringBuilder(args[initialIndex]);
|
||||||
|
for (int i = initialIndex + 1; i < args.length; i++)
|
||||||
|
buffer.append(" ").append(args[i]);
|
||||||
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getPaddedSlice(int index, int padding) {
|
public String[] getPaddedSlice(int index, int padding) {
|
||||||
@ -100,19 +90,29 @@ public class CommandContext {
|
|||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFlag(char ch) {
|
public String[] getSlice(int index) {
|
||||||
return flags.contains(ch);
|
String[] slice = new String[args.length - index];
|
||||||
|
System.arraycopy(args, index, slice, 0, args.length - index);
|
||||||
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Character> getFlags() {
|
public String getString(int index) {
|
||||||
return flags;
|
return args[index + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(int index, String def) {
|
||||||
|
return index + 1 < args.length ? args[index + 1] : def;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasFlag(char ch) {
|
||||||
|
return flags.contains(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int length() {
|
public int length() {
|
||||||
return args.length;
|
return args.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int argsLength() {
|
public boolean matches(String command) {
|
||||||
return args.length - 1;
|
return args[0].equalsIgnoreCase(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,11 +11,6 @@ public class CommandIdentifier {
|
|||||||
this.modifier = modifier;
|
this.modifier = modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(command, modifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
@ -38,11 +33,16 @@ public class CommandIdentifier {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
public String getModifier() {
|
public String getModifier() {
|
||||||
return modifier;
|
return modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommand() {
|
@Override
|
||||||
return command;
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(command, modifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,9 +33,9 @@ import java.util.logging.Logger;
|
|||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.npc.trait.trait.Owner;
|
import net.citizensnpcs.api.npc.trait.trait.Owner;
|
||||||
import net.citizensnpcs.command.annotation.Command;
|
import net.citizensnpcs.command.annotation.Command;
|
||||||
import net.citizensnpcs.command.annotation.Requirements;
|
|
||||||
import net.citizensnpcs.command.annotation.NestedCommand;
|
import net.citizensnpcs.command.annotation.NestedCommand;
|
||||||
import net.citizensnpcs.command.annotation.Permission;
|
import net.citizensnpcs.command.annotation.Permission;
|
||||||
|
import net.citizensnpcs.command.annotation.Requirements;
|
||||||
import net.citizensnpcs.command.annotation.ServerCommand;
|
import net.citizensnpcs.command.annotation.ServerCommand;
|
||||||
import net.citizensnpcs.command.exception.CommandException;
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||||
@ -51,205 +51,6 @@ import org.bukkit.command.ConsoleCommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
// Logger for general errors.
|
|
||||||
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
|
||||||
/*
|
|
||||||
* Mapping of commands (including aliases) with a description. Root commands
|
|
||||||
* are stored under a key of null, whereas child commands are cached under
|
|
||||||
* their respective Method. The child map has the key of the command name
|
|
||||||
* (one for each alias) with the method.
|
|
||||||
*/
|
|
||||||
private final Map<Method, Map<CommandIdentifier, Method>> commands = new HashMap<Method, Map<CommandIdentifier, Method>>();
|
|
||||||
// Used to store the instances associated with a method.
|
|
||||||
private final Map<Method, Object> instances = new HashMap<Method, Object>();
|
|
||||||
/*
|
|
||||||
* Mapping of commands (not including aliases) with a description. This is
|
|
||||||
* only for top level commands.
|
|
||||||
*/
|
|
||||||
private final Map<CommandIdentifier, String> descs = new HashMap<CommandIdentifier, String>();
|
|
||||||
// Stores the injector used to getInstance.
|
|
||||||
private Injector injector;
|
|
||||||
private final Map<Method, Requirements> requirements = new HashMap<Method, Requirements>();
|
|
||||||
private final Map<Method, ServerCommand> serverCommands = new HashMap<Method, ServerCommand>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Register an class that contains commands (denoted by Command. If no
|
|
||||||
* dependency injector is specified, then the methods of the class will be
|
|
||||||
* registered to be called statically. Otherwise, new instances will be
|
|
||||||
* created of the command classes and methods will not be called statically.
|
|
||||||
*/
|
|
||||||
public void register(Class<?> clazz) {
|
|
||||||
registerMethods(clazz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Register the methods of a class. This will automatically construct
|
|
||||||
* instances as necessary.
|
|
||||||
*/
|
|
||||||
private void registerMethods(Class<?> clazz, Method parent) {
|
|
||||||
Object obj = injector.getInstance(clazz);
|
|
||||||
registerMethods(clazz, parent, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the methods of a class.
|
|
||||||
private void registerMethods(Class<?> clazz, Method parent, Object obj) {
|
|
||||||
Map<CommandIdentifier, Method> map;
|
|
||||||
|
|
||||||
// Make a new hash map to cache the commands for this class
|
|
||||||
// as looking up methods via reflection is fairly slow
|
|
||||||
if (commands.containsKey(parent))
|
|
||||||
map = commands.get(parent);
|
|
||||||
else {
|
|
||||||
map = new HashMap<CommandIdentifier, Method>();
|
|
||||||
commands.put(parent, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Method method : clazz.getMethods()) {
|
|
||||||
if (!method.isAnnotationPresent(Command.class))
|
|
||||||
continue;
|
|
||||||
boolean isStatic = Modifier.isStatic(method.getModifiers());
|
|
||||||
|
|
||||||
Command cmd = method.getAnnotation(Command.class);
|
|
||||||
String[] modifiers = cmd.modifiers();
|
|
||||||
|
|
||||||
// Cache the aliases too
|
|
||||||
for (String alias : cmd.aliases())
|
|
||||||
for (String modifier : modifiers)
|
|
||||||
map.put(new CommandIdentifier(alias, modifier), method);
|
|
||||||
|
|
||||||
Requirements cmdRequirements = null;
|
|
||||||
if (method.getDeclaringClass().isAnnotationPresent(Requirements.class))
|
|
||||||
cmdRequirements = method.getDeclaringClass().getAnnotation(Requirements.class);
|
|
||||||
|
|
||||||
if (method.isAnnotationPresent(Requirements.class))
|
|
||||||
cmdRequirements = method.getAnnotation(Requirements.class);
|
|
||||||
|
|
||||||
if (requirements != null)
|
|
||||||
requirements.put(method, cmdRequirements);
|
|
||||||
|
|
||||||
ServerCommand serverCommand = null;
|
|
||||||
if (method.isAnnotationPresent(ServerCommand.class))
|
|
||||||
serverCommand = method.getAnnotation(ServerCommand.class);
|
|
||||||
|
|
||||||
if (serverCommand != null)
|
|
||||||
serverCommands.put(method, serverCommand);
|
|
||||||
|
|
||||||
// We want to be able invoke with an instance
|
|
||||||
if (!isStatic) {
|
|
||||||
// Can't register this command if we don't have an instance
|
|
||||||
if (obj == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
instances.put(method, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build a list of commands and their usage details, at least for
|
|
||||||
// root level commands
|
|
||||||
if (parent == null)
|
|
||||||
if (cmd.usage().length() == 0)
|
|
||||||
descs.put(new CommandIdentifier(cmd.aliases()[0], cmd.modifiers()[0]), cmd.desc());
|
|
||||||
else
|
|
||||||
descs.put(new CommandIdentifier(cmd.aliases()[0], cmd.modifiers()[0]),
|
|
||||||
cmd.usage() + " - " + cmd.desc());
|
|
||||||
|
|
||||||
// Look for nested commands -- if there are any, those have
|
|
||||||
// to be cached too so that they can be quickly looked
|
|
||||||
// up when processing commands
|
|
||||||
if (method.isAnnotationPresent(NestedCommand.class)) {
|
|
||||||
NestedCommand nestedCmd = method.getAnnotation(NestedCommand.class);
|
|
||||||
|
|
||||||
for (Class<?> nestedCls : nestedCmd.value())
|
|
||||||
registerMethods(nestedCls, method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks to see whether there is a command named such at the root level.
|
|
||||||
* This will check aliases as well.
|
|
||||||
*/
|
|
||||||
public boolean hasCommand(String command, String modifier) {
|
|
||||||
return commands.get(null).containsKey(new CommandIdentifier(command.toLowerCase(), modifier.toLowerCase()))
|
|
||||||
|| commands.get(null).containsKey(new CommandIdentifier(command.toLowerCase(), "*"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a list of command descriptions. This is only for root commands.
|
|
||||||
public Map<CommandIdentifier, String> getCommands() {
|
|
||||||
return descs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the usage string for a command.
|
|
||||||
private String getUsage(String[] args, int level, Command cmd) {
|
|
||||||
StringBuilder command = new StringBuilder();
|
|
||||||
|
|
||||||
command.append("/");
|
|
||||||
|
|
||||||
for (int i = 0; i <= level; i++)
|
|
||||||
command.append(args[i] + " ");
|
|
||||||
|
|
||||||
// removed arbitrary positioning of flags.
|
|
||||||
command.append(cmd.usage());
|
|
||||||
|
|
||||||
return command.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the usage string for a nested command.
|
|
||||||
private String getNestedUsage(String[] args, int level, Method method, Player player) throws CommandException {
|
|
||||||
StringBuilder command = new StringBuilder();
|
|
||||||
|
|
||||||
command.append("/");
|
|
||||||
|
|
||||||
for (int i = 0; i <= level; i++)
|
|
||||||
command.append(args[i] + " ");
|
|
||||||
|
|
||||||
Map<CommandIdentifier, Method> map = commands.get(method);
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
command.append("<");
|
|
||||||
|
|
||||||
Set<String> allowedCommands = new HashSet<String>();
|
|
||||||
|
|
||||||
for (Map.Entry<CommandIdentifier, Method> entry : map.entrySet()) {
|
|
||||||
Method childMethod = entry.getValue();
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
if (hasPermission(childMethod, player)) {
|
|
||||||
Command childCmd = childMethod.getAnnotation(Command.class);
|
|
||||||
|
|
||||||
allowedCommands.add(childCmd.aliases()[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allowedCommands.size() > 0)
|
|
||||||
command.append(joinString(allowedCommands, "|", 0));
|
|
||||||
else {
|
|
||||||
if (!found)
|
|
||||||
command.append("?");
|
|
||||||
else
|
|
||||||
throw new NoPermissionsException();
|
|
||||||
}
|
|
||||||
|
|
||||||
command.append(">");
|
|
||||||
|
|
||||||
return command.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String joinString(Collection<?> str, String delimiter, int initialIndex) {
|
|
||||||
if (str.size() == 0)
|
|
||||||
return "";
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
|
||||||
int i = 0;
|
|
||||||
for (Object o : str) {
|
|
||||||
if (i >= initialIndex) {
|
|
||||||
if (i > 0)
|
|
||||||
buffer.append(delimiter);
|
|
||||||
buffer.append(o.toString());
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to execute a command. This version takes a separate command name
|
* Attempt to execute a command. This version takes a separate command name
|
||||||
* (for the root command) and then a list of following arguments.
|
* (for the root command) and then a list of following arguments.
|
||||||
@ -354,6 +155,79 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getAllCommandModifiers(String command) {
|
||||||
|
Set<String> cmds = new HashSet<String>();
|
||||||
|
for (Map<CommandIdentifier, Method> enclosing : commands.values()) {
|
||||||
|
for (CommandIdentifier identifier : enclosing.keySet()) {
|
||||||
|
if (identifier.getCommand().equals(command)) {
|
||||||
|
cmds.add(identifier.getModifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cmds.toArray(new String[cmds.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of command descriptions. This is only for root commands.
|
||||||
|
public Map<CommandIdentifier, String> getCommands() {
|
||||||
|
return descs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the usage string for a nested command.
|
||||||
|
private String getNestedUsage(String[] args, int level, Method method, Player player) throws CommandException {
|
||||||
|
StringBuilder command = new StringBuilder();
|
||||||
|
|
||||||
|
command.append("/");
|
||||||
|
|
||||||
|
for (int i = 0; i <= level; i++)
|
||||||
|
command.append(args[i] + " ");
|
||||||
|
|
||||||
|
Map<CommandIdentifier, Method> map = commands.get(method);
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
command.append("<");
|
||||||
|
|
||||||
|
Set<String> allowedCommands = new HashSet<String>();
|
||||||
|
|
||||||
|
for (Map.Entry<CommandIdentifier, Method> entry : map.entrySet()) {
|
||||||
|
Method childMethod = entry.getValue();
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
if (hasPermission(childMethod, player)) {
|
||||||
|
Command childCmd = childMethod.getAnnotation(Command.class);
|
||||||
|
|
||||||
|
allowedCommands.add(childCmd.aliases()[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedCommands.size() > 0)
|
||||||
|
command.append(joinString(allowedCommands, "|", 0));
|
||||||
|
else {
|
||||||
|
if (!found)
|
||||||
|
command.append("?");
|
||||||
|
else
|
||||||
|
throw new NoPermissionsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
command.append(">");
|
||||||
|
|
||||||
|
return command.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the usage string for a command.
|
||||||
|
private String getUsage(String[] args, int level, Command cmd) {
|
||||||
|
StringBuilder command = new StringBuilder();
|
||||||
|
|
||||||
|
command.append("/");
|
||||||
|
|
||||||
|
for (int i = 0; i <= level; i++)
|
||||||
|
command.append(args[i] + " ");
|
||||||
|
|
||||||
|
// removed arbitrary positioning of flags.
|
||||||
|
command.append(cmd.usage());
|
||||||
|
|
||||||
|
return command.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// Returns whether a player has access to a command.
|
// Returns whether a player has access to a command.
|
||||||
private boolean hasPermission(Method method, Player player) {
|
private boolean hasPermission(Method method, Player player) {
|
||||||
Permission permission = method.getAnnotation(Permission.class);
|
Permission permission = method.getAnnotation(Permission.class);
|
||||||
@ -371,19 +245,151 @@ public class CommandManager {
|
|||||||
return player.hasPermission("citizens." + perm);
|
return player.hasPermission("citizens." + perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getAllCommandModifiers(String command) {
|
|
||||||
Set<String> cmds = new HashSet<String>();
|
|
||||||
for (Map<CommandIdentifier, Method> enclosing : commands.values()) {
|
|
||||||
for (CommandIdentifier identifier : enclosing.keySet()) {
|
|
||||||
if (identifier.getCommand().equals(command)) {
|
|
||||||
cmds.add(identifier.getModifier());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmds.toArray(new String[cmds.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInjector(Injector injector) {
|
public void setInjector(Injector injector) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger for general errors.
|
||||||
|
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mapping of commands (including aliases) with a description. Root commands
|
||||||
|
* are stored under a key of null, whereas child commands are cached under
|
||||||
|
* their respective Method. The child map has the key of the command name
|
||||||
|
* (one for each alias) with the method.
|
||||||
|
*/
|
||||||
|
private final Map<Method, Map<CommandIdentifier, Method>> commands = new HashMap<Method, Map<CommandIdentifier, Method>>();
|
||||||
|
|
||||||
|
// Used to store the instances associated with a method.
|
||||||
|
private final Map<Method, Object> instances = new HashMap<Method, Object>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mapping of commands (not including aliases) with a description. This is
|
||||||
|
* only for top level commands.
|
||||||
|
*/
|
||||||
|
private final Map<CommandIdentifier, String> descs = new HashMap<CommandIdentifier, String>();
|
||||||
|
|
||||||
|
// Stores the injector used to getInstance.
|
||||||
|
private Injector injector;
|
||||||
|
|
||||||
|
private final Map<Method, Requirements> requirements = new HashMap<Method, Requirements>();
|
||||||
|
|
||||||
|
private final Map<Method, ServerCommand> serverCommands = new HashMap<Method, ServerCommand>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks to see whether there is a command named such at the root level.
|
||||||
|
* This will check aliases as well.
|
||||||
|
*/
|
||||||
|
public boolean hasCommand(String command, String modifier) {
|
||||||
|
return commands.get(null).containsKey(new CommandIdentifier(command.toLowerCase(), modifier.toLowerCase()))
|
||||||
|
|| commands.get(null).containsKey(new CommandIdentifier(command.toLowerCase(), "*"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register an class that contains commands (denoted by Command. If no
|
||||||
|
* dependency injector is specified, then the methods of the class will be
|
||||||
|
* registered to be called statically. Otherwise, new instances will be
|
||||||
|
* created of the command classes and methods will not be called statically.
|
||||||
|
*/
|
||||||
|
public void register(Class<?> clazz) {
|
||||||
|
registerMethods(clazz, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register the methods of a class. This will automatically construct
|
||||||
|
* instances as necessary.
|
||||||
|
*/
|
||||||
|
private void registerMethods(Class<?> clazz, Method parent) {
|
||||||
|
Object obj = injector.getInstance(clazz);
|
||||||
|
registerMethods(clazz, parent, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the methods of a class.
|
||||||
|
private void registerMethods(Class<?> clazz, Method parent, Object obj) {
|
||||||
|
Map<CommandIdentifier, Method> map;
|
||||||
|
|
||||||
|
// Make a new hash map to cache the commands for this class
|
||||||
|
// as looking up methods via reflection is fairly slow
|
||||||
|
if (commands.containsKey(parent))
|
||||||
|
map = commands.get(parent);
|
||||||
|
else {
|
||||||
|
map = new HashMap<CommandIdentifier, Method>();
|
||||||
|
commands.put(parent, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Method method : clazz.getMethods()) {
|
||||||
|
if (!method.isAnnotationPresent(Command.class))
|
||||||
|
continue;
|
||||||
|
boolean isStatic = Modifier.isStatic(method.getModifiers());
|
||||||
|
|
||||||
|
Command cmd = method.getAnnotation(Command.class);
|
||||||
|
String[] modifiers = cmd.modifiers();
|
||||||
|
|
||||||
|
// Cache the aliases too
|
||||||
|
for (String alias : cmd.aliases())
|
||||||
|
for (String modifier : modifiers)
|
||||||
|
map.put(new CommandIdentifier(alias, modifier), method);
|
||||||
|
|
||||||
|
Requirements cmdRequirements = null;
|
||||||
|
if (method.getDeclaringClass().isAnnotationPresent(Requirements.class))
|
||||||
|
cmdRequirements = method.getDeclaringClass().getAnnotation(Requirements.class);
|
||||||
|
|
||||||
|
if (method.isAnnotationPresent(Requirements.class))
|
||||||
|
cmdRequirements = method.getAnnotation(Requirements.class);
|
||||||
|
|
||||||
|
if (requirements != null)
|
||||||
|
requirements.put(method, cmdRequirements);
|
||||||
|
|
||||||
|
ServerCommand serverCommand = null;
|
||||||
|
if (method.isAnnotationPresent(ServerCommand.class))
|
||||||
|
serverCommand = method.getAnnotation(ServerCommand.class);
|
||||||
|
|
||||||
|
if (serverCommand != null)
|
||||||
|
serverCommands.put(method, serverCommand);
|
||||||
|
|
||||||
|
// We want to be able invoke with an instance
|
||||||
|
if (!isStatic) {
|
||||||
|
// Can't register this command if we don't have an instance
|
||||||
|
if (obj == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
instances.put(method, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a list of commands and their usage details, at least for
|
||||||
|
// root level commands
|
||||||
|
if (parent == null)
|
||||||
|
if (cmd.usage().length() == 0)
|
||||||
|
descs.put(new CommandIdentifier(cmd.aliases()[0], cmd.modifiers()[0]), cmd.desc());
|
||||||
|
else
|
||||||
|
descs.put(new CommandIdentifier(cmd.aliases()[0], cmd.modifiers()[0]),
|
||||||
|
cmd.usage() + " - " + cmd.desc());
|
||||||
|
|
||||||
|
// Look for nested commands -- if there are any, those have
|
||||||
|
// to be cached too so that they can be quickly looked
|
||||||
|
// up when processing commands
|
||||||
|
if (method.isAnnotationPresent(NestedCommand.class)) {
|
||||||
|
NestedCommand nestedCmd = method.getAnnotation(NestedCommand.class);
|
||||||
|
|
||||||
|
for (Class<?> nestedCls : nestedCmd.value())
|
||||||
|
registerMethods(nestedCls, method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String joinString(Collection<?> str, String delimiter, int initialIndex) {
|
||||||
|
if (str.size() == 0)
|
||||||
|
return "";
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
int i = 0;
|
||||||
|
for (Object o : str) {
|
||||||
|
if (i >= initialIndex) {
|
||||||
|
if (i > 0)
|
||||||
|
buffer.append(delimiter);
|
||||||
|
buffer.append(o.toString());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
}
|
}
|
@ -26,15 +26,15 @@ public @interface Command {
|
|||||||
|
|
||||||
String[] aliases();
|
String[] aliases();
|
||||||
|
|
||||||
String usage() default "";
|
|
||||||
|
|
||||||
String desc();
|
String desc();
|
||||||
|
|
||||||
String[] modifiers() default "";
|
String flags() default "";
|
||||||
|
|
||||||
int min() default 0;
|
|
||||||
|
|
||||||
int max() default -1;
|
int max() default -1;
|
||||||
|
|
||||||
String flags() default "";
|
int min() default 0;
|
||||||
|
|
||||||
|
String[] modifiers() default "";
|
||||||
|
|
||||||
|
String usage() default "";
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Requirements {
|
public @interface Requirements {
|
||||||
|
|
||||||
boolean selected() default false;
|
|
||||||
|
|
||||||
boolean ownership() default false;
|
boolean ownership() default false;
|
||||||
|
|
||||||
|
boolean selected() default false;
|
||||||
}
|
}
|
@ -32,13 +32,8 @@ public class NPCCommands {
|
|||||||
this.characterManager = characterManager;
|
this.characterManager = characterManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "create [name] [type] (character)", desc = "Create a new NPC",
|
||||||
aliases = { "npc" },
|
modifiers = { "create" }, min = 3, max = 4)
|
||||||
usage = "create [name] [type] (character)",
|
|
||||||
desc = "Create a new NPC",
|
|
||||||
modifiers = { "create" },
|
|
||||||
min = 3,
|
|
||||||
max = 4)
|
|
||||||
@Permission("npc.create")
|
@Permission("npc.create")
|
||||||
@Requirements
|
@Requirements
|
||||||
public void createNPC(CommandContext args, Player player, NPC npc) {
|
public void createNPC(CommandContext args, Player player, NPC npc) {
|
||||||
@ -49,7 +44,7 @@ public class NPCCommands {
|
|||||||
Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC.");
|
Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CitizensNPC create = (CitizensNPC) npcManager.createNPC(type, args.getString(1));
|
NPC create = npcManager.createNPC(type, args.getString(1));
|
||||||
String successMsg = ChatColor.GREEN + "You created " + StringHelper.wrap(create.getName());
|
String successMsg = ChatColor.GREEN + "You created " + StringHelper.wrap(create.getName());
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
if (args.argsLength() == 4) {
|
if (args.argsLength() == 4) {
|
||||||
@ -77,13 +72,8 @@ public class NPCCommands {
|
|||||||
Messaging.send(player, successMsg);
|
Messaging.send(player, successMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1,
|
||||||
aliases = { "npc" },
|
max = 1)
|
||||||
usage = "despawn",
|
|
||||||
desc = "Despawn an NPC",
|
|
||||||
modifiers = { "despawn" },
|
|
||||||
min = 1,
|
|
||||||
max = 1)
|
|
||||||
@Permission("npc.despawn")
|
@Permission("npc.despawn")
|
||||||
public void despawnNPC(CommandContext args, Player player, NPC npc) {
|
public void despawnNPC(CommandContext args, Player player, NPC npc) {
|
||||||
npc.getTrait(Spawned.class).setSpawned(false);
|
npc.getTrait(Spawned.class).setSpawned(false);
|
||||||
@ -91,13 +81,26 @@ public class NPCCommands {
|
|||||||
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "select [id]", desc = "Select an NPC", modifiers = { "select" }, min = 2,
|
||||||
aliases = { "npc" },
|
max = 2)
|
||||||
usage = "spawn [id]",
|
@Permission("npc.select")
|
||||||
desc = "Spawn an existing NPC",
|
@Requirements(ownership = true)
|
||||||
modifiers = { "spawn" },
|
public void selectNPC(CommandContext args, Player player, NPC npc) {
|
||||||
min = 2,
|
NPC toSelect = npcManager.getNPC(args.getInteger(1));
|
||||||
max = 2)
|
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) {
|
||||||
|
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (npc != null && toSelect.getId() == npc.getId()) {
|
||||||
|
Messaging.sendError(player, "You already have that NPC selected.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
npcManager.selectNPC(player, toSelect);
|
||||||
|
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" },
|
||||||
|
min = 2, max = 2)
|
||||||
@Permission("npc.spawn")
|
@Permission("npc.spawn")
|
||||||
@Requirements
|
@Requirements
|
||||||
public void spawnNPC(CommandContext args, Player player, NPC npc) {
|
public void spawnNPC(CommandContext args, Player player, NPC npc) {
|
||||||
@ -124,62 +127,24 @@ public class NPCCommands {
|
|||||||
+ " is already spawned at another location. Use '/npc tphere' to teleport the NPC to your location.");
|
+ " is already spawned at another location. Use '/npc tphere' to teleport the NPC to your location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport an NPC to your location",
|
||||||
aliases = { "npc" },
|
modifiers = { "tphere" }, min = 1, max = 1)
|
||||||
usage = "select [id]",
|
|
||||||
desc = "Select an NPC",
|
|
||||||
modifiers = { "select" },
|
|
||||||
min = 2,
|
|
||||||
max = 2)
|
|
||||||
@Permission("npc.select")
|
|
||||||
@Requirements(ownership = true)
|
|
||||||
public void selectNPC(CommandContext args, Player player, NPC npc) {
|
|
||||||
NPC toSelect = npcManager.getNPC(args.getInteger(1));
|
|
||||||
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn()) {
|
|
||||||
Messaging.sendError(player, "No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (npc != null && toSelect.getId() == npc.getId()) {
|
|
||||||
Messaging.sendError(player, "You already have that NPC selected.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
npcManager.selectNPC(player, toSelect);
|
|
||||||
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(
|
|
||||||
aliases = { "npc" },
|
|
||||||
usage = "tphere",
|
|
||||||
desc = "Teleport an NPC to your location",
|
|
||||||
modifiers = { "tphere" },
|
|
||||||
min = 1,
|
|
||||||
max = 1)
|
|
||||||
@Permission("npc.tphere")
|
@Permission("npc.tphere")
|
||||||
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
|
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
|
||||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "tp", desc = "Teleport to an NPC", modifiers = { "tp", "teleport" }, min = 1,
|
||||||
aliases = { "npc" },
|
max = 1)
|
||||||
usage = "tp",
|
|
||||||
desc = "Teleport to an NPC",
|
|
||||||
modifiers = { "tp", "teleport" },
|
|
||||||
min = 1,
|
|
||||||
max = 1)
|
|
||||||
@Permission("npc.tp")
|
@Permission("npc.tp")
|
||||||
public void teleportToNPC(CommandContext args, Player player, NPC npc) {
|
public void teleportToNPC(CommandContext args, Player player, NPC npc) {
|
||||||
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
||||||
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = {
|
||||||
aliases = { "npc" },
|
"lookclose", "look", "rotate" }, min = 1, max = 1)
|
||||||
usage = "lookclose",
|
|
||||||
desc = "Toggle an NPC's look-close state",
|
|
||||||
modifiers = { "lookclose", "look", "rotate" },
|
|
||||||
min = 1,
|
|
||||||
max = 1)
|
|
||||||
@Permission("npc.look-close")
|
@Permission("npc.look-close")
|
||||||
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
|
public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
|
||||||
npc.getTrait(LookClose.class).setLookClose(!npc.getTrait(LookClose.class).shouldLookClose());
|
npc.getTrait(LookClose.class).setLookClose(!npc.getTrait(LookClose.class).shouldLookClose());
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
package net.citizensnpcs.command.exception;
|
package net.citizensnpcs.command.exception;
|
||||||
|
|
||||||
public class CommandException extends Exception {
|
public class CommandException extends Exception {
|
||||||
private static final long serialVersionUID = 870638193072101739L;
|
|
||||||
|
|
||||||
public CommandException() {
|
public CommandException() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -33,4 +31,6 @@ public class CommandException extends Exception {
|
|||||||
public CommandException(Throwable t) {
|
public CommandException(Throwable t) {
|
||||||
super(t);
|
super(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 870638193072101739L;
|
||||||
}
|
}
|
@ -20,9 +20,9 @@
|
|||||||
package net.citizensnpcs.command.exception;
|
package net.citizensnpcs.command.exception;
|
||||||
|
|
||||||
public class MissingNestedCommandException extends CommandUsageException {
|
public class MissingNestedCommandException extends CommandUsageException {
|
||||||
private static final long serialVersionUID = -4382896182979285355L;
|
|
||||||
|
|
||||||
public MissingNestedCommandException(String message, String usage) {
|
public MissingNestedCommandException(String message, String usage) {
|
||||||
super(message, usage);
|
super(message, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4382896182979285355L;
|
||||||
}
|
}
|
@ -2,9 +2,9 @@ package net.citizensnpcs.command.exception;
|
|||||||
|
|
||||||
public class RequirementMissingException extends CommandException {
|
public class RequirementMissingException extends CommandException {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4299721983654504028L;
|
|
||||||
|
|
||||||
public RequirementMissingException(String message) {
|
public RequirementMissingException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4299721983654504028L;
|
||||||
}
|
}
|
@ -20,9 +20,9 @@
|
|||||||
package net.citizensnpcs.command.exception;
|
package net.citizensnpcs.command.exception;
|
||||||
|
|
||||||
public class WrappedCommandException extends CommandException {
|
public class WrappedCommandException extends CommandException {
|
||||||
private static final long serialVersionUID = -4075721444847778918L;
|
|
||||||
|
|
||||||
public WrappedCommandException(Throwable t) {
|
public WrappedCommandException(Throwable t) {
|
||||||
super(t);
|
super(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4075721444847778918L;
|
||||||
}
|
}
|
@ -1,8 +1,5 @@
|
|||||||
package net.citizensnpcs.npc;
|
package net.citizensnpcs.npc;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||||
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
||||||
import net.citizensnpcs.api.npc.AbstractNPC;
|
import net.citizensnpcs.api.npc.AbstractNPC;
|
||||||
@ -12,39 +9,23 @@ import net.citizensnpcs.api.npc.trait.trait.Spawned;
|
|||||||
import net.citizensnpcs.npc.ai.CitizensNavigator;
|
import net.citizensnpcs.npc.ai.CitizensNavigator;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.minecraft.server.EntityLiving;
|
|
||||||
import net.minecraft.server.EntityTypes;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.WorldServer;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
public class CitizensNPC extends AbstractNPC {
|
public abstract class CitizensNPC extends AbstractNPC {
|
||||||
protected EntityLiving mcEntity;
|
private static final double lookRange = 5;
|
||||||
protected final CitizensNPCManager manager;
|
protected final CitizensNPCManager manager;
|
||||||
|
protected net.minecraft.server.Entity mcEntity;
|
||||||
|
|
||||||
private Map<Integer, Class<? extends net.minecraft.server.Entity>> intToClass;
|
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
private Map<Class<? extends net.minecraft.server.Entity>, Integer> classToInt;
|
|
||||||
private Class<? extends EntityLiving> entityClass;
|
|
||||||
private double lookRange = 5;
|
|
||||||
|
|
||||||
protected CitizensNPC(CitizensNPCManager manager, int id, String name, Class<? extends EntityLiving> entityClass) {
|
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
if (intToClass == null || classToInt == null)
|
|
||||||
createMaps();
|
|
||||||
this.entityClass = entityClass;
|
|
||||||
// No need to register entity class for normal human NPC entity
|
|
||||||
if (entityClass != null)
|
|
||||||
registerEntityClass(entityClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract net.minecraft.server.Entity createHandle(Location loc);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean despawn() {
|
public boolean despawn() {
|
||||||
if (!isSpawned()) {
|
if (!isSpawned()) {
|
||||||
@ -60,12 +41,35 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: is this necessary? it's a helper method...
|
||||||
|
protected void faceEntity(Location target) {
|
||||||
|
if (getBukkitEntity().getWorld() != target.getWorld())
|
||||||
|
return;
|
||||||
|
Location loc = getBukkitEntity().getLocation();
|
||||||
|
|
||||||
|
double xDiff = target.getX() - loc.getX();
|
||||||
|
double yDiff = target.getY() - loc.getY();
|
||||||
|
double zDiff = target.getZ() - loc.getZ();
|
||||||
|
|
||||||
|
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
||||||
|
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
|
||||||
|
|
||||||
|
double yaw = (Math.acos(xDiff / distanceXZ) * 180 / Math.PI);
|
||||||
|
double pitch = (Math.acos(yDiff / distanceY) * 180 / Math.PI) - 90;
|
||||||
|
if (zDiff < 0.0) {
|
||||||
|
yaw = yaw + (Math.abs(180 - yaw) * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
mcEntity.yaw = (float) yaw - 90;
|
||||||
|
mcEntity.pitch = (float) pitch;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity getBukkitEntity() {
|
public Entity getBukkitEntity() {
|
||||||
return getHandle().getBukkitEntity();
|
return getHandle().getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityLiving getHandle() {
|
public net.minecraft.server.Entity getHandle() {
|
||||||
return mcEntity;
|
return mcEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +102,8 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
if (spawnEvent.isCancelled())
|
if (spawnEvent.isCancelled())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (entityClass != null) {
|
mcEntity = createHandle(loc);
|
||||||
mcEntity = createEntityFromClass(getWorldServer(loc.getWorld()));
|
mcEntity.world.addEntity(mcEntity);
|
||||||
mcEntity.setPosition(loc.getX(), loc.getY(), loc.getZ());
|
|
||||||
mcEntity.world.addEntity(mcEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the location
|
// Set the location
|
||||||
addTrait(new SpawnLocation(loc));
|
addTrait(new SpawnLocation(loc));
|
||||||
@ -111,79 +112,13 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WorldServer getWorldServer(World world) {
|
|
||||||
return ((CraftWorld) world).getHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MinecraftServer getMinecraftServer(Server server) {
|
|
||||||
return ((CraftServer) server).getServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (mcEntity != null)
|
// TODO: this needs to be less hard-coded... does everyone want this
|
||||||
|
// behaviour?
|
||||||
|
if (mcEntity != null) {
|
||||||
if (getTrait(LookClose.class).shouldLookClose()
|
if (getTrait(LookClose.class).shouldLookClose()
|
||||||
&& mcEntity.world.findNearbyPlayer(mcEntity, lookRange) != null)
|
&& mcEntity.world.findNearbyPlayer(mcEntity, lookRange) != null)
|
||||||
faceEntity(mcEntity.world.findNearbyPlayer(mcEntity, lookRange).getBukkitEntity());
|
faceEntity(mcEntity.world.findNearbyPlayer(mcEntity, lookRange).getBukkitEntity().getLocation());
|
||||||
}
|
|
||||||
|
|
||||||
protected void faceEntity(Entity target) {
|
|
||||||
if (getBukkitEntity().getWorld() != target.getWorld())
|
|
||||||
return;
|
|
||||||
Location loc = getBukkitEntity().getLocation();
|
|
||||||
Location targetLoc = target.getLocation();
|
|
||||||
|
|
||||||
double xDiff = targetLoc.getX() - loc.getX();
|
|
||||||
double yDiff = targetLoc.getY() - loc.getY();
|
|
||||||
double zDiff = targetLoc.getZ() - loc.getZ();
|
|
||||||
|
|
||||||
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
|
||||||
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
|
|
||||||
|
|
||||||
double yaw = (Math.acos(xDiff / distanceXZ) * 180 / Math.PI);
|
|
||||||
double pitch = (Math.acos(yDiff / distanceY) * 180 / Math.PI) - 90;
|
|
||||||
if (zDiff < 0.0) {
|
|
||||||
yaw = yaw + (Math.abs(180 - yaw) * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
mcEntity.yaw = (float) yaw - 90;
|
|
||||||
mcEntity.pitch = (float) pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerEntityClass(Class<? extends net.minecraft.server.Entity> clazz) {
|
|
||||||
if (classToInt == null || intToClass == null)
|
|
||||||
return;
|
|
||||||
Class<?> search = clazz;
|
|
||||||
while ((search = search.getSuperclass()) != null && net.minecraft.server.Entity.class.isAssignableFrom(search)) {
|
|
||||||
if (!classToInt.containsKey(search))
|
|
||||||
continue;
|
|
||||||
int code = classToInt.get(search);
|
|
||||||
intToClass.put(code, clazz);
|
|
||||||
classToInt.put(clazz, code);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("unable to find valid entity superclass");
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void createMaps() {
|
|
||||||
try {
|
|
||||||
Field field = EntityTypes.class.getDeclaredField("d");
|
|
||||||
field.setAccessible(true);
|
|
||||||
intToClass = (Map<Integer, Class<? extends net.minecraft.server.Entity>>) field.get(null);
|
|
||||||
field = EntityTypes.class.getDeclaredField("e");
|
|
||||||
field.setAccessible(true);
|
|
||||||
classToInt = (Map<Class<? extends net.minecraft.server.Entity>, Integer>) field.get(null);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityLiving createEntityFromClass(net.minecraft.server.World world) {
|
|
||||||
try {
|
|
||||||
return entityClass.getConstructor(net.minecraft.server.World.class).newInstance(world);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,6 @@ import net.citizensnpcs.api.npc.NPC;
|
|||||||
import net.citizensnpcs.api.npc.NPCManager;
|
import net.citizensnpcs.api.npc.NPCManager;
|
||||||
import net.citizensnpcs.api.npc.trait.Character;
|
import net.citizensnpcs.api.npc.trait.Character;
|
||||||
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
|
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
|
||||||
|
|
||||||
import net.citizensnpcs.storage.Storage;
|
import net.citizensnpcs.storage.Storage;
|
||||||
import net.citizensnpcs.util.ByIdArray;
|
import net.citizensnpcs.util.ByIdArray;
|
||||||
import net.citizensnpcs.util.NPCBuilder;
|
import net.citizensnpcs.util.NPCBuilder;
|
||||||
@ -31,16 +30,6 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
this.saves = saves;
|
this.saves = saves;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NPC createNPC(CreatureType type, String name) {
|
|
||||||
return createNPC(type, name, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NPC createNPC(CreatureType type, String name, Character character) {
|
|
||||||
return createNPC(type, generateUniqueId(), name, character);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NPC createNPC(CreatureType type, int id, String name, Character character) {
|
public NPC createNPC(CreatureType type, int id, String name, Character character) {
|
||||||
if (npcs.contains(id))
|
if (npcs.contains(id))
|
||||||
throw new IllegalArgumentException("An NPC already has the ID '" + id + "'.");
|
throw new IllegalArgumentException("An NPC already has the ID '" + id + "'.");
|
||||||
@ -51,15 +40,27 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return npc;
|
return npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC createNPC(CreatureType type, String name) {
|
||||||
|
return createNPC(type, name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC createNPC(CreatureType type, String name, Character character) {
|
||||||
|
return createNPC(type, generateUniqueId(), name, character);
|
||||||
|
}
|
||||||
|
|
||||||
public void despawn(NPC npc) {
|
public void despawn(NPC npc) {
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
||||||
selected.removeAll(npc.getId());
|
selected.removeAll(npc.getId());
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int generateUniqueId() {
|
||||||
public Iterator<NPC> iterator() {
|
int count = 0;
|
||||||
return npcs.iterator();
|
while (getNPC(count++) != null)
|
||||||
|
;
|
||||||
|
return count - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,11 +85,12 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return npcs;
|
return npcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int generateUniqueId() {
|
public NPC getSelectedNPC(Player player) {
|
||||||
int count = 0;
|
for (int id : selected.keySet()) {
|
||||||
while (getNPC(count++) != null)
|
if (selected.get(id).contains(player.getName()))
|
||||||
;
|
return getNPC(id);
|
||||||
return count - 1;
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,6 +98,17 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return getNPC(entity) != null;
|
return getNPC(entity) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<NPC> iterator() {
|
||||||
|
return npcs.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean npcIsSelectedByPlayer(Player player, NPC npc) {
|
||||||
|
if (!selected.containsKey(npc.getId()))
|
||||||
|
return false;
|
||||||
|
return selected.get(npc.getId()).contains(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
public void remove(NPC npc) {
|
public void remove(NPC npc) {
|
||||||
if (npc.isSpawned())
|
if (npc.isSpawned())
|
||||||
despawn(npc);
|
despawn(npc);
|
||||||
@ -111,18 +124,4 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
selected.get(existing.getId()).remove(player.getName());
|
selected.get(existing.getId()).remove(player.getName());
|
||||||
selected.put(npc.getId(), player.getName());
|
selected.put(npc.getId(), player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean npcIsSelectedByPlayer(Player player, NPC npc) {
|
|
||||||
if (!selected.containsKey(npc.getId()))
|
|
||||||
return false;
|
|
||||||
return selected.get(npc.getId()).contains(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NPC getSelectedNPC(Player player) {
|
|
||||||
for (int id : selected.keySet()) {
|
|
||||||
if (selected.get(id).contains(player.getName()))
|
|
||||||
return getNPC(id);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,24 +5,33 @@ import net.citizensnpcs.api.npc.ai.NavigatorCallback;
|
|||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
public class CitizensNavigator implements Navigator {
|
public class CitizensNavigator implements Navigator {
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
|
private PathStrategy executing;
|
||||||
|
|
||||||
public CitizensNavigator(CitizensNPC npc) {
|
public CitizensNavigator(CitizensNPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDestination(Location destination) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCallback(NavigatorCallback callback) {
|
public void registerCallback(NavigatorCallback callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
if (executing != null) {
|
||||||
|
executing.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTarget(Entity target, boolean aggressive) {
|
public void setDestination(Location destination) {
|
||||||
|
executing = new MoveStrategy(npc, destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTarget(LivingEntity target, boolean aggressive) {
|
||||||
|
executing = new TargetStrategy(npc, target, aggressive);
|
||||||
}
|
}
|
||||||
}
|
}
|
86
src/net/citizensnpcs/npc/ai/MoveStrategy.java
Normal file
86
src/net/citizensnpcs/npc/ai/MoveStrategy.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package net.citizensnpcs.npc.ai;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.minecraft.server.EntityLiving;
|
||||||
|
import net.minecraft.server.MathHelper;
|
||||||
|
import net.minecraft.server.PathEntity;
|
||||||
|
import net.minecraft.server.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class MoveStrategy implements PathStrategy {
|
||||||
|
private final EntityLiving handle;
|
||||||
|
private final PathEntity path;
|
||||||
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
public MoveStrategy(CitizensNPC handle, Location destination) {
|
||||||
|
this.handle = (EntityLiving) handle.getHandle();
|
||||||
|
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
|
||||||
|
destination.getBlockZ(), 16F);
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveStrategy(EntityLiving handle, PathEntity path) {
|
||||||
|
this.handle = handle;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vec3D getVector() {
|
||||||
|
Vec3D vec3d = path.a(handle);
|
||||||
|
double lengthSq = (handle.width * 2.0F);
|
||||||
|
lengthSq *= lengthSq;
|
||||||
|
while (vec3d != null && vec3d.d(handle.locX, vec3d.b, handle.locZ) < lengthSq) {
|
||||||
|
this.path.a(); // Increment path index.
|
||||||
|
if (this.path.b()) { // finished.
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
vec3d = this.path.a(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vec3d;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update() {
|
||||||
|
if (handle.dead)
|
||||||
|
return true;
|
||||||
|
Vec3D vector = getVector();
|
||||||
|
if (vector == null)
|
||||||
|
return true;
|
||||||
|
int yHeight = MathHelper.floor(handle.boundingBox.b + 0.5D);
|
||||||
|
boolean inWater = ((Player) handle.getBukkitEntity()).getRemainingAir() < 20;
|
||||||
|
boolean onFire = handle.fireTicks > 0;
|
||||||
|
double diffX = vector.a - handle.locX;
|
||||||
|
double diffZ = vector.c - handle.locZ;
|
||||||
|
|
||||||
|
handle.yaw += getYawDifference(diffZ, diffX);
|
||||||
|
if (vector.b - yHeight > 0.0D) {
|
||||||
|
jump();
|
||||||
|
}
|
||||||
|
handle.d();
|
||||||
|
// handle.walk();
|
||||||
|
|
||||||
|
if (handle.positionChanged) {
|
||||||
|
jump();
|
||||||
|
}
|
||||||
|
if (random.nextFloat() < 0.8F && (inWater || onFire)) {
|
||||||
|
handle.motY += 0.04D;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getYawDifference(double diffZ, double diffX) {
|
||||||
|
float vectorYaw = (float) (Math.atan2(diffZ, diffX) * 180.0D / Math.PI) - 90.0F;
|
||||||
|
float diffYaw = (vectorYaw - handle.yaw) % 360;
|
||||||
|
return Math.max(-30F, Math.min(30, diffYaw));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void jump() {
|
||||||
|
if (handle.onGround)
|
||||||
|
handle.motY = JUMP_VELOCITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final double JUMP_VELOCITY = 0.49D;
|
||||||
|
}
|
5
src/net/citizensnpcs/npc/ai/PathStrategy.java
Normal file
5
src/net/citizensnpcs/npc/ai/PathStrategy.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package net.citizensnpcs.npc.ai;
|
||||||
|
|
||||||
|
public interface PathStrategy {
|
||||||
|
boolean update();
|
||||||
|
}
|
39
src/net/citizensnpcs/npc/ai/TargetStrategy.java
Normal file
39
src/net/citizensnpcs/npc/ai/TargetStrategy.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package net.citizensnpcs.npc.ai;
|
||||||
|
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.minecraft.server.EntityHuman;
|
||||||
|
import net.minecraft.server.EntityLiving;
|
||||||
|
import net.minecraft.server.EntityMonster;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
|
public class TargetStrategy implements PathStrategy {
|
||||||
|
private final EntityLiving handle, target;
|
||||||
|
private final boolean aggro;
|
||||||
|
private PathStrategy current = null;
|
||||||
|
|
||||||
|
public TargetStrategy(CitizensNPC handle, LivingEntity target, boolean aggro) {
|
||||||
|
this.handle = (EntityLiving) handle.getHandle();
|
||||||
|
this.target = ((CraftLivingEntity) target).getHandle();
|
||||||
|
this.aggro = aggro;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update() {
|
||||||
|
if (target == null || target.dead)
|
||||||
|
return true;
|
||||||
|
current = new MoveStrategy(handle, handle.world.findPath(handle, target, 16F));
|
||||||
|
// NPCManager.faceEntity(handle.getBukkitEntity(),
|
||||||
|
// target.getBukkitEntity());
|
||||||
|
if (aggro) {
|
||||||
|
if (handle instanceof EntityMonster) {
|
||||||
|
((EntityMonster) handle).d(target);
|
||||||
|
} else if (handle instanceof EntityHuman) {
|
||||||
|
((EntityHuman) handle).attack(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current.update();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityBlazeNPC;
|
import net.minecraft.server.EntityBlaze;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensBlazeNPC extends CitizensNPC {
|
import org.bukkit.entity.Blaze;
|
||||||
|
|
||||||
|
public class CitizensBlazeNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensBlazeNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensBlazeNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityBlazeNPC.class);
|
super(manager, id, name, EntityBlazeNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blaze getBukkitEntity() {
|
||||||
|
return (Blaze) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityBlazeNPC extends EntityBlaze {
|
||||||
|
|
||||||
|
public EntityBlazeNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityCaveSpiderNPC;
|
import net.minecraft.server.EntityCaveSpider;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensCaveSpiderNPC extends CitizensNPC {
|
import org.bukkit.entity.CaveSpider;
|
||||||
|
|
||||||
|
public class CitizensCaveSpiderNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensCaveSpiderNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensCaveSpiderNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityCaveSpiderNPC.class);
|
super(manager, id, name, EntityCaveSpiderNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CaveSpider getBukkitEntity() {
|
||||||
|
return (CaveSpider) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCaveSpiderNPC extends EntityCaveSpider {
|
||||||
|
|
||||||
|
public EntityCaveSpiderNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityChickenNPC;
|
import net.minecraft.server.EntityChicken;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensChickenNPC extends CitizensNPC {
|
import org.bukkit.entity.Chicken;
|
||||||
|
|
||||||
|
public class CitizensChickenNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensChickenNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensChickenNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityChickenNPC.class);
|
super(manager, id, name, EntityChickenNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chicken getBukkitEntity() {
|
||||||
|
return (Chicken) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityChickenNPC extends EntityChicken {
|
||||||
|
|
||||||
|
public EntityChickenNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityCowNPC;
|
import net.minecraft.server.EntityCow;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensCowNPC extends CitizensNPC {
|
import org.bukkit.entity.Cow;
|
||||||
|
|
||||||
|
public class CitizensCowNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensCowNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensCowNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityCowNPC.class);
|
super(manager, id, name, EntityCowNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cow getBukkitEntity() {
|
||||||
|
return (Cow) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCowNPC extends EntityCow {
|
||||||
|
|
||||||
|
public EntityCowNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityCreeperNPC;
|
import net.minecraft.server.EntityCreeper;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensCreeperNPC extends CitizensNPC {
|
import org.bukkit.entity.Creeper;
|
||||||
|
|
||||||
|
public class CitizensCreeperNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensCreeperNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensCreeperNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityCreeperNPC.class);
|
super(manager, id, name, EntityCreeperNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Creeper getBukkitEntity() {
|
||||||
|
return (Creeper) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCreeperNPC extends EntityCreeper {
|
||||||
|
|
||||||
|
public EntityCreeperNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityEnderDragonNPC;
|
import net.minecraft.server.EntityEnderDragon;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensEnderDragonNPC extends CitizensNPC {
|
import org.bukkit.entity.EnderDragon;
|
||||||
|
|
||||||
|
public class CitizensEnderDragonNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensEnderDragonNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensEnderDragonNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityEnderDragonNPC.class);
|
super(manager, id, name, EntityEnderDragonNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnderDragon getBukkitEntity() {
|
||||||
|
return (EnderDragon) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEnderDragonNPC extends EntityEnderDragon {
|
||||||
|
|
||||||
|
public EntityEnderDragonNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityEndermanNPC;
|
import net.minecraft.server.EntityEnderman;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensEndermanNPC extends CitizensNPC {
|
import org.bukkit.entity.Enderman;
|
||||||
|
|
||||||
|
public class CitizensEndermanNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensEndermanNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensEndermanNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityEndermanNPC.class);
|
super(manager, id, name, EntityEndermanNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enderman getBukkitEntity() {
|
||||||
|
return (Enderman) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEndermanNPC extends EntityEnderman {
|
||||||
|
|
||||||
|
public EntityEndermanNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityGhastNPC;
|
import net.minecraft.server.EntityGhast;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensGhastNPC extends CitizensNPC {
|
import org.bukkit.entity.Ghast;
|
||||||
|
|
||||||
|
public class CitizensGhastNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensGhastNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensGhastNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityGhastNPC.class);
|
super(manager, id, name, EntityGhastNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ghast getBukkitEntity() {
|
||||||
|
return (Ghast) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGhastNPC extends EntityGhast {
|
||||||
|
|
||||||
|
public EntityGhastNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityGiantNPC;
|
import net.minecraft.server.EntityGiantZombie;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensGiantNPC extends CitizensNPC {
|
import org.bukkit.entity.Giant;
|
||||||
|
|
||||||
|
public class CitizensGiantNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensGiantNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensGiantNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityGiantNPC.class);
|
super(manager, id, name, EntityGiantNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Giant getBukkitEntity() {
|
||||||
|
return (Giant) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGiantNPC extends EntityGiantZombie {
|
||||||
|
|
||||||
|
public EntityGiantNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,30 +3,38 @@ package net.citizensnpcs.npc.entity;
|
|||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityHumanNPC;
|
import net.citizensnpcs.resource.lib.entity.EntityHumanNPC;
|
||||||
|
import net.minecraft.server.EntityLiving;
|
||||||
import net.minecraft.server.ItemInWorldManager;
|
import net.minecraft.server.ItemInWorldManager;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.WorldServer;
|
import net.minecraft.server.WorldServer;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CitizensHumanNPC extends CitizensNPC {
|
public class CitizensHumanNPC extends CitizensNPC {
|
||||||
|
|
||||||
public CitizensHumanNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensHumanNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, null);
|
super(manager, id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean spawn(Location loc) {
|
public Player getBukkitEntity() {
|
||||||
if (super.spawn(loc)) {
|
return (Player) getHandle().getBukkitEntity();
|
||||||
WorldServer ws = getWorldServer(loc.getWorld());
|
}
|
||||||
mcEntity = new EntityHumanNPC(getMinecraftServer(ws.getServer()), ws, getFullName(),
|
|
||||||
new ItemInWorldManager(ws));
|
protected static MinecraftServer getMinecraftServer(Server server) {
|
||||||
((EntityHumanNPC) mcEntity).removeFromPlayerMap(getFullName());
|
return ((CraftServer) server).getServer();
|
||||||
mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
}
|
||||||
ws.addEntity(mcEntity);
|
|
||||||
ws.players.remove(mcEntity);
|
@Override
|
||||||
return true;
|
protected EntityLiving createHandle(Location loc) {
|
||||||
}
|
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
return false;
|
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, getFullName(),
|
||||||
|
new ItemInWorldManager(ws));
|
||||||
|
handle.removeFromPlayerMap(getFullName());
|
||||||
|
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityMagmaCubeNPC;
|
import net.minecraft.server.EntityMagmaCube;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensMagmaCubeNPC extends CitizensNPC {
|
import org.bukkit.entity.MagmaCube;
|
||||||
|
|
||||||
|
public class CitizensMagmaCubeNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensMagmaCubeNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensMagmaCubeNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityMagmaCubeNPC.class);
|
super(manager, id, name, EntityMagmaCubeNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MagmaCube getBukkitEntity() {
|
||||||
|
return (MagmaCube) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityMagmaCubeNPC extends EntityMagmaCube {
|
||||||
|
|
||||||
|
public EntityMagmaCubeNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
83
src/net/citizensnpcs/npc/entity/CitizensMobNPC.java
Normal file
83
src/net/citizensnpcs/npc/entity/CitizensMobNPC.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
|
import net.minecraft.server.Entity;
|
||||||
|
import net.minecraft.server.EntityLiving;
|
||||||
|
import net.minecraft.server.EntityTypes;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
|
public abstract class CitizensMobNPC extends CitizensNPC {
|
||||||
|
private final Constructor<? extends EntityLiving> constructor;
|
||||||
|
|
||||||
|
protected CitizensMobNPC(CitizensNPCManager manager, int id, String name, Class<? extends EntityLiving> clazz) {
|
||||||
|
super(manager, id, name);
|
||||||
|
try {
|
||||||
|
this.constructor = clazz.getConstructor(World.class);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new IllegalStateException("unable to find an entity constructor");
|
||||||
|
}
|
||||||
|
if (!classToInt.containsKey(clazz))
|
||||||
|
registerEntityClass(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityLiving createEntityFromClass(net.minecraft.server.World world) {
|
||||||
|
try {
|
||||||
|
return constructor.newInstance(world);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EntityLiving createHandle(Location loc) {
|
||||||
|
EntityLiving entity = createEntityFromClass(((CraftWorld) loc.getWorld()).getHandle());
|
||||||
|
mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LivingEntity getBukkitEntity() {
|
||||||
|
return (LivingEntity) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Class<? extends Entity>, Integer> classToInt;
|
||||||
|
private static Map<Integer, Class<? extends Entity>> intToClass;
|
||||||
|
|
||||||
|
private static void registerEntityClass(Class<? extends Entity> clazz) {
|
||||||
|
Class<?> search = clazz;
|
||||||
|
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
|
||||||
|
if (!classToInt.containsKey(search))
|
||||||
|
continue;
|
||||||
|
int code = classToInt.get(search);
|
||||||
|
intToClass.put(code, clazz);
|
||||||
|
classToInt.put(clazz, code);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("unable to find valid entity superclass");
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Field field = EntityTypes.class.getDeclaredField("d");
|
||||||
|
field.setAccessible(true);
|
||||||
|
intToClass = (Map<Integer, Class<? extends Entity>>) field.get(null);
|
||||||
|
field = EntityTypes.class.getDeclaredField("e");
|
||||||
|
field.setAccessible(true);
|
||||||
|
classToInt = (Map<Class<? extends Entity>, Integer>) field.get(null);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unable to fetch entity class mapping - is Citizens updated for this version of CraftBukkit?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityMushroomCowNPC;
|
import net.minecraft.server.EntityMushroomCow;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensMushroomCowNPC extends CitizensNPC {
|
import org.bukkit.entity.MushroomCow;
|
||||||
|
|
||||||
|
public class CitizensMushroomCowNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensMushroomCowNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensMushroomCowNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityMushroomCowNPC.class);
|
super(manager, id, name, EntityMushroomCowNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MushroomCow getBukkitEntity() {
|
||||||
|
return (MushroomCow) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityMushroomCowNPC extends EntityMushroomCow {
|
||||||
|
|
||||||
|
public EntityMushroomCowNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityPigNPC;
|
import net.minecraft.server.EntityPig;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensPigNPC extends CitizensNPC {
|
import org.bukkit.entity.Pig;
|
||||||
|
|
||||||
|
public class CitizensPigNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensPigNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensPigNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityPigNPC.class);
|
super(manager, id, name, EntityPigNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pig getBukkitEntity() {
|
||||||
|
return (Pig) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPigNPC extends EntityPig {
|
||||||
|
|
||||||
|
public EntityPigNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityPigZombieNPC;
|
import net.minecraft.server.EntityPigZombie;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensPigZombieNPC extends CitizensNPC {
|
import org.bukkit.entity.PigZombie;
|
||||||
|
|
||||||
|
public class CitizensPigZombieNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensPigZombieNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensPigZombieNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityPigZombieNPC.class);
|
super(manager, id, name, EntityPigZombieNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PigZombie getBukkitEntity() {
|
||||||
|
return (PigZombie) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPigZombieNPC extends EntityPigZombie {
|
||||||
|
|
||||||
|
public EntityPigZombieNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySheepNPC;
|
import net.minecraft.server.EntitySheep;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSheepNPC extends CitizensNPC {
|
import org.bukkit.entity.Sheep;
|
||||||
|
|
||||||
|
public class CitizensSheepNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSheepNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSheepNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySheepNPC.class);
|
super(manager, id, name, EntitySheepNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sheep getBukkitEntity() {
|
||||||
|
return (Sheep) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySheepNPC extends EntitySheep {
|
||||||
|
|
||||||
|
public EntitySheepNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySilverfishNPC;
|
import net.minecraft.server.EntitySilverfish;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSilverfishNPC extends CitizensNPC {
|
import org.bukkit.entity.Silverfish;
|
||||||
|
|
||||||
|
public class CitizensSilverfishNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSilverfishNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSilverfishNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySilverfishNPC.class);
|
super(manager, id, name, EntitySilverfishNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Silverfish getBukkitEntity() {
|
||||||
|
return (Silverfish) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySilverfishNPC extends EntitySilverfish {
|
||||||
|
|
||||||
|
public EntitySilverfishNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySkeletonNPC;
|
import net.minecraft.server.EntitySkeleton;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSkeletonNPC extends CitizensNPC {
|
import org.bukkit.entity.Skeleton;
|
||||||
|
|
||||||
|
public class CitizensSkeletonNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSkeletonNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSkeletonNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySkeletonNPC.class);
|
super(manager, id, name, EntitySkeletonNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Skeleton getBukkitEntity() {
|
||||||
|
return (Skeleton) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySkeletonNPC extends EntitySkeleton {
|
||||||
|
|
||||||
|
public EntitySkeletonNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySlimeNPC;
|
import net.minecraft.server.EntitySlime;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSlimeNPC extends CitizensNPC {
|
import org.bukkit.entity.Slime;
|
||||||
|
|
||||||
|
public class CitizensSlimeNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSlimeNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSlimeNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySlimeNPC.class);
|
super(manager, id, name, EntitySlimeNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Slime getBukkitEntity() {
|
||||||
|
return (Slime) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySlimeNPC extends EntitySlime {
|
||||||
|
|
||||||
|
public EntitySlimeNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySnowmanNPC;
|
import net.minecraft.server.EntitySnowman;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSnowmanNPC extends CitizensNPC {
|
import org.bukkit.entity.Snowman;
|
||||||
|
|
||||||
|
public class CitizensSnowmanNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSnowmanNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSnowmanNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySnowmanNPC.class);
|
super(manager, id, name, EntitySnowmanNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Snowman getBukkitEntity() {
|
||||||
|
return (Snowman) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySnowmanNPC extends EntitySnowman {
|
||||||
|
|
||||||
|
public EntitySnowmanNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySpiderNPC;
|
import net.minecraft.server.EntitySpider;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSpiderNPC extends CitizensNPC {
|
import org.bukkit.entity.Spider;
|
||||||
|
|
||||||
|
public class CitizensSpiderNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSpiderNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSpiderNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySpiderNPC.class);
|
super(manager, id, name, EntitySpiderNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Spider getBukkitEntity() {
|
||||||
|
return (Spider) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySpiderNPC extends EntitySpider {
|
||||||
|
|
||||||
|
public EntitySpiderNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntitySquidNPC;
|
import net.minecraft.server.EntitySquid;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensSquidNPC extends CitizensNPC {
|
import org.bukkit.entity.Squid;
|
||||||
|
|
||||||
|
public class CitizensSquidNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensSquidNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensSquidNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntitySquidNPC.class);
|
super(manager, id, name, EntitySquidNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Squid getBukkitEntity() {
|
||||||
|
return (Squid) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySquidNPC extends EntitySquid {
|
||||||
|
|
||||||
|
public EntitySquidNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityVillagerNPC;
|
import net.minecraft.server.EntityVillager;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensVillagerNPC extends CitizensNPC {
|
import org.bukkit.entity.Villager;
|
||||||
|
|
||||||
|
public class CitizensVillagerNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensVillagerNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensVillagerNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityVillagerNPC.class);
|
super(manager, id, name, EntityVillagerNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Villager getBukkitEntity() {
|
||||||
|
return (Villager) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityVillagerNPC extends EntityVillager {
|
||||||
|
|
||||||
|
public EntityVillagerNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityWolfNPC;
|
import net.minecraft.server.EntityWolf;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensWolfNPC extends CitizensNPC {
|
import org.bukkit.entity.Wolf;
|
||||||
|
|
||||||
|
public class CitizensWolfNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensWolfNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensWolfNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityWolfNPC.class);
|
super(manager, id, name, EntityWolfNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Wolf getBukkitEntity() {
|
||||||
|
return (Wolf) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityWolfNPC extends EntityWolf {
|
||||||
|
|
||||||
|
public EntityWolfNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,30 @@
|
|||||||
package net.citizensnpcs.npc.entity;
|
package net.citizensnpcs.npc.entity;
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.entity.EntityZombieNPC;
|
import net.minecraft.server.EntityZombie;
|
||||||
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
public class CitizensZombieNPC extends CitizensNPC {
|
import org.bukkit.entity.Zombie;
|
||||||
|
|
||||||
|
public class CitizensZombieNPC extends CitizensMobNPC {
|
||||||
|
|
||||||
public CitizensZombieNPC(CitizensNPCManager manager, int id, String name) {
|
public CitizensZombieNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(manager, id, name, EntityZombieNPC.class);
|
super(manager, id, name, EntityZombieNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Zombie getBukkitEntity() {
|
||||||
|
return (Zombie) getHandle().getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityZombieNPC extends EntityZombie {
|
||||||
|
|
||||||
|
public EntityZombieNPC(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void m_() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityBlaze;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityBlazeNPC extends EntityBlaze {
|
|
||||||
|
|
||||||
public EntityBlazeNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityCaveSpider;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityCaveSpiderNPC extends EntityCaveSpider {
|
|
||||||
|
|
||||||
public EntityCaveSpiderNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityChicken;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityChickenNPC extends EntityChicken {
|
|
||||||
|
|
||||||
public EntityChickenNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityCow;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityCowNPC extends EntityCow {
|
|
||||||
|
|
||||||
public EntityCowNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityCreeper;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityCreeperNPC extends EntityCreeper {
|
|
||||||
|
|
||||||
public EntityCreeperNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityEnderDragon;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityEnderDragonNPC extends EntityEnderDragon {
|
|
||||||
|
|
||||||
public EntityEnderDragonNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityEnderman;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityEndermanNPC extends EntityEnderman {
|
|
||||||
|
|
||||||
public EntityEndermanNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityGhast;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityGhastNPC extends EntityGhast {
|
|
||||||
|
|
||||||
public EntityGhastNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityGiantZombie;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityGiantNPC extends EntityGiantZombie {
|
|
||||||
|
|
||||||
public EntityGiantNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityMagmaCube;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityMagmaCubeNPC extends EntityMagmaCube {
|
|
||||||
|
|
||||||
public EntityMagmaCubeNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityMushroomCow;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityMushroomCowNPC extends EntityMushroomCow {
|
|
||||||
|
|
||||||
public EntityMushroomCowNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityPig;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityPigNPC extends EntityPig {
|
|
||||||
|
|
||||||
public EntityPigNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityPigZombie;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityPigZombieNPC extends EntityPigZombie {
|
|
||||||
|
|
||||||
public EntityPigZombieNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySheep;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySheepNPC extends EntitySheep {
|
|
||||||
|
|
||||||
public EntitySheepNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySilverfish;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySilverfishNPC extends EntitySilverfish {
|
|
||||||
|
|
||||||
public EntitySilverfishNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySkeleton;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySkeletonNPC extends EntitySkeleton {
|
|
||||||
|
|
||||||
public EntitySkeletonNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySlime;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySlimeNPC extends EntitySlime {
|
|
||||||
|
|
||||||
public EntitySlimeNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySnowman;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySnowmanNPC extends EntitySnowman {
|
|
||||||
|
|
||||||
public EntitySnowmanNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySpider;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySpiderNPC extends EntitySpider {
|
|
||||||
|
|
||||||
public EntitySpiderNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntitySquid;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntitySquidNPC extends EntitySquid {
|
|
||||||
|
|
||||||
public EntitySquidNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityVillager;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityVillagerNPC extends EntityVillager {
|
|
||||||
|
|
||||||
public EntityVillagerNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityWolf;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityWolfNPC extends EntityWolf {
|
|
||||||
|
|
||||||
public EntityWolfNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.citizensnpcs.resource.lib.entity;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityZombie;
|
|
||||||
import net.minecraft.server.World;
|
|
||||||
|
|
||||||
public class EntityZombieNPC extends EntityZombie {
|
|
||||||
|
|
||||||
public EntityZombieNPC(World world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void m_() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,29 +28,6 @@ public class YamlStorage implements Storage {
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
try {
|
|
||||||
config.load(file);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
try {
|
|
||||||
config.save(file);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DataKey getKey(String root) {
|
|
||||||
return new YamlKey(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void create() {
|
private void create() {
|
||||||
try {
|
try {
|
||||||
Messaging.log("Creating file: " + file.getName());
|
Messaging.log("Creating file: " + file.getName());
|
||||||
@ -61,10 +38,33 @@ public class YamlStorage implements Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataKey getKey(String root) {
|
||||||
|
return new YamlKey(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
try {
|
||||||
|
config.load(file);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean pathExists(String key) {
|
private boolean pathExists(String key) {
|
||||||
return config.get(key) != null;
|
return config.get(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
config.save(file);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class YamlKey extends DataKey {
|
public class YamlKey extends DataKey {
|
||||||
private final String current;
|
private final String current;
|
||||||
|
|
||||||
@ -150,6 +150,14 @@ public class YamlStorage implements Storage {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getKeyExt(String from) {
|
||||||
|
if (from.isEmpty())
|
||||||
|
return current;
|
||||||
|
if (from.charAt(0) == '.')
|
||||||
|
return current.isEmpty() ? from.substring(1, from.length()) : current + from;
|
||||||
|
return current.isEmpty() ? from : current + "." + from;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLong(String key) {
|
public long getLong(String key) {
|
||||||
String path = getKeyExt(key);
|
String path = getKeyExt(key);
|
||||||
@ -169,6 +177,11 @@ public class YamlStorage implements Storage {
|
|||||||
return config.getLong(getKeyExt(key), def);
|
return config.getLong(getKeyExt(key), def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getRaw(String key) {
|
||||||
|
return config.get(getKeyExt(key));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataKey getRelative(String relative) {
|
public DataKey getRelative(String relative) {
|
||||||
if (relative == null || relative.isEmpty())
|
if (relative == null || relative.isEmpty())
|
||||||
@ -234,27 +247,14 @@ public class YamlStorage implements Storage {
|
|||||||
config.set(getKeyExt(key), value);
|
config.set(getKeyExt(key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setString(String key, String value) {
|
|
||||||
config.set(getKeyExt(key), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getRaw(String key) {
|
|
||||||
return config.get(getKeyExt(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRaw(String key, Object value) {
|
public void setRaw(String key, Object value) {
|
||||||
config.set(getKeyExt(key), value);
|
config.set(getKeyExt(key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getKeyExt(String from) {
|
@Override
|
||||||
if (from.isEmpty())
|
public void setString(String key, String value) {
|
||||||
return current;
|
config.set(getKeyExt(key), value);
|
||||||
if (from.charAt(0) == '.')
|
|
||||||
return current.isEmpty() ? from.substring(1, from.length()) : current + from;
|
|
||||||
return current.isEmpty() ? from : current + "." + from;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,14 +30,14 @@ public class LookClose implements Trait {
|
|||||||
key.setBoolean("", shouldLookClose);
|
key.setBoolean("", shouldLookClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldLookClose() {
|
|
||||||
return shouldLookClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLookClose(boolean shouldLookClose) {
|
public void setLookClose(boolean shouldLookClose) {
|
||||||
this.shouldLookClose = shouldLookClose;
|
this.shouldLookClose = shouldLookClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldLookClose() {
|
||||||
|
return shouldLookClose;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LookClose{" + shouldLookClose + "}";
|
return "LookClose{" + shouldLookClose + "}";
|
||||||
|
@ -33,6 +33,10 @@ public class Messaging {
|
|||||||
player.sendMessage(send);
|
player.sendMessage(send);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendError(Player player, Object msg) {
|
||||||
|
send(player, ChatColor.RED.toString() + msg);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendWithNPC(Player player, Object msg, NPC npc) {
|
public static void sendWithNPC(Player player, Object msg, NPC npc) {
|
||||||
String send = msg.toString();
|
String send = msg.toString();
|
||||||
|
|
||||||
@ -41,8 +45,4 @@ public class Messaging {
|
|||||||
|
|
||||||
send(player, send);
|
send(player, send);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendError(Player player, Object msg) {
|
|
||||||
send(player, ChatColor.RED.toString() + msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,8 +3,6 @@ package net.citizensnpcs.util;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.CreatureType;
|
|
||||||
|
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.npc.entity.CitizensBlazeNPC;
|
import net.citizensnpcs.npc.entity.CitizensBlazeNPC;
|
||||||
@ -32,10 +30,12 @@ import net.citizensnpcs.npc.entity.CitizensVillagerNPC;
|
|||||||
import net.citizensnpcs.npc.entity.CitizensWolfNPC;
|
import net.citizensnpcs.npc.entity.CitizensWolfNPC;
|
||||||
import net.citizensnpcs.npc.entity.CitizensZombieNPC;
|
import net.citizensnpcs.npc.entity.CitizensZombieNPC;
|
||||||
|
|
||||||
public class NPCBuilder {
|
import org.bukkit.entity.CreatureType;
|
||||||
private final Map<CreatureType, Class<? extends CitizensNPC>> types = new HashMap<CreatureType, Class<? extends CitizensNPC>>();
|
|
||||||
|
|
||||||
public NPCBuilder() {
|
public class NPCBuilder {
|
||||||
|
private static final Map<CreatureType, Class<? extends CitizensNPC>> types = new HashMap<CreatureType, Class<? extends CitizensNPC>>();
|
||||||
|
|
||||||
|
static {
|
||||||
types.put(CreatureType.BLAZE, CitizensBlazeNPC.class);
|
types.put(CreatureType.BLAZE, CitizensBlazeNPC.class);
|
||||||
types.put(CreatureType.CAVE_SPIDER, CitizensCaveSpiderNPC.class);
|
types.put(CreatureType.CAVE_SPIDER, CitizensCaveSpiderNPC.class);
|
||||||
types.put(CreatureType.CHICKEN, CitizensChickenNPC.class);
|
types.put(CreatureType.CHICKEN, CitizensChickenNPC.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user