Merge branch 'bukkit-impl'

# Conflicts:
#	pom.xml
#	src/main/java/cn/lunadeer/dominion/controllers/PrivilegeController.java
This commit is contained in:
zhangyuheng 2024-06-09 21:35:55 +08:00
commit e731a9023d
12 changed files with 60 additions and 105 deletions

View File

@ -82,7 +82,7 @@
<dependency>
<groupId>cn.lunadeer</groupId>
<artifactId>MinecraftPluginUtils</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.3.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.BlueMap-Minecraft</groupId>
@ -90,11 +90,5 @@
<version>v2.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -4,10 +4,10 @@ import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.ParticleRender;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -143,7 +143,7 @@ public class Cache {
// Notification.info(player, "您已离开子领地:%s", last_dominion.getName());
String msg = last_dominion.getLeaveMessage();
msg = msg.replace("${DOM_NAME}", last_dominion.getName());
player.sendActionBar(Component.text(msg));
Notification.actionBar(player, msg);
}
if (current_dom_id != -1) {
// if (current_dominion.getParentDomId() == -1)
@ -152,7 +152,7 @@ public class Cache {
// Notification.info(player, "您正在进入子领地:%s", current_dominion.getName());
String msg = current_dominion.getJoinMessage();
msg = msg.replace("${DOM_NAME}", current_dominion.getName());
player.sendActionBar(Component.text(msg));
Notification.actionBar(player, msg);
}
lightOrNot(player, current_dominion); // 发光检查

View File

@ -37,14 +37,7 @@ public final class Dominion extends JavaPlugin {
new Scheduler(this);
AutoClean.run();
Cache.instance = new Cache();
if (config.getEconomyEnable()) {
vault = new VaultConnect(this);
if (vault.getEconomy() == null) {
XLogger.err("你没有安装 Vault 前置插件,无法使用经济功能。");
config.setEconomyEnable(false);
}
}
new VaultConnect(this);
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this);
@ -63,7 +56,7 @@ public final class Dominion extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new CuiManager(this), this);
XLogger.info("领地插件已启动");
XLogger.info("版本:" + this.getPluginMeta().getVersion());
XLogger.info("版本:" + this.getDescription().getVersion());
// http://patorjk.com/software/taag/#p=display&f=Big&t=Dominion
XLogger.info(" _____ _ _");
XLogger.info(" | __ \\ (_) (_)");
@ -79,6 +72,7 @@ public final class Dominion extends JavaPlugin {
@Override
public void onDisable() {
// Plugin shutdown logic
database.close();
}
public static Dominion instance;
@ -86,5 +80,4 @@ public final class Dominion extends JavaPlugin {
public static DatabaseManager database;
public static Map<UUID, Map<Integer, Location>> pointsSelect = new HashMap<>();
private GiteaReleaseCheck giteaReleaseCheck;
public static VaultConnect vault;
}

View File

@ -1,62 +0,0 @@
package cn.lunadeer.dominion;
import cn.lunadeer.minecraftpluginutils.XLogger;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class VaultConnect {
private Economy econ = null;
private Permission perms = null;
private Chat chat = null;
private JavaPlugin plugin;
public VaultConnect(JavaPlugin plugin) {
this.plugin = plugin;
if (!setupEconomy()) {
XLogger.err("你没有安装 Vault 前置插件,无法使用经济功能,如果不需要使用经济功能请前往配置文件关闭。");
return;
}
setupPermissions();
setupChat();
}
private boolean setupEconomy() {
if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
private boolean setupChat() {
RegisteredServiceProvider<Chat> rsp = plugin.getServer().getServicesManager().getRegistration(Chat.class);
chat = rsp.getProvider();
return chat != null;
}
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> rsp = plugin.getServer().getServicesManager().getRegistration(Permission.class);
perms = rsp.getProvider();
return perms != null;
}
public Economy getEconomy() {
return econ;
}
public Permission getPermissions() {
return perms;
}
public Chat getChat() {
return chat;
}
}

View File

@ -6,6 +6,7 @@ import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.ParticleRender;
import cn.lunadeer.minecraftpluginutils.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.World;
@ -143,6 +144,10 @@ public class DominionController {
}
// 检查经济
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(FAIL.addMessage("没有可用的经济插件系统,请联系服主。"));
return;
}
int count;
if (Dominion.config.getEconomyOnlyXZ()) {
count = dominion.getSquare();
@ -150,12 +155,12 @@ public class DominionController {
count = dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice();
if (Dominion.vault.getEconomy().getBalance(operator.getPlayer()) < price) {
operator.setResponse(FAIL.addMessage("你的余额不足,创建此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
if (VaultConnect.instance.getBalance(operator.getPlayer()) < price) {
operator.setResponse(FAIL.addMessage("你的余额不足,创建此领地需要 %.2f %s", price, VaultConnect.instance.currencyNamePlural()));
return;
}
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
Dominion.vault.getEconomy().withdrawPlayer(operator.getPlayer(), price);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "已扣除 %.2f %s", price, VaultConnect.instance.currencyNamePlural()));
VaultConnect.instance.withdrawPlayer(operator.getPlayer(), price);
}
dominion = DominionDTO.insert(dominion);
if (dominion == null) {
@ -264,6 +269,10 @@ public class DominionController {
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功扩展领地 %s %d格", dominion_name, size);
// 检查经济
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(FAIL.addMessage("没有可用的经济插件系统,请联系服主。"));
return;
}
int count;
if (Dominion.config.getEconomyOnlyXZ()) {
count = (x2 - x1 + 1) * (z2 - z1 + 1) - dominion.getSquare();
@ -271,12 +280,12 @@ public class DominionController {
count = (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1) - dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice();
if (Dominion.vault.getEconomy().getBalance(operator.getPlayer()) < price) {
operator.setResponse(FAIL.addMessage("你的余额不足,扩展此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
if (VaultConnect.instance.getBalance(operator.getPlayer()) < price) {
operator.setResponse(FAIL.addMessage("你的余额不足,扩展此领地需要 %.2f %s", price, VaultConnect.instance.currencyNamePlural()));
return;
}
SUCCESS.addMessage("已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
Dominion.vault.getEconomy().withdrawPlayer(operator.getPlayer(), price);
SUCCESS.addMessage("已扣除 %.2f %s", price, VaultConnect.instance.currencyNamePlural());
VaultConnect.instance.withdrawPlayer(operator.getPlayer(), price);
}
if (operator instanceof BukkitPlayerOperator) {
World world = Dominion.instance.getServer().getWorld(dominion.getWorld());
@ -376,6 +385,10 @@ public class DominionController {
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功缩小领地 %s %d格", dominion_name, size);
// 退还经济
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(FAIL.addMessage("没有可用的经济插件系统,请联系服主。"));
return;
}
int count;
if (Dominion.config.getEconomyOnlyXZ()) {
count = dominion.getSquare() - (x2 - x1 + 1) * (z2 - z1 + 1);
@ -383,8 +396,8 @@ public class DominionController {
count = dominion.getVolume() - (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1);
}
float refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
Dominion.vault.getEconomy().depositPlayer(operator.getPlayer(), refund);
SUCCESS.addMessage("已退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
VaultConnect.instance.depositPlayer(operator.getPlayer(), refund);
SUCCESS.addMessage("已退还 %.2f %s", refund, VaultConnect.instance.currencyNamePlural());
}
if (operator instanceof BukkitPlayerOperator) {
World world = Dominion.instance.getServer().getWorld(dominion.getWorld());
@ -429,6 +442,10 @@ public class DominionController {
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "领地 %s 及其所有子领地已删除", dominion_name);
// 退还经济
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "退款失败,没有可用的经济插件系统,请联系服主。"));
return;
}
int count = 0;
if (Dominion.config.getEconomyOnlyXZ()) {
for (DominionDTO sub_dominion : sub_dominions) {
@ -440,8 +457,8 @@ public class DominionController {
}
}
float refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
Dominion.vault.getEconomy().depositPlayer(operator.getPlayer(), refund);
SUCCESS.addMessage("已退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
VaultConnect.instance.depositPlayer(operator.getPlayer(), refund);
SUCCESS.addMessage("已退还 %.2f %s", refund, VaultConnect.instance.currencyNamePlural());
}
operator.setResponse(SUCCESS);
}

View File

@ -27,8 +27,8 @@ public enum Flag {
CRAFT("craft", "使用工作台", "是否可以使用工作台", false, false, true),
CREEPER_EXPLODE("creeper_explode", "实体爆炸", "包含:苦力怕/凋零头颅/水晶爆炸", false, true, true),
COMPARER("comparer", "比较器交互", "是否可以与比较器交互", false, false, true),
DOOR("door", "门交互", "是否可以使用各种材质的门", false, false, true),
DYE("dye", "染色", "是否可以使用染料染色", false, false, true),
DOOR("door", "门交互", "是否可以使用各种材质的门(包括活板门)", false, false, true),
DYE("dye", "染色", "是否可以使用染料(对羊、狗项圈、猫项圈)染色", false, false, true),
EGG("egg", "扔鸡蛋", "是否可以扔鸡蛋", false, false, true),
ENCHANT("enchant", "使用附魔台", "是否可以使用附魔台", false, false, true),
ENDER_MAN("ender_man", "末影人行为", "包含:末影人是否可以生成、瞬移", false, true, true),

View File

@ -63,8 +63,7 @@ public class Apis {
String.format("你没有 %s (%s) 权限", flag.getDisplayName(), flag.getDescription()),
Style.style(TextColor.color(0xFF0000), TextDecoration.BOLD))
.hoverEvent(Component.text(flag.getDescription()));
// Notification.error(player, msg);
player.sendActionBar(msg);
Notification.actionBar(player, msg);
if (event != null) {
event.setCancelled(true);
}

View File

@ -3,7 +3,6 @@ package cn.lunadeer.dominion.events;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import com.destroystokyo.paper.event.entity.EndermanEscapeEvent;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
@ -16,6 +15,7 @@ import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Objects;
@ -133,8 +133,11 @@ public class EnvironmentEvents implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST) // ender_man escape
public void onEnderManEscape(EndermanEscapeEvent event) {
public void onEnderManEscape(EntityTeleportEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.ENDERMAN) {
return;
}
DominionDTO dom = Cache.instance.getDominion(entity.getLocation());
checkFlag(dom, Flag.ENDER_MAN, event);
}

View File

@ -6,7 +6,6 @@ import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Teleport;
import io.papermc.paper.event.entity.EntityDyeEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -338,12 +337,15 @@ public class PlayerEvents implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST) // dye
public void dyeEvent(EntityDyeEvent event) {
public void dyeEvent(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
if (player == null) {
Entity entity = event.getRightClicked();
if (!(entity instanceof Sheep)
&& !(entity instanceof Wolf)
&& !(entity instanceof Cat)) {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getEntity().getLocation());
DominionDTO dom = Cache.instance.getDominion(entity.getLocation());
checkFlag(dom, Flag.DYE, player, event);
}

View File

@ -4,6 +4,7 @@ import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.ParticleRender;
import cn.lunadeer.minecraftpluginutils.VaultConnect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -75,6 +76,10 @@ public class SelectPointEvents implements Listener {
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();
@ -82,7 +87,7 @@ public class SelectPointEvents implements Listener {
count = dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice();
Notification.info(player, "预计领地创建价格为 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
Notification.info(player, "预计领地创建价格为 %.2f %s", price, VaultConnect.instance.currencyNamePlural());
}
ParticleRender.showBoxFace(Dominion.instance, player, loc1, loc2);
Notification.info(player, "尺寸: %d x %d x %d", dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ());

View File

@ -351,6 +351,8 @@ public class ConfigManager {
public void setEconomyEnable(Boolean economy_enable) {
_economy_enable = economy_enable;
_file.set("Economy.Enable", economy_enable);
_plugin.saveConfig();
}
public Float getEconomyPrice() {

View File

@ -4,6 +4,8 @@ main: cn.lunadeer.dominion.Dominion
api-version: '1.20'
load: STARTUP
folia-supported: true
loadbefore:
- Vault
commands:
Dominion:
description: 领地插件命令