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'