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行,这又没行号,怎么看?

解决方案二:

我已经知道了。是在获取cachetime的时候没有提前获取。而是在与需要这一变量的函数同时进行。我已经延后了。就成功了

解决方案三:

出错在153和171行

解决方案四:

没有高手么。求高手帮我。

时间: 2024-10-13 15:21:55

java-求高手帮忙看看这段Java代码有什么错误。的相关文章

线程-java server端发送数据给客户端出现问题,求高手帮忙看下!

问题描述 java server端发送数据给客户端出现问题,求高手帮忙看下! java server端发送数据给客户端出现问题,求高手帮忙看下! package com.zeph.multiclient; import java.io.*; import java.net.ServerSocket; import java.net.Socket; public class MultiThreadServer extends Thread { private Socket client; publ

懂PHP得帮下忙,求帮我把这段c#代码翻成php

问题描述 求高手帮忙把一段C#的程序翻译成PHPHttpWebRequestrequest=(HttpWebRequest)WebRequest.Create("http://......");request.Method="POST";request.KeepAlive=false;request.AllowAutoRedirect=true;request.ContentType="application/json";request.Acce

加密-java和php的hmac_sha1结果不同,求高手帮忙

问题描述 java和php的hmac_sha1结果不同,求高手帮忙 最近遇到hmac_sha1跨语言加密的问题,只提供给了java加密文件,没提供php的,我用php hmac_sha1内置函数,得到的sig加密结果不同,欢迎高手帮忙提供相对应的php代码,提供的java类如下 欢迎加QQ: 847036019 public abstract class Coder { public static final String KEY_SHA = "SHA"; public static

对象-求帮忙看一段java代码,很短的

问题描述 求帮忙看一段java代码,很短的 import java.util.*; public class Student implements Comparable { int score=0; String name; Student(int score,String name){ this.name=name; this.score=score; } public int compareTo(Object b){ Student st=(Student)b; return(this.sc

c-求帮忙把这段校验代码翻译成JAVA

问题描述 求帮忙把这段校验代码翻译成JAVA const u8 CRCHi[] = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,0x80, 0x41, 0x01, 0xC0, 0x80

eclipse+gradle build过程中出现此问题 求高手帮忙解决下

问题描述 eclipse+gradle build过程中出现此问题 求高手帮忙解决下 Execution failed for task ':PunkHoo:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: android/support/v4/internal/view/ SupportMenu.class

项目启动报oracle错-项目启动报错,在网上查了好多资料还是为解决,求高手帮忙

问题描述 项目启动报错,在网上查了好多资料还是为解决,求高手帮忙 [14:22:13] [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] WARN - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@11765ae -- Acquisition Attempt Failed!!! Clearing pending acquires. While t

dfs-HUD 1010老超时求高手帮忙

问题描述 HUD 1010老超时求高手帮忙 import java.util.Scanner; public class Num2 { static int t,y2,x2,v; static char[][] map; public static void dfs(int i,int j,int count){ if(i<0 || j<0 || i>=map.length || j>=map[i].length){ return; } if(((t-count)-(Math.ab

app-跪求高手帮忙看下程序为什么android连接不到servlet上,谢谢大家了

问题描述 跪求高手帮忙看下程序为什么android连接不到servlet上,谢谢大家了 android客户端 package com.android.helloworld; import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException;