This commit is contained in:
Telesphoreo
2018-07-24 19:44:00 -07:00
committed by Seth
parent 0d503a6c06
commit 7278176143
24 changed files with 184 additions and 53 deletions

View File

@ -23,9 +23,9 @@ import java.util.List;
public class CoreProtectBridge extends FreedomService
{
private CoreProtectAPI coreProtectAPI = null;
private final List<String> tables = Arrays.asList("co_sign", "co_session", "co_container", "co_block");
private BukkitTask wiper;
public CoreProtectBridge(TotalFreedomMod plugin)
@ -56,7 +56,7 @@ public class CoreProtectBridge extends FreedomService
if (coreProtectPlugin != null && coreProtectPlugin instanceof CoreProtect)
{
coreProtect = (CoreProtect)coreProtectPlugin;
coreProtect = (CoreProtect) coreProtectPlugin;
}
}
catch (Exception ex)
@ -73,9 +73,9 @@ public class CoreProtectBridge extends FreedomService
try
{
final CoreProtect coreProtect = getCoreProtect();
coreProtectAPI = coreProtect.getAPI();
// Check if the plugin or api is not enabled, if so, return null
if (!coreProtect.isEnabled() || !coreProtectAPI.isEnabled())
{
@ -90,7 +90,7 @@ public class CoreProtectBridge extends FreedomService
return coreProtectAPI;
}
public boolean isEnabled()
{
final CoreProtect coreProtect = getCoreProtect();
@ -117,7 +117,7 @@ public class CoreProtectBridge extends FreedomService
}
}.runTaskAsynchronously(plugin);
}
// Reverts a rollback for the specifed player's edits that were in the last 24 hours.
public void undoRollback(final String name)
{
@ -137,7 +137,7 @@ public class CoreProtectBridge extends FreedomService
}
}.runTaskAsynchronously(plugin);
}
public File getDatabase()
{
if (!isEnabled())
@ -145,9 +145,9 @@ public class CoreProtectBridge extends FreedomService
return null;
}
return(new File(getCoreProtect().getDataFolder(), "database.db"));
return (new File(getCoreProtect().getDataFolder(), "database.db"));
}
private void createAutomaticWiper()
{
final long interval = 10 * 20L;
@ -165,15 +165,15 @@ public class CoreProtectBridge extends FreedomService
FUtil.bcastMsg("The CoreProtect log file has grown too big for the server to cope, the data is being wiped!", ChatColor.RED);
PluginManager pluginManager = server.getPluginManager();
pluginManager.disablePlugin(coreProtect);
for(World world : Bukkit.getWorlds())
for (World world : Bukkit.getWorlds())
{
if(!world.equals(plugin.wm.adminworld.getWorld()))
if (!world.equals(plugin.wm.adminworld.getWorld()))
{
clearDatabase(world);
}
}
//check if still too big, if so delete all data
if(getDBSize() > ConfigEntry.COREPROTECT_FILE_LIMIT.getInteger())
if (getDBSize() > ConfigEntry.COREPROTECT_FILE_LIMIT.getInteger())
{
FUtil.deleteFolder(databaseFile);
}
@ -182,6 +182,7 @@ public class CoreProtectBridge extends FreedomService
}
}.runTaskTimer(plugin, interval, interval);
}
public double getDBSize()
{
double bytes = getDatabase().length();
@ -189,6 +190,7 @@ public class CoreProtectBridge extends FreedomService
double megabytes = (kilobytes / 1024);
return (megabytes / 1024);
}
// Wipes DB for the specified world
public void clearDatabase(World world)
{
@ -214,7 +216,7 @@ public class CoreProtectBridge extends FreedomService
connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile);
final Statement statement = connection.createStatement();
statement.setQueryTimeout(30);
// Obtain world ID from CoreProtect database
ResultSet resultSet = statement.executeQuery("SELECT id FROM co_world WHERE world = '" + world.getName() + "'");
String worldID = null;
@ -250,7 +252,7 @@ public class CoreProtectBridge extends FreedomService
// This exits for flatlands wipes
if (shutdown)
{
if(plugin.amp.enabled)
if (plugin.amp.enabled)
{
plugin.amp.restartServer();
}