sumijie 2016-02-19 11:24 采纳率: 100%
浏览 1674
已采纳

求高手帮忙看看这段Java代码有什么错误。

package com.nightworld.why;

import java.io.File;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class NightWorld extends JavaPlugin implements Listener {
int MaxPeopleOfNightWorld=NightWorld.this.getConfig().getInt("MaxPeopleOfNightWorld");
int EveryPeopleZombieSpeed=NightWorld.this.getConfig().getInt("EveryPeopleZombieSpeed");
int cacheTime;
boolean IsZombieRun=false;
boolean IsPlayerInNightWorld=false;
boolean RunAnother=false;
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
boolean IsNightWorld=NightWorldFile();
if (args.length {
sender.sendMessage("§5参数过少");
return false;
}
if (args.length>1) {
sender.sendMessage("§5参数过多");
return false;
}
Plugin IsMv=getServer().getPluginManager().getPlugin("Multiverse-Core");
if (IsMv==null)
{
sender.sendMessage("§5对不起§3,您的服务器不拥有该插件的前置插件§5Multiverse-Core§3所以NightWorld插件停止运行。");
return true;
}
if(sender instanceof Player)
{
if (IsNightWorld==true)
{
if (cmd.getName().equalsIgnoreCase("nightworld")){
teleportNightWorld((Player)sender,args[0]);

return true;
}
}
else
{
if (cmd.getName().equalsIgnoreCase("nightworld")){
sender.sendMessage("§3由于§5"+this.getConfig().getString("NightWorld")+"§3世界不存在。所以即将生成§5"+this.getConfig().getString("NightWorld")+"§3世界。");
getServer().dispatchCommand(getServer().getConsoleSender(), "mv create "+this.getConfig().getString("NightWorld")+" normal");
sender.sendMessage("§3生成§5"+this.getConfig().getString("NightWorld")+"§3世界完成");
sender.sendMessage("§3即将加载§5"+this.getConfig().getString("NightWorld")+"§3世界");
getServer().dispatchCommand(getServer().getConsoleSender(), "mv load "+this.getConfig().getString("NightWorld"));
sender.sendMessage("§3加载§5"+this.getConfig().getString("NightWorld")+"§3世界完成");
sender.sendMessage("§3即将配置§5"+this.getConfig().getString("NightWorld")+"§3世界");
World NightWorld=getServer().getWorld(this.getConfig().getString("NightWorld"));
int x=0;
int y=1;
int z=0;
Location NightWorldLocation=new Location(NightWorld,x,y,z);
Location NightWorldOn=new Location(NightWorld,x,y+1,z);
Block LocationId=NightWorldLocation.getBlock();
Block OnId=NightWorldOn.getBlock();
LocationId.setType(Material.AIR);
OnId.setType(Material.AIR);
NightWorld.setGameRuleValue("doDaylightCycle", "false");
NightWorld.setTime(18000L);
sender.sendMessage("§3配置§5"+this.getConfig().getString("NightWorld")+"§3世界完成");
teleportNightWorld((Player)sender,args[0]);

return true;
}
}
}
else
{
sender.sendMessage("§5该指令只能由玩家进行");
return true;
}
return false;
}

public boolean NightWorldFile(){
boolean IsNightWorld;
File NightWorldFile = new File("../"+this.getConfig().getString("NightWorld"));
if(Bukkit.getWorld(this.getConfig().getString("NightWorld"))!=null & !NightWorldFile.exists())
{IsNightWorld=true;}
else
{IsNightWorld=false;}
return IsNightWorld;

}

public void teleportNightWorld(Player sender,String teleportplayer){
Player target;
if (teleportplayer!=null)
{
target = (Bukkit.getServer().getPlayer(teleportplayer));
if (target == null) {
sender.sendMessage("§5" + teleportplayer + "§3不在线");
return;
}
}
else
{
target = sender;
}
World NightWorld=getServer().getWorld(this.getConfig().getString("NightWorld"));
int x=0;
int y=1;
int z=0;
Location NightWorldLocation=new Location(NightWorld,x,y,z);
target.sendMessage("§2正在将§5"+target.getName()+"§2传送至永夜服务器");
target.teleport(NightWorldLocation);
getServer().dispatchCommand(getServer().getConsoleSender(), "spreadplayers ~ ~ 0 2500 false "+target.getName());
target.sendMessage("§2已经将§5"+target.getName()+"§2传送至永夜服务器");
}
public void onEnable(){
if (!getDataFolder().exists())
{
getDataFolder().mkdir();
}
File NightWorldConfig=new File(getDataFolder()+"config.yml");
if (!(NightWorldConfig.exists()))
{saveDefaultConfig();}
reloadConfig();
getLogger().info("NightWorld插件载入成功");
runFor();
}
public void onDisable() {
getLogger().info("NightWorld插件载出成功");
}
public void runFor()
{
Timer timer=new Timer();
timer.scheduleAtFixedRate(new NightWorldTimer(), 0L,1000L);
}
public void runForTime()
{
Timer timer=new Timer();
timer.scheduleAtFixedRate(new NightWorldTimer2(), 0L,1000L);
}
public void runForTimeFirst()
{
Timer timer=new Timer();
timer.scheduleAtFixedRate(new NightWorldTimer3(), 0L,cacheTime);
}
public class NightWorldTimer extends TimerTask {
@SuppressWarnings("deprecation")
public void run(){
if (IsZombieRun==false)
{
Player[] Players=getServer().getOnlinePlayers();
for (int PlayersLength=Players.length; PlayersLength > 0; PlayersLength--) {
if (Players[PlayersLength-1].getWorld().getName().equals(NightWorld.this.getConfig().getString("NightWorld")))
{
IsPlayerInNightWorld=true;
}
}
if (IsPlayerInNightWorld==true)
{
getLogger().info("3");
runForTime();
runForTimeFirst();
IsZombieRun=true;
}
}
else
{
int NotIsPlayer=0;
Player[] Players=getServer().getOnlinePlayers();
for (int PlayersLength=Players.length; PlayersLength > 0; PlayersLength--) {
if (!Players[PlayersLength-1].getWorld().getName().equals(NightWorld.this.getConfig().getString("NightWorld")))
{
NotIsPlayer++;
}
}
if (NotIsPlayer==Players.length)
{
IsPlayerInNightWorld=false;
}
}

}

}
public class NightWorldTimer2 extends TimerTask {
public void run(){
if (IsPlayerInNightWorld==false)
{
return;
}
List NightWorldPlayer=getServer().getWorld(NightWorld.this.getConfig().getString("NightWorld")).getPlayers();
int NightWorldPlayers=NightWorldPlayer.size();
cacheTime= (MaxPeopleOfNightWorld+1-NightWorldPlayers)*EveryPeopleZombieSpeed;

}

}
public class NightWorldTimer3 extends TimerTask {
public void run(){
getLogger().info("5.5");
if (IsPlayerInNightWorld==false)
{
getLogger().info("no");
IsZombieRun=false;
return;
}
List NightWorldPlayer=getServer().getWorld(NightWorld.this.getConfig().getString("NightWorld")).getPlayers();
int NightWorldPlayers=NightWorldPlayer.size();
double RandomNum=Math.random()*NightWorldPlayers;
Player NightWorldPlayerOfPlayer=NightWorldPlayer.get((int)RandomNum);
Location PlayerOfPlayerLocation=NightWorldPlayerOfPlayer.getLocation();
getServer().getWorld(NightWorld.this.getConfig().getString("NightWorld")).spawnEntity(PlayerOfPlayerLocation,EntityType.ZOMBIE);
getLogger().info("6");
}

}

}

  • 写回答

4条回答 默认 最新

  • 丑旦 2016-02-19 12:56
    关注

    最好能说下那地方出错,你说153行和171行,这又没行号,怎么看?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。