整理了部分代码逻辑

这是一个长期版本
已经完全实现了基本功能 修复了大量bug
后续会在此版本基础上实现更多丰富的功能(任务种类)
This commit is contained in:
张宇衡 2023-06-06 14:58:47 +08:00
parent 3f6629eef8
commit 6d7c1f3c20
4 changed files with 190 additions and 353 deletions

View File

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

View File

@ -25,167 +25,210 @@ public class Commands implements TabExecutor {
return true;
}
if (Objects.equals(args[0], "point") || Objects.equals(args[0], "p")) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length == 5) {
try {
Integer index = Integer.parseInt(args[1]);
int x = Integer.parseInt(args[2]);
int y = Integer.parseInt(args[3]);
int z = Integer.parseInt(args[4]);
// 选择的点不允许超过128格范围
if (!Job.in_range(player, new Location(player.getWorld(), x, y, z))) {
return true;
}
Point point = new Point(x, y, z, player);
if (!LiteWorldEdit.instance.getCache().addPoint(player, index, point)) {
sender.sendMessage("点的数量不允许超过20请使用已有点序号覆盖已有点。");
return true;
}
sender.sendMessage("" + index + " 已设置为 " + x + ", " + y + ", " + z + "");
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
return addPoint(sender, args);
} else if (Objects.equals(args[0], "points")) {
if (sender instanceof Player) {
Player player = (Player) sender;
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPoints(player);
if (points != null) {
sender.sendMessage("你创建的点:");
for (Map.Entry<Integer, Point> entry : points.entrySet()) {
Point point = entry.getValue();
sender.sendMessage(entry.getKey() + ": " + point.x + ", " + point.y + ", " + point.z);
}
} else {
sender.sendMessage("你没有设置任何点。");
}
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
listPoints(sender);
return true;
} else if (Objects.equals(args[0], "fill")) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length == 3) {
try {
Integer indexA = Integer.parseInt(args[1]);
Integer indexB = Integer.parseInt(args[2]);
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPoints(player);
if (points == null) {
sender.sendMessage("你没有设置任何点。");
return true;
}
Point pointA = points.get(indexA);
Point pointB = points.get(indexB);
if (pointA == null || pointB == null) {
sender.sendMessage("点不存在。");
return true;
}
if (out_of_region(pointA, pointB)) {
sender.sendMessage("选择的区域不可以超过 " + LiteWorldEdit.instance.getConfigMgr().getXMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getYMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getZMax() + "");
return true;
}
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
sender.sendMessage("你手上没有方块。");
return true;
}
Material material = Material.getMaterial(items_in_hand.getType().name());
Fill.fill(player, player.getWorld(), pointA, pointB, material);
sender.sendMessage("已添加任务。");
return true;
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
return fillTask(sender, args);
} else if (Objects.equals(args[0], "empty")) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length == 3) {
try {
Integer indexA = Integer.parseInt(args[1]);
Integer indexB = Integer.parseInt(args[2]);
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPoints(player);
if (points == null) {
sender.sendMessage("你没有设置任何点。");
return true;
}
Point pointA = points.get(indexA);
Point pointB = points.get(indexB);
if (pointA != null && pointB != null) {
if (out_of_region(pointA, pointB)) {
sender.sendMessage("选择的区域不可以超过 " + LiteWorldEdit.instance.getConfigMgr().getXMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getYMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getZMax() + "");
return true;
}
Empty.empty(player, player.getWorld(), pointA, pointB);
sender.sendMessage("已添加任务。");
} else {
sender.sendMessage("点不存在。");
}
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
return emptyTask(sender, args);
} else if (Objects.equals(args[0], "help")) {
print_help(sender);
return true;
} else if (Objects.equals(args[0], "cancel")) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).cancel();
sender.sendMessage("已取消。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
cancerJobs(sender);
return true;
} else if (Objects.equals(args[0], "reload")) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
sender.sendMessage("你没有权限。");
} else {
LiteWorldEdit.instance.reloadConfig();
sender.sendMessage("已重载配置文件。");
}
} else {
LiteWorldEdit.instance.reloadConfig();
sender.sendMessage("已重载配置文件。");
}
reloadConfigs(sender);
return true;
} else if (Objects.equals(args[0], "pause")) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).pause();
sender.sendMessage("已暂停。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
pauseJobs(sender);
return true;
} else if (Objects.equals(args[0], "resume")) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).resume();
sender.sendMessage("已恢复。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
resumeJobs(sender);
return true;
} else {
sender.sendMessage("参数错误。");
}
return true;
}
private static void resumeJobs(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).resume();
sender.sendMessage("已恢复。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
}
private static void pauseJobs(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).pause();
sender.sendMessage("已暂停。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
}
private static void reloadConfigs(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
sender.sendMessage("你没有权限。");
} else {
LiteWorldEdit.instance.reloadConfig();
sender.sendMessage("已重载配置文件。");
}
} else {
LiteWorldEdit.instance.reloadConfig();
sender.sendMessage("已重载配置文件。");
}
}
private static void cancerJobs(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
LiteWorldEdit.instance.getCache().getQueueOf(player).cancel();
sender.sendMessage("已取消。");
} else {
sender.sendMessage("该命令只能由玩家执行。");
}
}
private static boolean emptyTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("该命令只能由玩家执行。");
return true;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return true;
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
sender.sendMessage("已添加任务。");
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
return false;
}
private static boolean fillTask(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("该命令只能由玩家执行。");
return true;
}
Player player = (Player) sender;
if (args.length == 3) {
try {
Vector2 diagonalPoint = getVector2(sender, args, player);
if (diagonalPoint == null) return true;
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
sender.sendMessage("你手上没有方块。");
return true;
}
Material material = Material.getMaterial(items_in_hand.getType().name());
Fill.fill(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
sender.sendMessage("已添加任务。");
return true;
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
return false;
}
private static Vector2 getVector2(CommandSender sender, String[] args, Player player) {
Integer indexA = Integer.parseInt(args[1]);
Integer indexB = Integer.parseInt(args[2]);
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPoints(player);
if (points == null) {
sender.sendMessage("你没有设置任何点。");
return null;
}
Point pointA = points.get(indexA);
Point pointB = points.get(indexB);
if (pointA == null || pointB == null) {
sender.sendMessage("点不存在。");
return null;
}
if (out_of_region(pointA, pointB)) {
sender.sendMessage("选择的区域不可以超过 " + LiteWorldEdit.instance.getConfigMgr().getXMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getYMax() + "x" + LiteWorldEdit.instance.getConfigMgr().getZMax() + "");
return null;
}
return new Vector2(pointA, pointB);
}
private static class Vector2 {
public final Point pointA;
public final Point pointB;
public Vector2(Point pointA, Point pointB) {
this.pointA = pointA;
this.pointB = pointB;
}
}
private static void listPoints(CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage("该命令只能由玩家执行。");
return;
}
Player player = (Player) sender;
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPoints(player);
if (points != null) {
sender.sendMessage("你创建的点:");
for (Map.Entry<Integer, Point> entry : points.entrySet()) {
Point point = entry.getValue();
sender.sendMessage(entry.getKey() + ": " + point.x + ", " + point.y + ", " + point.z);
}
} else {
sender.sendMessage("你没有设置任何点。");
}
}
private static boolean addPoint(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("该命令只能由玩家执行。");
return true;
}
Player player = (Player) sender;
if (args.length == 5) {
try {
Integer index = Integer.parseInt(args[1]);
int x = Integer.parseInt(args[2]);
int y = Integer.parseInt(args[3]);
int z = Integer.parseInt(args[4]);
// 选择的点不允许超过128格范围
if (!Job.in_range(player, new Location(player.getWorld(), x, y, z))) {
return true;
}
Point point = new Point(x, y, z, player);
if (!LiteWorldEdit.instance.getCache().addPoint(player, index, point)) {
sender.sendMessage("点的数量不允许超过20请使用已有点序号覆盖已有点。");
return true;
}
sender.sendMessage("" + index + " 已设置为 " + x + ", " + y + ", " + z + "");
} catch (NumberFormatException e) {
sender.sendMessage("参数错误。");
}
} else {
sender.sendMessage("参数错误。");
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {

View File

@ -1,6 +1,5 @@
package site.deercloud.liteworldedit.Managers;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.bukkit.configuration.file.FileConfiguration;
import site.deercloud.liteworldedit.LiteWorldEdit;

View File

@ -1,205 +0,0 @@
package site.deercloud.liteworldedit.Managers;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import java.util.List;
public class ProgressBar implements BossBar {
/**
* Returns the title of this boss bar
*
* @return the title of the bar
*/
@Override
public String getTitle() {
return null;
}
/**
* Sets the title of this boss bar
*
* @param title the title of the bar
*/
@Override
public void setTitle(String title) {
}
/**
* Returns the color of this boss bar
*
* @return the color of the bar
*/
@Override
public BarColor getColor() {
return null;
}
/**
* Sets the color of this boss bar.
*
* @param color the color of the bar
*/
@Override
public void setColor(BarColor color) {
}
/**
* Returns the style of this boss bar
*
* @return the style of the bar
*/
@Override
public BarStyle getStyle() {
return null;
}
/**
* Sets the bar style of this boss bar
*
* @param style the style of the bar
*/
@Override
public void setStyle(BarStyle style) {
}
/**
* Remove an existing flag on this boss bar
*
* @param flag the existing flag to remove
*/
@Override
public void removeFlag(BarFlag flag) {
}
/**
* Add an optional flag to this boss bar
*
* @param flag an optional flag to set on the boss bar
*/
@Override
public void addFlag(BarFlag flag) {
}
/**
* Returns whether this boss bar as the passed flag set
*
* @param flag the flag to check
* @return whether it has the flag
*/
@Override
public boolean hasFlag(BarFlag flag) {
return false;
}
/**
* Sets the progress of the bar. Values should be between 0.0 (empty) and
* 1.0 (full)
*
* @param progress the progress of the bar
*/
@Override
public void setProgress(double progress) {
}
/**
* Returns the progress of the bar between 0.0 and 1.0
*
* @return the progress of the bar
*/
@Override
public double getProgress() {
return 0;
}
/**
* Adds the player to this boss bar causing it to display on their screen.
*
* @param player the player to add
*/
@Override
public void addPlayer(Player player) {
}
/**
* Removes the player from this boss bar causing it to be removed from their
* screen.
*
* @param player the player to remove
*/
@Override
public void removePlayer(Player player) {
}
/**
* Removes all players from this boss bar
*
* @see #removePlayer(Player)
*/
@Override
public void removeAll() {
}
/**
* Returns all players viewing this boss bar
*
* @return a immutable list of players
*/
@Override
public List<Player> getPlayers() {
return null;
}
/**
* Set if the boss bar is displayed to attached players.
*
* @param visible visible status
*/
@Override
public void setVisible(boolean visible) {
}
/**
* Return if the boss bar is displayed to attached players.
*
* @return visible status
*/
@Override
public boolean isVisible() {
return false;
}
/**
* Shows the previously hidden boss bar to all attached players
*
* @deprecated {@link #setVisible(boolean)}
*/
@Override
public void show() {
}
/**
* Hides this boss bar from all attached players
*
* @deprecated {@link #setVisible(boolean)}
*/
@Override
public void hide() {
}
}