2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
2012-12-09 03:42:29 +00:00
|
|
|
|
2014-04-14 19:11:41 +00:00
|
|
|
import java.util.Arrays;
|
2013-08-24 19:35:09 +00:00
|
|
|
import java.util.List;
|
2016-03-06 15:56:15 +00:00
|
|
|
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;
|
2012-12-09 03:42:29 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class ServerInterface extends FreedomService
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2017-05-22 18:05:41 +00:00
|
|
|
public static final String COMPILE_NMS_VERSION = "v1_12_R1";
|
2012-12-09 03:42:29 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public ServerInterface(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void setOnlineMode(boolean mode)
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
final PropertyManager manager = getServer().getPropertyManager();
|
2014-09-24 22:37:12 +00:00
|
|
|
manager.setProperty("online-mode", mode);
|
2014-04-14 19:11:41 +00:00
|
|
|
manager.savePropertiesFile();
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public int purgeWhitelist()
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
String[] whitelisted = getServer().getPlayerList().getWhitelisted();
|
2014-04-14 19:11:41 +00:00
|
|
|
int size = whitelisted.length;
|
2016-03-01 16:59:44 +00:00
|
|
|
for (EntityPlayer player : getServer().getPlayerList().players)
|
2015-04-26 22:31:54 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
getServer().getPlayerList().getWhitelist().remove(player.getProfile());
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.warning("Could not purge the whitelist!");
|
|
|
|
FLog.warning(ex);
|
2014-04-17 16:29:08 +00:00
|
|
|
}
|
2014-04-14 19:11:41 +00:00
|
|
|
return size;
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public boolean isWhitelisted()
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
return getServer().getPlayerList().getHasWhitelist();
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public List<?> getWhitelisted()
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
return Arrays.asList(getServer().getPlayerList().getWhitelisted());
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public String getVersion()
|
2012-12-09 03:42:29 +00:00
|
|
|
{
|
2016-03-01 16:59:44 +00:00
|
|
|
return getServer().getVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
private MinecraftServer getServer()
|
|
|
|
{
|
|
|
|
return ((CraftServer) Bukkit.getServer()).getServer();
|
2012-12-09 03:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|