Merge branch 'refs/heads/nms-for-multi-version'

This commit is contained in:
zhangyuheng 2024-08-05 20:36:35 +08:00
commit 3923973778
90 changed files with 1843 additions and 217 deletions

View File

@ -13,18 +13,16 @@ jobs:
uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3 uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: "Set up Maven" - name: "Set up JDK 21"
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
- name: "Set up JDK 17"
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3 uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
with: with:
java-version: '17' java-version: '21'
distribution: 'zulu' distribution: 'zulu'
cache: maven cache: gradle
- name: "Build with Maven" - name: "Build with Gradle"
run: mvn -B package --file pom.xml run: ./gradlew buildPlugin
- name: "Copy jar to staging" - name: "Copy jar to staging"
run: mkdir staging && cp target/*.jar staging run: mkdir staging && cp build/libs/*.jar staging/
- name: "Build & test" - name: "Build & test"
run: | run: |
echo "done!" echo "done!"

70
build.gradle.kts Normal file
View File

@ -0,0 +1,70 @@
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
}
group = "cn.lunadeer"
version = "1.44.6-beta"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
// utf-8
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
allprojects {
apply(plugin = "java")
apply(plugin = "com.github.johnrengelman.shadow")
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("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")
}
tasks.processResources {
// replace @version@ in plugin.yml with project version
filesMatching("**/plugin.yml") {
filter {
it.replace("@version@", rootProject.version.toString())
}
}
}
tasks.shadowJar {
archiveClassifier.set("")
archiveVersion.set(project.version.toString())
dependsOn(tasks.withType<ProcessResources>())
}
}
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"))
}

16
core/build.gradle.kts Normal file
View File

@ -0,0 +1,16 @@
plugins {
id("java")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
// utf-8
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
}

View File

@ -1,8 +1,6 @@
package cn.lunadeer.dominion; package cn.lunadeer.dominion;
import cn.lunadeer.dominion.events.EnvironmentEvents; import cn.lunadeer.dominion.events.RegisterEvents;
import cn.lunadeer.dominion.events.PlayerEvents;
import cn.lunadeer.dominion.events.SelectPointEvents;
import cn.lunadeer.dominion.managers.ConfigManager; import cn.lunadeer.dominion.managers.ConfigManager;
import cn.lunadeer.dominion.managers.DatabaseTables; import cn.lunadeer.dominion.managers.DatabaseTables;
import cn.lunadeer.dominion.utils.DynmapConnect; import cn.lunadeer.dominion.utils.DynmapConnect;
@ -41,9 +39,7 @@ public final class Dominion extends JavaPlugin {
AutoClean.run(); AutoClean.run();
Cache.instance = new Cache(); Cache.instance = new Cache();
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this); new RegisterEvents(this);
Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this);
Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this);
Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands()); Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands());
bStatsMetrics metrics = new bStatsMetrics(this, 21445); bStatsMetrics metrics = new bStatsMetrics(this, 21445);

View File

