新增排水功能
All checks were successful
Java CI-CD with Maven / build (push) Successful in 3m56s

This commit is contained in:
zhangyuheng 2024-03-05 22:18:40 +08:00
parent d978fcab50
commit 24aff565fb
7 changed files with 129 additions and 24 deletions

View File

@ -62,6 +62,8 @@
`/lwe overlay [点序号A] [点序号B]` 在选区地面上铺一层方块 - 需要手持被放置的方块
`/lwe drain [点序号A] [点序号B]` 排干AB点对角线间的流体 - 需要背包里有一个海绵
`/lwe cancel` 取消(终止)所有任务
`/lwe pause` 暂停所有任务

View File

@ -6,7 +6,7 @@
<groupId>site.deercloud</groupId>
<artifactId>LiteWorldEdit</artifactId>
<version>2.3.5.6</version>
<version>2.3.6.1</version>
<packaging>jar</packaging>
<name>LiteWorldEdit</name>

View File

@ -8,6 +8,7 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import site.deercloud.liteworldedit.JobGenerator.Drain;
import site.deercloud.liteworldedit.JobGenerator.Empty;
import site.deercloud.liteworldedit.JobGenerator.Fill;
import site.deercloud.liteworldedit.JobGenerator.OverLay;
@ -31,11 +32,17 @@ public class Commands implements TabExecutor {
listPoints(sender);
return true;
} else if (Objects.equals(args[0], "fill")) {
return fillTask(sender, args);
fillTask(sender, args);
return true;
} else if (Objects.equals(args[0], "empty")) {
return emptyTask(sender, args);
emptyTask(sender, args);
return true;
} else if (Objects.equals(args[0], "overlay")) {
return overlayTask(sender, args);
overlayTask(sender, args);
return true;
} else if (Objects.equals(args[0], "drain")) {
drainTask(sender, args);
return true;
} else if (Objects.equals(args[0], "help")) {
print_help(sender);
return true;
@ -114,16 +121,16 @@ public class Commands implements TabExecutor {
}
}
private static boolean emptyTask(CommandSender sender, String[] args) {
private static void emptyTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
LoggerX.err("该命令只能由玩家执行。");
return true;
return;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return true;
if (diagonalPoint == null) return;
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
Notification.info(player, "已添加任务。");
@ -133,63 +140,81 @@ public class Commands implements TabExecutor {
} else {
Notification.error(player, "参数错误。");
}
return true;
}
private static boolean overlayTask(CommandSender sender, String[] args) {
private static void drainTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
LoggerX.err("该命令只能由玩家执行。");
return true;
return;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return true;
if (diagonalPoint == null) return;
Drain.drain(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
Notification.info(player, "已添加任务。");
} catch (NumberFormatException e) {
Notification.error(player, "参数错误。");
}
} else {
Notification.error(player, "参数错误。");
}
}
private static void overlayTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
LoggerX.err("该命令只能由玩家执行。");
return;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return;
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
Notification.error(player, "你手上没有方块。");
return true;
return;
}
Material material = Material.getMaterial(items_in_hand.getType().name());
OverLay.overLay(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
Notification.info(player, "已添加任务。");
return true;
return;
} catch (NumberFormatException e) {
Notification.error(player, "参数错误。");
}
} else {
Notification.error(player, "参数错误。");
}
return true;
}
private static boolean fillTask(CommandSender sender, String[] args) {
private static void fillTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
LoggerX.err("该命令只能由玩家执行。");
return true;
return;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return true;
if (diagonalPoint == null) return;
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
Notification.error(player, "你手上没有方块。");
return true;
return;
}
Material material = Material.getMaterial(items_in_hand.getType().name());
Fill.fill(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
Notification.info(player, "已添加任务。");
return true;
return;
} catch (NumberFormatException e) {
Notification.error(player, "参数错误。");
}
} else {
Notification.error(player, "参数错误。");
}
return true;
}
private static Vector2 getVector2(CommandSender sender, String[] args, Player player) {
@ -275,11 +300,11 @@ public class Commands implements TabExecutor {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
return Arrays.asList("point", "p", "points", "fill", "empty", "overlay", "cancel", "pause", "resume", "help", "reload");
return Arrays.asList("point", "p", "points", "fill", "empty", "overlay", "drain", "cancel", "pause", "resume", "help", "reload");
} else if (args.length == 2) {
if (args[0].equals("point") || args[0].equals("p")) {
return Collections.singletonList("[点序号(整数)] [x] [y] [z] - 创建点");
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay")) {
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay") || args[0].equals("drain")) {
return Collections.singletonList("[点序号A] [点序号B]");
}
}
@ -298,6 +323,7 @@ public class Commands implements TabExecutor {
Notification.info((Player) sender, "/lwe fill [点序号A] [点序号B] - (在AB点对角线间放置方块 - 需要手持被放置的方块)");
Notification.info((Player) sender, "/lwe empty [点序号A] [点序号B] - (破坏AB点对角线间方块 - 需要拥有下届合金镐)");
Notification.info((Player) sender, "/lwe overlay [点序号A] [点序号B] - (在AB点对角线间放置方块 - 不需要手持被放置的方块)");
Notification.info((Player) sender, "/lwe drain [点序号A] [点序号B] - (排干AB点对角线间的流体 - 需要背包里有一个海绵)");
Notification.info((Player) sender, "/lwe cancel - 取消当前任务");
Notification.info((Player) sender, "/lwe pause - 暂停当前任务");
Notification.info((Player) sender, "/lwe resume - 恢复当前任务");

View File

@ -0,0 +1,23 @@
package site.deercloud.liteworldedit.JobGenerator;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import site.deercloud.liteworldedit.Jobs.Absorb;
import site.deercloud.liteworldedit.Jobs.Remove;
import site.deercloud.liteworldedit.LiteWorldEdit;
import site.deercloud.liteworldedit.Managers.Point;
public class Drain {
public static void drain(Player player, World world, Point p1, Point p2) {
for (int y = Math.max(p1.y, p2.y); y >= Math.min(p1.y, p2.y); y--) {
for (int x = Math.min(p1.x, p2.x); x <= Math.max(p1.x, p2.x); x++) {
for (int z = Math.min(p1.z, p2.z); z <= Math.max(p1.z, p2.z); z++) {
Location location = new Location(world, (double) x, (double) y, (double) z);
Absorb absorb_job = new Absorb(location, player);
LiteWorldEdit.instance.getCache().getPlayer(player).addJob(absorb_job);
}
}
}
}
}

View File

@ -0,0 +1,52 @@
package site.deercloud.liteworldedit.Jobs;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SpongeAbsorbEvent;
import org.bukkit.inventory.ItemStack;
import site.deercloud.liteworldedit.LoggerX;
import java.util.HashMap;
public class Absorb extends Job {
public Absorb(Location location, Player player) {
super(player.getWorld(), location, player);
}
@Override
public JobErrCode Do() {
Player _creator = this.get_creator();
Location _location = this.get_location();
World _world = this.get_world();
// 超出距离
if (!in_range(_creator, _location)) {
LoggerX.debug("超出距离!");
return JobErrCode.OUT_OF_RANGE;
}
Block raw_block = _world.getBlockAt(_location);
// 跳过非流体
if (!raw_block.isLiquid()) {
LoggerX.debug("目标方块不是流体!");
return JobErrCode.NOT_LIQUID;
}
HashMap<Integer, ?> sponge = _creator.getInventory().all(Material.SPONGE);
if (sponge.size() == 0) {
return JobErrCode.NO_SPONGE;
}
// 模拟海绵吸水事件
BlockPlaceEvent event = new BlockPlaceEvent(raw_block, raw_block.getState(), raw_block, new ItemStack(Material.SPONGE), _creator, true, null);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
raw_block.setType(Material.SPONGE);
raw_block.setType(Material.AIR);
return JobErrCode.OK;
} else {
return JobErrCode.NO_PERMISSION;
}
}
}

View File

@ -8,11 +8,13 @@ public enum JobErrCode {
NOT_ENOUGH_DURATION(102, "所有下界合金镐耐久均不足10"),
NOT_ENOUGH_ITEMS(103, "物品不足"),
OUT_OF_RANGE(104, "超出操作距离"),
NO_SPONGE(105, "没有海绵,无法排水"),
// ------------ 以下结果应当跳过任务 ------------
NO_PERMISSION(201, "跳过没有权限操作的方块"),
NOT_AIR_BLOCK(202, "跳过非空气方块"),
NO_BREAKABLE(203, "跳过不可破坏方块"),
NOT_LIQUID(204, "跳过非液体方块"),
;
private final int value;

View File

@ -35,8 +35,8 @@ public class Place extends Job {
}
// 跳过非空气方块
Block raw_block = _world.getBlockAt(_location);
if (!raw_block.isEmpty() && !raw_block.isLiquid()) {
LoggerX.debug("目标方块不是空气或流体");
if (!raw_block.isEmpty()) {
LoggerX.debug("目标方块不是空气");
return JobErrCode.NOT_AIR_BLOCK;
}
// 获取到玩家物品中材料的第一个堆叠