1.0.8
This commit is contained in:
14
config.yml
14
config.yml
@@ -1,6 +1,18 @@
|
||||
#AuxProtect
|
||||
#Developed by Heliosares
|
||||
#https://www.spigotmc.org/resources/auxprotect.99147/
|
||||
|
||||
# MySQL functionality is experimental. Use with caution.
|
||||
# OLD LOGS WILL NOT BE MIGRATED.
|
||||
MySQL:
|
||||
use: false
|
||||
host: localhost
|
||||
port: 3306
|
||||
database: database
|
||||
username: username
|
||||
password: password
|
||||
#Prefix to be used for all table names. Editing this after creating your databases will cause all past data to be lost.
|
||||
table-prefix: ''
|
||||
purge-cmds:
|
||||
- 'auxprotect 90d'
|
||||
- 'auxprotect_spam 30d'
|
||||
@@ -62,6 +74,8 @@ Actions:
|
||||
Enabled: true
|
||||
ahbuy:
|
||||
Enabled: true
|
||||
elytra:
|
||||
Enabled: true
|
||||
#Automatically check for updates and display notifications in game.
|
||||
#It's recommended to leave this enabled, as I'm constantly improving the plugin.
|
||||
checkforupdates: true
|
||||
@@ -87,6 +87,9 @@ actions:
|
||||
command: executed
|
||||
kill: killed
|
||||
land: projectile landed
|
||||
elytra:
|
||||
p: started flying
|
||||
n: stopped flying
|
||||
ignoreabandoned: ignored abandoned warning
|
||||
ip: Unique IP
|
||||
username: username
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: AuxProtect
|
||||
version: 1.0.7
|
||||
version: 1.0.8
|
||||
main: dev.heliosares.auxprotect.AuxProtect
|
||||
description: A plugin designed to suplement CoreProtect in a few ways.
|
||||
api-version: 1.13
|
||||
|
||||
7
pom.xml
7
pom.xml
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>AuxProtect</groupId>
|
||||
<artifactId>AuxProtect</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.8</version>
|
||||
<name>AuxProtect</name>
|
||||
<build>
|
||||
<directory>${myPath}/plugins</directory>
|
||||
@@ -109,6 +109,11 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${myPath}/plugins/AuctionHouse-1.18-3.1.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.Gypopo</groupId>
|
||||
<artifactId>EconomyShopGUI-API</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<myPath>${env.USERPROFILE}/Documents/TestServer/Test1/</myPath>
|
||||
|
||||
@@ -30,7 +30,7 @@ public class APConfig {
|
||||
inventoryInterval = config.getLong("Actions.inventory.Interval", 3600000);
|
||||
moneyInterval = config.getLong("Actions.money.Interval", 600000);
|
||||
for (EntryAction action : EntryAction.values()) {
|
||||
boolean enabled = config.getBoolean("Actions." + action.toString().toLowerCase() + ".Enabled", false);
|
||||
boolean enabled = config.getBoolean("Actions." + action.toString().toLowerCase() + ".Enabled", true);
|
||||
action.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import dev.heliosares.auxprotect.command.PurgeCommand;
|
||||
import dev.heliosares.auxprotect.database.DatabaseRunnable;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager;
|
||||
import dev.heliosares.auxprotect.database.SQLManager;
|
||||
import dev.heliosares.auxprotect.listeners.*;
|
||||
import dev.heliosares.auxprotect.utils.InvSerialization;
|
||||
import dev.heliosares.auxprotect.utils.Language;
|
||||
@@ -62,7 +62,7 @@ public class AuxProtect extends JavaPlugin implements IAuxProtect {
|
||||
private Economy econ;
|
||||
private static AuxProtect instance;
|
||||
|
||||
SQLiteManager sqlManager;
|
||||
SQLManager sqlManager;
|
||||
|
||||
public String update;
|
||||
long lastCheckedForUpdate;
|
||||
@@ -107,31 +107,51 @@ public class AuxProtect extends JavaPlugin implements IAuxProtect {
|
||||
}
|
||||
debug("Compatability version: " + SERVER_VERSION, 1);
|
||||
|
||||
File sqliteFile = new File(getDataFolder(), "database/auxprotect.db");
|
||||
if (!sqliteFile.getParentFile().exists()) {
|
||||
if (!sqliteFile.getParentFile().mkdirs()) {
|
||||
this.getLogger().severe("Failed to create database directory.");
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!sqliteFile.exists()) {
|
||||
try {
|
||||
if (!sqliteFile.createNewFile()) {
|
||||
throw new IOException();
|
||||
boolean mysql = getConfig().getBoolean("MySQL.use", false);
|
||||
String user = getConfig().getString("MySQL.username", "");
|
||||
String pass = getConfig().getString("MySQL.password", "");
|
||||
String uri = "";
|
||||
if (mysql) {
|
||||
String host = getConfig().getString("MySQL.host", "localhost");
|
||||
String port = getConfig().getString("MySQL.port", "3306");
|
||||
String database = getConfig().getString("MySQL.database", "database");
|
||||
uri = String.format("jdbc:mysql://%s:%s/%s", host, port, database);
|
||||
} else {
|
||||
File sqliteFile = new File(getDataFolder(), "database/auxprotect.db");
|
||||
if (!sqliteFile.getParentFile().exists()) {
|
||||
if (!sqliteFile.getParentFile().mkdirs()) {
|
||||
this.getLogger().severe("Failed to create database directory.");
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
this.getLogger().severe("Failed to create database file.");
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
if (!sqliteFile.exists()) {
|
||||
try {
|
||||
if (!sqliteFile.createNewFile()) {
|
||||
throw new IOException();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
this.getLogger().severe("Failed to create database file.");
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
uri = "jdbc:sqlite:" + sqliteFile.getAbsolutePath();
|
||||
}
|
||||
sqlManager = new SQLiteManager(this, "jdbc:sqlite:" + sqliteFile.getAbsolutePath());
|
||||
|
||||
sqlManager = new SQLManager(this, uri, getConfig().getString("MySQL.table-prefix"));
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!sqlManager.connect()) {
|
||||
boolean success = false;
|
||||
if (mysql) {
|
||||
success = sqlManager.connect(user, pass);
|
||||
} else {
|
||||
success = sqlManager.connect();
|
||||
}
|
||||
if (!success) {
|
||||
getLogger().severe("Failed to connect to SQL database. Disabling.");
|
||||
setEnabled(false);
|
||||
return;
|
||||
@@ -312,7 +332,7 @@ public class AuxProtect extends JavaPlugin implements IAuxProtect {
|
||||
}
|
||||
}
|
||||
|
||||
public SQLiteManager getSqlManager() {
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.heliosares.auxprotect;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager;
|
||||
import dev.heliosares.auxprotect.database.SQLManager;
|
||||
|
||||
public interface IAuxProtect {
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface IAuxProtect {
|
||||
|
||||
boolean isBungee();
|
||||
|
||||
SQLiteManager getSqlManager();
|
||||
SQLManager getSqlManager();
|
||||
|
||||
int getDebug();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.UUID;
|
||||
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.LookupException;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
|
||||
@@ -13,7 +13,7 @@ import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.bungee.command.APCommand;
|
||||
import dev.heliosares.auxprotect.database.DatabaseRunnable;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager;
|
||||
import dev.heliosares.auxprotect.database.SQLManager;
|
||||
import dev.heliosares.auxprotect.listeners.ChestShopListener;
|
||||
import dev.heliosares.auxprotect.listeners.EntityListener;
|
||||
import dev.heliosares.auxprotect.listeners.GuiShopListener;
|
||||
@@ -34,7 +34,7 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
|
||||
protected Configuration config;
|
||||
public Language lang;
|
||||
public int debug;
|
||||
SQLiteManager sqlManager;
|
||||
SQLManager sqlManager;
|
||||
public DatabaseRunnable dbRunnable;
|
||||
private static AuxProtectBungee instance;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sqlManager = new SQLiteManager(this, "jdbc:sqlite:" + sqliteFile.getAbsolutePath());
|
||||
sqlManager = new SQLManager(this, "jdbc:sqlite:" + sqliteFile.getAbsolutePath(), null);
|
||||
if (!sqlManager.connect()) {
|
||||
this.getLogger().severe("Failed to connect to SQL database. Disabling.");
|
||||
this.onDisable();
|
||||
@@ -121,7 +121,7 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
|
||||
return getResourceAsStream(string);
|
||||
}
|
||||
|
||||
public SQLiteManager getSqlManager() {
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.heliosares.auxprotect.bungee.AuxProtectBungee;
|
||||
import dev.heliosares.auxprotect.bungee.Results;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.LookupException;
|
||||
import dev.heliosares.auxprotect.utils.MyPermission;
|
||||
import dev.heliosares.auxprotect.utils.PlayTimeSolver;
|
||||
import dev.heliosares.auxprotect.utils.TimeUtil;
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.heliosares.auxprotect.command;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -174,7 +175,7 @@ public class APCommand implements CommandExecutor {
|
||||
sender.sendMessage("§7Average record time per execution: §9"
|
||||
+ Math.round(plugin.getSqlManager().putTimePerExec.getMean() / 1000.0) / 1000.0 + "§7ms");
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("sql")) {
|
||||
} else if (args[0].equalsIgnoreCase("sql") || args[0].equalsIgnoreCase("sqlu")) {
|
||||
if (!MyPermission.SQL.hasPermission(sender) || !sender.equals(Bukkit.getConsoleSender())) {
|
||||
sender.sendMessage(plugin.translate("no-permission"));
|
||||
return true;
|
||||
@@ -184,7 +185,20 @@ public class APCommand implements CommandExecutor {
|
||||
msg += args[i] + " ";
|
||||
}
|
||||
try {
|
||||
plugin.getSqlManager().execute(msg.trim());
|
||||
if (args[0].equalsIgnoreCase("sql")) {
|
||||
plugin.getSqlManager().execute(msg.trim());
|
||||
} else {
|
||||
List<List<String>> results = plugin.getSqlManager().executeUpdate(msg.trim());
|
||||
if (results != null) {
|
||||
for (List<String> result : results) {
|
||||
String line = "";
|
||||
for (String part : result) {
|
||||
line += part + ", ";
|
||||
}
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
sender.sendMessage("§cAn error occured.");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -14,7 +14,7 @@ import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.Results;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.LookupException;
|
||||
import dev.heliosares.auxprotect.utils.MoneySolver;
|
||||
import dev.heliosares.auxprotect.utils.MyPermission;
|
||||
import dev.heliosares.auxprotect.utils.PlayTimeSolver;
|
||||
|
||||
@@ -15,8 +15,8 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.TABLE;
|
||||
import dev.heliosares.auxprotect.database.SQLManager;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.TABLE;
|
||||
import dev.heliosares.auxprotect.utils.MyPermission;
|
||||
|
||||
public class LookupCommandTab implements TabCompleter {
|
||||
@@ -76,7 +76,7 @@ public class LookupCommandTab implements TabCompleter {
|
||||
if (MyPermission.ADMIN.hasPermission(sender)) {
|
||||
possible.add("db:");
|
||||
if (currentArg.startsWith("db:")) {
|
||||
for (TABLE table : SQLiteManager.TABLE.values()) {
|
||||
for (TABLE table : SQLManager.TABLE.values()) {
|
||||
possible.add("db:" + table.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.database.Results;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.TABLE;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.TABLE;
|
||||
import dev.heliosares.auxprotect.utils.TimeUtil;
|
||||
|
||||
public class PurgeCommand implements CommandExecutor {
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager;
|
||||
import dev.heliosares.auxprotect.database.SQLManager;
|
||||
|
||||
public class PurgeCommandTab implements TabCompleter {
|
||||
// private final AuxProtect plugin;
|
||||
@@ -24,7 +24,7 @@ public class PurgeCommandTab implements TabCompleter {
|
||||
String currentArg = args[args.length - 1];
|
||||
|
||||
if (args.length == 2) {
|
||||
for (SQLiteManager.TABLE table : SQLiteManager.TABLE.values()) {
|
||||
for (SQLManager.TABLE table : SQLManager.TABLE.values()) {
|
||||
possible.add(table.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.Results;
|
||||
import dev.heliosares.auxprotect.database.XrayEntry;
|
||||
import dev.heliosares.auxprotect.database.XrayResults;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.TABLE;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.TABLE;
|
||||
import dev.heliosares.auxprotect.utils.EntryFormatter;
|
||||
import dev.heliosares.auxprotect.utils.MyPermission;
|
||||
import dev.heliosares.auxprotect.utils.TimeUtil;
|
||||
|
||||
@@ -6,15 +6,15 @@ import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import dev.heliosares.auxprotect.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.TABLE;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.TABLE;
|
||||
|
||||
public class DatabaseRunnable implements Runnable {
|
||||
private ConcurrentLinkedQueue<DbEntry> queue;
|
||||
private ConcurrentLinkedQueue<Runnable> lookupqueue;
|
||||
private final SQLiteManager sqlManager;
|
||||
private final SQLManager sqlManager;
|
||||
private final IAuxProtect plugin;
|
||||
|
||||
public DatabaseRunnable(IAuxProtect plugin, SQLiteManager sqlManager) {
|
||||
public DatabaseRunnable(IAuxProtect plugin, SQLManager sqlManager) {
|
||||
queue = new ConcurrentLinkedQueue<>();
|
||||
lookupqueue = new ConcurrentLinkedQueue<>();
|
||||
this.sqlManager = sqlManager;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DbEntry {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getUser(SQLiteManager sqlManager) {
|
||||
public String getUser(SQLManager sqlManager) {
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.heliosares.auxprotect.database;
|
||||
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.TABLE;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.TABLE;
|
||||
|
||||
public enum EntryAction {
|
||||
// TODO Migrate Kick to singles
|
||||
@@ -17,7 +17,7 @@ public enum EntryAction {
|
||||
// END DEFAULT (255)
|
||||
|
||||
// START SPAM(256)
|
||||
POS(256), HURT(257), INV(258, 259), COMMAND(260), KILL(261), LAND(262),
|
||||
POS(256), HURT(257), INV(258, 259), COMMAND(260), KILL(261), LAND(262), ELYTRA(263, 264),
|
||||
// END SPAM(511)
|
||||
|
||||
// START IGNOREABANDONED(512)
|
||||
|
||||
@@ -4,10 +4,13 @@ import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -20,10 +23,12 @@ import org.bukkit.command.CommandSender;
|
||||
import dev.heliosares.auxprotect.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.utils.MovingAverage;
|
||||
|
||||
public class SQLiteManager {
|
||||
public class SQLManager {
|
||||
private Connection connection;
|
||||
private String dbFile;
|
||||
private String targetString;
|
||||
private final IAuxProtect plugin;
|
||||
private static String tablePrefix;
|
||||
private boolean mysql;
|
||||
|
||||
private boolean isConnected;
|
||||
|
||||
@@ -32,6 +37,8 @@ public class SQLiteManager {
|
||||
|
||||
private int version;
|
||||
|
||||
public static final int DBVERSION = 2;
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
@@ -50,23 +57,31 @@ public class SQLiteManager {
|
||||
private int count;
|
||||
|
||||
public static enum TABLE {
|
||||
AUXPROTECT, AUXPROTECT_SPAM, AUXPROTECT_LONGTERM, AUXPROTECT_ABANDONED, AUXPROTECT_INVENTORY, WORLDS;
|
||||
AUXPROTECT, AUXPROTECT_SPAM, AUXPROTECT_LONGTERM, AUXPROTECT_ABANDONED, AUXPROTECT_INVENTORY, AUXPROTECT_WORLDS;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
return tablePrefix + super.toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public String holdingConnection;
|
||||
public long holdingConnectionSince;
|
||||
|
||||
public SQLiteManager(IAuxProtect plugin, String dbFile) {
|
||||
public SQLManager(IAuxProtect plugin, String target, String prefix) {
|
||||
this.plugin = plugin;
|
||||
this.dbFile = dbFile;
|
||||
this.targetString = target;
|
||||
if (prefix == null) {
|
||||
tablePrefix = "";
|
||||
} else {
|
||||
tablePrefix = prefix;
|
||||
if (tablePrefix.length() > 0 && !tablePrefix.endsWith("_")) {
|
||||
tablePrefix += "_";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
public boolean connect(String user, String pass) {
|
||||
boolean driver = false;
|
||||
if (!driver)
|
||||
try {
|
||||
@@ -92,7 +107,13 @@ public class SQLiteManager {
|
||||
}
|
||||
|
||||
try {
|
||||
connection = DriverManager.getConnection(dbFile);
|
||||
if (user != null && pass != null) {
|
||||
mysql = true;
|
||||
connection = DriverManager.getConnection(targetString, user, pass);
|
||||
} else {
|
||||
mysql = false;
|
||||
connection = DriverManager.getConnection(targetString);
|
||||
}
|
||||
init();
|
||||
|
||||
isConnected = true;
|
||||
@@ -103,6 +124,10 @@ public class SQLiteManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
return connect(null, null);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (connection != null) {
|
||||
synchronized (connection) {
|
||||
@@ -139,7 +164,7 @@ public class SQLiteManager {
|
||||
version = version_;
|
||||
versionTime = versionTime_;
|
||||
}
|
||||
plugin.debug("Version at " + versionTime_ + " was v" + version_ + ".", 5);
|
||||
plugin.debug("Version at " + versionTime_ + " was v" + version_ + ".", 1);
|
||||
}
|
||||
results.close();
|
||||
|
||||
@@ -147,10 +172,25 @@ public class SQLiteManager {
|
||||
PreparedStatement pstmt = connection
|
||||
.prepareStatement("INSERT INTO version (time,version) VALUES (?,?)");
|
||||
pstmt.setLong(1, System.currentTimeMillis());
|
||||
pstmt.setInt(2, 1);
|
||||
plugin.debug("Updating database to v1", 1);
|
||||
pstmt.setInt(2, DBVERSION);
|
||||
plugin.debug("Setting database to v" + DBVERSION, 1);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
} else {
|
||||
// This is inside an else so that it's only done if this isn't the first time
|
||||
// running the plugin.
|
||||
if (version < 2) {
|
||||
plugin.info("Migrating database to v2");
|
||||
execute("ALTER TABLE worlds RENAME TO auxprotect_worlds;");
|
||||
|
||||
PreparedStatement pstmt = connection
|
||||
.prepareStatement("INSERT INTO version (time,version) VALUES (?,?)");
|
||||
pstmt.setLong(1, System.currentTimeMillis());
|
||||
pstmt.setInt(2, 2);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
plugin.info("Done migrating.");
|
||||
}
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + TABLE.AUXPROTECT.toString() + " (\n";
|
||||
@@ -222,11 +262,12 @@ public class SQLiteManager {
|
||||
statement.execute(stmt);
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + TABLE.WORLDS.toString() + " (name varchar(255), wid SMALLINT);";
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + TABLE.AUXPROTECT_WORLDS.toString()
|
||||
+ " (name varchar(255), wid SMALLINT);";
|
||||
plugin.debug(stmt, 3);
|
||||
statement.execute(stmt);
|
||||
|
||||
stmt = "SELECT * FROM " + TABLE.WORLDS + ";";
|
||||
stmt = "SELECT * FROM " + TABLE.AUXPROTECT_WORLDS.toString() + ";";
|
||||
plugin.debug(stmt, 3);
|
||||
results = statement.executeQuery(stmt);
|
||||
while (results.next()) {
|
||||
@@ -246,11 +287,37 @@ public class SQLiteManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void execute(String string) throws SQLException {
|
||||
public void execute(String stmt) throws SQLException {
|
||||
plugin.debug(stmt, 2);
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute(stmt);
|
||||
statement.close();
|
||||
}
|
||||
|
||||
public List<List<String>> executeUpdate(String string) throws SQLException {
|
||||
plugin.debug(string, 2);
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute(string);
|
||||
ResultSet rs = statement.executeQuery(string);
|
||||
|
||||
if (rs == null) {
|
||||
statement.close();
|
||||
return null;
|
||||
}
|
||||
final ResultSetMetaData meta = rs.getMetaData();
|
||||
final int columnCount = meta.getColumnCount();
|
||||
final List<List<String>> rowList = new LinkedList<List<String>>();
|
||||
while (rs.next()) {
|
||||
final List<String> columnList = new LinkedList<String>();
|
||||
rowList.add(columnList);
|
||||
|
||||
for (int column = 1; column <= columnCount; ++column) {
|
||||
final Object value = rs.getObject(column);
|
||||
columnList.add(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
statement.close();
|
||||
return rowList;
|
||||
}
|
||||
|
||||
protected long put(TABLE table, ArrayList<DbEntry> entries) throws SQLException {
|
||||
@@ -293,7 +360,7 @@ public class SQLiteManager {
|
||||
stmt += ",";
|
||||
}
|
||||
}
|
||||
PreparedStatement statement = connection.prepareStatement(stmt);
|
||||
PreparedStatement statement = connection.prepareStatement(stmt, Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
int i = 1;
|
||||
for (DbEntry dbEntry : entries) {
|
||||
@@ -571,7 +638,7 @@ public class SQLiteManager {
|
||||
} else if (table == TABLE.AUXPROTECT_ABANDONED) {
|
||||
stmt = "SELECT time, user, action_id, world_id, x, y, z, target FROM " + table.toString() + stmt;
|
||||
hasData = false;
|
||||
} else if (table == TABLE.WORLDS && plugin.getDebug() > 0) {
|
||||
} else if (table == TABLE.AUXPROTECT_WORLDS && plugin.getDebug() > 0) {
|
||||
stmt = "SELECT * FROM " + table.toString();
|
||||
plugin.debug(stmt, 3);
|
||||
try {
|
||||
@@ -861,7 +928,7 @@ public class SQLiteManager {
|
||||
}
|
||||
try {
|
||||
|
||||
String stmt = "INSERT INTO " + TABLE.WORLDS.toString() + " (name, wid)";
|
||||
String stmt = "INSERT INTO " + TABLE.AUXPROTECT_WORLDS.toString() + " (name, wid)";
|
||||
stmt += "\nVALUES (?,?)";
|
||||
PreparedStatement pstmt = connection.prepareStatement(stmt);
|
||||
pstmt.setString(1, world);
|
||||
@@ -889,9 +956,19 @@ public class SQLiteManager {
|
||||
holdingConnectionSince = System.currentTimeMillis();
|
||||
holdingConnection = "count";
|
||||
try {
|
||||
PreparedStatement pstmt = connection.prepareStatement("SELECT COUNT(1) FROM " + table.toString());
|
||||
String stmtStr = "";
|
||||
if (mysql) {
|
||||
stmtStr = "SELECT COUNT(*) FROM " + table.toString();
|
||||
} else {
|
||||
stmtStr = "SELECT COUNT(1) FROM " + table.toString();
|
||||
}
|
||||
plugin.debug(stmtStr, 5);
|
||||
PreparedStatement pstmt = connection.prepareStatement(stmtStr);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
int count = rs.getInt(1);
|
||||
int count = 0;
|
||||
if (rs.next()) {
|
||||
count = rs.getInt(1);
|
||||
}
|
||||
total += count;
|
||||
plugin.debug(table.toString() + ": " + count + " rows.");
|
||||
rs.close();
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.event.entity.PlayerLeashEntityEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@@ -37,7 +38,7 @@ import dev.heliosares.auxprotect.AuxProtect;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.PickupEntry;
|
||||
import dev.heliosares.auxprotect.database.SQLiteManager.LookupException;
|
||||
import dev.heliosares.auxprotect.database.SQLManager.LookupException;
|
||||
import dev.heliosares.auxprotect.utils.ChartRenderer;
|
||||
import dev.heliosares.auxprotect.utils.InvSerialization;
|
||||
import dev.heliosares.auxprotect.utils.MyPermission;
|
||||
@@ -117,6 +118,16 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEntityToggleGlideEvent(EntityToggleGlideEvent e) {
|
||||
if (e.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
DbEntry entry = new DbEntry(AuxProtect.getLabel(e.getEntity()), EntryAction.ELYTRA, e.isGliding(),
|
||||
e.getEntity().getLocation(), "", "");
|
||||
plugin.dbRunnable.add(entry);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onConsume(PlayerItemConsumeEvent e) {
|
||||
if (e.isCancelled()) {
|
||||
|
||||
Reference in New Issue
Block a user