mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 19:46:42 +00:00
Patches
1. Remove marco from dev 2. Add namehistory 3. Fix grammar issues 4. Actually use CoreProtect bridge to rollback players 5. Improve automatic wiper
This commit is contained in:
@ -0,0 +1,259 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.CoreProtectAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.ResultSet;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
|
||||
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)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
if (ConfigEntry.COREPROTECT_AUTO_WIPING_ENABLED.getBoolean() && getCoreProtect() != null)
|
||||
{
|
||||
createAutomaticWiper();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public CoreProtect getCoreProtect()
|
||||
{
|
||||
CoreProtect coreProtect = null;
|
||||
try
|
||||
{
|
||||
final Plugin coreProtectPlugin = Bukkit.getServer().getPluginManager().getPlugin("CoreProtect");
|
||||
|
||||
if (coreProtectPlugin != null && coreProtectPlugin instanceof CoreProtect)
|
||||
{
|
||||
coreProtect = (CoreProtect)coreProtectPlugin;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return coreProtect;
|
||||
}
|
||||
|
||||
public CoreProtectAPI getCoreProtectAPI()
|
||||
{
|
||||
if (coreProtectAPI == null)
|
||||
{
|
||||
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())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return coreProtectAPI;
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
final CoreProtect coreProtect = getCoreProtect();
|
||||
|
||||
return coreProtect != null && coreProtect.isEnabled();
|
||||
}
|
||||
|
||||
// Rollback the specifed player's edits that were in the last 24 hours.
|
||||
public void rollback(final String name)
|
||||
{
|
||||
final CoreProtectAPI coreProtect = getCoreProtectAPI();
|
||||
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
coreProtect.performRollback(86400, Arrays.asList(name), null, null, null, null, 0, null);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
// Reverts a rollback for the specifed player's edits that were in the last 24 hours.
|
||||
public void undoRollback(final String name)
|
||||
{
|
||||
final CoreProtectAPI coreProtect = getCoreProtectAPI();
|
||||
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
coreProtect.performRestore(86400, Arrays.asList(name), null, null, null, null, 0, null);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
public File getDatabase()
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return(new File(getCoreProtect().getDataFolder(), "database.db"));
|
||||
}
|
||||
|
||||
private void createAutomaticWiper()
|
||||
{
|
||||
final long interval = 10 * 20L;
|
||||
final File databaseFile = getDatabase();
|
||||
|
||||
wiper = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final CoreProtect coreProtect = getCoreProtect();
|
||||
if (getDBSize() > ConfigEntry.COREPROTECT_FILE_LIMIT.getInteger())
|
||||
{
|
||||
FLog.info("The CoreProtect log file has grown too big for the server to cope, the data is being wiped!");
|
||||
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())
|
||||
{
|
||||
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())
|
||||
{
|
||||
FUtil.deleteFolder(databaseFile);
|
||||
}
|
||||
pluginManager.enablePlugin(coreProtect);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, interval, interval);
|
||||
}
|
||||
public double getDBSize()
|
||||
{
|
||||
double bytes = getDatabase().length();
|
||||
double kilobytes = (bytes / 1024);
|
||||
double megabytes = (kilobytes / 1024);
|
||||
return (megabytes / 1024);
|
||||
}
|
||||
// Wipes DB for the specified world
|
||||
public void clearDatabase(World world)
|
||||
{
|
||||
clearDatabase(world, false);
|
||||
}
|
||||
|
||||
// Wipes DB for the specified world
|
||||
public void clearDatabase(World world, Boolean shutdown)
|
||||
{
|
||||
final CoreProtect coreProtect = getCoreProtect();
|
||||
|
||||
if (coreProtect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* As CoreProtect doesn't have an api method for deleting all of the data for a specific world
|
||||
we have to do this manually via sql */
|
||||
File databaseFile = getDatabase();
|
||||
Connection connection = null;
|
||||
try
|
||||
{
|
||||
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;
|
||||
while (resultSet.next())
|
||||
{
|
||||
worldID = String.valueOf(resultSet.getInt("id"));
|
||||
}
|
||||
|
||||
// Ensure the world ID is not null
|
||||
if (worldID == null)
|
||||
{
|
||||
FLog.warning("Failed to obtain the world ID for the " + world.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate through each table and delete their data if the world ID matches
|
||||
for (String table : tables)
|
||||
{
|
||||
statement.executeUpdate("DELETE FROM " + table + " WHERE wid = " + worldID);
|
||||
}
|
||||
|
||||
// This shrinks down the file size
|
||||
statement.executeUpdate("VACUUM");
|
||||
|
||||
connection.close();
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.warning("Failed to delete the CoreProtect data for the " + world.getName());
|
||||
}
|
||||
|
||||
// This exits for flatlands wipes
|
||||
if (shutdown)
|
||||
{
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,137 +1,191 @@
|
||||
|
||||
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.Bukkit;
|
||||
import me.totalfreedom.totalfreedommod.command.Command_vanish;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
|
||||
public class EssentialsBridge extends FreedomService
|
||||
{
|
||||
|
||||
private Essentials essentialsPlugin = null;
|
||||
|
||||
public EssentialsBridge(TotalFreedomMod plugin)
|
||||
{
|
||||
private Essentials essentialsPlugin;
|
||||
|
||||
public EssentialsBridge(final TotalFreedomMod plugin) {
|
||||
super(plugin);
|
||||
this.essentialsPlugin = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
|
||||
protected void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
|
||||
protected void onStop() {
|
||||
Command_vanish.vanished.clear();
|
||||
}
|
||||
|
||||
public Essentials getEssentialsPlugin()
|
||||
{
|
||||
if (essentialsPlugin == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
public Essentials getEssentialsPlugin() {
|
||||
if (this.essentialsPlugin == null) {
|
||||
try {
|
||||
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (essentials != null)
|
||||
{
|
||||
if (essentials instanceof Essentials)
|
||||
{
|
||||
essentialsPlugin = (Essentials) essentials;
|
||||
}
|
||||
if (essentials != null && essentials instanceof Essentials) {
|
||||
this.essentialsPlugin = (Essentials)essentials;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return essentialsPlugin;
|
||||
return this.essentialsPlugin;
|
||||
}
|
||||
|
||||
public User getEssentialsUser(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = getEssentialsPlugin();
|
||||
if (essentials != null)
|
||||
{
|
||||
|
||||
public User getEssentialsUser(final String username) {
|
||||
try {
|
||||
final Essentials essentials = this.getEssentialsPlugin();
|
||||
if (essentials != null) {
|
||||
return essentials.getUserMap().getUser(username);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setNickname(String username, String nickname)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
|
||||
public void setNickname(final String username, final String nickname) {
|
||||
try {
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
user.setNickname(nickname);
|
||||
user.setDisplayNick();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getNickname(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
|
||||
public String getNickname(final String username) {
|
||||
try {
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
return user.getNickname();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getLastActivity(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
return FUtil.<Long>getField(user, "lastActivity"); // This is weird
|
||||
|
||||
public long getLastActivity(final String username) {
|
||||
try {
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
return FUtil.getField(user, "lastActivity");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public boolean isEssentialsEnabled()
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = getEssentialsPlugin();
|
||||
if (essentials != null)
|
||||
{
|
||||
|
||||
public void setVanished(final String username, final boolean vanished) {
|
||||
try {
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
user.setVanished(vanished);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
final Player playerdata = (Player)event.getWhoClicked();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvsee()) {
|
||||
final InventoryHolder invHolder = top.getHolder();
|
||||
if (invHolder != null && invHolder instanceof HumanEntity) {
|
||||
final Player invOwner = (Player)invHolder;
|
||||
final Rank recieverRank = ((TotalFreedomMod)this.plugin).rm.getRank(playerdata);
|
||||
final Rank playerRank = ((TotalFreedomMod)this.plugin).rm.getRank(invOwner);
|
||||
if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline()) {
|
||||
event.setCancelled(true);
|
||||
refreshPlayer = playerdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (refreshPlayer != null) {
|
||||
final Player player = refreshPlayer;
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.updateInventory();
|
||||
}
|
||||
}.runTaskLater((Plugin)this.plugin, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
final Player playerdata = (Player)event.getPlayer();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvsee()) {
|
||||
fPlayer.setInvsee(false);
|
||||
refreshPlayer = playerdata;
|
||||
}
|
||||
if (refreshPlayer != null) {
|
||||
final Player player = refreshPlayer;
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.updateInventory();
|
||||
}
|
||||
}.runTaskLater((Plugin)this.plugin, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuitEvent(final PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (Command_vanish.vanished.contains(player)) {
|
||||
Command_vanish.vanished.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEssentialsEnabled() {
|
||||
try {
|
||||
final Essentials essentials = this.getEssentialsPlugin();
|
||||
if (essentials != null) {
|
||||
return essentials.isEnabled();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return false;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
//import me.libraryaddict.disguise.DisallowedDisguises;
|
||||
//import me.libraryaddict.disguise.LibsDisguises;
|
||||
//import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisallowedDisguises;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.plugin.Plugin;
|
||||
public class LibsDisguisesBridge extends FreedomService
|
||||
{
|
||||
|
||||
// private LibsDisguises libsDisguisesPlugin = null;
|
||||
private LibsDisguises libsDisguisesPlugin = null;
|
||||
|
||||
public LibsDisguisesBridge(TotalFreedomMod plugin)
|
||||
{
|
||||
@ -29,7 +29,7 @@ public class LibsDisguisesBridge extends FreedomService
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
/*
|
||||
|
||||
public LibsDisguises getLibsDisguisesPlugin()
|
||||
{
|
||||
if (libsDisguisesPlugin == null)
|
||||
@ -134,5 +134,5 @@ public class LibsDisguisesBridge extends FreedomService
|
||||
}
|
||||
|
||||
return ld.isEnabled();
|
||||
}*/
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user