mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2024-12-20 01:06:31 +08:00
新增领地边界显示相关功能以及对应权限控制
This commit is contained in:
parent
0244c4ae20
commit
3dd1843adb
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>Dominion</artifactId>
|
||||
<version>1.20.3-beta</version>
|
||||
<version>1.21.4-beta</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Dominion</name>
|
||||
|
@ -3,6 +3,7 @@ package cn.lunadeer.dominion;
|
||||
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
|
||||
import cn.lunadeer.dominion.utils.Notification;
|
||||
import cn.lunadeer.dominion.utils.ParticleRender;
|
||||
import cn.lunadeer.dominion.utils.XLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
@ -127,7 +128,7 @@ public class Cache {
|
||||
if (dominion.getParentDomId() == -1) {
|
||||
Notification.info(player, "您已离开领地:" + dominion.getName());
|
||||
player.sendMessage(Component.text(dominion.getLeaveMessage()));
|
||||
player_current_dominion_id.put(player.getUniqueId(), null);
|
||||
update_player_current_dominion(player, null);
|
||||
dominion = null;
|
||||
} else {
|
||||
Notification.info(player, "您已离开子领地:" + dominion.getName());
|
||||
@ -172,7 +173,16 @@ public class Cache {
|
||||
}
|
||||
|
||||
private void update_player_current_dominion(Player player, DominionDTO dominion) {
|
||||
if (dominion == null) {
|
||||
player.setGlowing(false);
|
||||
player_current_dominion_id.put(player.getUniqueId(), null);
|
||||
return;
|
||||
}
|
||||
player_current_dominion_id.put(player.getUniqueId(), dominion.getId());
|
||||
// show border
|
||||
if (dominion.getShowBorder()) {
|
||||
ParticleRender.showBoxBorder(dominion);
|
||||
}
|
||||
// glow
|
||||
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
|
||||
if (privilege != null) {
|
||||
|
@ -380,16 +380,6 @@ public class DominionOperate {
|
||||
if (location == null) {
|
||||
Notification.error(sender, "此领地没有设置传送点");
|
||||
return;
|
||||
// int center_x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2;
|
||||
// int center_z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2;
|
||||
// // find safe location
|
||||
// World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld());
|
||||
// if (world == null) {
|
||||
// Notification.error(sender, "此领地所在世界不存在");
|
||||
// XLogger.warn("领地 " + dominionDTO.getName() + " 所在世界不存在");
|
||||
// return;
|
||||
// }
|
||||
// location = world.getHighestBlockAt(center_x, center_z).getLocation();
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.lunadeer.dominion.controllers.Apis.*;
|
||||
import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder;
|
||||
|
||||
public class DominionController {
|
||||
|
||||
@ -157,6 +158,7 @@ public class DominionController {
|
||||
Notification.error(owner, "创建失败,详细错误请联系管理员查询日志(当前时间:" + Time.nowStr() + ")");
|
||||
return null;
|
||||
}
|
||||
showBoxBorder(dominion.getWorld(), dominion.getX1(), dominion.getY1(), dominion.getZ1(), dominion.getX2(), dominion.getY2(), dominion.getZ2());
|
||||
return dominion.setParentDomId(parent_dominion.getId());
|
||||
}
|
||||
|
||||
@ -268,6 +270,7 @@ public class DominionController {
|
||||
Notification.info(operator, "已扣除 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
Dominion.vault.getEconomy().withdrawPlayer(operator, price);
|
||||
}
|
||||
showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2);
|
||||
return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
@ -368,6 +371,7 @@ public class DominionController {
|
||||
Dominion.vault.getEconomy().depositPlayer(operator, refund);
|
||||
Notification.info(operator, "已经退还 " + refund + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
}
|
||||
showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2);
|
||||
return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ public class FlagsController {
|
||||
case "repeater": return dominion.setRepeater(value);
|
||||
case "shear": return dominion.setShear(value);
|
||||
case "shoot": return dominion.setShoot(value);
|
||||
case "show_border": return dominion.setShowBorder(value);
|
||||
case "teleport": return dominion.setTeleport(value);
|
||||
case "tnt_explode": return dominion.setTntExplode(value);
|
||||
case "trade": return dominion.setTrade(value);
|
||||
|
@ -78,6 +78,7 @@ public class DominionDTO {
|
||||
rs.getBoolean("repeater"),
|
||||
rs.getBoolean("shear"),
|
||||
rs.getBoolean("shoot"),
|
||||
rs.getBoolean("show_border"),
|
||||
rs.getBoolean("teleport"),
|
||||
rs.getBoolean("tnt_explode"),
|
||||
rs.getBoolean("trade"),
|
||||
@ -233,6 +234,7 @@ public class DominionDTO {
|
||||
"repeater = " + dominion.getRepeater() + ", " +
|
||||
"shear = " + dominion.getShear() + ", " +
|
||||
"shoot = " + dominion.getShoot() + ", " +
|
||||
"show_border = " + dominion.getShowBorder() + ", " + // dom only
|
||||
"teleport = " + dominion.getTeleport() + ", " +
|
||||
"tnt_explode = " + dominion.getTntExplode() + ", " + // dom only
|
||||
"trade = " + dominion.getTrade() + ", " +
|
||||
@ -265,7 +267,7 @@ public class DominionDTO {
|
||||
Boolean mobDropItem, Boolean monsterKilling, Boolean move,
|
||||
Boolean place, Boolean pressure,
|
||||
Boolean riding, Boolean repeater,
|
||||
Boolean shear, Boolean shoot,
|
||||
Boolean shear, Boolean shoot, Boolean showBorder,
|
||||
Boolean teleport, Boolean tntExplode, Boolean trade, Boolean trample,
|
||||
Boolean vehicleDestroy,
|
||||
Boolean vehicleSpawn,
|
||||
@ -322,6 +324,7 @@ public class DominionDTO {
|
||||
this.repeater = repeater;
|
||||
this.shear = shear;
|
||||
this.shoot = shoot;
|
||||
this.showBorder = showBorder;
|
||||
this.teleport = teleport;
|
||||
this.tntExplode = tntExplode;
|
||||
this.trade = trade;
|
||||
@ -416,6 +419,7 @@ public class DominionDTO {
|
||||
private Boolean repeater = false;
|
||||
private Boolean shear = false;
|
||||
private Boolean shoot = false;
|
||||
private Boolean showBorder = true;
|
||||
private Boolean teleport = false;
|
||||
private Boolean tntExplode = false;
|
||||
private Boolean trade = false;
|
||||
@ -880,6 +884,15 @@ public class DominionDTO {
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public Boolean getShowBorder() {
|
||||
return showBorder;
|
||||
}
|
||||
|
||||
public DominionDTO setShowBorder(Boolean showBorder) {
|
||||
this.showBorder = showBorder;
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public Boolean getTeleport() {
|
||||
return teleport;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.lunadeer.dominion.events;
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.utils.Notification;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,6 +17,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder;
|
||||
|
||||
|
||||
public class SelectPointEvents implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -54,6 +57,10 @@ public class SelectPointEvents implements Listener {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
if (!points.get(0).getWorld().equals(points.get(1).getWorld())) {
|
||||
Notification.error(player, "两个点不在同一个世界");
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc1 = points.get(0);
|
||||
Location loc2 = points.get(1);
|
||||
@ -73,7 +80,7 @@ public class SelectPointEvents implements Listener {
|
||||
double price = count * Dominion.config.getEconomyPrice();
|
||||
Notification.info(player, "预计领地创建价格为 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural());
|
||||
}
|
||||
// todo 用粒子效果显示边界
|
||||
showBoxBorder(loc1, loc2);
|
||||
|
||||
Notification.info(player, "已选择两个点,可以使用 /dominion create <领地名称> 创建领地");
|
||||
Notification.info(player, "尺寸为 " +
|
||||
|
@ -380,6 +380,15 @@ public class DominionFlagInfo {
|
||||
.append(Button.createRed("☐", "/dominion set shoot true " + dominion.getName() + " " + page))
|
||||
.append("射箭/雪球/三叉戟"));
|
||||
}
|
||||
if (dominion.getShowBorder()) {
|
||||
view.add(Line.create()
|
||||
.append(Button.createGreen("☑", "/dominion set show_border false " + dominion.getName() + " " + page))
|
||||
.append("玩家进入时是否显示领地边界"));
|
||||
} else {
|
||||
view.add(Line.create()
|
||||
.append(Button.createRed("☐", "/dominion set show_border true " + dominion.getName() + " " + page))
|
||||
.append("玩家进入时是否显示领地边界"));
|
||||
}
|
||||
if (dominion.getTeleport()) {
|
||||
view.add(Line.create()
|
||||
.append(Button.createGreen("☑", "/dominion set teleport false " + dominion.getName() + " " + page))
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
|
||||
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
|
||||
import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder;
|
||||
|
||||
public class DominionSizeInfo {
|
||||
public static void show(CommandSender sender, String[] args) {
|
||||
@ -47,5 +48,6 @@ public class DominionSizeInfo {
|
||||
.append(Button.create("管理界面", "/dominion manage " + dominion.getName()))
|
||||
.append(Button.create("权限列表", "/dominion flag_info " + dominion.getName())))
|
||||
.showOn(player);
|
||||
showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
}
|
||||
|
@ -245,5 +245,8 @@ public class Database {
|
||||
addColumnIfNotExists("dominion", "tp_location", "TEXT NOT NULL DEFAULT 'default'");
|
||||
addColumnIfNotExists("dominion", "teleport", "BOOLEAN NOT NULL DEFAULT FALSE");
|
||||
addColumnIfNotExists("player_privilege", "teleport", "BOOLEAN NOT NULL DEFAULT FALSE");
|
||||
|
||||
// 1.21
|
||||
addColumnIfNotExists("dominion", "show_border", "BOOLEAN NOT NULL DEFAULT TRUE");
|
||||
}
|
||||
}
|
||||
|
55
src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java
Normal file
55
src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java
Normal file
@ -0,0 +1,55 @@
|
||||
package cn.lunadeer.dominion.utils;
|
||||
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class ParticleRender {
|
||||
|
||||
public static void showBoxBorder(DominionDTO dominion) {
|
||||
showBoxBorder(dominion.getWorld(), dominion.getX1(), dominion.getY1(), dominion.getZ1(), dominion.getX2(), dominion.getY2(), dominion.getZ2());
|
||||
}
|
||||
|
||||
public static void showBoxBorder(String world, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
showBoxBorder(new Location(Dominion.instance.getServer().getWorld(world), x1, y1, z1), new Location(Dominion.instance.getServer().getWorld(world), x2, y2, z2));
|
||||
}
|
||||
|
||||
public static void showBoxBorder(Location loc1, Location loc2) {
|
||||
Dominion.scheduler.region.run(Dominion.instance, (instance) -> {
|
||||
if (!loc1.getWorld().equals(loc2.getWorld())) {
|
||||
return;
|
||||
}
|
||||
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;
|
||||
World world = loc1.getWorld();
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
spawnParticle(world, x, minY, minZ);
|
||||
spawnParticle(world, x, minY, maxZ);
|
||||
spawnParticle(world, x, maxY, minZ);
|
||||
spawnParticle(world, x, maxY, maxZ);
|
||||
}
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
spawnParticle(world, minX, y, minZ);
|
||||
spawnParticle(world, minX, y, maxZ);
|
||||
spawnParticle(world, maxX, y, minZ);
|
||||
spawnParticle(world, maxX, y, maxZ);
|
||||
}
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
spawnParticle(world, minX, minY, z);
|
||||
spawnParticle(world, minX, maxY, z);
|
||||
spawnParticle(world, maxX, minY, z);
|
||||
spawnParticle(world, maxX, maxY, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void spawnParticle(World world, double x, double y, double z) {
|
||||
world.spawnParticle(Particle.FLAME, x, y, z, 10, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user