This commit is contained in:
parent
7328e9aff1
commit
4bd817bd84
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>Dominion</artifactId>
|
||||
<version>1.31.5-beta</version>
|
||||
<version>1.31.6-beta</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Dominion</name>
|
||||
|
@ -43,12 +43,12 @@ public class BlueMapConnect {
|
||||
double z = vectors.iterator().next().getY();
|
||||
double y = dominion.getY1();
|
||||
|
||||
Color line = new Color(0, 191, 255, 0.8F);
|
||||
Color fill = new Color(0, 191, 255, 0.2F);
|
||||
if (dominion.getParentDomId() != -1) { // for children dominion
|
||||
line = new Color(240, 230, 140, 0.8F);
|
||||
fill = new Color(240, 230, 140, 0.2F);
|
||||
}
|
||||
int r = dominion.getColorR();
|
||||
int g = dominion.getColorG();
|
||||
int b = dominion.getColorB();
|
||||
|
||||
Color line = new Color(r, g, b, 0.8F);
|
||||
Color fill = new Color(r, g, b, 0.2F);
|
||||
ExtrudeMarker marker = ExtrudeMarker.builder()
|
||||
.label(dominion.getName())
|
||||
.position(x, y, z)
|
||||
|
@ -174,6 +174,9 @@ public class Commands implements TabExecutor {
|
||||
case "select_template":
|
||||
SelectTemplate.show(sender, args);
|
||||
break;
|
||||
case "set_map_color":
|
||||
DominionOperate.setMapColor(sender, args);
|
||||
break;
|
||||
// ---=== CUI ===---
|
||||
case "cui_rename":
|
||||
RenameDominion.open(sender, args);
|
||||
@ -193,6 +196,9 @@ public class Commands implements TabExecutor {
|
||||
case "cui_template_create":
|
||||
CreateTemplate.open(sender, args);
|
||||
break;
|
||||
case "cui_set_map_color":
|
||||
SetMapColor.open(sender, args);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -233,7 +239,9 @@ public class Commands implements TabExecutor {
|
||||
"template_manage",
|
||||
"template_delete",
|
||||
"template_create",
|
||||
"template_set_flag"
|
||||
"template_set_flag",
|
||||
"all_dominion",
|
||||
"set_map_color"
|
||||
);
|
||||
}
|
||||
if (args.length == 2) {
|
||||
@ -281,6 +289,8 @@ public class Commands implements TabExecutor {
|
||||
return allTemplates(sender);
|
||||
case "template_create":
|
||||
return Collections.singletonList("输入模板名称");
|
||||
case "set_map_color":
|
||||
return Collections.singletonList("输入颜色(16进制)");
|
||||
}
|
||||
}
|
||||
if (args.length == 3) {
|
||||
@ -300,6 +310,7 @@ public class Commands implements TabExecutor {
|
||||
case "set_enter_msg":
|
||||
case "set_leave_msg":
|
||||
case "apply_template":
|
||||
case "set_map_color":
|
||||
return playerDominions(sender);
|
||||
case "rename":
|
||||
return Collections.singletonList("输入新领地名称");
|
||||
|
@ -428,4 +428,25 @@ public class DominionOperate {
|
||||
}
|
||||
}, 20L * Dominion.config.getTpDelay());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置领地卫星地图地块颜色
|
||||
*
|
||||
* @param sender 命令发送者
|
||||
* @param args 命令参数
|
||||
*/
|
||||
public static void setMapColor(CommandSender sender, String[] args) {
|
||||
Player player = playerOnly(sender);
|
||||
if (player == null) return;
|
||||
if (args.length < 2) {
|
||||
Notification.error(sender, "用法: /dominion set_map_color <颜色> [领地名称]");
|
||||
return;
|
||||
}
|
||||
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
|
||||
if (args.length == 2) {
|
||||
DominionController.setMapColor(operator, args[1]);
|
||||
} else {
|
||||
DominionController.setMapColor(operator, args[1], args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -655,6 +655,48 @@ public class DominionController {
|
||||
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功将领地 %s 及其所有子领地转让给 %s", dom_name, player_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置领地的卫星地图地块颜色
|
||||
*
|
||||
* @param operator 操作者
|
||||
* @param color 16进制颜色 例如 #ff0000
|
||||
* @param dom_name 领地名称
|
||||
*/
|
||||
public static void setMapColor(AbstractOperator operator, String color, String dom_name) {
|
||||
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置领地地图颜色失败");
|
||||
DominionDTO dominion = getExistDomAndIsOwner(operator, dom_name);
|
||||
if (dominion == null) {
|
||||
return;
|
||||
}
|
||||
if (notOwner(operator, dominion)) {
|
||||
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者", dom_name));
|
||||
return;
|
||||
}
|
||||
color = color.toUpperCase(); // 转换为大写
|
||||
if (!color.matches("^#[0-9a-fA-F]{6}$")) {
|
||||
operator.setResponse(FAIL.addMessage("颜色格式不正确"));
|
||||
return;
|
||||
}
|
||||
dominion.setColor(color);
|
||||
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的卫星地图颜色为 %s", dom_name, color));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置领地的卫星地图地块颜色
|
||||
*
|
||||
* @param operator 操作者
|
||||
* @param color 16进制颜色 例如 #ff0000
|
||||
*/
|
||||
public static void setMapColor(AbstractOperator operator, String color) {
|
||||
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置领地地图颜色失败");
|
||||
DominionDTO dominion = getPlayerCurrentDominion(operator);
|
||||
if (dominion == null) {
|
||||
operator.setResponse(FAIL.addMessage("无法获取你所处的领地,请指定名称"));
|
||||
return;
|
||||
}
|
||||
setMapColor(operator, color, dominion.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断两个领地是否相交
|
||||
*/
|
||||
|
49
src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java
Normal file
49
src/main/java/cn/lunadeer/dominion/cuis/SetMapColor.java
Normal file
@ -0,0 +1,49 @@
|
||||
package cn.lunadeer.dominion.cuis;
|
||||
|
||||
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
|
||||
import cn.lunadeer.dominion.controllers.DominionController;
|
||||
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||
import cn.lunadeer.dominion.tuis.DominionManage;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
|
||||
|
||||
public class SetMapColor {
|
||||
|
||||
private static class setMapColorCB implements CuiTextInput.InputCallback {
|
||||
private final Player sender;
|
||||
private final String dominionName;
|
||||
|
||||
public setMapColorCB(Player sender, String dominionName) {
|
||||
this.sender = sender;
|
||||
this.dominionName = dominionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleData(String input) {
|
||||
XLogger.debug("editLeaveMessageCB.run: %s", input);
|
||||
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
|
||||
DominionController.setMapColor(operator, input, dominionName);
|
||||
DominionManage.show(sender, new String[]{"manage", dominionName});
|
||||
}
|
||||
}
|
||||
|
||||
public static void open(CommandSender sender, String[] args) {
|
||||
Player player = playerOnly(sender);
|
||||
if (player == null) return;
|
||||
DominionDTO dominion = DominionDTO.select(args[1]);
|
||||
if (dominion == null) {
|
||||
Notification.error(sender, "领地不存在");
|
||||
return;
|
||||
}
|
||||
CuiTextInput.InputCallback setMapColorCB = new SetMapColor.setMapColorCB(player, dominion.getName());
|
||||
CuiTextInput view = CuiTextInput.create(setMapColorCB).setText(dominion.getColor()).title("输入卫星地图地块颜色(16进制)");
|
||||
view.setSuggestCommand("/dominion set_map_color <颜色> [领地名称]");
|
||||
view.open(player);
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,11 @@ import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.awt.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class DominionDTO {
|
||||
private static List<DominionDTO> query(String sql, Object... args) {
|
||||
@ -36,12 +38,14 @@ public class DominionDTO {
|
||||
for (Flag f : Flag.getDominionFlagsEnabled()) {
|
||||
flags.put(f, rs.getBoolean(f.getFlagName()));
|
||||
}
|
||||
String color = rs.getString("color");
|
||||
|
||||
DominionDTO dominion = new DominionDTO(id, owner, name, world, x1, y1, z1, x2, y2, z2, parentDomId,
|
||||
rs.getString("join_message"),
|
||||
rs.getString("leave_message"),
|
||||
flags,
|
||||
tp_location
|
||||
tp_location,
|
||||
color
|
||||
);
|
||||
dominions.add(dominion);
|
||||
}
|
||||
@ -148,7 +152,7 @@ public class DominionDTO {
|
||||
Location loc = dominion.getTpLocation();
|
||||
tp_location = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
}
|
||||
String sql = "UPDATE dominion SET " +
|
||||
StringBuilder sql = new StringBuilder("UPDATE dominion SET " +
|
||||
"owner = ?," +
|
||||
"name = ?," +
|
||||
"world = ?," +
|
||||
@ -160,19 +164,19 @@ public class DominionDTO {
|
||||
"z2 = " + dominion.getZ2() + ", " +
|
||||
"parent_dom_id = " + dominion.getParentDomId() + ", " +
|
||||
"join_message = ?," +
|
||||
"leave_message = ?,";
|
||||
"leave_message = ?," +
|
||||
"color = ?,");
|
||||
for (Flag f : Flag.getDominionFlagsEnabled()) {
|
||||
sql += f.getFlagName() + " = " + dominion.getFlagValue(f) + ",";
|
||||
sql.append(f.getFlagName()).append(" = ").append(dominion.getFlagValue(f)).append(",");
|
||||
}
|
||||
sql += "tp_location = ?" +
|
||||
" WHERE id = " + dominion.getId() +
|
||||
" RETURNING *;";
|
||||
List<DominionDTO> dominions = query(sql,
|
||||
sql.append("tp_location = ?" + " WHERE id = ").append(dominion.getId()).append(" RETURNING *;");
|
||||
List<DominionDTO> dominions = query(sql.toString(),
|
||||
dominion.getOwner().toString(),
|
||||
dominion.getName(),
|
||||
dominion.getWorld(),
|
||||
dominion.getJoinMessage(),
|
||||
dominion.getLeaveMessage(),
|
||||
dominion.getColor(),
|
||||
tp_location);
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
@ -183,7 +187,8 @@ public class DominionDTO {
|
||||
Integer parentDomId,
|
||||
String joinMessage, String leaveMessage,
|
||||
Map<Flag, Boolean> flags,
|
||||
String tp_location) {
|
||||
String tp_location,
|
||||
String color) {
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
@ -199,6 +204,7 @@ public class DominionDTO {
|
||||
this.leaveMessage = leaveMessage;
|
||||
this.flags.putAll(flags);
|
||||
this.tp_location = tp_location;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
@ -238,6 +244,7 @@ public class DominionDTO {
|
||||
private String leaveMessage = "再见";
|
||||
private final Map<Flag, Boolean> flags = new HashMap<>();
|
||||
private String tp_location;
|
||||
private String color;
|
||||
|
||||
// getters and setters
|
||||
public Integer getId() {
|
||||
@ -421,4 +428,25 @@ public class DominionDTO {
|
||||
public Location getLocation2() {
|
||||
return new Location(Dominion.instance.getServer().getWorld(world), x2, y2, z2);
|
||||
}
|
||||
|
||||
public DominionDTO setColor(String color) {
|
||||
this.color = color;
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public int getColorR() {
|
||||
return Integer.valueOf(color.substring(1, 3), 16);
|
||||
}
|
||||
|
||||
public int getColorG() {
|
||||
return Integer.valueOf(color.substring(3, 5), 16);
|
||||
}
|
||||
|
||||
public int getColorB() {
|
||||
return Integer.valueOf(color.substring(5, 7), 16);
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
@ -100,5 +100,8 @@ public class DatabaseTables {
|
||||
flag.getFlagName(),
|
||||
"BOOLEAN NOT NULL DEFAULT " + flag.getDefaultValue());
|
||||
}
|
||||
|
||||
// 1.31.6
|
||||
Dominion.database.addColumnIfNotExists("dominion", "color", "TEXT NOT NULL DEFAULT '#00BFFF'");
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
package cn.lunadeer.dominion.tuis;
|
||||
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.ListView;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
|
||||
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -43,6 +46,11 @@ public class DominionManage {
|
||||
Line leave_msg = Line.create()
|
||||
.append(Button.create("编辑离开提示语").setExecuteCommand("/dominion cui_edit_leave_message " + dominion.getName()).build())
|
||||
.append("当玩家离开领地时显示的消息");
|
||||
Line map_color = Line.create()
|
||||
.append(Button.create("设置颜色").setExecuteCommand("/dominion cui_set_map_color " + dominion.getName()).build())
|
||||
.append(Component.text("设置卫星地图上的地块颜色")
|
||||
.append(Component.text(dominion.getColor(),
|
||||
TextColor.color(dominion.getColorR(), dominion.getColorG(), dominion.getColorB()))));
|
||||
ListView view = ListView.create(10, "/dominion manage " + dominion.getName());
|
||||
view.title("领地 " + dominion.getName() + " 管理界面")
|
||||
.navigator(Line.create()
|
||||
@ -55,7 +63,10 @@ public class DominionManage {
|
||||
.add(set_tp)
|
||||
.add(rename)
|
||||
.add(join_msg)
|
||||
.add(leave_msg)
|
||||
.showOn(player, 1);
|
||||
.add(leave_msg);
|
||||
if (Dominion.config.getBlueMap()) {
|
||||
view.add(map_color);
|
||||
}
|
||||
view.showOn(player, 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user