TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java

93 lines
2.3 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
2017-05-22 18:05:41 +00:00
import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.PropertyManager;
2016-03-01 16:59:44 +00:00
import org.bukkit.Bukkit;
2017-05-22 18:05:41 +00:00
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
public class ServerInterface extends FreedomService
{
2017-05-22 18:05:41 +00:00
public static final String COMPILE_NMS_VERSION = "v1_12_R1";
public ServerInterface(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
public static void warnVersion()
{
final String nms = FUtil.getNmsVersion();
if (!COMPILE_NMS_VERSION.equals(nms))
{
FLog.warning(TotalFreedomMod.pluginName + " is compiled for " + COMPILE_NMS_VERSION + " but the server is running version " + nms + "!");
FLog.warning("This might result in unexpected behaviour!");
}
}
public void setOnlineMode(boolean mode)
{
2016-03-01 16:59:44 +00:00
final PropertyManager manager = getServer().getPropertyManager();
manager.setProperty("online-mode", mode);
manager.savePropertiesFile();
}
public int purgeWhitelist()
{
2016-03-01 16:59:44 +00:00
String[] whitelisted = getServer().getPlayerList().getWhitelisted();
int size = whitelisted.length;
2016-03-01 16:59:44 +00:00
for (EntityPlayer player : getServer().getPlayerList().players)
{
2016-03-01 16:59:44 +00:00
getServer().getPlayerList().getWhitelist().remove(player.getProfile());
}
2014-04-17 16:29:08 +00:00
try
{
2016-03-01 16:59:44 +00:00
getServer().getPlayerList().getWhitelist().save();
2014-04-17 16:29:08 +00:00
}
catch (Exception ex)
{
FLog.warning("Could not purge the whitelist!");
FLog.warning(ex);
2014-04-17 16:29:08 +00:00
}
return size;
}
public boolean isWhitelisted()
{
2016-03-01 16:59:44 +00:00
return getServer().getPlayerList().getHasWhitelist();
}
public List<?> getWhitelisted()
{
2016-03-01 16:59:44 +00:00
return Arrays.asList(getServer().getPlayerList().getWhitelisted());
}
public String getVersion()
{
2016-03-01 16:59:44 +00:00
return getServer().getVersion();
}
private MinecraftServer getServer()
{
return ((CraftServer) Bukkit.getServer()).getServer();
}
}