diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 43335aa..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "image": "mcr.microsoft.com/devcontainers/java", - "remoteUser": "root", - "features": { - "ghcr.io/devcontainers/features/common-utils:2": { - "configureZshAsDefaultShell": true, - "installOhMyZsh": true, - "upgradePackages": true - }, - "ghcr.io/devcontainers/features/git:1": {} - }, - "customizations": { - "vscode": { - "extensions": [ - "esbenp.prettier-vscode", - "formulahendry.code-runner", - "github.copilot", - "github.vscode-github-actions", - "pkief.material-icon-theme", - "qwtel.sqlite-viewer", - "usernamehw.errorlens", - "vsls-contrib.gistfs" - ] - } - }, - "postCreateCommand": "sudo apt update -y && sudo apt install gradle -y", - "shutdownAction": "stopContainer" -} diff --git a/.gitignore b/.gitignore index b936cdc..a61e10e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,6 @@ build/ .idea/ *.iml -# VS Code specific files -.vscode/ - # OS generated files .DS_Store Thumbs.db diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 3a655b7..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "java.import.gradle.java.home": "/usr/lib/jvm/msopenjdk-current", - "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m -Xlog:disable" -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index b1d9f76..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "buildJar", - "type": "shell", - "command": "./gradlew build", - "options": { "cwd": "${workspaceFolder}" }, - "group": { "kind": "build", "isDefault": true } - } - ] -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7226cfb --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ + + +

+
+ + VanillaPlus Logo + +

+ VanillaPlus +
+
+

+ +

Minecraft plugin that enhances the base gameplay.


+ +
+ +[![Contributors][contributors_shield_url]][contributors_url] +[![Issues][issues_shield_url]][issues_url] +[![Roadmap][roadmap_shield_url]][roadmap_url]
+ +## Table of Contents + +- [About The Project](#about-the-project) +- [Code of Conduct][code_of_conduct_url] +- [Contributing][contributing_url] +- [License][license_url] + +## About The Project + + + +

Built With

+ +[![Built With][built_with_shield_url]][built_with_url]
+ +

