This commit is contained in:
parent
f259f63703
commit
ace2e35a19
8
pom.xml
8
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>Dominion</artifactId>
|
||||
<version>1.19.1-beta</version>
|
||||
<version>1.20.1-beta</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Dominion</name>
|
||||
@ -91,5 +91,11 @@
|
||||
<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>
|
||||
|
@ -28,6 +28,13 @@ public final class Dominion extends JavaPlugin {
|
||||
AutoClean.run();
|
||||
Cache.instance = new Cache();
|
||||
|
||||
if (config.getEconomyEnable()) {
|
||||
vault = new VaultConnect(this);
|
||||
if (vault.getEconomy() == null) {
|
||||
config.setEconomyEnable(false);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SelectPointEvents(), this);
|
||||
@ -68,4 +75,5 @@ public final class Dominion extends JavaPlugin {
|
||||
public static Map<UUID, Map<Integer, Location>> pointsSelect = new HashMap<>();
|
||||
public static Scheduler scheduler;
|
||||
private GiteaReleaseCheck giteaReleaseCheck;
|
||||
public static VaultConnect vault;
|
||||
}
|
||||
|
62
src/main/java/cn/lunadeer/dominion/VaultConnect.java
Normal file
62
src/main/java/cn/lunadeer/dominion/VaultConnect.java
Normal file
@ -0,0 +1,62 @@
|
||||
package cn.lunadeer.dominion;
|
||||
|
||||
import cn.lunadeer.dominion.utils.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;
|
||||
}
|
||||
}
|
@ -90,6 +90,21 @@ public class DominionController {
|
||||
loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ())) {
|
||||
return null;
|
||||
}
|
||||
// 检查经济
|
||||
if (Dominion.config.getEconomyEnable()) {
|
||||
int count;
|
||||
if (Dominion.config.getEconomyOnlyXZ()) {
|
||||
count = (loc2.getBlockX() - loc1.getBlockX() + 1) * (loc2.getBlockZ() - loc1.getBlockZ() + 1);
|
||||
} else {
|
||||
count = (loc2.getBlockX() - loc1.getBlockX() + 1) * (loc2.getBlockY() - loc1.getBlockY() + 1) * (loc2.getBlockZ() - loc1.getBlockZ() + 1);
|
||||
}
|
||||
double price = count * Dominion.config.getEconomyPrice();
|
||||
if (Dominion.vault.getEconomy().getBalance(owner) < price) {
|
||||
Notification.error(owner, "你的余额不足,创建此领地需要 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
return null;
|
||||
}
|
||||
Dominion.vault.getEconomy().withdrawPlayer(owner, price);
|
||||
}
|
||||
DominionDTO dominion = new DominionDTO(owner.getUniqueId(), name, owner.getWorld().getName(),
|
||||
(int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
|
||||
(int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),
|
||||
@ -236,6 +251,21 @@ public class DominionController {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 检查经济
|
||||
if (Dominion.config.getEconomyEnable()) {
|
||||
int count;
|
||||
if (Dominion.config.getEconomyOnlyXZ()) {
|
||||
count = (x2 - x1 + 1) * (z2 - z1 + 1) - dominion.getSquare();
|
||||
} else {
|
||||
count = (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1) - dominion.getVolume();
|
||||
}
|
||||
double price = count * Dominion.config.getEconomyPrice();
|
||||
if (Dominion.vault.getEconomy().getBalance(operator) < price) {
|
||||
Notification.error(operator, "你的余额不足,扩展此领地需要 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
return null;
|
||||
}
|
||||
Dominion.vault.getEconomy().withdrawPlayer(operator, price);
|
||||
}
|
||||
return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
@ -324,6 +354,18 @@ public class DominionController {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 退还经济
|
||||
if (Dominion.config.getEconomyEnable()) {
|
||||
int count;
|
||||
if (Dominion.config.getEconomyOnlyXZ()) {
|
||||
count = dominion.getSquare() - (x2 - x1 + 1) * (z2 - z1 + 1);
|
||||
} else {
|
||||
count = dominion.getVolume() - (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1);
|
||||
}
|
||||
double refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
|
||||
Dominion.vault.getEconomy().depositPlayer(operator, refund);
|
||||
XLogger.info("已经退还 " + refund + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
}
|
||||
return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
@ -358,6 +400,22 @@ public class DominionController {
|
||||
return;
|
||||
}
|
||||
DominionDTO.delete(dominion);
|
||||
// 退还经济
|
||||
if (Dominion.config.getEconomyEnable()) {
|
||||
int count = 0;
|
||||
if (Dominion.config.getEconomyOnlyXZ()) {
|
||||
for (DominionDTO sub_dominion : sub_dominions) {
|
||||
count += sub_dominion.getSquare();
|
||||
}
|
||||
} else {
|
||||
for (DominionDTO sub_dominion : sub_dominions) {
|
||||
count += sub_dominion.getVolume();
|
||||
}
|
||||
}
|
||||
double refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
|
||||
Dominion.vault.getEconomy().depositPlayer(operator, refund);
|
||||
XLogger.info("已经退还 " + refund + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
}
|
||||
Notification.info(operator, "领地 " + dominion_name + " 及其所有子领地已删除");
|
||||
}
|
||||
|
||||
|
@ -512,6 +512,14 @@ public class DominionDTO {
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public Integer getSquare() {
|
||||
return (x2 - x1) * (z2 - z1);
|
||||
}
|
||||
|
||||
public Integer getVolume() {
|
||||
return getSquare() * (y2 - y1);
|
||||
}
|
||||
|
||||
public Integer getParentDomId() {
|
||||
return parentDomId;
|
||||
}
|
||||
|
@ -68,6 +68,10 @@ public class ConfigManager {
|
||||
XLogger.err("工具名称设置错误,已重置为 ARROW");
|
||||
setTool("ARROW");
|
||||
}
|
||||
_economy_enable = _file.getBoolean("Economy.Enable", false);
|
||||
_economy_price = (float) _file.getDouble("Economy.Price", 10.0);
|
||||
_economy_only_xz = _file.getBoolean("Economy.OnlyXZ", false);
|
||||
_economy_refund = (float) _file.getDouble("Economy.Refund", 0.85);
|
||||
}
|
||||
|
||||
public Boolean isDebug() {
|
||||
@ -276,6 +280,26 @@ public class ConfigManager {
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public Boolean getEconomyEnable() {
|
||||
return _economy_enable;
|
||||
}
|
||||
|
||||
public void setEconomyEnable(Boolean economy_enable) {
|
||||
_economy_enable = economy_enable;
|
||||
}
|
||||
|
||||
public Float getEconomyPrice() {
|
||||
return _economy_price;
|
||||
}
|
||||
|
||||
public Boolean getEconomyOnlyXZ() {
|
||||
return _economy_only_xz;
|
||||
}
|
||||
|
||||
public Float getEconomyRefund() {
|
||||
return _economy_refund;
|
||||
}
|
||||
|
||||
private final Dominion _plugin;
|
||||
private FileConfiguration _file;
|
||||
private Boolean _debug;
|
||||
@ -306,4 +330,9 @@ public class ConfigManager {
|
||||
private Integer _tp_delay;
|
||||
private Integer _tp_cool_down;
|
||||
private String _tool;
|
||||
|
||||
private Boolean _economy_enable;
|
||||
private Float _economy_price;
|
||||
private Boolean _economy_only_xz;
|
||||
private Float _economy_refund;
|
||||
}
|
||||
|
@ -33,6 +33,16 @@ AutoCleanAfterDays: 180 # -1 表示不开启
|
||||
# 圈地工具
|
||||
Tool: ARROW
|
||||
|
||||
# 经济系统 - 需要安装Vault插件
|
||||
Economy:
|
||||
Enable: false
|
||||
# 单价 - 每方块
|
||||
Price: 10.0
|
||||
# 是否只计算xz平面积
|
||||
OnlyXZ: false
|
||||
# 删除领地退还比例
|
||||
Refund: 0.85
|
||||
|
||||
BlueMap: true
|
||||
|
||||
CheckUpdate: true
|
||||
|
Reference in New Issue
Block a user