1

我想在 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;
     }
 }
4

2 回答 2

3

我想你的意思是你想创建一个 AsyncPlayerChatEvent 的实例?

new AsyncPlayerChatEvent();

但是你需要传递你的论点:

boolean async, Player who, String message, Set<Player> players
于 2013-08-01T23:30:59.797 回答
0

而不是用 调用构造函数AsyncPlayerChatEvent.AsyncPlayerChatEvent(),您应该new AsyncPlayerChatEvent()改用。这将创建一个新AsyncPlayerChatEvent的并在其上调用构造函数。

于 2013-08-01T23:29:58.777 回答