程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> java-求高手幫忙看看這段Java代碼有什麼錯誤。

java-求高手幫忙看看這段Java代碼有什麼錯誤。

編輯:編程解疑
求高手幫忙看看這段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");
}

}

}

最佳回答:


最好能說下那地方出錯,你說153行和171行,這又沒行號,怎麼看?

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved