mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
changes to text editing, added click to talk and some talk settings
This commit is contained in:
parent
b6b00f8fef
commit
de6d1b7e18
@ -7,6 +7,7 @@ import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -112,7 +113,10 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// TODO NPC text
|
||||
if ((player.hasPermission("citizens.npc.talk") || player.hasPermission("citizens.admin"))
|
||||
&& player.getItemInHand().getTypeId() == Setting.TALK_ITEM.asInt())
|
||||
npc.getTrait(Text.class).sendText(player);
|
||||
|
||||
if (npc.getCharacter() != null)
|
||||
npc.getCharacter().onRightClick(npc, player);
|
||||
}
|
||||
|
@ -36,11 +36,15 @@ public class Settings {
|
||||
DATABASE_URL("database.url", ""),
|
||||
DATABASE_USERNAME("database.username", ""),
|
||||
DEBUG_MODE("general.debug-mode", false),
|
||||
DEFAULT_LOOK_CLOSE("npc.default.look-close", false),
|
||||
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
|
||||
DEFAULT_TALK_CLOSE("npc.default.talk-close", false),
|
||||
QUICK_SELECT("npc.selection.quick-select", false),
|
||||
SELECTION_ITEM("npc.selection.item", 280),
|
||||
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
|
||||
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.talk.max-cooldown", 60),
|
||||
TALK_CLOSE_MINIMUM_COOLDOWN("npc.talk.min-cooldown", 30),
|
||||
TALK_ITEM("npc.talk-item", 340),
|
||||
USE_DATABASE("use-database", false);
|
||||
|
||||
private String path;
|
||||
|
@ -19,7 +19,6 @@ import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Paginator;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
@ -207,10 +206,8 @@ public class NPCCommands {
|
||||
max = 1,
|
||||
permission = "npc.lookclose")
|
||||
public void lookClose(CommandContext args, Player player, NPC npc) {
|
||||
LookClose trait = npc.getTrait(LookClose.class);
|
||||
trait.toggle();
|
||||
String msg = StringHelper.wrap(npc.getName()) + " will "
|
||||
+ (trait.shouldLookClose() ? "now rotate" : "no longer rotate");
|
||||
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
|
||||
Messaging.send(player, msg += " when a player is nearby.");
|
||||
}
|
||||
|
||||
@ -333,22 +330,6 @@ public class NPCCommands {
|
||||
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "talkclose",
|
||||
desc = "Toggle whether an NPC talks when a player is near",
|
||||
modifiers = { "talkclose", "talk" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.talkclose")
|
||||
public void talkClose(CommandContext args, Player player, NPC npc) {
|
||||
Text trait = npc.getTrait(Text.class);
|
||||
trait.toggle();
|
||||
String msg = StringHelper.wrap(npc.getName()) + " will "
|
||||
+ (trait.shouldTalkClose() ? "now talk" : "no longer talk");
|
||||
Messaging.send(player, msg += " when a player is nearby.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "tp",
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.SaveId;
|
||||
@ -14,7 +15,7 @@ import org.bukkit.entity.Entity;
|
||||
@SaveId("look-close")
|
||||
public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
private final NPC npc;
|
||||
private boolean shouldLookClose;
|
||||
private boolean lookClose = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
|
||||
|
||||
public LookClose(NPC npc) {
|
||||
this.npc = npc;
|
||||
@ -45,37 +46,30 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
shouldLookClose = key.getBoolean("");
|
||||
lookClose = key.getBoolean("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
EntityLiving search = null;
|
||||
CitizensNPC handle = (CitizensNPC) npc;
|
||||
if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null && shouldLookClose)
|
||||
if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null && lookClose)
|
||||
faceEntity(handle, search.getBukkitEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setBoolean("", shouldLookClose);
|
||||
}
|
||||
|
||||
public void setLookClose(boolean shouldLookClose) {
|
||||
this.shouldLookClose = shouldLookClose;
|
||||
}
|
||||
|
||||
public boolean shouldLookClose() {
|
||||
return shouldLookClose;
|
||||
key.setBoolean("", lookClose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggle() {
|
||||
shouldLookClose = !shouldLookClose;
|
||||
public boolean toggle() {
|
||||
lookClose = !lookClose;
|
||||
return lookClose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LookClose{" + shouldLookClose + "}";
|
||||
return "LookClose{" + lookClose + "}";
|
||||
}
|
||||
}
|
@ -2,5 +2,5 @@ package net.citizensnpcs.trait;
|
||||
|
||||
public interface Toggleable {
|
||||
|
||||
public void toggle();
|
||||
public boolean toggle();
|
||||
}
|
@ -33,7 +33,9 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
private final NPC npc;
|
||||
private final List<String> text = new ArrayList<String>();
|
||||
private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>();
|
||||
private boolean talkClose;
|
||||
private boolean talkClose = Setting.DEFAULT_TALK_CLOSE.asBoolean();
|
||||
private boolean randomTalker = Setting.DEFAULT_RANDOM_TALKER.asBoolean();
|
||||
private int currentIndex;
|
||||
|
||||
public Text(NPC npc) {
|
||||
this.npc = npc;
|
||||
@ -47,18 +49,22 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
|
||||
if (key.keyExists("talk-close"))
|
||||
talkClose = key.getBoolean("talk-close");
|
||||
if (key.keyExists("random-talker"))
|
||||
randomTalker = key.getBoolean("random-talker");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.setBoolean("talk-close", talkClose);
|
||||
key.setBoolean("random-talker", randomTalker);
|
||||
for (int i = 0; i < text.size(); i++)
|
||||
key.setString(String.valueOf(i), text.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggle() {
|
||||
public boolean toggle() {
|
||||
talkClose = !talkClose;
|
||||
return talkClose;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,7 +79,7 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
return;
|
||||
cooldowns.remove(player.getName());
|
||||
}
|
||||
sendRandomText(player);
|
||||
if (sendText(player)) {
|
||||
// Add a cooldown if the text was successfully sent
|
||||
Calendar wait = Calendar.getInstance();
|
||||
wait.add(
|
||||
@ -83,6 +89,7 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
cooldowns.put(player.getName(), wait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -94,10 +101,6 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public boolean shouldTalkClose() {
|
||||
return talkClose;
|
||||
}
|
||||
|
||||
public Editor getEditor(final Player player) {
|
||||
final StartPrompt startPrompt = new StartPrompt(this);
|
||||
return new Editor() {
|
||||
@ -142,7 +145,26 @@ public class Text extends Trait implements Runnable, Toggleable {
|
||||
return paginator.sendPage(player, page);
|
||||
}
|
||||
|
||||
private void sendRandomText(Player player) {
|
||||
npc.chat(player, text.get(new Random().nextInt(text.size())));
|
||||
public boolean sendText(Player player) {
|
||||
if (text.size() == 0)
|
||||
return false;
|
||||
|
||||
int index = 0;
|
||||
if (randomTalker)
|
||||
index = new Random().nextInt(text.size());
|
||||
else {
|
||||
if (currentIndex > text.size() - 1)
|
||||
currentIndex = 0;
|
||||
index = currentIndex++;
|
||||
}
|
||||
Messaging.log("current: " + currentIndex);
|
||||
Messaging.log("index: " + index);
|
||||
npc.chat(player, text.get(index));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean toggleRandomTalker() {
|
||||
randomTalker = !randomTalker;
|
||||
return randomTalker;
|
||||
}
|
||||
}
|
@ -10,35 +10,30 @@ import org.bukkit.conversations.NumericPrompt;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextEditSelectIndexPrompt extends NumericPrompt {
|
||||
public class PageChangePrompt extends NumericPrompt {
|
||||
private Text text;
|
||||
|
||||
public TextEditSelectIndexPrompt(Text text) {
|
||||
public PageChangePrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||
context.setSessionData("index", input.intValue());
|
||||
Messaging.send((Player) context.getForWhom(), "<a>Now <e>editing <a>the entry at index <e>" + input.intValue()
|
||||
+ "<a>.");
|
||||
return new TextEditPrompt(text);
|
||||
Player player = (Player) context.getForWhom();
|
||||
if (!text.sendPage(player, input.intValue())) {
|
||||
Messaging.sendError(player, "Invalid page number.");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
return (Prompt) context.getSessionData("previous");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFailedValidationText(ConversationContext context, String input) {
|
||||
return ChatColor.RED + "'" + input + "' is not a valid index!";
|
||||
return ChatColor.RED + "Invalid page number.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
text.sendPage(player, 1);
|
||||
return StringHelper.parseColors("<a>Enter the index of the entry you wish to edit.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNumberValid(ConversationContext context, Number input) {
|
||||
return text.hasIndex(input.intValue());
|
||||
return StringHelper.parseColors("<a>Enter a page number to view more text entries.");
|
||||
}
|
||||
}
|
@ -17,14 +17,20 @@ public class StartPrompt extends StringPrompt {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String string) {
|
||||
if (string.equalsIgnoreCase("add"))
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase("add"))
|
||||
return new TextAddPrompt(text);
|
||||
else if (string.equalsIgnoreCase("edit"))
|
||||
return new TextEditSelectIndexPrompt(text);
|
||||
else if (string.equalsIgnoreCase("remove"))
|
||||
else if (input.equalsIgnoreCase("edit"))
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
return new TextRemovePrompt(text);
|
||||
else {
|
||||
if (input.equalsIgnoreCase("random"))
|
||||
Messaging.send((Player) context.getForWhom(), "<e>Random talker <a>set to <e>"
|
||||
+ text.toggleRandomTalker() + "<a>.");
|
||||
else if (input.equalsIgnoreCase("close")) {
|
||||
Messaging.send((Player) context.getForWhom(), "<e>Close talker <a>set to <e>" + text.toggle() + "<a>.");
|
||||
} else
|
||||
Messaging.sendError((Player) context.getForWhom(), "Invalid edit type.");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
@ -33,6 +39,6 @@ public class StartPrompt extends StringPrompt {
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
return StringHelper
|
||||
.parseColors("<a>Type <e>add <a>to add an entry, <e>edit <a>to edit entries, and <e>remove <a>to remove entries.");
|
||||
.parseColors("<a>Type <e>add <a>to add an entry, <e>edit <a>to edit entries, <e>remove <a>to remove entries, <e>close <a>to toggle the NPC as a close talker, and <e>random <a>to toggle the NPC as a random talker.");
|
||||
}
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
package net.citizensnpcs.trait.text.prompt;
|
||||
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
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;
|
||||
@ -18,7 +20,8 @@ public class TextAddPrompt extends StringPrompt {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
text.add(input);
|
||||
context.getForWhom().sendRawMessage(StringHelper.parseColors("<e>Added <a>the entry <e>" + input + "."));
|
||||
Messaging.send((Player) context.getForWhom(), StringHelper.parseColors("<e>Added <a>the entry <e>" + input
|
||||
+ "."));
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ package net.citizensnpcs.trait.text.prompt;
|
||||
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
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;
|
||||
@ -18,15 +18,15 @@ public class TextEditPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
text.edit((Integer) context.getSessionData("index"), input);
|
||||
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + context.getSessionData("index")
|
||||
+ " <a>to <e>" + input + "<a>.");
|
||||
int index = (Integer) context.getSessionData("index");
|
||||
text.edit(index, input);
|
||||
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + index + " <a>to <e>" + input
|
||||
+ "<a>.");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
return StringHelper.parseColors("<a>Enter text to change the entry at the index <e>"
|
||||
+ context.getSessionData("index") + "<a>.");
|
||||
return ChatColor.GREEN + "Enter text to edit the entry.";
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package net.citizensnpcs.trait.text.prompt;
|
||||
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
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;
|
||||
|
||||
public TextEditStartPrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
try {
|
||||
int index = Integer.parseInt(input);
|
||||
if (!text.hasIndex(index)) {
|
||||
Messaging.sendError(player, "'" + index + "' is not a valid index!");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
context.setSessionData("index", index);
|
||||
return new TextEditPrompt(text);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (input.equalsIgnoreCase("page")) {
|
||||
context.setSessionData("previous", this);
|
||||
return new PageChangePrompt(text);
|
||||
}
|
||||
}
|
||||
Messaging.sendError(player, "Invalid input.");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
text.sendPage(((Player) context.getForWhom()), 1);
|
||||
return StringHelper
|
||||
.parseColors("<a>Enter the index of the entry you wish to edit or <e>page <a>to view more pages.");
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@ package net.citizensnpcs.trait.text.prompt;
|
||||
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
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.conversations.StringPrompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TextRemovePrompt extends NumericPrompt {
|
||||
public class TextRemovePrompt extends StringPrompt {
|
||||
private Text text;
|
||||
|
||||
public TextRemovePrompt(Text text) {
|
||||
@ -17,27 +17,31 @@ public class TextRemovePrompt extends NumericPrompt {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||
int index = input.intValue();
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
try {
|
||||
int index = Integer.parseInt(input);
|
||||
if (!text.hasIndex(index)) {
|
||||
Messaging.sendError(player, "'" + index + "' is not a valid index!");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
text.remove(index);
|
||||
Messaging.send((Player) context.getForWhom(), "<e>Removed <a>entry at index <e>" + index + "<a>.");
|
||||
Messaging.send(player, "<e>Removed <a>entry at index <e>" + index + "<a>.");
|
||||
return new StartPrompt(text);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (input.equalsIgnoreCase("page")) {
|
||||
context.setSessionData("previous", this);
|
||||
return new PageChangePrompt(text);
|
||||
}
|
||||
}
|
||||
Messaging.sendError(player, "Invalid input.");
|
||||
return new StartPrompt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFailedValidationText(ConversationContext context, String input) {
|
||||
return ChatColor.RED + "'" + input + "' is not a valid index!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
text.sendPage(player, 1);
|
||||
return ChatColor.GREEN + "Enter the index of the entry you wish to remove.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNumberValid(ConversationContext context, Number input) {
|
||||
return text.hasIndex(input.intValue());
|
||||
text.sendPage(((Player) context.getForWhom()), 1);
|
||||
return StringHelper
|
||||
.parseColors("<a>Enter the index of the entry you wish to remove or <e>page <a>to view more pages.");
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ permissions:
|
||||
citizens.npc.rename: true
|
||||
citizens.npc.select: true
|
||||
citizens.npc.spawn: true
|
||||
citizens.npc.talk: true
|
||||
citizens.npc.tp: true
|
||||
citizens.npc.tphere: true
|
||||
citizens.npc.lookclose: true
|
Loading…
Reference in New Issue
Block a user