Per-world Creeper settings complete
- Added per-world Block Damage settings - Added per-world Entity Damage settings - Added creeper_settings database support - Added world-specific Creeper menus - Added automatic world registration/default inheritance - Split Creeper listeners - Updated Creeper behavior to use world settings - Removed obsolete global Creeper indicators - Adopted logger-based error reporting standard
This commit is contained in:
1 parent
ebf030b192
commit
73a0ef8ae6
23 files changed
+1203
-73
No files matched your search
@@ -1,19 +1,16 @@
|
|||||||
package com.rsscripting.serveradmin;
|
package com.rsscripting.serveradmin;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.dao.*;
|
||||||
import com.rsscripting.serveradmin.database.DatabaseManager;
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
import com.rsscripting.serveradmin.database.SettingsDAO;
|
|
||||||
import com.rsscripting.serveradmin.commands.RSAdminCommand;
|
import com.rsscripting.serveradmin.commands.RSAdminCommand;
|
||||||
import com.rsscripting.serveradmin.keepinventory.KeepInventoryDAO;
|
|
||||||
import com.rsscripting.serveradmin.listeners.CreeperBlockDamageListener;
|
import com.rsscripting.serveradmin.listeners.CreeperBlockDamageListener;
|
||||||
import com.rsscripting.serveradmin.security.SecurityManager;
|
import com.rsscripting.serveradmin.security.SecurityManager;
|
||||||
import com.rsscripting.serveradmin.listeners.InventoryListener;
|
import com.rsscripting.serveradmin.listeners.InventoryListener;
|
||||||
import com.rsscripting.serveradmin.listeners.CreeperEntityDamageListener;
|
import com.rsscripting.serveradmin.listeners.CreeperEntityDamageListener;
|
||||||
import com.rsscripting.serveradmin.update.GitHubUpdateChecker;
|
import com.rsscripting.serveradmin.update.GitHubUpdateChecker;
|
||||||
import com.rsscripting.serveradmin.listeners.WorldLoadListener;
|
import com.rsscripting.serveradmin.listeners.WorldLoadListener;
|
||||||
import com.rsscripting.serveradmin.creeper.CreeperSettingsDAO;
|
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
import com.rsscripting.serveradmin.worlds.WorldsDAO;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@@ -29,6 +26,7 @@ public class RSServerAdmin extends JavaPlugin {
|
|||||||
private SecurityManager securityManager;
|
private SecurityManager securityManager;
|
||||||
private WorldsDAO worldsDAO;
|
private WorldsDAO worldsDAO;
|
||||||
private CreeperSettingsDAO creeperSettingsDAO;
|
private CreeperSettingsDAO creeperSettingsDAO;
|
||||||
|
private EquipmentDropSettingsDAO equipmentDropSettingsDAO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -62,6 +60,11 @@ public class RSServerAdmin extends JavaPlugin {
|
|||||||
databaseManager
|
databaseManager
|
||||||
);
|
);
|
||||||
|
|
||||||
|
equipmentDropSettingsDAO =
|
||||||
|
new EquipmentDropSettingsDAO(
|
||||||
|
databaseManager
|
||||||
|
);
|
||||||
|
|
||||||
securityManager = new SecurityManager(this);
|
securityManager = new SecurityManager(this);
|
||||||
|
|
||||||
boolean keepInventoryDefault =
|
boolean keepInventoryDefault =
|
||||||
@@ -96,6 +99,10 @@ public class RSServerAdmin extends JavaPlugin {
|
|||||||
entityDamageDefault
|
entityDamageDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
|
equipmentDropSettingsDAO.ensureWorldExists(
|
||||||
|
world.getName()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCommand("rsadmin") != null) {
|
if (getCommand("rsadmin") != null) {
|
||||||
@@ -188,4 +195,11 @@ public class RSServerAdmin extends JavaPlugin {
|
|||||||
return creeperSettingsDAO;
|
return creeperSettingsDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EquipmentDropSettingsDAO
|
||||||
|
getEquipmentDropSettingsDAO() {
|
||||||
|
|
||||||
|
return equipmentDropSettingsDAO;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,8 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public class RSAdminCommand implements CommandExecutor {
|
public class RSAdminCommand implements CommandExecutor {
|
||||||
|
|
||||||
@@ -17,10 +19,10 @@ public class RSAdminCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(
|
public boolean onCommand(
|
||||||
CommandSender sender,
|
@NotNull CommandSender sender,
|
||||||
Command command,
|
@NotNull Command command,
|
||||||
String label,
|
@NotNull String label,
|
||||||
String[] args
|
@NotNull String @NonNull [] args
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.creeper;
|
package com.rsscripting.serveradmin.dao;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.database.DatabaseManager;
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
|
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
package com.rsscripting.serveradmin.dao;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class EquipmentDropSettingsDAO {
|
||||||
|
|
||||||
|
private final DatabaseManager databaseManager;
|
||||||
|
|
||||||
|
public EquipmentDropSettingsDAO(
|
||||||
|
DatabaseManager databaseManager
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.databaseManager =
|
||||||
|
databaseManager;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ensureWorldExists(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
Connection connection =
|
||||||
|
databaseManager.getConnection();
|
||||||
|
|
||||||
|
try (PreparedStatement statement =
|
||||||
|
connection.prepareStatement(
|
||||||
|
"""
|
||||||
|
INSERT OR IGNORE INTO equipment_drop_settings (
|
||||||
|
world_name,
|
||||||
|
helmet,
|
||||||
|
chestplate,
|
||||||
|
leggings,
|
||||||
|
boots,
|
||||||
|
main_hand,
|
||||||
|
off_hand
|
||||||
|
)
|
||||||
|
VALUES (?, 1, 1, 1, 1, 1, 1)
|
||||||
|
"""
|
||||||
|
)) {
|
||||||
|
|
||||||
|
statement.setString(
|
||||||
|
1,
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getHelmet(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"helmet"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHelmet(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"helmet",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getChestplate(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"chestplate"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChestplate(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"chestplate",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getLeggings(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"leggings"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeggings(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"leggings",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoots(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"boots"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoots(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"boots",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getMainHand(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"main_hand"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMainHand(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"main_hand",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getOffHand(
|
||||||
|
String worldName
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
return getValue(
|
||||||
|
worldName,
|
||||||
|
"off_hand"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffHand(
|
||||||
|
String worldName,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
setValue(
|
||||||
|
worldName,
|
||||||
|
"off_hand",
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getValue(
|
||||||
|
String worldName,
|
||||||
|
String column
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
Connection connection =
|
||||||
|
databaseManager.getConnection();
|
||||||
|
|
||||||
|
try (PreparedStatement statement =
|
||||||
|
connection.prepareStatement(
|
||||||
|
"SELECT " + column +
|
||||||
|
" FROM equipment_drop_settings " +
|
||||||
|
"WHERE world_name = ?"
|
||||||
|
)) {
|
||||||
|
|
||||||
|
statement.setString(
|
||||||
|
1,
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
try (ResultSet result =
|
||||||
|
statement.executeQuery()) {
|
||||||
|
|
||||||
|
if (result.next()) {
|
||||||
|
|
||||||
|
return result.getBoolean(
|
||||||
|
column
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setValue(
|
||||||
|
String worldName,
|
||||||
|
String column,
|
||||||
|
boolean enabled
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
Connection connection =
|
||||||
|
databaseManager.getConnection();
|
||||||
|
|
||||||
|
try (PreparedStatement statement =
|
||||||
|
connection.prepareStatement(
|
||||||
|
"UPDATE equipment_drop_settings " +
|
||||||
|
"SET " + column +
|
||||||
|
" = ? WHERE world_name = ?"
|
||||||
|
)) {
|
||||||
|
|
||||||
|
statement.setBoolean(
|
||||||
|
1,
|
||||||
|
enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
statement.setString(
|
||||||
|
2,
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-38
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.keepinventory;
|
package com.rsscripting.serveradmin.dao;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.database.DatabaseManager;
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
|
|
||||||
@@ -139,41 +139,4 @@ public class KeepInventoryDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.util.List<String> getAllWorlds()
|
|
||||||
throws SQLException {
|
|
||||||
|
|
||||||
java.util.List<String> worlds =
|
|
||||||
new java.util.ArrayList<>();
|
|
||||||
|
|
||||||
Connection connection =
|
|
||||||
databaseManager.getConnection();
|
|
||||||
|
|
||||||
try (PreparedStatement statement =
|
|
||||||
connection.prepareStatement(
|
|
||||||
"""
|
|
||||||
SELECT world_name
|
|
||||||
FROM keep_inventory
|
|
||||||
ORDER BY world_name
|
|
||||||
"""
|
|
||||||
);
|
|
||||||
|
|
||||||
ResultSet rs =
|
|
||||||
statement.executeQuery()) {
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
|
|
||||||
worlds.add(
|
|
||||||
rs.getString(
|
|
||||||
"world_name"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return worlds;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
-3
@@ -1,5 +1,6 @@
|
|||||||
package com.rsscripting.serveradmin.database;
|
package com.rsscripting.serveradmin.dao;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -50,9 +51,9 @@ public class SettingsDAO {
|
|||||||
case KEEP_INVENTORY -> true;
|
case KEEP_INVENTORY -> true;
|
||||||
|
|
||||||
case CREEPER_BLOCK_DAMAGE,
|
case CREEPER_BLOCK_DAMAGE,
|
||||||
CREEPER_ENTITY_DAMAGE -> false;
|
CREEPER_ENTITY_DAMAGE,
|
||||||
|
KEEP_INVENTORY_NEW_WORLD -> false;
|
||||||
|
|
||||||
case KEEP_INVENTORY_NEW_WORLD -> false;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.worlds;
|
package com.rsscripting.serveradmin.dao;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.database.DatabaseManager;
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
||||||
|
|
||||||
@@ -22,7 +22,15 @@ public class DatabaseManager {
|
|||||||
File dataFolder = plugin.getDataFolder();
|
File dataFolder = plugin.getDataFolder();
|
||||||
|
|
||||||
if (!dataFolder.exists()) {
|
if (!dataFolder.exists()) {
|
||||||
dataFolder.mkdirs();
|
|
||||||
|
if (!dataFolder.mkdirs()) {
|
||||||
|
|
||||||
|
throw new SQLException(
|
||||||
|
"Failed to create plugin data folder."
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File databaseFile = new File(
|
File databaseFile = new File(
|
||||||
@@ -86,6 +94,20 @@ public class DatabaseManager {
|
|||||||
"""
|
"""
|
||||||
);
|
);
|
||||||
|
|
||||||
|
statement.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS equipment_drop_settings (
|
||||||
|
world_name TEXT PRIMARY KEY,
|
||||||
|
helmet INTEGER NOT NULL,
|
||||||
|
chestplate INTEGER NOT NULL,
|
||||||
|
leggings INTEGER NOT NULL,
|
||||||
|
boots INTEGER NOT NULL,
|
||||||
|
main_hand INTEGER NOT NULL,
|
||||||
|
off_hand INTEGER NOT NULL
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
import com.rsscripting.serveradmin.creeper.CreeperSettingsDAO;
|
import com.rsscripting.serveradmin.dao.CreeperSettingsDAO;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
import com.rsscripting.serveradmin.utils.MenuLayoutUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
import com.rsscripting.serveradmin.creeper.CreeperSettingsDAO;
|
import com.rsscripting.serveradmin.dao.CreeperSettingsDAO;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
import com.rsscripting.serveradmin.utils.MenuLayoutUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@@ -111,13 +113,22 @@ public class CreeperMenu {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to build Creeper menu: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
ex.printStackTrace();
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to build Creeper menu: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
import com.rsscripting.serveradmin.keepinventory.KeepInventoryDAO;
|
import com.rsscripting.serveradmin.dao.KeepInventoryDAO;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
import com.rsscripting.serveradmin.utils.MenuLayoutUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.gui.GUIUtils;
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.gui.RSMenuHolder;
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
import com.rsscripting.serveradmin.gui.KeepInventoryMenu;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@@ -57,6 +55,31 @@ public class MainMenu {
|
|||||||
|
|
||||||
inventory.setItem(11, creeper);
|
inventory.setItem(11, creeper);
|
||||||
|
|
||||||
|
ItemStack mobDrops =
|
||||||
|
new ItemStack(
|
||||||
|
Material.SKELETON_SKULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta mobDropsMeta =
|
||||||
|
mobDrops.getItemMeta();
|
||||||
|
|
||||||
|
if (mobDropsMeta != null) {
|
||||||
|
|
||||||
|
mobDropsMeta.setDisplayName(
|
||||||
|
"§aMob Equipment Drops"
|
||||||
|
);
|
||||||
|
|
||||||
|
mobDrops.setItemMeta(
|
||||||
|
mobDropsMeta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
13,
|
||||||
|
mobDrops
|
||||||
|
);
|
||||||
|
|
||||||
ItemStack keepInventory =
|
ItemStack keepInventory =
|
||||||
new ItemStack(Material.CHEST);
|
new ItemStack(Material.CHEST);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class MobEquipmentMenu {
|
||||||
|
|
||||||
|
public static Inventory create() {
|
||||||
|
|
||||||
|
RSMenuHolder holder =
|
||||||
|
new RSMenuHolder(
|
||||||
|
"MOB_EQUIPMENT"
|
||||||
|
);
|
||||||
|
|
||||||
|
Inventory inventory =
|
||||||
|
Bukkit.createInventory(
|
||||||
|
holder,
|
||||||
|
27,
|
||||||
|
"Mob Equipment Drops"
|
||||||
|
);
|
||||||
|
|
||||||
|
GUIUtils.fillEmptySlots(
|
||||||
|
inventory
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Back
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack back =
|
||||||
|
new ItemStack(
|
||||||
|
Material.ARROW
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta backMeta =
|
||||||
|
back.getItemMeta();
|
||||||
|
|
||||||
|
if (backMeta != null) {
|
||||||
|
|
||||||
|
backMeta.setDisplayName(
|
||||||
|
"§cBack"
|
||||||
|
);
|
||||||
|
|
||||||
|
back.setItemMeta(
|
||||||
|
backMeta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
4,
|
||||||
|
back
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Armor Drops
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack armor =
|
||||||
|
new ItemStack(
|
||||||
|
Material.DIAMOND_CHESTPLATE
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta armorMeta =
|
||||||
|
armor.getItemMeta();
|
||||||
|
|
||||||
|
if (armorMeta != null) {
|
||||||
|
|
||||||
|
armorMeta.setDisplayName(
|
||||||
|
"§aArmor Drops"
|
||||||
|
);
|
||||||
|
|
||||||
|
armor.setItemMeta(
|
||||||
|
armorMeta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
11,
|
||||||
|
armor
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Hand Item Drops
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack hands =
|
||||||
|
new ItemStack(
|
||||||
|
Material.DIAMOND_SWORD
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta handMeta =
|
||||||
|
hands.getItemMeta();
|
||||||
|
|
||||||
|
if (handMeta != null) {
|
||||||
|
|
||||||
|
handMeta.setDisplayName(
|
||||||
|
"§aHand Item Drops"
|
||||||
|
);
|
||||||
|
|
||||||
|
hands.setItemMeta(
|
||||||
|
handMeta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
15,
|
||||||
|
hands
|
||||||
|
);
|
||||||
|
|
||||||
|
return inventory;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class MobEquipmentSettingsMenu {
|
||||||
|
|
||||||
|
public static Inventory create(
|
||||||
|
String worldName
|
||||||
|
) {
|
||||||
|
|
||||||
|
RSMenuHolder holder =
|
||||||
|
new RSMenuHolder(
|
||||||
|
"MOB_EQUIPMENT_SETTINGS"
|
||||||
|
);
|
||||||
|
|
||||||
|
holder.setWorldName(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
boolean helmetEnabled = true;
|
||||||
|
boolean chestplateEnabled = true;
|
||||||
|
boolean leggingsEnabled = true;
|
||||||
|
boolean bootsEnabled = true;
|
||||||
|
boolean mainHandEnabled = true;
|
||||||
|
boolean offHandEnabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
helmetEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getHelmet(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
chestplateEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getChestplate(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
leggingsEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getLeggings(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
bootsEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getBoots(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
mainHandEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getMainHand(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
offHandEnabled =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.getOffHand(
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to load equipment drop settings for "
|
||||||
|
+ worldName
|
||||||
|
+ ": "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Inventory inventory =
|
||||||
|
Bukkit.createInventory(
|
||||||
|
holder,
|
||||||
|
54,
|
||||||
|
"Equipment: " + worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
GUIUtils.fillEmptySlots(
|
||||||
|
inventory
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Back
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack back =
|
||||||
|
new ItemStack(
|
||||||
|
Material.ARROW
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta backMeta =
|
||||||
|
back.getItemMeta();
|
||||||
|
|
||||||
|
if (backMeta != null) {
|
||||||
|
|
||||||
|
backMeta.setDisplayName(
|
||||||
|
"§cBack"
|
||||||
|
);
|
||||||
|
|
||||||
|
back.setItemMeta(
|
||||||
|
backMeta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
4,
|
||||||
|
back
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Helmet
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack helmet =
|
||||||
|
new ItemStack(
|
||||||
|
Material.LEATHER_HELMET
|
||||||
|
);
|
||||||
|
|
||||||
|
if (helmetEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
helmet
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
13,
|
||||||
|
helmet
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Off Hand
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack offHand =
|
||||||
|
new ItemStack(
|
||||||
|
Material.SHIELD
|
||||||
|
);
|
||||||
|
|
||||||
|
if (offHandEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
offHand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
20,
|
||||||
|
offHand
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Chestplate
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack chestplate =
|
||||||
|
new ItemStack(
|
||||||
|
Material.LEATHER_CHESTPLATE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (chestplateEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
chestplate
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
21,
|
||||||
|
chestplate
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Main Hand
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack mainHand =
|
||||||
|
new ItemStack(
|
||||||
|
Material.IRON_SWORD
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mainHandEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
mainHand
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
22,
|
||||||
|
mainHand
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Leggings
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack leggings =
|
||||||
|
new ItemStack(
|
||||||
|
Material.LEATHER_LEGGINGS
|
||||||
|
);
|
||||||
|
|
||||||
|
if (leggingsEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
leggings
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
29,
|
||||||
|
leggings
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Boots
|
||||||
|
*/
|
||||||
|
|
||||||
|
ItemStack boots =
|
||||||
|
new ItemStack(
|
||||||
|
Material.LEATHER_BOOTS
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bootsEnabled) {
|
||||||
|
|
||||||
|
GUIUtils.addGlow(
|
||||||
|
boots
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
37,
|
||||||
|
boots
|
||||||
|
);
|
||||||
|
|
||||||
|
return inventory;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
package com.rsscripting.serveradmin.gui;
|
||||||
|
|
||||||
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
|
import com.rsscripting.serveradmin.utils.GUIUtils;
|
||||||
|
import com.rsscripting.serveradmin.utils.MenuLayoutUtils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MobEquipmentWorldMenu {
|
||||||
|
|
||||||
|
private static final int WORLDS_PER_PAGE = 45;
|
||||||
|
|
||||||
|
public static Inventory create(
|
||||||
|
int page
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
RSMenuHolder holder =
|
||||||
|
new RSMenuHolder(
|
||||||
|
"MOB_EQUIPMENT_WORLDS"
|
||||||
|
);
|
||||||
|
|
||||||
|
holder.setPage(
|
||||||
|
page
|
||||||
|
);
|
||||||
|
|
||||||
|
Inventory inventory =
|
||||||
|
Bukkit.createInventory(
|
||||||
|
holder,
|
||||||
|
54,
|
||||||
|
"Mob Equipment Drops"
|
||||||
|
);
|
||||||
|
|
||||||
|
GUIUtils.fillEmptySlots(
|
||||||
|
inventory
|
||||||
|
);
|
||||||
|
|
||||||
|
createBackButton(
|
||||||
|
inventory
|
||||||
|
);
|
||||||
|
|
||||||
|
populateWorlds(
|
||||||
|
inventory,
|
||||||
|
page
|
||||||
|
);
|
||||||
|
|
||||||
|
return inventory;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createBackButton(
|
||||||
|
Inventory inventory
|
||||||
|
) {
|
||||||
|
|
||||||
|
ItemStack item =
|
||||||
|
new ItemStack(
|
||||||
|
Material.ARROW
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta meta =
|
||||||
|
item.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
|
||||||
|
meta.setDisplayName(
|
||||||
|
"§cBack"
|
||||||
|
);
|
||||||
|
|
||||||
|
item.setItemMeta(
|
||||||
|
meta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
4,
|
||||||
|
item
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void populateWorlds(
|
||||||
|
Inventory inventory,
|
||||||
|
int page
|
||||||
|
) throws SQLException {
|
||||||
|
|
||||||
|
List<String> worlds =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getWorldsDAO()
|
||||||
|
.getAllWorlds();
|
||||||
|
|
||||||
|
int start =
|
||||||
|
(page - 1) * WORLDS_PER_PAGE;
|
||||||
|
|
||||||
|
int end =
|
||||||
|
Math.min(
|
||||||
|
start + WORLDS_PER_PAGE,
|
||||||
|
worlds.size()
|
||||||
|
);
|
||||||
|
|
||||||
|
int worldCount =
|
||||||
|
end - start;
|
||||||
|
|
||||||
|
for (int i = start;
|
||||||
|
i < end;
|
||||||
|
i++) {
|
||||||
|
|
||||||
|
String worldName =
|
||||||
|
worlds.get(i);
|
||||||
|
|
||||||
|
ItemStack item =
|
||||||
|
new ItemStack(
|
||||||
|
Material.SKELETON_SKULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta meta =
|
||||||
|
item.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
|
||||||
|
meta.setDisplayName(
|
||||||
|
"§e" + worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
meta.getPersistentDataContainer()
|
||||||
|
.set(
|
||||||
|
new NamespacedKey(
|
||||||
|
RSServerAdmin.getInstance(),
|
||||||
|
"world_name"
|
||||||
|
),
|
||||||
|
PersistentDataType.STRING,
|
||||||
|
worldName
|
||||||
|
);
|
||||||
|
|
||||||
|
meta.setLore(
|
||||||
|
List.of(
|
||||||
|
"§7Configure equipment drops"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
item.setItemMeta(
|
||||||
|
meta
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int relativeIndex =
|
||||||
|
i - start;
|
||||||
|
|
||||||
|
int row =
|
||||||
|
relativeIndex / 9;
|
||||||
|
|
||||||
|
int indexInRow =
|
||||||
|
relativeIndex % 9;
|
||||||
|
|
||||||
|
int itemsRemaining =
|
||||||
|
worldCount - (row * 9);
|
||||||
|
|
||||||
|
boolean lastPartialRow =
|
||||||
|
itemsRemaining < 9;
|
||||||
|
|
||||||
|
int slot;
|
||||||
|
|
||||||
|
if (lastPartialRow) {
|
||||||
|
|
||||||
|
List<Integer> rowSlots =
|
||||||
|
MenuLayoutUtils.getCenteredSlots(
|
||||||
|
itemsRemaining
|
||||||
|
);
|
||||||
|
|
||||||
|
slot =
|
||||||
|
9
|
||||||
|
+ (row * 9)
|
||||||
|
+ rowSlots.get(
|
||||||
|
indexInRow
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
slot =
|
||||||
|
9
|
||||||
|
+ (row * 9)
|
||||||
|
+ indexInRow;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.setItem(
|
||||||
|
slot,
|
||||||
|
item
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.rsscripting.serveradmin.listeners;
|
package com.rsscripting.serveradmin.listeners;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
|
||||||
import org.bukkit.entity.Creeper;
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.rsscripting.serveradmin.listeners;
|
package com.rsscripting.serveradmin.listeners;
|
||||||
|
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
|
||||||
import org.bukkit.entity.Creeper;
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package com.rsscripting.serveradmin.listeners;
|
|||||||
|
|
||||||
import com.rsscripting.serveradmin.gui.*;
|
import com.rsscripting.serveradmin.gui.*;
|
||||||
import com.rsscripting.serveradmin.RSServerAdmin;
|
import com.rsscripting.serveradmin.RSServerAdmin;
|
||||||
|
import com.rsscripting.serveradmin.menuholder.RSMenuHolder;
|
||||||
import com.rsscripting.serveradmin.settings.SettingKey;
|
import com.rsscripting.serveradmin.settings.SettingKey;
|
||||||
import com.rsscripting.serveradmin.keepinventory.KeepInventoryDAO;
|
import com.rsscripting.serveradmin.dao.KeepInventoryDAO;
|
||||||
|
import com.rsscripting.serveradmin.gui.MobEquipmentWorldMenu;
|
||||||
|
import com.rsscripting.serveradmin.gui.MobEquipmentSettingsMenu;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -60,6 +63,20 @@ public class InventoryListener implements Listener {
|
|||||||
SettingKey.KEEP_INVENTORY_NEW_WORLD
|
SettingKey.KEEP_INVENTORY_NEW_WORLD
|
||||||
);
|
);
|
||||||
|
|
||||||
|
boolean blockDamageDefault =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getSettingsDAO()
|
||||||
|
.getDefault(
|
||||||
|
SettingKey.CREEPER_BLOCK_DAMAGE
|
||||||
|
);
|
||||||
|
|
||||||
|
boolean entityDamageDefault =
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getSettingsDAO()
|
||||||
|
.getDefault(
|
||||||
|
SettingKey.CREEPER_ENTITY_DAMAGE
|
||||||
|
);
|
||||||
|
|
||||||
for (org.bukkit.World world
|
for (org.bukkit.World world
|
||||||
: org.bukkit.Bukkit.getWorlds()) {
|
: org.bukkit.Bukkit.getWorlds()) {
|
||||||
|
|
||||||
@@ -76,6 +93,20 @@ public class InventoryListener implements Listener {
|
|||||||
keepInventoryDefault
|
keepInventoryDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getCreeperSettingsDAO()
|
||||||
|
.ensureWorldExists(
|
||||||
|
world.getName(),
|
||||||
|
blockDamageDefault,
|
||||||
|
entityDamageDefault
|
||||||
|
);
|
||||||
|
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getEquipmentDropSettingsDAO()
|
||||||
|
.ensureWorldExists(
|
||||||
|
world.getName()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
@@ -84,7 +115,12 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"World scan failed: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
"§cWorld scan failed."
|
"§cWorld scan failed."
|
||||||
@@ -94,6 +130,33 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
| Mob Inventory Drop
|
||||||
|
*/
|
||||||
|
|
||||||
|
case 13 -> {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
player.openInventory(
|
||||||
|
MobEquipmentWorldMenu.create(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to open Mob Equipment menu: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
| Creeper menu
|
| Creeper menu
|
||||||
*/
|
*/
|
||||||
@@ -118,7 +181,12 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to open Keep Inventory menu: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +296,12 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to update Keep Inventory default: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +384,12 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to update Keep Inventory world setting: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,6 +671,120 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "MOB_EQUIPMENT" -> {
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getSlot()) {
|
||||||
|
|
||||||
|
case 4 -> player.openInventory(
|
||||||
|
MainMenu.create()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case "MOB_EQUIPMENT_WORLDS" -> {
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getSlot()) {
|
||||||
|
|
||||||
|
case 4 -> {
|
||||||
|
|
||||||
|
player.openInventory(
|
||||||
|
MainMenu.create()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
default -> {
|
||||||
|
|
||||||
|
if (event.getCurrentItem() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getCurrentItem().hasItemMeta()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta meta =
|
||||||
|
event.getCurrentItem()
|
||||||
|
.getItemMeta();
|
||||||
|
|
||||||
|
if (meta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String worldName =
|
||||||
|
meta.getPersistentDataContainer()
|
||||||
|
.get(
|
||||||
|
new NamespacedKey(
|
||||||
|
RSServerAdmin.getInstance(),
|
||||||
|
"world_name"
|
||||||
|
),
|
||||||
|
PersistentDataType.STRING
|
||||||
|
);
|
||||||
|
|
||||||
|
if (worldName == null
|
||||||
|
|| worldName.isBlank()) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(
|
||||||
|
MobEquipmentSettingsMenu.create(
|
||||||
|
worldName
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case "MOB_EQUIPMENT_SETTINGS" -> {
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getSlot()) {
|
||||||
|
|
||||||
|
case 4 -> {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
player.openInventory(
|
||||||
|
MobEquipmentWorldMenu.create(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to open Mob Equipment world menu: "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ public class WorldLoadListener implements Listener {
|
|||||||
entityDamageDefault
|
entityDamageDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
|
plugin.getEquipmentDropSettingsDAO()
|
||||||
|
.ensureWorldExists(
|
||||||
|
event.getWorld().getName()
|
||||||
|
);
|
||||||
|
|
||||||
boolean keepInventoryEnabled =
|
boolean keepInventoryEnabled =
|
||||||
plugin.getKeepInventoryDAO()
|
plugin.getKeepInventoryDAO()
|
||||||
.getWorldSetting(
|
.getWorldSetting(
|
||||||
@@ -68,7 +73,14 @@ public class WorldLoadListener implements Listener {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
RSServerAdmin.getInstance()
|
||||||
|
.getLogger()
|
||||||
|
.warning(
|
||||||
|
"Failed to register world settings for "
|
||||||
|
+ event.getWorld().getName()
|
||||||
|
+ ": "
|
||||||
|
+ ex.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.menuholder;
|
||||||
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
@@ -11,6 +11,8 @@ public class RSMenuHolder
|
|||||||
|
|
||||||
private int page = 1;
|
private int page = 1;
|
||||||
|
|
||||||
|
private String worldName;
|
||||||
|
|
||||||
public RSMenuHolder(
|
public RSMenuHolder(
|
||||||
String menuId
|
String menuId
|
||||||
) {
|
) {
|
||||||
@@ -45,6 +47,20 @@ public class RSMenuHolder
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWorldName() {
|
||||||
|
|
||||||
|
return worldName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorldName(
|
||||||
|
String worldName
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.worldName = worldName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Inventory getInventory() {
|
public @NotNull Inventory getInventory() {
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.utils;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.rsscripting.serveradmin.gui;
|
package com.rsscripting.serveradmin.utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
Reference in new issue
Block a user