From 3fa46142492843a24dfba5553862d41a8d67086d Mon Sep 17 00:00:00 2001 From: shockpast Date: Thu, 25 Jul 2024 22:19:40 +0300 Subject: [PATCH] feat: moved tweak events to split file chore: moved from intellij idea to vscode chore: commented all tweaks in config.yml build: removed paperweight since it's not being used build: added run-paper plugin for debugging purposes --- .editorconfig | 7 ++ .gitignore | 6 +- .vscode/settings.json | 3 +- build.gradle | 21 ++-- src/main/java/me/shockpast/roflan/Roflan.java | 6 +- .../me/shockpast/roflan/commands/Tweak.java | 1 + .../roflan/listeners/TweakListener.java | 99 +++++++++++++++++++ src/main/resources/config.yml | 14 ++- 8 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 .editorconfig create mode 100644 src/main/java/me/shockpast/roflan/listeners/TweakListener.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7387919 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true +charset = utf-8 + +[*.java] +indent_style = space +indent_size = 4 +tab_width = 4 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7477b27..cccc3b2 100644 --- a/.gitignore +++ b/.gitignore @@ -108,4 +108,8 @@ nb-configuration.xml .nb-gradle/ ### MacOS ### -.DS_Store \ No newline at end of file +.DS_Store + + +### +run/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ca4d0b..e90aa2d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.compile.nullAnalysis.mode": "automatic" + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "automatic" } \ No newline at end of file diff --git a/build.gradle b/build.gradle index d435f69..d6fd070 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ plugins { id("java") - id("io.papermc.paperweight.userdev") version "1.7.1" + // id("io.papermc.paperweight.userdev") version "1.7.1" + id("xyz.jpenilla.run-paper") version "2.3.0" } -group = 'me.shockpast' -version = '1.0-SNAPSHOT' +group = "me.shockpast" +version = "1.0-SNAPSHOT" repositories { mavenCentral() @@ -21,7 +22,7 @@ repositories { dependencies { compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") - paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") + // paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") } def targetJavaVersion = 21 @@ -36,8 +37,14 @@ java { } } +tasks { + runServer { + minecraftVersion("1.21") + } +} + tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' + options.encoding = "UTF-8" if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { options.release.set(targetJavaVersion) @@ -47,8 +54,8 @@ tasks.withType(JavaCompile).configureEach { processResources { def props = [version: version] inputs.properties props - filteringCharset 'UTF-8' - filesMatching('paper-plugin.yml') { + filteringCharset "UTF-8" + filesMatching("paper-plugin.yml") { expand props } } diff --git a/src/main/java/me/shockpast/roflan/Roflan.java b/src/main/java/me/shockpast/roflan/Roflan.java index 50ffe34..eddc12d 100644 --- a/src/main/java/me/shockpast/roflan/Roflan.java +++ b/src/main/java/me/shockpast/roflan/Roflan.java @@ -3,7 +3,6 @@ import me.shockpast.roflan.commands.*; import me.shockpast.roflan.listeners.*; import org.bukkit.Server; -import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -22,6 +21,7 @@ public void onEnable() { // pluginManager.registerEvents(new PlayerListener(this, data), this); pluginManager.registerEvents(new EntityListener(this), this); + pluginManager.registerEvents(new TweakListener(this), this); // getCommand("vanish").setExecutor(new Vanish(this, data)); @@ -30,9 +30,5 @@ public void onEnable() { getCommand("report").setExecutor(new Report(data)); getCommand("item").setExecutor(new Item()); getCommand("tweak").setExecutor(new Tweak(this)); - - // Additional Permissions - pluginManager.addPermission(new Permission("roflan.command.report.send")); - pluginManager.addPermission(new Permission("roflan.command.report.close")); } } diff --git a/src/main/java/me/shockpast/roflan/commands/Tweak.java b/src/main/java/me/shockpast/roflan/commands/Tweak.java index 00c8dff..60918f9 100644 --- a/src/main/java/me/shockpast/roflan/commands/Tweak.java +++ b/src/main/java/me/shockpast/roflan/commands/Tweak.java @@ -2,6 +2,7 @@ import me.shockpast.roflan.constants.Colors; import net.kyori.adventure.text.Component; + import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; diff --git a/src/main/java/me/shockpast/roflan/listeners/TweakListener.java b/src/main/java/me/shockpast/roflan/listeners/TweakListener.java new file mode 100644 index 0000000..493c79a --- /dev/null +++ b/src/main/java/me/shockpast/roflan/listeners/TweakListener.java @@ -0,0 +1,99 @@ +package me.shockpast.roflan.listeners; + +import java.util.List; + +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.java.JavaPlugin; + +import io.papermc.paper.event.player.PlayerItemCooldownEvent; + +public class TweakListener implements Listener { + private final JavaPlugin plugin; + private final FileConfiguration config; + + public TweakListener(JavaPlugin plugin) { + this.plugin = plugin; + this.config = plugin.getConfig(); + } + + @EventHandler + public void creativeNetherWaterPlacement(PlayerBucketEmptyEvent event) { + if (!config.getBoolean("tweaks.creativeNetherWaterPlacement")) + return; + + World world = event.getBlock().getWorld(); + if (world.getEnvironment() != Environment.NETHER) + return; + + Block block = event.getBlockClicked(); + BlockFace blockFace = event.getBlockFace(); + + block.getRelative(blockFace) + .setType(Material.WATER); + } + + @EventHandler + public void creativeNoItemCooldown(PlayerItemCooldownEvent event) { + if (!config.getBoolean("tweaks.creativeNoItemCooldown")) + return; + + Player player = event.getPlayer(); + if (player.getGameMode() != GameMode.CREATIVE) + return; + + event.setCooldown(0); + } + + @EventHandler + public void creativeOpenContainerForcibly(PlayerInteractEvent event) { + if (!config.getBoolean("tweaks.creativeOpenContainerForcibly")) + return; + + Player player = event.getPlayer(); + if (player.getGameMode() != GameMode.CREATIVE) + return; + + Block block = event.getClickedBlock(); + if (block == null) + return; + if (!(block.getState() instanceof Chest)) + return; + + Chest chest = (Chest)block.getState(); + if (chest.isBlocked() || chest.isLocked()) { + player.openInventory(chest.getInventory()); + player.setMetadata("creativeOpenContainerForcibly", new FixedMetadataValue(plugin, chest)); + + chest.open(); + } + } + + @EventHandler + public void creativeOpenContainerForcibly_InventoryClose(InventoryCloseEvent event) { + Player player = (Player)event.getPlayer(); + if (player == null) + return; + + List meta = player.getMetadata("creativeOpenContainerForcibly"); + if (meta.isEmpty()) + return; + + Chest chest = (Chest)meta.getFirst().value(); + chest.close(); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6c3b242..624bb10 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,2 +1,14 @@ +# fabric-carpet but made as paper plugin tweaks: - explosionNoBlockDamage: false \ No newline at end of file + # explosions will be cancelled at last tick + # so it won't actually explode anything + explosionNoBlockDamage: false + # water can be placed if player is in creative + # (in nether) + creativeNetherWaterPlacement: false + # removes any cooldown from items for players + # that are in creative + creativeNoItemCooldown: false + # players in creative will open containers + # regardless of it's block/lock state + creativeOpenContainerForcibly: false \ No newline at end of file