adminchat.java에서 AsyncPlayerChatEvent.java를 실행하고 싶습니다. 특히 사람이 command/ac를 입력하면 AsycPlayerChatEvent.java를 사용하여 처리 할 수 있습니다. ive googled하지만 낫지는 않지만 AsyncPlayerChatEvent.AsyncPlayerChatEvent();를 추가해 보았습니다. 하지만 그것은 작동하지 않았습니다. 여기 코드가 있습니다.다른 클래스 파일에서 Java .class 파일을 실행하십시오. (보다 구체적으로)
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;
}
}
당신 "는'.class' 파일을 실행"무엇을 의미합니까? 'AsyncPlayerChatEvent'는 메인 클래스가 아니며 ('main' 메쏘드가 없습니다), 메인이 아닌 클래스를 "실행할"수 없습니다. – chrylis
이 문제를 해결할 수있는 방법은 없나요? 죄송합니다. 자바에 처음 신되었습니다. –
'AsyncPlayerChatEvent'로 무엇을하고 싶은지 구체적으로 알려주세요. 게시 한 코드에 따라 실제로 흥미로운 일을하지 않는 것은 C++의'struct'와 같은 데이터 객체 일뿐입니다. 플레이어의 다른 서비스로 보낼 것을 만들려고합니까? – chrylis