新增载具放置权限
All checks were successful
Java CI-CD with Maven / build (push) Successful in 15m4s

增加了领地名称判断 避免空格
This commit is contained in:
zhangyuheng 2024-02-23 14:56:20 +08:00
parent 52cd061cc1
commit 33bff49268
11 changed files with 126 additions and 25 deletions

View File

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

View File

@ -32,6 +32,7 @@ public class Helper {
"shear", "shoot",
"tnt_explode", "trade",
"vehicle_destroy",
"vehicle_spawn",
"wither_spawn");
}
@ -51,7 +52,8 @@ public class Helper {
"place", "pressure", "riding", "repeater",
"shear", "shoot",
"trade",
"vehicle_destroy");
"vehicle_destroy",
"vehicle_spawn");
}
/**

View File

@ -53,6 +53,10 @@ public class DominionController {
public static DominionDTO create(Player owner, String name,
Location loc1, Location loc2,
String parent_dominion_name) {
if (name.contains(" ")) {
Notification.error(owner, "领地名称不能包含空格");
return null;
}
if (DominionDTO.select(name) != null) {
Notification.error(owner, "已经存在名称为 " + name + " 的领地");
return null;
@ -413,6 +417,10 @@ public class DominionController {
* @param new_name 新名称
*/
public static void rename(Player operator, String old_name, String new_name) {
if (new_name.contains(" ")) {
Notification.error(operator, "领地名称不能包含空格");
return;
}
DominionDTO dominion = DominionDTO.select(old_name);
if (dominion == null) {
Notification.error(operator, "领地 " + old_name + " 不存在");

View File

@ -76,6 +76,7 @@ public class FlagsController {
case "tnt_explode": return dominion.setTntExplode(value);
case "trade": return dominion.setTrade(value);
case "vehicle_destroy": return dominion.setVehicleDestroy(value);
case "vehicle_spawn": return dominion.setVehicleSpawn(value);
case "wither_spawn": return dominion.setWitherSpawn(value);
default:
Notification.error(operator, "未知的领地权限 " + flag);

View File

@ -211,6 +211,9 @@ public class PrivilegeController {
case "vehicle_destroy":
privilege.setVehicleDestroy(value);
break;
case "vehicle_spawn":
privilege.setVehicleSpawn(value);
break;
default:
Notification.error(operator, "未知的领地权限 " + flag);
return false;
@ -264,7 +267,8 @@ public class PrivilegeController {
dom.getRiding(), dom.getRepeater(),
dom.getShear(), dom.getShoot(),
dom.getTrade(),
dom.getVehicleDestroy());
dom.getVehicleDestroy(),
dom.getVehicleSpawn());
privilege = PlayerPrivilegeDTO.insert(privilege);
if (privilege == null) {
Notification.error(operator, "创建玩家特权失败,可能是此玩家已存在特权");

View File

@ -70,6 +70,7 @@ public class DominionDTO {
rs.getBoolean("tnt_explode"),
rs.getBoolean("trade"),
rs.getBoolean("vehicle_destroy"),
rs.getBoolean("vehicle_spawn"),
rs.getBoolean("wither_spawn")
);
dominions.add(dominion);
@ -215,6 +216,7 @@ public class DominionDTO {
"tnt_explode = " + dominion.getTntExplode() + ", " + // dom only
"trade = " + dominion.getTrade() + ", " +
"vehicle_destroy = " + dominion.getVehicleDestroy() + ", " +
"vehicle_spawn = " + dominion.getVehicleSpawn() + ", " +
"wither_spawn = " + dominion.getWitherSpawn() + " " + // dom only
" WHERE id = " + dominion.getId() +
" RETURNING *;";
@ -243,6 +245,7 @@ public class DominionDTO {
Boolean shear, Boolean shoot,
Boolean tntExplode, Boolean trade,
Boolean vehicleDestroy,
Boolean vehicleSpawn,
Boolean witherSpawn) {
this.id = id;
this.owner = owner;
@ -296,6 +299,7 @@ public class DominionDTO {
this.tntExplode = tntExplode;
this.trade = trade;
this.vehicleDestroy = vehicleDestroy;
this.vehicleSpawn = vehicleSpawn;
this.witherSpawn = witherSpawn;
}
@ -311,7 +315,7 @@ public class DominionDTO {
false, false, false, false, true,
true, false, false, false, false, false, false,
false, true, false, false, false, false,
false, false, false, false, false, false);
false, false, false, false, false, false, false);
}
public DominionDTO(UUID owner, String name, String world,
@ -370,6 +374,7 @@ public class DominionDTO {
private Boolean tntExplode = false;
private Boolean trade = false;
private Boolean vehicleDestroy = false;
private Boolean vehicleSpawn = false;
private Boolean witherSpawn = false;
private Boolean harvest = false;
@ -828,6 +833,15 @@ public class DominionDTO {
return update(this);
}
public Boolean getVehicleSpawn() {
return vehicleSpawn;
}
public DominionDTO setVehicleSpawn(Boolean vehicleSpawn) {
this.vehicleSpawn = vehicleSpawn;
return update(this);
}
public Boolean getWitherSpawn() {
return witherSpawn;
}

View File

@ -28,7 +28,8 @@ public class PlayerPrivilegeDTO {
"riding, repeater, " +
"shear, shoot, " +
"trade, " +
"vehicle_destroy" +
"vehicle_destroy, " +
"vehicle_spawn" +
") VALUES (" +
"'" + player.getPlayerUUID() + "', " + player.getAdmin() + ", " + player.getDomID() + ", " +
player.getAnchor() + ", " + player.getAnimalKilling() + ", " + player.getAnvil() + ", " +
@ -46,7 +47,8 @@ public class PlayerPrivilegeDTO {
player.getRiding() + ", " + player.getRepeater() + ", " +
player.getShear() + ", " + player.getShoot() + ", " +
player.getTrade() + ", " +
player.getVehicleDestroy() +
player.getVehicleDestroy() + ", " +
player.getVehicleSpawn() + " " +
") RETURNING *;";
List<PlayerPrivilegeDTO> players = query(sql);
if (players.size() == 0) return null;
@ -105,6 +107,7 @@ public class PlayerPrivilegeDTO {
private Boolean enderPearl;
private Boolean feed;
private Boolean glow;
private Boolean harvest;
private Boolean honey;
private Boolean hook;
private Boolean hopper;
@ -120,7 +123,7 @@ public class PlayerPrivilegeDTO {
private Boolean shoot;
private Boolean trade;
private Boolean vehicleDestroy;
private Boolean harvest;
private Boolean vehicleSpawn;
public Integer getId() {
return id;
@ -214,6 +217,10 @@ public class PlayerPrivilegeDTO {
return glow;
}
public Boolean getHarvest() {
return harvest;
}
public Boolean getHoney() {
return honey;
}
@ -274,8 +281,8 @@ public class PlayerPrivilegeDTO {
return vehicleDestroy;
}
public Boolean getHarvest() {
return harvest;
public Boolean getVehicleSpawn() {
return vehicleSpawn;
}
public PlayerPrivilegeDTO setAnchor(Boolean anchor) {
@ -448,6 +455,11 @@ public class PlayerPrivilegeDTO {
return update(this);
}
public PlayerPrivilegeDTO setVehicleSpawn(Boolean vehicleSpawn) {
this.vehicleSpawn = vehicleSpawn;
return update(this);
}
public PlayerPrivilegeDTO setHarvest(Boolean harvest) {
this.harvest = harvest;
return update(this);
@ -474,7 +486,8 @@ public class PlayerPrivilegeDTO {
Boolean riding, Boolean repeater,
Boolean shear, Boolean shoot,
Boolean trade,
Boolean vehicleDestroy) {
Boolean vehicleDestroy,
Boolean vehicleSpawn) {
this.id = id;
this.playerUUID = playerUUID;
this.admin = admin;
@ -514,6 +527,7 @@ public class PlayerPrivilegeDTO {
this.shoot = shoot;
this.trade = trade;
this.vehicleDestroy = vehicleDestroy;
this.vehicleSpawn = vehicleSpawn;
}
public PlayerPrivilegeDTO(UUID playerUUID, Integer domID,
@ -532,7 +546,8 @@ public class PlayerPrivilegeDTO {
Boolean riding, Boolean repeater,
Boolean shear, Boolean shoot,
Boolean trade,
Boolean vehicleDestroy
Boolean vehicleDestroy,
Boolean vehicleSpawn
) {
this(null, playerUUID, false, domID,
anchor, animalKilling, anvil,
@ -550,7 +565,8 @@ public class PlayerPrivilegeDTO {
riding, repeater,
shear, shoot,
trade,
vehicleDestroy);
vehicleDestroy,
vehicleSpawn);
}
private static List<PlayerPrivilegeDTO> query(String sql) {
@ -597,7 +613,8 @@ public class PlayerPrivilegeDTO {
rs.getBoolean("shear"),
rs.getBoolean("shoot"),
rs.getBoolean("trade"),
rs.getBoolean("vehicle_destroy")
rs.getBoolean("vehicle_destroy"),
rs.getBoolean("vehicle_spawn")
);
players.add(player);
}
@ -650,7 +667,8 @@ public class PlayerPrivilegeDTO {
"shear = " + player.getShear() + ", " +
"shoot = " + player.getShoot() + ", " +
"trade = " + player.getTrade() + ", " +
"vehicle_destroy = " + player.getVehicleDestroy() + " " +
"vehicle_destroy = " + player.getVehicleDestroy() + ", " +
"vehicle_spawn = " + player.getVehicleSpawn() + " " +
"WHERE id = " + player.getId() + " " +
"RETURNING *;";
List<PlayerPrivilegeDTO> players = query(sql);

View File

@ -8,10 +8,7 @@ import cn.lunadeer.dominion.utils.Notification;
import io.papermc.paper.event.entity.EntityDyeEvent;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -19,6 +16,8 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
@ -1104,4 +1103,35 @@ public class PlayerEvents implements Listener {
Notification.error(player, "你没有破坏交通工具的权限");
event.setCancelled(true);
}
@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.getPlayerCurrentDominion(player);
if (dom == null) {
return;
}
if (Apis.hasPermission(player, dom)) {
return;
}
PlayerPrivilegeDTO privilege = Cache.instance.getPlayerPrivilege(player, dom);
if (privilege != null) {
if (privilege.getVehicleSpawn()) {
return;
}
} else {
if (dom.getVehicleSpawn()) {
return;
}
}
Notification.error(player, "你没有放置交通工具的权限");
event.setCancelled(true);
}
}

View File

@ -146,7 +146,7 @@ public class DominionFlagInfo {
.append(Button.createRed("", "/dominion set creeper_explode true " + dominion.getName() + " " + page))
.append("苦力怕/凋零头颅爆炸"));
}
if (dominion.getComparer()){
if (dominion.getComparer()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set comparer false " + dominion.getName() + " " + page))
.append("比较器交互"));
@ -281,7 +281,7 @@ public class DominionFlagInfo {
.append(Button.createRed("", "/dominion set ignite true " + dominion.getName() + " " + page))
.append("点燃"));
}
if (dominion.getLever()){
if (dominion.getLever()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set lever false " + dominion.getName() + " " + page))
.append("使用拉杆"));
@ -311,11 +311,11 @@ public class DominionFlagInfo {
if (dominion.getPlace()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set place false " + dominion.getName() + " " + page))
.append("放置"));
.append("放置方块"));
} else {
view.add(Line.create()
.append(Button.createRed("", "/dominion set place true " + dominion.getName() + " " + page))
.append("放置"));
.append("放置方块"));
}
if (dominion.getPressure()) {
view.add(Line.create()
@ -335,7 +335,7 @@ public class DominionFlagInfo {
.append(Button.createRed("", "/dominion set riding true " + dominion.getName() + " " + page))
.append("骑乘载具"));
}
if (dominion.getRepeater()){
if (dominion.getRepeater()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set repeater false " + dominion.getName() + " " + page))
.append("中继器交互"));
@ -389,6 +389,15 @@ public class DominionFlagInfo {
.append(Button.createRed("", "/dominion set vehicle_destroy true " + dominion.getName() + " " + page))
.append("破坏载具"));
}
if (dominion.getVehicleSpawn()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set vehicle_spawn false " + dominion.getName() + " " + page))
.append("放置载具"));
} else {
view.add(Line.create()
.append(Button.createRed("", "/dominion set vehicle_spawn true " + dominion.getName() + " " + page))
.append("放置载具"));
}
if (dominion.getWitherSpawn()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set wither_spawn false " + dominion.getName() + " " + page))

View File

@ -307,11 +307,11 @@ public class PrivilegeInfo {
if (privilege.getPlace()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set_privilege " + playerName + " place false " + dominion.getName() + " " + page))
.append("放置"));
.append("放置方块"));
} else {
view.add(Line.create()
.append(Button.createRed("", "/dominion set_privilege " + playerName + " place true " + dominion.getName() + " " + page))
.append("放置"));
.append("放置方块"));
}
if (privilege.getPressure()) {
view.add(Line.create()
@ -376,6 +376,15 @@ public class PrivilegeInfo {
.append(Button.createRed("", "/dominion set_privilege " + playerName + " vehicle_destroy true " + dominion.getName() + " " + page))
.append("破坏载具"));
}
if (privilege.getVehicleSpawn()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set_privilege " + playerName + " vehicle_spawn false " + dominion.getName() + " " + page))
.append("放置载具"));
} else {
view.add(Line.create()
.append(Button.createRed("", "/dominion set_privilege " + playerName + " vehicle_spawn true " + dominion.getName() + " " + page))
.append("放置载具"));
}
view.showOn(player, page);
}
}

View File

@ -176,5 +176,11 @@ public class Database {
query(sql);
sql = "ALTER TABLE player_privilege ADD COLUMN IF NOT EXISTS hopper BOOLEAN NOT NULL DEFAULT FALSE;";
query(sql);
// 1.9.0
sql = "ALTER TABLE dominion ADD COLUMN IF NOT EXISTS vehicle_spawn BOOLEAN NOT NULL DEFAULT FALSE;";
query(sql);
sql = "ALTER TABLE player_privilege ADD COLUMN IF NOT EXISTS vehicle_spawn BOOLEAN NOT NULL DEFAULT FALSE;";
query(sql);
}
}