From 71127c31520ea72705955aa16c91de176c7e8359 Mon Sep 17 00:00:00 2001 From: Allink <44676012+allinkdev@users.noreply.github.com> Date: Mon, 20 Feb 2023 23:39:40 +0000 Subject: [PATCH 1/3] Add configuration option for disabling books (#275) FS-458 Co-authored-by: Video Co-authored-by: Paldiu --- .../totalfreedommod/blocking/InteractBlocker.java | 5 +++++ .../totalfreedommod/command/Command_toggle.java | 8 +++++++- .../totalfreedom/totalfreedommod/config/ConfigEntry.java | 1 + src/main/resources/config.yml | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 6a70f7d4..08437c25 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -171,6 +171,11 @@ public class InteractBlocker extends FreedomService } case WRITTEN_BOOK: { + if (ConfigEntry.ALLOW_BOOKS.getBoolean()) + { + break; + } + player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "Books are currently disabled."); event.setCancelled(true); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 2639b9d5..43a37446 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -19,7 +19,7 @@ public class Command_toggle extends FreedomCommand private final List toggles = Arrays.asList( "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]", - "explosives [radius]", "unsafeenchs", "bells", "armorstands", "masterblocks", "grindstones", + "explosives [radius]", "unsafeenchs", "bells", "armorstands", "masterblocks", "books", "grindstones", "jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob", "gravity"); @@ -199,6 +199,12 @@ public class Command_toggle extends FreedomCommand break; } + case "books": + { + toggle("Books are", ConfigEntry.ALLOW_BOOKS); + break; + } + case "grindstones": { toggle("Grindstones are", ConfigEntry.ALLOW_GRINDSTONES); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 019d7843..aad8c8aa 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -34,6 +34,7 @@ public enum ConfigEntry AUTO_CLEAR(Boolean.class, "allow.auto_clear"), ALLOW_GRAVITY(Boolean.class, "allow.gravity"), ALLOW_MASTERBLOCKS(Boolean.class, "allow.masterblocks"), + ALLOW_BOOKS(Boolean.class, "allow.books"), // BLOCKED_CHATCODES(String.class, "blocked_chatcodes"), // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dea8a9f3..6631fedb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -220,6 +220,7 @@ allow: auto_clear: false gravity: false masterblocks: false + books: true blocked_commands: # From 3deaaafb8804d0c6634ab22d970f58ab8c529778 Mon Sep 17 00:00:00 2001 From: Video Date: Wed, 8 Mar 2023 19:52:30 -0700 Subject: [PATCH 2/3] Patches critical exploit --- .../blocking/command/CommandBlocker.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java index 2074f3e5..850b0159 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java @@ -24,7 +24,7 @@ import org.bukkit.plugin.SimplePluginManager; public class CommandBlocker extends FreedomService { - + private final Pattern whitespacePattern = Pattern.compile("^/?( +)(.*)?"); private final Pattern flagPattern = Pattern.compile("(:([0-9]){5,})"); // private final Map entryList = Maps.newHashMap(); @@ -156,6 +156,14 @@ public class CommandBlocker extends FreedomService // Format command = command.toLowerCase().trim(); + + // Whitespaces + Matcher whitespaceMatcher = whitespacePattern.matcher(command); + if (whitespaceMatcher.matches() && whitespaceMatcher.groupCount() == 2) + { + command = whitespaceMatcher.group(2); + } + command = command.startsWith("/") ? command.substring(1) : command; // Check for plugin specific commands From 41331e719d3d784f29c109d1a5ad943bb906e94a Mon Sep 17 00:00:00 2001 From: Video Date: Wed, 8 Mar 2023 19:58:14 -0700 Subject: [PATCH 3/3] Updates version to 2022.06.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a6d8a95e..d9ed9205 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ me.totalfreedom TotalFreedomMod - 2022.06 + 2022.06.1 jar