+ +[built_with_shield_url]: https://skillicons.dev/icons?i=vscode,docker,java,gradle,sqlite,github,githubactions +[built_with_url]: https://skillicons.dev +[code_of_conduct_url]: https://github.com/XodiumSoftware/xCLOUD?tab=coc-ov-file +[contributing_url]: https://github.com/XodiumSoftware/xCLOUD/blob/main/CONTRIBUTING.md +[contributors_shield_url]: https://img.shields.io/github/contributors/XodiumSoftware/xCLOUD?style=for-the-badge&color=blue +[contributors_url]: https://github.com/XodiumSoftware/xCLOUD/graphs/contributors +[issues_shield_url]: https://img.shields.io/github/issues/XodiumSoftware/xCLOUD?style=for-the-badge&color=yellow +[issues_url]: https://github.com/XodiumSoftware/xCLOUD/issues +[license_url]: https://github.com/XodiumSoftware/xCLOUD?tab=AGPL-3.0-1-ov-file +[roadmap_shield_url]: https://img.shields.io/badge/Roadmap-Click%20Me!-purple.svg?style=for-the-badge +[roadmap_url]: https://github.com/orgs/XodiumSoftware/projects/4 diff --git a/build.gradle.kts b/build.gradle.kts index cee8048..3ec74c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "org.xodium.vanillaplus" -version = "1.1.4" +version = "1.2.0" description = "Minecraft plugin that enhances the base gameplay." repositories { diff --git a/src/main/java/org/xodium/vanillaplus/Database.java b/src/main/java/org/xodium/vanillaplus/Database.java deleted file mode 100644 index 3406d74..0000000 --- a/src/main/java/org/xodium/vanillaplus/Database.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.xodium.vanillaplus; - -import java.io.File; -import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.Date; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -public class Database { - private Connection conn; - private final VanillaPlus vp = VanillaPlus.getInstance(); - - private static final String DB_URL_PREFIX = "jdbc:sqlite:"; - private static final String DB_FILE = "vanillaplus.db"; - - private static final String INIT_TABLES = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)"; - private static final String SET_DATA_INITIAL = "INSERT INTO config (key, value) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM config WHERE key = ?)"; - private static final String SET_DATA_UPSERT = "INSERT INTO config (key, value) VALUES (?, ?) " - + "ON CONFLICT(key) DO UPDATE SET value = EXCLUDED.value"; - private static final String GET_DATA = "SELECT value FROM config WHERE key = ?"; - private static final String GET_DATA_COLUMN_VALUE = "value"; - - private static final Map, Function> TYPE_PARSERS = new HashMap<>() { - { - put(Boolean.class, Boolean::parseBoolean); - put(Long.class, Long::parseLong); - put(Integer.class, Integer::parseInt); - put(Double.class, Double::parseDouble); - put(Float.class, Float::parseFloat); - put(BigDecimal.class, BigDecimal::new); - put(String.class, Function.identity()); - put(Date.class, Date::valueOf); - } - }; - - public Database() { - try { - vp.getDataFolder().mkdirs(); - conn = DriverManager - .getConnection(DB_URL_PREFIX + new File(vp.getDataFolder(), DB_FILE).getAbsolutePath()); - initTables(); - } catch (SQLException err) { - err.printStackTrace(); - } - } - - private void initTables() { - try (PreparedStatement stmt = conn.prepareStatement(INIT_TABLES)) { - stmt.executeUpdate(); - } catch (SQLException err) { - err.printStackTrace(); - } - } - - public void setData(String key, Object value) { - setData(key, value, true); - } - - public void setData(String key, Object value, boolean initial) { - String sql = initial ? SET_DATA_INITIAL : SET_DATA_UPSERT; - try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, key); - stmt.setObject(2, value instanceof Boolean ? ((Boolean) value ? "true" : "false") : value); - if (initial) { - stmt.setString(3, key); - } - stmt.executeUpdate(); - } catch (SQLException err) { - err.printStackTrace(); - } - } - - public T getData(String key, Class type) { - try (PreparedStatement stmt = conn.prepareStatement(GET_DATA)) { - stmt.setString(1, key); - try (ResultSet rs = stmt.executeQuery()) { - if (rs.next()) { - String value = rs.getString(GET_DATA_COLUMN_VALUE); - Function parser = TYPE_PARSERS.get(type); - if (parser != null) { - return type.cast(parser.apply(value)); - } - throw new ClassCastException("Unsupported type: " + type.getSimpleName()); - } else { - throw new IllegalArgumentException("No data found for key: " + key); - } - } - } catch (SQLException | IllegalArgumentException err) { - err.printStackTrace(); - return null; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/xodium/vanillaplus/ModuleManager.java b/src/main/java/org/xodium/vanillaplus/ModuleManager.java index a1247a7..621f5e1 100644 --- a/src/main/java/org/xodium/vanillaplus/ModuleManager.java +++ b/src/main/java/org/xodium/vanillaplus/ModuleManager.java @@ -1,22 +1,25 @@ package org.xodium.vanillaplus; -import org.xodium.vanillaplus.interfaces.MSG; -import org.xodium.vanillaplus.interfaces.Modular; +import org.xodium.vanillaplus.interfaces.ModuleInterface; import org.xodium.vanillaplus.modules.DoorsModule; +import org.xodium.vanillaplus.modules.SaplingModule; -import java.util.List; +import java.util.stream.Stream; public class ModuleManager { - private final VanillaPlus vp = VanillaPlus.getInstance(); + private static final VanillaPlus VP = VanillaPlus.getInstance(); - { - List.of(new DoorsModule()) - .stream() - .peek(Modular::config) - .filter(Modular::isEnabled) - .forEach(module -> { - vp.getServer().getPluginManager().registerEvents(module, vp); - vp.getLogger().info(MSG.MODULE_LOADED + module.getClass().getSimpleName()); + static { + Stream.of(new DoorsModule(), new SaplingModule()) + .peek(ModuleInterface::config) + .filter(ModuleInterface::enabled) + .forEach(mod -> { + long startTime = System.currentTimeMillis(); + VP.getServer().getPluginManager().registerEvents(mod, VP); + long endTime = System.currentTimeMillis(); + VP.getLogger() + .info("Loaded: " + mod.getClass().getSimpleName() + "| Took " + (endTime - startTime) + + "ms"); }); } } \ No newline at end of file diff --git a/src/main/java/org/xodium/vanillaplus/VanillaPlus.java b/src/main/java/org/xodium/vanillaplus/VanillaPlus.java index f44aa2f..ea48cd5 100644 --- a/src/main/java/org/xodium/vanillaplus/VanillaPlus.java +++ b/src/main/java/org/xodium/vanillaplus/VanillaPlus.java @@ -1,46 +1,50 @@ package org.xodium.vanillaplus; -import java.util.Arrays; import org.bukkit.plugin.java.JavaPlugin; import org.xodium.vanillaplus.commands.ReloadCommand; +import java.util.Arrays; + public class VanillaPlus extends JavaPlugin { + private static final String[] V = {"1.21.3"}; + private static final String[] PAPER = { "Paper" }; + private static final String IS_PAPER_MSG = "This plugin is not compatible with non-Paper servers."; + private static final String IS_SUPPORTED_VERSION_MSG = "This plugin requires Paper version(s): " + + String.join(", ", V); - private static final String[] V = { "1.21.3" }; - private static final String[] PAPER = { "Paper" }; - private static final String IS_PAPER_MSG = "This plugin is not compatible with non-Paper servers."; - private static final String IS_SUPPORTED_VERSION_MSG = "This plugin requires Paper version: " + String.join(", ", V); + public static final String PREFIX = "[VanillaPlus] "; - public static VanillaPlus getInstance() { - return getPlugin(VanillaPlus.class); - } + public static VanillaPlus getInstance() { + return getPlugin(VanillaPlus.class); + } - @Override - public void onEnable() { - if (!isPaper()) { - disablePlugin(IS_PAPER_MSG); - return; + @Override + public void onEnable() { + if (!isPaper()) { + disablePlugin(IS_PAPER_MSG); + return; + } + if (!isSupportedVersion()) { + disablePlugin(IS_SUPPORTED_VERSION_MSG); + return; + } + saveDefaultConfig(); + new ReloadCommand(); + new ModuleManager(); } - if (!isSupportedVersion()) { - disablePlugin(IS_SUPPORTED_VERSION_MSG); - return; + + private void disablePlugin(String msg) { + getLogger().severe(msg); + getServer().getPluginManager().disablePlugin(this); + } + + private boolean isSupportedVersion() { + return Arrays.stream(V) + .anyMatch(v -> getServer().getVersion().contains(v)); + } + + private boolean isPaper() { + return Arrays.stream(PAPER) + .anyMatch(v -> getServer().getName().contains(v)); } - new ReloadCommand(); - new ModuleManager(); - } - - private void disablePlugin(String msg) { - getLogger().severe(msg); - getServer().getPluginManager().disablePlugin(this); - } - - private boolean isSupportedVersion() { - return Arrays.stream(V) - .anyMatch(v -> getServer().getVersion().contains(v)); - } - - private boolean isPaper() { - return Arrays.stream(PAPER) - .anyMatch(v -> getServer().getName().contains(v)); - } } \ No newline at end of file diff --git a/src/main/java/org/xodium/vanillaplus/commands/ReloadCommand.java b/src/main/java/org/xodium/vanillaplus/commands/ReloadCommand.java index dfeaf58..9592ca1 100644 --- a/src/main/java/org/xodium/vanillaplus/commands/ReloadCommand.java +++ b/src/main/java/org/xodium/vanillaplus/commands/ReloadCommand.java @@ -1,42 +1,54 @@ package org.xodium.vanillaplus.commands; -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.xodium.vanillaplus.VanillaPlus; -import org.xodium.vanillaplus.interfaces.MSG; -import org.xodium.vanillaplus.interfaces.PERMS; import com.mojang.brigadier.Command; import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.xodium.vanillaplus.VanillaPlus; + +import java.util.List; -public class ReloadCommand implements MSG { - private static final String RELOAD_SUCC_LOG_MSG = "Configuration reloaded successfully."; - private static final String RELOAD_SUCC_MSG = PREFIX + "Configuration reloaded successfully."; - private static final String PERM_ERR_MSG = PREFIX + "You do not have permission to use this command!"; - private final static VanillaPlus vp = VanillaPlus.getInstance(); - private final static MiniMessage mm = MiniMessage.miniMessage(); +public class ReloadCommand { + private static final VanillaPlus VP = VanillaPlus.getInstance(); + private static final MiniMessage MM = MiniMessage.miniMessage(); - { - vp.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, e -> { - e.registrar().register( - Commands.literal("vanillaplus") - .executes(ctx -> { - CommandSender cs = ctx.getSource().getSender(); - if (cs instanceof Player p && !p.hasPermission(PERMS.RELOAD)) { - p.sendMessage(mm.deserialize(PERM_ERR_MSG)); + static { + VP.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, e -> e.registrar().register( + Commands.literal("vanillaplus") + .executes(ctx -> { + CommandSender cs = ctx.getSource().getSender(); + if (cs instanceof Player p) { + if (!p.hasPermission(PERMS.RELOAD)) { + p.sendMessage(MSG.PERM_ERR); return 0; } - vp.reloadConfig(); - cs.sendMessage(mm.deserialize(RELOAD_SUCC_MSG)); - vp.getLogger().info(RELOAD_SUCC_LOG_MSG); - return Command.SINGLE_SUCCESS; - }) - .build(), - "Reloads VanillaPlus", - List.of("vp")); - }); + } + VP.reloadConfig(); + cs.sendMessage(MSG.RELOAD_SUCC_MSG); + VP.getLogger().info(MSG.RELOAD_SUCC_LOG_MSG); + return Command.SINGLE_SUCCESS; + }) + .build(), + "Opens the GUI", + List.of("vp"))); + } + + private interface MSG { + String PREFIX = "[VanillaPlus] "; + @NotNull + Component PERM_ERR = MM.deserialize(VanillaPlus.PREFIX + + "You do not have permission to use this command!"); + @NotNull + Component RELOAD_SUCC_MSG = MM + .deserialize(PREFIX + "Configuration reloaded successfully."); + String RELOAD_SUCC_LOG_MSG = "Configuration reloaded successfully."; + } + + private interface PERMS { + String RELOAD = VP.getClass().getSimpleName() + ".reload"; } } diff --git a/src/main/java/org/xodium/vanillaplus/interfaces/MSG.java b/src/main/java/org/xodium/vanillaplus/interfaces/MSG.java deleted file mode 100644 index 317406c..0000000 --- a/src/main/java/org/xodium/vanillaplus/interfaces/MSG.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.xodium.vanillaplus.interfaces; - -public interface MSG { - String PREFIX = "[VanillaPlus] "; - String MODULE_LOADED = "Loaded: "; -} diff --git a/src/main/java/org/xodium/vanillaplus/interfaces/Modular.java b/src/main/java/org/xodium/vanillaplus/interfaces/Modular.java deleted file mode 100644 index 27a441a..0000000 --- a/src/main/java/org/xodium/vanillaplus/interfaces/Modular.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.xodium.vanillaplus.interfaces; - -import org.bukkit.event.Listener; - -public interface Modular extends Listener { - String ENABLE = ".enable"; - - boolean isEnabled(); - - void config(); -} \ No newline at end of file diff --git a/src/main/java/org/xodium/vanillaplus/interfaces/ModuleInterface.java b/src/main/java/org/xodium/vanillaplus/interfaces/ModuleInterface.java new file mode 100644 index 0000000..61a68d9 --- /dev/null +++ b/src/main/java/org/xodium/vanillaplus/interfaces/ModuleInterface.java @@ -0,0 +1,13 @@ +package org.xodium.vanillaplus.interfaces; + +import org.bukkit.event.Listener; + +public interface ModuleInterface extends Listener { + interface CONFIG { + String ENABLE = ".enable"; + } + + boolean enabled(); + + void config(); +} \ No newline at end of file diff --git a/src/main/java/org/xodium/vanillaplus/interfaces/PERMS.java b/src/main/java/org/xodium/vanillaplus/interfaces/PERMS.java deleted file mode 100644 index f647009..0000000 --- a/src/main/java/org/xodium/vanillaplus/interfaces/PERMS.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.xodium.vanillaplus.interfaces; - -public interface PERMS { - String VANILLAPLUS = "vanillaplus."; - String RELOAD = VANILLAPLUS + "reload"; - - interface DOORSMODULE { - String USE = VANILLAPLUS + "doubledoors"; - String KNOCK = VANILLAPLUS + "knock"; - String AUTOCLOSE = VANILLAPLUS + "autoclose"; - } -} diff --git a/src/main/java/org/xodium/vanillaplus/modules/DoorsModule.java b/src/main/java/org/xodium/vanillaplus/modules/DoorsModule.java index 641feb0..58b2a2e 100644 --- a/src/main/java/org/xodium/vanillaplus/modules/DoorsModule.java +++ b/src/main/java/org/xodium/vanillaplus/modules/DoorsModule.java @@ -1,20 +1,7 @@ package org.xodium.vanillaplus.modules; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; - -import org.bukkit.event.Event; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.Sound; -import org.bukkit.SoundCategory; -import org.bukkit.World; +import com.google.common.base.Enums; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.Bisected; @@ -23,48 +10,27 @@ import org.bukkit.block.data.type.Door; import org.bukkit.block.data.type.Gate; import org.bukkit.block.data.type.TrapDoor; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.scheduler.BukkitRunnable; -import org.xodium.vanillaplus.Database; import org.xodium.vanillaplus.VanillaPlus; -import org.xodium.vanillaplus.interfaces.Modular; -import org.xodium.vanillaplus.interfaces.PERMS; +import org.xodium.vanillaplus.interfaces.ModuleInterface; import org.xodium.vanillaplus.records.AdjacentBlockRecord; -import com.google.common.base.Enums; +import java.util.*; // TODO: refactor. -public class DoorsModule implements Modular { - private final String className = getClass().getSimpleName(); - private final VanillaPlus vp = VanillaPlus.getInstance(); - private final Database db = new Database(); - - // Sound settings - public static final String SOUND_KNOCK_CATEGORY = ".sound_knock_category"; - public static final String SOUND_KNOCK_PITCH = ".sound_knock_pitch"; - public static final String SOUND_KNOCK_VOLUME = ".sound_knock_volume"; - public static final String SOUND_KNOCK_WOOD = ".sound_knock_wood"; - - // Behavior settings - public static final String ALLOW_AUTOCLOSE = ".allow_autoclose"; - public static final String ALLOW_DOUBLEDOORS = ".allow_doubledoors"; - public static final String ALLOW_KNOCKING = ".allow_knocking"; - public static final String ALLOW_KNOCKING_GATES = ".allow_knocking_gates"; - public static final String ALLOW_KNOCKING_TRAPDOORS = ".allow_knocking_trapdoors"; - public static final String KNOCKING_REQUIRES_EMPTY_HAND = ".knocking_requires_empty_hand"; - public static final String KNOCKING_REQUIRES_SHIFT = ".knocking_requires_shift"; - - // Auto-close settings - public static final String AUTOCLOSE_DELAY = ".autoclose_delay"; - - // Others - private final HashMap autoClose = new HashMap<>(); - private final static AdjacentBlockRecord[] POSSIBLE_NEIGHBOURS = { +public class DoorsModule implements ModuleInterface { + private final String cn = getClass().getSimpleName(); + private static final VanillaPlus VP = VanillaPlus.getInstance(); + private static final FileConfiguration FC = VP.getConfig(); + private static final AdjacentBlockRecord[] POSSIBLE_NEIGHBOURS = { new AdjacentBlockRecord(0, -1, Door.Hinge.RIGHT, BlockFace.EAST), new AdjacentBlockRecord(0, 1, Door.Hinge.LEFT, BlockFace.EAST), @@ -77,9 +43,10 @@ public class DoorsModule implements Modular { new AdjacentBlockRecord(-1, 0, Door.Hinge.RIGHT, BlockFace.NORTH), new AdjacentBlockRecord(1, 0, Door.Hinge.LEFT, BlockFace.NORTH) }; + private final HashMap autoClose = new HashMap<>(); { - Bukkit.getScheduler().runTaskTimer(vp, () -> { + Bukkit.getScheduler().runTaskTimer(VP, () -> { Iterator> it = autoClose.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); @@ -87,13 +54,12 @@ public class DoorsModule implements Modular { Long time = entry.getValue(); if (System.currentTimeMillis() < time) continue; - if (b.getBlockData() instanceof Openable) { - Openable openable = (Openable) b.getBlockData(); + if (b.getBlockData() instanceof Openable openable) { if (openable.isOpen()) { if (openable instanceof Door) { - Block otherDoor = this.getOtherPart((Door) openable, b); + Block otherDoor = getOtherPart((Door) openable, b); if (otherDoor != null) { - this.toggleOtherDoor(b, otherDoor, false); + toggleOtherDoor(b, otherDoor, false); } } else if (openable instanceof Gate) { b.getWorld().playSound(b.getLocation(), Sound.BLOCK_FENCE_GATE_CLOSE, 1.0f, 1.0f); @@ -119,61 +85,49 @@ public void onRightClick(PlayerInteractEvent e) { || e.getAction() != Action.RIGHT_CLICK_BLOCK || e.useInteractedBlock() == Event.Result.DENY || e.useItemInHand() == Event.Result.DENY - || !e.getPlayer().hasPermission(PERMS.DOORSMODULE.USE) - || !(blockData instanceof Door || blockData instanceof Gate)) - return; - - if (!db.getData(className + ALLOW_DOUBLEDOORS, Boolean.class)) { - vp.getLogger() - .warning("Double doors are disabled. ALLOW_DOUBLEDOORS value: " - + db.getData(className + ALLOW_DOUBLEDOORS, Boolean.class)); + || !e.getPlayer().hasPermission(PERMS.USE) + || !(blockData instanceof Door || blockData instanceof Gate) + || !FC.getBoolean(cn + CONFIG.ALLOW_DOUBLEDOORS)) return; - } if (blockData instanceof Door) { - Door door = this.getBottomDoor((Door) blockData, clickedBlock); - Block otherDoorBlock = this.getOtherPart(door, clickedBlock); - if (otherDoorBlock != null && otherDoorBlock.getBlockData() instanceof Door) { - Door otherDoor = (Door) otherDoorBlock.getBlockData(); - this.toggleOtherDoor(clickedBlock, otherDoorBlock, !otherDoor.isOpen()); - autoClose.put(otherDoorBlock, - System.currentTimeMillis() - + db.getData(className + AUTOCLOSE_DELAY, Long.class) * 1000); + Door door = getBottomDoor((Door) blockData, clickedBlock); + Block otherDoorBlock = getOtherPart(door, clickedBlock); + if (otherDoorBlock != null && otherDoorBlock.getBlockData() instanceof Door otherDoor) { + toggleOtherDoor(clickedBlock, otherDoorBlock, !otherDoor.isOpen()); + if (e.getPlayer().hasPermission(PERMS.AUTOCLOSE)) { + autoClose.put(otherDoorBlock, + System.currentTimeMillis() + + FC.getLong(cn + CONFIG.AUTOCLOSE_DELAY) * 1000); + } } } - autoClose.put(clickedBlock, - System.currentTimeMillis() + db.getData(className + AUTOCLOSE_DELAY, Long.class) * 1000); + if (e.getPlayer().hasPermission(PERMS.AUTOCLOSE)) { + autoClose.put(clickedBlock, + System.currentTimeMillis() + FC.getLong(cn + CONFIG.AUTOCLOSE_DELAY) * 1000); + } } @EventHandler public void onKnock(PlayerInteractEvent e) { Player p = e.getPlayer(); - GameMode gm = p.getGameMode(); - if (gm == GameMode.CREATIVE || gm == GameMode.SPECTATOR) - return; - - if (!p.hasPermission(PERMS.DOORSMODULE.KNOCK) || e.getAction() != Action.LEFT_CLICK_BLOCK - || e.getHand() != EquipmentSlot.HAND) - return; - - if (db.getData(className + KNOCKING_REQUIRES_SHIFT, Boolean.class) && !p.isSneaking()) - return; - - if (db.getData(className + KNOCKING_REQUIRES_EMPTY_HAND, Boolean.class) - && p.getInventory().getItemInMainHand().getType() != Material.AIR) - return; - - if (e.getClickedBlock() == null) + if (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR + || !p.hasPermission(PERMS.KNOCK) || e.getAction() != Action.LEFT_CLICK_BLOCK + || e.getHand() != EquipmentSlot.HAND + || (FC.getBoolean(cn + CONFIG.KNOCKING_REQUIRES_SHIFT) && !p.isSneaking()) + || (FC.getBoolean(cn + CONFIG.KNOCKING_REQUIRES_EMPTY_HAND) + && p.getInventory().getItemInMainHand().getType() != Material.AIR) + || e.getClickedBlock() == null) return; Block block = e.getClickedBlock(); BlockData blockData = block.getBlockData(); - if ((blockData instanceof Door && db.getData(className + ALLOW_KNOCKING, Boolean.class)) - || (blockData instanceof TrapDoor && db.getData(className + ALLOW_KNOCKING_TRAPDOORS, Boolean.class)) - || (blockData instanceof Gate && db.getData(className + ALLOW_KNOCKING_GATES, Boolean.class))) { - this.playKnockSound(block); + if ((blockData instanceof Door && FC.getBoolean(cn + CONFIG.ALLOW_KNOCKING)) + || (blockData instanceof TrapDoor && FC.getBoolean(cn + CONFIG.ALLOW_KNOCKING_TRAPDOORS)) + || (blockData instanceof Gate && FC.getBoolean(cn + CONFIG.ALLOW_KNOCKING_GATES))) { + playKnockSound(block); } } @@ -184,18 +138,41 @@ public void playKnockSound(Block block) { .ofNullable( Registry.SOUNDS .get(NamespacedKey.minecraft( - db.getData(className + SOUND_KNOCK_WOOD, String.class).toLowerCase()))) + Objects.requireNonNull(FC.getString(cn + CONFIG.SOUND_KNOCK_WOOD)).toLowerCase()))) .orElse(Sound.ITEM_SHIELD_BLOCK); SoundCategory category = Enums .getIfPresent(SoundCategory.class, - db.getData(className + SOUND_KNOCK_CATEGORY, String.class).toUpperCase()) + Objects.requireNonNull(FC.getString(cn + CONFIG.SOUND_KNOCK_CATEGORY)).toUpperCase()) .or(SoundCategory.BLOCKS); - float volume = db.getData(className + SOUND_KNOCK_VOLUME, Float.class); - float pitch = db.getData(className + SOUND_KNOCK_PITCH, Float.class); + float volume = (float) FC.getInt(cn + CONFIG.SOUND_KNOCK_VOLUME); + float pitch = (float) FC.getInt(cn + CONFIG.SOUND_KNOCK_PITCH); world.playSound(loc, sound, category, volume, pitch); } + public void toggleOtherDoor(Block block, Block otherBlock, boolean open) { + if (!(block.getBlockData() instanceof Door door) || !(otherBlock.getBlockData() instanceof Door otherDoor)) + return; + + new BukkitRunnable() { + @Override + public void run() { + if (!(otherBlock.getBlockData() instanceof Door)) + return; + Door newDoor = (Door) block.getBlockData(); + if (newDoor.isOpen() == door.isOpen()) { + return; + } + DoorsModule.toggleDoor(otherBlock, otherDoor, open); + } + }.runTaskLater(VP, 1L); + } + + @Override + public boolean enabled() { + return FC.getBoolean(cn + CONFIG.ENABLE); + } + public static void toggleDoor(Block doorBlock, Openable openable, boolean open) { openable.setOpen(open); doorBlock.setBlockData(openable); @@ -228,46 +205,47 @@ public Block getOtherPart(Door door, Block block) { return null; } - public void toggleOtherDoor(Block block, Block otherBlock, boolean open) { - if (!(block.getBlockData() instanceof Door) || !(otherBlock.getBlockData() instanceof Door)) - return; - - Door door = (Door) block.getBlockData(); - Door otherDoor = (Door) otherBlock.getBlockData(); - - new BukkitRunnable() { - @Override - public void run() { - if (!(otherBlock.getBlockData() instanceof Door)) - return; - Door newDoor = (Door) block.getBlockData(); - if (newDoor.isOpen() == door.isOpen()) { - return; - } - DoorsModule.toggleDoor(otherBlock, otherDoor, open); - } - }.runTaskLater(vp, 1L); + @Override + public void config() { + FC.addDefault(cn + CONFIG.ENABLE, true); + FC.addDefault(cn + CONFIG.SOUND_KNOCK_CATEGORY, "BLOCKS"); + FC.addDefault(cn + CONFIG.SOUND_KNOCK_PITCH, 1.0); + FC.addDefault(cn + CONFIG.SOUND_KNOCK_VOLUME, 1.0); + FC.addDefault(cn + CONFIG.SOUND_KNOCK_WOOD, "entity_zombie_attack_wooden_door"); + FC.addDefault(cn + CONFIG.ALLOW_AUTOCLOSE, true); + FC.addDefault(cn + CONFIG.ALLOW_DOUBLEDOORS, true); + FC.addDefault(cn + CONFIG.ALLOW_KNOCKING, true); + FC.addDefault(cn + CONFIG.ALLOW_KNOCKING_GATES, true); + FC.addDefault(cn + CONFIG.ALLOW_KNOCKING_TRAPDOORS, true); + FC.addDefault(cn + CONFIG.KNOCKING_REQUIRES_EMPTY_HAND, true); + FC.addDefault(cn + CONFIG.KNOCKING_REQUIRES_SHIFT, false); + FC.addDefault(cn + CONFIG.AUTOCLOSE_DELAY, 6); + VP.saveConfig(); } - @Override - public boolean isEnabled() { - return db.getData(className + ENABLE, Boolean.class); + private interface CONFIG extends ModuleInterface.CONFIG { + // Sound settings + String SOUND_KNOCK_CATEGORY = ".sound_knock_category"; + String SOUND_KNOCK_PITCH = ".sound_knock_pitch"; + String SOUND_KNOCK_VOLUME = ".sound_knock_volume"; + String SOUND_KNOCK_WOOD = ".sound_knock_wood"; + + // Behavior settings + String ALLOW_AUTOCLOSE = ".allow_autoclose"; + String ALLOW_DOUBLEDOORS = ".allow_doubledoors"; + String ALLOW_KNOCKING = ".allow_knocking"; + String ALLOW_KNOCKING_GATES = ".allow_knocking_gates"; + String ALLOW_KNOCKING_TRAPDOORS = ".allow_knocking_trapdoors"; + String KNOCKING_REQUIRES_EMPTY_HAND = ".knocking_requires_empty_hand"; + String KNOCKING_REQUIRES_SHIFT = ".knocking_requires_shift"; + + // Auto-close settings + String AUTOCLOSE_DELAY = ".autoclose_delay"; } - @Override - public void config() { - db.setData(className + ENABLE, true); - db.setData(className + SOUND_KNOCK_CATEGORY, "BLOCKS"); - db.setData(className + SOUND_KNOCK_PITCH, 1.0); - db.setData(className + SOUND_KNOCK_VOLUME, 1.0); - db.setData(className + SOUND_KNOCK_WOOD, "entity_zombie_attack_wooden_door"); - db.setData(className + ALLOW_AUTOCLOSE, true); - db.setData(className + ALLOW_DOUBLEDOORS, true); - db.setData(className + ALLOW_KNOCKING, true); - db.setData(className + ALLOW_KNOCKING_GATES, true); - db.setData(className + ALLOW_KNOCKING_TRAPDOORS, true); - db.setData(className + KNOCKING_REQUIRES_EMPTY_HAND, true); - db.setData(className + KNOCKING_REQUIRES_SHIFT, false); - db.setData(className + AUTOCLOSE_DELAY, 6); + private interface PERMS { + String USE = VP.getClass().getSimpleName() + ".doubledoors"; + String KNOCK = VP.getClass().getSimpleName() + ".knock"; + String AUTOCLOSE = VP.getClass().getSimpleName() + ".autoclose"; } } diff --git a/src/main/java/org/xodium/vanillaplus/modules/ElevatorModule.java b/src/main/java/org/xodium/vanillaplus/modules/ElevatorModule.java deleted file mode 100644 index 6668728..0000000 --- a/src/main/java/org/xodium/vanillaplus/modules/ElevatorModule.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.xodium.vanillaplus.modules; - -import org.xodium.vanillaplus.Database; -import org.xodium.vanillaplus.interfaces.Modular; - -public class ElevatorModule implements Modular { - private final String className = getClass().getSimpleName(); - private final Database db = new Database(); - - @Override - public boolean isEnabled() { - return db.getData(className + ENABLE, Boolean.class); - } - - @Override - public void config() { - db.setData(className + ENABLE, true); - } - -} diff --git a/src/main/java/org/xodium/vanillaplus/modules/SaplingModule.java b/src/main/java/org/xodium/vanillaplus/modules/SaplingModule.java new file mode 100644 index 0000000..c06b291 --- /dev/null +++ b/src/main/java/org/xodium/vanillaplus/modules/SaplingModule.java @@ -0,0 +1,23 @@ +package org.xodium.vanillaplus.modules; + +import org.bukkit.configuration.file.FileConfiguration; +import org.xodium.vanillaplus.VanillaPlus; +import org.xodium.vanillaplus.interfaces.ModuleInterface; + +public class SaplingModule implements ModuleInterface { + private final String cn = getClass().getSimpleName(); + private static final VanillaPlus VP = VanillaPlus.getInstance(); + private static final FileConfiguration FC = VP.getConfig(); + + @Override + public boolean enabled() { + return FC.getBoolean(cn + CONFIG.ENABLE); + } + + @Override + public void config() { + FC.addDefault(cn + CONFIG.ENABLE, true); + VP.saveConfig(); + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..3ebc95d --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,17 @@ +DoorsModule: + enable: true + sound_knock_category: "BLOCKS" + sound_knock_pitch: 1.0 + sound_knock_volume: 1.0 + sound_knock_wood: "entity_zombie_attack_wooden_door" + allow_autoclose: true + allow_doubledoors: true + allow_knocking: true + allow_knocking_gates: true + allow_knocking_trapdoors: true + knocking_requires_empty_hand: true + knocking_requires_shift: false + autoclose_delay: 6 + +SaplingModule: + enable: false \ No newline at end of file diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index 3c0d960..fafb1ab 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -1,17 +1,17 @@ name: VanillaPlus -version: 1.1.4 +version: 1.2.0 main: org.xodium.vanillaplus.VanillaPlus description: Minecraft plugin that enhances the base gameplay. -api-version: 1.21.3 +api-version: 1.21.4 authors: - XodiumSoftware permissions: - vanillaplus.doubledoors: + VanillaPlus.doubledoors: description: Allows to open double doors with one click default: true - vanillaplus.knock: + VanillaPlus.knock: description: Allows to knock on doors using left-click default: true - vanillaplus.autoclose: + VanillaPlus.autoclose: description: Allows players to have their doors close automatically default: true