下面列出了怎么用org.bukkit.conversations.Conversable的API类实例代码及写法,或者点击链接到github查看源代码。
public boolean dispatchServerCommand(CommandSender sender, PendingCommand serverCommand) {
if (sender instanceof Conversable) {
Conversable conversable = (Conversable) sender;
if (conversable.isConversing()) {
conversable.acceptConversationInput(serverCommand.command);
return true;
}
}
try {
this.playerCommandState = true;
return this.dispatchCommand(sender, serverCommand.command);
} catch (Exception ex) {
getLogger().log(Level.WARNING,
"Unexpected exception while parsing console command \"" + serverCommand.command + '"', ex);
return false;
} finally {
this.playerCommandState = false;
}
}
public static void askForName(Conversable whom, IPet pet, boolean admin) {
new ConversationFactory(EchoPet.getPlugin())
.withModality(true)
.withLocalEcho(false)
.withPrefix(new NameConversationPrefix())
.withTimeout(90)
.withFirstPrompt(new NamePrompt(pet, admin))
.withEscapeSequence("exit")
.withEscapeSequence("quit")
.buildConversation(whom).begin();
}
public boolean dispatchServerCommand(CommandSender sender, net.minecraft.command.ServerCommand serverCommand) {
if (sender instanceof Conversable) {
Conversable conversable = (Conversable)sender;
if (conversable.isConversing()) {
conversable.acceptConversationInput(serverCommand.command);
return true;
}
}
try {
this.playerCommandState = true;
// Cauldron start - handle bukkit/vanilla console commands
int space = serverCommand.command.indexOf(" ");
// if bukkit command exists then execute it over vanilla
if (this.getCommandMap().getCommand(serverCommand.command.substring(0, space != -1 ? space : serverCommand.command.length())) != null)
{
return this.dispatchCommand(sender, serverCommand.command);
}
else { // process vanilla console command
craftCommandMap.setVanillaConsoleSender(serverCommand.sender);
return this.dispatchVanillaCommand(sender, serverCommand.command);
}
// Cauldron end
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Unexpected exception while parsing console command \"" + serverCommand.command + '"', ex);
return false;
} finally {
this.playerCommandState = false;
}
}
public static void send(Conversable conversable, String message) {
if (conversable instanceof CommandSender) {
send((CommandSender) conversable, message);
return;
}
if (message != null) {
conversable.sendRawMessage(HoloAPI.getPrefix() + ChatColor.translateAlternateColorCodes('&', message));
}
}
@Command(
command = "create",
description = "Create a hologram from text",
permission = "holoapi.holo.create",
help = {"Lines can be entered one after another", "Once the command is entered, you will be prompted to enter the line content"}
)
public boolean create(CommandEvent event) {
if (!(event.sender() instanceof Conversable)) {
event.respond(Lang.NOT_CONVERSABLE.getValue());
return true;
}
InputFactory.buildBasicConversation().withFirstPrompt(new InputPrompt()).buildConversation((Conversable) event.sender()).begin();
return true;
}
@Command(
command = "create animation",
description = "Create a hologram using animations",
permission = "holoapi.holo.create",
help = "Animation can be defined in the HoloAPI config file"
)
public boolean createAnimation(CommandEvent event) {
if (!(event.sender() instanceof Conversable)) {
event.respond(Lang.NOT_CONVERSABLE.getValue());
return true;
}
InputFactory.buildBasicConversation().withFirstPrompt(new AnimationBuilderInputPrompt()).buildConversation((Conversable) event.sender()).begin();
return true;
}
@Command(
command = "build",
description = "Dynamically build a combined hologram of both text and images",
permission = "holoapi.holo.build"
)
public boolean command(CommandEvent event) {
if (!(event.sender() instanceof Conversable)) {
event.respond(Lang.NOT_CONVERSABLE.getValue());
return true;
}
InputFactory.buildBasicConversation().withFirstPrompt(new BuilderInputPrompt()).buildConversation((Conversable) event.sender()).begin();
return true;
}
public static void askForName(Conversable whom, IPet pet, boolean admin) {
new ConversationFactory(EchoPet.getPlugin())
.withModality(true)
.withLocalEcho(false)
.withPrefix(new NameConversationPrefix())
.withTimeout(90)
.withFirstPrompt(new NamePrompt(pet, admin))
.withEscapeSequence("exit")
.withEscapeSequence("quit")
.buildConversation(whom).begin();
}
public void send(Conversable conversable, String... pairedReplacements) {
send(conversable, getValue(pairedReplacements));
}