实现了飞行、修复了发光效果逻辑错误问题

This commit is contained in:
zhangyuheng 2024-05-23 17:01:35 +08:00
parent 079961dddb
commit efebd24467
7 changed files with 84 additions and 62 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.25.0-beta</version>
<version>1.26.0-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>

View File

@ -5,6 +5,7 @@ import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.ParticleRender;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -162,6 +163,7 @@ public class Cache {
private void update_player_current_dominion(Player player, DominionDTO dominion) {
lightOrNot(player, dominion); // 发光检查
flyOrNot(player, dominion); // 飞行检查
if (dominion == null) {
player_current_dominion_id.put(player.getUniqueId(), null);
return;
@ -182,7 +184,35 @@ public class Cache {
* @param dominion 领地
*/
private void lightOrNot(Player player, DominionDTO dominion) {
player.setGlowing(checkFlag(dominion, Flag.GLOW, player, null));
if (!Flag.GLOW.getEnable()) {
return;
}
if (dominion == null) {
player.setGlowing(false);
return;
}
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
if (privilege != null) {
player.setGlowing(privilege.getFlagValue(Flag.GLOW));
} else {
player.setGlowing(dominion.getFlagValue(Flag.GLOW));
}
}
private void flyOrNot(Player player, DominionDTO dominion) {
if (!Flag.FLY.getEnable()) {
return;
}
if (dominion == null) {
player.setAllowFlight(false);
return;
}
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
if (privilege != null) {
player.setAllowFlight(privilege.getFlagValue(Flag.FLY));
} else {
player.setAllowFlight(dominion.getFlagValue(Flag.FLY));
}
}
private List<DominionDTO> getDominionsParentAndChildren(Location loc) {

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.dtos;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.minecraftpluginutils.JsonFile;
import cn.lunadeer.minecraftpluginutils.XLogger;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@ -32,7 +33,8 @@ public enum Flag {
ENDER_PEARL("ender_pearl", "投掷末影珍珠", "是否可以使用末影珍珠", false, false, true),
FEED("feed", "喂养", "是否可以喂养动物", false, false, true),
FIRE_SPREAD("fire_spread", "火焰蔓延", "是否可以火焰蔓延", false, true, true),
FLOW_IN_PROTECTION("flow_in_protection", "外部流体是否可以进入", "包含:岩浆、水", false, true, true),
FLOW_IN_PROTECTION("flow_in_protection", "外部流体是否可以进入", "包含:岩浆、水(不会阻止领地内部的流体蔓延)", false, true, true),
FLY("fly", "飞行", "不是翅鞘飞行,是类似于创造模式的飞行", false, false, false),
GLOW("glow", "玩家发光", "类似光灵箭的高亮效果", false, false, true),
HARVEST("harvest", "收获", "收获庄稼、作物", false, false, true),
HONEY("honey", "蜂巢交互", "是否可以采蜂蜜", false, false, true),
@ -177,13 +179,21 @@ public enum Flag {
saveToJson();
}
JSONObject jsonObject = JsonFile.loadFromFile(flagFile);
if (jsonObject == null) {
Dominion.logger.warn("读取权限配置失败,已重置");
saveToJson();
}
for (Flag flag : getAllFlags()) {
JSONObject flagJson = (JSONObject) jsonObject.get(flag.getFlagName());
if (flagJson != null) {
flag.setDisplayName((String) flagJson.get("display_name"));
flag.setDescription((String) flagJson.get("description"));
flag.setDefaultValue((Boolean) flagJson.get("default_value"));
flag.setEnable((Boolean) flagJson.get("enable"));
try {
JSONObject flagJson = (JSONObject) jsonObject.get(flag.getFlagName());
if (flagJson != null) {
flag.setDisplayName((String) flagJson.get("display_name"));
flag.setDescription((String) flagJson.get("description"));
flag.setDefaultValue((Boolean) flagJson.get("default_value"));
flag.setEnable((Boolean) flagJson.get("enable"));
}
} catch (Exception e) {
Dominion.logger.warn("读取权限 %s 配置失败:%s已跳过", flag.getFlagName(), e.getMessage());
}
}
saveToJson(); // 复写一遍确保文件中包含所有权限
@ -203,6 +213,7 @@ public enum Flag {
flagJson.put("enable", f.enable);
json.put(f.getFlagName(), flagJson);
}
Dominion.logger.debug("保存权限配置:%s", json.toJSONString());
File flagFile = new File(Dominion.instance.getDataFolder(), "flags.json");
JsonFile.saveToFile(json, flagFile);
} catch (Exception e) {

View File

@ -63,4 +63,18 @@ public class Apis {
}
return false;
}
public static boolean checkFlag(DominionDTO dom, Flag flag, Cancellable event) {
if (!flag.getEnable()) {
return true;
}
if (dom == null) {
return true;
}
if (dom.getFlagValue(flag)) {
return true;
}
event.setCancelled(true);
return false;
}
}

View File

@ -22,6 +22,7 @@ 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 {
@ -36,13 +37,7 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.CREEPER_EXPLODE)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // fire_spread
@ -53,13 +48,7 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getBlock().getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.FIRE_SPREAD)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.FIRE_SPREAD, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // flow_in_protection
@ -76,9 +65,7 @@ public class EnvironmentEvents implements Listener {
return;
}
}
if (dom_to.getFlagValue(Flag.FLOW_IN_PROTECTION)) {
event.setCancelled(true);
}
checkFlag(dom_to, Flag.FLOW_IN_PROTECTION, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // mob_drop_item
@ -91,6 +78,9 @@ public class EnvironmentEvents implements Listener {
if (dom == null) {
return;
}
if (!Flag.MOB_DROP_ITEM.getEnable()) {
return;
}
if (dom.getFlagValue(Flag.MOB_DROP_ITEM)) {
return;
}
@ -104,13 +94,7 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.TNT_EXPLODE)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.TNT_EXPLODE, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // trample
@ -127,13 +111,7 @@ public class EnvironmentEvents implements Listener {
}
Location location = block.getLocation();
DominionDTO dom = Cache.instance.getDominion(location);
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.TRAMPLE)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.TRAMPLE, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // wither_spawn
@ -143,13 +121,7 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getDominion(entity.getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.WITHER_SPAWN)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.WITHER_SPAWN, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // ender_man spawn
@ -159,25 +131,13 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getDominion(entity.getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.ENDER_MAN)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.ENDER_MAN, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // ender_man escape
public void onEnderManEscape(EndermanEscapeEvent event){
Entity entity = event.getEntity();
DominionDTO dom = Cache.instance.getDominion(entity.getLocation());
if (dom == null) {
return;
}
if (dom.getFlagValue(Flag.ENDER_MAN)) {
return;
}
event.setCancelled(true);
checkFlag(dom, Flag.ENDER_MAN, event);
}
}

View File

@ -40,6 +40,9 @@ public class PlayerEvents implements Listener {
Player bukkitPlayer = event.getPlayer();
PlayerDTO player = PlayerDTO.get(bukkitPlayer);
player.onJoin(); // update name
if (!Flag.FLY.getEnable()) {
bukkitPlayer.setAllowFlight(false);
}
}
@EventHandler(priority = EventPriority.HIGHEST) // anchor
@ -49,7 +52,7 @@ public class PlayerEvents implements Listener {
return;
}
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer);
if (checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) {
if (!checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) {
if (bukkitPlayer.getBedSpawnLocation() != null) {
event.setRespawnLocation(bukkitPlayer.getBedSpawnLocation());
} else {

View File

@ -165,5 +165,9 @@ public class DatabaseTables {
// 1.21
Dominion.database.addColumnIfNotExists("dominion", "show_border", "BOOLEAN NOT NULL DEFAULT TRUE");
// 1.26
Dominion.database.addColumnIfNotExists("dominion", "fly", "BOOLEAN NOT NULL DEFAULT FALSE");
Dominion.database.addColumnIfNotExists("player_privilege", "fly", "BOOLEAN NOT NULL DEFAULT FALSE");
}
}