Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.nuclyon.technicallycoded.inventoryrollback</groupId>
<artifactId>InventoryRollbackPlus</artifactId>
<version>1.7.6</version>
<version>1.7.7-custom</version>
<packaging>jar</packaging>
<name>InventoryRollbackPlus</name>
<url>https://github.com/TechnicallyCoded/Inventory-Rollback-Plus/</url>
Expand Down Expand Up @@ -64,13 +64,13 @@
<systemPath>${project.basedir}/lib/spigot-1.19.3.jar</systemPath>
<optional>true</optional>
</dependency>-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.5-R0.1-SNAPSHOT</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.spigotmc</groupId>-->
<!-- <artifactId>spigot</artifactId>-->
<!-- <version>1.20.5-R0.1-SNAPSHOT</version>-->
<!-- <optional>true</optional>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- bStats API -->
<dependency>
<groupId>org.bstats</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public void onEnable() {
// Run after all plugin enable
getServer().getScheduler().runTask(this, EventLogs::patchLowestHandlers);

//register bungeecord messaging channel
getServer().getMessenger().registerOutgoingPluginChannel(InventoryRollback.getInstance(), "BungeeCord");

// PaperLib
if (!PaperLib.isPaper()) {
this.getLogger().info("----------------------------------------");
Expand Down Expand Up @@ -123,6 +126,9 @@ public void onDisable() {
// Unregister event listeners
HandlerList.unregisterAll(this);

//register bungeecord messaging channel
getServer().getMessenger().unregisterOutgoingPluginChannel(InventoryRollback.getInstance(), "BungeeCord");

// Cancel tasks
this.getServer().getScheduler().cancelTasks(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public String getName() {
private static boolean mysqlVerifyCertificate;
private static boolean mysqlPubKeyRetrieval;

private static String serverName;
private static boolean allowOtherPluginEditDeathInventory;
private static boolean restoreToPlayerButton;
private static int backupLinesVisible;
Expand Down Expand Up @@ -130,7 +131,9 @@ public void setVariables() {
setMySQLPassword((String) getDefaultValue("mysql.details.password", "password"));
setMySQLUseSSL((boolean) getDefaultValue("mysql.details.use-SSL", true));
setMySQLVerifyCertificate((boolean) getDefaultValue("mysql.details.verifyCertificate", true));
setMysqlPubKeyRetrievalAllowed((boolean) getDefaultValue("mysql.details.allowPubKeyRetrieval", false));
setMySQLPubKeyRetrievalAllowed((boolean) getDefaultValue("mysql.details.allowPubKeyRetrieval", false));

setServerName((String) getDefaultValue("servername", "default"));

setAllowOtherPluginEditDeathInventory((boolean) getDefaultValue("allow-other-plugins-edit-death-inventory", false));
setRestoreToPlayerButton((boolean) getDefaultValue("restore-to-player-button", true));
Expand Down Expand Up @@ -201,10 +204,12 @@ public static void setMySQLVerifyCertificate(boolean value) {
mysqlVerifyCertificate = value;
}

public static void setMysqlPubKeyRetrievalAllowed(boolean value) {
public static void setMySQLPubKeyRetrievalAllowed(boolean value) {
mysqlPubKeyRetrieval = value;
}

public static void setServerName(String value) { serverName = value; }

public static void setRestoreToPlayerButton(boolean value) {
restoreToPlayerButton = value;
}
Expand Down Expand Up @@ -333,6 +338,8 @@ public static boolean isMySQLPubKeyRetrievalAllowed() {
return mysqlPubKeyRetrieval;
}

public static String getServerName() { return serverName; }

public static boolean isRestoreToPlayerButton() {
return restoreToPlayerButton;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public boolean saveConfig() {
private static String experienceButtonLore;

// Death logs messages
private static String deathLocationServer;
private static String deathLocationWorld;
private static String deathLocationX;
private static String deathLocationY;
Expand Down Expand Up @@ -178,6 +179,7 @@ public void setMessages() {
setExperienceButtonLore(convertColorCodes((String) getDefaultValue("attribute-restore.experience.button-lore", "&rLevel %XP%")));

// Death only gui
setDeathLocationServer(convertColorCodes((String) getDefaultValue("death-location.server", "&6Server: &f%SERVER%")));
setDeathLocationWorld(convertColorCodes((String) getDefaultValue("death-location.world", "&6World: &f%WORLD%")));
setDeathLocationX(convertColorCodes((String) getDefaultValue("death-location.x", "&6X: &f%X%")));
setDeathLocationY(convertColorCodes((String) getDefaultValue("death-location.y", "&6Y: &f%Y%")));
Expand Down Expand Up @@ -345,6 +347,9 @@ public static void setExperienceButtonLore(String message) {
experienceButtonLore = message;
}

public static void setDeathLocationServer(String message) {
deathLocationServer = message;
}
public static void setDeathLocationWorld(String message) {
deathLocationWorld = message;
}
Expand Down Expand Up @@ -549,6 +554,9 @@ public static String getExperienceRestoreLevel(int xp) {
return experienceButtonLore.replaceAll(xpVariable, xp + "");
}

public static String getDeathLocationServer(String server) {
return deathLocationServer.replace("%SERVER%", server);
}
public static String getDeathLocationWorld(String world) {
return deathLocationWorld.replace("%WORLD%", world);
}
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/me/danjono/inventoryrollback/data/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getTableName() {
private double health;
private int hunger;
private float saturation;
private String server;
private String world;
private double x;
private double y;
Expand Down Expand Up @@ -110,7 +111,8 @@ public void createTables() throws SQLException {
"`xp` FLOAT NOT NULL," +
"`health` DOUBLE NOT NULL," +
"`hunger` INT NOT NULL," +
"`saturation` FLOAT NOT NULL," +
"`saturation` FLOAT NOT NULL," +
"`location_server` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci," +
"`location_world` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL," +
"`location_x` DOUBLE NOT NULL," +
"`location_y` DOUBLE NOT NULL," +
Expand Down Expand Up @@ -260,6 +262,8 @@ public void setSaturation(float saturation) {
this.saturation = saturation;
}

public void setServer(String server) { this.server = server; }

public void setWorld(String world) {
this.world = world;
}
Expand Down Expand Up @@ -288,7 +292,7 @@ public void getRollbackMenuData() throws SQLException {
openConnection();

try {
String query = "SELECT timestamp,death_reason,location_world,location_x,location_y,location_z " +
String query = "SELECT timestamp,death_reason,location_server,location_world,location_x,location_y,location_z " +
"FROM " + backupTable.getTableName() + " WHERE " +
"uuid = ? AND timestamp = ?";

Expand All @@ -298,7 +302,8 @@ public void getRollbackMenuData() throws SQLException {

try (ResultSet results = statement.executeQuery()) {
results.next();


server = results.getString("location_server");
world = results.getString("location_world");
x = results.getDouble("location_x");
y = results.getDouble("location_y");
Expand Down Expand Up @@ -333,6 +338,7 @@ public void getAllBackupData() throws SQLException {
health = results.getDouble("health");
hunger = results.getInt("hunger");
saturation = results.getFloat("saturation");
server = results.getString("location_server");
world = results.getString("location_world");
x = results.getDouble("location_x");
y = results.getDouble("location_y");
Expand Down Expand Up @@ -375,6 +381,8 @@ public float getSaturation() {
return this.saturation;
}

public String getServer() { return this.server; }

public String getWorld() {
return this.world;
}
Expand Down Expand Up @@ -404,8 +412,8 @@ public void saveData() throws SQLException {

try {
String update = "INSERT INTO " + backupTable.getTableName() + " " +
"(uuid, timestamp, xp, health, hunger, saturation, location_world, location_x, location_y, location_z, version, death_reason, main_inventory, armour, ender_chest)" + " " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
"(uuid, timestamp, xp, health, hunger, saturation, location_server, location_world, location_x, location_y, location_z, version, death_reason, main_inventory, armour, ender_chest)" + " " +
Copy link
Owner

@TechnicallyCoded TechnicallyCoded Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User-optional DB migration for previous installs (as mentioned in original PR comment)

"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

try (PreparedStatement statement = connection.prepareStatement(update)) {
statement.setString(1, uuid + "");
Expand All @@ -414,15 +422,16 @@ public void saveData() throws SQLException {
statement.setDouble(4, health);
statement.setInt(5, hunger);
statement.setFloat(6, saturation);
statement.setString(7, world);
statement.setDouble(8, x);
statement.setDouble(9, y);
statement.setDouble(10, z);
statement.setString(11, packageVersion);
statement.setString(12, deathReason);
statement.setString(13, mainInventory);
statement.setString(14, armour);
statement.setString(15, enderChest);
statement.setString(7, server);
statement.setString(8, world);
statement.setDouble(9, x);
statement.setDouble(10, y);
statement.setDouble(11, z);
statement.setString(12, packageVersion);
statement.setString(13, deathReason);
statement.setString(14, mainInventory);
statement.setString(15, armour);
statement.setString(16, enderChest);
statement.executeUpdate();
}
} finally {
Expand Down Expand Up @@ -482,6 +491,7 @@ public static void convertYAMLToMySQL() {
mysql.setHealth(yaml.getHealth());
mysql.setFoodLevel(yaml.getFoodLevel());
mysql.setSaturation(yaml.getSaturation());
mysql.setServer(yaml.getServer());
mysql.setWorld(yaml.getWorld());
mysql.setX(yaml.getX());
mysql.setY(yaml.getY());
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/me/danjono/inventoryrollback/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ public void setSaturation(float saturation) {
}
}

public void setServer(String server) {
if (ConfigData.getSaveType() == SaveType.YAML) {
yaml.setServer(server);
} else if (ConfigData.getSaveType() == SaveType.MYSQL) {
mysql.setServer(server);
}
}

public void setWorld(String world) {
if (ConfigData.getSaveType() == SaveType.YAML) {
yaml.setWorld(world);
Expand Down Expand Up @@ -353,6 +361,15 @@ public float getSaturation() {

return 0;
}
public String getServer() {
if (ConfigData.getSaveType() == SaveType.YAML) {
return yaml.getServer();
} else if (ConfigData.getSaveType() == SaveType.MYSQL) {
return mysql.getServer();
}

return null;
}

public String getWorld() {
if (ConfigData.getSaveType() == SaveType.YAML) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/danjono/inventoryrollback/data/YAML.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class YAML {
private double health;
private int hunger;
private float saturation;
private String server;
private String world;
private double x;
private double y;
Expand Down Expand Up @@ -244,6 +245,7 @@ public void setSaturation(float saturation) {
this.saturation = saturation;
}

public void setServer(String server) { this.server = server; }
public void setWorld(String world) {
this.world = world;
}
Expand Down Expand Up @@ -303,6 +305,7 @@ public float getSaturation() {
return Float.parseFloat(data.getString("saturation"));
}

public String getServer() { return data.getString("location.server"); }
public String getWorld() {
return data.getString("location.world");
}
Expand Down Expand Up @@ -347,6 +350,7 @@ public void saveData() {
data.set("health", health);
data.set("hunger", hunger);
data.set("saturation", saturation);
data.set("location.server", server);
data.set("location.world", world);
data.set("location.x", x);
data.set("location.y", y);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/me/danjono/inventoryrollback/gui/Buttons.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,11 @@ public ItemStack enderPearlButton(LogType logType, String location) {
List<String> lore = new ArrayList<>();
if (location != null) {
String[] loc = location.split(",");
lore.add(ChatColor.GOLD + "World: " + ChatColor.WHITE + loc[0]);
lore.add(ChatColor.GOLD + "X: " + ChatColor.WHITE + loc[1]);
lore.add(ChatColor.GOLD + "Y: " + ChatColor.WHITE + loc[2]);
lore.add(ChatColor.GOLD + "Z: " + ChatColor.WHITE + loc[3]);
lore.add(ChatColor.GOLD + "Server: "+ ChatColor.WHITE + loc[0]);
lore.add(ChatColor.GOLD + "World: " + ChatColor.WHITE + loc[1]);
lore.add(ChatColor.GOLD + "X: " + ChatColor.WHITE + loc[2]);
lore.add(ChatColor.GOLD + "Y: " + ChatColor.WHITE + loc[3]);
lore.add(ChatColor.GOLD + "Z: " + ChatColor.WHITE + loc[4]);

meta.setLore(lore);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public void showBackupItems() {

int invPosition = 0;
int itemPos = 0;
final int max = mainInvLen - 5; // excluded

// Calculate max based on whether armor is stored separately or not
// Old versions (<=1.8): armor stored separately in 'armour' array, process all main inventory
// New versions (>=1.9): armor in mainInventory from slot 36+, only process slots 0-35
final int max = (armour != null && armour.length > 0) ? mainInvLen : Math.min(36, mainInvLen);

@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.UUID;

import com.nuclyon.technicallycoded.inventoryrollback.InventoryRollbackPlus;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -99,12 +100,16 @@ public void showBackups() {
if (deathReason != null)
lore.add(MessageData.getDeathReason(deathReason));

String server = playerData.getServer();
String world = playerData.getWorld();
double x = playerData.getX();
double y = playerData.getY();
double z = playerData.getZ();
String location = world + "," + x + "," + y + "," + z;
String location = server + "," + world + "," + x + "," + y + "," + z;

InventoryRollbackPlus.getInstance().getLogger().info(location);

lore.add(MessageData.getDeathLocationServer(server));
lore.add(MessageData.getDeathLocationWorld(world));
lore.add(MessageData.getDeathLocationX(x));
lore.add(MessageData.getDeathLocationY(y));
Expand Down
Loading