我正在尝试将所有在线玩家设置为游戏模式0(生存)(我做一个varo插件)
以下是我的代码:
package com.abgelutscht.varo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
private int gamemode = 2;
private int countdown = 30;
private boolean countdownStarted = false;
private boolean started = false;
private Timer count = new Timer();
private TimerTask count2 = new TimerTask(){
public void run(){
if(countdown>0){
Bukkit.broadcastMessage(blue+"Noch "+aqua+countdown+blue+" Sekunden bis zum Start!");
countdown--;
}
else{
Bukkit.broadcastMessage(blue+"Los gehts!");
startVaro();
count.cancel();
}
}
};
private List<String[]> teams = new ArrayList<String[]>();
public static final ChatColor dRed = ChatColor.DARK_RED;
public static final ChatColor red = ChatColor.RED;
public static final ChatColor aqua = ChatColor.AQUA;
public static final ChatColor dAqua = ChatColor.DARK_AQUA;
public static final ChatColor blue = ChatColor.BLUE;
public static final ChatColor yellow = ChatColor.YELLOW;
public static final ChatColor white = ChatColor.WHITE;
private final String teamCommands = red+"Team-Befehle:\n"+blue
+ "/team " + dRed + "create " + red + "<" + aqua + "Teamname" + red + ">" + blue + "\n"
+ "/team " + dRed + "create " + red + "<" + aqua + "Teamname" + red + "> " + blue + red+ "<"+ dAqua+ "Spieler1" + red + "> " + blue + red+ "<"+ dAqua+ "Spieler2" + red + ">" + blue+ "\n"
+ "/team " + dRed + "add " + red + "<" + aqua + "Teamname" + red + ">" + blue + " "+ red+ "<"+ dAqua+ "Spieler" + red + ">" + blue + "\n"
+ "/team " + dRed + "remove " + red + "<" + aqua + "Teamname" + red + ">" + blue + " "+ red+ "<"+ dAqua+ "Spieler" + red + ">" + blue + "\n"
+ "/team " + dRed + "delete " + red + "<" + aqua + "Teamname" + red + ">" + blue;
@Override
public void onEnable(){
new PlayerListener(this);
loadConfig();
System.out.println("varo-plugin by abgelutscht enabled");
}
@Override
public void onDisable(){
writeConfig();
System.out.println("varo-plugin by abgelutscht disabled");
}
private void loadConfig(){
this.getConfig().options().copyDefaults(true);
this.saveConfig();
for(int i = 0; i < this.getConfig().getInt("length"); i++){
List<String> list = new ArrayList<String>();
list = getConfig().getStringList(String.format("%s", i));
String[] team = new String[3];
if(list.size()==1){
team[0] = list.get(0);
}
else if(list.size()==2){
team[0] = list.get(0);
team[1] = list.get(1);
}
else if(list.size()==3){
team[0] = list.get(0);
team[1] = list.get(1);
team[2] = list.get(2);
}
teams.add(team);
}
if(this.getConfig().getInt("countdown")!=0){
countdown = this.getConfig().getInt("countdown");
}
started = this.getConfig().getBoolean("started");
if(started){
gamemode = 0;
}
if(!started){
gamemode = 2;
}
}
private void writeConfig(){
this.getConfig().set("countdown", countdown);
this.getConfig().set("started", started);
this.getConfig().set("length", teams.size());
for(int i = 0; i<teams.size(); i++){
this.getConfig().set(""+i, teams.get(i));
}
this.getConfig().options().copyDefaults(true);
this.saveConfig();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
Player player = null;
if(sender instanceof Player){
player = (Player) sender;
}
if(command.getName().equalsIgnoreCase("team")){
if(player.isOp()){
if(!(args.length==0 || args.length>4)){
if(args.length==1){
if(args[0].equals("list")){
if(teams.size()!=0){
player.sendMessage(red+"Die Teams:\n");
for(int i = 0; i<teams.size(); i++){
player.sendMessage(aqua+teams.get(i)[0]+blue+" "+teams.get(i)[1]+" "+teams.get(i)[2]+"\n");
}
}
else{
player.sendMessage(dRed+"[Fehler] Es existieren keine Teams!");
}
}
}
else if(args.length==2){
if(args[0].equals("create")){
if(!teamExisting(args[1])){
String[] team = new String[3];
team[0] = args[1];
teams.add(team);
player.sendMessage(blue+"Das Team "+aqua+args[1]+blue+" wurde erstellt");
}
else{
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" existiert bereits!");
}
}
else if(args[0].equals("remove")){
for(int i = 0; i<teams.size(); i++){
if(teams.get(i)[0].equals(args[1])){
teams.remove(i);
player.sendMessage(blue+"Das Team "+aqua+args[1]+blue+" wurde entfernt!");
}
}
if(teamExisting(args[1])){
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" existiert nicht!");
}
}
}
else if(args.length==3){
if(args[0].equals("add")){
for(int i = 0; i<teams.size(); i++){
if(teams.get(i)[0].equals(args[1])){
if(teams.get(i)[1]!=null && teams.get(i)[2]!=null){
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" ist voll!");
}
else if(teams.get(i)[1]==null && teams.get(i)[2]==null){
if(!playerExisting(args[2])){
teams.get(i)[1] = args[2];
player.sendMessage(blue+"Der Spieler "+aqua+args[2]+blue+" wurde zum Team "+aqua+args[1]+blue+" hinzugefügt!");
}
else{
player.sendMessage(dRed+"[Fehler] Der Spieler "+aqua+args[2]+dRed+" ist bereits in einem anderen Team!");
}
}
else if((teams.get(i)[1]!=null && teams.get(i)[2]==null) && !teams.get(i)[1].equals(args[2])){
if(!playerExisting(args[2])){
teams.get(i)[2] = args[2];
player.sendMessage(blue+"Der Spieler "+aqua+args[2]+blue+" wurde zum Team "+aqua+args[1]+blue+" hinzugefügt!");
}
else{
player.sendMessage(dRed+"[Fehler] Der Spieler "+aqua+args[2]+dRed+" ist bereits in einem anderen Team!");
}
}
else if((teams.get(i)[1]!=null && teams.get(i)[2]==null) && teams.get(i)[1].equals(args[2])){
player.sendMessage(dRed+"[Fehler] Der Spieler "+aqua+args[2]+dRed+" ist bereits in dem Team");
}
}
}
if(!teamExisting(args[1])){
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" existiert nicht!");
}
}
else if(args[0].equals("remove")){
for(int i = 0; i<teams.size(); i++){
if(teams.get(i)[0].equals(args[1])){
if(teams.get(i)[1]==null && teams.get(i)[2]==null){
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+blue+" ist leer!");
}
else if(teams.get(i)[1]!=null && teams.get(i)[2]!=null){
if(args[2].equals(teams.get(i)[1])){
teams.get(i)[1] = teams.get(i)[2];
teams.get(i)[2] = null;
player.sendMessage(blue+"Der Spieler "+aqua+args[2]+blue+" wurde aus dem Team "+aqua+args[1]+blue+" entfernt!");
}
else if(args[2].equals(teams.get(i)[2])){
teams.get(i)[2] = null;
player.sendMessage(blue+"Der Spieler "+aqua+args[2]+blue+" wurde aus dem Team "+aqua+args[1]+blue+" entfernt!");
}
}
else if((teams.get(i)[1]!=null && teams.get(i)[2]==null) && teams.get(i)[1].equals(args[2])){
teams.get(i)[1] = null;
player.sendMessage(blue+"Der Spieler "+aqua+args[2]+blue+" wurde aus dem Team "+aqua+args[1]+blue+" entfernt!");
}
else if(!args[2].equals(teams.get(i)[1]) && !args[2].equals(teams.get(i)[2])){
player.sendMessage(dRed+"[Fehler] Der Spieler "+aqua+args[2]+dRed+" ist nicht in dem Team!");
}
}
}
if(!teamExisting(args[1])){
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" existiert nicht!");
}
}
}
else if(args.length==4){
if(args[0].equalsIgnoreCase("create")){
if(args[2]!=args[3] && (!playerExisting(args[2]) && !playerExisting(args[3])) && !args[2].equals(args[3])){
if(!teamExisting(args[1])){
String[] team = new String[3];
team[0] = args[1];
team[1] = args[2];
team[2] = args[3];
teams.add(team);
player.sendMessage(blue+"Das Team "+aqua+args[1]+blue+" wurde erstellt");
}
else{
player.sendMessage(dRed+"[Fehler] Das Team "+aqua+args[1]+dRed+" existiert bereits!");
}
}
else if(args[2].equals(args[3])){
player.sendMessage(dRed+"[Fehler] Die Spieler "+aqua+args[2]+dRed+" und "+aqua+args[3]+dRed+" sind identisch!");
}
}
}
}
else{
player.sendMessage(teamCommands);
}
}
else{
player.sendMessage(dRed+"[Fehler] Du hast nicht die nötigen Rechte, diesen Befehl auszuführen!");
}
}
if(command.getName().equalsIgnoreCase("countdown")){
if(args.length==1){
if(args[0].equals("start")){
if(!countdownStarted && !started){
countdownStarted = true;
count.schedule(count2, 0, 1000);
}
else{
player.sendMessage(dRed+"[Fehler] Der Countdown ist bereits gestartet worden!");
}
}
}
else if(args.length==2){
if(args[0].equals("set")){
if(!countdownStarted && !started){
try{
if(Integer.parseInt(args[1])<=0){
player.sendMessage(dRed+"[Fehler] Die Eingabe "+aqua+args[1]+dRed+" ist ungültig!");
}
else{
countdown = Integer.parseInt(args[1]);
player.sendMessage(blue+"Der Countdown wurde auf "+aqua+args[1]+blue+" gesetzt!");
}
}
catch(Exception e){
player.sendMessage(dRed+"[Fehler] Die Eingabe "+aqua+args[1]+dRed+" ist ungültig!");
}
}
else{
player.sendMessage(dRed+"[Fehler] Der Countdown ist bereits gestartet worden!");
}
}
}
}
return true;
}
private boolean playerExisting(String player){
for(int i = 0; i<teams.size(); i++){
try{
for(int i2 = 0; i2<teams.get(i).length; i++){
if(player.equals(teams.get(i)[i2])){
return true;
}
}
}
catch(Exception e){}
}
return false;
}
private boolean teamExisting(String team){
for(int i = 0; i<teams.size(); i++){
if(team.equals(teams.get(i)[0])){
return true;
}
}
return false;
}
private void startVaro(){
started = true;
for(Player player: this.getServer().getOnlinePlayers()){
player.setGameMode(GameMode.SURVIVAL);
}
}
public List<String[]> getTeams(){
return teams;
}
public int getGamemode(){
return gamemode;
}
}
如果我开始倒计时,并且调用了startVaro()方法,我会得到一个错误:
Exception in thread "Timer-0"
[20:04:39 WARN]: java.lang.IllegalStateException: Asynchronous player tracker update!
[20:04:39 WARN]: at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14)
[20:04:39 WARN]: at net.minecraft.server.v1_8_R3.EntityTrackerEntry.updatePlayer(EntityTrackerEntry.java:313)
[20:04:39 WARN]: at net.minecraft.server.v1_8_R3.EntityTracker.a(EntityTracker.java:207)
[20:04:39 WARN]: at net.minecraft.server.v1_8_R3.EntityPlayer.B(EntityPlayer.java:1041)
[20:04:39 WARN]: at net.minecraft.server.v1_8_R3.EntityPlayer.updateAbilities(EntityPlayer.java:934)
[20:04:39 WARN]: at net.minecraft.server.v1_8_R3.PlayerInteractManager.setGameMode(PlayerInteractManager.java:36)
[20:04:39 WARN]: at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.setGameMode(CraftPlayer.java:759)
[20:04:39 WARN]: at com.x.varo.Main.startVaro(Main.java:304)
[20:04:39 WARN]: at com.x.varo.Main.access$2(Main.java:300)
[20:04:39 WARN]: at com.x.varo.Main$1.run(Main.java:31)
[20:04:39 WARN]: at java.util.TimerThread.mainLoop(Unknown Source)
[20:04:39 WARN]: at java.util.TimerThread.run(Unknown Source)
为什么我有这个错误?我该如何解决它?
问题的原因是您试图异步更改玩家状态(相对于Bukkit的主线程)。查看Scheduler Programming了解如何安排单个或重复Bukkit任务的详细信息。我相信您最感兴趣的方法是scheduleSyncDelayedTask()
我想知道是否有一种方法可以使插件具有当用户在我的网站上执行操作时触发的事件。我想这样做来制作一个定制商店,因为我不喜欢 Enjin 或 Buycraft,因为它们不是很可定制。
我目前正在开发一个插件,可以让你假设另一个玩家的身份。它几乎完美无缺地做到了这一点:您的UUID和用户名被更改为您假定为服务器端的用户的身份,就服务器和插件所知,您似乎就是那个玩家。你将拥有与他们相同的等级,相同的权限,一切。我唯一没能得到的就是皮肤。我以为当UUID是的时候,一个玩家的皮肤会为其他玩家改变,但事实似乎并非如此。我使用反射来更改GameProfile和EntityPlayer中的U
我正在编码我的第一个《我的世界》mod,我可以让我的项目加载纹理。我对编码《我的世界》mod很不熟悉,我有点困惑。以下是基本项目的代码: 这是实际项目的代码:
我有中的图片。我知道它应该工作,因为还有很多其他物品有工作纹理。我的项目类看起来像这样: ItemBase类构造函数如下所示: 我不知道该怎么办。我的源代码在这里:链接,如果你需要的话。非常感谢。
我正在制作一个mod,我得到了这个错误: 使用缺少的纹理,无法加载空:纹理/项目/训练紧身靴。png java。伊奥。FileNotFoundException:null:纹理/项目/训练紧身靴。巴布亚新几内亚 我有纹理名称设置为完全以上和文件夹项目。 这是我的代码: 我换了这部分
我正在进行一个处理项目,需要能够确定鼠标是否在圆内。因此,我需要获得圆的位置和鼠标的位置。但是,圆的位置已使用矩阵函数进行了修改,如和。例如: 在处理中有什么方法可以做到这一点吗?我在看留档,但似乎找不到任何功能。如果没有,我如何实现我的目标? 谢谢。