mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 20:55:44 +01:00
changes
This commit is contained in:
parent
0ef4192769
commit
a4b1858c3a
Binary file not shown.
@ -1,5 +1,8 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -8,11 +11,19 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.editor.EquipmentEditor;
|
||||
import net.citizensnpcs.editor.TextEditor;
|
||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class EditorCommands {
|
||||
private final Citizens plugin;
|
||||
private static final Map<String, Editor> editors = new HashMap<String, Editor>();
|
||||
|
||||
public EditorCommands(Citizens plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -25,17 +36,19 @@ public class EditorCommands {
|
||||
permission = "npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, type = EntityType.PLAYER)
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
toggleEditor(player, npc, "equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "path",
|
||||
desc = "Toggle the waypoint editor",
|
||||
modifiers = { "path", "waypoints" },
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
toggleEditor(player, npc, "path");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -47,5 +60,38 @@ public class EditorCommands {
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
public void text(CommandContext args, Player player, NPC npc) {
|
||||
toggleEditor(player, npc, "text");
|
||||
}
|
||||
|
||||
public static void removeEditor(Player player) {
|
||||
if (editors.containsKey(player.getName()))
|
||||
editors.remove(player.getName());
|
||||
}
|
||||
|
||||
private void toggleEditor(Player player, NPC npc, String name) {
|
||||
if (editors.containsKey(player.getName())) {
|
||||
if (editors.get(player.getName()).getName().equals(name)) {
|
||||
editors.get(player.getName()).end();
|
||||
editors.remove(player.getName());
|
||||
} else {
|
||||
Messaging.sendError(player, "You can only be in one editor at a time.");
|
||||
Messaging.sendError(player, "Type /npc " + name + " to exit the current editor.");
|
||||
}
|
||||
} else {
|
||||
Editor editor = getEditor(player, npc, name);
|
||||
editors.put(player.getName(), editor);
|
||||
editor.begin();
|
||||
}
|
||||
}
|
||||
|
||||
private Editor getEditor(Player player, NPC npc, String name) {
|
||||
if (name.equals("equip"))
|
||||
return new EquipmentEditor(plugin, player, npc);
|
||||
else if (name.equals("path"))
|
||||
return npc.getTrait(Waypoints.class).getEditor(player);
|
||||
else if (name.equals("text"))
|
||||
return new TextEditor();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,38 +1,12 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
public interface Editor extends Listener {
|
||||
|
||||
public abstract class Editor implements Listener {
|
||||
public abstract void begin();
|
||||
public void begin();
|
||||
|
||||
public abstract void end();
|
||||
public void end();
|
||||
|
||||
public static void enterEditor(Player player, Editor editor) {
|
||||
if (editing.containsKey(player.getName())) {
|
||||
Messaging.sendError(player, "You're already in an editor!");
|
||||
return;
|
||||
}
|
||||
editor.begin();
|
||||
Bukkit.getPluginManager().registerEvents(editor, Bukkit.getPluginManager().getPlugin("Citizens"));
|
||||
editing.put(player.getName(), editor);
|
||||
}
|
||||
|
||||
public static void leaveEditor(Player player) {
|
||||
if (!editing.containsKey(player.getName()))
|
||||
return;
|
||||
Editor editor = editing.remove(player.getName());
|
||||
HandlerList.unregisterAll(editor);
|
||||
editor.end();
|
||||
}
|
||||
|
||||
private static final Map<String, Editor> editing = Maps.newHashMap();
|
||||
public String getName();
|
||||
}
|
@ -1,12 +1,60 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
public class EquipmentEditor extends Editor {
|
||||
import net.citizensnpcs.Citizens;
|
||||
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.HandlerList;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class EquipmentEditor implements Editor {
|
||||
private final Citizens plugin;
|
||||
private final Player player;
|
||||
private final NPC npc;
|
||||
|
||||
public EquipmentEditor(Citizens plugin, Player player, NPC npc) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
Messaging.send(player, "<a>Entered the equipment editor!");
|
||||
Messaging.send(player, "<a>Right click to equip armor and items.");
|
||||
Messaging.send(player, "<a>Right click while crouching to equip armor in the NPC's hand.");
|
||||
Messaging.send(player, "<a>Left click to remove all armor and items.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
HandlerList.unregisterAll(this);
|
||||
Messaging.send(player, "<a>Exited equipment editor.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "equip";
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR && event.getPlayer().getName().equals(player.getName()))
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (plugin.getNPCManager().isNPC(event.getRightClicked())
|
||||
&& plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|
||||
&& event.getPlayer().getName().equals(player.getName())) {
|
||||
npc.chat("You clicked me!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
public class PathEditor extends Editor {
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
public class TextEditor extends Editor {
|
||||
public class TextEditor implements Editor {
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
@ -9,4 +9,9 @@ public class TextEditor extends Editor {
|
||||
@Override
|
||||
public void end() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "text";
|
||||
}
|
||||
}
|
@ -33,6 +33,11 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "path";
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SuppressWarnings("unused")
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
|
@ -7,6 +7,7 @@ import net.citizensnpcs.editor.Editor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface WaypointProvider {
|
||||
|
||||
public Editor createEditor(Player player);
|
||||
|
||||
public void load(DataKey key);
|
||||
|
@ -8,16 +8,17 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class StorageUtils {
|
||||
|
||||
public static Location loadLocation(DataKey root) {
|
||||
root = root.getRelative("location");
|
||||
return new Location(Bukkit.getWorld(root.getString("world")), root.getDouble("x"), root.getDouble("y"),
|
||||
root.getDouble("z"), (float) root.getDouble("yaw", 0), (float) root.getDouble("pitch", 0));
|
||||
return new Location(Bukkit.getWorld(root.getString("world")), root.getDouble("x"), root.getDouble("y"), root
|
||||
.getDouble("z"), (float) root.getDouble("yaw", 0), (float) root.getDouble("pitch", 0));
|
||||
}
|
||||
|
||||
public static ItemStack loadItemStack(DataKey root) {
|
||||
root = root.getRelative("item");
|
||||
return new ItemStack(Material.matchMaterial(root.getString("id")), root.getInt("amount"),
|
||||
(short) (root.keyExists("data") ? root.getInt("data") : 0));
|
||||
return new ItemStack(Material.matchMaterial(root.getString("id")), root.getInt("amount"), (short) (root
|
||||
.keyExists("data") ? root.getInt("data") : 0));
|
||||
}
|
||||
|
||||
public static void saveLocation(DataKey key, Location location) {
|
||||
|
Loading…
Reference in New Issue
Block a user