Warn when NMS versions don't match. Resolves #165

This commit is contained in:
unknown 2014-05-05 00:01:57 +02:00
parent 56b55eb3e2
commit 489549a0ea
4 changed files with 35 additions and 15 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun May 04 23:06:18 CEST 2014
build.number=811
#Sun May 04 23:59:18 CEST 2014
build.number=816

View File

@ -16,8 +16,9 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
public class TFM_ServerInterface
{
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public static final String COMPILE_NMS_VERSION = "v1_7_R3";
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public static void setOnlineMode(boolean mode)
{

View File

@ -363,6 +363,24 @@ public class TFM_Util
return false;
}
public static void deleteCoreDumps()
{
final File[] coreDumps = new File(".").listFiles(new FileFilter()
{
@Override
public boolean accept(File file)
{
return file.getName().startsWith("java.core");
}
});
for (File dump : coreDumps)
{
TFM_Log.info("Removing core dump file: " + dump.getName());
dump.delete();
}
}
public static EntityType getEntityType(String mobname) throws Exception
{
mobname = mobname.toLowerCase().trim();
@ -881,6 +899,12 @@ public class TFM_Util
return date.getTime() / 1000L;
}
public static String getNmsVersion()
{
String packageName = Bukkit.getServer().getClass().getPackage().getName();
return packageName.substring(packageName.lastIndexOf('.') + 1);
}
public static class TFM_EntityWiper
{
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();

View File

@ -15,6 +15,7 @@ import java.util.Properties;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
import me.StevenLawson.TotalFreedomMod.Listener.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.World;
@ -79,19 +80,13 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.info("Made by Madgeek1450 and DarthSalamon");
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator);
final File[] coreDumps = new File(".").listFiles(new FileFilter()
{
@Override
public boolean accept(File file)
{
return file.getName().startsWith("java.core");
}
});
TFM_Util.deleteCoreDumps();
for (File dump : coreDumps)
if (!TFM_ServerInterface.COMPILE_NMS_VERSION.equals(TFM_Util.getNmsVersion()))
{
TFM_Log.info("Removing core dump file: " + dump.getName());
dump.delete();
TFM_Log.warning(pluginName + " is compiled for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
+ "version " + TFM_Util.getNmsVersion() + "!");
TFM_Log.warning("This might result in unexpected behaviour!");
}
// Admin list
@ -177,7 +172,7 @@ public class TotalFreedomMod extends JavaPlugin
TFM_HTTPD_Manager.getInstance().start();
TFM_FrontDoor.getInstance().start();
TFM_Log.info("Version " + pluginVersion + " enabled");
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled");
// Delayed Start:
new BukkitRunnable()