我想在adminchat.java中运行AsyncPlayerChatEvent.java,特别是当用户键入命令/ ac时,它将使用AsycPlayerChatEvent.java来处理它。香港专业教育学院谷歌它,但似乎没有解决,我试图添加AsyncPlayerChatEvent.AsyncPlayerChatEvent();但它没有用,这是代码。
adminchat.java
package alo.adminchat;
import java.util.IllegalFormatException;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
public final class adminchat extends JavaPlugin
{
@Override
public void onEnable()
{
System.out.println("Adminchat by Alo k2ivitus!");
// TODO Insert logic to be performed when the plugin is enabled
}
@Override
public void onDisable()
{
System.out.println("Adminchat by Alo sulgus!");
// TODO Insert logic to be performed when the plugin is disabled
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if(cmd.getName().equalsIgnoreCase("achelp"))
{ // If the player typed /ac then do the following...
// doSomething
return false;
} //If this has happened the function will return true.
// If this hasn't happened the a value of false will be returned.
return false;
}
public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args)
{
if(cmd.getName().equalsIgnoreCase("ac"))
{ // If the player typed /ac then do the following...
AsyncPlayerChatEvent.AsyncPlayerChatEvent(); //This is what needs fixing
return true;
} //If this has happened the function will return true.
// If this hasn't happened the a value of false will be returned.
return false;
}
}
AsyncPlayerChatEvent.java
package alo.adminchat;
import java.util.IllegalFormatException;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public class AsyncPlayerChatEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private String message;
private String format = "<%1$s> %2$s";
private final boolean recipients;
public AsyncPlayerChatEvent(final boolean async, final Player who, final String message, final Set<Player> players) {
super(who, async);
this.message = message;
recipients = player.hasPermission("adminchat.use");
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getFormat() {
return format;
}
public void setFormat(final String format) throws IllegalFormatException, NullPointerException {
// Oh for a better way to do this!
try {
String.format(format, player, message);
} catch (RuntimeException ex) {
ex.fillInStackTrace();
throw ex;
}
this.format = format;
}
public boolean getRecipients() {
return recipients;
}
public boolean isCancelled() {
return cancel ;
}
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
最佳答案
我认为您的意思是您要创建AsyncPlayerChatEvent的实例吗?
new AsyncPlayerChatEvent();
但是您需要传递参数:
boolean async, Player who, String message, Set<Player> players