CoreProtect v20.0 release
This commit is contained in:
parent
415d7b323a
commit
48ef18e2c8
173 changed files with 25072 additions and 1 deletions
329
src/main/java/net/coreprotect/patch/Patch.java
Executable file
329
src/main/java/net/coreprotect/patch/Patch.java
Executable file
|
|
@ -0,0 +1,329 @@
|
|||
package net.coreprotect.patch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Consumer;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class Patch {
|
||||
|
||||
private static boolean patching = false;
|
||||
private static boolean patchNotification = false;
|
||||
private static Integer[] firstVersion = null;
|
||||
|
||||
public static boolean continuePatch() {
|
||||
return patching && ConfigHandler.serverRunning;
|
||||
}
|
||||
|
||||
public static String getFirstVersion() {
|
||||
String result = "";
|
||||
if (firstVersion != null) {
|
||||
if ((firstVersion[0] + "." + firstVersion[1] + "." + firstVersion[2]).equals("0.0.0")) {
|
||||
result = Util.getPluginVersion();
|
||||
}
|
||||
else {
|
||||
result = firstVersion[1] + "." + firstVersion[2];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static String getClassVersion(String version) {
|
||||
return (version.split(".__"))[1].replaceAll("_", ".");
|
||||
}
|
||||
|
||||
public static Integer[] getDatabaseVersion(Connection connection, boolean lastVersion) {
|
||||
Integer[] last_version = new Integer[] { 0, 0, 0 };
|
||||
try {
|
||||
String query = "SELECT version FROM " + ConfigHandler.prefix + "version ORDER BY rowid " + (lastVersion ? "DESC" : "ASC") + " LIMIT 0, 1";
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet rs = statement.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
String version = rs.getString("version");
|
||||
if (!version.contains(".")) { // v200-205
|
||||
int version_int = Integer.parseInt(version);
|
||||
version = String.format(Locale.ROOT, "%3.2f", version_int / 100.0);
|
||||
}
|
||||
version = version.replaceAll(",", ".");
|
||||
String[] old_version_split = version.split("\\.");
|
||||
if (old_version_split.length > 2) { // #.#.#
|
||||
last_version[0] = Integer.parseInt(old_version_split[0]);
|
||||
last_version[1] = Integer.parseInt(old_version_split[1]);
|
||||
last_version[2] = Integer.parseInt(old_version_split[2]);
|
||||
}
|
||||
else { // #.#
|
||||
int revision = 0;
|
||||
String parse = old_version_split[1];
|
||||
if (parse.length() > 1) {
|
||||
revision = Integer.parseInt(parse.substring(1));
|
||||
}
|
||||
last_version[0] = Integer.parseInt(old_version_split[0]);
|
||||
last_version[1] = revision;
|
||||
last_version[2] = 0;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return last_version;
|
||||
}
|
||||
|
||||
private static List<String> getPatches() {
|
||||
List<String> patches = new ArrayList<>();
|
||||
|
||||
try {
|
||||
File pluginFile = new File(CoreProtect.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
if (pluginFile.getPath().endsWith(".jar")) {
|
||||
JarInputStream jarInputStream = new JarInputStream(new FileInputStream(pluginFile));
|
||||
while (true) {
|
||||
JarEntry jarEntry = jarInputStream.getNextJarEntry();
|
||||
if (jarEntry == null) {
|
||||
break;
|
||||
}
|
||||
String className = jarEntry.getName();
|
||||
if (className.startsWith("net/coreprotect/patch/script/__") && className.endsWith(".class")) {
|
||||
Class<?> patchClass = Class.forName(className.substring(0, className.length() - 6).replaceAll("/", "."));
|
||||
String patchVersion = getClassVersion(patchClass.getName());
|
||||
if (!Util.newVersion(Util.getInternalPluginVersion(), patchVersion)) {
|
||||
patches.add(patchVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
jarInputStream.close();
|
||||
}
|
||||
|
||||
Collections.sort(patches, (o1, o2) -> {
|
||||
if (Util.newVersion(o1, o2)) {
|
||||
return -1;
|
||||
}
|
||||
else if (Util.newVersion(o2, o1)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return patches;
|
||||
}
|
||||
|
||||
public static void processConsumer() {
|
||||
try {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_PROCESSING));
|
||||
boolean isRunning = ConfigHandler.serverRunning;
|
||||
ConfigHandler.serverRunning = true;
|
||||
Consumer.isPaused = false;
|
||||
Thread.sleep(1000);
|
||||
while (Consumer.isPaused) {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
ConfigHandler.serverRunning = isRunning;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static int runPatcher(Integer[] lastVersion, Integer[] version) {
|
||||
int result = -1;
|
||||
patching = true;
|
||||
|
||||
try {
|
||||
boolean patched = false;
|
||||
boolean allPatches = true;
|
||||
Connection connection = Database.getConnection(true, 0);
|
||||
Statement statement = connection.createStatement();
|
||||
Integer[] newVersion = lastVersion;
|
||||
|
||||
// Fix for versions 2.0.0 through 2.0.9
|
||||
if (newVersion[1] == 0 && newVersion[2] > 0) {
|
||||
newVersion[1] = newVersion[2];
|
||||
newVersion[2] = 0;
|
||||
}
|
||||
|
||||
List<String> patches = getPatches();
|
||||
for (String patchData : patches) {
|
||||
String[] thePatch = patchData.split("\\.");
|
||||
int patchMajor = Integer.parseInt(thePatch[0]);
|
||||
int patchMinor = Integer.parseInt(thePatch[1]);
|
||||
int patchRevision = Integer.parseInt(thePatch[2]);
|
||||
Integer[] patchVersion = new Integer[] { patchMajor, patchMinor, patchRevision };
|
||||
|
||||
boolean performPatch = Util.newVersion(newVersion, patchVersion);
|
||||
if (performPatch) {
|
||||
boolean success = false;
|
||||
try {
|
||||
Chat.console("-----");
|
||||
Chat.console(Phrase.build(Phrase.PATCH_STARTED, "v" + patchMinor + "." + patchRevision));
|
||||
Chat.console("-----");
|
||||
|
||||
if (continuePatch()) {
|
||||
Class<?> patchClass = Class.forName("net.coreprotect.patch.script.__" + patchData.replaceAll("\\.", "_"));
|
||||
Method patchMethod = patchClass.getDeclaredMethod("patch", Statement.class);
|
||||
patchMethod.setAccessible(true);
|
||||
success = (Boolean) patchMethod.invoke(null, statement);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (success) {
|
||||
patched = true;
|
||||
newVersion = patchVersion;
|
||||
}
|
||||
else {
|
||||
allPatches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allPatches) { // all patches completed
|
||||
if (patched) { // actually performed a patch
|
||||
result = 1;
|
||||
}
|
||||
else { // no patches necessary
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// mark as being up to date
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
if (result >= 0) {
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version (time,version) VALUES ('" + unixtimestamp + "', '" + version[0] + "." + version[1] + "." + version[2] + "')");
|
||||
}
|
||||
else if (patched) {
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version (time,version) VALUES ('" + unixtimestamp + "', '" + newVersion[0] + "." + newVersion[1] + "." + newVersion[2] + "')");
|
||||
}
|
||||
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
patching = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean versionCheck(Statement statement) {
|
||||
try {
|
||||
Integer[] currentVersion = Util.getInternalPluginVersion();
|
||||
firstVersion = getDatabaseVersion(statement.getConnection(), false);
|
||||
Integer[] lastVersion = getDatabaseVersion(statement.getConnection(), true);
|
||||
|
||||
boolean newVersion = Util.newVersion(lastVersion, currentVersion);
|
||||
if (newVersion && lastVersion[0] > 0 && !ConfigHandler.converterRunning) {
|
||||
Integer[] minimumVersion = new Integer[] { 2, 0, 0 };
|
||||
if (Util.newVersion(lastVersion, minimumVersion)) {
|
||||
Chat.sendConsoleMessage("§c[CoreProtect] " + Phrase.build(Phrase.PATCH_OUTDATED_1, "v" + minimumVersion[0] + "." + minimumVersion[1] + "." + minimumVersion[2]));
|
||||
Chat.sendConsoleMessage("§c[CoreProtect] " + Phrase.build(Phrase.PATCH_OUTDATED_2));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ConfigHandler.EDITION_BRANCH.contains("-dev")) {
|
||||
Chat.sendConsoleMessage("§e[CoreProtect] " + Phrase.build(Phrase.DEVELOPMENT_BRANCH));
|
||||
return true;
|
||||
}
|
||||
|
||||
ConfigHandler.converterRunning = true;
|
||||
Consumer.isPaused = true;
|
||||
final Integer[] oldVersion = lastVersion;
|
||||
final Integer[] newVersionFinal = currentVersion;
|
||||
class patchStatus implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int time_start = (int) (System.currentTimeMillis() / 1000L);
|
||||
int alertTime = time_start + 10;
|
||||
if (patchNotification) {
|
||||
alertTime = alertTime + 20;
|
||||
}
|
||||
while (ConfigHandler.converterRunning) {
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
if (time >= alertTime) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_UPGRADING));
|
||||
alertTime = alertTime + 30;
|
||||
patchNotification = true;
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
class runPatch implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int finished = runPatcher(oldVersion, newVersionFinal);
|
||||
ConfigHandler.converterRunning = false;
|
||||
if (finished == 1) {
|
||||
processConsumer();
|
||||
Chat.console("-----");
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SUCCESS, "v" + CoreProtect.getInstance().getDescription().getVersion()));
|
||||
Chat.console("-----");
|
||||
}
|
||||
else if (finished == 0) {
|
||||
Consumer.isPaused = false;
|
||||
}
|
||||
else if (finished == -1) {
|
||||
processConsumer();
|
||||
Chat.console(Phrase.build(Phrase.PATCH_INTERRUPTED));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
(new Thread(new runPatch())).start();
|
||||
(new Thread(new patchStatus())).start();
|
||||
}
|
||||
else if (lastVersion[0] == 0) {
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version (time,version) VALUES ('" + unixtimestamp + "', '" + currentVersion[0] + "." + (ConfigHandler.EDITION_BRANCH.contains("-dev") ? (currentVersion[1] - 1) : currentVersion[1]) + "." + currentVersion[2] + "')");
|
||||
}
|
||||
else {
|
||||
currentVersion[2] = 0;
|
||||
lastVersion[2] = 0;
|
||||
if (Util.newVersion(currentVersion, lastVersion)) {
|
||||
Chat.sendConsoleMessage(Color.RED + "[CoreProtect] " + Phrase.build(Phrase.VERSION_REQUIRED, "CoreProtect", "v" + lastVersion[1] + "." + lastVersion[2]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
27
src/main/java/net/coreprotect/patch/script/__2_10_0.java
Executable file
27
src/main/java/net/coreprotect/patch/script/__2_10_0.java
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class __2_10_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user ADD COLUMN uuid varchar(64), ADD INDEX(uuid)");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user ADD COLUMN uuid TEXT;");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS uuid_index ON " + ConfigHandler.prefix + "user(uuid);");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
71
src/main/java/net/coreprotect/patch/script/__2_11_0.java
Executable file
71
src/main/java/net/coreprotect/patch/script/__2_11_0.java
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class __2_11_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("START TRANSACTION");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("BEGIN TRANSACTION");
|
||||
}
|
||||
|
||||
for (Art artType : Art.values()) {
|
||||
Integer type = artType.getId();
|
||||
String name = artType.toString().toLowerCase(Locale.ROOT);
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "art_map (id, art) VALUES ('" + type + "', '" + name + "')");
|
||||
ConfigHandler.art.put(name, type);
|
||||
ConfigHandler.artReversed.put(type, name);
|
||||
if (type > ConfigHandler.artId) {
|
||||
ConfigHandler.artId = type;
|
||||
}
|
||||
}
|
||||
|
||||
for (EntityType entityType : EntityType.values()) {
|
||||
Integer type = (int) entityType.getTypeId();
|
||||
String name = entityType.toString().toLowerCase(Locale.ROOT);
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "entity_map (id, entity) VALUES ('" + type + "', '" + name + "')");
|
||||
ConfigHandler.entities.put(name, type);
|
||||
ConfigHandler.entitiesReversed.put(type, name);
|
||||
if (type > ConfigHandler.entityId) {
|
||||
ConfigHandler.entityId = type;
|
||||
}
|
||||
}
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
Integer type = material.getId();
|
||||
String name = material.toString().toLowerCase(Locale.ROOT);
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "material_map (id, material) VALUES ('" + type + "', '" + name + "')");
|
||||
ConfigHandler.materials.put(name, type);
|
||||
ConfigHandler.materialsReversed.put(type, name);
|
||||
if (type > ConfigHandler.materialId) {
|
||||
ConfigHandler.materialId = type;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("COMMIT");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("COMMIT TRANSACTION");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
62
src/main/java/net/coreprotect/patch/script/__2_15_0.java
Executable file
62
src/main/java/net/coreprotect/patch/script/__2_15_0.java
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
|
||||
public class __2_15_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat MODIFY message VARCHAR(1000)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command MODIFY message VARCHAR(1000)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user MODIFY user VARCHAR(100)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "username_log MODIFY user VARCHAR(100)");
|
||||
}
|
||||
|
||||
String query = "SELECT rowid as id, material FROM " + ConfigHandler.prefix + "material_map";
|
||||
String preparedQuery = "UPDATE " + ConfigHandler.prefix + "material_map SET material = ? WHERE rowid = ?";
|
||||
PreparedStatement preparedStatement = statement.getConnection().prepareStatement(preparedQuery);
|
||||
|
||||
Database.beginTransaction(statement);
|
||||
ResultSet rs = statement.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
int rowid = rs.getInt("id");
|
||||
String material = rs.getString("material");
|
||||
if (material.startsWith("minecraft:") && !material.contains("minecraft:legacy_")) {
|
||||
material = material.replace("minecraft:", "minecraft:legacy_");
|
||||
preparedStatement.setString(1, material);
|
||||
preparedStatement.setInt(2, rowid);
|
||||
preparedStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
Database.commitTransaction(statement);
|
||||
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block MODIFY COLUMN rowid bigint(20) NOT NULL AUTO_INCREMENT, ADD COLUMN blockdata BLOB");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block ADD COLUMN blockdata BLOB");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// already updated
|
||||
}
|
||||
|
||||
ConfigHandler.loadTypes(statement);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
108
src/main/java/net/coreprotect/patch/script/__2_16_0.java
Executable file
108
src/main/java/net/coreprotect/patch/script/__2_16_0.java
Executable file
|
|
@ -0,0 +1,108 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.patch.Patch;
|
||||
|
||||
public class __2_16_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull MODIFY owner VARCHAR(64), DROP COLUMN type, DROP COLUMN data, DROP COLUMN rotation");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// update already ran
|
||||
}
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("BEGIN TRANSACTION");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull RENAME TO " + ConfigHandler.prefix + "skull_temp");
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + ConfigHandler.prefix + "skull (id INTEGER PRIMARY KEY ASC, time INTEGER, owner TEXT);");
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "skull SELECT id, time, owner FROM " + ConfigHandler.prefix + "skull_temp");
|
||||
statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "skull_temp");
|
||||
statement.executeUpdate("COMMIT TRANSACTION");
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
String idList = "";
|
||||
String query = "SELECT id FROM " + ConfigHandler.prefix + "material_map WHERE material LIKE '%_CONCRETE' OR material LIKE '%_CONCRETE_POWDER'";
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
String id = resultSet.getString("id");
|
||||
if (idList.length() == 0) {
|
||||
idList = id;
|
||||
}
|
||||
else {
|
||||
idList = idList + ", " + id;
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
|
||||
if (idList.length() > 0) {
|
||||
query = "SELECT rowid as id FROM " + ConfigHandler.prefix + "block WHERE type IN(" + idList + ") AND y='0'";
|
||||
String preparedQueryDelete = "DELETE FROM " + ConfigHandler.prefix + "block WHERE rowid = ?";
|
||||
PreparedStatement preparedStatementDelete = statement.getConnection().prepareStatement(preparedQueryDelete);
|
||||
Database.beginTransaction(statement);
|
||||
resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
int rowid = resultSet.getInt("id");
|
||||
preparedStatementDelete.setInt(1, rowid);
|
||||
preparedStatementDelete.executeUpdate();
|
||||
}
|
||||
resultSet.close();
|
||||
Database.commitTransaction(statement);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String query = "SELECT rowid as id, user FROM " + ConfigHandler.prefix + "user WHERE uuid IS NULL";
|
||||
String preparedQuerySelect = "SELECT EXISTS (SELECT user FROM " + ConfigHandler.prefix + "session WHERE user = ?) OR EXISTS (SELECT user FROM " + ConfigHandler.prefix + "container WHERE user = ?) OR EXISTS (SELECT user FROM " + ConfigHandler.prefix + "command WHERE user = ?) OR EXISTS (SELECT user FROM " + ConfigHandler.prefix + "chat WHERE user = ?) OR EXISTS (SELECT user FROM " + ConfigHandler.prefix + "block WHERE user = ?) as userExists";
|
||||
String preparedQueryDelete = "DELETE FROM " + ConfigHandler.prefix + "user WHERE rowid = ?";
|
||||
PreparedStatement preparedStatementSelect = statement.getConnection().prepareStatement(preparedQuerySelect);
|
||||
PreparedStatement preparedStatementDelete = statement.getConnection().prepareStatement(preparedQueryDelete);
|
||||
|
||||
Database.beginTransaction(statement);
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
int rowid = resultSet.getInt("id");
|
||||
String user = resultSet.getString("user");
|
||||
if (!user.startsWith("#")) {
|
||||
Database.setMultiInt(preparedStatementSelect, rowid, 5);
|
||||
ResultSet resultSetUser = preparedStatementSelect.executeQuery();
|
||||
resultSetUser.next();
|
||||
boolean userExists = resultSetUser.getBoolean("userExists");
|
||||
if (!userExists) {
|
||||
preparedStatementDelete.setInt(1, rowid);
|
||||
preparedStatementDelete.executeUpdate();
|
||||
}
|
||||
resultSetUser.close();
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
Database.commitTransaction(statement);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
26
src/main/java/net/coreprotect/patch/script/__2_17_0.java
Executable file
26
src/main/java/net/coreprotect/patch/script/__2_17_0.java
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class __2_17_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN color int(8)");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN color INTEGER");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
300
src/main/java/net/coreprotect/patch/script/__2_18_0.java
Normal file
300
src/main/java/net/coreprotect/patch/script/__2_18_0.java
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.patch.Patch;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class __2_18_0 {
|
||||
|
||||
protected static boolean createIndexes = true;
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block ADD COLUMN blockdata BLOB");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
String error = e.getMessage().toLowerCase();
|
||||
if (!error.contains("duplicate") && !error.contains("error 1060")) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String query = "SELECT rowid, id, material FROM " + ConfigHandler.prefix + "material_map WHERE material LIKE 'minecraft:legacy_%' LIMIT 0, 1";
|
||||
String preparedBlockQuery = "SELECT rowid as id, data, blockdata FROM " + ConfigHandler.prefix + "block WHERE type = ? AND action < '3'";
|
||||
String preparedContainerQuery = "SELECT rowid as id FROM " + ConfigHandler.prefix + "container WHERE type = ?";
|
||||
String preparedBlockUpdateQuery = "UPDATE " + ConfigHandler.prefix + "block SET type = ?, blockdata = ? WHERE rowid = ?";
|
||||
String preparedContainerUpdateQuery = "UPDATE " + ConfigHandler.prefix + "container SET type = ? WHERE rowid = ?";
|
||||
String preparedMaterialDeleteQuery = "DELETE FROM " + ConfigHandler.prefix + "material_map WHERE rowid = ?";
|
||||
|
||||
boolean hasLegacy = true;
|
||||
while (hasLegacy) {
|
||||
hasLegacy = false;
|
||||
|
||||
PreparedStatement preparedBlockStatement = statement.getConnection().prepareStatement(preparedBlockQuery);
|
||||
PreparedStatement preparedBlockUpdateStatement = statement.getConnection().prepareStatement(preparedBlockUpdateQuery);
|
||||
PreparedStatement preparedContainerStatement = statement.getConnection().prepareStatement(preparedContainerQuery);
|
||||
PreparedStatement preparedContainerUpdateStatement = statement.getConnection().prepareStatement(preparedContainerUpdateQuery);
|
||||
PreparedStatement preparedMaterialDeleteStatement = statement.getConnection().prepareStatement(preparedMaterialDeleteQuery);
|
||||
Database.beginTransaction(statement);
|
||||
try {
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
int blockCount = 1;
|
||||
int containerCount = 1;
|
||||
int rowid = resultSet.getInt("rowid");
|
||||
int oldID = resultSet.getInt("id");
|
||||
String materialName = resultSet.getString("material");
|
||||
|
||||
boolean legacy = true;
|
||||
switch (materialName) {
|
||||
case "minecraft:legacy_wall_sign":
|
||||
materialName = "minecraft:oak_wall_sign";
|
||||
legacy = false;
|
||||
break;
|
||||
case "minecraft:legacy_skull":
|
||||
materialName = "minecraft:skeleton_skull";
|
||||
legacy = false;
|
||||
break;
|
||||
case "minecraft:legacy_long_grass":
|
||||
materialName = "minecraft:grass";
|
||||
legacy = false;
|
||||
break;
|
||||
case "minecraft:legacy_double_plant":
|
||||
materialName = "minecraft:tall_grass";
|
||||
legacy = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Material material = Material.matchMaterial(materialName, legacy);
|
||||
int newID = Util.getBlockId(material);
|
||||
|
||||
preparedBlockStatement.setInt(1, oldID);
|
||||
ResultSet blockResults = preparedBlockStatement.executeQuery();
|
||||
while (blockResults.next()) {
|
||||
int blockID = blockResults.getInt("id");
|
||||
int blockData = blockResults.getInt("data");
|
||||
byte[] blockBlockData = blockResults.getBytes("blockdata");
|
||||
|
||||
Material validatedMaterial = material;
|
||||
int validatedID = newID;
|
||||
if (validatedMaterial == Material.WHITE_WOOL) {
|
||||
validatedMaterial = getWoolColor(blockData);
|
||||
validatedID = Util.getBlockId(validatedMaterial);
|
||||
}
|
||||
|
||||
if (blockBlockData == null && validatedMaterial.isBlock()) {
|
||||
BlockData newBlockData = null;
|
||||
try {
|
||||
newBlockData = Bukkit.getUnsafe().fromLegacy(validatedMaterial, (byte) blockData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// unable to generate block data
|
||||
}
|
||||
if (newBlockData != null) {
|
||||
if (validatedMaterial == Material.OAK_WALL_SIGN && newBlockData instanceof Directional) {
|
||||
Directional directional = (Directional) newBlockData;
|
||||
BlockFace newDirection = getLegacyDirection(blockData);
|
||||
directional.setFacing(newDirection);
|
||||
}
|
||||
if (validatedMaterial == Material.SKELETON_SKULL && newBlockData instanceof Rotatable) {
|
||||
Rotatable rotatable = (Rotatable) newBlockData;
|
||||
BlockFace newRotation = getLegacyRotation(blockData);
|
||||
rotatable.setRotation(newRotation);
|
||||
}
|
||||
blockBlockData = Util.stringToByteData(newBlockData.getAsString(), validatedID);
|
||||
}
|
||||
}
|
||||
|
||||
preparedBlockUpdateStatement.setInt(1, validatedID);
|
||||
preparedBlockUpdateStatement.setObject(2, blockBlockData);
|
||||
preparedBlockUpdateStatement.setInt(3, blockID);
|
||||
preparedBlockUpdateStatement.addBatch();
|
||||
if (blockCount % 1000 == 0) {
|
||||
preparedBlockUpdateStatement.executeBatch();
|
||||
}
|
||||
blockCount++;
|
||||
}
|
||||
preparedBlockUpdateStatement.executeBatch();
|
||||
blockResults.close();
|
||||
|
||||
preparedContainerStatement.setInt(1, oldID);
|
||||
ResultSet containerResults = preparedContainerStatement.executeQuery();
|
||||
while (containerResults.next()) {
|
||||
int containerID = containerResults.getInt("id");
|
||||
preparedContainerUpdateStatement.setInt(1, newID);
|
||||
preparedContainerUpdateStatement.setInt(2, containerID);
|
||||
preparedContainerUpdateStatement.addBatch();
|
||||
if (containerCount % 1000 == 0) {
|
||||
preparedContainerUpdateStatement.executeBatch();
|
||||
}
|
||||
containerCount++;
|
||||
}
|
||||
preparedContainerUpdateStatement.executeBatch();
|
||||
containerResults.close();
|
||||
|
||||
preparedMaterialDeleteStatement.setInt(1, rowid);
|
||||
preparedMaterialDeleteStatement.executeUpdate();
|
||||
hasLegacy = true;
|
||||
}
|
||||
resultSet.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Database.commitTransaction(statement);
|
||||
|
||||
preparedBlockStatement.close();
|
||||
preparedBlockUpdateStatement.close();
|
||||
preparedContainerStatement.close();
|
||||
preparedContainerUpdateStatement.close();
|
||||
preparedMaterialDeleteStatement.close();
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (createIndexes) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "art_map ADD INDEX(id)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "entity_map ADD INDEX(id)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "material_map ADD INDEX(id)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "world ADD INDEX(id)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "blockdata_map ADD INDEX(id)");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS art_map_id_index ON " + ConfigHandler.prefix + "art_map(id);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS blockdata_map_id_index ON " + ConfigHandler.prefix + "blockdata_map(id);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS entity_map_id_index ON " + ConfigHandler.prefix + "entity_map(id);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS material_map_id_index ON " + ConfigHandler.prefix + "material_map(id);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS world_id_index ON " + ConfigHandler.prefix + "world(id);");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static Material getWoolColor(int data) {
|
||||
switch (data) {
|
||||
case 0:
|
||||
return Material.WHITE_WOOL;
|
||||
case 1:
|
||||
return Material.ORANGE_WOOL;
|
||||
case 2:
|
||||
return Material.MAGENTA_WOOL;
|
||||
case 3:
|
||||
return Material.LIGHT_BLUE_WOOL;
|
||||
case 4:
|
||||
return Material.YELLOW_WOOL;
|
||||
case 5:
|
||||
return Material.LIME_WOOL;
|
||||
case 6:
|
||||
return Material.PINK_WOOL;
|
||||
case 7:
|
||||
return Material.GRAY_WOOL;
|
||||
case 8:
|
||||
return Material.LIGHT_GRAY_WOOL;
|
||||
case 9:
|
||||
return Material.CYAN_WOOL;
|
||||
case 10:
|
||||
return Material.PURPLE_WOOL;
|
||||
case 11:
|
||||
return Material.BLUE_WOOL;
|
||||
case 12:
|
||||
return Material.BROWN_WOOL;
|
||||
case 13:
|
||||
return Material.GREEN_WOOL;
|
||||
case 14:
|
||||
return Material.RED_WOOL;
|
||||
case 15:
|
||||
return Material.BLACK_WOOL;
|
||||
default:
|
||||
return Material.WHITE_WOOL;
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockFace getLegacyDirection(int data) {
|
||||
switch (data) {
|
||||
case 2:
|
||||
return BlockFace.NORTH;
|
||||
case 3:
|
||||
return BlockFace.SOUTH;
|
||||
case 4:
|
||||
return BlockFace.WEST;
|
||||
case 5:
|
||||
return BlockFace.EAST;
|
||||
default:
|
||||
return BlockFace.NORTH;
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockFace getLegacyRotation(int data) {
|
||||
switch (data) {
|
||||
case 1:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 3:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 4:
|
||||
return BlockFace.WEST;
|
||||
case 5:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 6:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 7:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
case 8:
|
||||
return BlockFace.NORTH;
|
||||
case 9:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 10:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 11:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 12:
|
||||
return BlockFace.EAST;
|
||||
case 13:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 14:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 15:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
default:
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/net/coreprotect/patch/script/__2_18_1.java
Normal file
24
src/main/java/net/coreprotect/patch/script/__2_18_1.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.patch.Patch;
|
||||
|
||||
public class __2_18_1 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
__2_18_0.createIndexes = false;
|
||||
Integer[] last_version = Patch.getDatabaseVersion(statement.getConnection(), true);
|
||||
if (last_version[0] == 2 && last_version[1] == 18 && last_version[2] == 0) {
|
||||
return __2_18_0.patch(statement);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
178
src/main/java/net/coreprotect/patch/script/__2_19_0.java
Normal file
178
src/main/java/net/coreprotect/patch/script/__2_19_0.java
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.patch.Patch;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class __2_19_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN action int(1)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign DROP INDEX wid");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD INDEX(wid,x,z,time), ADD INDEX(user,time), ADD INDEX(time)");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat ADD COLUMN wid int(4), ADD COLUMN x int(8), ADD COLUMN y int(3), ADD COLUMN z int(8), ADD INDEX(wid,x,z,time)");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "chat", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command ADD COLUMN wid int(4), ADD COLUMN x int(8), ADD COLUMN y int(3), ADD COLUMN z int(8), ADD INDEX(wid,x,z,time)");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "command", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Update co_sign table */
|
||||
try {
|
||||
statement.executeUpdate("DROP INDEX IF EXISTS sign_index;");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.SECOND, Selector.THIRD));
|
||||
}
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN action INTEGER;");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
try {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS sign_index ON " + ConfigHandler.prefix + "sign(wid,x,z,time);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS sign_user_index ON " + ConfigHandler.prefix + "sign(user,time);");
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS sign_time_index ON " + ConfigHandler.prefix + "sign(time);");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.SECOND, Selector.SECOND));
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Update co_chat table */
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat ADD COLUMN wid INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat ADD COLUMN x INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat ADD COLUMN y INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat ADD COLUMN z INTEGER;");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "chat", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
try {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS chat_wid_index ON " + ConfigHandler.prefix + "chat(wid,x,z,time);");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "chat", Selector.SECOND, Selector.SECOND));
|
||||
}
|
||||
|
||||
/* Update co_command table */
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command ADD COLUMN wid INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command ADD COLUMN x INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command ADD COLUMN y INTEGER;");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command ADD COLUMN z INTEGER;");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "command", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
try {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS command_wid_index ON " + ConfigHandler.prefix + "command(wid,x,z,time);");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "command", Selector.SECOND, Selector.SECOND));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> signList = new ArrayList<>();
|
||||
for (Material material : Tag.SIGNS.getValues()) {
|
||||
int id = Util.getBlockId(material.name(), false);
|
||||
if (id > -1) {
|
||||
signList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (signList.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder signData = new StringBuilder();
|
||||
for (Integer id : signList) {
|
||||
if (signData.length() == 0) {
|
||||
signData = signData.append(id);
|
||||
}
|
||||
else {
|
||||
signData.append(",").append(id);
|
||||
}
|
||||
}
|
||||
|
||||
String blockQuery = "SELECT time, user, wid, x, y, z FROM " + ConfigHandler.prefix + "block WHERE type IN(" + signData.toString() + ") AND action='1' ORDER BY rowid ASC";
|
||||
String preparedSignQuery = "SELECT rowid as id FROM " + ConfigHandler.prefix + "sign WHERE user = ? AND wid = ? AND x = ? AND y = ? AND z = ? AND time >= ? ORDER BY rowid ASC LIMIT 0, 1";
|
||||
String preparedQueryUpdate = "UPDATE " + ConfigHandler.prefix + "sign SET action = 1 WHERE rowid = ?";
|
||||
PreparedStatement preparedSignStatement = statement.getConnection().prepareStatement(preparedSignQuery);
|
||||
PreparedStatement preparedStatementUpdate = statement.getConnection().prepareStatement(preparedQueryUpdate);
|
||||
Database.beginTransaction(statement);
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(blockQuery);
|
||||
while (resultSet.next()) {
|
||||
preparedSignStatement.setInt(1, resultSet.getInt("user"));
|
||||
preparedSignStatement.setInt(2, resultSet.getInt("wid"));
|
||||
preparedSignStatement.setInt(3, resultSet.getInt("x"));
|
||||
preparedSignStatement.setInt(4, resultSet.getInt("y"));
|
||||
preparedSignStatement.setInt(5, resultSet.getInt("z"));
|
||||
preparedSignStatement.setInt(6, resultSet.getInt("time"));
|
||||
|
||||
ResultSet signResults = preparedSignStatement.executeQuery();
|
||||
while (signResults.next()) {
|
||||
int id = signResults.getInt("id");
|
||||
preparedStatementUpdate.setInt(1, id);
|
||||
preparedStatementUpdate.executeUpdate();
|
||||
}
|
||||
signResults.close();
|
||||
}
|
||||
resultSet.close();
|
||||
preparedSignStatement.close();
|
||||
preparedStatementUpdate.close();
|
||||
|
||||
Database.commitTransaction(statement);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
109
src/main/java/net/coreprotect/patch/script/__2_20_0.java
Normal file
109
src/main/java/net/coreprotect/patch/script/__2_20_0.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.patch.Patch;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class __2_20_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command MODIFY message VARCHAR(16000), CONVERT TO CHARACTER SET utf8mb4");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "command", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat MODIFY message VARCHAR(16000), CONVERT TO CHARACTER SET utf8mb4");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "chat", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN data tinyint(1)");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN data INTEGER;");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "sign", Selector.FIRST, Selector.FIRST));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String entityQuery = "SELECT rowid, data FROM " + ConfigHandler.prefix + "block WHERE type = (SELECT id FROM " + ConfigHandler.prefix + "material_map WHERE material='minecraft:spawner' LIMIT 1) ORDER BY rowid ASC";
|
||||
String preparedQueryUpdate = "UPDATE " + ConfigHandler.prefix + "block SET data = ? WHERE rowid = ?";
|
||||
PreparedStatement preparedStatementUpdate = statement.getConnection().prepareStatement(preparedQueryUpdate);
|
||||
Database.beginTransaction(statement);
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(entityQuery);
|
||||
while (resultSet.next()) {
|
||||
EntityType entityType = EntityType.PIG;
|
||||
switch (resultSet.getInt("data")) {
|
||||
case 1:
|
||||
entityType = EntityType.ZOMBIE;
|
||||
break;
|
||||
case 2:
|
||||
entityType = EntityType.SKELETON;
|
||||
break;
|
||||
case 3:
|
||||
entityType = EntityType.SPIDER;
|
||||
break;
|
||||
case 4:
|
||||
entityType = EntityType.CAVE_SPIDER;
|
||||
break;
|
||||
case 5:
|
||||
entityType = EntityType.SILVERFISH;
|
||||
break;
|
||||
case 6:
|
||||
entityType = EntityType.BLAZE;
|
||||
break;
|
||||
default:
|
||||
entityType = EntityType.PIG;
|
||||
break;
|
||||
}
|
||||
|
||||
preparedStatementUpdate.setInt(1, Util.getSpawnerType(entityType));
|
||||
preparedStatementUpdate.setInt(2, resultSet.getInt("rowid"));
|
||||
preparedStatementUpdate.executeUpdate();
|
||||
}
|
||||
resultSet.close();
|
||||
preparedStatementUpdate.close();
|
||||
|
||||
Database.commitTransaction(statement);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
39
src/main/java/net/coreprotect/patch/script/__2_5_0.java
Executable file
39
src/main/java/net/coreprotect/patch/script/__2_5_0.java
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.patch.Patch;
|
||||
|
||||
public class __2_5_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_1 VARCHAR(100)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_2 VARCHAR(100)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_3 VARCHAR(100)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_4 VARCHAR(100)");
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user MODIFY user VARCHAR(32)");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!Patch.continuePatch()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block ADD COLUMN meta BLOB");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
40
src/main/java/net/coreprotect/patch/script/__2_6_0.java
Executable file
40
src/main/java/net/coreprotect/patch/script/__2_6_0.java
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
package net.coreprotect.patch.script;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class __2_6_0 {
|
||||
|
||||
protected static boolean patch(Statement statement) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("START TRANSACTION");
|
||||
statement.executeUpdate("CREATE TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp(rowid int(8), time int(10), version varchar(16)) ENGINE=InnoDB");
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version_tmp SELECT rowid,time,version FROM " + ConfigHandler.prefix + "version;");
|
||||
statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version;");
|
||||
statement.executeUpdate("CREATE TABLE " + ConfigHandler.prefix + "version(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10),version varchar(16)) ENGINE=InnoDB");
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version SELECT rowid,time,version FROM " + ConfigHandler.prefix + "version_tmp;");
|
||||
statement.executeUpdate("DROP TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp;");
|
||||
statement.executeUpdate("COMMIT");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("BEGIN TRANSACTION");
|
||||
statement.executeUpdate("CREATE TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp (time INTEGER, version TEXT);");
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version_tmp SELECT time,version FROM " + ConfigHandler.prefix + "version;");
|
||||
statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version;");
|
||||
statement.executeUpdate("CREATE TABLE " + ConfigHandler.prefix + "version (time INTEGER, version TEXT);");
|
||||
statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version SELECT time,version FROM " + ConfigHandler.prefix + "version_tmp;");
|
||||
statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version_tmp;");
|
||||
statement.executeUpdate("COMMIT TRANSACTION");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue