From 8c55e29db10c1ac936946002ec60c4306276ecf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9l=C3=A9anore=20is=20not=20coding=20in=20the=20slight?= =?UTF-8?q?est?= <166862894+eleanordoesntcode@users.noreply.github.com> Date: Tue, 15 Apr 2025 19:34:19 +0200 Subject: [PATCH 01/27] Personalising template (no actual code done) --- .github/workflows/build-and-test.yaml | 11 ++-- .github/workflows/release.yml | 3 +- README.md | 50 +++++-------------- pom.xml | 8 +-- .../mc/notes}/TemplateConfig.java | 0 .../mc/notes}/TemplateListener.java | 0 .../mc/notes}/TemplatePlugin.java | 0 .../notes}/commands/TemplateTestCommand.java | 0 src/main/resources/plugin.yml | 34 +++++++++---- 9 files changed, 48 insertions(+), 58 deletions(-) rename src/main/java/org/{retromc/templateplugin => eleanorsilly/mc/notes}/TemplateConfig.java (100%) rename src/main/java/org/{retromc/templateplugin => eleanorsilly/mc/notes}/TemplateListener.java (100%) rename src/main/java/org/{retromc/templateplugin => eleanorsilly/mc/notes}/TemplatePlugin.java (100%) rename src/main/java/org/{retromc/templateplugin => eleanorsilly/mc/notes}/commands/TemplateTestCommand.java (100%) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 2047703..7bca7ba 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -9,6 +9,7 @@ on: branches: - master - main + - dev jobs: build: @@ -27,15 +28,15 @@ jobs: - name: Set up Maven uses: stCarolas/setup-maven@v4.5 with: - maven-version: 3.9.1 + maven-version: 3.9.9 - name: build application shell: bash run: | - mvn clean install + mvn clean package - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{ github.event.repository.name }}-artifact - path: target/*.jar \ No newline at end of file + name: artifacts + path: target/*.jar diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70c055d..5269456 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,9 +36,10 @@ jobs: - name: Create GitHub Release if: ${{ !endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }} - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: tag_name: ${{ env.PROJECT_VERSION }} + body_path: changelogs/${{ env.PROJECT_VERSION }}.md files: | target/*.jar env: diff --git a/README.md b/README.md index d2b175d..9670241 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,19 @@ -# Poseidon-Plugin-Template +# SimpleNotes -This repository serves as a template to assist with creating plugins for Project Poseidon. +This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. -It includes examples of: -- A configuration file. -- A listener. -- A command. +## Commands -## Steps to Use This Template +The plugin uses one command, /note (with aliases /notes, /warning and /warnings). -1. **Clone the Repository** - - Clone this repository to your local machine. +### Subcommands -2. **Modify `pom.xml`** - - Update the following fields to reflect your plugin: - - `name` - - `version` - - `description` - - **Note:** Removing `-SNAPSHOT` from the version will trigger the `release.yml` GitHub Action to create a GitHub release. +- /note help: list the subcommands you have access to +- /note list: list your own notes/warnings (permission: simplenotes.seenotes.self) +- /note list : list other player's notes/warnings (permission: simplenotes.seenotes.others) +- /note add : add a note to a player (permission: simplenotes.addnotes) +- /note remove : remove a note from a player (permission: simplenotes.removenotes) -3. **Refactor Package Structure** - - Refactor the package `org.retromc.templateplugin` to a unique package name for your plugin to avoid conflicts. +## Compiling -4. **Update `plugin.yml`** - - Update the `plugin.yml` file to match the refactored package name and plugin metadata. - -5. **Modify the Code** - - Customize the code as required for your plugin. - - **Important:** - - Remove the player greeting example in the listener. - - Remove the test command. - -## GitHub Actions - -This repository includes a pre-configured GitHub Action: - -1. **`build-and-test.yml`**: - - Runs tests on every push to ensure code quality. - - Uploads an artifact for each commit, allowing others to download the plugin for testing. - -2. **`release.yml`**: - - Automatically creates a GitHub release if the `-SNAPSHOT` suffix is removed from the version in `pom.xml`. - -With this template, you can kickstart your plugin development for Project Poseidon quickly and efficiently. +Clone the repository and run `mvn clean package`. The resulting jar should be in the `target` folder. diff --git a/pom.xml b/pom.xml index 643ddfa..c6c1a3b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example - Poseidon-Plugin-Template + org.eleanorsilly.mc.notes + SimpleNotes 1.0.0-SNAPSHOT - A template for creating plugins for the Poseidon server software. + A note system for moderators and admins, with the objective to be light on the system and on the codebase. 8 @@ -71,4 +71,4 @@ - \ No newline at end of file + diff --git a/src/main/java/org/retromc/templateplugin/TemplateConfig.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java similarity index 100% rename from src/main/java/org/retromc/templateplugin/TemplateConfig.java rename to src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java diff --git a/src/main/java/org/retromc/templateplugin/TemplateListener.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java similarity index 100% rename from src/main/java/org/retromc/templateplugin/TemplateListener.java rename to src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java diff --git a/src/main/java/org/retromc/templateplugin/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java similarity index 100% rename from src/main/java/org/retromc/templateplugin/TemplatePlugin.java rename to src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java diff --git a/src/main/java/org/retromc/templateplugin/commands/TemplateTestCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java similarity index 100% rename from src/main/java/org/retromc/templateplugin/commands/TemplateTestCommand.java rename to src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ab373a5..fe8d34f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,22 +1,36 @@ name: ${project.name} description: ${project.description} -main: org.retromc.templateplugin.TemplatePlugin +main: org.eleanorsilly.mc.notes version: ${project.version} authors: - - JohnyMuffin + - eleanorsilly softdepend: - Essentials commands: testcommand: - description: A test command for the plugin. - usage: / [args] - aliases: [tc] - permission: myplugin.testcommand - permission-message: You do not have permission to use this command. + description: The main command of the plugin. /note help for more details. + usage: /note [args] + aliases: [notes, warning, warnings] permissions: - myplugin.*: - description: Gives access to all myplugin commands. + simplenotes.*: + description: Gives access to all commands of the plugin. Should be used sparingly, e.g. for admins. children: - myplugin.testcommand: true \ No newline at end of file + simplenotes.addnotes: true + simplenotes.removenotes: true + simplenotes.seenotes.self: true + simplenotes.seenotes.others: true + simplenotes.addnotes: + description: Gives the permission to add notes/warnings. + simplenotes.removenotes: + description: Gives the permission to remove notes/warnings. + simplenotes.seenotes.*: + description: Gives the permission to see the notes/warnings of all players. + children: + simplenotes.seenotes.self: true + simplenotes.seenotes.others: true + simplenotes.seenotes.self: + description: Gives the permission to see your own notes/warnings + simplenotes.seenotes.others: + description: "Gives the permission to see other people's notes/warnings" From cfb03c6d99276c825d4fa0bf991d930b5f02b773 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:12:01 +0000 Subject: [PATCH 02/27] handle licensing with retromc's code --- LICENSE | 2 +- LICENSE-retromc | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 LICENSE-retromc diff --git a/LICENSE b/LICENSE index ab5a771..268491a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 RetroMC Development Group +Copyright (c) 2025 eleanorsilly Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE-retromc b/LICENSE-retromc new file mode 100644 index 0000000..ab5a771 --- /dev/null +++ b/LICENSE-retromc @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 RetroMC Development Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From af3c9b01b3f417c9489ffc2ccc80b8af307063b7 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:30:06 +0000 Subject: [PATCH 03/27] warning on top of the README for any dev :P --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9670241..3ae8c6f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# THIS IS NOT PRODUCTION READY BY ANY MEANS. DO NOT INSTALL. + # SimpleNotes This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. From 0ff03fb779f0750f22537f24dca5b80b93fc73fb Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:33:10 +0000 Subject: [PATCH 04/27] use a repository that isn't down --- pom.xml | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index c6c1a3b..2818fdf 100644 --- a/pom.xml +++ b/pom.xml @@ -18,25 +18,8 @@ - johnymuffin-nexus-releases - https://repository.johnymuffin.com/repository/maven-public/ - - true - - - false - - - - - johnymuffin-nexus-snapshots - https://repository.johnymuffin.com/repository/maven-snapshots/ - - false - - - true - + jitpack.io + https://jitpack.io @@ -64,9 +47,9 @@ - com.legacyminecraft.poseidon - poseidon-craftbukkit - 1.1.8 + com.github.retromcorg + Project-Poseidon + 1.1.10-250328-1731-f67a8e3 From cdde8b09fba9fa8f23d921b946bee793c322792c Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 00:14:01 +0200 Subject: [PATCH 05/27] fix package name --- src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java | 2 +- .../java/org/eleanorsilly/mc/notes/TemplateListener.java | 2 +- src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java | 4 ++-- .../eleanorsilly/mc/notes/commands/TemplateTestCommand.java | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java index 072c1d8..d4120a2 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java @@ -1,4 +1,4 @@ -package org.retromc.templateplugin; +package org.eleanorsilly.mc.notes; import org.bukkit.util.config.Configuration; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java index 846827e..cef4470 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java @@ -1,4 +1,4 @@ -package org.retromc.templateplugin; +package org.eleanorsilly.mc.notes; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java index 5f06a40..4a4e0c0 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java @@ -1,9 +1,9 @@ -package org.retromc.templateplugin; +package org.eleanorsilly.mc.notes; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import org.retromc.templateplugin.commands.TemplateTestCommand; +import org.eleanorsilly.mc.notes.commands.TemplateTestCommand; import java.io.File; import java.util.logging.Level; diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java index b23c08e..0cdb8d3 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java @@ -1,11 +1,11 @@ -package org.retromc.templateplugin.commands; +package org.eleanorsilly.mc.notes.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.retromc.templateplugin.TemplateConfig; -import org.retromc.templateplugin.TemplatePlugin; +import org.eleanorsilly.mc.notes.TemplateConfig; +import org.eleanorsilly.mc.notes.TemplatePlugin; public class TemplateTestCommand implements CommandExecutor { From 1a6fb448c5fe36810b5c5aa75daa20f2038954b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9l=C3=A9anore=20is=20not=20coding=20in=20the=20slight?= =?UTF-8?q?est?= <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 02:18:00 +0200 Subject: [PATCH 06/27] whoops, forgot that template use --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fe8d34f..253153b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,7 +8,7 @@ softdepend: - Essentials commands: - testcommand: + notecommand: description: The main command of the plugin. /note help for more details. usage: /note [args] aliases: [notes, warning, warnings] From 577653e8365199b64019f3d68334a6f64b0532ae Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 02:27:36 +0200 Subject: [PATCH 07/27] no, we do not greet the player. --- .../org/eleanorsilly/mc/notes/TemplateListener.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java index cef4470..87de259 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java @@ -14,15 +14,4 @@ public TemplateListener(TemplatePlugin plugin) { this.plugin = plugin; this.config = plugin.getConfig(); } - - // Handle player join event - @EventHandler(priority = Event.Priority.Normal) - public void onPlayerJoin(PlayerJoinEvent event) { - // Example action: Send a welcome message configured in the plugin's configuration file to the player when they join the server - - String welcomeMessage = config.getConfigString("settings.welcome-message.value"); - welcomeMessage = welcomeMessage.replace("%player%", event.getPlayer().getName()); - - event.getPlayer().sendMessage(welcomeMessage); - } } From 9bbd57d1fd7f4bc7a1438cf528f85efa22f18370 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 02:33:17 +0200 Subject: [PATCH 08/27] start of coding for this. an IDE really helps. --- .../eleanorsilly/mc/notes/TemplatePlugin.java | 15 ++++++-- ...plateTestCommand.java => NoteCommand.java} | 38 +++++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) rename src/main/java/org/eleanorsilly/mc/notes/commands/{TemplateTestCommand.java => NoteCommand.java} (53%) diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java index 4a4e0c0..7aced97 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java @@ -3,7 +3,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import org.eleanorsilly.mc.notes.commands.TemplateTestCommand; +import org.eleanorsilly.mc.notes.commands.NoteCommand; import java.io.File; import java.util.logging.Level; @@ -17,7 +17,6 @@ public class TemplatePlugin extends JavaPlugin { private TemplateConfig configuration; - @Override public void onEnable() { plugin = this; @@ -29,8 +28,12 @@ public void onEnable() { // Load configuration configuration = new TemplateConfig(this, new File(getDataFolder(), "config.yml")); // Load the configuration file from the plugin's data folder - // Register the commands - getCommand("testcommand").setExecutor(new TemplateTestCommand(this)); + // Register the command and the aliases + getCommand("note").setExecutor(new NoteCommand(this)); + getCommand("notes").setExecutor(new NoteCommand(this)); + getCommand("warn").setExecutor(new NoteCommand(this)); + getCommand("warning").setExecutor(new NoteCommand(this)); + getCommand("warnings").setExecutor(new NoteCommand(this)); // Register the listeners TemplateListener listener = new TemplateListener(this); @@ -56,4 +59,8 @@ public void logger(Level level, String message) { public TemplateConfig getConfig() { return configuration; } + + public boolean WriteToFile(String filename, String content) { + return false + } } diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java similarity index 53% rename from src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java rename to src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index 0cdb8d3..0e376c1 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/TemplateTestCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -7,29 +7,42 @@ import org.eleanorsilly.mc.notes.TemplateConfig; import org.eleanorsilly.mc.notes.TemplatePlugin; -public class TemplateTestCommand implements CommandExecutor { +public class NoteCommand implements CommandExecutor { private final TemplatePlugin plugin; private final TemplateConfig config; - public TemplateTestCommand(TemplatePlugin plugin) { + public NoteCommand(TemplatePlugin plugin) { this.plugin = plugin; this.config = plugin.getConfig(); } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if the sender is a player - if (!(sender instanceof Player)) { - sender.sendMessage("This command can only be executed by players."); + public boolean NoteAdd(CommandSender sender, String[] args) { + if (!sender.hasPermission("simplenotes.addnotes") && !sender.isOp()) { + sender.sendMessage("You do not have permission to use this subcommand."); return true; } + } - if (!sender.hasPermission("myplugin.testcommand") && !sender.isOp()) { - sender.sendMessage("You do not have permission to execute this command."); + public boolean NoteRemove(CommandSender sender, String[] args) { + if (!sender.hasPermission("simplenotes.removenotes") && !sender.isOp()) { + sender.sendMessage("You do not have permission to use this subcommand."); return true; } + return false + } + + public boolean NoteList(CommandSender sender, String[] args) { + return false + } + + public boolean NoteHelp(CommandSender sender) { + return false + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { // Check if the command is enabled Boolean isEnabled = config.getConfigBoolean("settings.test-command.enabled.value"); @@ -37,12 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St sender.sendMessage("This command is currently disabled."); return true; } - - // Get the response message from the config - String response = config.getConfigString("settings.test-command.response.value"); - - // Send the response message to the player - sender.sendMessage(response); + // todo: logic to call the different functions above return true; } } From 6849e1c352e39176853ea320275372149a9e8da5 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 14:37:20 +0200 Subject: [PATCH 09/27] missing semicolons (i dont like java) --- .../java/org/eleanorsilly/mc/notes/TemplatePlugin.java | 2 +- .../org/eleanorsilly/mc/notes/commands/NoteCommand.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java index 7aced97..f95a136 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java @@ -61,6 +61,6 @@ public TemplateConfig getConfig() { } public boolean WriteToFile(String filename, String content) { - return false + return false; } } diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index 0e376c1..bec0b2c 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -23,6 +23,7 @@ public boolean NoteAdd(CommandSender sender, String[] args) { sender.sendMessage("You do not have permission to use this subcommand."); return true; } + return false; } public boolean NoteRemove(CommandSender sender, String[] args) { @@ -30,15 +31,15 @@ public boolean NoteRemove(CommandSender sender, String[] args) { sender.sendMessage("You do not have permission to use this subcommand."); return true; } - return false + return false; } public boolean NoteList(CommandSender sender, String[] args) { - return false + return false; } public boolean NoteHelp(CommandSender sender) { - return false + return false; } @Override From 37c5cbb12baa9c68f99f57bc6c50945db3b99cf4 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 19 Apr 2025 15:10:55 +0200 Subject: [PATCH 10/27] add more detailed permissions (only in documentation) --- README.md | 8 ++--- .../eleanorsilly/mc/notes/TemplatePlugin.java | 1 + src/main/resources/plugin.yml | 34 ++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3ae8c6f..57764dd 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ The plugin uses one command, /note (with aliases /notes, /warning and /warnings) ### Subcommands - /note help: list the subcommands you have access to -- /note list: list your own notes/warnings (permission: simplenotes.seenotes.self) -- /note list : list other player's notes/warnings (permission: simplenotes.seenotes.others) -- /note add : add a note to a player (permission: simplenotes.addnotes) -- /note remove : remove a note from a player (permission: simplenotes.removenotes) +- /note list: list your own notes/warnings (permission: simplenotes.see.self.notes/warnings) +- /note list [player]: list other player's notes/warnings (permission: simplenotes.see.others.notes/warnings) +- /note add [player] [type (note/warn)] [content]: add a note to a player (permission: simplenotes.addnotes) +- /note remove [player] [id]: remove a note from a player (permission: simplenotes.removenotes) ## Compiling diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java index f95a136..910ebf8 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java @@ -32,6 +32,7 @@ public void onEnable() { getCommand("note").setExecutor(new NoteCommand(this)); getCommand("notes").setExecutor(new NoteCommand(this)); getCommand("warn").setExecutor(new NoteCommand(this)); + getCommand("warns").setExecutor(new NoteCommand(this)); getCommand("warning").setExecutor(new NoteCommand(this)); getCommand("warnings").setExecutor(new NoteCommand(this)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 253153b..c977273 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,7 +11,7 @@ commands: notecommand: description: The main command of the plugin. /note help for more details. usage: /note [args] - aliases: [notes, warning, warnings] + aliases: [notes, warn, warns, warning, warnings] permissions: simplenotes.*: @@ -19,18 +19,36 @@ permissions: children: simplenotes.addnotes: true simplenotes.removenotes: true - simplenotes.seenotes.self: true - simplenotes.seenotes.others: true + simplenotes.see.self.notes: true + simplenotes.see.self.warns: true + simplenotes.see.others.notes: true + simplenotes.see.others.warns: true simplenotes.addnotes: description: Gives the permission to add notes/warnings. simplenotes.removenotes: description: Gives the permission to remove notes/warnings. - simplenotes.seenotes.*: + simplenotes.see.*: description: Gives the permission to see the notes/warnings of all players. children: - simplenotes.seenotes.self: true - simplenotes.seenotes.others: true - simplenotes.seenotes.self: + simplenotes.see.self.notes: true + simplenotes.see.self.warns: true + simplenotes.see.others.notes: true + simplenotes.see.others.warns: true + simplenotes.see.self.*: description: Gives the permission to see your own notes/warnings - simplenotes.seenotes.others: + children: + simplenotes.see.self.notes: true + simplenotes.see.self.warns: true + simplenotes.see.self.notes: + description: Gives the permission to see your own notes + simplenotes.see.self.warns: + description: Gives the permission to see your own warnings + simplenotes.see.others.*: description: "Gives the permission to see other people's notes/warnings" + children: + simplenotes.see.others.notes: true + simplenotes.see.others.warns: true + simplenotes.see.others.notes: + description: "Gives the permission to see other people's notes" + simplenotes.see.others.warns: + description: "Gives the permission to see other people's warnings" From 036c4a5243d00d0d2b4b0f7923de114a1d3075a0 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 15 May 2025 23:47:01 +0200 Subject: [PATCH 11/27] saving progress. oh boy. that doesn't fit into a commit message. --- README.md | 7 +- pom.xml | 44 +++- .../{TemplatePlugin.java => NotePlugin.java} | 29 +-- .../eleanorsilly/mc/notes/TemplateConfig.java | 5 +- .../mc/notes/TemplateListener.java | 7 +- .../mc/notes/commands/NoteCommand.java | 232 +++++++++++++++++- src/main/resources/plugin.yml | 2 +- 7 files changed, 279 insertions(+), 47 deletions(-) rename src/main/java/org/eleanorsilly/mc/notes/{TemplatePlugin.java => NotePlugin.java} (66%) diff --git a/README.md b/README.md index 57764dd..2780714 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,19 @@ This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. +This plugin currently assumes all players are paid accounts. Adding offline players isn't planned for now. ## Commands -The plugin uses one command, /note (with aliases /notes, /warning and /warnings). +The plugin uses one command, /note (with aliases /notes, /warn, /warns, /warning and /warnings). ### Subcommands - /note help: list the subcommands you have access to - /note list: list your own notes/warnings (permission: simplenotes.see.self.notes/warnings) - /note list [player]: list other player's notes/warnings (permission: simplenotes.see.others.notes/warnings) -- /note add [player] [type (note/warn)] [content]: add a note to a player (permission: simplenotes.addnotes) +- /note add [player] [content]: add a note to a player (permission: simplenotes.addnotes) +- /warn add [player] [content]: add a warn to a player (permission: simplenotes.addnotes) + - This is the only case where the alias matter. You can use any of the warn* aliases for this. - /note remove [player] [id]: remove a note from a player (permission: simplenotes.removenotes) ## Compiling diff --git a/pom.xml b/pom.xml index 2818fdf..a91a944 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,25 @@ - jitpack.io - https://jitpack.io + johnymuffin-nexus-releases + https://repository.johnymuffin.com/repository/maven-public/ + + true + + + false + + + + + johnymuffin-nexus-snapshots + https://repository.johnymuffin.com/repository/maven-snapshots/ + + false + + + true + @@ -43,15 +60,26 @@ - - - com.github.retromcorg - Project-Poseidon + com.legacyminecraft.poseidon + poseidon-craftbukkit 1.1.10-250328-1731-f67a8e3 - + + org.apache.commons + commons-text + 1.13.1 + + + org.json + json + 20250107 + + + com.opencsv + opencsv + 5.11 + - diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java similarity index 66% rename from src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java rename to src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java index 910ebf8..38bb88a 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplatePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java @@ -1,15 +1,23 @@ package org.eleanorsilly.mc.notes; +import org.apache.commons.lang3.StringEscapeUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.eleanorsilly.mc.notes.commands.NoteCommand; -import java.io.File; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; -public class TemplatePlugin extends JavaPlugin { +public class NotePlugin extends JavaPlugin { private JavaPlugin plugin; private Logger log; private String pluginName; @@ -23,34 +31,27 @@ public void onEnable() { log = this.getServer().getLogger(); pdf = this.getDescription(); pluginName = pdf.getName(); - log.info("[" + pluginName + "] Is Loading, Version: " + pdf.getVersion()); + log.info("[" + pluginName + "] is loading, version: " + pdf.getVersion()); // Load configuration configuration = new TemplateConfig(this, new File(getDataFolder(), "config.yml")); // Load the configuration file from the plugin's data folder // Register the command and the aliases getCommand("note").setExecutor(new NoteCommand(this)); - getCommand("notes").setExecutor(new NoteCommand(this)); - getCommand("warn").setExecutor(new NoteCommand(this)); - getCommand("warns").setExecutor(new NoteCommand(this)); - getCommand("warning").setExecutor(new NoteCommand(this)); - getCommand("warnings").setExecutor(new NoteCommand(this)); // Register the listeners TemplateListener listener = new TemplateListener(this); getServer().getPluginManager().registerEvents(listener, this); - log.info("[" + pluginName + "] Is Loaded, Version: " + pdf.getVersion()); + log.info("[" + pluginName + "] Plugin loaded!"); } @Override public void onDisable() { - log.info("[" + pluginName + "] Is Unloading, Version: " + pdf.getVersion()); - // Save configuration //config.save(); // Save the configuration file to disk. This should only be necessary if the configuration cam be modified during runtime. - log.info("[" + pluginName + "] Is Unloaded, Version: " + pdf.getVersion()); + log.info("[" + pluginName + "] Plugin unloaded!"); } public void logger(Level level, String message) { @@ -60,8 +61,4 @@ public void logger(Level level, String message) { public TemplateConfig getConfig() { return configuration; } - - public boolean WriteToFile(String filename, String content) { - return false; - } } diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java index d4120a2..d8f3e07 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java @@ -1,7 +1,6 @@ package org.eleanorsilly.mc.notes; import org.bukkit.util.config.Configuration; -import org.jetbrains.annotations.Nullable; import java.io.File; @@ -14,7 +13,7 @@ public class TemplateConfig extends Configuration { private final int configVersion = 1; - private TemplatePlugin plugin; + private NotePlugin plugin; /** * Constructs a new TemplateConfig instance. @@ -22,7 +21,7 @@ public class TemplateConfig extends Configuration { * @param plugin The plugin instance associated with this configuration. * @param configFile The configuration file to be managed. */ - public TemplateConfig(TemplatePlugin plugin, File configFile) { + public TemplateConfig(NotePlugin plugin, File configFile) { super(configFile); this.plugin = plugin; this.reload(); diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java index 87de259..0500ddf 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java @@ -1,16 +1,13 @@ package org.eleanorsilly.mc.notes; -import org.bukkit.event.Event; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; public class TemplateListener implements Listener { - private TemplatePlugin plugin; + private NotePlugin plugin; private TemplateConfig config; // Constructor to link the plugin instance - public TemplateListener(TemplatePlugin plugin) { + public TemplateListener(NotePlugin plugin) { this.plugin = plugin; this.config = plugin.getConfig(); } diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index bec0b2c..5564ed3 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -1,45 +1,242 @@ package org.eleanorsilly.mc.notes.commands; +import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; +import com.opencsv.CSVWriter; +import com.opencsv.CSVWriterBuilder; +import com.opencsv.exceptions.CsvValidationException; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.eleanorsilly.mc.notes.TemplateConfig; -import org.eleanorsilly.mc.notes.TemplatePlugin; +import org.eleanorsilly.mc.notes.NotePlugin; +import org.json.JSONObject; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import static org.bukkit.Bukkit.getPlayer; public class NoteCommand implements CommandExecutor { - private final TemplatePlugin plugin; + private final NotePlugin plugin; private final TemplateConfig config; - public NoteCommand(TemplatePlugin plugin) { + public NoteCommand(NotePlugin plugin) { this.plugin = plugin; this.config = plugin.getConfig(); } - public boolean NoteAdd(CommandSender sender, String[] args) { + public boolean CheckFileExists(File file) { + if (file.exists()) { + return true; + } else { + // we create the folders above + List parentList = Arrays.asList(file.getParentFile()); + while (parentList.get(parentList.size() - 1).exists()) { + parentList.add(parentList.get(parentList.size() - 1).getParentFile()); + } + for (int i = parentList.size()-1; i > -1; i--) { + // create all parents, going through the list in reverse + try { + parentList.get(i).mkdirs(); + } catch (Exception e) { + // probably a permission issue, failed to create the dirs + return false; + } + } + // then we return false, now that all parents exist. + return false; + } + } + + public Object getUUIDFromName(String playerName) { + try { + String urlString = "https://api.mojang.com/users/profiles/minecraft/" + playerName; + URL url = new URL(urlString); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + + int responseCode = conn.getResponseCode(); + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String inputLine; + StringBuilder content = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + + in.close(); + conn.disconnect(); + + JSONObject jsonobj = new JSONObject(content.toString()); + if (jsonobj.has("errorMessage")) { + // couldn't find a profile with this name + return null; + } + return jsonobj.getString("id"); + } catch (Exception e) { + // probably network error. nothing we can do. + // unlikely to happen realistically though + return null; + } + } + + public boolean NoteAdd(CommandSender sender, String[] args, String type) { if (!sender.hasPermission("simplenotes.addnotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); - return true; + return false; + } + if (args.length == 1) { + sender.sendMessage("Please provide a player name."); + return false; + } + String requestSubject = args[1]; + Object subjectUUID = this.getUUIDFromName(requestSubject); + if (subjectUUID == null) { + sender.sendMessage("Player doesn't exist."); + return false; + } + + String filename = plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"; + + File dataFile = new File(filename); + if (!this.CheckFileExists(dataFile)) { + try { + dataFile.createNewFile(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + } + dataFile.delete(); + + // the following is copied from opencsv's documentation + CSVReader reader = null; + try { + reader = new CSVReaderBuilder(new FileReader(filename)).build(); + } catch (FileNotFoundException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + String [] nextLine; + while (true) { + try { + if ((nextLine = reader.readNext()) == null) { + break; + } + } catch (IOException e) { + throw new RuntimeException(e); + } catch (CsvValidationException e) { + throw new RuntimeException(e); + } } - return false; + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + if (nextLine == null) { + nextLine[0] = "0"; + } + Integer id = Integer.valueOf(nextLine[0])+1; // we use the last ID + 1 + String id_str = id.toString(); + type = type.substring(0,3); + char separator = '°'; + String author; + if (sender instanceof Player) { + author = sender.getName(); + } else { + author = "CONSOLE"; + } + try { + CSVWriter writer = new CSVWriter(new FileWriter(filename), + separator, + '\"', + CSVWriter.DEFAULT_ESCAPE_CHARACTER, + CSVWriter.DEFAULT_LINE_END); + writer.writeNext(new String[] {id_str, type, author, String.join(" ", Arrays.copyOfRange(args, 2, args.length))}); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + return true; } public boolean NoteRemove(CommandSender sender, String[] args) { if (!sender.hasPermission("simplenotes.removenotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); - return true; + return false; + } + if (args.length <= 1) { + sender.sendMessage("Please provide a player name and an id."); + return false; + } + String requestSubject = args[0]; + Object subjectUUID = this.getUUIDFromName(requestSubject); + if (subjectUUID == null) { + sender.sendMessage("Player doesn't exist."); + return false; } - return false; + File dataFile = new File(plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"); + if (!this.CheckFileExists(dataFile)) { + try { + dataFile.createNewFile(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); + return false; + } + } + + return true; } public boolean NoteList(CommandSender sender, String[] args) { - return false; + String RequestSubject; + if (args.length == 1) { + if (!(sender instanceof Player)) { + sender.sendMessage("You need to provide a player name when running this in the console."); + return false; + } + RequestSubject = sender.getName(); + } + else RequestSubject = args[1]; + if (RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.self.notes") && !sender.hasPermission("simplenotes.see.self.warns") && !sender.isOp()) { + sender.sendMessage("You do not have permission to check your own notes/warns."); + return false; + } + if (!RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.others.notes") && !sender.hasPermission("simplenotes.see.others.warns") && !sender.isOp()) { + sender.sendMessage("You do not have permission to check other people's notes/warns."); + return false; + } + + OfflinePlayer subject = getPlayer(RequestSubject); + Object uuid = this.getUUIDFromName(RequestSubject); + if (uuid == null) { + sender.sendMessage("Player doesn't exist."); + return false; + } + + String playerDataFolder = plugin.getDataFolder().getAbsolutePath()+File.separator+"data"; + return true; } public boolean NoteHelp(CommandSender sender) { - return false; + return true; } @Override @@ -51,7 +248,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St sender.sendMessage("This command is currently disabled."); return true; } - // todo: logic to call the different functions above - return true; + if (args.length == 0 || args[0] == "help" ) { + return this.NoteHelp(sender); + } else if (args[0] == "add") { + // label is needed because of the differentiation between notes and warnings + return this.NoteAdd(sender, args, label); + } else if (args[0] == "remove") { + return this.NoteRemove(sender, args); + } else if (args[0] == "list") { + return this.NoteList(sender, args); + } else { + sender.sendMessage("Unrecognized argument."); + return this.NoteHelp(sender); + } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c977273..6cca72c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,7 +9,7 @@ softdepend: commands: notecommand: - description: The main command of the plugin. /note help for more details. + description: Add, remove or see notes or warnings. /note help for more details. usage: /note [args] aliases: [notes, warn, warns, warning, warnings] From d8a51cd38bc48ab87010c9b4aa06774f9c980447 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 15 May 2025 23:54:13 +0200 Subject: [PATCH 12/27] add changelog (so that it's done for later) --- changelogs/1.0.0.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/1.0.0.md diff --git a/changelogs/1.0.0.md b/changelogs/1.0.0.md new file mode 100644 index 0000000..1936fc8 --- /dev/null +++ b/changelogs/1.0.0.md @@ -0,0 +1,3 @@ +First release. + +Adds /note add, /warn add, /note remove, /note list and /note help. \ No newline at end of file From 8cab8d4b6f2877351edd5af8b4a85897218eeea3 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 15 May 2025 23:57:09 +0200 Subject: [PATCH 13/27] removing useless imports --- src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java | 8 -------- .../org/eleanorsilly/mc/notes/commands/NoteCommand.java | 1 - 2 files changed, 9 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java index 38bb88a..0bb2145 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java @@ -1,19 +1,11 @@ package org.eleanorsilly.mc.notes; -import org.apache.commons.lang3.StringEscapeUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.eleanorsilly.mc.notes.commands.NoteCommand; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index 5564ed3..b720462 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -3,7 +3,6 @@ import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVWriter; -import com.opencsv.CSVWriterBuilder; import com.opencsv.exceptions.CsvValidationException; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; From 7f34670176fb8b1c9ddfad77f74e315ca9c765d4 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Tue, 20 May 2025 19:35:21 +0200 Subject: [PATCH 14/27] fix permission desc and add supported platforms --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2780714..efbf82b 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. This plugin currently assumes all players are paid accounts. Adding offline players isn't planned for now. + +Tested with Project Poseidon. Plain Bukkit should work since this project doesn't use any of Poseidon's APIs. + ## Commands The plugin uses one command, /note (with aliases /notes, /warn, /warns, /warning and /warnings). @@ -12,11 +15,11 @@ The plugin uses one command, /note (with aliases /notes, /warn, /warns, /warning ### Subcommands - /note help: list the subcommands you have access to -- /note list: list your own notes/warnings (permission: simplenotes.see.self.notes/warnings) -- /note list [player]: list other player's notes/warnings (permission: simplenotes.see.others.notes/warnings) +- /note list: list your own notes/warnings (permission: simplenotes.see.self.notes/warns) +- /note list [player]: list another player's notes/warnings (permission: simplenotes.see.others.notes/warns) - /note add [player] [content]: add a note to a player (permission: simplenotes.addnotes) - /warn add [player] [content]: add a warn to a player (permission: simplenotes.addnotes) - - This is the only case where the alias matter. You can use any of the warn* aliases for this. + - This is the only case where the alias matter. You can use any of the warn* aliases for this. - /note remove [player] [id]: remove a note from a player (permission: simplenotes.removenotes) ## Compiling From 7b90e5cf98e9bf31b65761eb91aa0d8723ca7be5 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 24 May 2025 01:21:25 +0200 Subject: [PATCH 15/27] ok, this should be a working version (haha kidding theres probably dozens of bugs) --- .../{TemplateConfig.java => NoteConfig.java} | 30 +-- .../eleanorsilly/mc/notes/NoteListener.java | 27 ++ .../org/eleanorsilly/mc/notes/NotePlugin.java | 11 +- .../mc/notes/TemplateListener.java | 14 - .../mc/notes/commands/NoteCommand.java | 246 +++++++++++++++--- 5 files changed, 255 insertions(+), 73 deletions(-) rename src/main/java/org/eleanorsilly/mc/notes/{TemplateConfig.java => NoteConfig.java} (73%) create mode 100644 src/main/java/org/eleanorsilly/mc/notes/NoteListener.java delete mode 100644 src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java similarity index 73% rename from src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java rename to src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java index d8f3e07..0afa807 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateConfig.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java @@ -9,19 +9,18 @@ * Extends the {@link Configuration} class to provide additional utility methods for * reading and writing configuration options with defaults. */ -public class TemplateConfig extends Configuration { - private final int configVersion = 1; - +public class NoteConfig extends Configuration { + private final int configVersion = 0; private NotePlugin plugin; /** - * Constructs a new TemplateConfig instance. + * Constructs a new NoteConfig instance. * * @param plugin The plugin instance associated with this configuration. * @param configFile The configuration file to be managed. */ - public TemplateConfig(NotePlugin plugin, File configFile) { + public NoteConfig(NotePlugin plugin, File configFile) { super(configFile); this.plugin = plugin; this.reload(); @@ -43,24 +42,21 @@ private void write() { generateConfigOption("config-version", configVersion); // Plugin options - generateConfigOption("settings.test-command.enabled.value", true); - generateConfigOption("settings.test-command.enabled.info", "Whether the test command is enabled."); // Informational comment + generateConfigOption("settings.plugin.enabled.value", true); + generateConfigOption("settings.plugin.enabled.info", "Whether the test command is enabled."); + + generateConfigOption("settings.warns.showonlogin.value", true); + generateConfigOption("settings.warns.showonlogin.info", "Whether one's warns should be shown on login. Requires simplenotes.see.self.warns."); - generateConfigOption("settings.test-command.response.value", "This is the response sent to players when they execute the test command."); - generateConfigOption("settings.test-command.response.info", "The response sent to players when they execute the test command."); // Informational comment - generateConfigOption("settings.welcome-message.value", "Welcome to the server, %player%!"); - generateConfigOption("settings.welcome-message.info", "The message sent to players when join the server."); // Informational comment + generateConfigOption("settings.notes.showonlogin.value", false); + generateConfigOption("settings.notes.showonlogin.info", "Whether one's notes should be shown on login. Requires simplenotes.see.self.notes."); } private void convertToNewConfig() { // Convert old configuration keys to new keys - - // Convert from old config version 0 to new config version 1 - if(this.getString("config-version") == null || Integer.valueOf(this.getString("config-version")) < 1) { - convertToNewAddress("settings.test-command-response.value", "settings.test-command.response.value", true); - convertToNewAddress("settings.test-command.enabled", "settings.test-command.enabled.value", true); - } + // Currently unused + ; } /** diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java new file mode 100644 index 0000000..ecb4740 --- /dev/null +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java @@ -0,0 +1,27 @@ +package org.eleanorsilly.mc.notes; + +import org.bukkit.Note; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.eleanorsilly.mc.notes.commands.NoteCommand; + +public class NoteListener implements Listener { + private NotePlugin plugin; + private NoteConfig config; + + // Constructor to link the plugin instance + public NoteListener(NotePlugin plugin) { + this.plugin = plugin; + this.config = plugin.getConfig(); + } + + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + NoteCommand commands = new NoteCommand(plugin); + if (!player.hasPermission("simplenotes.see.self.warns") || config.getConfigBoolean("")) { + return; + } + boolean b = commands.NoteList(player, new String[] {""}, true); + } +} diff --git a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java index 0bb2145..6f94142 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java @@ -1,6 +1,7 @@ package org.eleanorsilly.mc.notes; import org.bukkit.Bukkit; +import org.bukkit.event.Event; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.eleanorsilly.mc.notes.commands.NoteCommand; @@ -15,7 +16,7 @@ public class NotePlugin extends JavaPlugin { private String pluginName; private PluginDescriptionFile pdf; - private TemplateConfig configuration; + private NoteConfig configuration; @Override public void onEnable() { @@ -26,14 +27,14 @@ public void onEnable() { log.info("[" + pluginName + "] is loading, version: " + pdf.getVersion()); // Load configuration - configuration = new TemplateConfig(this, new File(getDataFolder(), "config.yml")); // Load the configuration file from the plugin's data folder + configuration = new NoteConfig(this, new File(getDataFolder(), "config.yml")); // Load the configuration file from the plugin's data folder // Register the command and the aliases getCommand("note").setExecutor(new NoteCommand(this)); // Register the listeners - TemplateListener listener = new TemplateListener(this); - getServer().getPluginManager().registerEvents(listener, this); + NoteListener listener = new NoteListener(this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, listener, Event.Priority.Monitor, this); log.info("[" + pluginName + "] Plugin loaded!"); } @@ -50,7 +51,7 @@ public void logger(Level level, String message) { Bukkit.getLogger().log(level, "[" + plugin.getDescription().getName() + "] " + message); } - public TemplateConfig getConfig() { + public NoteConfig getConfig() { return configuration; } } diff --git a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java b/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java deleted file mode 100644 index 0500ddf..0000000 --- a/src/main/java/org/eleanorsilly/mc/notes/TemplateListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.eleanorsilly.mc.notes; - -import org.bukkit.event.Listener; - -public class TemplateListener implements Listener { - private NotePlugin plugin; - private TemplateConfig config; - - // Constructor to link the plugin instance - public TemplateListener(NotePlugin plugin) { - this.plugin = plugin; - this.config = plugin.getConfig(); - } -} diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index b720462..0f6f646 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -3,29 +3,32 @@ import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVWriter; +import com.opencsv.exceptions.CsvException; import com.opencsv.exceptions.CsvValidationException; -import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.eleanorsilly.mc.notes.TemplateConfig; +import org.eleanorsilly.mc.notes.NoteConfig; import org.eleanorsilly.mc.notes.NotePlugin; import org.json.JSONObject; import java.io.*; import java.net.HttpURLConnection; +import java.net.URI; import java.net.URL; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; - -import static org.bukkit.Bukkit.getPlayer; +import java.util.Objects; public class NoteCommand implements CommandExecutor { private final NotePlugin plugin; - private final TemplateConfig config; + private final NoteConfig config; public NoteCommand(NotePlugin plugin) { this.plugin = plugin; @@ -44,7 +47,10 @@ public boolean CheckFileExists(File file) { for (int i = parentList.size()-1; i > -1; i--) { // create all parents, going through the list in reverse try { - parentList.get(i).mkdirs(); + boolean b = parentList.get(i).mkdirs(); + if (!b) { + throw new RuntimeException(); + } } catch (Exception e) { // probably a permission issue, failed to create the dirs return false; @@ -58,7 +64,7 @@ public boolean CheckFileExists(File file) { public Object getUUIDFromName(String playerName) { try { String urlString = "https://api.mojang.com/users/profiles/minecraft/" + playerName; - URL url = new URL(urlString); + URL url = URI.create(urlString).toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); @@ -88,6 +94,7 @@ public Object getUUIDFromName(String playerName) { } public boolean NoteAdd(CommandSender sender, String[] args, String type) { + // done. not checked for bugs if (!sender.hasPermission("simplenotes.addnotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); return false; @@ -102,9 +109,9 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { sender.sendMessage("Player doesn't exist."); return false; } + subjectUUID = subjectUUID.toString(); String filename = plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"; - File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { try { @@ -116,7 +123,6 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { return false; } } - dataFile.delete(); // the following is copied from opencsv's documentation CSVReader reader = null; @@ -129,13 +135,18 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { return false; } String [] nextLine; + int i = 0; while (true) { try { + i = i + 1; if ((nextLine = reader.readNext()) == null) { break; } } catch (IOException e) { - throw new RuntimeException(e); + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; } catch (CsvValidationException e) { throw new RuntimeException(e); } @@ -143,15 +154,19 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { try { reader.close(); } catch (IOException e) { - throw new RuntimeException(e); + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; } - if (nextLine == null) { - nextLine[0] = "0"; - } - Integer id = Integer.valueOf(nextLine[0])+1; // we use the last ID + 1 + Integer id = i+1; // we use the last ID + 1 String id_str = id.toString(); - type = type.substring(0,3); + type = type.substring(0,3).toUpperCase(); // we keep the first 4 char, so that we have note or warn + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + String dateStr = dateFormat.format(date); + char separator = '°'; String author; if (sender instanceof Player) { @@ -165,17 +180,20 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { '\"', CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); - writer.writeNext(new String[] {id_str, type, author, String.join(" ", Arrays.copyOfRange(args, 2, args.length))}); + writer.writeNext(new String[] {id_str, type, dateStr, author, String.join(" ", Arrays.copyOfRange(args, 2, args.length))}); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } + // success! + sender.sendMessage(type.substring(0, 1).toUpperCase() + type.substring(1)+" added."); return true; } public boolean NoteRemove(CommandSender sender, String[] args) { + // done. not checked for bugs if (!sender.hasPermission("simplenotes.removenotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); return false; @@ -190,21 +208,92 @@ public boolean NoteRemove(CommandSender sender, String[] args) { sender.sendMessage("Player doesn't exist."); return false; } - File dataFile = new File(plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"); + subjectUUID = subjectUUID.toString(); + String filename = "plugin.getDataFolder()"+File.separator+"data"+File.separator+subjectUUID+".csv"; + File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { - try { - dataFile.createNewFile(); - } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); - return false; + // we do not try to create the file, since if it doesn't exist, the warn/note doesn't exist either + sender.sendMessage("Note/warn not found."); + return false; + } + + CSVReader reader = null; + try { + reader = new CSVReader(new FileReader(dataFile)); + } catch (FileNotFoundException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + List allElements = null; + try { + allElements = reader.readAll(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } catch (CsvException e) { + throw new RuntimeException(e); + } + try { + reader.close(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + try { + // we delete the file, since we recreate the contents entirely later. + dataFile.delete(); + dataFile.createNewFile(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + int rowNumber = -1; + for (int i = 0; i < allElements.size(); i++) { + // we iterate through the list, and check the id of each row + if (Integer.parseInt(allElements.get(i)[0]) == Integer.parseInt(args[2])) { + rowNumber = i; + break; } } + if (rowNumber == -1) { + sender.sendMessage("Note/warn not found."); + return false; + } + allElements.remove(rowNumber); + FileWriter sw = null; + try { + sw = new FileWriter(dataFile); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + CSVWriter writer = new CSVWriter(sw); + writer.writeAll(allElements); + try { + writer.close(); + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + // success! + sender.sendMessage("Note/warn removed."); return true; } - public boolean NoteList(CommandSender sender, String[] args) { + public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErrorMessage) { String RequestSubject; if (args.length == 1) { if (!(sender instanceof Player)) { @@ -215,46 +304,129 @@ public boolean NoteList(CommandSender sender, String[] args) { } else RequestSubject = args[1]; if (RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.self.notes") && !sender.hasPermission("simplenotes.see.self.warns") && !sender.isOp()) { - sender.sendMessage("You do not have permission to check your own notes/warns."); + if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check your own notes/warns."); return false; } if (!RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.others.notes") && !sender.hasPermission("simplenotes.see.others.warns") && !sender.isOp()) { - sender.sendMessage("You do not have permission to check other people's notes/warns."); + if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check other people's notes/warns."); return false; } - OfflinePlayer subject = getPlayer(RequestSubject); - Object uuid = this.getUUIDFromName(RequestSubject); - if (uuid == null) { - sender.sendMessage("Player doesn't exist."); + Object subjectUUID = this.getUUIDFromName(RequestSubject); + if (subjectUUID == null) { + if (!dontShowErrorMessage) sender.sendMessage("Player doesn't exist."); + return false; + } + subjectUUID = subjectUUID.toString(); + + String filename = plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"; + File dataFile = new File(filename); + if (!this.CheckFileExists(dataFile)) { + // we do not try to create the file, since if it doesn't exist, there are no warns/notes + if (!dontShowErrorMessage) sender.sendMessage("No notes or warns to show."); + return false; + } + + CSVReader reader = null; + try { + reader = new CSVReader(new FileReader(dataFile)); + } catch (FileNotFoundException e) { + if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } + List allElements = null; + try { + allElements = reader.readAll(); + } catch (IOException e) { + if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } catch (CsvException e) { + throw new RuntimeException(e); + } + try { + reader.close(); + } catch (IOException e) { + if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } - String playerDataFolder = plugin.getDataFolder().getAbsolutePath()+File.separator+"data"; + int shownCounter = 0; + for (int i = 0; i < allElements.size(); i++) { + if (!RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.others.notes") && Objects.equals(allElements.get(i)[1], "NOTE")) { + shownCounter = shownCounter + 1; + sender.sendMessage("| "+String.join(" | ", allElements.get(i))); + } else if (RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.self.notes") && Objects.equals(allElements.get(i)[1], "NOTE")) { + shownCounter = shownCounter + 1; + sender.sendMessage("| "+String.join(" | ", allElements.get(i))); + } else if (!RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.others.warns") && Objects.equals(allElements.get(i)[1], "WARN")) { + shownCounter = shownCounter + 1; + sender.sendMessage("| "+String.join(" | ", allElements.get(i))); + } else if (RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.self.warns") && Objects.equals(allElements.get(i)[1], "WARN")) { + shownCounter = shownCounter + 1; + sender.sendMessage("| "+String.join(" | ", allElements.get(i))); + } + } + if (shownCounter == 1) { + sender.sendMessage("No notes or warnings to show."); + } return true; } + // the following should be used in all cases. + // the only reason we have dontShowErrorMessage is because of the NoteListener + public boolean NoteList(CommandSender sender, String[] args) { + return NoteList(sender, args, false); + } + public boolean NoteHelp(CommandSender sender) { + int removedCommands = 0; + sender.sendMessage("=== Command list ==="); + sender.sendMessage("- /note help: show this"); + if (sender.hasPermission("simplenotes.see.self.notes") || sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) { + sender.sendMessage("- /note list: show your notes"); + removedCommands = removedCommands + 1; + } + if (sender.hasPermission("simplenotes.see.others.notes") || sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) { + sender.sendMessage("- /note list : show another player's notes"); + removedCommands = removedCommands + 1; + } + if (sender.hasPermission("simplenotes.addnotes") || sender.isOp()) { + sender.sendMessage("- /note add : add a note"); + removedCommands = removedCommands + 1; + } + if (sender.hasPermission("simplenotes.removenotes") || sender.isOp()) { + sender.sendMessage("- /note remove : remove a note (you can get the id via /note list!)"); + removedCommands = removedCommands + 1; + } + if (removedCommands > 0) { + sender.sendMessage("You do not have access to any other subcommand."); + } return true; } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // Check if the command is enabled Boolean isEnabled = config.getConfigBoolean("settings.test-command.enabled.value"); if (!isEnabled) { sender.sendMessage("This command is currently disabled."); return true; } - if (args.length == 0 || args[0] == "help" ) { + // objects.equals is used to shut the IDE. it's not gonna be null let's be realistic. + if (args.length == 0 || Objects.equals(args[0], "help")) { return this.NoteHelp(sender); - } else if (args[0] == "add") { + } else if (Objects.equals(args[0], "add")) { // label is needed because of the differentiation between notes and warnings return this.NoteAdd(sender, args, label); - } else if (args[0] == "remove") { + } else if (Objects.equals(args[0], "remove")) { return this.NoteRemove(sender, args); - } else if (args[0] == "list") { + } else if (Objects.equals(args[0], "list")) { return this.NoteList(sender, args); } else { sender.sendMessage("Unrecognized argument."); From 77dc95e1e692d26d65a728eba81a2e1a216f9728 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 24 May 2025 10:58:13 +0200 Subject: [PATCH 16/27] version that starts (and add shading) --- pom.xml | 18 +++++++++++++----- .../eleanorsilly/mc/notes/NoteListener.java | 1 - src/main/resources/plugin.yml | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index a91a944..f6a66ed 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,19 @@ 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 3.6.0 + + + package + + shade + + + + @@ -66,11 +79,6 @@ poseidon-craftbukkit 1.1.10-250328-1731-f67a8e3 - - org.apache.commons - commons-text - 1.13.1 - org.json json diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java index ecb4740..5fdb60d 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java @@ -1,6 +1,5 @@ package org.eleanorsilly.mc.notes; -import org.bukkit.Note; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6cca72c..eaf5367 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ${project.name} description: ${project.description} -main: org.eleanorsilly.mc.notes +main: org.eleanorsilly.mc.notes.NotePlugin version: ${project.version} authors: - eleanorsilly @@ -8,7 +8,7 @@ softdepend: - Essentials commands: - notecommand: + note: description: Add, remove or see notes or warnings. /note help for more details. usage: /note [args] aliases: [notes, warn, warns, warning, warnings] From f901938212ff3f18dc821b0c00d150797944fb32 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Sat, 24 May 2025 11:26:21 +0200 Subject: [PATCH 17/27] version that works (apart from player join listener) + better shading --- pom.xml | 9 + .../eleanorsilly/mc/notes/NoteListener.java | 5 +- .../mc/notes/commands/NoteCommand.java | 182 +++++++++++------- src/main/resources/plugin.yml | 4 +- 4 files changed, 122 insertions(+), 78 deletions(-) diff --git a/pom.xml b/pom.xml index f6a66ed..8747a22 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,14 @@ org.apache.maven.plugins maven-shade-plugin 3.6.0 + + + + com.opencsv:opencsv + org.json:json + + + package @@ -78,6 +86,7 @@ com.legacyminecraft.poseidon poseidon-craftbukkit 1.1.10-250328-1731-f67a8e3 + provided org.json diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java index 5fdb60d..d096a11 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java @@ -1,11 +1,11 @@ package org.eleanorsilly.mc.notes; import org.bukkit.entity.Player; -import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; import org.eleanorsilly.mc.notes.commands.NoteCommand; -public class NoteListener implements Listener { +public class NoteListener extends PlayerListener { private NotePlugin plugin; private NoteConfig config; @@ -15,6 +15,7 @@ public NoteListener(NotePlugin plugin) { this.config = plugin.getConfig(); } + @Override public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); NoteCommand commands = new NoteCommand(plugin); diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index 0f6f646..4ff5181 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -1,5 +1,6 @@ package org.eleanorsilly.mc.notes.commands; +import com.opencsv.CSVParserBuilder; import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVWriter; @@ -19,10 +20,7 @@ import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; public class NoteCommand implements CommandExecutor { @@ -40,8 +38,9 @@ public boolean CheckFileExists(File file) { return true; } else { // we create the folders above - List parentList = Arrays.asList(file.getParentFile()); - while (parentList.get(parentList.size() - 1).exists()) { + List parentListInit = Arrays.asList(file.getParentFile()); + List parentList = new ArrayList(parentListInit); + while (parentList.get(parentList.size() - 1).getParentFile() != null) { parentList.add(parentList.get(parentList.size() - 1).getParentFile()); } for (int i = parentList.size()-1; i > -1; i--) { @@ -94,7 +93,6 @@ public Object getUUIDFromName(String playerName) { } public boolean NoteAdd(CommandSender sender, String[] args, String type) { - // done. not checked for bugs if (!sender.hasPermission("simplenotes.addnotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); return false; @@ -115,7 +113,9 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { try { - dataFile.createNewFile(); + if (!dataFile.createNewFile()) { + throw new IOException("this didn't work"); + } } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); @@ -135,21 +135,22 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { return false; } String [] nextLine; - int i = 0; - while (true) { - try { - i = i + 1; - if ((nextLine = reader.readNext()) == null) { + int i = 1; + try { + while (true) { + if ((nextLine = reader.readNext()) != null) { + i = Integer.parseInt(nextLine[0]) + 1; + } else { break; } - } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); - return false; - } catch (CsvValidationException e) { - throw new RuntimeException(e); } + } catch (IOException e) { + sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + return false; + } catch (CsvValidationException e) { + throw new RuntimeException(e); } try { reader.close(); @@ -160,14 +161,14 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { return false; } - Integer id = i+1; // we use the last ID + 1 + Integer id = i; // we use the last ID + 1 String id_str = id.toString(); - type = type.substring(0,3).toUpperCase(); // we keep the first 4 char, so that we have note or warn + type = type.substring(0,4).toUpperCase(); // we keep the first 4 char, so that we have note or warn + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); String dateStr = dateFormat.format(date); - char separator = '°'; String author; if (sender instanceof Player) { author = sender.getName(); @@ -175,12 +176,22 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { author = "CONSOLE"; } try { - CSVWriter writer = new CSVWriter(new FileWriter(filename), - separator, + CSVWriter writer = new CSVWriter(new FileWriter(filename, true), + CSVWriter.DEFAULT_SEPARATOR, '\"', CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); - writer.writeNext(new String[] {id_str, type, dateStr, author, String.join(" ", Arrays.copyOfRange(args, 2, args.length))}); + String[] line = { + id_str, + type, + dateStr, + author, + String.join(" ", + Arrays.copyOfRange(args, 2, args.length) + ) + }; + writer.writeNext(line, true); + writer.close(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); @@ -188,28 +199,29 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { return false; } // success! - sender.sendMessage(type.substring(0, 1).toUpperCase() + type.substring(1)+" added."); + sender.sendMessage(type.charAt(0) + type.substring(1).toLowerCase()+" added."); return true; } public boolean NoteRemove(CommandSender sender, String[] args) { - // done. not checked for bugs if (!sender.hasPermission("simplenotes.removenotes") && !sender.isOp()) { sender.sendMessage("You do not have permission to use this subcommand."); return false; } - if (args.length <= 1) { + if (args.length <= 2) { sender.sendMessage("Please provide a player name and an id."); - return false; + return true; } - String requestSubject = args[0]; + + String requestSubject = args[1]; Object subjectUUID = this.getUUIDFromName(requestSubject); if (subjectUUID == null) { sender.sendMessage("Player doesn't exist."); - return false; + return true; } subjectUUID = subjectUUID.toString(); - String filename = "plugin.getDataFolder()"+File.separator+"data"+File.separator+subjectUUID+".csv"; + + String filename = plugin.getDataFolder()+File.separator+"data"+File.separator+subjectUUID+".csv"; File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { // we do not try to create the file, since if it doesn't exist, the warn/note doesn't exist either @@ -217,9 +229,12 @@ public boolean NoteRemove(CommandSender sender, String[] args) { return false; } + // We dump the entire CSV file into allElements CSVReader reader = null; try { - reader = new CSVReader(new FileReader(dataFile)); + reader = new CSVReaderBuilder(new FileReader(filename)) + .withCSVParser(new CSVParserBuilder().build()) + .build(); } catch (FileNotFoundException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); @@ -245,10 +260,19 @@ public boolean NoteRemove(CommandSender sender, String[] args) { System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } + + /* + we delete the file, since we recreate the contents entirely later. + this is the recommended way to remove a specific line in a CSV file + */ try { - // we delete the file, since we recreate the contents entirely later. - dataFile.delete(); - dataFile.createNewFile(); + if (!dataFile.delete() || !dataFile.createNewFile()) { + // something went wrong. we do not do data loss here + // so everything is printed to console + System.out.println("Content of "+filename+":"); + System.out.println(allElements); + throw new IOException("this didn't work"); + } } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); @@ -269,16 +293,19 @@ public boolean NoteRemove(CommandSender sender, String[] args) { } allElements.remove(rowNumber); - FileWriter sw = null; + CSVWriter writer = null; try { - sw = new FileWriter(dataFile); + writer = new CSVWriter(new FileWriter(filename), + CSVWriter.DEFAULT_SEPARATOR, + '\"', + CSVWriter.DEFAULT_ESCAPE_CHARACTER, + CSVWriter.DEFAULT_LINE_END); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } - CSVWriter writer = new CSVWriter(sw); writer.writeAll(allElements); try { writer.close(); @@ -298,24 +325,24 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr if (args.length == 1) { if (!(sender instanceof Player)) { sender.sendMessage("You need to provide a player name when running this in the console."); - return false; + return true; } RequestSubject = sender.getName(); } else RequestSubject = args[1]; if (RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.self.notes") && !sender.hasPermission("simplenotes.see.self.warns") && !sender.isOp()) { if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check your own notes/warns."); - return false; + return true; } if (!RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.others.notes") && !sender.hasPermission("simplenotes.see.others.warns") && !sender.isOp()) { if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check other people's notes/warns."); - return false; + return true; } Object subjectUUID = this.getUUIDFromName(RequestSubject); if (subjectUUID == null) { if (!dontShowErrorMessage) sender.sendMessage("Player doesn't exist."); - return false; + return true; } subjectUUID = subjectUUID.toString(); @@ -324,12 +351,14 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr if (!this.CheckFileExists(dataFile)) { // we do not try to create the file, since if it doesn't exist, there are no warns/notes if (!dontShowErrorMessage) sender.sendMessage("No notes or warns to show."); - return false; + return true; } CSVReader reader = null; try { - reader = new CSVReader(new FileReader(dataFile)); + reader = new CSVReaderBuilder(new FileReader(filename)) + .withCSVParser(new CSVParserBuilder().build()) + .build(); } catch (FileNotFoundException e) { if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); @@ -357,23 +386,24 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr } int shownCounter = 0; - for (int i = 0; i < allElements.size(); i++) { - if (!RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.others.notes") && Objects.equals(allElements.get(i)[1], "NOTE")) { + System.out.println(Arrays.toString(allElements.get(0))); + for (String[] line : allElements) { + if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE")) { shownCounter = shownCounter + 1; - sender.sendMessage("| "+String.join(" | ", allElements.get(i))); - } else if (RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.self.notes") && Objects.equals(allElements.get(i)[1], "NOTE")) { + sender.sendMessage("| " + String.join(" | ", line)); + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE")) { shownCounter = shownCounter + 1; - sender.sendMessage("| "+String.join(" | ", allElements.get(i))); - } else if (!RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.others.warns") && Objects.equals(allElements.get(i)[1], "WARN")) { + sender.sendMessage("| " + String.join(" | ", line)); + } else if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) && Objects.equals(line[1], "WARN")) { shownCounter = shownCounter + 1; - sender.sendMessage("| "+String.join(" | ", allElements.get(i))); - } else if (RequestSubject.equals(sender.getName()) && sender.hasPermission("simplenotes.see.self.warns") && Objects.equals(allElements.get(i)[1], "WARN")) { + sender.sendMessage("| " + String.join(" | ", line)); + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) && Objects.equals(line[1], "WARN")) { shownCounter = shownCounter + 1; - sender.sendMessage("| "+String.join(" | ", allElements.get(i))); + sender.sendMessage("| " + String.join(" | ", line)); } } - if (shownCounter == 1) { - sender.sendMessage("No notes or warnings to show."); + if (shownCounter == 0) { + sender.sendMessage("No notes or warns to show."); } return true; } @@ -384,25 +414,31 @@ public boolean NoteList(CommandSender sender, String[] args) { return NoteList(sender, args, false); } - public boolean NoteHelp(CommandSender sender) { - int removedCommands = 0; + public boolean NoteHelp(CommandSender sender, String alias) { + int removedCommands = 4; sender.sendMessage("=== Command list ==="); - sender.sendMessage("- /note help: show this"); - if (sender.hasPermission("simplenotes.see.self.notes") || sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) { - sender.sendMessage("- /note list: show your notes"); - removedCommands = removedCommands + 1; + sender.sendMessage("- /"+alias+" help: show this"); + if ((sender.hasPermission("simplenotes.see.self.notes") && sender.hasPermission("simplenotes.see.self.warns")) || sender.isOp()) { + sender.sendMessage("- /"+alias+" list: show your notes/warns"); + removedCommands = removedCommands - 1; + } else if (sender.hasPermission("simplenotes.see.self.notes")) { + sender.sendMessage("- /"+alias+" list: show your notes"); + removedCommands = removedCommands - 1; + } else if (sender.hasPermission("simplenotes.see.self.warns")) { + sender.sendMessage("- /"+alias+" list: show your warns"); + removedCommands = removedCommands - 1; } if (sender.hasPermission("simplenotes.see.others.notes") || sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) { - sender.sendMessage("- /note list : show another player's notes"); - removedCommands = removedCommands + 1; + sender.sendMessage("- /"+alias+" list : show another player's notes"); + removedCommands = removedCommands - 1; } if (sender.hasPermission("simplenotes.addnotes") || sender.isOp()) { - sender.sendMessage("- /note add : add a note"); - removedCommands = removedCommands + 1; + sender.sendMessage("- /"+alias+" add : add a "+alias.substring(0, 4)); + removedCommands = removedCommands - 1; } if (sender.hasPermission("simplenotes.removenotes") || sender.isOp()) { - sender.sendMessage("- /note remove : remove a note (you can get the id via /note list!)"); - removedCommands = removedCommands + 1; + sender.sendMessage("- /"+alias+" remove : remove a note/warn (you can get the id via /"+alias+" list!)"); + removedCommands = removedCommands - 1; } if (removedCommands > 0) { sender.sendMessage("You do not have access to any other subcommand."); @@ -413,14 +449,14 @@ public boolean NoteHelp(CommandSender sender) { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { // Check if the command is enabled - Boolean isEnabled = config.getConfigBoolean("settings.test-command.enabled.value"); + Boolean isEnabled = config.getConfigBoolean("settings.plugin.enabled.value"); if (!isEnabled) { - sender.sendMessage("This command is currently disabled."); + sender.sendMessage("This command is currently disabled. Please check the config."); return true; } // objects.equals is used to shut the IDE. it's not gonna be null let's be realistic. if (args.length == 0 || Objects.equals(args[0], "help")) { - return this.NoteHelp(sender); + return this.NoteHelp(sender, label); } else if (Objects.equals(args[0], "add")) { // label is needed because of the differentiation between notes and warnings return this.NoteAdd(sender, args, label); @@ -430,7 +466,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return this.NoteList(sender, args); } else { sender.sendMessage("Unrecognized argument."); - return this.NoteHelp(sender); + return this.NoteHelp(sender, label); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index eaf5367..b521318 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,13 +4,11 @@ main: org.eleanorsilly.mc.notes.NotePlugin version: ${project.version} authors: - eleanorsilly -softdepend: - - Essentials commands: note: description: Add, remove or see notes or warnings. /note help for more details. - usage: /note [args] + usage: /note [subcommand] [player] [additional arguments] aliases: [notes, warn, warns, warning, warnings] permissions: From 3cc033539b31d01e74d9389d352125c09a2888a3 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Tue, 27 May 2025 23:29:41 +0200 Subject: [PATCH 18/27] (attempt to) fix listener and use proper logging --- .../org/eleanorsilly/mc/notes/NoteConfig.java | 7 +- .../eleanorsilly/mc/notes/NoteListener.java | 3 +- .../org/eleanorsilly/mc/notes/NotePlugin.java | 6 +- .../mc/notes/commands/NoteCommand.java | 84 +++++++++---------- 4 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java index 0afa807..37bf9f5 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java @@ -43,14 +43,13 @@ private void write() { // Plugin options generateConfigOption("settings.plugin.enabled.value", true); - generateConfigOption("settings.plugin.enabled.info", "Whether the test command is enabled."); + generateConfigOption("settings.plugin.enabled.info", "Whether the command is enabled."); generateConfigOption("settings.warns.showonlogin.value", true); - generateConfigOption("settings.warns.showonlogin.info", "Whether one's warns should be shown on login. Requires simplenotes.see.self.warns."); - + generateConfigOption("settings.warns.showonlogin.info", "Whether one's warns should be shown on login. Requires the player to have simplenotes.see.self.warns."); generateConfigOption("settings.notes.showonlogin.value", false); - generateConfigOption("settings.notes.showonlogin.info", "Whether one's notes should be shown on login. Requires simplenotes.see.self.notes."); + generateConfigOption("settings.notes.showonlogin.info", "Whether one's notes should be shown on login. Requires the player to have simplenotes.see.self.notes."); } private void convertToNewConfig() { diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java index d096a11..8fe0ab2 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java @@ -19,7 +19,8 @@ public NoteListener(NotePlugin plugin) { public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); NoteCommand commands = new NoteCommand(plugin); - if (!player.hasPermission("simplenotes.see.self.warns") || config.getConfigBoolean("")) { + if ((!player.hasPermission("simplenotes.see.self.warns") || !config.getConfigBoolean("settings.warns.showonlogin.value")) + && (!player.hasPermission("simplenotes.see.self.notes") || !config.getConfigBoolean("settings.notes.showonlogin.value"))) { return; } boolean b = commands.NoteList(player, new String[] {""}, true); diff --git a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java index 6f94142..4ba9d99 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java @@ -33,8 +33,10 @@ public void onEnable() { getCommand("note").setExecutor(new NoteCommand(this)); // Register the listeners - NoteListener listener = new NoteListener(this); - getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, listener, Event.Priority.Monitor, this); + if (configuration.getConfigBoolean("settings.warns.showonlogin.value") || configuration.getConfigBoolean("settings.notes.showonlogin.value")) { + NoteListener listener = new NoteListener(this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, listener, Event.Priority.Monitor, this); + } log.info("[" + pluginName + "] Plugin loaded!"); } diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index 4ff5181..ef37f72 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -21,6 +21,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.logging.Level; public class NoteCommand implements CommandExecutor { @@ -118,8 +119,8 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { } } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } } @@ -130,8 +131,8 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { reader = new CSVReaderBuilder(new FileReader(filename)).build(); } catch (FileNotFoundException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } String [] nextLine; @@ -146,8 +147,8 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { } } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } catch (CsvValidationException e) { throw new RuntimeException(e); @@ -156,8 +157,8 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { reader.close(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } @@ -194,8 +195,8 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { writer.close(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } // success! @@ -237,8 +238,8 @@ public boolean NoteRemove(CommandSender sender, String[] args) { .build(); } catch (FileNotFoundException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } List allElements = null; @@ -246,8 +247,8 @@ public boolean NoteRemove(CommandSender sender, String[] args) { allElements = reader.readAll(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } catch (CsvException e) { throw new RuntimeException(e); @@ -256,8 +257,8 @@ public boolean NoteRemove(CommandSender sender, String[] args) { reader.close(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } @@ -269,14 +270,14 @@ public boolean NoteRemove(CommandSender sender, String[] args) { if (!dataFile.delete() || !dataFile.createNewFile()) { // something went wrong. we do not do data loss here // so everything is printed to console - System.out.println("Content of "+filename+":"); - System.out.println(allElements); + this.plugin.logger(Level.INFO,"Content of "+filename+":"); + this.plugin.logger(Level.INFO,allElements.stream().map(Arrays::toString).reduce((a, b) -> a + "\n" + b).orElse("")); throw new IOException("this didn't work"); } } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } int rowNumber = -1; @@ -302,8 +303,8 @@ public boolean NoteRemove(CommandSender sender, String[] args) { CSVWriter.DEFAULT_LINE_END); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } writer.writeAll(allElements); @@ -311,8 +312,8 @@ public boolean NoteRemove(CommandSender sender, String[] args) { writer.close(); } catch (IOException e) { sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } // success! @@ -320,7 +321,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { return true; } - public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErrorMessage) { + public boolean NoteList(CommandSender sender, String[] args, boolean isListener) { String RequestSubject; if (args.length == 1) { if (!(sender instanceof Player)) { @@ -331,17 +332,17 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr } else RequestSubject = args[1]; if (RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.self.notes") && !sender.hasPermission("simplenotes.see.self.warns") && !sender.isOp()) { - if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check your own notes/warns."); + if (!isListener) sender.sendMessage("You do not have permission to check your own notes/warns."); return true; } if (!RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.others.notes") && !sender.hasPermission("simplenotes.see.others.warns") && !sender.isOp()) { - if (!dontShowErrorMessage) sender.sendMessage("You do not have permission to check other people's notes/warns."); + if (!isListener) sender.sendMessage("You do not have permission to check other people's notes/warns."); return true; } Object subjectUUID = this.getUUIDFromName(RequestSubject); if (subjectUUID == null) { - if (!dontShowErrorMessage) sender.sendMessage("Player doesn't exist."); + if (!isListener) sender.sendMessage("Player doesn't exist."); return true; } subjectUUID = subjectUUID.toString(); @@ -350,7 +351,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { // we do not try to create the file, since if it doesn't exist, there are no warns/notes - if (!dontShowErrorMessage) sender.sendMessage("No notes or warns to show."); + if (!isListener) sender.sendMessage("No notes or warns to show."); return true; } @@ -360,18 +361,18 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr .withCSVParser(new CSVParserBuilder().build()) .build(); } catch (FileNotFoundException e) { - if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } List allElements = null; try { allElements = reader.readAll(); } catch (IOException e) { - if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } catch (CsvException e) { throw new RuntimeException(e); @@ -379,25 +380,24 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr try { reader.close(); } catch (IOException e) { - if (!dontShowErrorMessage) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); - System.out.println("["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); - System.out.println("["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); + if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); + this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; } int shownCounter = 0; - System.out.println(Arrays.toString(allElements.get(0))); for (String[] line : allElements) { if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE")) { shownCounter = shownCounter + 1; sender.sendMessage("| " + String.join(" | ", line)); - } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE")) { + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE") && (!isListener || config.getConfigBoolean("settings.notes.showonlogin.value"))) { shownCounter = shownCounter + 1; sender.sendMessage("| " + String.join(" | ", line)); } else if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) && Objects.equals(line[1], "WARN")) { shownCounter = shownCounter + 1; sender.sendMessage("| " + String.join(" | ", line)); - } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) && Objects.equals(line[1], "WARN")) { + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) && Objects.equals(line[1], "WARN") && (!isListener || config.getConfigBoolean("settings.warns.showonlogin.value"))) { shownCounter = shownCounter + 1; sender.sendMessage("| " + String.join(" | ", line)); } @@ -409,7 +409,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean dontShowErr } // the following should be used in all cases. - // the only reason we have dontShowErrorMessage is because of the NoteListener + // the only reason we have isListener is because of the NoteListener public boolean NoteList(CommandSender sender, String[] args) { return NoteList(sender, args, false); } From 5fd870eee7a6183f144602193ad45f78ec7a86b6 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Tue, 27 May 2025 23:47:43 +0200 Subject: [PATCH 19/27] add caching for UUIDs and optimize slightly CheckFileExists --- pom.xml | 6 ++ .../mc/notes/commands/NoteCommand.java | 64 +++++++++++-------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 8747a22..2645d30 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,7 @@ com.opencsv:opencsv org.json:json + com.google.guava:guava @@ -98,5 +99,10 @@ opencsv 5.11 + + com.google.guava + guava + 33.4.8-jre + diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index ef37f72..d0a0b37 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -13,6 +13,8 @@ import org.eleanorsilly.mc.notes.NoteConfig; import org.eleanorsilly.mc.notes.NotePlugin; import org.json.JSONObject; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import java.io.*; import java.net.HttpURLConnection; @@ -22,6 +24,8 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.logging.Level; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; public class NoteCommand implements CommandExecutor { @@ -41,7 +45,7 @@ public boolean CheckFileExists(File file) { // we create the folders above List parentListInit = Arrays.asList(file.getParentFile()); List parentList = new ArrayList(parentListInit); - while (parentList.get(parentList.size() - 1).getParentFile() != null) { + while (parentList.get(parentList.size() - 1).getParentFile() != null && !parentList.get(parentList.size() - 1).getParentFile().exists()) { parentList.add(parentList.get(parentList.size() - 1).getParentFile()); } for (int i = parentList.size()-1; i > -1; i--) { @@ -61,34 +65,44 @@ public boolean CheckFileExists(File file) { } } + // caching for UUIDs, to prevent unnecessary requests to the API + private final Cache uuidCache = CacheBuilder.newBuilder() + .expireAfterWrite(30, TimeUnit.DAYS) + .build(); public Object getUUIDFromName(String playerName) { try { - String urlString = "https://api.mojang.com/users/profiles/minecraft/" + playerName; - URL url = URI.create(urlString).toURL(); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - - int responseCode = conn.getResponseCode(); - BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String inputLine; - StringBuilder content = new StringBuilder(); - - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } + return uuidCache.get(playerName, () -> { + try { + String urlString = "https://api.mojang.com/users/profiles/minecraft/" + playerName; + URL url = URI.create(urlString).toURL(); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + + int responseCode = conn.getResponseCode(); + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String inputLine; + StringBuilder content = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } - in.close(); - conn.disconnect(); + in.close(); + conn.disconnect(); - JSONObject jsonobj = new JSONObject(content.toString()); - if (jsonobj.has("errorMessage")) { - // couldn't find a profile with this name - return null; - } - return jsonobj.getString("id"); - } catch (Exception e) { - // probably network error. nothing we can do. - // unlikely to happen realistically though + JSONObject jsonobj = new JSONObject(content.toString()); + if (jsonobj.has("errorMessage")) { + // couldn't find a profile with this name + return null; + } + return jsonobj.getString("id"); + } catch (Exception e) { + // probably network error. nothing we can do. + // unlikely to happen realistically though + return null; + } + }); + } catch (ExecutionException e) { return null; } } From e71da09a4cb91f567dd89a933195efe915bb04b5 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 16:34:19 +0200 Subject: [PATCH 20/27] adding colouring. should be good to go. --- .../mc/notes/commands/NoteCommand.java | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java index d0a0b37..f12a479 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java @@ -30,8 +30,9 @@ public class NoteCommand implements CommandExecutor { private final NotePlugin plugin; - private final NoteConfig config; + private final String errorColorCode = "§e"; + private final String permissionColorCode = "§3"; public NoteCommand(NotePlugin plugin) { this.plugin = plugin; @@ -109,17 +110,17 @@ public Object getUUIDFromName(String playerName) { public boolean NoteAdd(CommandSender sender, String[] args, String type) { if (!sender.hasPermission("simplenotes.addnotes") && !sender.isOp()) { - sender.sendMessage("You do not have permission to use this subcommand."); + sender.sendMessage(permissionColorCode+"You do not have permission to use this subcommand."); return false; } if (args.length == 1) { - sender.sendMessage("Please provide a player name."); + sender.sendMessage(errorColorCode+"Please provide a player name."); return false; } String requestSubject = args[1]; Object subjectUUID = this.getUUIDFromName(requestSubject); if (subjectUUID == null) { - sender.sendMessage("Player doesn't exist."); + sender.sendMessage(errorColorCode+"Player doesn't exist."); return false; } subjectUUID = subjectUUID.toString(); @@ -132,7 +133,7 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { throw new IOException("this didn't work"); } } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to create "+dataFile.getAbsolutePath()); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -144,7 +145,7 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { try { reader = new CSVReaderBuilder(new FileReader(filename)).build(); } catch (FileNotFoundException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -160,7 +161,7 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { } } } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -170,7 +171,7 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { try { reader.close(); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -208,7 +209,7 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { writer.writeNext(line, true); writer.close(); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -220,18 +221,18 @@ public boolean NoteAdd(CommandSender sender, String[] args, String type) { public boolean NoteRemove(CommandSender sender, String[] args) { if (!sender.hasPermission("simplenotes.removenotes") && !sender.isOp()) { - sender.sendMessage("You do not have permission to use this subcommand."); + sender.sendMessage(permissionColorCode+"You do not have permission to use this subcommand."); return false; } if (args.length <= 2) { - sender.sendMessage("Please provide a player name and an id."); + sender.sendMessage(errorColorCode+"Please provide a player name and an id."); return true; } String requestSubject = args[1]; Object subjectUUID = this.getUUIDFromName(requestSubject); if (subjectUUID == null) { - sender.sendMessage("Player doesn't exist."); + sender.sendMessage(errorColorCode+"Player doesn't exist."); return true; } subjectUUID = subjectUUID.toString(); @@ -240,7 +241,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { // we do not try to create the file, since if it doesn't exist, the warn/note doesn't exist either - sender.sendMessage("Note/warn not found."); + sender.sendMessage(errorColorCode+"Note/warn not found."); return false; } @@ -251,7 +252,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { .withCSVParser(new CSVParserBuilder().build()) .build(); } catch (FileNotFoundException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -260,7 +261,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { try { allElements = reader.readAll(); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -270,7 +271,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { try { reader.close(); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -289,7 +290,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { throw new IOException("this didn't work"); } } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -303,7 +304,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { } } if (rowNumber == -1) { - sender.sendMessage("Note/warn not found."); + sender.sendMessage(errorColorCode+"Note/warn not found."); return false; } allElements.remove(rowNumber); @@ -316,7 +317,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -325,7 +326,7 @@ public boolean NoteRemove(CommandSender sender, String[] args) { try { writer.close(); } catch (IOException e) { - sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -346,17 +347,17 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) } else RequestSubject = args[1]; if (RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.self.notes") && !sender.hasPermission("simplenotes.see.self.warns") && !sender.isOp()) { - if (!isListener) sender.sendMessage("You do not have permission to check your own notes/warns."); + if (!isListener) sender.sendMessage(permissionColorCode+"You do not have permission to check your own notes/warns."); return true; } if (!RequestSubject.equals(sender.getName()) && !sender.hasPermission("simplenotes.see.others.notes") && !sender.hasPermission("simplenotes.see.others.warns") && !sender.isOp()) { - if (!isListener) sender.sendMessage("You do not have permission to check other people's notes/warns."); + if (!isListener) sender.sendMessage(permissionColorCode+"You do not have permission to check other people's notes/warns."); return true; } Object subjectUUID = this.getUUIDFromName(RequestSubject); if (subjectUUID == null) { - if (!isListener) sender.sendMessage("Player doesn't exist."); + if (!isListener) sender.sendMessage(errorColorCode+"Player doesn't exist."); return true; } subjectUUID = subjectUUID.toString(); @@ -365,7 +366,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) File dataFile = new File(filename); if (!this.CheckFileExists(dataFile)) { // we do not try to create the file, since if it doesn't exist, there are no warns/notes - if (!isListener) sender.sendMessage("No notes or warns to show."); + if (!isListener) sender.sendMessage(errorColorCode+"No notes or warns to show."); return true; } @@ -375,7 +376,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) .withCSVParser(new CSVParserBuilder().build()) .build(); } catch (FileNotFoundException e) { - if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + if (!isListener) sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -384,7 +385,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) try { allElements = reader.readAll(); } catch (IOException e) { - if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + if (!isListener) sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -394,7 +395,7 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) try { reader.close(); } catch (IOException e) { - if (!isListener) sender.sendMessage("Internal error. Ask your local sys-admin to check the console."); + if (!isListener) sender.sendMessage(errorColorCode+"Internal error. Ask your local sys-admin to check the console."); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] ERROR: Failed to access "+filename); this.plugin.logger(Level.SEVERE,"["+this.plugin.getDescription().getName()+"] Check the permissions of the folders."); return false; @@ -402,18 +403,24 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) int shownCounter = 0; for (String[] line : allElements) { - if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE")) { + // some transformation first + line[0] = "§8"+line[0]; + if (Objects.equals(line[1], "NOTE")) line[1] = "§eNOTE"; + if (Objects.equals(line[1], "WARN")) line[1] = "§cWARN"; + line[2] = "§9"+line[2]; + + if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.notes") || sender.isOp()) && Objects.equals(line[1].substring(line[1].length() -4), "NOTE")) { shownCounter = shownCounter + 1; - sender.sendMessage("| " + String.join(" | ", line)); - } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.notes") || sender.isOp()) && Objects.equals(line[1], "NOTE") && (!isListener || config.getConfigBoolean("settings.notes.showonlogin.value"))) { + sender.sendMessage("§8| " + String.join(" §8|§r ", line)); + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.notes") || sender.isOp()) && Objects.equals(line[1].substring(line[1].length() -4), "NOTE") && (!isListener || config.getConfigBoolean("settings.notes.showonlogin.value"))) { shownCounter = shownCounter + 1; - sender.sendMessage("| " + String.join(" | ", line)); - } else if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) && Objects.equals(line[1], "WARN")) { + sender.sendMessage("§8| " + String.join(" §8|§r ", line)); + } else if (!RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.others.warns") || sender.isOp()) && Objects.equals(line[1].substring(line[1].length() -4), "WARN")) { shownCounter = shownCounter + 1; - sender.sendMessage("| " + String.join(" | ", line)); - } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) && Objects.equals(line[1], "WARN") && (!isListener || config.getConfigBoolean("settings.warns.showonlogin.value"))) { + sender.sendMessage("§8| " + String.join(" §8|§r ", line)); + } else if (RequestSubject.equals(sender.getName()) && (sender.hasPermission("simplenotes.see.self.warns") || sender.isOp()) && Objects.equals(line[1].substring(line[1].length() -4), "WARN") && (!isListener || config.getConfigBoolean("settings.warns.showonlogin.value"))) { shownCounter = shownCounter + 1; - sender.sendMessage("| " + String.join(" | ", line)); + sender.sendMessage("§8| " + String.join(" §8|§r ", line)); } } if (shownCounter == 0) { @@ -455,7 +462,7 @@ public boolean NoteHelp(CommandSender sender, String alias) { removedCommands = removedCommands - 1; } if (removedCommands > 0) { - sender.sendMessage("You do not have access to any other subcommand."); + sender.sendMessage(permissionColorCode+"You do not have access to any other subcommand."); } return true; } @@ -479,7 +486,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } else if (Objects.equals(args[0], "list")) { return this.NoteList(sender, args); } else { - sender.sendMessage("Unrecognized argument."); + sender.sendMessage(errorColorCode+"Unrecognized argument."); return this.NoteHelp(sender, label); } } From d579c9e08e1cba1d9c13baae9a19959a39507f45 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 16:35:12 +0200 Subject: [PATCH 21/27] relicense as part of RetroHaven --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 268491a..6dc18d1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 eleanorsilly +Copyright (c) 2025 RetroHaven Development Group Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From dbc60ce47a4395407864c77e6b8850235482d218 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 16:41:23 +0200 Subject: [PATCH 22/27] disable command by default --- README.md | 6 ++++-- src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index efbf82b..3ef3ffe 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. -This plugin currently assumes all players are paid accounts. Adding offline players isn't planned for now. +This plugin currently assumes all players are paid accounts. Adding offline players support isn't planned for now. Tested with Project Poseidon. Plain Bukkit should work since this project doesn't use any of Poseidon's APIs. @@ -12,6 +12,8 @@ Tested with Project Poseidon. Plain Bukkit should work since this project doesn' The plugin uses one command, /note (with aliases /notes, /warn, /warns, /warning and /warnings). +This command is disabled by default to make you look through the config (it's located in plugins/SimpleNotes/config.yml!). + ### Subcommands - /note help: list the subcommands you have access to @@ -24,4 +26,4 @@ The plugin uses one command, /note (with aliases /notes, /warn, /warns, /warning ## Compiling -Clone the repository and run `mvn clean package`. The resulting jar should be in the `target` folder. +Clone the repository and run `mvn clean package`. The resulting jar should be in the `target` folder. \ No newline at end of file diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java index 37bf9f5..741b50e 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java +++ b/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java @@ -42,7 +42,7 @@ private void write() { generateConfigOption("config-version", configVersion); // Plugin options - generateConfigOption("settings.plugin.enabled.value", true); + generateConfigOption("settings.plugin.enabled.value", false); generateConfigOption("settings.plugin.enabled.info", "Whether the command is enabled."); generateConfigOption("settings.warns.showonlogin.value", true); From 7049a2e49f6e39cd560eeb7205507e993a54cc80 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 17:18:39 +0200 Subject: [PATCH 23/27] better shading for guava (previous one didn't work) --- pom.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2645d30..3ada016 100644 --- a/pom.xml +++ b/pom.xml @@ -66,9 +66,23 @@ com.opencsv:opencsv org.json:json - com.google.guava:guava + com.google.guava:* + + + com.google.common + org.eleanorsilly.shaded.com.google.common + + + + + com.google.guava:guava + + com/google/common/** + + + From 0066a5ae3dfe4ba48ff6174bb6100823b7c480a5 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 17:47:40 +0200 Subject: [PATCH 24/27] refactor to org.retrohaven.mc.notes and remove warning --- README.md | 2 -- pom.xml | 4 ++-- .../{eleanorsilly => retrohaven}/mc/notes/NoteConfig.java | 2 +- .../{eleanorsilly => retrohaven}/mc/notes/NoteListener.java | 4 ++-- .../{eleanorsilly => retrohaven}/mc/notes/NotePlugin.java | 4 ++-- .../mc/notes/commands/NoteCommand.java | 6 +++--- src/main/resources/plugin.yml | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) rename src/main/java/org/{eleanorsilly => retrohaven}/mc/notes/NoteConfig.java (99%) rename src/main/java/org/{eleanorsilly => retrohaven}/mc/notes/NoteListener.java (91%) rename src/main/java/org/{eleanorsilly => retrohaven}/mc/notes/NotePlugin.java (95%) rename src/main/java/org/{eleanorsilly => retrohaven}/mc/notes/commands/NoteCommand.java (99%) diff --git a/README.md b/README.md index 3ef3ffe..983918b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# THIS IS NOT PRODUCTION READY BY ANY MEANS. DO NOT INSTALL. - # SimpleNotes This plugin aims to provide a note/warning system implemented easily for beta 1.7.3. No other Minecraft versions are targeted and no support is provided for those other versions. diff --git a/pom.xml b/pom.xml index 3ada016..c89a653 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.eleanorsilly.mc.notes + org.retrohaven.mc.notes SimpleNotes 1.0.0-SNAPSHOT A note system for moderators and admins, with the objective to be light on the system and on the codebase. @@ -72,7 +72,7 @@ com.google.common - org.eleanorsilly.shaded.com.google.common + org.retrohaven.shaded.com.google.common diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java b/src/main/java/org/retrohaven/mc/notes/NoteConfig.java similarity index 99% rename from src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java rename to src/main/java/org/retrohaven/mc/notes/NoteConfig.java index 741b50e..1322802 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteConfig.java +++ b/src/main/java/org/retrohaven/mc/notes/NoteConfig.java @@ -1,4 +1,4 @@ -package org.eleanorsilly.mc.notes; +package org.retrohaven.mc.notes; import org.bukkit.util.config.Configuration; diff --git a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java b/src/main/java/org/retrohaven/mc/notes/NoteListener.java similarity index 91% rename from src/main/java/org/eleanorsilly/mc/notes/NoteListener.java rename to src/main/java/org/retrohaven/mc/notes/NoteListener.java index 8fe0ab2..b8eda12 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NoteListener.java +++ b/src/main/java/org/retrohaven/mc/notes/NoteListener.java @@ -1,9 +1,9 @@ -package org.eleanorsilly.mc.notes; +package org.retrohaven.mc.notes; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; -import org.eleanorsilly.mc.notes.commands.NoteCommand; +import org.retrohaven.mc.notes.commands.NoteCommand; public class NoteListener extends PlayerListener { private NotePlugin plugin; diff --git a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java b/src/main/java/org/retrohaven/mc/notes/NotePlugin.java similarity index 95% rename from src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java rename to src/main/java/org/retrohaven/mc/notes/NotePlugin.java index 4ba9d99..e11cbf4 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/NotePlugin.java +++ b/src/main/java/org/retrohaven/mc/notes/NotePlugin.java @@ -1,10 +1,10 @@ -package org.eleanorsilly.mc.notes; +package org.retrohaven.mc.notes; import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import org.eleanorsilly.mc.notes.commands.NoteCommand; +import org.retrohaven.mc.notes.commands.NoteCommand; import java.io.*; import java.util.logging.Level; diff --git a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java b/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java similarity index 99% rename from src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java rename to src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java index f12a479..58392e7 100644 --- a/src/main/java/org/eleanorsilly/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java @@ -1,4 +1,4 @@ -package org.eleanorsilly.mc.notes.commands; +package org.retrohaven.mc.notes.commands; import com.opencsv.CSVParserBuilder; import com.opencsv.CSVReader; @@ -10,8 +10,8 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.eleanorsilly.mc.notes.NoteConfig; -import org.eleanorsilly.mc.notes.NotePlugin; +import org.retrohaven.mc.notes.NoteConfig; +import org.retrohaven.mc.notes.NotePlugin; import org.json.JSONObject; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b521318..09d1590 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ${project.name} description: ${project.description} -main: org.eleanorsilly.mc.notes.NotePlugin +main: org.retrohaven.mc.notes.NotePlugin version: ${project.version} authors: - eleanorsilly From 9e5259d4a6cb56e1107cb15577fcacc4e830d5c5 Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 18:03:59 +0200 Subject: [PATCH 25/27] fix listener not working properly --- src/main/java/org/retrohaven/mc/notes/NoteListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/retrohaven/mc/notes/NoteListener.java b/src/main/java/org/retrohaven/mc/notes/NoteListener.java index b8eda12..bc6a462 100644 --- a/src/main/java/org/retrohaven/mc/notes/NoteListener.java +++ b/src/main/java/org/retrohaven/mc/notes/NoteListener.java @@ -18,11 +18,11 @@ public NoteListener(NotePlugin plugin) { @Override public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - NoteCommand commands = new NoteCommand(plugin); - if ((!player.hasPermission("simplenotes.see.self.warns") || !config.getConfigBoolean("settings.warns.showonlogin.value")) - && (!player.hasPermission("simplenotes.see.self.notes") || !config.getConfigBoolean("settings.notes.showonlogin.value"))) { + if ((!player.hasPermission("simplenotes.see.self.warns") && !player.isOp() && !config.getConfigBoolean("settings.warns.showonlogin.value")) + && (!player.hasPermission("simplenotes.see.self.notes") && !player.isOp() && !config.getConfigBoolean("settings.notes.showonlogin.value"))) { return; } + NoteCommand commands = new NoteCommand(plugin); boolean b = commands.NoteList(player, new String[] {""}, true); } } From 0bdd614d6ad944f83a2e3fb02777163e91bfa43c Mon Sep 17 00:00:00 2001 From: eleanordoesntcode <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 18:19:00 +0200 Subject: [PATCH 26/27] remove useless line --- src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java b/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java index 58392e7..029952b 100644 --- a/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java +++ b/src/main/java/org/retrohaven/mc/notes/commands/NoteCommand.java @@ -404,7 +404,6 @@ public boolean NoteList(CommandSender sender, String[] args, boolean isListener) int shownCounter = 0; for (String[] line : allElements) { // some transformation first - line[0] = "§8"+line[0]; if (Objects.equals(line[1], "NOTE")) line[1] = "§eNOTE"; if (Objects.equals(line[1], "WARN")) line[1] = "§cWARN"; line[2] = "§9"+line[2]; From f0833d1e903a7289080433717ff6a073b48f83e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9l=C3=A9anore=20is=20not=20coding=20in=20the=20slight?= =?UTF-8?q?est?= <166862894+eleanordoesntcode@users.noreply.github.com> Date: Thu, 29 May 2025 18:28:34 +0200 Subject: [PATCH 27/27] 1.0.0 release! --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c89a653..d29e639 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.retrohaven.mc.notes SimpleNotes - 1.0.0-SNAPSHOT + 1.0.0 A note system for moderators and admins, with the objective to be light on the system and on the codebase.