mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-05 07:57:41 +01:00
Some work on implementation
This commit is contained in:
parent
b0ff804209
commit
3d8e797251
@ -1,80 +1,41 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.CitizensPlugin;
|
||||
import net.citizensnpcs.api.abstraction.Server;
|
||||
import net.citizensnpcs.api.attachment.AttachmentFactory;
|
||||
import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.citizensnpcs.api.scripting.EventRegistrar;
|
||||
import net.citizensnpcs.api.scripting.ObjectProvider;
|
||||
import net.citizensnpcs.api.scripting.ScriptCompiler;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.DatabaseStorage;
|
||||
import net.citizensnpcs.api.util.NBTStorage;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.citizensnpcs.command.CommandManager;
|
||||
import net.citizensnpcs.command.Injector;
|
||||
import net.citizensnpcs.command.command.AdminCommands;
|
||||
import net.citizensnpcs.command.command.EditorCommands;
|
||||
import net.citizensnpcs.command.command.HelpCommands;
|
||||
import net.citizensnpcs.command.command.NPCCommands;
|
||||
import net.citizensnpcs.command.command.ScriptCommands;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||
import net.citizensnpcs.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensAttachmentFactory;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCRegistry;
|
||||
import net.citizensnpcs.npc.CitizensTraitManager;
|
||||
import net.citizensnpcs.npc.NPCSelector;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class Citizens implements CitizensPlugin {
|
||||
private final CitizensAttachmentFactory attachmentFactory = new CitizensAttachmentFactory();
|
||||
private final File dataFolder;
|
||||
private final Server server;
|
||||
private final NPCSelector selector = new NPCSelector();
|
||||
private final NPCRegistry registry;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
private final CommandManager commands = new CommandManager();
|
||||
private boolean compatible;
|
||||
private Settings config;
|
||||
private ClassLoader contextClassLoader;
|
||||
private CitizensNPCRegistry npcRegistry;
|
||||
private Storage saves; // TODO: refactor this, it's used in too many places
|
||||
private NPCSelector selector;
|
||||
private CitizensAttachmentFactory attachmentFactory;
|
||||
|
||||
public Iterable<net.citizensnpcs.command.Command> getCommands(String base) {
|
||||
return commands.getCommands(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCRegistry getNPCRegistry() {
|
||||
return npcRegistry;
|
||||
public Citizens(Server server, NPCRegistry registry, File dataFolder) {
|
||||
this.server = server;
|
||||
this.registry = registry;
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
public NPCSelector getNPCSelector() {
|
||||
return selector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCRegistry getNPCRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getScriptFolder() {
|
||||
return new File(getDataFolder(), "scripts");
|
||||
@ -86,257 +47,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
|
||||
try {
|
||||
// must put command into split.
|
||||
String[] split = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, split, 1, args.length);
|
||||
split[0] = cmd.getName().toLowerCase();
|
||||
|
||||
String modifier = args.length > 0 ? args[0] : "";
|
||||
|
||||
if (!commands.hasCommand(split[0], modifier) && !modifier.isEmpty()) {
|
||||
return suggestClosestModifier(sender, split[0], modifier);
|
||||
}
|
||||
|
||||
NPC npc = selector.getSelected(sender);
|
||||
// TODO: change the args supplied to a context style system for
|
||||
// flexibility (ie. adding more context in the future without
|
||||
// changing everything)
|
||||
try {
|
||||
commands.execute(split, sender, sender, npc);
|
||||
} catch (ServerCommandException ex) {
|
||||
Messaging.send(sender, "You must be in-game to execute that command.");
|
||||
} catch (CommandUsageException ex) {
|
||||
Messaging.sendError(sender, ex.getMessage());
|
||||
Messaging.sendError(sender, ex.getUsage());
|
||||
} catch (WrappedCommandException ex) {
|
||||
throw ex.getCause();
|
||||
} catch (UnhandledCommandException ex) {
|
||||
return false;
|
||||
} catch (CommandException ex) {
|
||||
Messaging.sendError(sender, ex.getMessage());
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
Messaging.sendError(sender, "That is not a valid number.");
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
if (sender instanceof Player) {
|
||||
Messaging.sendError(sender, "Please report this error: [See console]");
|
||||
Messaging.sendError(sender, ex.getClass().getName() + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
CitizensAPI.getServer().callEvent(new CitizensDisableEvent());
|
||||
|
||||
tearDownScripting();
|
||||
// Don't bother with this part if MC versions are not compatible
|
||||
if (compatible) {
|
||||
save();
|
||||
despawnNPCs();
|
||||
npcRegistry = null;
|
||||
}
|
||||
|
||||
Messaging.logF("v%s disabled.", getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Disable if the server is not using the compatible Minecraft version
|
||||
String mcVersion = CitizensAPI.getServer().getMinecraftVersion();
|
||||
compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION);
|
||||
if (!compatible) {
|
||||
Messaging.severeF("v%s is not compatible with Minecraft v%s. Disabling.", getDescription().getVersion(),
|
||||
mcVersion);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
registerScriptHelpers();
|
||||
|
||||
config = new Settings(getDataFolder());
|
||||
|
||||
setupStorage();
|
||||
|
||||
npcRegistry = new CitizensNPCRegistry(saves);
|
||||
attachmentFactory = new CitizensTraitManager(this);
|
||||
selector = new NPCSelector(this);
|
||||
CitizensAPI.setImplementation(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new EventListen(), this);
|
||||
|
||||
registerCommands();
|
||||
|
||||
Messaging.logF("v%s enabled.", getDescription().getVersion());
|
||||
|
||||
// Setup NPCs after all plugins have been enabled (allows for multiworld
|
||||
// support and for NPCs to properly register external settings)
|
||||
if (getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setupNPCs();
|
||||
startMetrics();
|
||||
}
|
||||
|
||||
private void startMetrics() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(Citizens.this);
|
||||
if (metrics.isOptOut())
|
||||
return;
|
||||
metrics.addCustomData(new Metrics.Plotter() {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return Iterables.size(npcRegistry);
|
||||
}
|
||||
});
|
||||
attachmentFactory.addPlotters(metrics);
|
||||
metrics.start();
|
||||
Messaging.log("Metrics started.");
|
||||
} catch (IOException e) {
|
||||
Messaging.logF("Unable to start metrics: %s.", e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}) == -1) {
|
||||
Messaging.severe("Issue enabling plugin. Disabling.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImplementationChanged() {
|
||||
Messaging.severe("Citizens implementation changed, disabling plugin.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
commands.setInjector(new Injector(this));
|
||||
|
||||
// Register command classes
|
||||
commands.register(AdminCommands.class);
|
||||
commands.register(EditorCommands.class);
|
||||
commands.register(HelpCommands.class);
|
||||
commands.register(NPCCommands.class);
|
||||
commands.register(ScriptCommands.class);
|
||||
}
|
||||
|
||||
private void registerScriptHelpers() {
|
||||
setupScripting();
|
||||
ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
|
||||
compiler.registerGlobalContextProvider(new EventRegistrar(this));
|
||||
compiler.registerGlobalContextProvider(new ObjectProvider("plugin", this));
|
||||
}
|
||||
|
||||
public void reload() throws NPCLoadException {
|
||||
Editor.leaveAll();
|
||||
config.reload();
|
||||
despawnNPCs();
|
||||
setupNPCs();
|
||||
|
||||
CitizensAPI.getServer().callEvent(new CitizensReloadEvent());
|
||||
}
|
||||
|
||||
private void despawnNPCs() {
|
||||
Iterator<NPC> itr = npcRegistry.iterator();
|
||||
while (itr.hasNext()) {
|
||||
NPC npc = itr.next();
|
||||
itr.remove();
|
||||
npc.despawn();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
for (NPC npc : npcRegistry)
|
||||
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
||||
|
||||
saves.save();
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
private void setupNPCs() {
|
||||
saves.load();
|
||||
int created = 0, spawned = 0;
|
||||
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
|
||||
int id = Integer.parseInt(key.name());
|
||||
if (!key.keyExists("name")) {
|
||||
Messaging.logF("Could not find a name for the NPC with ID '%s'.", id);
|
||||
continue;
|
||||
}
|
||||
String unparsedEntityType = key.getString("traits.type", "PLAYER");
|
||||
EntityType type = EntityType.fromName(unparsedEntityType);
|
||||
if (type == null) {
|
||||
try {
|
||||
type = EntityType.valueOf(unparsedEntityType);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Messaging.logF("NPC type '%s' was not recognized. Did you spell it correctly?", unparsedEntityType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
NPC npc = npcRegistry.createNPC(type, id, key.getString("name"), null);
|
||||
((CitizensNPC) npc).load(key);
|
||||
|
||||
++created;
|
||||
if (npc.isSpawned())
|
||||
++spawned;
|
||||
}
|
||||
Messaging.logF("Loaded %d NPCs (%d spawned).", created, spawned);
|
||||
}
|
||||
|
||||
private void setupScripting() {
|
||||
contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
||||
// workaround to fix scripts not loading plugin classes properly
|
||||
}
|
||||
|
||||
private void setupStorage() {
|
||||
String type = Setting.STORAGE_TYPE.asString();
|
||||
if (type.equalsIgnoreCase("db") || type.equalsIgnoreCase("database")) {
|
||||
try {
|
||||
saves = new DatabaseStorage(Setting.DATABASE_DRIVER.asString(), Setting.DATABASE_URL.asString(),
|
||||
Setting.DATABASE_USERNAME.asString(), Setting.DATABASE_PASSWORD.asString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Messaging.log("Unable to connect to database, falling back to YAML");
|
||||
}
|
||||
} else if (type.equalsIgnoreCase("nbt")) {
|
||||
saves = new NBTStorage(getDataFolder() + File.separator + Setting.STORAGE_FILE.asString(),
|
||||
"Citizens NPC Storage");
|
||||
}
|
||||
if (saves == null) {
|
||||
saves = new YamlStorage(getDataFolder() + File.separator + Setting.STORAGE_FILE.asString(),
|
||||
"Citizens NPC Storage");
|
||||
}
|
||||
Messaging.logF("Save method set to %s.", saves.toString());
|
||||
}
|
||||
|
||||
private boolean suggestClosestModifier(CommandSender sender, String command, String modifier) {
|
||||
int minDist = Integer.MAX_VALUE;
|
||||
String closest = "";
|
||||
for (String string : commands.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;
|
||||
}
|
||||
|
||||
private void tearDownScripting() {
|
||||
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
||||
}
|
||||
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.2.5";
|
||||
}
|
||||
}
|
||||
|
322
src/main/java/net/citizensnpcs/CitizensBukkit.java
Normal file
322
src/main/java/net/citizensnpcs/CitizensBukkit.java
Normal file
@ -0,0 +1,322 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.Loader;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.abstraction.bukkit.BukkitEventConverter;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.scripting.EventRegistrar;
|
||||
import net.citizensnpcs.api.scripting.ObjectProvider;
|
||||
import net.citizensnpcs.api.scripting.ScriptCompiler;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.DatabaseStorage;
|
||||
import net.citizensnpcs.api.util.NBTStorage;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
import net.citizensnpcs.command.CommandManager;
|
||||
import net.citizensnpcs.command.Injector;
|
||||
import net.citizensnpcs.command.command.AdminCommands;
|
||||
import net.citizensnpcs.command.command.EditorCommands;
|
||||
import net.citizensnpcs.command.command.HelpCommands;
|
||||
import net.citizensnpcs.command.command.NPCCommands;
|
||||
import net.citizensnpcs.command.command.ScriptCommands;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||
import net.citizensnpcs.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensAttachmentFactory;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCRegistry;
|
||||
import net.citizensnpcs.npc.NPCSelector;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class CitizensBukkit extends JavaPlugin {
|
||||
private final CommandManager commands = new CommandManager();
|
||||
private boolean compatible;
|
||||
private Citizens implementation;
|
||||
private Settings config;
|
||||
private ClassLoader contextClassLoader;
|
||||
private Storage saves; // TODO: refactor this, it's used in too many places
|
||||
private NPCSelector selector;
|
||||
|
||||
public Iterable<net.citizensnpcs.command.Command> getCommands(String base) {
|
||||
return commands.getCommands(base);
|
||||
}
|
||||
|
||||
public NPCSelector getNPCSelector() {
|
||||
return selector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command cmd, String cmdName,
|
||||
String[] args) {
|
||||
try {
|
||||
// must put command into split.
|
||||
String[] split = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, split, 1, args.length);
|
||||
split[0] = cmd.getName().toLowerCase();
|
||||
|
||||
String modifier = args.length > 0 ? args[0] : "";
|
||||
|
||||
if (!commands.hasCommand(split[0], modifier) && !modifier.isEmpty()) {
|
||||
return suggestClosestModifier(sender, split[0], modifier);
|
||||
}
|
||||
|
||||
NPC npc = selector.getSelected(sender);
|
||||
// TODO: change the args supplied to a context style system for
|
||||
// flexibility (ie. adding more context in the future without
|
||||
// changing everything)
|
||||
try {
|
||||
commands.execute(split, sender, sender, npc);
|
||||
} catch (ServerCommandException ex) {
|
||||
Messaging.send(sender, "You must be in-game to execute that command.");
|
||||
} catch (CommandUsageException ex) {
|
||||
Messaging.sendError(sender, ex.getMessage());
|
||||
Messaging.sendError(sender, ex.getUsage());
|
||||
} catch (WrappedCommandException ex) {
|
||||
throw ex.getCause();
|
||||
} catch (UnhandledCommandException ex) {
|
||||
return false;
|
||||
} catch (CommandException ex) {
|
||||
Messaging.sendError(sender, ex.getMessage());
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
Messaging.sendError(sender, "That is not a valid number.");
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
if (sender instanceof Player) {
|
||||
Messaging.sendError(sender, "Please report this error: [See console]");
|
||||
Messaging.sendError(sender, ex.getClass().getName() + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
CitizensAPI.getServer().callEvent(new CitizensDisableEvent());
|
||||
|
||||
tearDownScripting();
|
||||
// Don't bother with this part if MC versions are not compatible
|
||||
if (compatible) {
|
||||
save();
|
||||
despawnNPCs();
|
||||
}
|
||||
|
||||
implementation = null;
|
||||
|
||||
Messaging.logF("v%s disabled.", getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Disable if the server is not using the compatible Minecraft version
|
||||
String mcVersion = CitizensAPI.getServer().getMinecraftVersion();
|
||||
compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION);
|
||||
if (!compatible) {
|
||||
Messaging.severeF("v%s is not compatible with Minecraft v%s. Disabling.", getDescription().getVersion(),
|
||||
mcVersion);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
setupClassLoader();
|
||||
registerScriptHelpers();
|
||||
|
||||
config = new Settings(new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration"));
|
||||
|
||||
setupStorage();
|
||||
|
||||
implementation = new Citizens(null, new CitizensNPCRegistry(saves), getDataFolder());
|
||||
CitizensAPI.setImplementation(implementation);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new EventListen(), this);
|
||||
|
||||
registerCommands();
|
||||
|
||||
Messaging.logF("v%s enabled.", getDescription().getVersion());
|
||||
|
||||
// Setup NPCs after all plugins have been enabled (allows for multiworld
|
||||
// support and for NPCs to properly register external settings)
|
||||
if (getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setupNPCs();
|
||||
startMetrics();
|
||||
}
|
||||
|
||||
private void startMetrics() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(CitizensBukkit.this);
|
||||
if (metrics.isOptOut())
|
||||
return;
|
||||
metrics.addCustomData(new Metrics.Plotter() {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return Iterables.size(implementation.getNPCRegistry());
|
||||
}
|
||||
});
|
||||
((CitizensAttachmentFactory) implementation.getAttachmentFactory()).addPlotters(metrics);
|
||||
metrics.start();
|
||||
Messaging.log("Metrics started.");
|
||||
} catch (IOException e) {
|
||||
Messaging.logF("Unable to start metrics: %s.", e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}) == -1) {
|
||||
Messaging.severe("Issue enabling plugin. Disabling.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
commands.setInjector(new Injector(this));
|
||||
|
||||
// Register command classes
|
||||
commands.register(AdminCommands.class);
|
||||
commands.register(EditorCommands.class);
|
||||
commands.register(HelpCommands.class);
|
||||
commands.register(NPCCommands.class);
|
||||
commands.register(ScriptCommands.class);
|
||||
}
|
||||
|
||||
private void registerScriptHelpers() {
|
||||
ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
|
||||
compiler.registerGlobalContextProvider(new EventRegistrar(this));
|
||||
compiler.registerGlobalContextProvider(new ObjectProvider("plugin", this));
|
||||
}
|
||||
|
||||
public void reload() throws NPCLoadException {
|
||||
Editor.leaveAll();
|
||||
config.reload();
|
||||
despawnNPCs();
|
||||
setupNPCs();
|
||||
|
||||
CitizensAPI.getServer().callEvent(new CitizensReloadEvent());
|
||||
}
|
||||
|
||||
private void despawnNPCs() {
|
||||
Iterator<NPC> itr = CitizensAPI.getNPCRegistry().iterator();
|
||||
while (itr.hasNext()) {
|
||||
NPC npc = itr.next();
|
||||
itr.remove();
|
||||
npc.despawn();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
for (NPC npc : CitizensAPI.getNPCRegistry())
|
||||
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
||||
|
||||
saves.save();
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
private void setupNPCs() {
|
||||
saves.load();
|
||||
int created = 0, spawned = 0;
|
||||
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
|
||||
int id = Integer.parseInt(key.name());
|
||||
if (!key.keyExists("name")) {
|
||||
Messaging.logF("Could not find a name for the NPC with ID '%s'.", id);
|
||||
continue;
|
||||
}
|
||||
String unparsedEntityType = key.getString("traits.type", "PLAYER");
|
||||
MobType type = MobType.fromName(unparsedEntityType);
|
||||
if (type == null) {
|
||||
try {
|
||||
type = MobType.valueOf(unparsedEntityType);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Messaging.logF("NPC type '%s' was not recognized. Did you spell it correctly?", unparsedEntityType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
CitizensNPC npc = new CitizensNPC(key.getString("name"));
|
||||
npc.setEntityController(null);// TODO
|
||||
npc.load(key);
|
||||
|
||||
++created;
|
||||
if (npc.isSpawned())
|
||||
++spawned;
|
||||
}
|
||||
Messaging.logF("Loaded %d NPCs (%d spawned).", created, spawned);
|
||||
}
|
||||
|
||||
private void setupClassLoader() {
|
||||
Loader loader = new Loader(getClassLoader(), ClassPool.getDefault());
|
||||
try {
|
||||
loader.addTranslator(ClassPool.getDefault(), new BukkitEventConverter());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
}
|
||||
|
||||
private void setupStorage() {
|
||||
String type = Setting.STORAGE_TYPE.asString();
|
||||
if (type.equalsIgnoreCase("db") || type.equalsIgnoreCase("database")) {
|
||||
try {
|
||||
saves = new DatabaseStorage(Setting.DATABASE_DRIVER.asString(), Setting.DATABASE_URL.asString(),
|
||||
Setting.DATABASE_USERNAME.asString(), Setting.DATABASE_PASSWORD.asString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Messaging.log("Unable to connect to database, falling back to YAML");
|
||||
}
|
||||
} else if (type.equalsIgnoreCase("nbt")) {
|
||||
saves = new NBTStorage(getDataFolder() + File.separator + Setting.STORAGE_FILE.asString(),
|
||||
"Citizens NPC Storage");
|
||||
}
|
||||
if (saves == null) {
|
||||
saves = new YamlStorage(getDataFolder() + File.separator + Setting.STORAGE_FILE.asString(),
|
||||
"Citizens NPC Storage");
|
||||
}
|
||||
Messaging.logF("Save method set to %s.", saves.toString());
|
||||
}
|
||||
|
||||
private boolean suggestClosestModifier(org.bukkit.command.CommandSender sender, String command, String modifier) {
|
||||
int minDist = Integer.MAX_VALUE;
|
||||
String closest = "";
|
||||
for (String string : commands.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;
|
||||
}
|
||||
|
||||
private void tearDownScripting() {
|
||||
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
||||
}
|
||||
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.2.5";
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import javassist.compiler.ast.Pair;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.abstraction.bukkit.BukkitConverter;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.Chunk;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.Listener;
|
||||
import net.citizensnpcs.api.abstraction.WorldVector;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.event.CitizensImplementationChangedEvent;
|
||||
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
|
||||
import net.citizensnpcs.api.event.NPCDamageEvent;
|
||||
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
||||
@ -14,13 +19,12 @@ import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
@ -39,14 +43,20 @@ import com.google.common.collect.ListMultimap;
|
||||
|
||||
public class EventListen implements Listener {
|
||||
private final NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
|
||||
private final ListMultimap<Pair<Integer, Integer>, Integer> toRespawn = ArrayListMultimap.create();
|
||||
private final ListMultimap<ChunkCoord, Integer> toRespawn = ArrayListMultimap.create();
|
||||
|
||||
@EventHandler
|
||||
public void onImplementationChanged(CitizensImplementationChangedEvent event) {
|
||||
Messaging.severe("Citizens implementation changed, disabling plugin.");
|
||||
Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("Citizens"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Chunk events
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
Pair<Integer, Integer> coord = toIntPair(event.getChunk());
|
||||
ChunkCoord coord = new ChunkCoord(event.getChunk().getX(), event.getChunk().getZ());
|
||||
if (!toRespawn.containsKey(coord))
|
||||
return;
|
||||
for (int id : toRespawn.get(coord)) {
|
||||
@ -61,12 +71,12 @@ public class EventListen implements Listener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
Pair<Integer, Integer> coord = toIntPair(event.getChunk());
|
||||
ChunkCoord coord = new ChunkCoord(event.getChunk().getX(), event.getChunk().getZ());
|
||||
for (NPC npc : npcRegistry) {
|
||||
if (!npc.isSpawned())
|
||||
continue;
|
||||
WorldVector loc = npc.getEntity().getLocation();
|
||||
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().equals(loc.getChunk())) {
|
||||
if (loc.getWorld().equals(event.getWorld()) && loc.getChunk().equals(event.getChunk())) {
|
||||
npc.despawn();
|
||||
toRespawn.put(coord, npc.getId());
|
||||
}
|
||||
@ -82,18 +92,25 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
|
||||
NPC npc = npcRegistry.getNPC(event.getEntity());
|
||||
NPCDamageEvent damageEvent;
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
NPCDamageByEntityEvent damageEvent = new NPCDamageByEntityEvent(npc, (EntityDamageByEntityEvent) event);
|
||||
NPCDamageByEntityEvent damageByEntityEvent = new NPCDamageByEntityEvent(npc, event.getDamage(),
|
||||
BukkitConverter.toEntity(((EntityDamageByEntityEvent) event).getDamager()));
|
||||
damageEvent = damageByEntityEvent;
|
||||
CitizensAPI.getServer().callEvent(damageEvent);
|
||||
|
||||
if (!damageEvent.isCancelled() || !(damageEvent.getDamager() instanceof Player))
|
||||
return;
|
||||
Player damager = (Player) damageEvent.getDamager();
|
||||
|
||||
CitizensAPI.getServer().callEvent(new NPCLeftClickEvent(npc, damager));
|
||||
if (!damageEvent.isCancelled() || !(damageByEntityEvent.getDamager() instanceof Player)) {
|
||||
Player damager = (Player) damageByEntityEvent.getDamager();
|
||||
CitizensAPI.getServer().callEvent(new NPCLeftClickEvent(npc, damager));
|
||||
}
|
||||
event.setDamage(damageEvent.getDamage());
|
||||
event.setCancelled(damageEvent.isCancelled());
|
||||
} else {
|
||||
CitizensAPI.getServer().callEvent(new NPCDamageEvent(npc, event));
|
||||
damageEvent = new NPCDamageEvent(npc, event.getDamage());
|
||||
CitizensAPI.getServer().callEvent(damageEvent);
|
||||
}
|
||||
event.setDamage(damageEvent.getDamage());
|
||||
event.setCancelled(damageEvent.isCancelled());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -114,13 +131,13 @@ public class EventListen implements Listener {
|
||||
|
||||
// Call right-click event
|
||||
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
|
||||
Bukkit.getPluginManager().callEvent(rightClickEvent);
|
||||
CitizensAPI.getServer().callEvent(rightClickEvent);
|
||||
if (rightClickEvent.isCancelled())
|
||||
return;
|
||||
// If the NPC isn't a close talker
|
||||
// TODO: move this into text.class
|
||||
if (Util.isSettingFulfilled(player, Setting.TALK_ITEM) && !npc.getTrait(Text.class).shouldTalkClose())
|
||||
npc.getTrait(Text.class).sendText(player);
|
||||
if (Util.isSettingFulfilled(player, Setting.TALK_ITEM) && !npc.getAttachment(Text.class).shouldTalkClose())
|
||||
npc.getAttachment(Text.class).sendText(player);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -146,7 +163,7 @@ public class EventListen implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Editor.leave(event.getPlayer());
|
||||
Editor.leave(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -154,12 +171,12 @@ public class EventListen implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
for (Pair<Integer, Integer> chunk : toRespawn.keySet()) {
|
||||
if (!event.getWorld().isChunkLoaded(chunk.first, chunk.second))
|
||||
for (ChunkCoord chunk : toRespawn.keySet()) {
|
||||
if (!event.getWorld().isChunkLoaded(chunk.x, chunk.z))
|
||||
continue;
|
||||
for (int id : toRespawn.get(chunk)) {
|
||||
NPC npc = npcRegistry.getNPC(id);
|
||||
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||
NPC npc = npcRegistry.getById(id);
|
||||
npc.spawn(npc.getAttachment(CurrentLocation.class).getLocation());
|
||||
}
|
||||
toRespawn.removeAll(chunk);
|
||||
}
|
||||
@ -171,15 +188,39 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
|
||||
for (NPC npc : npcRegistry) {
|
||||
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
|
||||
if (!npc.isSpawned() || !npc.getEntity().getWorld().equals(event.getWorld()))
|
||||
continue;
|
||||
|
||||
npc.despawn();
|
||||
toRespawn.put(toIntPair(npc.getBukkitEntity().getLocation().getChunk()), npc.getId());
|
||||
Chunk chunk = npc.getEntity().getLocation().getChunk();
|
||||
toRespawn.put(new ChunkCoord(chunk.getX(), chunk.getZ()), npc.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private Pair<Integer, Integer> toIntPair(Chunk chunk) {
|
||||
return new Pair<Integer, Integer>(chunk.getX(), chunk.getZ());
|
||||
private static class ChunkCoord {
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
private ChunkCoord(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (31 + x) + z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ChunkCoord other = (ChunkCoord) obj;
|
||||
return x == other.x && z == other.z;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,18 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
public class Settings {
|
||||
private final Storage config;
|
||||
private final DataKey root;
|
||||
|
||||
public Settings(File folder) {
|
||||
config = new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration");
|
||||
public Settings(Storage storage) {
|
||||
config = storage;
|
||||
root = config.getKey("");
|
||||
|
||||
config.load();
|
||||
|
@ -0,0 +1,43 @@
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.WorldVector;
|
||||
import net.citizensnpcs.api.abstraction.entity.Entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class BukkitConverter {
|
||||
|
||||
public static Entity toEntity(org.bukkit.entity.Entity entity) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public static WorldVector toWorldVector(Location location) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public static World toWorld(org.bukkit.World world) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MobType toMobType(EntityType type) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.bukkit.inventory.ItemStack fromItemStack(ItemStack itemStack) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack toItemStack(org.bukkit.inventory.ItemStack itemInHand) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.WorldVector;
|
||||
import net.citizensnpcs.api.abstraction.entity.Entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class BukkitEntity implements Entity {
|
||||
protected final org.bukkit.entity.Entity entity;
|
||||
|
||||
public BukkitEntity(org.bukkit.entity.Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getNearbyEntities(double dX, double dY, double dZ) {
|
||||
List<org.bukkit.entity.Entity> bEntities = entity.getNearbyEntities(dX, dY, dZ);
|
||||
List<Entity> converted = Lists.newArrayList();
|
||||
for (org.bukkit.entity.Entity bEntity : bEntities) {
|
||||
converted.add(BukkitConverter.toEntity(bEntity));
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldVector getLocation() {
|
||||
return BukkitConverter.toWorldVector(entity.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return BukkitConverter.toWorld(entity.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(double yaw, double pitch) {
|
||||
Location loc = entity.getLocation();
|
||||
loc.setYaw((float) yaw);
|
||||
loc.setPitch((float) pitch);
|
||||
entity.teleport(loc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 + ((entity == null) ? 0 : entity.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BukkitEntity other = (BukkitEntity) obj;
|
||||
if (entity == null) {
|
||||
if (other.entity != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!entity.equals(other.entity)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* CitizensAPI
|
||||
* Copyright (C) 2012 CitizensDev <http://citizensnpcs.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtField;
|
||||
import javassist.CtMethod;
|
||||
import javassist.CtNewMethod;
|
||||
import javassist.Modifier;
|
||||
import javassist.NotFoundException;
|
||||
import javassist.Translator;
|
||||
import javassist.bytecode.AnnotationsAttribute;
|
||||
import javassist.bytecode.ConstPool;
|
||||
import javassist.bytecode.annotation.Annotation;
|
||||
import javassist.bytecode.annotation.EnumMemberValue;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
|
||||
public class BukkitEventConverter implements Translator {
|
||||
private CtClass bukkitEvent;
|
||||
private CtClass bukkitListener;
|
||||
private CtClass citizensEvent;
|
||||
private CtClass citizensListener;
|
||||
|
||||
private void addHandlerList(CtClass clazz) throws NotFoundException, CannotCompileException {
|
||||
clazz.addField(CtField.make("private static final HanderList handlers = new HanderList();", clazz));
|
||||
CtMethod getHandlers = CtNewMethod.getter("getHandlerList", clazz.getField("handlers"));
|
||||
getHandlers.setModifiers(getHandlers.getModifiers() & Modifier.STATIC);
|
||||
clazz.addMethod(getHandlers);
|
||||
clazz.addMethod(CtNewMethod.getter("handlers", clazz.getField("handlers")));
|
||||
}
|
||||
|
||||
private void convertListener(CtClass clazz) throws NotFoundException {
|
||||
clazz.addInterface(bukkitListener);
|
||||
|
||||
ConstPool constPool = clazz.getClassFile().getConstPool();
|
||||
|
||||
for (CtMethod method : clazz.getMethods()) {
|
||||
if (!method.hasAnnotation(EventHandler.class))
|
||||
continue;
|
||||
Annotation eventHandler = new Annotation("org.bukkit.event.EventHandler", constPool);
|
||||
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
|
||||
attr.addAnnotation(eventHandler);
|
||||
|
||||
EnumMemberValue value = new EnumMemberValue(constPool);
|
||||
value.setType("org.bukkit.event.Priority");
|
||||
EventHandler handler;
|
||||
try {
|
||||
handler = (EventHandler) method.getAnnotation(EventHandler.class);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
value.setValue(handler.priority().name());
|
||||
|
||||
eventHandler.addMemberValue("priority", value);
|
||||
method.getMethodInfo().addAttribute(attr);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isListener(CtClass clazz) throws NotFoundException {
|
||||
for (CtClass implement : clazz.getInterfaces()) {
|
||||
if (implement == citizensListener)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException {
|
||||
CtClass clazz = pool.get(classname);
|
||||
if (isListener(clazz)) {
|
||||
convertListener(clazz);
|
||||
return;
|
||||
}
|
||||
CtClass superClass = clazz.getSuperclass(), last;
|
||||
while (true) {
|
||||
last = superClass;
|
||||
superClass = superClass.getSuperclass();
|
||||
if (superClass == null)
|
||||
return;
|
||||
else if (superClass != citizensEvent)
|
||||
continue;
|
||||
last.setSuperclass(bukkitEvent);
|
||||
addHandlerList(clazz);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(ClassPool pool) throws NotFoundException, CannotCompileException {
|
||||
citizensEvent = pool.get("net.citizensnpcs.api.abstraction.Event");
|
||||
citizensListener = pool.get("net.citizensnpcs.api.abstraction.Listener");
|
||||
bukkitEvent = pool.get("org.bukkit.event.Event");
|
||||
bukkitListener = pool.get("org.bukkit.event.Listener");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.abstraction.entity.LivingEntity;
|
||||
|
||||
public class BukkitLivingEntity extends BukkitEntity implements LivingEntity {
|
||||
public BukkitLivingEntity(org.bukkit.entity.LivingEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHealth() {
|
||||
return getEntity().getHealth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobType getType() {
|
||||
return BukkitConverter.toMobType(getEntity().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealth(int health) {
|
||||
getEntity().setHealth(health);
|
||||
}
|
||||
|
||||
private org.bukkit.entity.LivingEntity getEntity() {
|
||||
return (org.bukkit.entity.LivingEntity) entity;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.Equipment;
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class BukkitPlayer extends BukkitLivingEntity implements Player {
|
||||
public BukkitPlayer(org.bukkit.entity.Player entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getPlayer().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return getPlayer().hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
getPlayer().sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useCommand(String cmd) {
|
||||
Bukkit.getServer().dispatchCommand(getPlayer(), cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getEquipment(Equipment slot) {
|
||||
switch (slot) {
|
||||
case CARRIED:
|
||||
return BukkitConverter.toItemStack(getPlayer().getItemInHand());
|
||||
case HELMET:
|
||||
return BukkitConverter.toItemStack(getPlayer().getInventory().getHelmet());
|
||||
case BOOTS:
|
||||
return BukkitConverter.toItemStack(getPlayer().getInventory().getBoots());
|
||||
case CHESTPLATE:
|
||||
return BukkitConverter.toItemStack(getPlayer().getInventory().getChestplate());
|
||||
case LEGGINGS:
|
||||
return BukkitConverter.toItemStack(getPlayer().getInventory().getLeggings());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEquipment(Equipment slot, ItemStack item) {
|
||||
switch (slot) {
|
||||
case CARRIED:
|
||||
getPlayer().setItemInHand(BukkitConverter.fromItemStack(item));
|
||||
case HELMET:
|
||||
getPlayer().getInventory().setHelmet(BukkitConverter.fromItemStack(item));
|
||||
case BOOTS:
|
||||
getPlayer().getInventory().setBoots(BukkitConverter.fromItemStack(item));
|
||||
case CHESTPLATE:
|
||||
getPlayer().getInventory().setChestplate(BukkitConverter.fromItemStack(item));
|
||||
case LEGGINGS:
|
||||
getPlayer().getInventory().setLeggings(BukkitConverter.fromItemStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return getPlayer().isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmor(ItemStack[] armor) {
|
||||
org.bukkit.inventory.ItemStack[] stacks = new org.bukkit.inventory.ItemStack[armor.length];
|
||||
for (int i = 0; i < armor.length; ++i) {
|
||||
stacks[i] = BukkitConverter.fromItemStack(armor[i]);
|
||||
}
|
||||
getPlayer().getInventory().setArmorContents(stacks);
|
||||
}
|
||||
|
||||
private org.bukkit.entity.Player getPlayer() {
|
||||
return (org.bukkit.entity.Player) entity;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package net.citizensnpcs.abstraction.bukkit;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.Server;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class BukkitServer implements Server {
|
||||
private final Plugin plugin;
|
||||
|
||||
public BukkitServer(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callEvent(Object event) {
|
||||
Bukkit.getPluginManager().callEvent((Event) event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEvents(Object listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) listener, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(Runnable task) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(Runnable task, long delay) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleRepeating(Runnable task, long delay) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, 0, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleRepeating(Runnable task, long initialDelay, long repeatDelay) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, initialDelay, repeatDelay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterAll(Object listener) {
|
||||
HandlerList.unregisterAll((Listener) listener);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package net.citizensnpcs.command;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.acl.Owner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
@ -15,8 +16,10 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.abstraction.ConsoleCommandSender;
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.attachment.builtin.Owner;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||
@ -26,11 +29,6 @@ import net.citizensnpcs.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class CommandManager {
|
||||
@ -109,7 +107,7 @@ public class CommandManager {
|
||||
|
||||
if (npc != null) {
|
||||
Set<MobType> types = Sets.newEnumSet(Arrays.asList(cmdRequirements.types()), MobType.class);
|
||||
if (types.contains(EntityType.UNKNOWN))
|
||||
if (types.contains(MobType.UNKNOWN))
|
||||
types = EnumSet.allOf(MobType.class);
|
||||
types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes()));
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.CitizensBukkit;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.Command;
|
||||
@ -10,13 +11,11 @@ import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Requirements
|
||||
public class AdminCommands {
|
||||
private final Citizens plugin;
|
||||
private final CitizensBukkit plugin;
|
||||
|
||||
public AdminCommands(Citizens plugin) {
|
||||
public AdminCommands(CitizensBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
@ -9,9 +11,6 @@ import net.citizensnpcs.editor.EquipmentEditor;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class EditorCommands {
|
||||
|
||||
@ -23,8 +22,8 @@ public class EditorCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG,
|
||||
EntityType.SHEEP })
|
||||
@Requirements(selected = true, ownership = true, types = { MobType.ENDERMAN, MobType.PLAYER, MobType.PIG,
|
||||
MobType.SHEEP })
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
|
||||
}
|
||||
@ -37,10 +36,10 @@ public class EditorCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.ENDER_DRAGON, EntityType.SQUID,
|
||||
EntityType.GHAST, EntityType.BLAZE })
|
||||
@Requirements(selected = true, ownership = true, excludedTypes = { MobType.ENDER_DRAGON, MobType.SQUID,
|
||||
MobType.GHAST, MobType.BLAZE })
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
||||
Editor.enterOrLeave(player, npc.getAttachment(Waypoints.class).getEditor(player));
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -52,6 +51,6 @@ public class EditorCommands {
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
public void text(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
|
||||
Editor.enterOrLeave(player, npc.getAttachment(Text.class).getEditor(player));
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.CitizensBukkit;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
@ -13,13 +14,11 @@ import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.util.Paginator;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Requirements
|
||||
public class HelpCommands {
|
||||
private final Citizens plugin;
|
||||
private final CitizensBukkit plugin;
|
||||
|
||||
public HelpCommands(Citizens plugin) {
|
||||
public HelpCommands(CitizensBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import java.security.acl.Owner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.CitizensBukkit;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.attachment.builtin.Owner;
|
||||
import net.citizensnpcs.api.attachment.builtin.Spawned;
|
||||
import net.citizensnpcs.api.abstraction.entity.Ageable;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.citizensnpcs.command.Command;
|
||||
@ -31,7 +32,6 @@ import net.citizensnpcs.util.Paginator;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
@ -42,7 +42,7 @@ public class NPCCommands {
|
||||
private final NPCRegistry npcRegistry;
|
||||
private final NPCSelector selector;
|
||||
|
||||
public NPCCommands(Citizens plugin) {
|
||||
public NPCCommands(CitizensBukkit plugin) {
|
||||
npcRegistry = CitizensAPI.getNPCRegistry();
|
||||
selector = plugin.getNPCSelector();
|
||||
}
|
||||
@ -90,7 +90,7 @@ public class NPCCommands {
|
||||
public void behaviour(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Iterable<String> files = Splitter.on(',').split(args.getJoinedStrings(1, ','));
|
||||
npc.getAttachment(Behaviour.class).addScripts(files);
|
||||
sender.sendMessage(ChatColor.GREEN + "Behaviours added.");
|
||||
sender.sendMessage("<a>Behaviours added.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -187,12 +187,11 @@ public class NPCCommands {
|
||||
msg += ".";
|
||||
|
||||
// Initialize necessary traits
|
||||
npc.addTrait(Owner.class);
|
||||
npc.attach(Owner.class);
|
||||
if (!Setting.SERVER_OWNS_NPCS.asBoolean())
|
||||
npc.getAttachment(Owner.class).setOwner(player.getName());
|
||||
npc.getAttachment(MobType.class).setType(type.toString());
|
||||
npc.addTrait(LookClose.class);
|
||||
npc.addTrait(Text.class);
|
||||
npc.attach(LookClose.class);
|
||||
npc.attach(Text.class);
|
||||
|
||||
npc.spawn(player.getLocation());
|
||||
|
||||
@ -213,7 +212,6 @@ public class NPCCommands {
|
||||
max = 1,
|
||||
permission = "npc.despawn")
|
||||
public void despawn(CommandContext args, CommandSender sender, NPC npc) {
|
||||
npc.getAttachment(Spawned.class).setSpawned(false);
|
||||
npc.despawn();
|
||||
Messaging.send(sender, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ package net.citizensnpcs.command.command;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.CitizensBukkit;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.scripting.CompileCallback;
|
||||
import net.citizensnpcs.api.scripting.Script;
|
||||
@ -13,14 +14,12 @@ import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
public class ScriptCommands {
|
||||
private final Citizens plugin;
|
||||
private final CitizensBukkit plugin;
|
||||
|
||||
public ScriptCommands(Citizens plugin) {
|
||||
public ScriptCommands(CitizensBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,11 @@ package net.citizensnpcs.editor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.Listener;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class Editor implements Listener {
|
||||
public abstract void begin();
|
||||
|
||||
@ -16,32 +15,32 @@ public abstract class Editor implements Listener {
|
||||
|
||||
private static final Map<String, Editor> editing = new HashMap<String, Editor>();
|
||||
|
||||
private static void enter(Player player, Editor editor) {
|
||||
private static void enter(String player, Editor editor) {
|
||||
editor.begin();
|
||||
player.getServer().getPluginManager()
|
||||
.registerEvents(editor, player.getServer().getPluginManager().getPlugin("Citizens"));
|
||||
editing.put(player.getName(), editor);
|
||||
CitizensAPI.getServer().registerEvents(editor);
|
||||
editing.put(player.toLowerCase(), editor);
|
||||
}
|
||||
|
||||
public static void enterOrLeave(Player player, Editor editor) {
|
||||
Editor edit = editing.get(player.getName());
|
||||
if (edit == null)
|
||||
enter(player, editor);
|
||||
else if (edit.getClass() == editor.getClass())
|
||||
leave(player);
|
||||
else
|
||||
Editor edit = editing.get(player.getName().toLowerCase());
|
||||
if (edit == null) {
|
||||
enter(player.getName(), editor);
|
||||
} else if (edit.getClass() == editor.getClass()) {
|
||||
leave(player.getName());
|
||||
} else
|
||||
Messaging.sendError(player, "You're already in an editor!");
|
||||
}
|
||||
|
||||
public static boolean hasEditor(Player player) {
|
||||
return editing.containsKey(player.getName());
|
||||
public static boolean hasEditor(String player) {
|
||||
return editing.containsKey(player.toLowerCase());
|
||||
}
|
||||
|
||||
public static void leave(Player player) {
|
||||
public static void leave(String player) {
|
||||
player = player.toLowerCase();
|
||||
if (!hasEditor(player))
|
||||
return;
|
||||
Editor editor = editing.remove(player.getName());
|
||||
HandlerList.unregisterAll(editor);
|
||||
Editor editor = editing.remove(player);
|
||||
CitizensAPI.getServer().unregisterAll(editor);
|
||||
editor.end();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
|
||||
public interface Equipable {
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import net.citizensnpcs.abstraction.bukkit.BukkitPlayer;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -33,7 +34,7 @@ public class EquipmentEditor extends Editor {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR && Editor.hasEditor(event.getPlayer()))
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR && Editor.hasEditor(event.getPlayer().getName()))
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ public class EquipmentEditor extends Editor {
|
||||
return;
|
||||
|
||||
if (npc instanceof Equipable) {
|
||||
((Equipable) npc).equip(event.getPlayer());
|
||||
((Equipable) npc).equip(new BukkitPlayer(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import net.citizensnpcs.Metrics;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.attachment.AttachmentFactory;
|
||||
import net.citizensnpcs.api.attachment.AttachmentInfo;
|
||||
@ -22,4 +23,9 @@ public class CitizensAttachmentFactory implements AttachmentFactory {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void addPlotters(Metrics metrics) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,10 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityTypes;
|
||||
import net.minecraft.server.World;
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class CitizensMobNPC extends CitizensNPC {
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.LivingEntity;
|
||||
import net.citizensnpcs.api.abstraction.WorldVector;
|
||||
import net.citizensnpcs.api.abstraction.entity.LivingEntity;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.attachment.builtin.Spawned;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
@ -15,14 +14,16 @@ import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
public class CitizensNPC extends AbstractNPC {
|
||||
public CitizensNPC(String name) {
|
||||
super(CitizensAPI.getNPCRegistry(), name);
|
||||
}
|
||||
private boolean spawned;
|
||||
|
||||
public CitizensNPC(NPCRegistry registry, String name) {
|
||||
super(registry, name);
|
||||
}
|
||||
|
||||
public CitizensNPC(String name) {
|
||||
super(CitizensAPI.getNPCRegistry(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean despawn() {
|
||||
if (!isSpawned()) {
|
||||
@ -37,6 +38,17 @@ public class CitizensNPC extends AbstractNPC {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Attachment getAttachmentFor(Class<? extends Attachment> clazz) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
private Attachment getAttachmentFor(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return (LivingEntity) controller.getEntity();
|
||||
@ -47,22 +59,16 @@ public class CitizensNPC extends AbstractNPC {
|
||||
return getEntity() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Attachment getAttachmentFor(Class<? extends Attachment> clazz) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void load(DataKey root) {
|
||||
// Load traits
|
||||
for (DataKey attachmentKey : root.getRelative("traits").getSubKeys()) {
|
||||
Attachment trait = attachmentFactory.getTrait(attachmentKey.name(), this);
|
||||
Attachment trait = getAttachmentFor(attachmentKey.name());
|
||||
if (trait == null) {
|
||||
Messaging.severeF("Skipped missing attachment '%s' while loading NPC ID: '%d'. Has the name changed?",
|
||||
attachmentKey.name(), getId());
|
||||
continue;
|
||||
}
|
||||
addAttachment(trait);
|
||||
attach(trait);
|
||||
try {
|
||||
getAttachment(trait.getClass()).load(attachmentKey);
|
||||
} catch (NPCLoadException ex) {
|
||||
@ -72,7 +78,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
|
||||
// Spawn the NPC
|
||||
if (getAttachment(Spawned.class).shouldSpawn()) {
|
||||
spawned = root.getBoolean("spawned");
|
||||
if (spawned) {
|
||||
WorldVector spawnLoc = getAttachment(CurrentLocation.class).getLocation();
|
||||
if (spawnLoc != null)
|
||||
spawn(spawnLoc);
|
||||
@ -80,7 +87,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
|
||||
public void save(DataKey root) {
|
||||
root.setString("name", getFullName());
|
||||
root.setString("name", name);
|
||||
// Save all existing traits
|
||||
for (Attachment trait : attachments.values()) {
|
||||
trait.save(root.getRelative("traits." + trait.getName()));
|
||||
@ -104,7 +111,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
// Set the spawned state
|
||||
getAttachment(CurrentLocation.class).setLocation(at);
|
||||
getAttachment(Spawned.class).setSpawned(true);
|
||||
spawned = true;
|
||||
|
||||
// Modify NPC using traits after the entity has been created
|
||||
for (Attachment attached : attachments.values())
|
||||
|
@ -38,7 +38,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
|
||||
@Override
|
||||
public NPC createAndSpawn(String name, WorldVector at, MobType type) {
|
||||
NPC npc = new CitizensNPC(this, name);
|
||||
CitizensNPC npc = new CitizensNPC(this, name);
|
||||
npc.setEntityController(null); // TODO;
|
||||
npc.spawn(at);
|
||||
return npc;
|
||||
|
@ -1,19 +1,14 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.security.acl.Owner;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.Equipment;
|
||||
import net.citizensnpcs.api.abstraction.MobType;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitFactory;
|
||||
import net.citizensnpcs.api.trait.TraitManager;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.api.trait.trait.Inventory;
|
||||
import net.citizensnpcs.api.trait.trait.MobType;
|
||||
import net.citizensnpcs.api.trait.trait.Owner;
|
||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.trait.Age;
|
||||
import net.citizensnpcs.trait.Behaviour;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
@ -27,8 +22,6 @@ import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CitizensTraitManager implements TraitManager {
|
||||
private final Map<Class<? extends Trait>, Constructor<? extends Trait>> CACHED_CTORS = new HashMap<Class<? extends Trait>, Constructor<? extends Trait>>();
|
||||
private final Map<Plugin, Map<String, Class<? extends Trait>>> registered = new HashMap<Plugin, Map<String, Class<? extends Trait>>>();
|
||||
|
@ -1,9 +1,13 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import java.security.acl.Owner;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.event.NPCRemoveEvent;
|
||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -11,24 +15,11 @@ import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.mozilla.javascript.ContextFactory.Listener;
|
||||
|
||||
public class NPCSelector implements Listener {
|
||||
private final Plugin plugin;
|
||||
private int consoleSelectedNPC = -1;
|
||||
|
||||
public NPCSelector(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNPCRightClick(NPCRightClickEvent event) {
|
||||
Player player = event.getClicker();
|
||||
|
@ -1,11 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
|
||||
import org.bukkit.entity.Blaze;
|
||||
|
||||
public class CitizensBlazeNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityCaveSpider;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.CaveSpider;
|
||||
|
||||
public class CitizensCaveSpiderNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityChicken;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Chicken;
|
||||
|
||||
public class CitizensChickenNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityCow;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Cow;
|
||||
|
||||
public class CitizensCowNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,15 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityCreeper;
|
||||
import net.minecraft.server.EntityWeatherLighting;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Creeper;
|
||||
|
||||
public class CitizensCreeperNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityEnderDragon;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
|
||||
public class CitizensEnderDragonNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,21 +1,15 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.Equipment;
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.Material;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.minecraft.server.EntityEnderman;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityGhast;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Ghast;
|
||||
|
||||
public class CitizensGhastNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityGiantZombie;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Giant;
|
||||
|
||||
public class CitizensGiantNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,21 +1,16 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.api.abstraction.Equipment;
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.Material;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityIronGolem;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.IronGolem;
|
||||
|
||||
public class CitizensIronGolemNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityMagmaCube;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.MagmaCube;
|
||||
|
||||
public class CitizensMagmaCubeNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityMushroomCow;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.MushroomCow;
|
||||
|
||||
public class CitizensMushroomCowNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityOcelot;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Ocelot;
|
||||
|
||||
public class CitizensOcelotNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,22 +1,16 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.Material;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.citizensnpcs.trait.Saddle;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntityPig;
|
||||
import net.minecraft.server.EntityWeatherLighting;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityPigZombie;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.PigZombie;
|
||||
|
||||
public class CitizensPigZombieNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,23 +1,18 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.ItemStack;
|
||||
import net.citizensnpcs.api.abstraction.Material;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.abstraction.entity.Sheep;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.editor.Equipable;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.citizensnpcs.trait.Sheared;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.minecraft.server.EntitySheep;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySilverfish;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Silverfish;
|
||||
|
||||
public class CitizensSilverfishNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,11 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import java.rmi.server.Skeleton;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySkeleton;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Skeleton;
|
||||
|
||||
public class CitizensSkeletonNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySlime;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Slime;
|
||||
|
||||
public class CitizensSlimeNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySnowman;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Snowman;
|
||||
|
||||
public class CitizensSnowmanNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySpider;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Spider;
|
||||
|
||||
public class CitizensSpiderNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntitySquid;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Squid;
|
||||
|
||||
public class CitizensSquidNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityVillager;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
public class CitizensVillagerNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityWolf;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Wolf;
|
||||
|
||||
public class CitizensWolfNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensMobNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.minecraft.server.EntityZombie;
|
||||
import net.minecraft.server.PathfinderGoalSelector;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
public class CitizensZombieNPC extends CitizensMobNPC {
|
||||
|
||||
|
@ -2,19 +2,12 @@ package net.citizensnpcs.npc.entity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHandle;
|
||||
import net.citizensnpcs.npc.network.NPCNetHandler;
|
||||
import net.citizensnpcs.npc.network.NPCNetworkManager;
|
||||
import net.citizensnpcs.npc.network.NPCSocket;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Navigation;
|
||||
import net.minecraft.server.NetHandler;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
||||
private CitizensNPC npc;
|
||||
|
@ -1,21 +1,5 @@
|
||||
package net.citizensnpcs.npc.network;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.NetServerHandler;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.Packet;
|
||||
import net.minecraft.server.Packet102WindowClick;
|
||||
import net.minecraft.server.Packet106Transaction;
|
||||
import net.minecraft.server.Packet10Flying;
|
||||
import net.minecraft.server.Packet130UpdateSign;
|
||||
import net.minecraft.server.Packet14BlockDig;
|
||||
import net.minecraft.server.Packet15Place;
|
||||
import net.minecraft.server.Packet16BlockItemSwitch;
|
||||
import net.minecraft.server.Packet255KickDisconnect;
|
||||
import net.minecraft.server.Packet28EntityVelocity;
|
||||
import net.minecraft.server.Packet3Chat;
|
||||
import net.minecraft.server.Packet51MapChunk;
|
||||
|
||||
public class NPCNetHandler extends NetServerHandler {
|
||||
|
||||
|
@ -3,10 +3,6 @@ package net.citizensnpcs.npc.network;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Socket;
|
||||
|
||||
import net.minecraft.server.NetHandler;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.Packet;
|
||||
|
||||
public class NPCNetworkManager extends NetworkManager {
|
||||
|
||||
public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) {
|
||||
|
@ -1,15 +1,13 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Ageable;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.entity.Ageable;
|
||||
|
||||
public class Age extends Attachment implements Runnable, Toggleable {
|
||||
private int age = 0;
|
||||
private boolean locked = true;
|
||||
private boolean ageable = false;
|
||||
private final NPC npc;
|
||||
|
||||
@ -19,18 +17,16 @@ public class Age extends Attachment implements Runnable, Toggleable {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (npc.isSpawned() && !(npc.getBukkitEntity() instanceof Ageable))
|
||||
if (npc.isSpawned() && !(npc.getEntity() instanceof Ageable))
|
||||
throw new NPCLoadException("NPC must be ageable");
|
||||
age = key.getInt("age");
|
||||
locked = key.getBoolean("locked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (npc instanceof Ageable) {
|
||||
Ageable entity = (Ageable) npc.getBukkitEntity();
|
||||
if (npc.getEntity() instanceof Ageable) {
|
||||
Ageable entity = (Ageable) npc.getEntity();
|
||||
entity.setAge(age);
|
||||
entity.setAgeLock(locked);
|
||||
ageable = true;
|
||||
} else
|
||||
ageable = false;
|
||||
@ -38,32 +34,29 @@ public class Age extends Attachment implements Runnable, Toggleable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!locked && ageable)
|
||||
age = ((Ageable) npc.getBukkitEntity()).getAge();
|
||||
if (ageable)
|
||||
age = ((Ageable) npc.getEntity()).getAge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setInt("age", age);
|
||||
key.setBoolean("locked", locked);
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
if (ageable)
|
||||
((Ageable) npc.getBukkitEntity()).setAge(age);
|
||||
((Ageable) npc.getEntity()).setAge(age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
locked = !locked;
|
||||
if (ageable)
|
||||
((Ageable) npc.getBukkitEntity()).setAgeLock(locked);
|
||||
return locked;
|
||||
ageable = !ageable;
|
||||
return ageable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Age{age=" + age + ",locked=" + locked + "}";
|
||||
return "Age{age=" + age + "}";
|
||||
}
|
||||
}
|
@ -14,8 +14,6 @@ import net.citizensnpcs.api.scripting.CompileCallback;
|
||||
import net.citizensnpcs.api.scripting.ScriptFactory;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
@ -114,7 +112,8 @@ public class Behaviour extends Attachment {
|
||||
private final Map<Goal, Integer> goals = Maps.newHashMap();
|
||||
|
||||
public void addGoal(int priority, Goal goal) {
|
||||
Validate.notNull(goal);
|
||||
if (goal == null)
|
||||
throw new IllegalArgumentException("goal cannot be null");
|
||||
goals.put(goal, priority);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
@ -7,10 +8,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.mozilla.javascript.ContextFactory.Listener;
|
||||
|
||||
//TODO: reduce reliance on CitizensNPC
|
||||
public class Controllable extends Attachment implements Runnable, Listener, Toggleable {
|
||||
|
@ -6,9 +6,6 @@ import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class CurrentLocation extends Attachment implements Runnable {
|
||||
private WorldVector loc;
|
||||
private final NPC npc;
|
||||
|
@ -5,18 +5,15 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.abstraction.WorldVector;
|
||||
import net.citizensnpcs.api.abstraction.entity.Entity;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
public class LookClose extends Attachment implements Runnable, Toggleable {
|
||||
private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
|
||||
private Player lookingAt;
|
||||
private final NPC npc;
|
||||
@ -28,7 +25,7 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
private void faceEntity(Entity from, Entity at) {
|
||||
if (from.getWorld() != at.getWorld())
|
||||
return;
|
||||
Location loc = from.getLocation();
|
||||
WorldVector loc = from.getLocation();
|
||||
|
||||
double xDiff = at.getLocation().getX() - loc.getX();
|
||||
double yDiff = at.getLocation().getY() - loc.getY();
|
||||
@ -43,10 +40,7 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
yaw = yaw + (Math.abs(180 - yaw) * 2);
|
||||
}
|
||||
|
||||
EntityLiving handle = ((CraftLivingEntity) from).getHandle();
|
||||
handle.yaw = (float) yaw - 90;
|
||||
handle.pitch = (float) pitch;
|
||||
handle.X = handle.yaw;
|
||||
from.setRotation((float) yaw - 90, (float) pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,17 +56,17 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
findNewTarget();
|
||||
}
|
||||
if (lookingAt != null) {
|
||||
faceEntity(npc.getBukkitEntity(), lookingAt);
|
||||
faceEntity(npc.getEntity(), lookingAt);
|
||||
}
|
||||
}
|
||||
|
||||
private void findNewTarget() {
|
||||
List<Entity> nearby = npc.getBukkitEntity().getNearbyEntities(2.5, 5, 2.5);
|
||||
List<Entity> nearby = npc.getEntity().getNearbyEntities(2.5, 5, 2.5);
|
||||
Collections.sort(nearby, new Comparator<Entity>() {
|
||||
@Override
|
||||
public int compare(Entity o1, Entity o2) {
|
||||
double d1 = o1.getLocation().distanceSquared(npc.getBukkitEntity().getLocation());
|
||||
double d2 = o2.getLocation().distanceSquared(npc.getBukkitEntity().getLocation());
|
||||
double d1 = o1.getLocation().distanceSquared(npc.getEntity().getLocation());
|
||||
double d2 = o2.getLocation().distanceSquared(npc.getEntity().getLocation());
|
||||
return Double.compare(d1, d2);
|
||||
}
|
||||
});
|
||||
@ -88,8 +82,8 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
private boolean hasInvalidTarget() {
|
||||
if (lookingAt == null)
|
||||
return true;
|
||||
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getBukkitEntity().getWorld()
|
||||
|| lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > 5) {
|
||||
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getEntity().getWorld()
|
||||
|| lookingAt.getLocation().distanceSquared(npc.getEntity().getLocation()) > 5) {
|
||||
lookingAt = null;
|
||||
return true;
|
||||
}
|
||||
@ -103,8 +97,7 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
enabled = !enabled;
|
||||
return enabled;
|
||||
return (enabled = !enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,12 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Creeper;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.entity.Creeper;
|
||||
|
||||
public class Powered extends Trait implements Toggleable {
|
||||
public class Powered extends Attachment implements Toggleable {
|
||||
private final NPC npc;
|
||||
private boolean powered;
|
||||
|
||||
@ -21,9 +20,9 @@ public class Powered extends Trait implements Toggleable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Creeper)
|
||||
((Creeper) npc.getBukkitEntity()).setPowered(powered);
|
||||
public void onSpawn() {
|
||||
if (npc.getEntity() instanceof Creeper)
|
||||
((Creeper) npc.getEntity()).setPowered(powered);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,8 +33,8 @@ public class Powered extends Trait implements Toggleable {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
powered = !powered;
|
||||
if (npc.getBukkitEntity() instanceof Creeper)
|
||||
((Creeper) npc.getBukkitEntity()).setPowered(powered);
|
||||
if (npc.getEntity() instanceof Creeper)
|
||||
((Creeper) npc.getEntity()).setPowered(powered);
|
||||
return powered;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,13 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class Saddle extends Trait implements Toggleable, Listener {
|
||||
public class Saddle extends Attachment implements Toggleable, Listener {
|
||||
private final NPC npc;
|
||||
private boolean saddle;
|
||||
private boolean pig;
|
||||
@ -26,9 +22,9 @@ public class Saddle extends Trait implements Toggleable, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Pig) {
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
public void onSpawn() {
|
||||
if (npc.getEntity() instanceof Pig) {
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
pig = true;
|
||||
} else
|
||||
pig = false;
|
||||
@ -49,7 +45,7 @@ public class Saddle extends Trait implements Toggleable, Listener {
|
||||
public boolean toggle() {
|
||||
saddle = !saddle;
|
||||
if (pig)
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
return saddle;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,15 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.Listener;
|
||||
import net.citizensnpcs.api.abstraction.entity.Sheep;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
|
||||
public class Sheared extends Trait implements Toggleable, Listener {
|
||||
public class Sheared extends Attachment implements Toggleable, Listener {
|
||||
private final NPC npc;
|
||||
private boolean sheared;
|
||||
|
||||
@ -25,8 +23,8 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
public void onSpawn() {
|
||||
((Sheep) npc.getEntity()).setSheared(sheared);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -43,8 +41,8 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
sheared = !sheared;
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
if (npc.getEntity() instanceof Sheep)
|
||||
((Sheep) npc.getEntity()).setSheared(sheared);
|
||||
return sheared;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,6 @@ import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
public class VillagerProfession extends Attachment {
|
||||
private final NPC npc;
|
||||
private Profession profession = Profession.FARMER;
|
||||
|
@ -1,16 +1,14 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.entity.Sheep;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.SheepDyeWoolEvent;
|
||||
import org.mozilla.javascript.ContextFactory.Listener;
|
||||
|
||||
public class WoolColor extends Attachment implements Listener {
|
||||
private DyeColor color = DyeColor.WHITE;
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.NumericPrompt;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PageChangePrompt extends NumericPrompt {
|
||||
private Text text;
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class StartPrompt extends StringPrompt {
|
||||
private final Text text;
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.attachment.Attachment;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -18,14 +19,6 @@ import net.citizensnpcs.trait.Toggleable;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Paginator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.conversations.Conversation;
|
||||
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||
import org.bukkit.conversations.ConversationAbandonedListener;
|
||||
import org.bukkit.conversations.ConversationFactory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class Text extends Attachment implements Runnable, Toggleable, ConversationAbandonedListener {
|
||||
private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>();
|
||||
private int currentIndex;
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextAddPrompt extends StringPrompt {
|
||||
private Text text;
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextEditPrompt extends StringPrompt {
|
||||
private Text text;
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextEditStartPrompt extends StringPrompt {
|
||||
private Text text;
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
package net.citizensnpcs.trait.text;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextRemovePrompt extends StringPrompt {
|
||||
private final Text text;
|
||||
|
||||
|
@ -3,21 +3,15 @@ package net.citizensnpcs.trait.waypoint;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.ai.NavigationCallback;
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.EventHandler;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoint> {
|
||||
@ -59,6 +53,8 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
Messaging.send(player, String.format("<e>Added<a> a waypoint at (" + formatLoc(at)
|
||||
+ ") (<e>%d<a>, <e>%d<a>)", editingSlot + 1, waypoints.size()));
|
||||
} else if (waypoints.size() > 0) {
|
||||
editingSlot = Math.min(0, Math.max(waypoints.size() - 1, editingSlot));
|
||||
// normalise editing slot.
|
||||
waypoints.remove(editingSlot);
|
||||
editingSlot = Math.max(0, editingSlot - 1);
|
||||
Messaging.send(player, String.format("<e>Removed<a> a waypoint (<e>%d<a> remaining) (<e>%d<a>)",
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
public class Waypoint {
|
||||
private final Location location;
|
||||
|
@ -1,12 +1,10 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.ai.AI;
|
||||
import net.citizensnpcs.api.ai.NavigationCallback;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface WaypointProvider {
|
||||
|
||||
/**
|
||||
|
@ -4,14 +4,12 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Waypoints extends Trait {
|
||||
private final NPC npc;
|
||||
private WaypointProvider provider = new LinearWaypointProvider();
|
||||
|
@ -1,17 +1,14 @@
|
||||
package net.citizensnpcs.util;
|
||||
|
||||
import java.security.acl.Owner;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
import net.citizensnpcs.api.abstraction.Player;
|
||||
import net.citizensnpcs.api.attachment.builtin.Owner;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
public class Messaging {
|
||||
|
@ -3,7 +3,7 @@ package net.citizensnpcs.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import net.citizensnpcs.api.abstraction.CommandSender;
|
||||
|
||||
public class Paginator {
|
||||
private String header;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.citizensnpcs.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class StringHelper {
|
||||
|
||||
|
@ -6,16 +6,13 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.abstraction.Material;
|
||||
import net.citizensnpcs.api.abstraction.World;
|
||||
import net.citizensnpcs.api.abstraction.entity.Player;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.Packet;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
Loading…
Reference in New Issue
Block a user