From 7e759aace3cf95a0152361273d03c95e9b691037 Mon Sep 17 00:00:00 2001 From: steev Date: Thu, 28 Nov 2024 10:26:03 +0100 Subject: [PATCH 1/6] refactored config to it's own class --- .../java/de/steev/bm/BetterMinecraft.java | 66 ++++++++--------- src/main/java/de/steev/bm/utils/Config.java | 72 +++++++++++++++++++ .../java/de/steev/bm/utils/Constants.java | 9 +++ .../exceptions/ConfigEntryExceptions.java | 9 +++ 4 files changed, 119 insertions(+), 37 deletions(-) create mode 100644 src/main/java/de/steev/bm/utils/Config.java create mode 100644 src/main/java/de/steev/bm/utils/Constants.java create mode 100644 src/main/java/de/steev/bm/utils/exceptions/ConfigEntryExceptions.java diff --git a/src/main/java/de/steev/bm/BetterMinecraft.java b/src/main/java/de/steev/bm/BetterMinecraft.java index 7a92030..c84d3c3 100644 --- a/src/main/java/de/steev/bm/BetterMinecraft.java +++ b/src/main/java/de/steev/bm/BetterMinecraft.java @@ -5,89 +5,81 @@ import de.steev.bm.Listener.BedListener; import de.steev.bm.Listener.InteractListener; import de.steev.bm.Listener.KillListener; import de.steev.bm.Manager.GameManager; - +import de.steev.bm.utils.Config; +import de.steev.bm.utils.exceptions.ConfigEntryExceptions; import org.bukkit.ChatColor; import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; import java.io.IOException; +import java.util.Objects; import java.util.UUID; +import static de.steev.bm.utils.Constants.*; public class BetterMinecraft extends JavaPlugin implements Listener { // Global Variables that might come helpfull later public int playerInBed = 0; public World world; - String version = "1.2"; // Custom Playerdata File - private File playerdata; - private FileConfiguration playerDataConfig; - private final String playerdatafilename = "playerdata.yml"; - private static String prefix = ChatColor.GRAY + "[" + ChatColor.AQUA + "BetterMinecraft" + ChatColor.GRAY + "]"; - + private Config playerData = new Config(playerDataFilename, this); private GameManager gameManager; // Handles initialisation public void onEnable() { // Messaging - this.getLogger().info(prefix + ChatColor.WHITE + "Plugin Startet"); + this.getLogger().info(prefix + ChatColor.WHITE + "Plugin Startup"); this.getLogger().info(prefix + ChatColor.WHITE + "Initializing Gamemanager"); gameManager = new GameManager(this); // Registers Events - this.getLogger().info(prefix + ChatColor.WHITE + "Lade Events"); + this.getLogger().info(prefix + ChatColor.WHITE + "Load Events"); this.getServer().getPluginManager().registerEvents(new BedListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(new KillListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(new InteractListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(this, this); - this.getCommand("back").setExecutor(new back(this.gameManager)); + Objects.requireNonNull(this.getCommand("back")).setExecutor(new back(this.gameManager)); // PlayerData - playerdata = new File(this.getDataFolder(), playerdatafilename); - playerDataConfig = YamlConfiguration.loadConfiguration(playerdata); - saveplayerdata(); + try { + this.playerData.saveConfig(playerDataFilename); + } catch (IOException e) { + throw new RuntimeException(e); + } - // More Messaging - this.getLogger().info(ChatColor.AQUA + "Ich bin Fertig :D"); + // More Messaging + this.getLogger().info(ChatColor.AQUA + "Startup complete :D"); } @EventHandler void onPlayerJoin(PlayerJoinEvent e) { Player p = (Player) e.getPlayer(); UUID uuid = p.getUniqueId(); - // prevent this allways resetting the job count - if (this.playerDataConfig.get(uuid + "." + version + ".read") == null) { - p.sendMessage("================= Better Minecraft " + version + " ================="); - p.sendMessage("Command: /back eingefügt"); - p.sendMessage("====================================================="); - this.playerDataConfig.set(uuid + ".name", p.getName()); - this.playerDataConfig.set(uuid + "." + version + ".read", "true"); - saveplayerdata(); - } - } - - void saveplayerdata() { try { - playerDataConfig.save(playerdata); - } catch (IOException e) { - this.getLogger().warning("Unable to save " + playerdatafilename); // shouldn't really happen, but save - // throws the exception + // prevent this allways resetting the job count + if (this.playerData.readBooleanFromConfig(uuid + "." + Version + ".read")) { + p.sendMessage("================= Better Minecraft " + Version + " ================="); + p.sendMessage("Command: /back eingefügt"); + p.sendMessage("====================================================="); + + this.playerData.writeStringToConfig(uuid + ".name", p.getName()); + this.playerData.writeStringToConfig(uuid + "." + Version + ".read", "true"); + this.playerData.saveConfig(playerDataFilename); + } + } catch (ConfigEntryExceptions cee) { + this.getLogger().warning("reading config failed with error: " + cee.getMessage()); + } catch (IOException ioe) { + throw new RuntimeException(ioe); } } - public FileConfiguration getPlayerDataConfig(){ - return this.playerDataConfig; - } public static String LoggerPrefix(){ return prefix; } diff --git a/src/main/java/de/steev/bm/utils/Config.java b/src/main/java/de/steev/bm/utils/Config.java new file mode 100644 index 0000000..e05a69a --- /dev/null +++ b/src/main/java/de/steev/bm/utils/Config.java @@ -0,0 +1,72 @@ +package de.steev.bm.utils; + +import de.steev.bm.BetterMinecraft; +import de.steev.bm.utils.exceptions.ConfigEntryExceptions; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; + +import static de.steev.bm.utils.Constants.playerDataFilename; + +public class Config { + private String name; + private File configFile; + private FileConfiguration fileConfiguration; + private BetterMinecraft plugin; + + public Config(String name, BetterMinecraft plugin) { + this.name = name; + this.plugin = plugin; + configFile = new File(this.plugin.getDataFolder(), playerDataFilename); + fileConfiguration = YamlConfiguration.loadConfiguration(configFile); + } + + public void saveConfig(String name) throws IOException { + try { + fileConfiguration.save(configFile); + } catch (IOException e) { + this.plugin.getLogger().warning("Unable to save " + playerDataFilename); // shouldn't really happen, but save + // throws the exception + throw e; + } + } + + public void writeStringToConfig(String path, String value) { + this.fileConfiguration.set(path, value); + } + + public String readStringFromConfig(String path) throws ConfigEntryExceptions { + + if (this.fileConfiguration.get(path) == null) { + throw new ConfigEntryExceptions("entry at: " + path + " found null"); + } + + return this.fileConfiguration.getString(path); + } + + public int readIntFromConfig(String path) throws ConfigEntryExceptions { + if (this.fileConfiguration.get(path) == null) { + throw new ConfigEntryExceptions("entry at: " + path + " found null"); + } + + return this.fileConfiguration.getInt(path); + } + + public boolean readBooleanFromConfig(String path) throws ConfigEntryExceptions { + if (this.fileConfiguration.get(path) == null) { + throw new ConfigEntryExceptions("entry at: " + path + " found null"); + } + + return this.fileConfiguration.getBoolean(path); + } + + public FileConfiguration getConfig() { + return this.fileConfiguration; + } + + public String getName() { + return this.name; + } +} diff --git a/src/main/java/de/steev/bm/utils/Constants.java b/src/main/java/de/steev/bm/utils/Constants.java new file mode 100644 index 0000000..c8ccc92 --- /dev/null +++ b/src/main/java/de/steev/bm/utils/Constants.java @@ -0,0 +1,9 @@ +package de.steev.bm.utils; + +import org.bukkit.ChatColor; + +public class Constants { + public static final String prefix = ChatColor.GRAY + "[" + ChatColor.AQUA + "BetterMinecraft" + ChatColor.GRAY + "]"; + public static final String playerDataFilename = "playerdata.yml"; + public static final String Version = "1.2.2"; +} diff --git a/src/main/java/de/steev/bm/utils/exceptions/ConfigEntryExceptions.java b/src/main/java/de/steev/bm/utils/exceptions/ConfigEntryExceptions.java new file mode 100644 index 0000000..928c12d --- /dev/null +++ b/src/main/java/de/steev/bm/utils/exceptions/ConfigEntryExceptions.java @@ -0,0 +1,9 @@ +package de.steev.bm.utils.exceptions; + +public class ConfigEntryExceptions extends Exception { + public ConfigEntryExceptions() {} + + public ConfigEntryExceptions(String message) { + super(message); + } +} -- 2.49.1 From 59611ac1d1da41d7fc6a77b1fc94328e3cb6e660 Mon Sep 17 00:00:00 2001 From: steev Date: Thu, 5 Dec 2024 09:29:55 +0100 Subject: [PATCH 2/6] added changelog handler class --- .../java/de/steev/bm/utils/Changelog.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/de/steev/bm/utils/Changelog.java diff --git a/src/main/java/de/steev/bm/utils/Changelog.java b/src/main/java/de/steev/bm/utils/Changelog.java new file mode 100644 index 0000000..3564c62 --- /dev/null +++ b/src/main/java/de/steev/bm/utils/Changelog.java @@ -0,0 +1,37 @@ +package de.steev.bm.utils; + +import de.steev.bm.Manager.GameManager; +import org.bukkit.entity.Player; + +public class Changelog { + private GameManager plugin; + + public Changelog(GameManager plugin) { + this.plugin = plugin; + } + + /** + * handles getting changelog and sending it to the player + * @param player the receiving player + */ + public void SendChangelog(Player player) { + player.sendMessage(createChangelog()); + } + + /** + * handles checking the playerdata if a player already saw the changelog + * @param player the player to lookup + * @return boolean which tells whether or not a player has seen the changelog + */ + private boolean hasPlayerSeenChangelog(Player player) { + return false; + } + + /*** + * reads the set changlog file + * @return the resulting changelog as string + */ + private String createChangelog() { + return ""; + } +} -- 2.49.1 From 195e12e7e4db24afe61a46eacdd60e4b1f6aaf8d Mon Sep 17 00:00:00 2001 From: Steev Date: Fri, 27 Dec 2024 03:29:44 +0100 Subject: [PATCH 3/6] .gitea/workflows/test-release.yml aktualisiert --- .gitea/workflows/test-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test-release.yml b/.gitea/workflows/test-release.yml index 5294f1b..76a4247 100644 --- a/.gitea/workflows/test-release.yml +++ b/.gitea/workflows/test-release.yml @@ -3,7 +3,7 @@ name: Build and Release Minecraft Plugin on: push: branches: - - testing + - Testing jobs: -- 2.49.1 From 95dd5607798a8d19bdb4ee2e36b27d328f0ee344 Mon Sep 17 00:00:00 2001 From: steev Date: Tue, 2 Dec 2025 20:39:39 +0100 Subject: [PATCH 4/6] halted Changelog Screen refactor --- pom.xml | 4 +-- .../java/de/steev/bm/BetterMinecraft.java | 3 +- .../java/de/steev/bm/utils/Changelog.java | 31 ++++++++++++++++--- src/main/resources/config.yml | 13 ++++++++ src/main/resources/plugin.yml | 4 +-- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/config.yml diff --git a/pom.xml b/pom.xml index 84ef005..c0050bb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.steev.bm BetterMinecraft - stable + 1.2.2 17 @@ -25,7 +25,7 @@ org.spigotmc spigot-api - 1.20.1-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/de/steev/bm/BetterMinecraft.java b/src/main/java/de/steev/bm/BetterMinecraft.java index c84d3c3..ab41226 100644 --- a/src/main/java/de/steev/bm/BetterMinecraft.java +++ b/src/main/java/de/steev/bm/BetterMinecraft.java @@ -63,10 +63,9 @@ public class BetterMinecraft extends JavaPlugin implements Listener { UUID uuid = p.getUniqueId(); try { - // prevent this allways resetting the job count if (this.playerData.readBooleanFromConfig(uuid + "." + Version + ".read")) { p.sendMessage("================= Better Minecraft " + Version + " ================="); - p.sendMessage("Command: /back eingefügt"); + p.sendMessage("Amboss Kostengrenze entfernt"); p.sendMessage("====================================================="); this.playerData.writeStringToConfig(uuid + ".name", p.getName()); diff --git a/src/main/java/de/steev/bm/utils/Changelog.java b/src/main/java/de/steev/bm/utils/Changelog.java index 3564c62..7f53939 100644 --- a/src/main/java/de/steev/bm/utils/Changelog.java +++ b/src/main/java/de/steev/bm/utils/Changelog.java @@ -3,6 +3,11 @@ package de.steev.bm.utils; import de.steev.bm.Manager.GameManager; import org.bukkit.entity.Player; +enum ChangelogType { + SystemChangeLog, + CustomChangelog +} + public class Changelog { private GameManager plugin; @@ -15,15 +20,18 @@ public class Changelog { * @param player the receiving player */ public void SendChangelog(Player player) { - player.sendMessage(createChangelog()); + //player.sendMessage(createChangelog()); } /** * handles checking the playerdata if a player already saw the changelog * @param player the player to lookup - * @return boolean which tells whether or not a player has seen the changelog + * @return boolean which tells whether a player has seen the changelog or not */ - private boolean hasPlayerSeenChangelog(Player player) { + private boolean hasPlayerSeenChangelog(ChangelogType changelogType, Player player) { + // TODO: read from header what version the changelog is for + // TODO: read from playerdata.yml if the player has seen the changelog for that type + // TODO: return found result return false; } @@ -31,7 +39,22 @@ public class Changelog { * reads the set changlog file * @return the resulting changelog as string */ - private String createChangelog() { + private String createChangelog(ChangelogType changelogType) { + // TODO: FETCH from + + /*switch (changelogType) { + case SystemChangeLog: + // TODO: get changelog url from config + // TODO: fetch version changelog from git + // TODO: proccess changelog + break; + case CustomChangelog: + // TODO: fetch changes from changes.txt found in plugin folder or from configured destination + // TODO: proccess changelog + break; + + }*/ + return ""; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..04a95e9 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,13 @@ +# changelog +system_changelog: true +system_changelog_location: https://git.slpnetwork.de/Steev/betterminecraft/src/branch/main/changelog.txt +custom_changelog: true +custom_changelog_location: custom_changelog.txt + +# features +changelog: true # if this is toggled the whole changelog system is enabled or disabled +improved_bed: true # toggles whether the night should be skipped when half the server players sleep +custom_drops: false # toggles if custom drops should be enabled +custom_recipes: false # toggles if custom recipes should be enabled +replanting: true # toggles the right click replant feature +back_command: true # toggles the back to death point feature \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3515651..73d8a97 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: BetterMinecraft main: de.steev.bm.BetterMinecraft -version: 1.0 -api-version: 1.17 +version: 1.2.2 +api-version: 1.21 commands: back: description: "teleports players back to their deathpoint" \ No newline at end of file -- 2.49.1 From e29591bb7b88558c5c933b8c2cc474a52578c55b Mon Sep 17 00:00:00 2001 From: steev Date: Tue, 2 Dec 2025 21:08:03 +0100 Subject: [PATCH 5/6] removed cost cap from anvill --- .../steev/bm/Interaction/AnvilCalculator.java | 29 +++++++++++++++++++ .../bm/Listener/PrepareAnvilListener.java | 21 ++++++++++++++ src/main/resources/config.yml | 3 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/steev/bm/Interaction/AnvilCalculator.java create mode 100644 src/main/java/de/steev/bm/Listener/PrepareAnvilListener.java diff --git a/src/main/java/de/steev/bm/Interaction/AnvilCalculator.java b/src/main/java/de/steev/bm/Interaction/AnvilCalculator.java new file mode 100644 index 0000000..a617d0b --- /dev/null +++ b/src/main/java/de/steev/bm/Interaction/AnvilCalculator.java @@ -0,0 +1,29 @@ +package de.steev.bm.Interaction; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.Repairable; + +public class AnvilCalculator { + public static int getRepairCost(ItemStack item) { + if (item == null || item.getType().isAir()) return 0; + ItemMeta meta = item.getItemMeta(); + if (meta instanceof Repairable) { + Repairable r = (Repairable) meta; + return r.getRepairCost(); // default 0 wenn nicht gesetzt + } + return 0; + } + + public static ItemStack setRepairCost(ItemStack item, int cost) { + if (item == null || item.getType().isAir()) return item; + ItemMeta meta = item.getItemMeta(); + if (meta instanceof Repairable) { + Repairable r = (Repairable) meta; + r.setRepairCost(cost); + item.setItemMeta(meta); + } + return item; + } +} diff --git a/src/main/java/de/steev/bm/Listener/PrepareAnvilListener.java b/src/main/java/de/steev/bm/Listener/PrepareAnvilListener.java new file mode 100644 index 0000000..efaea84 --- /dev/null +++ b/src/main/java/de/steev/bm/Listener/PrepareAnvilListener.java @@ -0,0 +1,21 @@ +package de.steev.bm.Listener; + +import de.steev.bm.BetterMinecraft; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.bukkit.inventory.AnvilInventory; + +public class PrepareAnvilListener { + + private BetterMinecraft plugin; + + public PrepareAnvilListener(BetterMinecraft plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPrepare(PrepareAnvilEvent event) { + AnvilInventory inv = event.getInventory(); + inv.setMaximumRepairCost(Integer.MAX_VALUE); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 896d463..cfe8aa3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,4 +2,5 @@ improved_bed: true custom_drops: true custom_recipes: true replanting: true -back_command: true \ No newline at end of file +back_command: true +no_anvill_cost_cap: true \ No newline at end of file -- 2.49.1 From bb5d6c0b7f27fa6fda4505104cccbb83c6316608 Mon Sep 17 00:00:00 2001 From: steev Date: Tue, 2 Dec 2025 21:16:05 +0100 Subject: [PATCH 6/6] bugfix :worm: readded lost getter function for playerDataConfig --- src/main/java/de/steev/bm/BetterMinecraft.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/steev/bm/BetterMinecraft.java b/src/main/java/de/steev/bm/BetterMinecraft.java index e3e2232..4c4c242 100644 --- a/src/main/java/de/steev/bm/BetterMinecraft.java +++ b/src/main/java/de/steev/bm/BetterMinecraft.java @@ -9,6 +9,7 @@ import de.steev.bm.utils.Config; import de.steev.bm.utils.exceptions.ConfigEntryExceptions; import org.bukkit.ChatColor; import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -88,4 +89,8 @@ public class BetterMinecraft extends JavaPlugin implements Listener { // Even more Messaging this.getLogger().info(ChatColor.AQUA + "Ich geh dann mal :c"); } + + public FileConfiguration getPlayerDataConfig() { + return this.playerData.getConfig(); + } } \ No newline at end of file -- 2.49.1