fix: groupadd参数组名在前+tab补全在线玩家+选区防重复+一键创建超链接
This commit is contained in:
@@ -3991,6 +3991,18 @@ public class AreaProtection implements Listener {
|
|||||||
return areas.keySet();
|
return areas.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取所有用户组名(tab补全用) */
|
||||||
|
public List<String> getUserGroupNames() {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
UserGroupManager ugm = plugin.getUserGroup();
|
||||||
|
if (ugm != null) {
|
||||||
|
for (UserGroupManager.UserGroupConfig cfg : ugm.getAllGroups()) {
|
||||||
|
names.add(cfg.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据名称获取领地配置
|
* 根据名称获取领地配置
|
||||||
*/
|
*/
|
||||||
@@ -4368,26 +4380,47 @@ public class AreaProtection implements Listener {
|
|||||||
+ block.getY() + ", "
|
+ block.getY() + ", "
|
||||||
+ block.getZ());
|
+ block.getZ());
|
||||||
} else {
|
} else {
|
||||||
pos2.put(uid, block.getLocation());
|
Location newLoc = block.getLocation();
|
||||||
p.sendMessage("§a§l[防护] §f位置2: "
|
Location oldLoc = pos2.get(uid);
|
||||||
+ block.getX() + ", "
|
boolean changed = oldLoc == null
|
||||||
+ block.getY() + ", "
|
|| oldLoc.getBlockX() != newLoc.getBlockX()
|
||||||
+ block.getZ());
|
|| oldLoc.getBlockY() != newLoc.getBlockY()
|
||||||
// ★ 两个位置都选好后,显示面积+价格预览
|
|| oldLoc.getBlockZ() != newLoc.getBlockZ();
|
||||||
if (pos1.containsKey(uid)) {
|
pos2.put(uid, newLoc);
|
||||||
Location lp1 = pos1.get(uid);
|
if (changed) {
|
||||||
Location lp2 = block.getLocation();
|
p.sendMessage("§a§l[防护] §f位置2: "
|
||||||
int w = Math.abs(lp2.getBlockX() - lp1.getBlockX()) + 1;
|
+ block.getX() + ", "
|
||||||
int l = Math.abs(lp2.getBlockZ() - lp1.getBlockZ()) + 1;
|
+ block.getY() + ", "
|
||||||
int a = w * l;
|
+ block.getZ());
|
||||||
UserGroupManager ug = plugin.getUserGroup();
|
// ★ 两个位置都选好后,显示面积+价格预览 + 一键创建超链接
|
||||||
int pricePerSqm = (ug != null) ? ug.getPlayerLandPricePerSqm(p.getName(), globalCreatePricePerSqm) : globalCreatePricePerSqm;
|
if (pos1.containsKey(uid)) {
|
||||||
int totalCost = a * pricePerSqm;
|
Location lp1 = pos1.get(uid);
|
||||||
String src = (pricePerSqm != globalCreatePricePerSqm) ? " §7(用户组优惠价)" : "";
|
int w = Math.abs(newLoc.getBlockX() - lp1.getBlockX()) + 1;
|
||||||
BondManager bnd = plugin.getBonds();
|
int l = Math.abs(newLoc.getBlockZ() - lp1.getBlockZ()) + 1;
|
||||||
int bal = (bnd != null) ? bnd.getBonds(p.getName()) : 0;
|
int a = w * l;
|
||||||
p.sendMessage("§e§l[防护] §f选区完成!面积: §a" + a + "㎡§7(" + w + "×" + l + ") 单价: §f" + pricePerSqm + "/㎡" + src + " 预估: §e" + totalCost + "§7债券 余额: §a" + bal);
|
UserGroupManager ug = plugin.getUserGroup();
|
||||||
p.sendMessage("§7输入 §f/protect 创建 <领地名> §7开始创建,费用和面积将再次确认");
|
int pricePerSqm = (ug != null) ? ug.getPlayerLandPricePerSqm(p.getName(), globalCreatePricePerSqm) : globalCreatePricePerSqm;
|
||||||
|
int totalCost = a * pricePerSqm;
|
||||||
|
String src = (pricePerSqm != globalCreatePricePerSqm) ? " §7(用户组优惠价)" : "";
|
||||||
|
BondManager bnd = plugin.getBonds();
|
||||||
|
int bal = (bnd != null) ? bnd.getBonds(p.getName()) : 0;
|
||||||
|
p.sendMessage("§e§l[防护] §f选区完成!面积: §a" + a + "㎡§7(" + w + "×" + l + ") 单价: §f" + pricePerSqm + "/㎡" + src + " 预估: §e" + totalCost + "§7债券 余额: §a" + bal);
|
||||||
|
// ★ 一键创建超链接:自动用玩家名,冲突则加数字
|
||||||
|
String autoName = p.getName();
|
||||||
|
if (areas.containsKey(autoName)) {
|
||||||
|
for (int i = 0; i <= 99; i++) {
|
||||||
|
String candidate = autoName + i;
|
||||||
|
if (!areas.containsKey(candidate)) { autoName = candidate; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalAutoName = autoName;
|
||||||
|
p.sendMessage(Component.empty()
|
||||||
|
.append(Component.text("§a§l[✅ 点击一键创建]"))
|
||||||
|
.hoverEvent(HoverEvent.showText(Component.text("§e以 §f" + finalAutoName + " §e为名创建领地\n§7费用: " + totalCost + " 债券")))
|
||||||
|
.clickEvent(ClickEvent.runCommand("/protect confirm_create " + finalAutoName))
|
||||||
|
);
|
||||||
|
p.sendMessage(Component.text("§7或输入 §f/protect 创建 <自定义名> §7指定领地名"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6067,11 +6100,11 @@ public class AreaProtection implements Listener {
|
|||||||
|
|
||||||
if (sub.equals("groupadd") || sub.equals("addmember")) {
|
if (sub.equals("groupadd") || sub.equals("addmember")) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
sender.sendMessage("§e用法: /protect groupadd <玩家> <组名>");
|
sender.sendMessage("§e用法: /protect groupadd <组名> <玩家名>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String playerName = args[1];
|
String groupName = args[1].toLowerCase();
|
||||||
String groupName = args[2].toLowerCase();
|
String playerName = args[2];
|
||||||
UserGroupManager ugm = plugin.getUserGroup();
|
UserGroupManager ugm = plugin.getUserGroup();
|
||||||
if (ugm == null) { sender.sendMessage("§c用户组系统未初始化"); return true; }
|
if (ugm == null) { sender.sendMessage("§c用户组系统未初始化"); return true; }
|
||||||
if (ugm.getGroupConfig(groupName) == null) {
|
if (ugm.getGroupConfig(groupName) == null) {
|
||||||
@@ -6094,11 +6127,11 @@ public class AreaProtection implements Listener {
|
|||||||
|
|
||||||
if (sub.equals("groupdel")) {
|
if (sub.equals("groupdel")) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
sender.sendMessage("§e用法: /protect groupdel <玩家> <组名>");
|
sender.sendMessage("§e用法: /protect groupdel <组名> <玩家名>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String playerName = args[1];
|
String groupName = args[1].toLowerCase();
|
||||||
String groupName = args[2].toLowerCase();
|
String playerName = args[2];
|
||||||
UserGroupManager ugm = plugin.getUserGroup();
|
UserGroupManager ugm = plugin.getUserGroup();
|
||||||
if (ugm == null) { sender.sendMessage("§c用户组系统未初始化"); return true; }
|
if (ugm == null) { sender.sendMessage("§c用户组系统未初始化"); return true; }
|
||||||
if (ugm.removePlayer(playerName, groupName)) {
|
if (ugm.removePlayer(playerName, groupName)) {
|
||||||
@@ -6141,7 +6174,7 @@ public class AreaProtection implements Listener {
|
|||||||
.append(Component.text(" §f" + pn + " §7(添加者: " + (addedBy != null ? addedBy : "system") + ") "))
|
.append(Component.text(" §f" + pn + " §7(添加者: " + (addedBy != null ? addedBy : "system") + ") "))
|
||||||
.append(Component.text("§c[移除]"))
|
.append(Component.text("§c[移除]"))
|
||||||
.hoverEvent(HoverEvent.showText(Component.text("§c点击移除此成员")))
|
.hoverEvent(HoverEvent.showText(Component.text("§c点击移除此成员")))
|
||||||
.clickEvent(ClickEvent.runCommand("/protect groupdel " + pn + " " + groupName))
|
.clickEvent(ClickEvent.runCommand("/protect groupdel " + groupName + " " + pn))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(" §f" + pn + " §7(添加者: " + (addedBy != null ? addedBy : "system") + ")");
|
sender.sendMessage(" §f" + pn + " §7(添加者: " + (addedBy != null ? addedBy : "system") + ")");
|
||||||
@@ -6157,13 +6190,18 @@ public class AreaProtection implements Listener {
|
|||||||
pp.sendMessage(Component.empty()
|
pp.sendMessage(Component.empty()
|
||||||
.append(Component.text("§a[添加在线玩家] "))
|
.append(Component.text("§a[添加在线玩家] "))
|
||||||
.hoverEvent(HoverEvent.showText(Component.text("§e输入玩家名添加到此组")))
|
.hoverEvent(HoverEvent.showText(Component.text("§e输入玩家名添加到此组")))
|
||||||
.clickEvent(ClickEvent.suggestCommand("/protect groupadd <玩家名> " + groupName))
|
.clickEvent(ClickEvent.suggestCommand("/protect groupadd " + groupName + " "))
|
||||||
);
|
);
|
||||||
// 返回用户组列表
|
// 返回用户组列表
|
||||||
pp.sendMessage(Component.empty()
|
pp.sendMessage(Component.empty()
|
||||||
.append(Component.text("§c[返回用户组列表] "))
|
.append(Component.text("§c[返回用户组列表] "))
|
||||||
.clickEvent(ClickEvent.runCommand("/protect grouplist"))
|
.clickEvent(ClickEvent.runCommand("/protect grouplist"))
|
||||||
);
|
);
|
||||||
|
// 返回主菜单
|
||||||
|
pp.sendMessage(Component.empty()
|
||||||
|
.append(Component.text("§7[返回主菜单] "))
|
||||||
|
.clickEvent(ClickEvent.runCommand("/protect menu"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
sender.sendMessage("§7§l─────────────────────────────────");
|
sender.sendMessage("§7§l─────────────────────────────────");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6033,6 +6033,11 @@ public class Main extends JavaPlugin
|
|||||||
|
|
||||||
// ===== 第二层 =====
|
// ===== 第二层 =====
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
|
// groupadd/groupdel: 第二层是用户组名
|
||||||
|
if (sub.equals("groupadd") || sub.equals("groupdel")
|
||||||
|
|| sub.equals("addmember") || sub.equals("removemember")) {
|
||||||
|
return filterTab(areaProtection.getUserGroupNames(), args[1]);
|
||||||
|
}
|
||||||
// add/remove: 区域名 + global + 在线玩家
|
// add/remove: 区域名 + global + 在线玩家
|
||||||
if (sub.equals("add") || sub.equals("remove")) {
|
if (sub.equals("add") || sub.equals("remove")) {
|
||||||
List<String> all = new ArrayList<>();
|
List<String> all = new ArrayList<>();
|
||||||
@@ -6117,6 +6122,14 @@ public class Main extends JavaPlugin
|
|||||||
|
|
||||||
// ===== 第三层 =====
|
// ===== 第三层 =====
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
|
// groupadd/groupdel: 第三层是在线玩家名
|
||||||
|
if (sub.equals("groupadd") || sub.equals("groupdel")
|
||||||
|
|| sub.equals("addmember") || sub.equals("removemember")) {
|
||||||
|
List<String> players = new ArrayList<>();
|
||||||
|
for (Player pl : Bukkit.getOnlinePlayers())
|
||||||
|
players.add(pl.getName());
|
||||||
|
return filterTab(players, args[2]);
|
||||||
|
}
|
||||||
// add/remove: 第三层是玩家名
|
// add/remove: 第三层是玩家名
|
||||||
if (sub.equals("add") || sub.equals("remove")) {
|
if (sub.equals("add") || sub.equals("remove")) {
|
||||||
List<String> players = new ArrayList<>();
|
List<String> players = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user