From 2c013e0eb42ebc212a42ee9fe449d2b2e9db4ae0 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 1 Aug 2024 16:06:56 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=B7=BB=E5=8A=A01.21?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lunadeer/dominion/Dominion.java | 4 +-- .../java/cn/lunadeer/dominion/dtos/Flag.java | 1 + ...erEvents.java => PlayerEvents_1_20_1.java} | 2 +- .../dominion/events/PlayerEvents_1_21.java | 31 +++++++++++++++++++ .../dominion/managers/ConfigManager.java | 2 +- 5 files changed, 36 insertions(+), 4 deletions(-) rename src/main/java/cn/lunadeer/dominion/events/{PlayerEvents.java => PlayerEvents_1_20_1.java} (99%) create mode 100644 src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/src/main/java/cn/lunadeer/dominion/Dominion.java index 477be07..7fbc8cd 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -1,7 +1,7 @@ package cn.lunadeer.dominion; import cn.lunadeer.dominion.events.EnvironmentEvents; -import cn.lunadeer.dominion.events.PlayerEvents; +import cn.lunadeer.dominion.events.PlayerEvents_1_20_1; import cn.lunadeer.dominion.events.SelectPointEvents; import cn.lunadeer.dominion.managers.ConfigManager; import cn.lunadeer.dominion.managers.DatabaseTables; @@ -41,7 +41,7 @@ public final class Dominion extends JavaPlugin { AutoClean.run(); Cache.instance = new Cache(); - Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this); + Bukkit.getPluginManager().registerEvents(new PlayerEvents_1_20_1(), this); Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this); Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this); Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands()); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index b774a13..1170857 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -25,6 +25,7 @@ public enum Flag { CAKE("cake", "吃蛋糕", "是否可以吃蛋糕", false, false, true), CONTAINER("container", "一般容器", "包含:箱子/木桶/潜影盒/盔甲架/展示框", false, false, true), CRAFT("craft", "使用工作台", "是否可以使用工作台", false, false, true), + CRAFTER("crafter", "合成器", "是否可以修改自动合成器", false, false, true), CREEPER_EXPLODE("creeper_explode", "实体爆炸", "包含:苦力怕/凋零头颅/末影水晶/火球", false, true, true), COMPARER("comparer", "比较器交互", "是否可以修改比较器状态", false, false, true), DOOR("door", "门交互", "是否可以使用各种材质的门(包括活板门)", false, false, true), diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java rename to src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java index 5a2f13e..527087d 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java @@ -33,7 +33,7 @@ import org.spigotmc.event.entity.EntityMountEvent; import static cn.lunadeer.dominion.events.Apis.checkFlag; import static cn.lunadeer.dominion.events.Apis.getInvDominion; -public class PlayerEvents implements Listener { +public class PlayerEvents_1_20_1 implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player bukkitPlayer = event.getPlayer(); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java new file mode 100644 index 0000000..cdd54e0 --- /dev/null +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java @@ -0,0 +1,31 @@ +package cn.lunadeer.dominion.events; + +import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.Flag; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; + +import org.bukkit.inventory.Inventory; +import org.bukkit.event.inventory.InventoryType; + +import static cn.lunadeer.dominion.events.Apis.checkFlag; +import static cn.lunadeer.dominion.events.Apis.getInvDominion; + +public class PlayerEvents_1_21 extends PlayerEvents_1_20_1 { + + @EventHandler(priority = EventPriority.HIGHEST) // crafter + public void onCrafterOpen(InventoryOpenEvent event) { + Inventory inv = event.getInventory(); + if (inv.getType() != InventoryType.CR) { + return; + } + if (!(event.getPlayer() instanceof Player)) { + return; + } + Player bukkitPlayer = (Player) event.getPlayer(); + DominionDTO dom = getInvDominion(bukkitPlayer, inv); + checkFlag(dom, Flag.CRAFTER, bukkitPlayer, event); + } +} diff --git a/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 1a312da..30e1ef7 100644 --- a/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -91,7 +91,7 @@ public class ConfigManager { _fly_permission_nodes = _file.getStringList("FlyPermissionNodes"); _residence_migration = _file.getBoolean("ResidenceMigration", false); saveAll(); // 回写文件 防止文件中的数据不完整 - Flag.loadFromJson(); + Flag.loadFromJson(); // 加载 Flag 配置 } public void saveAll() { From 60077737106565cde229efeba4f22f736a60a083 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 1 Aug 2024 17:06:57 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=87=B3gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 29 ++++++ gradle.properties | 0 gradle/wrapper/gradle-wrapper.properties | 1 + pom.xml | 109 ----------------------- settings.gradle.kts | 1 + src/main/resources/plugin.yml | 2 +- 6 files changed, 32 insertions(+), 110 deletions(-) create mode 100644 build.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.properties delete mode 100644 pom.xml create mode 100644 settings.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..72b01d2 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("java") + id("com.github.johnrengelman.shadow") version "8.1.1" +} + +group = "cn.lunadeer" +version = "1.42.9-beta" + +repositories { + mavenCentral() + maven("https://oss.sonatype.org/content/groups/public") + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://jitpack.io") + maven("https://repo.mikeprimm.com/") + maven("https://ssl.lunadeer.cn:14454/repository/maven-snapshots/") +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2") + compileOnly("us.dynmap:DynmapCoreAPI:3.4") + + shadow("cn.lunadeer:MinecraftPluginUtils:1.3.4-SNAPSHOT") + shadow("org.yaml:snakeyaml:2.0") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..0d8ab51 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip diff --git a/pom.xml b/pom.xml deleted file mode 100644 index d9a1b17..0000000 --- a/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - 4.0.0 - - cn.lunadeer - Dominion - 1.42.9-beta - jar - - Dominion - - - 1.8 - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - - src/main/resources - true - - - - - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - jitpack.io - https://jitpack.io - - - lunadeer-repo - https://ssl.lunadeer.cn:14454/repository/maven-snapshots/ - - - MikeRepo - https://repo.mikeprimm.com/ - - - - - - dev.folia - folia-api - 1.20.1-R0.1-SNAPSHOT - provided - - - cn.lunadeer - MinecraftPluginUtils - 1.3.4-SNAPSHOT - - - com.github.BlueMap-Minecraft - BlueMapAPI - v2.6.2 - provided - - - org.yaml - snakeyaml - 2.0 - - - us.dynmap - dynmap-api - 3.4-beta-3 - provided - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3b5f9f8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "Dominion" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9136a42..f6cd063 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: Dominion -version: '${project.version}' +version: '${version}' main: cn.lunadeer.dominion.Dominion api-version: '1.20' load: STARTUP From 49772fadc9f3cd41773c5002b571061f32c81c85 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 1 Aug 2024 18:03:21 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=88=B0gradle=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 9 +++++++-- src/main/java/cn/lunadeer/dominion/Dominion.java | 4 ++-- ...mentEvents.java => EnvironmentEvents_1_20_1.java} | 12 +++++++----- .../dominion/events/PlayerEvents_1_20_1.java | 9 ++------- .../lunadeer/dominion/events/PlayerEvents_1_21.java | 5 ++--- 5 files changed, 20 insertions(+), 19 deletions(-) rename src/main/java/cn/lunadeer/dominion/events/{EnvironmentEvents.java => EnvironmentEvents_1_20_1.java} (95%) diff --git a/build.gradle.kts b/build.gradle.kts index 72b01d2..9542a97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,10 +20,15 @@ dependencies { compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2") compileOnly("us.dynmap:DynmapCoreAPI:3.4") - shadow("cn.lunadeer:MinecraftPluginUtils:1.3.4-SNAPSHOT") - shadow("org.yaml:snakeyaml:2.0") + implementation("cn.lunadeer:MinecraftPluginUtils:1.3.4-SNAPSHOT") + implementation("org.yaml:snakeyaml:2.0") } java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } + +tasks.shadowJar { + archiveBaseName.set(rootProject.name) + archiveVersion.set(version.toString()) +} diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/src/main/java/cn/lunadeer/dominion/Dominion.java index 7fbc8cd..faa4463 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion; -import cn.lunadeer.dominion.events.EnvironmentEvents; +import cn.lunadeer.dominion.events.EnvironmentEvents_1_20_1; import cn.lunadeer.dominion.events.PlayerEvents_1_20_1; import cn.lunadeer.dominion.events.SelectPointEvents; import cn.lunadeer.dominion.managers.ConfigManager; @@ -42,7 +42,7 @@ public final class Dominion extends JavaPlugin { Cache.instance = new Cache(); Bukkit.getPluginManager().registerEvents(new PlayerEvents_1_20_1(), this); - Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this); + Bukkit.getPluginManager().registerEvents(new EnvironmentEvents_1_20_1(), this); Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this); Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands()); diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java similarity index 95% rename from src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java rename to src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java index d56dc7d..eb2931f 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java @@ -5,7 +5,6 @@ import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -22,7 +21,7 @@ import java.util.Objects; import static cn.lunadeer.dominion.events.Apis.checkFlag; import static org.bukkit.Material.FARMLAND; -public class EnvironmentEvents implements Listener { +public class EnvironmentEvents_1_20_1 implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); @@ -82,7 +81,8 @@ public class EnvironmentEvents implements Listener { return damager.getType() != EntityType.CREEPER && damager.getType() != EntityType.WITHER_SKULL && damager.getType() != EntityType.FIREBALL - && damager.getType() != EntityType.ENDER_CRYSTAL; + && damager.getType().getTypeId() != 200; + // 200 -> end_crystal } @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @@ -147,7 +147,8 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode public void onTntExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { + // 45 -> minecart_tnt, 20 -> primed_tnt + if (entity.getType().getTypeId() != 45 && entity.getType().getTypeId() != 20) { return; } event.blockList().removeIf(block -> { @@ -163,7 +164,8 @@ public class EnvironmentEvents implements Listener { return; } Entity damager = event.getDamager(); - if (damager.getType() != EntityType.PRIMED_TNT && damager.getType() != EntityType.MINECART_TNT) { + // 45 -> minecart_tnt, 20 -> primed_tnt + if (entity.getType().getTypeId() != 45 && entity.getType().getTypeId() != 20) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java index 527087d..9e41274 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java @@ -15,10 +15,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.*; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityPlaceEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; @@ -28,7 +25,6 @@ import org.bukkit.event.player.*; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.inventory.Inventory; import org.bukkit.material.Colorable; -import org.spigotmc.event.entity.EntityMountEvent; import static cn.lunadeer.dominion.events.Apis.checkFlag; import static cn.lunadeer.dominion.events.Apis.getInvDominion; @@ -706,10 +702,9 @@ public class PlayerEvents_1_20_1 implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // riding public void onRiding(EntityMountEvent event) { - if (!(event.getEntity() instanceof Player)) { + if (!(event.getEntity() instanceof Player player)) { return; } - Player player = (Player) event.getEntity(); DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); checkFlag(dom, Flag.RIDING, player, event); } diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java index cdd54e0..8bd04ab 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java @@ -18,13 +18,12 @@ public class PlayerEvents_1_21 extends PlayerEvents_1_20_1 { @EventHandler(priority = EventPriority.HIGHEST) // crafter public void onCrafterOpen(InventoryOpenEvent event) { Inventory inv = event.getInventory(); - if (inv.getType() != InventoryType.CR) { + if (inv.getType() != InventoryType.CRAFTER) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = getInvDominion(bukkitPlayer, inv); checkFlag(dom, Flag.CRAFTER, bukkitPlayer, event); } From 9180a2a4e0335a46889dd5ff43a79f8fd74aefdc Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 1 Aug 2024 23:06:01 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=811.21?= =?UTF-8?q?=E7=9A=84=E5=90=88=E6=88=90=E5=8F=B0=E6=9D=83=E9=99=90=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 34 +++++++++++++++---- .../java/cn/lunadeer/dominion/Dominion.java | 8 ++--- ...nts_1_20_1.java => EnvironmentEvents.java} | 15 ++++---- ...erEvents_1_20_1.java => PlayerEvents.java} | 22 ++++++++++-- .../dominion/events/PlayerEvents_1_21.java | 30 ---------------- src/main/resources/plugin.yml | 2 +- 6 files changed, 58 insertions(+), 53 deletions(-) rename src/main/java/cn/lunadeer/dominion/events/{EnvironmentEvents_1_20_1.java => EnvironmentEvents.java} (95%) rename src/main/java/cn/lunadeer/dominion/events/{PlayerEvents_1_20_1.java => PlayerEvents.java} (97%) delete mode 100644 src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java diff --git a/build.gradle.kts b/build.gradle.kts index 9542a97..db240b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,24 @@ + plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" } group = "cn.lunadeer" -version = "1.42.9-beta" +version = "1.43.0-beta" + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +// utf-8 +tasks.withType { + options.encoding = "UTF-8" +} repositories { mavenCentral() + mavenLocal() maven("https://oss.sonatype.org/content/groups/public") maven("https://repo.papermc.io/repository/maven-public/") maven("https://jitpack.io") @@ -17,6 +28,7 @@ repositories { dependencies { compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2") compileOnly("us.dynmap:DynmapCoreAPI:3.4") @@ -24,11 +36,19 @@ dependencies { implementation("org.yaml:snakeyaml:2.0") } -java { - toolchain.languageVersion.set(JavaLanguageVersion.of(21)) -} +tasks { + processResources { + // replace @version@ in plugin.yml with project version + filesMatching("**/plugin.yml") { + filter { + it.replace("@version@", project.version.toString()) + } + } + } -tasks.shadowJar { - archiveBaseName.set(rootProject.name) - archiveVersion.set(version.toString()) + shadowJar { + archiveClassifier.set("") + archiveVersion.set(project.version.toString()) + dependsOn(processResources) + } } diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/src/main/java/cn/lunadeer/dominion/Dominion.java index faa4463..477be07 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -1,7 +1,7 @@ package cn.lunadeer.dominion; -import cn.lunadeer.dominion.events.EnvironmentEvents_1_20_1; -import cn.lunadeer.dominion.events.PlayerEvents_1_20_1; +import cn.lunadeer.dominion.events.EnvironmentEvents; +import cn.lunadeer.dominion.events.PlayerEvents; import cn.lunadeer.dominion.events.SelectPointEvents; import cn.lunadeer.dominion.managers.ConfigManager; import cn.lunadeer.dominion.managers.DatabaseTables; @@ -41,8 +41,8 @@ public final class Dominion extends JavaPlugin { AutoClean.run(); Cache.instance = new Cache(); - Bukkit.getPluginManager().registerEvents(new PlayerEvents_1_20_1(), this); - Bukkit.getPluginManager().registerEvents(new EnvironmentEvents_1_20_1(), this); + Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this); + Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this); Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this); Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands()); diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java similarity index 95% rename from src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java rename to src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index eb2931f..1501b76 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents_1_20_1.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -10,7 +10,9 @@ import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; @@ -21,7 +23,7 @@ import java.util.Objects; import static cn.lunadeer.dominion.events.Apis.checkFlag; import static org.bukkit.Material.FARMLAND; -public class EnvironmentEvents_1_20_1 implements Listener { +public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); @@ -81,8 +83,7 @@ public class EnvironmentEvents_1_20_1 implements Listener { return damager.getType() != EntityType.CREEPER && damager.getType() != EntityType.WITHER_SKULL && damager.getType() != EntityType.FIREBALL - && damager.getType().getTypeId() != 200; - // 200 -> end_crystal + && damager.getType() != EntityType.END_CRYSTAL; } @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @@ -147,8 +148,7 @@ public class EnvironmentEvents_1_20_1 implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode public void onTntExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - // 45 -> minecart_tnt, 20 -> primed_tnt - if (entity.getType().getTypeId() != 45 && entity.getType().getTypeId() != 20) { + if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { return; } event.blockList().removeIf(block -> { @@ -164,8 +164,7 @@ public class EnvironmentEvents_1_20_1 implements Listener { return; } Entity damager = event.getDamager(); - // 45 -> minecart_tnt, 20 -> primed_tnt - if (entity.getType().getTypeId() != 45 && entity.getType().getTypeId() != 20) { + if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java similarity index 97% rename from src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java rename to src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 9e41274..6d12046 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_20_1.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -15,7 +15,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.*; -import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityMountEvent; +import org.bukkit.event.entity.EntityPlaceEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; @@ -29,7 +32,7 @@ import org.bukkit.material.Colorable; import static cn.lunadeer.dominion.events.Apis.checkFlag; import static cn.lunadeer.dominion.events.Apis.getInvDominion; -public class PlayerEvents_1_20_1 implements Listener { +public class PlayerEvents implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player bukkitPlayer = event.getPlayer(); @@ -325,6 +328,19 @@ public class PlayerEvents_1_20_1 implements Listener { checkFlag(dom, Flag.CRAFT, bukkitPlayer, event); } + @EventHandler(priority = EventPriority.HIGHEST) // crafter + public void onCrafterOpen(InventoryOpenEvent event) { + Inventory inv = event.getInventory(); + if (inv.getType() != InventoryType.CRAFTER) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, inv); + checkFlag(dom, Flag.CRAFTER, bukkitPlayer, event); + } + @EventHandler(priority = EventPriority.HIGHEST) // comparer public void comparerChange(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { @@ -620,7 +636,7 @@ public class PlayerEvents_1_20_1 implements Listener { Teleport.doTeleportSafely(player, to).thenAccept((success) -> { if (!success) { Notification.warn(player, "传送失败,你将被传送到复活点"); - player.teleportAsync(player.getBedSpawnLocation() == null ? + player.teleport(player.getBedSpawnLocation() == null ? player.getWorld().getSpawnLocation() : player.getBedSpawnLocation() , PlayerTeleportEvent.TeleportCause.PLUGIN); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java deleted file mode 100644 index 8bd04ab..0000000 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents_1_21.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.lunadeer.dominion.events; - -import cn.lunadeer.dominion.dtos.DominionDTO; -import cn.lunadeer.dominion.dtos.Flag; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryOpenEvent; - -import org.bukkit.inventory.Inventory; -import org.bukkit.event.inventory.InventoryType; - -import static cn.lunadeer.dominion.events.Apis.checkFlag; -import static cn.lunadeer.dominion.events.Apis.getInvDominion; - -public class PlayerEvents_1_21 extends PlayerEvents_1_20_1 { - - @EventHandler(priority = EventPriority.HIGHEST) // crafter - public void onCrafterOpen(InventoryOpenEvent event) { - Inventory inv = event.getInventory(); - if (inv.getType() != InventoryType.CRAFTER) { - return; - } - if (!(event.getPlayer() instanceof Player bukkitPlayer)) { - return; - } - DominionDTO dom = getInvDominion(bukkitPlayer, inv); - checkFlag(dom, Flag.CRAFTER, bukkitPlayer, event); - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f6cd063..51e3ef5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: Dominion -version: '${version}' +version: @version@ main: cn.lunadeer.dominion.Dominion api-version: '1.20' load: STARTUP From 36a32c1d7ba23741b42c521f627dd92a5c2be7f7 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 1 Aug 2024 23:10:51 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E9=83=A8=E5=88=86api?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 6d12046..a618ef8 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -636,7 +636,7 @@ public class PlayerEvents implements Listener { Teleport.doTeleportSafely(player, to).thenAccept((success) -> { if (!success) { Notification.warn(player, "传送失败,你将被传送到复活点"); - player.teleport(player.getBedSpawnLocation() == null ? + player.teleportAsync(player.getBedSpawnLocation() == null ? player.getWorld().getSpawnLocation() : player.getBedSpawnLocation() , PlayerTeleportEvent.TeleportCause.PLUGIN); From 86fe23421f24a53192ff94a4232a24c6c60802fa Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 10:19:24 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=9A=E6=8A=95=E6=8E=B7=E7=89=A9=E8=A7=A6=E5=8F=91=E5=8E=8B?= =?UTF-8?q?=E5=8A=9B=E6=9D=BF=20=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=9A=E7=94=9F=E7=89=A9=E8=A7=A6=E5=8F=91=E5=8E=8B=E5=8A=9B?= =?UTF-8?q?=E6=9D=BF=20=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90=EF=BC=9A?= =?UTF-8?q?=E6=8E=89=E8=90=BD=E7=89=A9=E8=A7=A6=E5=8F=91=E5=8E=8B=E5=8A=9B?= =?UTF-8?q?=E6=9D=BF=20=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90=EF=BC=9A?= =?UTF-8?q?=E6=8A=95=E6=8E=B7=E7=89=A9=E6=98=AF=E5=90=A6=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=A0=B4=E5=9D=8F=E5=B1=95=E7=A4=BA=E6=A1=86/=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../java/cn/lunadeer/dominion/dtos/Flag.java | 6 +- .../dominion/events/EnvironmentEvents.java | 66 ++++++++++++++++--- .../dominion/events/PlayerEvents.java | 15 +---- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index db240b9..1da69b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "cn.lunadeer" -version = "1.43.0-beta" +version = "1.44.0-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index 1170857..a38fb15 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -48,6 +48,7 @@ public enum Flag { HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true), IGNITE("ignite", "点燃", "是否可以使用打火石点火", false, false, true), ITEM_FRAME_INTERACTIVE("item_frame_interactive", "展示框交互", "是否可以与物品展示框交互(旋转展示框的东西)", false, false, true), + ITEM_FRAME_PROJ_DAMAGE("item_frame_proj_damage", "投掷物是否可以破坏展示框/画", "非玩家发出的投掷物是否可以破坏展示框/画等悬挂物", false, true, true), LEVER("lever", "使用拉杆", "是否可以使用拉杆", false, false, true), MOB_DROP_ITEM("mob_drop_item", "生物战利品掉落", "生物死亡时是否产生掉落物", true, true, true), MONSTER_KILLING("monster_killing", "对怪物造成伤害", "玩家是否可以对怪物造成伤害", false, false, true), @@ -59,12 +60,15 @@ public enum Flag { RIDING("riding", "骑乘载具", "是否可以骑乘各种载具", false, false, true), REPEATER("repeater", "中继器交互", "是否可以与中继器交互", false, false, true), SHEAR("shear", "剪羊毛", "是否可以剪羊毛", false, false, true), - SHOOT("shoot", "发射类型武器", "包括:射箭/雪球/三叉戟", false, false, true), + SHOOT("shoot", "投掷型武器", "包括:射箭/雪球/三叉戟/风弹", false, false, true), SHOW_BORDER("show_border", "显示领地边界", "是否显示领地边界", true, true, true), TELEPORT("teleport", "领地传送", "是否开启领地传送", false, false, true), TNT_EXPLODE("tnt_explode", "TNT爆炸", "TNT是否可以爆炸", false, true, true), TRADE("trade", "村民交易", "是否可以与村民交易", false, false, true), TRAMPLE("trample", "作物践踏", "是否可以践踏作物(关闭意味着保护耕地)", false, true, true), + TRIG_PRESSURE_PROJ("trig_pressure_proj", "投掷物触发压力板", "投掷物(箭/风弹/雪球)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_MOB("trig_pressure_mob", "生物触发压力板", "生物(不包含玩家)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_DROP("trig_pressure_drop", "掉落物触发压力板", "掉落物是否可以触发压力板", false, true, true), VEHICLE_DESTROY("vehicle_destroy", "破坏载具", "是否可以破坏载具(主要是矿车)", false, false, true), VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true), VILLAGER_KILLING("villager_killing", "对村民造成伤害", "是否可以对村民造成伤害", false, false, true), diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index 1501b76..b61d272 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -5,6 +5,7 @@ import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.Location; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -17,6 +18,8 @@ import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.material.PressurePlate; +import org.bukkit.material.PressureSensor; import java.util.Objects; @@ -61,22 +64,21 @@ public class EnvironmentEvents implements Listener { checkFlag(dom, Flag.CREEPER_EXPLODE, event); } - @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - other projectiles - public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) { - Entity entity = event.getEntity(); - if (!(entity instanceof ItemFrame)) { + @EventHandler(priority = EventPriority.HIGHEST) // item_frame_proj_damage + public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) { + if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) { return; } - ItemFrame itemFrame = (ItemFrame) entity; - if (!(event.getDamager() instanceof Projectile)) { + Entity remover = event.getRemover(); + if (!(remover instanceof Projectile projectile)) { return; } - Projectile arrow = (Projectile) event.getDamager(); - if (arrow.getShooter() instanceof Player) { + if (!(projectile.getShooter() instanceof Player)) { + // 玩家破坏由 玩家 break 权限控制 return; } - DominionDTO dom = Cache.instance.getDominionByLoc(itemFrame.getLocation()); - checkFlag(dom, Flag.CREEPER_EXPLODE, event); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); + checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event); } private static boolean isNotExplodeEntity(Entity damager) { @@ -187,6 +189,50 @@ public class EnvironmentEvents implements Listener { checkFlag(dom, Flag.TRAMPLE, event); } + /* + TRIG_PRESSURE_PROJ("trig_pressure_proj", "投掷物触发压力板", "投掷物(箭/风弹/雪球)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_MOB("trig_pressure_mob", "生物触发压力板", "生物(不包含玩家)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_DROP("trig_pressure_drop", "掉落物触发压力板", "掉落物是否可以触发压力板", false, true, true), + */ + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_proj + public void onPressurePlateTriggeredByProjectile(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Projectile)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_PROJ, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_mob + public void onPressurePlateTriggeredByMob(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Mob)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_MOB, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_drop + public void onPressurePlateTriggeredByDrop(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Item)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_DROP, event); + } + @EventHandler(priority = EventPriority.HIGHEST) // wither_spawn public void onWitherSpawn(CreatureSpawnEvent event) { Entity entity = event.getEntity(); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index a618ef8..d94ca1a 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -15,10 +15,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.*; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityMountEvent; -import org.bukkit.event.entity.EntityPlaceEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; @@ -748,16 +745,10 @@ public class PlayerEvents implements Listener { } @EventHandler(priority = EventPriority.HIGHEST) // shoot - public void onShootArrowSnowball(ProjectileLaunchEvent event) { - if (!(event.getEntity().getShooter() instanceof Player)) { + public void onShootArrowSnowball(ProjectileHitEvent event) { + if (!(event.getEntity().getShooter() instanceof Player player)) { return; } - if (event.getEntity().getType() != EntityType.ARROW && - event.getEntity().getType() != EntityType.SNOWBALL && - event.getEntity().getType() != EntityType.TRIDENT) { - return; - } - Player player = (Player) event.getEntity().getShooter(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); checkFlag(dom, Flag.SHOOT, player, event); } From 533063ee7cdb8a8e077b6f91a6fdb854c5e644e7 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 10:22:44 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0CI-CD=E4=BB=A5=E9=80=82?= =?UTF-8?q?=E9=85=8Dgradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 16fa5bf..16f780f 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -13,18 +13,16 @@ jobs: uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3 with: fetch-depth: 0 - - name: "Set up Maven" - uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4 - - name: "Set up JDK 17" + - name: "Set up JDK 21" uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3 with: - java-version: '17' + java-version: '21' distribution: 'zulu' - cache: maven - - name: "Build with Maven" - run: mvn -B package --file pom.xml + cache: gradle + - name: "Build with Gradle" + run: ./gradlew shadowJar - name: "Copy jar to staging" - run: mkdir staging && cp target/*.jar staging + run: mkdir staging && cp build/libs/*.jar staging/ - name: "Build & test" run: | echo "done!" From 8bee085eda75d00ecfcc4464d14657c611d708d4 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 10:23:32 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=96=B0=E5=A2=9Egradle=E4=BB=A5?= =?UTF-8?q?=E8=BE=85=E5=8A=A9cicd=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradlew | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gradlew.bat | 89 ++++++++++++++++++++ 2 files changed, 323 insertions(+) create mode 100755 gradlew create mode 100644 gradlew.bat diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega From 010e9386da93befd19fe426b809dd186bcdca7e1 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 16:08:01 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/lunadeer/dominion/dtos/Flag.java | 2 +- .../cn/lunadeer/dominion/tuis/dominion/DominionList.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index a38fb15..bef2b29 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -72,7 +72,7 @@ public enum Flag { VEHICLE_DESTROY("vehicle_destroy", "破坏载具", "是否可以破坏载具(主要是矿车)", false, false, true), VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true), VILLAGER_KILLING("villager_killing", "对村民造成伤害", "是否可以对村民造成伤害", false, false, true), - VILLAGER_SPAWN("villager_spawn", "村民繁殖", "是否允许村民繁殖", true, true, true), + VILLAGER_SPAWN("villager_spawn", "村民繁殖", "是否允许村民繁殖(包括村民蛋)", true, true, true), WITHER_SPAWN("wither_spawn", "凋零生成", "凋零生成", false, true, true), ; private final String flag_name; diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java b/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java index 8b852cc..743fe61 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java @@ -29,7 +29,7 @@ public class DominionList { view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("我的领地")); view.addLines(BuildTreeLines(DominionNode.BuildNodeTree(-1, DominionDTO.selectByOwner(player.getUniqueId())), 0)); List admin_dominions = playerAdminDominions(sender); - if (admin_dominions.size() != 0) { + if (!admin_dominions.isEmpty()) { view.add(Line.create().append("")); view.add(Line.create().append(Component.text("--- 以下为你拥有管理员权限的领地 ---", ViewStyles.main_color))); } @@ -43,9 +43,7 @@ public class DominionList { public static List BuildTreeLines(List dominionTree, Integer depth) { List lines = new ArrayList<>(); StringBuilder prefix = new StringBuilder(); - for (int i = 0; i < depth; i++) { - prefix.append(" | "); - } + prefix.append(" | ".repeat(Math.max(0, depth))); for (DominionNode node : dominionTree) { TextComponent manage = Button.createGreen("管理").setExecuteCommand("/dominion manage " + node.getDominion().getName()).build(); TextComponent delete = Button.createRed("删除").setExecuteCommand("/dominion delete " + node.getDominion().getName()).build(); From c74b332e651a789063fb8ae876987b49cfd43994 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 17:48:25 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=AF=B91.20.x?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../dominion/events/EnvironmentEvents.java | 20 +++--- .../dominion/events/PlayerEvents.java | 63 +++++++------------ 3 files changed, 32 insertions(+), 53 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1da69b2..5905255 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "cn.lunadeer" -version = "1.44.0-beta" +version = "1.44.1-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index b61d272..9a909e4 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -18,8 +18,6 @@ import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.material.PressurePlate; -import org.bukkit.material.PressureSensor; import java.util.Objects; @@ -57,7 +55,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ARMOR_STAND) { return; } - if (event.getDamager() instanceof Player) { + if (isNotExplodeEntity(event.getDamager())) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); @@ -82,10 +80,13 @@ public class EnvironmentEvents implements Listener { } private static boolean isNotExplodeEntity(Entity damager) { - return damager.getType() != EntityType.CREEPER - && damager.getType() != EntityType.WITHER_SKULL - && damager.getType() != EntityType.FIREBALL - && damager.getType() != EntityType.END_CRYSTAL; + String materialName = damager.getType().name(); + return !materialName.equals("creeper") + && !materialName.equals("wither_skull") + && !materialName.equals("fireball") + && !materialName.equals("end_crystal") + && !materialName.equals("dragon_fireball") + && !materialName.equals("small_fireball"); } @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @@ -150,7 +151,7 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode public void onTntExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { + if (!entity.getType().name().contains("tnt")) { return; } event.blockList().removeIf(block -> { @@ -165,8 +166,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ARMOR_STAND) { return; } - Entity damager = event.getDamager(); - if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { + if (!event.getDamager().getType().name().contains("tnt")) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index d94ca1a..3bf2d65 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -61,14 +61,13 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // animal_killing public void onAnimalKilling(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) { + if (!(event.getDamager() instanceof Player bukkitPlayer)) { return; } // 如果不是动物 则不处理 if (!(event.getEntity() instanceof Animals)) { return; } - Player bukkitPlayer = (Player) event.getDamager(); DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); } @@ -78,10 +77,9 @@ public class PlayerEvents implements Listener { if (event.getInventory().getType() != InventoryType.ANVIL) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.ANVIL, bukkitPlayer, event); } @@ -91,10 +89,9 @@ public class PlayerEvents implements Listener { if (event.getInventory().getType() != InventoryType.BEACON) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.BEACON, bukkitPlayer, event); } @@ -121,10 +118,9 @@ public class PlayerEvents implements Listener { if (event.getInventory().getType() != InventoryType.BREWING) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.BREW, bukkitPlayer, event); } @@ -231,10 +227,9 @@ public class PlayerEvents implements Listener { event.getInventory().getType() != InventoryType.SHULKER_BOX) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); if (hasContainerPermission(bukkitPlayer, event.getInventory().getLocation())) { return; } @@ -253,10 +248,9 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // container (item frame put) public void putSomeOnItemFrame(PlayerInteractEntityEvent event) { Entity entity = event.getRightClicked(); - if (!(entity instanceof ItemFrame)) { + if (!(entity instanceof ItemFrame itemFrame)) { return; } - ItemFrame itemFrame = (ItemFrame) entity; if (itemFrame.getItem().getType() != Material.AIR) { return; } @@ -270,17 +264,15 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // container (item frame get) public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); - if (!(entity instanceof ItemFrame)) { + if (!(entity instanceof ItemFrame itemFrame)) { return; } - ItemFrame itemFrame = (ItemFrame) entity; if (itemFrame.getItem().getType() == Material.AIR) { return; } - if (!(event.getDamager() instanceof Player)) { + if (!(event.getDamager() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getDamager(); if (hasContainerPermission(bukkitPlayer, entity.getLocation())) { return; } @@ -290,21 +282,18 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // container (item frame get) public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); - if (!(entity instanceof ItemFrame)) { + if (!(entity instanceof ItemFrame itemFrame)) { return; } - ItemFrame itemFrame = (ItemFrame) entity; if (itemFrame.getItem().getType() == Material.AIR) { return; } - if (!(event.getDamager() instanceof Arrow)) { + if (!(event.getDamager() instanceof Arrow arrow)) { return; } - Arrow arrow = (Arrow) event.getDamager(); - if (!(arrow.getShooter() instanceof Player)) { + if (!(arrow.getShooter() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) arrow.getShooter(); if (hasContainerPermission(bukkitPlayer, itemFrame.getLocation())) { return; } @@ -317,10 +306,9 @@ public class PlayerEvents implements Listener { if (inv.getType() != InventoryType.WORKBENCH) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = getInvDominion(bukkitPlayer, inv); checkFlag(dom, Flag.CRAFT, bukkitPlayer, event); } @@ -425,13 +413,12 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // egg public void onThrowingEgg(ProjectileLaunchEvent event) { - if (!(event.getEntity().getShooter() instanceof Player)) { + if (!(event.getEntity().getShooter() instanceof Player player)) { return; } if (event.getEntity().getType() != EntityType.EGG) { return; } - Player player = (Player) event.getEntity().getShooter(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); checkFlag(dom, Flag.EGG, player, event); } @@ -441,23 +428,21 @@ public class PlayerEvents implements Listener { if (event.getInventory().getType() != InventoryType.ENCHANTING) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); checkFlag(dom, Flag.ENCHANT, bukkitPlayer, event); } @EventHandler(priority = EventPriority.HIGHEST) // ender_pearl public void onThrowingEndPearl(ProjectileLaunchEvent event) { - if (!(event.getEntity().getShooter() instanceof Player)) { + if (!(event.getEntity().getShooter() instanceof Player player)) { return; } if (event.getEntity().getType() != EntityType.ENDER_PEARL) { return; } - Player player = (Player) event.getEntity().getShooter(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); checkFlag(dom, Flag.ENDER_PEARL, player, event); } @@ -542,10 +527,9 @@ public class PlayerEvents implements Listener { ) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); checkFlag(dom, Flag.HOPPER, bukkitPlayer, event); } @@ -563,10 +547,9 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // item_frame_interactive public void onItemFrameInteractive(PlayerInteractEntityEvent event) { Entity entity = event.getRightClicked(); - if (!(entity instanceof ItemFrame)) { + if (!(entity instanceof ItemFrame itemFrame)) { return; } - ItemFrame itemFrame = (ItemFrame) entity; if (itemFrame.getItem().getType() == Material.AIR) { // 为空则当作容器处理见 putSomeOnItemFrame return; @@ -596,7 +579,7 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // monster_killing public void onMonsterKilling(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) { + if (!(event.getDamager() instanceof Player bukkitPlayer)) { return; } // 如果不是怪物 则不处理 @@ -604,7 +587,6 @@ public class PlayerEvents implements Listener { if (!(entity instanceof Monster)) { return; } - Player bukkitPlayer = (Player) event.getDamager(); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); } @@ -758,20 +740,18 @@ public class PlayerEvents implements Listener { if (event.getInventory().getType() != InventoryType.MERCHANT) { return; } - if (!(event.getPlayer() instanceof Player)) { + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - Player bukkitPlayer = (Player) event.getPlayer(); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); checkFlag(dom, Flag.TRADE, bukkitPlayer, event); } @EventHandler(priority = EventPriority.HIGHEST) // vehicle_destroy public void onVehicleDestroy(VehicleDestroyEvent event) { - if (!(event.getAttacker() instanceof Player)) { + if (!(event.getAttacker() instanceof Player player)) { return; } - Player player = (Player) event.getAttacker(); DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); } @@ -792,13 +772,12 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // villager_killing public void onVillagerKilling(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) { + if (!(event.getDamager() instanceof Player player)) { return; } if (!(event.getEntity() instanceof Villager)) { return; } - Player player = (Player) event.getDamager(); DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.VILLAGER_KILLING, player, event); } From 4a8ae8b568da5bd0b20cd33a73a20985db1dc58b Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 2 Aug 2024 22:26:45 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E6=8F=90=E9=AB=981.20.x=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../dominion/events/EnvironmentEvents.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5905255..ed9c9b1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "cn.lunadeer" -version = "1.44.1-beta" +version = "1.44.2-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index 9a909e4..5e0c995 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -81,12 +81,10 @@ public class EnvironmentEvents implements Listener { private static boolean isNotExplodeEntity(Entity damager) { String materialName = damager.getType().name(); - return !materialName.equals("creeper") - && !materialName.equals("wither_skull") - && !materialName.equals("fireball") - && !materialName.equals("end_crystal") - && !materialName.equals("dragon_fireball") - && !materialName.equals("small_fireball"); + return !materialName.contains("CREEPER") + && !materialName.contains("WITHER_SKULL") + && !materialName.contains("FIREBALL") + && !materialName.contains("CRYSTAL"); } @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @@ -151,7 +149,8 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode public void onTntExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - if (!entity.getType().name().contains("tnt")) { + XLogger.debug("EntityExplodeEvent#name(): " + entity.getType().name()); + if (!entity.getType().name().contains("TNT")) { return; } event.blockList().removeIf(block -> { @@ -166,7 +165,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ARMOR_STAND) { return; } - if (!event.getDamager().getType().name().contains("tnt")) { + if (!event.getDamager().getType().name().contains("TNT")) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); From 0ad56e3c0bddf7a0aa147cc5cdac2893b4a1057d Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sat, 3 Aug 2024 08:37:15 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E6=8F=90=E9=AB=981.20.x=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 3 +-- .../lunadeer/dominion/events/PlayerEvents.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ed9c9b1..1fc8b38 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,10 @@ - plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" } group = "cn.lunadeer" -version = "1.44.2-beta" +version = "1.44.3-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 3bf2d65..8821ae4 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -4,6 +4,7 @@ import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.PlayerDTO; +import cn.lunadeer.minecraftpluginutils.Common; import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Teleport; import org.bukkit.Location; @@ -316,7 +317,8 @@ public class PlayerEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // crafter public void onCrafterOpen(InventoryOpenEvent event) { Inventory inv = event.getInventory(); - if (inv.getType() != InventoryType.CRAFTER) { + // InventoryType.CRAFTER; + if (!inv.getType().name().contains("CRAFTER")) { return; } if (!(event.getPlayer() instanceof Player bukkitPlayer)) { @@ -615,10 +617,16 @@ public class PlayerEvents implements Listener { Teleport.doTeleportSafely(player, to).thenAccept((success) -> { if (!success) { Notification.warn(player, "传送失败,你将被传送到复活点"); - player.teleportAsync(player.getBedSpawnLocation() == null ? - player.getWorld().getSpawnLocation() : - player.getBedSpawnLocation() - , PlayerTeleportEvent.TeleportCause.PLUGIN); + Location bed = player.getBedSpawnLocation(); + if (bed == null) { + bed = player.getWorld().getSpawnLocation(); + } + if (Common.isPaper()) { + player.teleportAsync(bed, PlayerTeleportEvent.TeleportCause.PLUGIN); + } else { + player.teleport(bed, PlayerTeleportEvent.TeleportCause.PLUGIN); + } + } }); } From 96c07e3067a356f3a1b8b06cb25af97d32510028 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sun, 4 Aug 2024 22:50:12 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=89=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E7=8E=A9=E5=AE=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BB=8Eres=E8=BF=81=E7=A7=BB=E9=A2=86=E5=9C=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../java/cn/lunadeer/dominion/utils/ResMigration.java | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1fc8b38..aa4c354 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "1.44.3-beta" +version = "1.44.4-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java b/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java index 96adcc4..e0aab35 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java +++ b/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java @@ -1,14 +1,12 @@ package cn.lunadeer.dominion.utils; import cn.lunadeer.dominion.Dominion; -import cn.lunadeer.dominion.dtos.PlayerDTO; import cn.lunadeer.dominion.utils.Residence.Message; import cn.lunadeer.dominion.utils.Residence.Permission; import cn.lunadeer.dominion.utils.Residence.Residence; import cn.lunadeer.dominion.utils.Residence.SaveFile; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.Location; -import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; import org.yaml.snakeyaml.Yaml; @@ -58,19 +56,13 @@ public class ResMigration { } private static ResidenceNode parseDominion(String name, World world, Residence res, SaveFile save) { - OfflinePlayer bukkitOwner = Dominion.instance.getServer().getOfflinePlayer(UUID.fromString(res.Permissions.OwnerUUID)); - PlayerDTO owner = PlayerDTO.get(bukkitOwner); - if (owner == null) { - XLogger.warn("Owner not found: " + res.Permissions.OwnerUUID); - return null; - } String[] loc = res.Areas.values().toArray()[0].toString().split(":"); if (loc.length != 6) { XLogger.warn("Invalid location: " + res.Areas.get("main")); return null; } ResidenceNode dominionNode = new ResidenceNode(); - dominionNode.owner = owner.getUuid(); + dominionNode.owner = UUID.fromString(res.Permissions.OwnerUUID); dominionNode.world = world; dominionNode.name = name; dominionNode.joinMessage = save.Messages.get(res.Messages).EnterMessage; From cabd3149ff6609aa8633379835d5cbf75f8e9257 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 5 Aug 2024 00:52:12 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=A4=9A=E6=A8=A1=E5=9D=97=E5=BC=95=E5=85=A5=E5=A4=9A=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=94=AF=E6=8C=81(=E7=BC=96=E8=AF=91=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=9C=89=E9=97=AE=E9=A2=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 44 +- core/build.gradle.kts | 26 + .../java/cn/lunadeer/dominion/AutoClean.java | 0 .../main/java/cn/lunadeer/dominion/Cache.java | 0 .../java/cn/lunadeer/dominion/Commands.java | 0 .../java/cn/lunadeer/dominion/Dominion.java | 8 +- .../cn/lunadeer/dominion/DominionNode.java | 0 .../cn/lunadeer/dominion/commands/Apis.java | 0 .../dominion/commands/DominionFlag.java | 0 .../dominion/commands/DominionOperate.java | 0 .../cn/lunadeer/dominion/commands/Group.java | 0 .../cn/lunadeer/dominion/commands/Helper.java | 0 .../cn/lunadeer/dominion/commands/Member.java | 0 .../lunadeer/dominion/commands/Migration.java | 0 .../lunadeer/dominion/commands/Operator.java | 0 .../lunadeer/dominion/commands/SetConfig.java | 0 .../lunadeer/dominion/commands/Template.java | 0 .../controllers/AbstractOperator.java | 0 .../lunadeer/dominion/controllers/Apis.java | 0 .../controllers/BukkitPlayerOperator.java | 0 .../controllers/DominionController.java | 0 .../dominion/controllers/FlagsController.java | 0 .../dominion/controllers/GroupController.java | 0 .../controllers/MemberController.java | 0 .../controllers/PlayerController.java | 0 .../controllers/TemplateController.java | 0 .../dominion/cuis/CreateDominion.java | 0 .../lunadeer/dominion/cuis/CreateGroup.java | 0 .../dominion/cuis/CreateTemplate.java | 0 .../dominion/cuis/EditJoinMessage.java | 0 .../dominion/cuis/EditLeaveMessage.java | 0 .../cn/lunadeer/dominion/cuis/MemberAdd.java | 0 .../dominion/cuis/RenameDominion.java | 0 .../lunadeer/dominion/cuis/RenameGroup.java | 0 .../lunadeer/dominion/cuis/SetMapColor.java | 0 .../lunadeer/dominion/dtos/DominionDTO.java | 0 .../java/cn/lunadeer/dominion/dtos/Flag.java | 0 .../cn/lunadeer/dominion/dtos/GroupDTO.java | 0 .../cn/lunadeer/dominion/dtos/MemberDTO.java | 0 .../cn/lunadeer/dominion/dtos/PlayerDTO.java | 0 .../dominion/dtos/PrivilegeTemplateDTO.java | 0 .../cn/lunadeer/dominion/events/Apis.java | 0 .../dominion/events/RegisterEvents.java | 62 ++ .../dominion/managers/ConfigManager.java | 0 .../dominion/managers/DatabaseTables.java | 0 .../lunadeer/dominion/tuis/AllDominion.java | 0 .../java/cn/lunadeer/dominion/tuis/Apis.java | 0 .../java/cn/lunadeer/dominion/tuis/Menu.java | 0 .../lunadeer/dominion/tuis/MigrateList.java | 0 .../cn/lunadeer/dominion/tuis/SysConfig.java | 0 .../dominion/tuis/dominion/DominionList.java | 0 .../tuis/dominion/DominionManage.java | 0 .../tuis/dominion/manage/EnvSetting.java | 0 .../tuis/dominion/manage/GuestSetting.java | 0 .../tuis/dominion/manage/SizeInfo.java | 0 .../tuis/dominion/manage/group/GroupList.java | 0 .../dominion/manage/group/GroupSetting.java | 0 .../dominion/manage/group/SelectMember.java | 0 .../dominion/manage/member/MemberList.java | 0 .../dominion/manage/member/MemberSetting.java | 0 .../dominion/manage/member/SelectPlayer.java | 0 .../manage/member/SelectTemplate.java | 0 .../dominion/tuis/template/TemplateList.java | 0 .../tuis/template/TemplateSetting.java | 0 .../dominion/utils/BlueMapConnect.java | 0 .../dominion/utils/DynmapConnect.java | 0 .../cn/lunadeer/dominion/utils/MapRender.java | 0 .../cn/lunadeer/dominion/utils/Particle.java | 0 .../lunadeer/dominion/utils/ResMigration.java | 0 .../dominion/utils/Residence/Message.java | 0 .../dominion/utils/Residence/Permission.java | 0 .../dominion/utils/Residence/Residence.java | 0 .../dominion/utils/Residence/SaveFile.java | 0 {src => core/src}/main/resources/config.yml | 0 {src => core/src}/main/resources/plugin.yml | 0 settings.gradle.kts | 8 +- v1_20_1/build.gradle.kts | 21 + .../events_v1_20_1/EnvironmentEvents.java | 294 +++++++ .../dominion/events_v1_20_1/PlayerEvents.java | 796 ++++++++++++++++++ .../events_v1_20_1/SelectPointEvents.java | 104 +++ v1_21/build.gradle.kts | 21 + .../events_v1_21}/EnvironmentEvents.java | 18 +- .../dominion/events_v1_21}/PlayerEvents.java | 2 +- .../events_v1_21}/SelectPointEvents.java | 2 +- 84 files changed, 1367 insertions(+), 39 deletions(-) create mode 100644 core/build.gradle.kts rename {src => core/src}/main/java/cn/lunadeer/dominion/AutoClean.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/Cache.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/Commands.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/Dominion.java (89%) rename {src => core/src}/main/java/cn/lunadeer/dominion/DominionNode.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Apis.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/DominionFlag.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/DominionOperate.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Group.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Helper.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Member.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Migration.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Operator.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/SetConfig.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/commands/Template.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/Apis.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/DominionController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/FlagsController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/GroupController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/MemberController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/PlayerController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/controllers/TemplateController.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/CreateGroup.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/CreateTemplate.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/EditJoinMessage.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/EditLeaveMessage.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/MemberAdd.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/RenameDominion.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/RenameGroup.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/Flag.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/events/Apis.java (100%) create mode 100644 core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java rename {src => core/src}/main/java/cn/lunadeer/dominion/managers/ConfigManager.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/AllDominion.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/Apis.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/Menu.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/MigrateList.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/SysConfig.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/DominionManage.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/EnvSetting.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/GuestSetting.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/SizeInfo.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupList.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupSetting.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/SelectMember.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberList.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberSetting.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectPlayer.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectTemplate.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/template/TemplateList.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/tuis/template/TemplateSetting.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/MapRender.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/Particle.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/ResMigration.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/Residence/Message.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/Residence/Permission.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/Residence/Residence.java (100%) rename {src => core/src}/main/java/cn/lunadeer/dominion/utils/Residence/SaveFile.java (100%) rename {src => core/src}/main/resources/config.yml (100%) rename {src => core/src}/main/resources/plugin.yml (100%) create mode 100644 v1_20_1/build.gradle.kts create mode 100644 v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java create mode 100644 v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java create mode 100644 v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java create mode 100644 v1_21/build.gradle.kts rename {src/main/java/cn/lunadeer/dominion/events => v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21}/EnvironmentEvents.java (94%) rename {src/main/java/cn/lunadeer/dominion/events => v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21}/PlayerEvents.java (99%) rename {src/main/java/cn/lunadeer/dominion/events => v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21}/SelectPointEvents.java (99%) diff --git a/build.gradle.kts b/build.gradle.kts index aa4c354..7c4b0ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,28 +15,30 @@ tasks.withType { options.encoding = "UTF-8" } -repositories { - mavenCentral() - mavenLocal() - maven("https://oss.sonatype.org/content/groups/public") - maven("https://repo.papermc.io/repository/maven-public/") - maven("https://jitpack.io") - maven("https://repo.mikeprimm.com/") - maven("https://ssl.lunadeer.cn:14454/repository/maven-snapshots/") -} +subprojects { + apply(plugin = "java") + apply(plugin = "com.github.johnrengelman.shadow") -dependencies { - compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + repositories { + mavenCentral() + mavenLocal() + maven("https://oss.sonatype.org/content/groups/public") + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://jitpack.io") + maven("https://repo.mikeprimm.com/") + maven("https://ssl.lunadeer.cn:14454/repository/maven-snapshots/") + } - compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2") - compileOnly("us.dynmap:DynmapCoreAPI:3.4") + dependencies { + compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2") + compileOnly("us.dynmap:DynmapCoreAPI:3.4") - implementation("cn.lunadeer:MinecraftPluginUtils:1.3.4-SNAPSHOT") - implementation("org.yaml:snakeyaml:2.0") -} + implementation("cn.lunadeer:MinecraftPluginUtils:1.3.4-SNAPSHOT") + implementation("org.yaml:snakeyaml:2.0") + } -tasks { - processResources { + + tasks.withType { // replace @version@ in plugin.yml with project version filesMatching("**/plugin.yml") { filter { @@ -45,9 +47,9 @@ tasks { } } - shadowJar { + tasks.withType { archiveClassifier.set("") archiveVersion.set(project.version.toString()) - dependsOn(processResources) + dependsOn(tasks.withType()) } -} +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 0000000..26e4a71 --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("java") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +// utf-8 +tasks.withType { + options.encoding = "UTF-8" +} + +repositories { + mavenCentral() + mavenLocal() + maven("https://oss.sonatype.org/content/groups/public") + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://jitpack.io") + maven("https://repo.mikeprimm.com/") + maven("https://ssl.lunadeer.cn:14454/repository/maven-snapshots/") +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") +} diff --git a/src/main/java/cn/lunadeer/dominion/AutoClean.java b/core/src/main/java/cn/lunadeer/dominion/AutoClean.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/AutoClean.java rename to core/src/main/java/cn/lunadeer/dominion/AutoClean.java diff --git a/src/main/java/cn/lunadeer/dominion/Cache.java b/core/src/main/java/cn/lunadeer/dominion/Cache.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/Cache.java rename to core/src/main/java/cn/lunadeer/dominion/Cache.java diff --git a/src/main/java/cn/lunadeer/dominion/Commands.java b/core/src/main/java/cn/lunadeer/dominion/Commands.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/Commands.java rename to core/src/main/java/cn/lunadeer/dominion/Commands.java diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/core/src/main/java/cn/lunadeer/dominion/Dominion.java similarity index 89% rename from src/main/java/cn/lunadeer/dominion/Dominion.java rename to core/src/main/java/cn/lunadeer/dominion/Dominion.java index 477be07..6df810f 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/core/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -1,8 +1,6 @@ package cn.lunadeer.dominion; -import cn.lunadeer.dominion.events.EnvironmentEvents; -import cn.lunadeer.dominion.events.PlayerEvents; -import cn.lunadeer.dominion.events.SelectPointEvents; +import cn.lunadeer.dominion.events.RegisterEvents; import cn.lunadeer.dominion.managers.ConfigManager; import cn.lunadeer.dominion.managers.DatabaseTables; import cn.lunadeer.dominion.utils.DynmapConnect; @@ -41,9 +39,7 @@ public final class Dominion extends JavaPlugin { AutoClean.run(); Cache.instance = new Cache(); - Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this); - Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this); - Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this); + new RegisterEvents(this); Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands()); bStatsMetrics metrics = new bStatsMetrics(this, 21445); diff --git a/src/main/java/cn/lunadeer/dominion/DominionNode.java b/core/src/main/java/cn/lunadeer/dominion/DominionNode.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/DominionNode.java rename to core/src/main/java/cn/lunadeer/dominion/DominionNode.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Apis.java b/core/src/main/java/cn/lunadeer/dominion/commands/Apis.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Apis.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Apis.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java b/core/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java rename to core/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java rename to core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Group.java b/core/src/main/java/cn/lunadeer/dominion/commands/Group.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Group.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Group.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Helper.java b/core/src/main/java/cn/lunadeer/dominion/commands/Helper.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Helper.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Helper.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Member.java b/core/src/main/java/cn/lunadeer/dominion/commands/Member.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Member.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Member.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Migration.java b/core/src/main/java/cn/lunadeer/dominion/commands/Migration.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Migration.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Migration.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Operator.java b/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Operator.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Operator.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java b/core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/SetConfig.java rename to core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java diff --git a/src/main/java/cn/lunadeer/dominion/commands/Template.java b/core/src/main/java/cn/lunadeer/dominion/commands/Template.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/commands/Template.java rename to core/src/main/java/cn/lunadeer/dominion/commands/Template.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java b/core/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/Apis.java b/core/src/main/java/cn/lunadeer/dominion/controllers/Apis.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/Apis.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/Apis.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java b/core/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/DominionController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/GroupController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/GroupController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/GroupController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/GroupController.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/MemberController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/PlayerController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/PlayerController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/PlayerController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/PlayerController.java diff --git a/src/main/java/cn/lunadeer/dominion/controllers/TemplateController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/TemplateController.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/controllers/TemplateController.java rename to core/src/main/java/cn/lunadeer/dominion/controllers/TemplateController.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java b/core/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/CreateGroup.java b/core/src/main/java/cn/lunadeer/dominion/cuis/CreateGroup.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/CreateGroup.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/CreateGroup.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/CreateTemplate.java b/core/src/main/java/cn/lunadeer/dominion/cuis/CreateTemplate.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/CreateTemplate.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/CreateTemplate.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/EditJoinMessage.java b/core/src/main/java/cn/lunadeer/dominion/cuis/EditJoinMessage.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/EditJoinMessage.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/EditJoinMessage.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/EditLeaveMessage.java b/core/src/main/java/cn/lunadeer/dominion/cuis/EditLeaveMessage.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/EditLeaveMessage.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/EditLeaveMessage.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/MemberAdd.java b/core/src/main/java/cn/lunadeer/dominion/cuis/MemberAdd.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/MemberAdd.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/MemberAdd.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/RenameDominion.java b/core/src/main/java/cn/lunadeer/dominion/cuis/RenameDominion.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/RenameDominion.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/RenameDominion.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/RenameGroup.java b/core/src/main/java/cn/lunadeer/dominion/cuis/RenameGroup.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/RenameGroup.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/RenameGroup.java diff --git a/src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java b/core/src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java rename to core/src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/Flag.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java rename to core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java diff --git a/src/main/java/cn/lunadeer/dominion/events/Apis.java b/core/src/main/java/cn/lunadeer/dominion/events/Apis.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/events/Apis.java rename to core/src/main/java/cn/lunadeer/dominion/events/Apis.java diff --git a/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java b/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java new file mode 100644 index 0000000..66f90ef --- /dev/null +++ b/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java @@ -0,0 +1,62 @@ +package cn.lunadeer.dominion.events; + +import cn.lunadeer.minecraftpluginutils.XLogger; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +public class RegisterEvents { + + private JavaPlugin plugin; + + public RegisterEvents(JavaPlugin plugin) { + APIVersion version = GetAPIVersion(plugin); + this.plugin = plugin; + if (version == null) { + return; + } + try { + switch (version) { + case v1_21: + registerEvents("cn.lunadeer.dominion.events_v1_21.PlayerEvents"); + registerEvents("cn.lunadeer.dominion.events_v1_21.EnvironmentEvents"); + registerEvents("cn.lunadeer.dominion.events_v1_21.SelectPointEvents"); + break; + case v1_20_1: + registerEvents("cn.lunadeer.dominion.events_v1_20_1.PlayerEvents"); + registerEvents("cn.lunadeer.dominion.events_v1_20_1.EnvironmentEvents"); + registerEvents("cn.lunadeer.dominion.events_v1_20_1.SelectPointEvents"); + break; + } + } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + XLogger.err("Failed to register events: %s", e.getMessage()); + plugin.getServer().getPluginManager().disablePlugin(plugin); + } + } + + enum APIVersion { + v1_21, + v1_20_1 + } + + private static APIVersion GetAPIVersion(JavaPlugin plugin) { + String version = plugin.getServer().getBukkitVersion(); + if (version.contains("1.21")) { + return APIVersion.v1_21; + } else if (version.contains("1.20.1") + || version.contains("1.20.4") + || version.contains("1.20.6")) { + return APIVersion.v1_20_1; + } + XLogger.err("Unsupported API version: %s", version); + plugin.getServer().getPluginManager().disablePlugin(plugin); + return null; + } + + private void registerEvents(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + Class clazz = Class.forName(className); + Listener listener = (Listener) clazz.newInstance(); + Bukkit.getPluginManager().registerEvents(listener, plugin); + } + +} diff --git a/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java rename to core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java diff --git a/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java b/core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java rename to core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java b/core/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/Apis.java b/core/src/main/java/cn/lunadeer/dominion/tuis/Apis.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/Apis.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/Apis.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/Menu.java b/core/src/main/java/cn/lunadeer/dominion/tuis/Menu.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/Menu.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/Menu.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/MigrateList.java b/core/src/main/java/cn/lunadeer/dominion/tuis/MigrateList.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/MigrateList.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/MigrateList.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java b/core/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionManage.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionManage.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionManage.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionManage.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/EnvSetting.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/EnvSetting.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/EnvSetting.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/EnvSetting.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/GuestSetting.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/GuestSetting.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/GuestSetting.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/GuestSetting.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/SizeInfo.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/SizeInfo.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/SizeInfo.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/SizeInfo.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupList.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupList.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupList.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupList.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupSetting.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupSetting.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupSetting.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/GroupSetting.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/SelectMember.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/SelectMember.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/SelectMember.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/group/SelectMember.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberList.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberList.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberList.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberList.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberSetting.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberSetting.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberSetting.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/MemberSetting.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectPlayer.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectPlayer.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectPlayer.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectPlayer.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectTemplate.java b/core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectTemplate.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectTemplate.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/dominion/manage/member/SelectTemplate.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateList.java b/core/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateList.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/template/TemplateList.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateList.java diff --git a/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateSetting.java b/core/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateSetting.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/tuis/template/TemplateSetting.java rename to core/src/main/java/cn/lunadeer/dominion/tuis/template/TemplateSetting.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java rename to core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java rename to core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/MapRender.java b/core/src/main/java/cn/lunadeer/dominion/utils/MapRender.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/MapRender.java rename to core/src/main/java/cn/lunadeer/dominion/utils/MapRender.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/Particle.java b/core/src/main/java/cn/lunadeer/dominion/utils/Particle.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/Particle.java rename to core/src/main/java/cn/lunadeer/dominion/utils/Particle.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java b/core/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/ResMigration.java rename to core/src/main/java/cn/lunadeer/dominion/utils/ResMigration.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/Residence/Message.java b/core/src/main/java/cn/lunadeer/dominion/utils/Residence/Message.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/Residence/Message.java rename to core/src/main/java/cn/lunadeer/dominion/utils/Residence/Message.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/Residence/Permission.java b/core/src/main/java/cn/lunadeer/dominion/utils/Residence/Permission.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/Residence/Permission.java rename to core/src/main/java/cn/lunadeer/dominion/utils/Residence/Permission.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/Residence/Residence.java b/core/src/main/java/cn/lunadeer/dominion/utils/Residence/Residence.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/Residence/Residence.java rename to core/src/main/java/cn/lunadeer/dominion/utils/Residence/Residence.java diff --git a/src/main/java/cn/lunadeer/dominion/utils/Residence/SaveFile.java b/core/src/main/java/cn/lunadeer/dominion/utils/Residence/SaveFile.java similarity index 100% rename from src/main/java/cn/lunadeer/dominion/utils/Residence/SaveFile.java rename to core/src/main/java/cn/lunadeer/dominion/utils/Residence/SaveFile.java diff --git a/src/main/resources/config.yml b/core/src/main/resources/config.yml similarity index 100% rename from src/main/resources/config.yml rename to core/src/main/resources/config.yml diff --git a/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml similarity index 100% rename from src/main/resources/plugin.yml rename to core/src/main/resources/plugin.yml diff --git a/settings.gradle.kts b/settings.gradle.kts index 3b5f9f8..6f5ea9f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,7 @@ -rootProject.name = "Dominion" \ No newline at end of file +rootProject.name = "Dominion" + +include( + "core", + "v1_20_1", + "v1_21" +) \ No newline at end of file diff --git a/v1_20_1/build.gradle.kts b/v1_20_1/build.gradle.kts new file mode 100644 index 0000000..8d4eee1 --- /dev/null +++ b/v1_20_1/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + id("java") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +// utf-8 +tasks.withType { + options.encoding = "UTF-8" +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly(project(":core")) + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") +} \ No newline at end of file diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java new file mode 100644 index 0000000..dcb7114 --- /dev/null +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java @@ -0,0 +1,294 @@ +package cn.lunadeer.dominion.events_v1_20_1; + +import cn.lunadeer.dominion.Cache; +import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.Flag; +import cn.lunadeer.minecraftpluginutils.XLogger; +import org.bukkit.Location; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.util.Objects; + +import static cn.lunadeer.dominion.events.Apis.checkFlag; +import static org.bukkit.Material.FARMLAND; + +public class EnvironmentEvents implements Listener { + @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode + public void onEntityExplode(EntityExplodeEvent event) { + Entity entity = event.getEntity(); + XLogger.debug("EntityExplodeEvent: " + entity.getType()); + if (isNotExplodeEntity(entity)) { + return; + } + XLogger.debug("blockList" + event.blockList().size()); + event.blockList().removeIf(block -> { + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + return !checkFlag(dom, Flag.CREEPER_EXPLODE, null); + }); + } + + @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - item frame + public void onItemFrameExploded(HangingBreakByEntityEvent event) { + Entity entity = event.getEntity(); + if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.CREEPER_EXPLODE, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - armor stand + public void onArmorStandExploded(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.ARMOR_STAND) { + return; + } + if (isNotExplodeEntity(event.getDamager())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.CREEPER_EXPLODE, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // item_frame_proj_damage + public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) { + if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) { + return; + } + Entity remover = event.getRemover(); + if (!(remover instanceof Projectile projectile)) { + return; + } + if (!(projectile.getShooter() instanceof Player)) { + // 玩家破坏由 玩家 break 权限控制 + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); + checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event); + } + + private static boolean isNotExplodeEntity(Entity damager) { + return damager.getType() != EntityType.CREEPER + && damager.getType() != EntityType.WITHER_SKULL + && damager.getType() != EntityType.FIREBALL + && damager.getType() != EntityType.ENDER_CRYSTAL + && damager.getType() != EntityType.SMALL_FIREBALL + && damager.getType() != EntityType.DRAGON_FIREBALL; + } + + @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block + public void onDragonBreakBlock(EntityExplodeEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.ENDER_DRAGON) { + return; + } + event.blockList().removeIf(block -> { + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + return !checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, null); + }); + } + + @EventHandler(priority = EventPriority.HIGHEST) // fire_spread + public void onFireSpread(BlockIgniteEvent event) { + Player player = event.getPlayer(); + if (player != null) { + // 如果点燃事件没有玩家触发,那么就是火焰蔓延 + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); + checkFlag(dom, Flag.FIRE_SPREAD, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // flow_in_protection + public void onLiquidFlowIn(BlockFromToEvent event) { + Location from = event.getBlock().getLocation(); + Location to = event.getToBlock().getLocation(); + DominionDTO dom_to = Cache.instance.getDominionByLoc(to); + if (dom_to == null) { + return; + } + DominionDTO dom_from = Cache.instance.getDominionByLoc(from); + if (dom_from != null) { + if (Objects.equals(dom_from.getId(), dom_to.getId())) { + return; + } + } + checkFlag(dom_to, Flag.FLOW_IN_PROTECTION, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // mob_drop_item + public void onMobDropItem(EntityDeathEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + if (dom == null) { + return; + } + if (!Flag.MOB_DROP_ITEM.getEnable()) { + return; + } + if (dom.getFlagValue(Flag.MOB_DROP_ITEM)) { + return; + } + event.getDrops().clear(); + } + + @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode + public void onTntExplode(EntityExplodeEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { + return; + } + event.blockList().removeIf(block -> { + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + return !checkFlag(dom, Flag.TNT_EXPLODE, null); + }); + } + + @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand + public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.ARMOR_STAND) { + return; + } + if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.TNT_EXPLODE, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trample + public void onFarmlandTrample(PlayerInteractEvent event) { + if (event.getAction() != Action.PHYSICAL) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (block.getType() != FARMLAND) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRAMPLE, event); + } + + /* + TRIG_PRESSURE_PROJ("trig_pressure_proj", "投掷物触发压力板", "投掷物(箭/风弹/雪球)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_MOB("trig_pressure_mob", "生物触发压力板", "生物(不包含玩家)是否可以触发压力板", false, true, true), + TRIG_PRESSURE_DROP("trig_pressure_drop", "掉落物触发压力板", "掉落物是否可以触发压力板", false, true, true), + */ + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_proj + public void onPressurePlateTriggeredByProjectile(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Projectile)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_PROJ, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_mob + public void onPressurePlateTriggeredByMob(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Mob)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_MOB, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_drop + public void onPressurePlateTriggeredByDrop(EntityInteractEvent event) { + if (!(event.getEntity() instanceof Item)) { + return; + } + Block block = event.getBlock(); + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.TRIG_PRESSURE_DROP, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // wither_spawn + public void onWitherSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.WITHER) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.WITHER_SPAWN, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // ender_man spawn + public void onEnderManSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.ENDERMAN) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.ENDER_MAN, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // ender_man escape + public void onEnderManEscape(EntityTeleportEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.ENDERMAN) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.ENDER_MAN, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // monster_spawn + public void onMonsterSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof Monster)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.MONSTER_SPAWN, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // animal_spawn + public void onAnimalSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof Animals)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.ANIMAL_SPAWN, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // villager_spawn + public void onVillagerSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.VILLAGER) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.VILLAGER_SPAWN, event); + } +} diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java new file mode 100644 index 0000000..6d7bcad --- /dev/null +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java @@ -0,0 +1,796 @@ +package cn.lunadeer.dominion.events_v1_20_1; + +import cn.lunadeer.dominion.Cache; +import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.Flag; +import cn.lunadeer.dominion.dtos.PlayerDTO; +import cn.lunadeer.minecraftpluginutils.Common; +import cn.lunadeer.minecraftpluginutils.Notification; +import cn.lunadeer.minecraftpluginutils.Teleport; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityPlaceEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.*; +import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.material.Colorable; +import org.spigotmc.event.entity.EntityMountEvent; + +import static cn.lunadeer.dominion.events.Apis.checkFlag; +import static cn.lunadeer.dominion.events.Apis.getInvDominion; + +public class PlayerEvents implements Listener { + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player bukkitPlayer = event.getPlayer(); + PlayerDTO player = PlayerDTO.get(bukkitPlayer); + player.onJoin(bukkitPlayer.getName()); // update name + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player bukkitPlayer = event.getPlayer(); + Cache.instance.onPlayerQuit(bukkitPlayer); + } + + @EventHandler(priority = EventPriority.HIGHEST) // anchor + public void onRespawnAnchor(PlayerRespawnEvent event) { + Player bukkitPlayer = event.getPlayer(); + if (!event.isAnchorSpawn()) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); + if (!checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) { + if (bukkitPlayer.getBedSpawnLocation() != null) { + event.setRespawnLocation(bukkitPlayer.getBedSpawnLocation()); + } else { + event.setRespawnLocation(bukkitPlayer.getWorld().getSpawnLocation()); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) // animal_killing + public void onAnimalKilling(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player bukkitPlayer)) { + return; + } + // 如果不是动物 则不处理 + if (!(event.getEntity() instanceof Animals)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); + checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // anvil + public void onAnvilUse(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.ANVIL) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); + checkFlag(dom, Flag.ANVIL, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // beacon + public void onBeaconUse(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.BEACON) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); + checkFlag(dom, Flag.BEACON, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // bed + public void onBedUse(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Player bukkitPlayer = event.getPlayer(); + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (!(Tag.BEDS.isTagged(block.getType()))) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.BED, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // brew + public void onBrewUse(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.BREWING) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); + checkFlag(dom, Flag.BREW, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // break + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + if (onBreak(player, event.getBlock().getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // break - item frame + public void onItemFrameBreak(HangingBreakByEntityEvent event) { + Entity entity = event.getEntity(); + if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) { + return; + } + if (entity instanceof ItemFrame) { + if (((ItemFrame) entity).getItem().getType() != Material.AIR) { + if (!hasContainerPermission((Player) event.getRemover(), entity.getLocation())) { + event.setCancelled(true); + return; + } + } + } + if (onBreak((Player) event.getRemover(), entity.getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // break - armor stand + public void onArmorStandBreak(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof ArmorStand)) { + return; + } + if (!(event.getDamager() instanceof Player)) { + return; + } + if (onBreak((Player) event.getDamager(), entity.getLocation())) { + return; + } + event.setCancelled(true); + } + + public static boolean onBreak(Player player, Location location) { + DominionDTO dom = Cache.instance.getDominionByLoc(location); + return checkFlag(dom, Flag.BREAK_BLOCK, player, null); + } + + @EventHandler(priority = EventPriority.HIGHEST) // button + public void onButton(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Player player = event.getPlayer(); + if (event.getClickedBlock() == null) { + return; + } + Block block = event.getClickedBlock(); + if (!Tag.BUTTONS.isTagged(block.getType())) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.BUTTON, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // cake + public void eatCake(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + Material clicked = block.getType(); + if (clicked != Material.CAKE) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.CAKE, player, event); + } + + // 检查是否有容器权限 + private static boolean hasContainerPermission(Player player, Location loc) { + DominionDTO dom; + if (loc == null) { + dom = null; + } else { + dom = Cache.instance.getDominionByLoc(loc); + } + return checkFlag(dom, Flag.CONTAINER, player, null); + } + + @EventHandler(priority = EventPriority.HIGHEST) // container + public void openContainer(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.CHEST && + event.getInventory().getType() != InventoryType.BARREL && + event.getInventory().getType() != InventoryType.SHULKER_BOX) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + if (hasContainerPermission(bukkitPlayer, event.getInventory().getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // container (armor stand) + public void manipulateArmorStand(PlayerArmorStandManipulateEvent event) { + Player bukkitPlayer = event.getPlayer(); + if (hasContainerPermission(bukkitPlayer, event.getRightClicked().getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // container (item frame put) + public void putSomeOnItemFrame(PlayerInteractEntityEvent event) { + Entity entity = event.getRightClicked(); + if (!(entity instanceof ItemFrame itemFrame)) { + return; + } + if (itemFrame.getItem().getType() != Material.AIR) { + return; + } + Player bukkitPlayer = event.getPlayer(); + if (hasContainerPermission(bukkitPlayer, entity.getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // container (item frame get) + public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof ItemFrame itemFrame)) { + return; + } + if (itemFrame.getItem().getType() == Material.AIR) { + return; + } + if (!(event.getDamager() instanceof Player bukkitPlayer)) { + return; + } + if (hasContainerPermission(bukkitPlayer, entity.getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // container (item frame get) + public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof ItemFrame itemFrame)) { + return; + } + if (itemFrame.getItem().getType() == Material.AIR) { + return; + } + if (!(event.getDamager() instanceof Arrow arrow)) { + return; + } + if (!(arrow.getShooter() instanceof Player bukkitPlayer)) { + return; + } + if (hasContainerPermission(bukkitPlayer, itemFrame.getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // craft + public void onCraft(InventoryOpenEvent event) { + Inventory inv = event.getInventory(); + if (inv.getType() != InventoryType.WORKBENCH) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, inv); + checkFlag(dom, Flag.CRAFT, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // crafter + public void onCrafterOpen(InventoryOpenEvent event) { + Inventory inv = event.getInventory(); + // InventoryType.CRAFTER; + if (!inv.getType().name().contains("CRAFTER")) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, inv); + checkFlag(dom, Flag.CRAFTER, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // comparer + public void comparerChange(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + Material clicked = event.getClickedBlock().getType(); + if (clicked != Material.COMPARATOR) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + checkFlag(dom, Flag.COMPARER, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // door + public void doorUse(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (!Tag.DOORS.isTagged(block.getType())) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + checkFlag(dom, Flag.DOOR, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // dragon_egg + public void touchDragonEdd(PlayerInteractEvent event) { + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (block.getType() != Material.DRAGON_EGG) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.DRAGON_EGG, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // dye + public void dyeEvent(PlayerInteractEntityEvent event) { + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + if (!(entity instanceof Colorable)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.DYE, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // edit sign + public void onSignOpen(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (!(Tag.SIGNS.isTagged(block.getType()))) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.EDIT_SIGN, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // edit sign + public void onSignEdit(SignChangeEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.EDIT_SIGN, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // egg + public void onThrowingEgg(ProjectileLaunchEvent event) { + if (!(event.getEntity().getShooter() instanceof Player player)) { + return; + } + if (event.getEntity().getType() != EntityType.EGG) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); + checkFlag(dom, Flag.EGG, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // enchant + public void onEnchant(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.ENCHANTING) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); + checkFlag(dom, Flag.ENCHANT, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // ender_pearl + public void onThrowingEndPearl(ProjectileLaunchEvent event) { + if (!(event.getEntity().getShooter() instanceof Player player)) { + return; + } + if (event.getEntity().getType() != EntityType.ENDER_PEARL) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); + checkFlag(dom, Flag.ENDER_PEARL, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // feed + public void onFeedAnimal(PlayerInteractEntityEvent event) { + if (!(event.getRightClicked() instanceof Animals)) { + return; + } + // if shearing sheep instead + if (event.getPlayer().getInventory().getItem(event.getHand()).getType() == Material.SHEARS) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRightClicked().getLocation()); + checkFlag(dom, Flag.FEED, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // harvest + public void onHarvest(BlockBreakEvent event) { + Block block = event.getBlock(); + if (block.getType() != Material.COCOA && + block.getType() != Material.WHEAT && + block.getType() != Material.CARROTS && + block.getType() != Material.POTATOES && + block.getType() != Material.BEETROOTS && + block.getType() != Material.NETHER_WART && + block.getType() != Material.SWEET_BERRY_BUSH && + block.getType() != Material.MELON && + block.getType() != Material.PUMPKIN && + block.getType() != Material.SUGAR_CANE && + block.getType() != Material.BAMBOO && + block.getType() != Material.CACTUS && + block.getType() != Material.CHORUS_PLANT && + block.getType() != Material.CHORUS_FLOWER && + block.getType() != Material.KELP && + block.getType() != Material.KELP_PLANT) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.HARVEST, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // honey + public void honeyInteractive(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + Material clicked = block.getType(); + if (clicked != Material.BEEHIVE && clicked != Material.BEE_NEST) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.HONEY, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // hook + public void onHook(PlayerFishEvent event) { + Entity caught = event.getCaught(); + if (caught == null) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(caught.getLocation()); + checkFlag(dom, Flag.HOOK, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // hopper + public void openHopper(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.HOPPER && + event.getInventory().getType() != InventoryType.DROPPER && + event.getInventory().getType() != InventoryType.DISPENSER && + event.getInventory().getType() != InventoryType.FURNACE && + event.getInventory().getType() != InventoryType.BLAST_FURNACE && + event.getInventory().getType() != InventoryType.SMOKER + ) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); + checkFlag(dom, Flag.HOPPER, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // ignite + public void onPlayerIgnite(BlockIgniteEvent event) { + Player player = event.getPlayer(); + if (player == null) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); + checkFlag(dom, Flag.IGNITE, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // item_frame_interactive + public void onItemFrameInteractive(PlayerInteractEntityEvent event) { + Entity entity = event.getRightClicked(); + if (!(entity instanceof ItemFrame itemFrame)) { + return; + } + if (itemFrame.getItem().getType() == Material.AIR) { + // 为空则当作容器处理见 putSomeOnItemFrame + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.ITEM_FRAME_INTERACTIVE, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // lever + public void onLever(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + Material clicked = block.getType(); + if (clicked != Material.LEVER) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.LEVER, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // monster_killing + public void onMonsterKilling(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player bukkitPlayer)) { + return; + } + // 如果不是怪物 则不处理 + Entity entity = event.getEntity(); + if (!(entity instanceof Monster)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // move + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); + if (!checkFlag(dom, Flag.MOVE, player, null)) { + Location to = player.getLocation(); + int x1 = Math.abs(to.getBlockX() - dom.getX1()); + int x2 = Math.abs(to.getBlockX() - dom.getX2()); + int z1 = Math.abs(to.getBlockZ() - dom.getZ1()); + int z2 = Math.abs(to.getBlockZ() - dom.getZ2()); + // find min distance + int min = Math.min(Math.min(x1, x2), Math.min(z1, z2)); + if (min == x1) { + to.setX(dom.getX1() - 2); + } else if (min == x2) { + to.setX(dom.getX2() + 2); + } else if (min == z1) { + to.setZ(dom.getZ1() - 2); + } else { + to.setZ(dom.getZ2() + 2); + } + Teleport.doTeleportSafely(player, to).thenAccept((success) -> { + if (!success) { + Notification.warn(player, "传送失败,你将被传送到复活点"); + Location bed = player.getBedSpawnLocation(); + if (bed == null) { + bed = player.getWorld().getSpawnLocation(); + } + if (Common.isPaper()) { + player.teleportAsync(bed, PlayerTeleportEvent.TeleportCause.PLUGIN); + } else { + player.teleport(bed, PlayerTeleportEvent.TeleportCause.PLUGIN); + } + + } + }); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) // note_block + public void onNoteBlockClicked(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + Material clicked = block.getType(); + if (clicked != Material.NOTE_BLOCK) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.NOTE_BLOCK, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // place + public void onPlaceBlock(BlockPlaceEvent event) { + Player player = event.getPlayer(); + if (onPlace(player, event.getBlock().getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // place - lava or water + public void onPlaceLavaOrWater(PlayerBucketEmptyEvent event) { + Player player = event.getPlayer(); + if (onPlace(player, event.getBlock().getLocation())) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGHEST) // place - item frame + public void placeItemFrame(HangingPlaceEvent event) { + Entity entity = event.getEntity(); + Player player = event.getPlayer(); + if (player == null) { + return; + } + if (onPlace(player, entity.getLocation())) { + return; + } + event.setCancelled(true); + } + + public static boolean onPlace(Player player, Location location) { + DominionDTO dom = Cache.instance.getDominionByLoc(location); + return checkFlag(dom, Flag.PLACE, player, null); + } + + @EventHandler(priority = EventPriority.HIGHEST) // pressure + public void onPressure(PlayerInteractEvent event) { + if (event.getAction() != Action.PHYSICAL) { + return; + } + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.PRESSURE, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // riding + public void onRiding(EntityMountEvent event) { + if (!(event.getEntity() instanceof Player player)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); + checkFlag(dom, Flag.RIDING, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // repeater + public void onRepeaterChange(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) { + return; + } + Block block = event.getClickedBlock(); + Material clicked = block.getType(); + if (clicked != Material.REPEATER) { + return; + } + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); + checkFlag(dom, Flag.REPEATER, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // shear + public void onShear(PlayerShearEntityEvent event) { + Player player = event.getPlayer(); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); + checkFlag(dom, Flag.SHEAR, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // shoot + public void onShootArrowSnowball(ProjectileHitEvent event) { + if (!(event.getEntity().getShooter() instanceof Player player)) { + return; + } + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); + checkFlag(dom, Flag.SHOOT, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // trade + public void onTrade(InventoryOpenEvent event) { + if (event.getInventory().getType() != InventoryType.MERCHANT) { + return; + } + if (!(event.getPlayer() instanceof Player bukkitPlayer)) { + return; + } + DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); + checkFlag(dom, Flag.TRADE, bukkitPlayer, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // vehicle_destroy + public void onVehicleDestroy(VehicleDestroyEvent event) { + if (!(event.getAttacker() instanceof Player player)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); + checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // vehicle_spawn + public void onVehicleSpawn(EntityPlaceEvent event) { + Player player = event.getPlayer(); + if (player == null) { + return; + } + Entity entity = event.getEntity(); + if (!(entity instanceof Vehicle)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); + checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); + } + + @EventHandler(priority = EventPriority.HIGHEST) // villager_killing + public void onVillagerKilling(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player player)) { + return; + } + if (!(event.getEntity() instanceof Villager)) { + return; + } + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); + checkFlag(dom, Flag.VILLAGER_KILLING, player, event); + } +} diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java new file mode 100644 index 0000000..3b312f0 --- /dev/null +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java @@ -0,0 +1,104 @@ +package cn.lunadeer.dominion.events_v1_20_1; + +import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.utils.Particle; +import cn.lunadeer.minecraftpluginutils.Notification; +import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +public class SelectPointEvents implements Listener { + @EventHandler(priority = EventPriority.HIGHEST) + public void selectPoint(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = player.getInventory().getItemInMainHand(); + + if (item.getType() != Dominion.config.getTool()) { + return; + } + Block block = event.getClickedBlock(); + Action action = event.getAction(); + if (block == null) { + return; + } + + Map points = Dominion.pointsSelect.get(player.getUniqueId()); + if (points == null) { + points = new HashMap<>(); + } + + if (action == Action.LEFT_CLICK_BLOCK) { + event.setCancelled(true); + Notification.info(player, "已选择第一个点: %d %d %d", block.getX(), block.getY(), block.getZ()); + Location loc = block.getLocation(); + if (Dominion.config.getLimitVert()) { + loc.setY(Dominion.config.getLimitMinY()); + } + points.put(0, loc); + } else if (action == Action.RIGHT_CLICK_BLOCK) { + event.setCancelled(true); + Notification.info(player, "已选择第二个点: %d %d %d", block.getX(), block.getY(), block.getZ()); + Location loc = block.getLocation(); + if (Dominion.config.getLimitVert()) { + loc.setY(Dominion.config.getLimitMaxY() - 1); + } + points.put(1, loc); + } else { + return; + } + Dominion.pointsSelect.put(player.getUniqueId(), points); + + if (points.size() == 2) { + World world = points.get(0).getWorld(); + if (world == null) { + return; + } + if (!points.get(0).getWorld().equals(points.get(1).getWorld())) { + Notification.warn(player, "两个点不在同一个世界"); + return; + } + Notification.info(player, "已选择两个点,可以使用 /dominion create <领地名称> 创建领地"); + Location loc1 = points.get(0); + Location loc2 = points.get(1); + int minX = Math.min(loc1.getBlockX(), loc2.getBlockX()); + int minY = Math.min(loc1.getBlockY(), loc2.getBlockY()); + int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); + int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1; + int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1; + int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1; + DominionDTO dominion = new DominionDTO(player.getUniqueId(), "", loc1.getWorld().getName(), + minX, minY, minZ, maxX, maxY, maxZ); + if (Dominion.config.getEconomyEnable()) { + if (!VaultConnect.instance.economyAvailable()) { + Notification.error(player, "计算价格失败,没有可用的经济插件系统,请联系服主。"); + return; + } + int count; + if (Dominion.config.getEconomyOnlyXZ()) { + count = dominion.getSquare(); + } else { + count = dominion.getVolume(); + } + float price = count * Dominion.config.getEconomyPrice(); + Notification.info(player, "预计领地创建价格为 %.2f %s", price, VaultConnect.instance.currencyNamePlural()); + } + Particle.showBorder(player, dominion); + Notification.info(player, "尺寸: %d x %d x %d", dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ()); + Notification.info(player, "面积: %d", dominion.getSquare()); + Notification.info(player, "高度: %d", dominion.getHeight()); + Notification.info(player, "体积: %d", dominion.getVolume()); + } + } +} diff --git a/v1_21/build.gradle.kts b/v1_21/build.gradle.kts new file mode 100644 index 0000000..7e9f05b --- /dev/null +++ b/v1_21/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + id("java") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +// utf-8 +tasks.withType { + options.encoding = "UTF-8" +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly(project(":core")) + compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") +} \ No newline at end of file diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java similarity index 94% rename from src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java rename to v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java index 5e0c995..a0761fd 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java @@ -1,4 +1,4 @@ -package cn.lunadeer.dominion.events; +package cn.lunadeer.dominion.events_v1_21; import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; @@ -80,11 +80,12 @@ public class EnvironmentEvents implements Listener { } private static boolean isNotExplodeEntity(Entity damager) { - String materialName = damager.getType().name(); - return !materialName.contains("CREEPER") - && !materialName.contains("WITHER_SKULL") - && !materialName.contains("FIREBALL") - && !materialName.contains("CRYSTAL"); + return damager.getType() != EntityType.CREEPER + && damager.getType() != EntityType.WITHER_SKULL + && damager.getType() != EntityType.FIREBALL + && damager.getType() != EntityType.END_CRYSTAL + && damager.getType() != EntityType.SMALL_FIREBALL + && damager.getType() != EntityType.DRAGON_FIREBALL; } @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @@ -149,8 +150,7 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode public void onTntExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); - XLogger.debug("EntityExplodeEvent#name(): " + entity.getType().name()); - if (!entity.getType().name().contains("TNT")) { + if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { return; } event.blockList().removeIf(block -> { @@ -165,7 +165,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ARMOR_STAND) { return; } - if (!event.getDamager().getType().name().contains("TNT")) { + if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java rename to v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java index 8821ae4..0bc6bae 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java @@ -1,4 +1,4 @@ -package cn.lunadeer.dominion.events; +package cn.lunadeer.dominion.events_v1_21; import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; diff --git a/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java rename to v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java index 42d69c9..d3c86ff 100644 --- a/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java @@ -1,4 +1,4 @@ -package cn.lunadeer.dominion.events; +package cn.lunadeer.dominion.events_v1_21; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; From e0bd285e74b857cb54e9d95a6857e74dc81d2cd1 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 5 Aug 2024 15:45:59 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E5=A4=9A?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E3=80=81=E5=A4=9A=E7=89=88=E6=9C=AC=E6=89=93?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yml | 2 +- build.gradle.kts | 27 ++++++++++++++----- core/build.gradle.kts | 10 ------- .../dominion/events/RegisterEvents.java | 2 ++ v1_20_1/build.gradle.kts | 4 --- .../events_v1_20_1/EnvironmentEvents.java | 3 ++- .../dominion/events_v1_20_1/PlayerEvents.java | 2 +- v1_21/build.gradle.kts | 4 --- .../events_v1_21/EnvironmentEvents.java | 3 ++- .../dominion/events_v1_21/PlayerEvents.java | 8 +++--- 10 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 16f780f..d24e762 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -20,7 +20,7 @@ jobs: distribution: 'zulu' cache: gradle - name: "Build with Gradle" - run: ./gradlew shadowJar + run: ./gradlew buildPlugin - name: "Copy jar to staging" run: mkdir staging && cp build/libs/*.jar staging/ - name: "Build & test" diff --git a/build.gradle.kts b/build.gradle.kts index 7c4b0ab..f0cfc19 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "1.44.4-beta" +version = "1.44.6-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) @@ -15,7 +15,7 @@ tasks.withType { options.encoding = "UTF-8" } -subprojects { +allprojects { apply(plugin = "java") apply(plugin = "com.github.johnrengelman.shadow") @@ -37,19 +37,34 @@ subprojects { implementation("org.yaml:snakeyaml:2.0") } - - tasks.withType { + tasks.processResources { // replace @version@ in plugin.yml with project version filesMatching("**/plugin.yml") { filter { - it.replace("@version@", project.version.toString()) + it.replace("@version@", rootProject.version.toString()) } } } - tasks.withType { + tasks.shadowJar { archiveClassifier.set("") archiveVersion.set(project.version.toString()) dependsOn(tasks.withType()) } +} + +dependencies { + implementation(project(":core")) + implementation(project(":v1_20_1")) + implementation(project(":v1_21")) +} + +tasks.shadowJar { + archiveClassifier.set("") + archiveVersion.set(project.version.toString()) +} + +tasks.register("buildPlugin") { + dependsOn(tasks.getByName("clean")) + dependsOn(tasks.getByName("shadowJar")) } \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 26e4a71..0f4ac39 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -11,16 +11,6 @@ tasks.withType { options.encoding = "UTF-8" } -repositories { - mavenCentral() - mavenLocal() - maven("https://oss.sonatype.org/content/groups/public") - maven("https://repo.papermc.io/repository/maven-public/") - maven("https://jitpack.io") - maven("https://repo.mikeprimm.com/") - maven("https://ssl.lunadeer.cn:14454/repository/maven-snapshots/") -} - dependencies { compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") } diff --git a/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java b/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java index 66f90ef..5a251de 100644 --- a/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java +++ b/core/src/main/java/cn/lunadeer/dominion/events/RegisterEvents.java @@ -18,11 +18,13 @@ public class RegisterEvents { try { switch (version) { case v1_21: + XLogger.debug("Load API version: 1.21"); registerEvents("cn.lunadeer.dominion.events_v1_21.PlayerEvents"); registerEvents("cn.lunadeer.dominion.events_v1_21.EnvironmentEvents"); registerEvents("cn.lunadeer.dominion.events_v1_21.SelectPointEvents"); break; case v1_20_1: + XLogger.debug("Load API version: 1.20.1"); registerEvents("cn.lunadeer.dominion.events_v1_20_1.PlayerEvents"); registerEvents("cn.lunadeer.dominion.events_v1_20_1.EnvironmentEvents"); registerEvents("cn.lunadeer.dominion.events_v1_20_1.SelectPointEvents"); diff --git a/v1_20_1/build.gradle.kts b/v1_20_1/build.gradle.kts index 8d4eee1..7e0454c 100644 --- a/v1_20_1/build.gradle.kts +++ b/v1_20_1/build.gradle.kts @@ -11,10 +11,6 @@ tasks.withType { options.encoding = "UTF-8" } -repositories { - maven("https://repo.papermc.io/repository/maven-public/") -} - dependencies { compileOnly(project(":core")) compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java index dcb7114..d95e18f 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java @@ -162,10 +162,11 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); + Entity harmer = event.getDamager(); if (entity.getType() != EntityType.ARMOR_STAND) { return; } - if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { + if (harmer.getType() != EntityType.MINECART_TNT && harmer.getType() != EntityType.PRIMED_TNT) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java index 6d7bcad..ed0773d 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java @@ -359,7 +359,7 @@ public class PlayerEvents implements Listener { if (block == null) { return; } - if (!Tag.DOORS.isTagged(block.getType())) { + if (!Tag.DOORS.isTagged(block.getType()) && !Tag.TRAPDOORS.isTagged(block.getType())) { return; } Player player = event.getPlayer(); diff --git a/v1_21/build.gradle.kts b/v1_21/build.gradle.kts index 7e9f05b..7a133f2 100644 --- a/v1_21/build.gradle.kts +++ b/v1_21/build.gradle.kts @@ -11,10 +11,6 @@ tasks.withType { options.encoding = "UTF-8" } -repositories { - maven("https://repo.papermc.io/repository/maven-public/") -} - dependencies { compileOnly(project(":core")) compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java index a0761fd..0878e15 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java @@ -162,10 +162,11 @@ public class EnvironmentEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); + Entity harmer = event.getDamager(); if (entity.getType() != EntityType.ARMOR_STAND) { return; } - if (entity.getType() != EntityType.TNT_MINECART && entity.getType() != EntityType.TNT) { + if (harmer.getType() != EntityType.TNT_MINECART && harmer.getType() != EntityType.TNT) { return; } DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java index 0bc6bae..def9b37 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java @@ -52,8 +52,8 @@ public class PlayerEvents implements Listener { } DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); if (!checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) { - if (bukkitPlayer.getBedSpawnLocation() != null) { - event.setRespawnLocation(bukkitPlayer.getBedSpawnLocation()); + if (bukkitPlayer.getRespawnLocation() != null) { + event.setRespawnLocation(bukkitPlayer.getRespawnLocation()); } else { event.setRespawnLocation(bukkitPlayer.getWorld().getSpawnLocation()); } @@ -355,7 +355,7 @@ public class PlayerEvents implements Listener { if (block == null) { return; } - if (!Tag.DOORS.isTagged(block.getType())) { + if (!Tag.DOORS.isTagged(block.getType()) && !Tag.TRAPDOORS.isTagged(block.getType())) { return; } Player player = event.getPlayer(); @@ -617,7 +617,7 @@ public class PlayerEvents implements Listener { Teleport.doTeleportSafely(player, to).thenAccept((success) -> { if (!success) { Notification.warn(player, "传送失败,你将被传送到复活点"); - Location bed = player.getBedSpawnLocation(); + Location bed = player.getRespawnLocation(); if (bed == null) { bed = player.getWorld().getSpawnLocation(); }