新增耕地保护权限配置

This commit is contained in:
zhangyuheng 2024-02-23 16:57:01 +08:00
parent 914c05f484
commit 3ac9d5a1c5
7 changed files with 66 additions and 10 deletions

View File

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

View File

@ -30,7 +30,7 @@ public class Helper {
"place", "pressure",
"riding", "repeater",
"shear", "shoot",
"tnt_explode", "trade",
"tnt_explode", "trade", "trample",
"vehicle_destroy",
"vehicle_spawn",
"wither_spawn");

View File

@ -75,6 +75,7 @@ public class FlagsController {
case "shoot": return dominion.setShoot(value);
case "tnt_explode": return dominion.setTntExplode(value);
case "trade": return dominion.setTrade(value);
case "trample": return dominion.setTrample(value);
case "vehicle_destroy": return dominion.setVehicleDestroy(value);
case "vehicle_spawn": return dominion.setVehicleSpawn(value);
case "wither_spawn": return dominion.setWitherSpawn(value);

View File

@ -69,6 +69,7 @@ public class DominionDTO {
rs.getBoolean("shoot"),
rs.getBoolean("tnt_explode"),
rs.getBoolean("trade"),
rs.getBoolean("trample"),
rs.getBoolean("vehicle_destroy"),
rs.getBoolean("vehicle_spawn"),
rs.getBoolean("wither_spawn")
@ -215,6 +216,7 @@ public class DominionDTO {
"shoot = " + dominion.getShoot() + ", " +
"tnt_explode = " + dominion.getTntExplode() + ", " + // dom only
"trade = " + dominion.getTrade() + ", " +
"trample = " + dominion.getTrample() + ", " + // dom only
"vehicle_destroy = " + dominion.getVehicleDestroy() + ", " +
"vehicle_spawn = " + dominion.getVehicleSpawn() + ", " +
"wither_spawn = " + dominion.getWitherSpawn() + " " + // dom only
@ -243,7 +245,7 @@ public class DominionDTO {
Boolean place, Boolean pressure,
Boolean riding, Boolean repeater,
Boolean shear, Boolean shoot,
Boolean tntExplode, Boolean trade,
Boolean tntExplode, Boolean trade, Boolean trample,
Boolean vehicleDestroy,
Boolean vehicleSpawn,
Boolean witherSpawn) {
@ -298,6 +300,7 @@ public class DominionDTO {
this.shoot = shoot;
this.tntExplode = tntExplode;
this.trade = trade;
this.trample = trample;
this.vehicleDestroy = vehicleDestroy;
this.vehicleSpawn = vehicleSpawn;
this.witherSpawn = witherSpawn;
@ -315,7 +318,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, false, false);
}
public DominionDTO(UUID owner, String name, String world,
@ -373,6 +376,7 @@ public class DominionDTO {
private Boolean shoot = false;
private Boolean tntExplode = false;
private Boolean trade = false;
private Boolean trample = false;
private Boolean vehicleDestroy = false;
private Boolean vehicleSpawn = false;
private Boolean witherSpawn = false;
@ -824,6 +828,15 @@ public class DominionDTO {
return update(this);
}
public Boolean getTrample() {
return trample;
}
public DominionDTO setTrample(Boolean trample) {
this.trample = trample;
return update(this);
}
public Boolean getVehicleDestroy() {
return vehicleDestroy;
}

View File

@ -3,24 +3,30 @@ package cn.lunadeer.dominion.events;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Objects;
import static org.bukkit.Material.FARMLAND;
public class EnvironmentEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.CREEPER && entity.getType() != EntityType.WITHER_SKULL){
if (entity.getType() != EntityType.CREEPER && entity.getType() != EntityType.WITHER_SKULL) {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getLocation());
@ -34,7 +40,7 @@ public class EnvironmentEvents implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST) // fire_spread
public void onFireSpread(BlockIgniteEvent event){
public void onFireSpread(BlockIgniteEvent event) {
Player player = event.getPlayer();
if (player != null) {
// 如果点燃事件没有玩家触发那么就是火焰蔓延
@ -59,8 +65,8 @@ public class EnvironmentEvents implements Listener {
return;
}
DominionDTO dom_from = Cache.instance.getDominion(from);
if (dom_from != null){
if (Objects.equals(dom_from.getId(), dom_to.getId())){
if (dom_from != null) {
if (Objects.equals(dom_from.getId(), dom_to.getId())) {
return;
}
}
@ -72,7 +78,7 @@ public class EnvironmentEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // tnt_explode
public void onTntExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT){
if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) {
return;
}
DominionDTO dom = Cache.instance.getDominion(event.getLocation());
@ -85,8 +91,31 @@ public class EnvironmentEvents implements Listener {
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // trample
public void onFarmlandTrample(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if (block == null) {
return;
}
if (block.getType() != FARMLAND) {
return;
}
if (event.getAction() != Action.PHYSICAL) {
return;
}
Location location = block.getLocation();
DominionDTO dom = Cache.instance.getDominion(location);
if (dom == null) {
return;
}
if (dom.getTrample()) {
return;
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // wither_spawn
public void onWitherSpawn(CreatureSpawnEvent event){
public void onWitherSpawn(CreatureSpawnEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.WITHER) {
return;

View File

@ -380,6 +380,15 @@ public class DominionFlagInfo {
.append(Button.createRed("", "/dominion set trade true " + dominion.getName() + " " + page))
.append("交易"));
}
if (dominion.getTrample()){
view.add(Line.create()
.append(Button.createGreen("", "/dominion set trample false " + dominion.getName() + " " + page))
.append("践踏耕地"));
} else {
view.add(Line.create()
.append(Button.createRed("", "/dominion set trample true " + dominion.getName() + " " + page))
.append("践踏耕地"));
}
if (dominion.getVehicleDestroy()) {
view.add(Line.create()
.append(Button.createGreen("", "/dominion set vehicle_destroy false " + dominion.getName() + " " + page))

View File

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