From 7d1e575a8c992654b7c5c6905a8b4c153d6a87f9 Mon Sep 17 00:00:00 2001 From: MiniDay <372403923@qq.com> Date: Tue, 6 Jun 2023 22:58:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(hamster-protect-farmland):=20=E5=AE=8C?= =?UTF-8?q?=E6=88=90=20hamster-protect-farmland=20=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hamster-protect-farmland/build.gradle | 2 ++ .../farmland/FarmlandProtectPlugin.java | 35 +++++++++++++++++++ .../src/main/resources/plugin.yml | 8 +++++ settings.gradle | 1 + 4 files changed, 46 insertions(+) create mode 100644 hamster-protect-farmland/build.gradle create mode 100644 hamster-protect-farmland/src/main/java/cn/hamster3/mc/plugin/protect/farmland/FarmlandProtectPlugin.java create mode 100644 hamster-protect-farmland/src/main/resources/plugin.yml diff --git a/hamster-protect-farmland/build.gradle b/hamster-protect-farmland/build.gradle new file mode 100644 index 0000000..ea59cf5 --- /dev/null +++ b/hamster-protect-farmland/build.gradle @@ -0,0 +1,2 @@ +version '1.0.0' +setArchivesBaseName("HamsterProtect-Farmland") diff --git a/hamster-protect-farmland/src/main/java/cn/hamster3/mc/plugin/protect/farmland/FarmlandProtectPlugin.java b/hamster-protect-farmland/src/main/java/cn/hamster3/mc/plugin/protect/farmland/FarmlandProtectPlugin.java new file mode 100644 index 0000000..11faf84 --- /dev/null +++ b/hamster-protect-farmland/src/main/java/cn/hamster3/mc/plugin/protect/farmland/FarmlandProtectPlugin.java @@ -0,0 +1,35 @@ +package cn.hamster3.mc.plugin.protect.farmland; + +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class FarmlandProtectPlugin extends JavaPlugin implements Listener { + @Override + public void onEnable() { + Bukkit.getPluginManager().registerEvents(this, this); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) + public void trampleProtect(EntityInteractEvent event) { + if (event.getEntityType() == EntityType.FALLING_BLOCK) { + return; + } + Block block = event.getBlock(); + switch (block.getType()) { + case FARMLAND: + case SOUL_SAND: { + break; + } + default: { + return; + } + } + event.setCancelled(true); + } +} diff --git a/hamster-protect-farmland/src/main/resources/plugin.yml b/hamster-protect-farmland/src/main/resources/plugin.yml new file mode 100644 index 0000000..e50bbf7 --- /dev/null +++ b/hamster-protect-farmland/src/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: HamsterProtect-Farmland +main: cn.hamster3.mc.plugin.protect.farmland.FarmlandProtectPlugin +version: ${version} +api-version: 1.13 + +author: MiniDay +website: https://github.com/MiniDay/hamster-little-plugins +description: 耕地践踏保护 diff --git a/settings.gradle b/settings.gradle index bfb2f39..cd13bf8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,5 @@ include 'hamster-tpa' include 'hamster-join-message' include 'hamster-protect-explosion' include 'hamster-protect-piston-wool-carpet' +include 'hamster-protect-farmland'