diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 6abea8eb..9167102e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -14,6 +14,7 @@ + diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml index 901ee626..8fcbe357 100644 --- a/.idea/dbnavigator.xml +++ b/.idea/dbnavigator.xml @@ -17,14 +17,20 @@ - + @@ -39,16 +45,23 @@ + + + + + + + @@ -115,6 +128,7 @@ + @@ -142,7 +156,6 @@ - diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Protect.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Protect.java index ffe2b2a1..e85cd6c3 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Protect.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/commands/Protect.java @@ -27,7 +27,7 @@ private String getFlags() { StringBuilder sb = new StringBuilder(); sb.append("Available Flags: "); for (ProtectionFlags flag : flags) { - sb.append(flag.getName()).append(" "); + sb.append(flag.name()).append(" "); } return sb.toString(); } @@ -78,7 +78,7 @@ public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command if (ProtectionFlags.valueOf(args[2].toUpperCase()) != null) { p.sendMessage(PLUGIN_COMMAND_PROTECT_FLAG_ADD); pe.setPlayerState(PlayerState.PROTECTION_FLAG_ADD); - pe.setPlayerStateParameter(ProtectionFlags.valueOf(args[2].toUpperCase()).getName()); + pe.setPlayerStateParameter(ProtectionFlags.valueOf(args[2].toUpperCase()).name()); } } catch (IllegalArgumentException ex) { p.sendMessage(PLUGIN_COMMAND_PROTECT_FLAG_NOT_FOUND); @@ -89,7 +89,7 @@ public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command if (ProtectionFlags.valueOf(args[2].toUpperCase()) != null) { p.sendMessage(PLUGIN_COMMAND_PROTECT_FLAG_REMOVE); pe.setPlayerState(PlayerState.PROTECTION_FLAG_REMOVE); - pe.setPlayerStateParameter(ProtectionFlags.valueOf(args[2].toUpperCase()).getName()); + pe.setPlayerStateParameter(ProtectionFlags.valueOf(args[2].toUpperCase()).name()); } } catch (IllegalArgumentException ex) { p.sendMessage(PLUGIN_COMMAND_PROTECT_FLAG_NOT_FOUND); diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/ProtectionFlags.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/ProtectionFlags.java index d894e706..6c694734 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/ProtectionFlags.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/constants/ProtectionFlags.java @@ -4,17 +4,15 @@ @Getter public enum ProtectionFlags { - ALLOW_HOPPER("allowHopper", false), - ALLOW_REDSTONE("allowRedstone", false), - ALLOW_PUBLIC("allowPublic", false), - AUTO_CLOSE("autoClose", false); + ALLOW_HOPPER(false), + ALLOW_REDSTONE(false), + ALLOW_PUBLIC(false), + AUTO_CLOSE(false); - private final String name; private final boolean isDefault; - ProtectionFlags(String name, boolean isDefault){ - this.name = name; + ProtectionFlags(boolean isDefault){ this.isDefault = isDefault; } } \ No newline at end of file diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java index 0e9b567e..de474a8d 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java @@ -407,7 +407,7 @@ else if(b3.getBlockData() instanceof Chest cd3){ JSONObject flags = new JSONObject(); if(b.getType().equals(Material.LEVER) || b.getType().equals(Material.IRON_DOOR)){ - String[] flag = {ProtectionFlags.ALLOW_REDSTONE.getName()}; + String[] flag = {ProtectionFlags.ALLOW_REDSTONE.name()}; flags.put(PLUGIN_EVENT_PROTECT_FLAGS, flag); } bpe.setFlags(flags); @@ -538,7 +538,7 @@ else if(pe.getPlayerState().equals(PlayerState.PROTECTION_FLAG_REMOVE)){ if(pre.getFlags().has(PLUGIN_EVENT_PROTECT_FLAGS)){ JSONArray flagJSON = pre.getFlags().getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS); - String flag = ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).getName(); + String flag = ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).name(); List list = flagJSON.toList(); if(list.contains(flag)){ update = true; @@ -582,11 +582,11 @@ else if(pe.getPlayerState().equals(PlayerState.PROTECTION_FLAG_ADD)){ JSONArray flagJSON = pre.getFlags().getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS); List list = flagJSON.toList(); - String flag = ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).getName(); + String flag = ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).name(); if(!list.contains(flag)){ update = true; - list.add(ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).getName()); + list.add(ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).name()); } JSONObject flags = new JSONObject(); @@ -597,11 +597,11 @@ else if(pe.getPlayerState().equals(PlayerState.PROTECTION_FLAG_ADD)){ else{ JSONObject flags = new JSONObject(); if(Objects.requireNonNull(b).getType().equals(Material.LEVER) || b.getType().equals(Material.IRON_DOOR)){ - String[] flag = {ProtectionFlags.ALLOW_REDSTONE.getName(),ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).getName()}; + String[] flag = {ProtectionFlags.ALLOW_REDSTONE.name(),ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).name()}; flags.put(PLUGIN_EVENT_PROTECT_FLAGS, flag); } else{ - String[] flag = {ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).getName()}; + String[] flag = {ProtectionFlags.valueOf(((String)pe.getPlayerStateParameter()).toUpperCase()).name()}; flags.put(PLUGIN_EVENT_PROTECT_FLAGS, flag); } update = true; @@ -890,7 +890,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent e) { if (protection != null){ JSONObject flags = protection.getFlags(); - boolean isAllowed = (!flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS).toList().contains(ProtectionFlags.ALLOW_REDSTONE.getName())); + boolean isAllowed = (!flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS).toList().contains(ProtectionFlags.ALLOW_REDSTONE.name())); if(!isAllowed){ e.setNewCurrent(e.getOldCurrent()); } diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/DatabaseHelper.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/DatabaseHelper.java index b541aa4c..832cc0b1 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/DatabaseHelper.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/DatabaseHelper.java @@ -280,6 +280,16 @@ private void patch8() { executeScript(v + UPDATE_OLD_PLUGIN_INFORMATION); } + private void patch9() { + String v = "patches/v9/"; + + executeScript(v + "updateProtections.sql"); + executeScript(v + "fixProtections.sql"); + + executeScript(v + INSERT_NEW_DB_VERSION); + executeScript(v + UPDATE_OLD_PLUGIN_INFORMATION); + } + public void init() { applyPatch(getPluginInformation().getDbVersion()); } @@ -296,6 +306,7 @@ private void applyPatch(int version) { patch6(); patch7(); patch8(); + patch9(); break; case 1: patch2(); @@ -305,6 +316,7 @@ private void applyPatch(int version) { patch6(); patch7(); patch8(); + patch9(); break; case 2: patch3(); @@ -313,6 +325,7 @@ private void applyPatch(int version) { patch6(); patch7(); patch8(); + patch9(); break; case 3: patch4(); @@ -320,24 +333,32 @@ private void applyPatch(int version) { patch6(); patch7(); patch8(); + patch9(); break; case 4: patch5(); patch6(); patch7(); patch8(); + patch9(); break; case 5: patch6(); patch7(); patch8(); + patch9(); break; case 6: patch7(); patch8(); + patch9(); break; case 7: patch8(); + patch9(); + break; + case 8: + patch9(); break; default: // To add Scripts in Development without its own patch version diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/ProtectionHelper.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/ProtectionHelper.java index ae8780dd..69f072eb 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/ProtectionHelper.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/helpers/ProtectionHelper.java @@ -86,8 +86,8 @@ public static boolean hasPermission(ProtectionEntry pre, Player p){ public static boolean hasFlag(ProtectionEntry protection, ProtectionFlags flag) { JSONObject flags = protection.getFlags(); return( - (!flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.get(PLUGIN_EVENT_PROTECT_FLAGS) instanceof JSONArray && flags.getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS).toList().contains(flag.getName())) || - !flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.get(PLUGIN_EVENT_PROTECT_FLAGS) instanceof String && flags.get(PLUGIN_EVENT_PROTECT_FLAGS).equals(flag.getName()) + (!flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.get(PLUGIN_EVENT_PROTECT_FLAGS) instanceof JSONArray && flags.getJSONArray(PLUGIN_EVENT_PROTECT_FLAGS).toList().contains(flag.name())) || + !flags.isEmpty() && flags.has(PLUGIN_EVENT_PROTECT_FLAGS) && flags.get(PLUGIN_EVENT_PROTECT_FLAGS) instanceof String && flags.get(PLUGIN_EVENT_PROTECT_FLAGS).equals(flag.name()) ); } diff --git a/src/main/resources/sqls/patches/v9/fixProtections.sql b/src/main/resources/sqls/patches/v9/fixProtections.sql new file mode 100644 index 00000000..cb7b99c5 --- /dev/null +++ b/src/main/resources/sqls/patches/v9/fixProtections.sql @@ -0,0 +1,11 @@ +UPDATE protections +SET flags = CASE + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) IS NOT NULL THEN + JSON_SET(flags, '$.flags', JSON_ARRAY(JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')))) + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) IS NOT NULL THEN + JSON_SET(flags, '$.flags', JSON_ARRAY(JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')), JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')))) + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) IS NOT NULL THEN + JSON_SET(flags, '$.flags', JSON_ARRAY(JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')))) + ELSE + JSON_SET(flags, '$.flags', JSON_ARRAY()) + END; \ No newline at end of file diff --git a/src/main/resources/sqls/patches/v9/insertNewDBVersion.sql b/src/main/resources/sqls/patches/v9/insertNewDBVersion.sql new file mode 100644 index 00000000..d43d349b --- /dev/null +++ b/src/main/resources/sqls/patches/v9/insertNewDBVersion.sql @@ -0,0 +1,6 @@ +/** + * Author: rellu + * Created: 19.02.2023 + */ + +INSERT INTO `plugin_informations` (`CREATED`, `CREATEDBY`, `tab_header`, `tab_footer`, `motd_message`, `motd_players`, `db_version`) SELECT now(), 1, tab_header, tab_footer, motd_message, motd_players, 9 FROM `plugin_informations` where deletedby is null; diff --git a/src/main/resources/sqls/patches/v9/updateOldPluginInformation.sql b/src/main/resources/sqls/patches/v9/updateOldPluginInformation.sql new file mode 100644 index 00000000..39aac2c3 --- /dev/null +++ b/src/main/resources/sqls/patches/v9/updateOldPluginInformation.sql @@ -0,0 +1,6 @@ +/** + * Author: rellu + * Created: 19.02.2023 + */ + +UPDATE `plugin_informations` SET `deleted` = now(), `deletedby` = 1 WHERE `plugin_informations`.`DELETEDBY` IS NULL and `db_version` <> 9 ; \ No newline at end of file diff --git a/src/main/resources/sqls/patches/v9/updateProtections.sql b/src/main/resources/sqls/patches/v9/updateProtections.sql new file mode 100644 index 00000000..cb4228f2 --- /dev/null +++ b/src/main/resources/sqls/patches/v9/updateProtections.sql @@ -0,0 +1,28 @@ +UPDATE protections +SET flags = JSON_SET( + flags, + '$.flags', + JSON_ARRAY( + CASE + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) = 'allowHopper' THEN 'ALLOW_HOPPER' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) = 'allowPublic' THEN 'ALLOW_PUBLIC' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) = 'allowRedstone' THEN 'ALLOW_REDSTONE' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) = 'autoClose' THEN 'AUTO_CLOSE' + ELSE JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[0]')) + END, + CASE + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) = 'allowHopper' THEN 'ALLOW_HOPPER' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) = 'allowPublic' THEN 'ALLOW_PUBLIC' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) = 'allowRedstone' THEN 'ALLOW_REDSTONE' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) = 'autoClose' THEN 'AUTO_CLOSE' + ELSE JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[1]')) + END, + CASE + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[2]')) = 'allowHopper' THEN 'ALLOW_HOPPER' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[2]')) = 'allowPublic' THEN 'ALLOW_PUBLIC' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[2]')) = 'allowRedstone' THEN 'ALLOW_REDSTONE' + WHEN JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[2]')) = 'autoClose' THEN 'AUTO_CLOSE' + ELSE JSON_UNQUOTE(JSON_EXTRACT(flags, '$.flags[2]')) + END + ) +); \ No newline at end of file