@ -25,6 +25,7 @@ public enum Flag {
CAKE("cake", "吃蛋糕", "是否可以吃蛋糕", false, false, true), CAKE("cake", "吃蛋糕", "是否可以吃蛋糕", false, false, true),
CONTAINER("container", "一般容器", "包含:箱子/木桶/潜影盒/盔甲架/展示框", false, false, true), CONTAINER("container", "一般容器", "包含:箱子/木桶/潜影盒/盔甲架/展示框", false, false, true),
CRAFT("craft", "使用工作台", "是否可以使用工作台", false, false, true), CRAFT("craft", "使用工作台", "是否可以使用工作台", false, false, true),
CRAFTER("crafter", "合成器", "是否可以修改自动合成器", false, false, true),
CREEPER_EXPLODE("creeper_explode", "实体爆炸", "包含:苦力怕/凋零头颅/末影水晶/火球", false, true, true), CREEPER_EXPLODE("creeper_explode", "实体爆炸", "包含:苦力怕/凋零头颅/末影水晶/火球", false, true, true),
COMPARER("comparer", "比较器交互", "是否可以修改比较器状态", false, false, true), COMPARER("comparer", "比较器交互", "是否可以修改比较器状态", false, false, true),
DOOR("door", "门交互", "是否可以使用各种材质的门(包括活板门)", false, false, true), DOOR("door", "门交互", "是否可以使用各种材质的门(包括活板门)", false, false, true),
@ -47,6 +48,7 @@ public enum Flag {
HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true), HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true),
IGNITE("ignite", "点燃", "是否可以使用打火石点火", false, false, true), IGNITE("ignite", "点燃", "是否可以使用打火石点火", false, false, true),
ITEM_FRAME_INTERACTIVE("item_frame_interactive", "展示框交互", "是否可以与物品展示框交互(旋转展示框的东西)", 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), LEVER("lever", "使用拉杆", "是否可以使用拉杆", false, false, true),
MOB_DROP_ITEM("mob_drop_item", "生物战利品掉落", "生物死亡时是否产生掉落物", true, true, true), MOB_DROP_ITEM("mob_drop_item", "生物战利品掉落", "生物死亡时是否产生掉落物", true, true, true),
MONSTER_KILLING("monster_killing", "对怪物造成伤害", "玩家是否可以对怪物造成伤害", false, false, true), MONSTER_KILLING("monster_killing", "对怪物造成伤害", "玩家是否可以对怪物造成伤害", false, false, true),
@ -58,16 +60,19 @@ public enum Flag {
RIDING("riding", "骑乘载具", "是否可以骑乘各种载具", false, false, true), RIDING("riding", "骑乘载具", "是否可以骑乘各种载具", false, false, true),
REPEATER("repeater", "中继器交互", "是否可以与中继器交互", false, false, true), REPEATER("repeater", "中继器交互", "是否可以与中继器交互", false, false, true),
SHEAR("shear", "剪羊毛", "是否可以剪羊毛", 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), SHOW_BORDER("show_border", "显示领地边界", "是否显示领地边界", true, true, true),
TELEPORT("teleport", "领地传送", "是否开启领地传送", false, false, true), TELEPORT("teleport", "领地传送", "是否开启领地传送", false, false, true),
TNT_EXPLODE("tnt_explode", "TNT爆炸", "TNT是否可以爆炸", false, true, true), TNT_EXPLODE("tnt_explode", "TNT爆炸", "TNT是否可以爆炸", false, true, true),
TRADE("trade", "村民交易", "是否可以与村民交易", false, false, true), TRADE("trade", "村民交易", "是否可以与村民交易", false, false, true),
TRAMPLE("trample", "作物践踏", "是否可以践踏作物(关闭意味着保护耕地)", false, true, 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_DESTROY("vehicle_destroy", "破坏载具", "是否可以破坏载具(主要是矿车)", false, false, true),
VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true), VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true),
VILLAGER_KILLING("villager_killing", "对村民造成伤害", "是否可以对村民造成伤害", 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), WITHER_SPAWN("wither_spawn", "凋零生成", "凋零生成", false, true, true),
; ;
private final String flag_name; private final String flag_name;

View File

@ -0,0 +1,64 @@
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:
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");
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);
}
}

View File

