mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-26 02:57:39 +01:00
Changes
This commit is contained in:
parent
492d2cf6cb
commit
565f4ec8cb
@ -3,6 +3,7 @@ package net.citizensnpcs;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
@ -11,6 +12,7 @@ import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.exception.NPCException;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.character.CharacterManager;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.DatabaseStorage;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
@ -50,13 +52,15 @@ public class Citizens extends JavaPlugin {
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.2.3";
|
||||
|
||||
private final CommandManager commands = new CommandManager();
|
||||
private boolean compatible;
|
||||
private Settings config;
|
||||
private CitizensCharacterManager characterManager;
|
||||
private volatile CitizensNPCManager npcManager;
|
||||
private Storage saves;
|
||||
private boolean compatible;
|
||||
private final CitizensCharacterManager characterManager = new CitizensCharacterManager();
|
||||
private final CitizensTraitManager traitManager = new CitizensTraitManager();
|
||||
private CitizensNPCManager npcManager;
|
||||
private Storage saves; // TODO: refactor this into an NPCStore (remove
|
||||
// dependency on Storage).
|
||||
|
||||
public CitizensCharacterManager getCharacterManager() {
|
||||
public CharacterManager getCharacterManager() {
|
||||
return characterManager;
|
||||
}
|
||||
|
||||
@ -68,10 +72,6 @@ public class Citizens extends JavaPlugin {
|
||||
return npcManager;
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return saves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
|
||||
Player player = null;
|
||||
@ -123,8 +123,12 @@ public class Citizens extends JavaPlugin {
|
||||
// Don't bother with this part if MC versions are not compatible
|
||||
if (compatible) {
|
||||
save();
|
||||
for (NPC npc : npcManager)
|
||||
npc.despawn();
|
||||
Iterator<NPC> itr = npcManager.iterator();
|
||||
while (itr.hasNext()) {
|
||||
itr.next().despawn();
|
||||
itr.remove();
|
||||
}
|
||||
npcManager = null;
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
@ -143,8 +147,7 @@ public class Citizens extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
// Configuration file
|
||||
config = new Settings(this);
|
||||
config = new Settings(this.getDataFolder());
|
||||
config.load();
|
||||
|
||||
// NPC storage
|
||||
@ -161,11 +164,10 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Register API managers
|
||||
npcManager = new CitizensNPCManager(saves);
|
||||
characterManager = new CitizensCharacterManager();
|
||||
npcManager = new CitizensNPCManager(this, saves);
|
||||
CitizensAPI.setNPCManager(npcManager);
|
||||
CitizensAPI.setCharacterManager(characterManager);
|
||||
CitizensAPI.setTraitManager(new CitizensTraitManager());
|
||||
CitizensAPI.setTraitManager(traitManager);
|
||||
|
||||
// Register events
|
||||
getServer().getPluginManager().registerEvents(new EventListen(npcManager), this);
|
||||
@ -231,10 +233,8 @@ public class Citizens extends JavaPlugin {
|
||||
public void reload() throws NPCLoadException {
|
||||
Editor.leaveAll();
|
||||
config.load();
|
||||
for (NPC npc : npcManager)
|
||||
npc.despawn();
|
||||
|
||||
saves.load();
|
||||
npcManager.removeAll();
|
||||
setupNPCs();
|
||||
|
||||
getServer().getPluginManager().callEvent(new CitizensReloadEvent());
|
||||
@ -242,8 +242,9 @@ public class Citizens extends JavaPlugin {
|
||||
|
||||
public void save() {
|
||||
config.save();
|
||||
for (NPC npc : npcManager)
|
||||
for (NPC npc : npcManager) {
|
||||
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
||||
}
|
||||
saves.save();
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,15 @@ package net.citizensnpcs;
|
||||
import java.io.File;
|
||||
|
||||
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 YamlStorage config;
|
||||
private final Storage config;
|
||||
|
||||
public Settings(Citizens plugin) {
|
||||
config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml", "Citizens Configuration");
|
||||
public Settings(File folder) {
|
||||
config = new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
@ -7,8 +7,8 @@ import java.util.logging.Level;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
public class Injector {
|
||||
private Class<?>[] argClasses;
|
||||
private Object[] args;
|
||||
private final Class<?>[] argClasses;
|
||||
private final Object[] args;
|
||||
|
||||
public Injector(Object... args) {
|
||||
this.args = args;
|
||||
@ -24,9 +24,13 @@ public class Injector {
|
||||
ctr.setAccessible(true);
|
||||
return ctr.newInstance(args);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Messaging.log(Level.SEVERE, "Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (Exception ex) {
|
||||
Messaging.log(Level.SEVERE, "Error initializing commands class " + clazz + ": ");
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
Messaging.log(Level.SEVERE, "Error initializing commands class " + clazz + ": ");
|
||||
e.printStackTrace();
|
||||
|
@ -1,9 +1,5 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
@ -13,47 +9,45 @@ 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 {
|
||||
private final Citizens plugin;
|
||||
|
||||
public EditorCommands(Citizens plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "equip",
|
||||
desc = "Toggle the equipment editor",
|
||||
modifiers = { "equip" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
aliases = { "npc" },
|
||||
usage = "equip",
|
||||
desc = "Toggle the equipment editor",
|
||||
modifiers = { "equip" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, type = EntityType.PLAYER)
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, new EquipmentEditor(plugin, player, npc));
|
||||
Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "path",
|
||||
desc = "Toggle the waypoint editor",
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
aliases = { "npc" },
|
||||
usage = "path",
|
||||
desc = "Toggle the waypoint editor",
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "text",
|
||||
desc = "Toggle the text editor",
|
||||
modifiers = { "text" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
aliases = { "npc" },
|
||||
usage = "text",
|
||||
desc = "Toggle the text editor",
|
||||
modifiers = { "text" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
public void text(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ import java.util.List;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.character.Character;
|
||||
import net.citizensnpcs.api.npc.character.CharacterManager;
|
||||
import net.citizensnpcs.api.trait.trait.MobType;
|
||||
import net.citizensnpcs.api.trait.trait.Owner;
|
||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
||||
@ -16,7 +18,6 @@ import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.npc.CitizensCharacterManager;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -30,21 +31,21 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class NPCCommands {
|
||||
private final CitizensCharacterManager characterManager;
|
||||
private final CitizensNPCManager npcManager;
|
||||
private final CharacterManager characterManager = CitizensAPI.getCharacterManager();
|
||||
private final CitizensNPCManager npcManager; // TODO: remove reliance on
|
||||
// CitizensNPCManager
|
||||
|
||||
public NPCCommands(Citizens plugin) {
|
||||
npcManager = plugin.getNPCManager();
|
||||
characterManager = plugin.getCharacterManager();
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "character [character]",
|
||||
desc = "Set the character of an NPC",
|
||||
modifiers = { "character" },
|
||||
min = 2,
|
||||
max = 2)
|
||||
aliases = { "npc" },
|
||||
usage = "character [character]",
|
||||
desc = "Set the character of an NPC",
|
||||
modifiers = { "character" },
|
||||
min = 2,
|
||||
max = 2)
|
||||
public void character(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
String name = args.getString(1).toLowerCase();
|
||||
Character character = characterManager.getCharacter(name);
|
||||
@ -55,19 +56,19 @@ public class NPCCommands {
|
||||
if (!player.hasPermission("citizens.npc.character." + character.getName())
|
||||
&& !player.hasPermission("citizens.npc.character.*") && !player.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
|
||||
+ StringHelper.wrap(name) + "'.");
|
||||
Messaging.send(player,
|
||||
StringHelper.wrap(npc.getName() + "'s") + " character is now '" + StringHelper.wrap(name) + "'.");
|
||||
npc.setCharacter(character);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "create [name] (--type (type) --char (char))",
|
||||
desc = "Create a new NPC",
|
||||
modifiers = { "create" },
|
||||
min = 2,
|
||||
max = 5,
|
||||
permission = "npc.create")
|
||||
aliases = { "npc" },
|
||||
usage = "create [name] (--type (type) --char (char))",
|
||||
desc = "Create a new NPC",
|
||||
modifiers = { "create" },
|
||||
min = 2,
|
||||
max = 5,
|
||||
permission = "npc.create")
|
||||
@Requirements
|
||||
public void create(CommandContext args, Player player, NPC npc) {
|
||||
String name = args.getString(1);
|
||||
@ -116,13 +117,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "despawn",
|
||||
desc = "Despawn an NPC",
|
||||
modifiers = { "despawn" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.despawn")
|
||||
aliases = { "npc" },
|
||||
usage = "despawn",
|
||||
desc = "Despawn an NPC",
|
||||
modifiers = { "despawn" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.despawn")
|
||||
public void despawn(CommandContext args, Player player, NPC npc) {
|
||||
npc.getTrait(Spawned.class).setSpawned(false);
|
||||
npc.despawn();
|
||||
@ -130,14 +131,14 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))",
|
||||
desc = "List NPCs",
|
||||
flags = "a",
|
||||
modifiers = { "list" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.list")
|
||||
aliases = { "npc" },
|
||||
usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))",
|
||||
desc = "List NPCs",
|
||||
flags = "a",
|
||||
modifiers = { "list" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.list")
|
||||
@Requirements
|
||||
public void list(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
List<NPC> npcs = new ArrayList<NPC>();
|
||||
@ -202,13 +203,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "lookclose",
|
||||
desc = "Toggle whether an NPC will look when a player is near",
|
||||
modifiers = { "lookclose", "look", "rotate" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.lookclose")
|
||||
aliases = { "npc" },
|
||||
usage = "lookclose",
|
||||
desc = "Toggle whether an NPC will look when a player is near",
|
||||
modifiers = { "lookclose", "look", "rotate" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.lookclose")
|
||||
public void lookClose(CommandContext args, Player player, NPC npc) {
|
||||
String msg = StringHelper.wrap(npc.getName()) + " will "
|
||||
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
|
||||
@ -225,13 +226,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "owner [name]",
|
||||
desc = "Set the owner of an NPC",
|
||||
modifiers = { "owner" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.owner")
|
||||
aliases = { "npc" },
|
||||
usage = "owner [name]",
|
||||
desc = "Set the owner of an NPC",
|
||||
modifiers = { "owner" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.owner")
|
||||
public void owner(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
String name = args.getString(1);
|
||||
if (npc.getTrait(Owner.class).getOwner().equals(name))
|
||||
@ -242,12 +243,12 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "remove (all)",
|
||||
desc = "Remove an NPC",
|
||||
modifiers = { "remove" },
|
||||
min = 1,
|
||||
max = 2)
|
||||
aliases = { "npc" },
|
||||
usage = "remove (all)",
|
||||
desc = "Remove an NPC",
|
||||
modifiers = { "remove" },
|
||||
min = 1,
|
||||
max = 2)
|
||||
@Requirements
|
||||
public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
if (args.argsLength() == 2) {
|
||||
@ -270,13 +271,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "rename [name]",
|
||||
desc = "Rename an NPC",
|
||||
modifiers = { "rename" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.rename")
|
||||
aliases = { "npc" },
|
||||
usage = "rename [name]",
|
||||
desc = "Rename an NPC",
|
||||
modifiers = { "rename" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.rename")
|
||||
public void rename(CommandContext args, Player player, NPC npc) {
|
||||
String oldName = npc.getName();
|
||||
String newName = args.getString(1);
|
||||
@ -285,18 +286,19 @@ public class NPCCommands {
|
||||
newName = newName.substring(0, 15);
|
||||
}
|
||||
npc.setName(newName);
|
||||
Messaging.send(player, ChatColor.GREEN + "You renamed " + StringHelper.wrap(oldName) + " to "
|
||||
+ StringHelper.wrap(newName) + ".");
|
||||
Messaging.send(player,
|
||||
ChatColor.GREEN + "You renamed " + StringHelper.wrap(oldName) + " to " + StringHelper.wrap(newName)
|
||||
+ ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "select [id]",
|
||||
desc = "Select an NPC with the given ID",
|
||||
modifiers = { "select" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.select")
|
||||
aliases = { "npc" },
|
||||
usage = "select [id]",
|
||||
desc = "Select an NPC with the given ID",
|
||||
modifiers = { "select" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.select")
|
||||
@Requirements(ownership = true)
|
||||
public void select(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
NPC toSelect = npcManager.getNPC(args.getInteger(1));
|
||||
@ -309,13 +311,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "spawn [id]",
|
||||
desc = "Spawn an existing NPC",
|
||||
modifiers = { "spawn" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.spawn")
|
||||
aliases = { "npc" },
|
||||
usage = "spawn [id]",
|
||||
desc = "Spawn an existing NPC",
|
||||
modifiers = { "spawn" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.spawn")
|
||||
@Requirements
|
||||
public void spawn(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
NPC respawn = npcManager.getNPC(args.getInteger(1));
|
||||
@ -335,13 +337,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "tp",
|
||||
desc = "Teleport to an NPC",
|
||||
modifiers = { "tp", "teleport" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.tp")
|
||||
aliases = { "npc" },
|
||||
usage = "tp",
|
||||
desc = "Teleport to an NPC",
|
||||
modifiers = { "tp", "teleport" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.tp")
|
||||
public void tp(CommandContext args, Player player, NPC npc) {
|
||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||
if (!npc.isSpawned())
|
||||
@ -351,13 +353,13 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "tphere",
|
||||
desc = "Teleport an NPC to your location",
|
||||
modifiers = { "tphere" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.tphere")
|
||||
aliases = { "npc" },
|
||||
usage = "tphere",
|
||||
desc = "Teleport an NPC to your location",
|
||||
modifiers = { "tphere" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.tphere")
|
||||
public void tphere(CommandContext args, Player player, NPC npc) {
|
||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||
if (!npc.isSpawned())
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.trait.Equipment;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -17,10 +17,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
public class EquipmentEditor extends Editor {
|
||||
private final NPC npc;
|
||||
private final Player player;
|
||||
private final Citizens plugin;
|
||||
|
||||
public EquipmentEditor(Citizens plugin, Player player, NPC npc) {
|
||||
this.plugin = plugin;
|
||||
public EquipmentEditor(Player player, NPC npc) {
|
||||
this.player = player;
|
||||
this.npc = npc;
|
||||
}
|
||||
@ -46,8 +44,8 @@ public class EquipmentEditor extends Editor {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!plugin.getNPCManager().isNPC(event.getRightClicked())
|
||||
|| !plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|
||||
if (!CitizensAPI.getNPCManager().isNPC(event.getRightClicked())
|
||||
|| !CitizensAPI.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|
||||
|| !event.getPlayer().equals(player))
|
||||
return;
|
||||
|
||||
|
@ -29,8 +29,8 @@ public class CitizensNPCManager implements NPCManager {
|
||||
private final Citizens plugin;
|
||||
private final Storage saves;
|
||||
|
||||
public CitizensNPCManager(Storage saves) {
|
||||
plugin = (Citizens) Bukkit.getPluginManager().getPlugin("Citizens");
|
||||
public CitizensNPCManager(Citizens plugin, Storage saves) {
|
||||
this.plugin = plugin;
|
||||
this.saves = saves;
|
||||
}
|
||||
|
||||
@ -115,6 +115,7 @@ public class CitizensNPCManager implements NPCManager {
|
||||
iterator().next().remove();
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
public void selectNPC(Player player, NPC npc) {
|
||||
// Remove existing selection if any
|
||||
if (player.hasMetadata("selected"))
|
||||
|
@ -1,111 +0,0 @@
|
||||
package net.citizensnpcs.npc.ai;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Random;
|
||||
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.PathEntity;
|
||||
import net.minecraft.server.Vec3D;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MoveStrategy implements PathStrategy {
|
||||
private Float cachedSpeed;
|
||||
|
||||
private final EntityLiving handle;
|
||||
private final PathEntity path;
|
||||
private final Random random = new Random();
|
||||
|
||||
public MoveStrategy(CitizensNPC handle, Location destination) {
|
||||
this.handle = handle.getHandle();
|
||||
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
|
||||
destination.getBlockZ(), 16F, true, false, false, true);
|
||||
}
|
||||
|
||||
MoveStrategy(EntityLiving handle, PathEntity path) {
|
||||
this.handle = handle;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
private Vec3D getVector() {
|
||||
Vec3D vec3d = path.a(handle);
|
||||
double lengthSq = (handle.width * 2.0F);
|
||||
lengthSq *= lengthSq;
|
||||
while (vec3d != null && vec3d.d(handle.locX, vec3d.b, handle.locZ) < lengthSq) {
|
||||
this.path.a(); // Increment path index.
|
||||
if (this.path.b()) { // finished.
|
||||
return null;
|
||||
}
|
||||
vec3d = this.path.a(handle);
|
||||
}
|
||||
return vec3d;
|
||||
}
|
||||
|
||||
private float getYawDifference(double diffZ, double diffX) {
|
||||
float vectorYaw = (float) (Math.atan2(diffZ, diffX) * 180.0D / Math.PI) - 90.0F;
|
||||
float diffYaw = (vectorYaw - handle.yaw) % 360;
|
||||
return Math.max(-30F, Math.min(30, diffYaw));
|
||||
}
|
||||
|
||||
private void jump() {
|
||||
if (handle.onGround)
|
||||
handle.motY = JUMP_VELOCITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (handle.dead || path == null)
|
||||
return true;
|
||||
Vec3D vector = getVector();
|
||||
if (vector == null)
|
||||
return true;
|
||||
int yHeight = MathHelper.floor(handle.boundingBox.b + 0.5D);
|
||||
boolean inWater = ((Player) handle.getBukkitEntity()).getRemainingAir() < 20;
|
||||
boolean onFire = handle.fireTicks > 0;
|
||||
double diffX = vector.a - handle.locX;
|
||||
double diffZ = vector.c - handle.locZ;
|
||||
float diffYaw = getYawDifference(diffZ, diffX);
|
||||
handle.yaw += diffYaw;
|
||||
// handle.X += diffYaw;
|
||||
|
||||
if (vector.b - yHeight > 0.0D)
|
||||
jump();
|
||||
if (cachedSpeed == null) {
|
||||
try {
|
||||
cachedSpeed = SPEED_FIELD.getFloat(handle);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
cachedSpeed = 0.7F;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
cachedSpeed = 0.7F;
|
||||
}
|
||||
}
|
||||
handle.e(cachedSpeed);
|
||||
handle.e();
|
||||
// handle.walk();
|
||||
|
||||
if (handle.positionChanged)
|
||||
jump();
|
||||
if (random.nextFloat() < 0.8F && (inWater || onFire))
|
||||
handle.motY += 0.04D;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final double JUMP_VELOCITY = 0.49D;
|
||||
|
||||
private static Field SPEED_FIELD;
|
||||
static {
|
||||
try {
|
||||
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb");
|
||||
SPEED_FIELD.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -7,14 +7,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
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 net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -26,12 +18,19 @@ import net.citizensnpcs.trait.Toggleable;
|
||||
import net.citizensnpcs.trait.text.prompt.StartPrompt;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Paginator;
|
||||
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
|
||||
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 Trait implements Runnable, Toggleable, ConversationAbandonedListener {
|
||||
private final Citizens plugin;
|
||||
private final Plugin plugin;
|
||||
private final NPC npc;
|
||||
private final List<String> text = new ArrayList<String>();
|
||||
private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>();
|
||||
@ -41,7 +40,7 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
|
||||
public Text(NPC npc) {
|
||||
this.npc = npc;
|
||||
plugin = (Citizens) Bukkit.getPluginManager().getPlugin("Citizens");
|
||||
this.plugin = Bukkit.getPluginManager().getPlugin("Citizens");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,7 +94,7 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
|
||||
@Override
|
||||
public void conversationAbandoned(ConversationAbandonedEvent event) {
|
||||
plugin.getServer().dispatchCommand((Player) event.getContext().getForWhom(), "npc text");
|
||||
Bukkit.dispatchCommand((Player) event.getContext().getForWhom(), "npc text");
|
||||
}
|
||||
|
||||
public boolean shouldTalkClose() {
|
||||
@ -104,8 +103,8 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
|
||||
public Editor getEditor(final Player player) {
|
||||
final Conversation conversation = new ConversationFactory(plugin).addConversationAbandonedListener(this)
|
||||
.withLocalEcho(false).withEscapeSequence("/npc text").withModality(false).withFirstPrompt(
|
||||
new StartPrompt(this)).buildConversation(player);
|
||||
.withLocalEcho(false).withEscapeSequence("/npc text").withModality(false)
|
||||
.withFirstPrompt(new StartPrompt(this)).buildConversation(player);
|
||||
return new Editor() {
|
||||
|
||||
@Override
|
||||
|
@ -80,39 +80,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private int expected = ByIdArray.this.modCount;
|
||||
private int idx = lowest;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
return highest + 1 > idx && size > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T next() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
T next = (T) elementData[idx];
|
||||
if (next == null || idx > highest)
|
||||
throw new NoSuchElementException();
|
||||
do
|
||||
idx++;
|
||||
while (idx != highest + 1 && elementData[idx] == null);
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
ByIdArray.this.fastRemove(idx);
|
||||
expected = ByIdArray.this.modCount;
|
||||
}
|
||||
};
|
||||
return new Itr();
|
||||
}
|
||||
|
||||
public void put(int index, T t) {
|
||||
@ -165,6 +133,40 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
elementData = Arrays.copyOf(elementData, highest + 1);
|
||||
}
|
||||
|
||||
private class Itr implements Iterator<T> {
|
||||
private int expected = ByIdArray.this.modCount;
|
||||
private int idx = lowest;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
return highest + 1 > idx && size > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T next() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
T next = (T) elementData[idx];
|
||||
if (next == null || idx > highest)
|
||||
throw new NoSuchElementException();
|
||||
do
|
||||
idx++;
|
||||
while (idx != highest + 1 && elementData[idx] == null);
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (ByIdArray.this.modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
ByIdArray.this.fastRemove(idx);
|
||||
expected = ByIdArray.this.modCount;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> ByIdArray<T> create() {
|
||||
return new ByIdArray<T>();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user