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条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用