@ -91,7 +91,7 @@ public class ConfigManager {
_fly_permission_nodes = _file.getStringList("FlyPermissionNodes"); _fly_permission_nodes = _file.getStringList("FlyPermissionNodes");
_residence_migration = _file.getBoolean("ResidenceMigration", false); _residence_migration = _file.getBoolean("ResidenceMigration", false);
saveAll(); // 回写文件 防止文件中的数据不完整 saveAll(); // 回写文件 防止文件中的数据不完整
Flag.loadFromJson(); Flag.loadFromJson(); // 加载 Flag 配置
} }
public void saveAll() { public void saveAll() {

View File

@ -29,7 +29,7 @@ public class DominionList {
view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("我的领地")); view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("我的领地"));
view.addLines(BuildTreeLines(DominionNode.BuildNodeTree(-1, DominionDTO.selectByOwner(player.getUniqueId())), 0)); view.addLines(BuildTreeLines(DominionNode.BuildNodeTree(-1, DominionDTO.selectByOwner(player.getUniqueId())), 0));
List<String> admin_dominions = playerAdminDominions(sender); List<String> admin_dominions = playerAdminDominions(sender);
if (admin_dominions.size() != 0) { if (!admin_dominions.isEmpty()) {
view.add(Line.create().append("")); view.add(Line.create().append(""));
view.add(Line.create().append(Component.text("--- 以下为你拥有管理员权限的领地 ---", ViewStyles.main_color))); view.add(Line.create().append(Component.text("--- 以下为你拥有管理员权限的领地 ---", ViewStyles.main_color)));
} }
@ -43,9 +43,7 @@ public class DominionList {
public static List<Line> BuildTreeLines(List<DominionNode> dominionTree, Integer depth) { public static List<Line> BuildTreeLines(List<DominionNode> dominionTree, Integer depth) {
List<Line> lines = new ArrayList<>(); List<Line> lines = new ArrayList<>();
StringBuilder prefix = new StringBuilder(); StringBuilder prefix = new StringBuilder();
for (int i = 0; i < depth; i++) { prefix.append(" | ".repeat(Math.max(0, depth)));
prefix.append(" | ");
}
for (DominionNode node : dominionTree) { for (DominionNode node : dominionTree) {
TextComponent manage = Button.createGreen("管理").setExecuteCommand("/dominion manage " + node.getDominion().getName()).build(); TextComponent manage = Button.createGreen("管理").setExecuteCommand("/dominion manage " + node.getDominion().getName()).build();
TextComponent delete = Button.createRed("删除").setExecuteCommand("/dominion delete " + node.getDominion().getName()).build(); TextComponent delete = Button.createRed("删除").setExecuteCommand("/dominion delete " + node.getDominion().getName()).build();

View File

@ -1,14 +1,12 @@
package cn.lunadeer.dominion.utils; package cn.lunadeer.dominion.utils;
import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.utils.Residence.Message; import cn.lunadeer.dominion.utils.Residence.Message;
import cn.lunadeer.dominion.utils.Residence.Permission; import cn.lunadeer.dominion.utils.Residence.Permission;
import cn.lunadeer.dominion.utils.Residence.Residence; import cn.lunadeer.dominion.utils.Residence.Residence;
import cn.lunadeer.dominion.utils.Residence.SaveFile; import cn.lunadeer.dominion.utils.Residence.SaveFile;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@ -58,19 +56,13 @@ public class ResMigration {
} }
private static ResidenceNode parseDominion(String name, World world, Residence res, SaveFile save) { 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(":"); String[] loc = res.Areas.values().toArray()[0].toString().split(":");
if (loc.length != 6) { if (loc.length != 6) {
XLogger.warn("Invalid location: " + res.Areas.get("main")); XLogger.warn("Invalid location: " + res.Areas.get("main"));
return null; return null;
} }
ResidenceNode dominionNode = new ResidenceNode(); ResidenceNode dominionNode = new ResidenceNode();
dominionNode.owner = owner.getUuid(); dominionNode.owner = UUID.fromString(res.Permissions.OwnerUUID);
dominionNode.world = world; dominionNode.world = world;
dominionNode.name = name; dominionNode.name = name;
dominionNode.joinMessage = save.Messages.get(res.Messages).EnterMessage; dominionNode.joinMessage = save.Messages.get(res.Messages).EnterMessage;

View File

@ -1,5 +1,5 @@
name: Dominion name: Dominion
version: '${project.version}' version: @version@
main: cn.lunadeer.dominion.Dominion main: cn.lunadeer.dominion.Dominion
api-version: '1.20' api-version: '1.20'
load: STARTUP load: STARTUP

0
gradle.properties Normal file
View File

View File

@ -0,0 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip

234
gradlew vendored Executable file
View File

@ -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" "$@"

89
gradlew.bat vendored Normal file
View File

@ -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

109
pom.xml
View File

@ -1,109 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.42.9-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>lunadeer-repo</id>
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
</repository>
<repository>
<id>MikeRepo</id>
<url>https://repo.mikeprimm.com/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId>
<version>1.3.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.BlueMap-Minecraft</groupId>
<artifactId>BlueMapAPI</artifactId>
<version>v2.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>us.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
<version>3.4-beta-3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

7
settings.gradle.kts Normal file
View File

@ -0,0 +1,7 @@
rootProject.name = "Dominion"
include(
"core",
"v1_20_1",
"v1_21"
)

17
v1_20_1/build.gradle.kts Normal file
View File

@ -0,0 +1,17 @@
plugins {
id("java")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
// utf-8
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
dependencies {
compileOnly(project(":core"))
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
}

View File

@ -1,17 +1,19 @@
package cn.lunadeer.dominion.events; package cn.lunadeer.dominion.events_v1_20_1;
import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Tag;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; 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.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
@ -53,36 +55,37 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.ARMOR_STAND) { if (entity.getType() != EntityType.ARMOR_STAND) {
return; return;
} }
if (event.getDamager() instanceof Player) { if (isNotExplodeEntity(event.getDamager())) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event); checkFlag(dom, Flag.CREEPER_EXPLODE, event);
} }
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - other projectiles @EventHandler(priority = EventPriority.HIGHEST) // item_frame_proj_damage
public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) { public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) {
Entity entity = event.getEntity(); if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) {
if (!(entity instanceof ItemFrame)) {
return; return;
} }
ItemFrame itemFrame = (ItemFrame) entity; Entity remover = event.getRemover();
if (!(event.getDamager() instanceof Projectile)) { if (!(remover instanceof Projectile projectile)) {
return; return;
} }
Projectile arrow = (Projectile) event.getDamager(); if (!(projectile.getShooter() instanceof Player)) {
if (arrow.getShooter() instanceof Player) { // 玩家破坏由 玩家 break 权限控制
return; return;
} }
DominionDTO dom = Cache.instance.getDominionByLoc(itemFrame.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event); checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event);
} }
private static boolean isNotExplodeEntity(Entity damager) { private static boolean isNotExplodeEntity(Entity damager) {
return damager.getType() != EntityType.CREEPER return damager.getType() != EntityType.CREEPER
&& damager.getType() != EntityType.WITHER_SKULL && damager.getType() != EntityType.WITHER_SKULL
&& damager.getType() != EntityType.FIREBALL && damager.getType() != EntityType.FIREBALL
&& damager.getType() != EntityType.ENDER_CRYSTAL; && damager.getType() != EntityType.ENDER_CRYSTAL
&& damager.getType() != EntityType.SMALL_FIREBALL
&& damager.getType() != EntityType.DRAGON_FIREBALL;
} }
@EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block @EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block
@ -159,11 +162,11 @@ public class EnvironmentEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand @EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand
public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
Entity harmer = event.getDamager();
if (entity.getType() != EntityType.ARMOR_STAND) { if (entity.getType() != EntityType.ARMOR_STAND) {
return; return;
} }
Entity damager = event.getDamager(); if (harmer.getType() != EntityType.MINECART_TNT && harmer.getType() != EntityType.PRIMED_TNT) {
if (damager.getType() != EntityType.PRIMED_TNT && damager.getType() != EntityType.MINECART_TNT) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
@ -186,6 +189,50 @@ public class EnvironmentEvents implements Listener {
checkFlag(dom, Flag.TRAMPLE, event); 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 @EventHandler(priority = EventPriority.HIGHEST) // wither_spawn
public void onWitherSpawn(CreatureSpawnEvent event) { public void onWitherSpawn(CreatureSpawnEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();

View File

@ -1,9 +1,10 @@
package cn.lunadeer.dominion.events; package cn.lunadeer.dominion.events_v1_20_1;
import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO; import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Common;
import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Teleport; import cn.lunadeer.minecraftpluginutils.Teleport;
import org.bukkit.Location; import org.bukkit.Location;
@ -16,8 +17,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.*; import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityPlaceEvent; import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
@ -65,14 +66,13 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // animal_killing @EventHandler(priority = EventPriority.HIGHEST) // animal_killing
public void onAnimalKilling(EntityDamageByEntityEvent event) { public void onAnimalKilling(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)) { if (!(event.getDamager() instanceof Player bukkitPlayer)) {
return; return;
} }
// 如果不是动物 则不处理 // 如果不是动物 则不处理
if (!(event.getEntity() instanceof Animals)) { if (!(event.getEntity() instanceof Animals)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getDamager();
DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation());
checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event);
} }
@ -82,10 +82,9 @@ public class PlayerEvents implements Listener {
if (event.getInventory().getType() != InventoryType.ANVIL) { if (event.getInventory().getType() != InventoryType.ANVIL) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer);
checkFlag(dom, Flag.ANVIL, bukkitPlayer, event); checkFlag(dom, Flag.ANVIL, bukkitPlayer, event);
} }
@ -95,10 +94,9 @@ public class PlayerEvents implements Listener {
if (event.getInventory().getType() != InventoryType.BEACON) { if (event.getInventory().getType() != InventoryType.BEACON) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer);
checkFlag(dom, Flag.BEACON, bukkitPlayer, event); checkFlag(dom, Flag.BEACON, bukkitPlayer, event);
} }
@ -125,10 +123,9 @@ public class PlayerEvents implements Listener {
if (event.getInventory().getType() != InventoryType.BREWING) { if (event.getInventory().getType() != InventoryType.BREWING) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer);
checkFlag(dom, Flag.BREW, bukkitPlayer, event); checkFlag(dom, Flag.BREW, bukkitPlayer, event);
} }
@ -235,10 +232,9 @@ public class PlayerEvents implements Listener {
event.getInventory().getType() != InventoryType.SHULKER_BOX) { event.getInventory().getType() != InventoryType.SHULKER_BOX) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
if (hasContainerPermission(bukkitPlayer, event.getInventory().getLocation())) { if (hasContainerPermission(bukkitPlayer, event.getInventory().getLocation())) {
return; return;
} }
@ -257,10 +253,9 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // container item frame put @EventHandler(priority = EventPriority.HIGHEST) // container item frame put
public void putSomeOnItemFrame(PlayerInteractEntityEvent event) { public void putSomeOnItemFrame(PlayerInteractEntityEvent event) {
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
if (!(entity instanceof ItemFrame)) { if (!(entity instanceof ItemFrame itemFrame)) {
return; return;
} }
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() != Material.AIR) { if (itemFrame.getItem().getType() != Material.AIR) {
return; return;
} }
@ -274,17 +269,15 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // container item frame get @EventHandler(priority = EventPriority.HIGHEST) // container item frame get
public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) { public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame)) { if (!(entity instanceof ItemFrame itemFrame)) {
return; return;
} }
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.AIR) { if (itemFrame.getItem().getType() == Material.AIR) {
return; return;
} }
if (!(event.getDamager() instanceof Player)) { if (!(event.getDamager() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getDamager();
if (hasContainerPermission(bukkitPlayer, entity.getLocation())) { if (hasContainerPermission(bukkitPlayer, entity.getLocation())) {
return; return;
} }
@ -294,21 +287,18 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // container item frame get @EventHandler(priority = EventPriority.HIGHEST) // container item frame get
public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) { public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame)) { if (!(entity instanceof ItemFrame itemFrame)) {
return; return;
} }
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.AIR) { if (itemFrame.getItem().getType() == Material.AIR) {
return; return;
} }
if (!(event.getDamager() instanceof Arrow)) { if (!(event.getDamager() instanceof Arrow arrow)) {
return; return;
} }
Arrow arrow = (Arrow) event.getDamager(); if (!(arrow.getShooter() instanceof Player bukkitPlayer)) {
if (!(arrow.getShooter() instanceof Player)) {
return; return;
} }
Player bukkitPlayer = (Player) arrow.getShooter();
if (hasContainerPermission(bukkitPlayer, itemFrame.getLocation())) { if (hasContainerPermission(bukkitPlayer, itemFrame.getLocation())) {
return; return;
} }
@ -321,14 +311,27 @@ public class PlayerEvents implements Listener {
if (inv.getType() != InventoryType.WORKBENCH) { if (inv.getType() != InventoryType.WORKBENCH) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = getInvDominion(bukkitPlayer, inv); DominionDTO dom = getInvDominion(bukkitPlayer, inv);
checkFlag(dom, Flag.CRAFT, bukkitPlayer, event); 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 @EventHandler(priority = EventPriority.HIGHEST) // comparer
public void comparerChange(PlayerInteractEvent event) { public void comparerChange(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
@ -356,7 +359,7 @@ public class PlayerEvents implements Listener {
if (block == null) { if (block == null) {
return; return;
} }
if (!Tag.DOORS.isTagged(block.getType())) { if (!Tag.DOORS.isTagged(block.getType()) && !Tag.TRAPDOORS.isTagged(block.getType())) {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -416,13 +419,12 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // egg @EventHandler(priority = EventPriority.HIGHEST) // egg
public void onThrowingEgg(ProjectileLaunchEvent event) { public void onThrowingEgg(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player)) { if (!(event.getEntity().getShooter() instanceof Player player)) {
return; return;
} }
if (event.getEntity().getType() != EntityType.EGG) { if (event.getEntity().getType() != EntityType.EGG) {
return; return;
} }
Player player = (Player) event.getEntity().getShooter();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player);
checkFlag(dom, Flag.EGG, player, event); checkFlag(dom, Flag.EGG, player, event);
} }
@ -432,23 +434,21 @@ public class PlayerEvents implements Listener {
if (event.getInventory().getType() != InventoryType.ENCHANTING) { if (event.getInventory().getType() != InventoryType.ENCHANTING) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory());
checkFlag(dom, Flag.ENCHANT, bukkitPlayer, event); checkFlag(dom, Flag.ENCHANT, bukkitPlayer, event);
} }
@EventHandler(priority = EventPriority.HIGHEST) // ender_pearl @EventHandler(priority = EventPriority.HIGHEST) // ender_pearl
public void onThrowingEndPearl(ProjectileLaunchEvent event) { public void onThrowingEndPearl(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player)) { if (!(event.getEntity().getShooter() instanceof Player player)) {
return; return;
} }
if (event.getEntity().getType() != EntityType.ENDER_PEARL) { if (event.getEntity().getType() != EntityType.ENDER_PEARL) {
return; return;
} }
Player player = (Player) event.getEntity().getShooter();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player);
checkFlag(dom, Flag.ENDER_PEARL, player, event); checkFlag(dom, Flag.ENDER_PEARL, player, event);
} }
@ -533,10 +533,9 @@ public class PlayerEvents implements Listener {
) { ) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory());
checkFlag(dom, Flag.HOPPER, bukkitPlayer, event); checkFlag(dom, Flag.HOPPER, bukkitPlayer, event);
} }
@ -554,10 +553,9 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // item_frame_interactive @EventHandler(priority = EventPriority.HIGHEST) // item_frame_interactive
public void onItemFrameInteractive(PlayerInteractEntityEvent event) { public void onItemFrameInteractive(PlayerInteractEntityEvent event) {
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
if (!(entity instanceof ItemFrame)) { if (!(entity instanceof ItemFrame itemFrame)) {
return; return;
} }
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.AIR) { if (itemFrame.getItem().getType() == Material.AIR) {
// 为空则当作容器处理见 putSomeOnItemFrame // 为空则当作容器处理见 putSomeOnItemFrame
return; return;
@ -587,7 +585,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // monster_killing @EventHandler(priority = EventPriority.HIGHEST) // monster_killing
public void onMonsterKilling(EntityDamageByEntityEvent event) { public void onMonsterKilling(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)) { if (!(event.getDamager() instanceof Player bukkitPlayer)) {
return; return;
} }
// 如果不是怪物 则不处理 // 如果不是怪物 则不处理
@ -595,7 +593,6 @@ public class PlayerEvents implements Listener {
if (!(entity instanceof Monster)) { if (!(entity instanceof Monster)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getDamager();
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event);
} }
@ -624,10 +621,16 @@ public class PlayerEvents implements Listener {
Teleport.doTeleportSafely(player, to).thenAccept((success) -> { Teleport.doTeleportSafely(player, to).thenAccept((success) -> {
if (!success) { if (!success) {
Notification.warn(player, "传送失败,你将被传送到复活点"); Notification.warn(player, "传送失败,你将被传送到复活点");
player.teleportAsync(player.getBedSpawnLocation() == null ? Location bed = player.getBedSpawnLocation();
player.getWorld().getSpawnLocation() : if (bed == null) {
player.getBedSpawnLocation() bed = player.getWorld().getSpawnLocation();
, PlayerTeleportEvent.TeleportCause.PLUGIN); }
if (Common.isPaper()) {
player.teleportAsync(bed, PlayerTeleportEvent.TeleportCause.PLUGIN);
} else {
player.teleport(bed, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
} }
}); });
} }
@ -706,10 +709,9 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // riding @EventHandler(priority = EventPriority.HIGHEST) // riding
public void onRiding(EntityMountEvent event) { public void onRiding(EntityMountEvent event) {
if (!(event.getEntity() instanceof Player)) { if (!(event.getEntity() instanceof Player player)) {
return; return;
} }
Player player = (Player) event.getEntity();
DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation());
checkFlag(dom, Flag.RIDING, player, event); checkFlag(dom, Flag.RIDING, player, event);
} }
@ -737,16 +739,10 @@ public class PlayerEvents implements Listener {
} }
@EventHandler(priority = EventPriority.HIGHEST) // shoot @EventHandler(priority = EventPriority.HIGHEST) // shoot
public void onShootArrowSnowball(ProjectileLaunchEvent event) { public void onShootArrowSnowball(ProjectileHitEvent event) {
if (!(event.getEntity().getShooter() instanceof Player)) { if (!(event.getEntity().getShooter() instanceof Player player)) {
return; 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); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player);
checkFlag(dom, Flag.SHOOT, player, event); checkFlag(dom, Flag.SHOOT, player, event);
} }
@ -756,20 +752,18 @@ public class PlayerEvents implements Listener {
if (event.getInventory().getType() != InventoryType.MERCHANT) { if (event.getInventory().getType() != InventoryType.MERCHANT) {
return; return;
} }
if (!(event.getPlayer() instanceof Player)) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) {
return; return;
} }
Player bukkitPlayer = (Player) event.getPlayer();
DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory()); DominionDTO dom = getInvDominion(bukkitPlayer, event.getInventory());
checkFlag(dom, Flag.TRADE, bukkitPlayer, event); checkFlag(dom, Flag.TRADE, bukkitPlayer, event);
} }
@EventHandler(priority = EventPriority.HIGHEST) // vehicle_destroy @EventHandler(priority = EventPriority.HIGHEST) // vehicle_destroy
public void onVehicleDestroy(VehicleDestroyEvent event) { public void onVehicleDestroy(VehicleDestroyEvent event) {
if (!(event.getAttacker() instanceof Player)) { if (!(event.getAttacker() instanceof Player player)) {
return; return;
} }
Player player = (Player) event.getAttacker();
DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation());
checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event);
} }
@ -790,13 +784,12 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // villager_killing @EventHandler(priority = EventPriority.HIGHEST) // villager_killing
public void onVillagerKilling(EntityDamageByEntityEvent event) { public void onVillagerKilling(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)) { if (!(event.getDamager() instanceof Player player)) {
return; return;
} }
if (!(event.getEntity() instanceof Villager)) { if (!(event.getEntity() instanceof Villager)) {
return; return;
} }
Player player = (Player) event.getDamager();
DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation());
checkFlag(dom, Flag.VILLAGER_KILLING, player, event); checkFlag(dom, Flag.VILLAGER_KILLING, player, event);
} }

View File

@ -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<Integer, Location> 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());
}
}
}

17
v1_21/build.gradle.kts Normal file
View File

@ -0,0 +1,17 @@
plugins {
id("java")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
// utf-8
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
dependencies {
compileOnly(project(":core"))
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
}

View File

@ -0,0 +1,295 @@
package cn.lunadeer.dominion.events_v1_21;
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.END_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.TNT_MINECART && entity.getType() != EntityType.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();
Entity harmer = event.getDamager();
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
if (harmer.getType() != EntityType.TNT_MINECART && harmer.getType() != EntityType.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);
}
}

View File

@ -0,0 +1,792 @@
package cn.lunadeer.dominion.events_v1_21;
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.*;
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 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.getRespawnLocation() != null) {
event.setRespawnLocation(bukkitPlayer.getRespawnLocation());
} 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()) && !Tag.TRAPDOORS.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.getRespawnLocation();
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);
}
}

View File

@ -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.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.DominionDTO;