mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2024-12-24 04:48:55 +08:00
完成了部分tui的功能验证
This commit is contained in:
parent
8d62c34a66
commit
5810244de9
@ -69,6 +69,9 @@ public class Commands implements TabExecutor {
|
||||
case "menu":
|
||||
TUIs.menu(sender, args);
|
||||
break;
|
||||
case "list":
|
||||
TUIs.list(sender, args);
|
||||
break;
|
||||
case "help":
|
||||
TUIs.printHelp(sender, args);
|
||||
break;
|
||||
@ -163,7 +166,7 @@ public class Commands implements TabExecutor {
|
||||
return Arrays.asList("menu", "help", "info", "manage", "flag_info", "group_list", "privilege_list", "group",
|
||||
"create", "auto_create", "create_sub", "auto_create_sub", "expand", "contract", "delete", "set",
|
||||
"set_privilege", "clear_privilege", "create_group", "delete_group", "set_group", "add_player",
|
||||
"remove_player"
|
||||
"remove_player", "list"
|
||||
);
|
||||
}
|
||||
if (args.length == 2) {
|
||||
@ -177,8 +180,6 @@ public class Commands implements TabExecutor {
|
||||
case "delete":
|
||||
case "create_sub":
|
||||
case "auto_create_sub":
|
||||
case "expand":
|
||||
case "contract":
|
||||
case "info":
|
||||
case "manage":
|
||||
case "flag_info":
|
||||
@ -196,6 +197,9 @@ public class Commands implements TabExecutor {
|
||||
case "delete_group":
|
||||
case "set_group":
|
||||
return playerGroups(sender);
|
||||
case "expand":
|
||||
case "contract":
|
||||
return Collections.singletonList("大小(整数)");
|
||||
}
|
||||
}
|
||||
if (args.length == 3) {
|
||||
@ -209,6 +213,9 @@ public class Commands implements TabExecutor {
|
||||
case "add_player":
|
||||
case "remove_player":
|
||||
return playerGroups(sender);
|
||||
case "expand":
|
||||
case "contract":
|
||||
return playerDominions(sender);
|
||||
}
|
||||
}
|
||||
if (args.length == 4) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.lunadeer.dominion;
|
||||
|
||||
import cn.lunadeer.dominion.events.PlayerEvents;
|
||||
import cn.lunadeer.dominion.utils.ConfigManager;
|
||||
import cn.lunadeer.dominion.utils.Database;
|
||||
import cn.lunadeer.dominion.utils.XLogger;
|
||||
@ -8,6 +9,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.postgresql.core.Tuple;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.sql.Connection;
|
||||
import java.util.*;
|
||||
|
||||
@ -19,7 +21,9 @@ public final class Dominion extends JavaPlugin {
|
||||
instance = this;
|
||||
config = new ConfigManager(this);
|
||||
dbConnection = Database.createConnection();
|
||||
Database.migrate();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands());
|
||||
|
||||
XLogger.info("领地插件已启动");
|
||||
|
@ -25,9 +25,9 @@ import static cn.lunadeer.dominion.controllers.Apis.getPlayerCurrentDominion;
|
||||
public class TUIs {
|
||||
private static int getPage(String[] args) {
|
||||
int page = 1;
|
||||
if (args.length == 3) {
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
page = Integer.parseInt(args[2]);
|
||||
page = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
return 1;
|
||||
}
|
||||
@ -36,8 +36,8 @@ public class TUIs {
|
||||
}
|
||||
|
||||
private static DominionDTO getDominion(Player player, String[] args) {
|
||||
if (args.length == 3) {
|
||||
return DominionDTO.select(args[2]);
|
||||
if (args.length == 2) {
|
||||
return DominionDTO.select(args[1]);
|
||||
} else {
|
||||
return getPlayerCurrentDominion(player);
|
||||
}
|
||||
@ -136,24 +136,24 @@ public class TUIs {
|
||||
view.showOn(player, page);
|
||||
}
|
||||
|
||||
public static void groupDetail(CommandSender sender, String[] args){
|
||||
public static void groupDetail(CommandSender sender, String[] args) {
|
||||
Player player = playerOnly(sender);
|
||||
if (player == null) return;
|
||||
if (args.length < 2){
|
||||
if (args.length < 2) {
|
||||
Notification.error(sender, "用法: /dominion group_detail <权限组名称> [页码]");
|
||||
return;
|
||||
}
|
||||
int page = 1;
|
||||
if (args.length == 3){
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
page = Integer.parseInt(args[2]);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "页码格式错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
PrivilegeTemplateDTO template = PrivilegeTemplateDTO.select(player.getUniqueId(), args[1]);
|
||||
if (template == null){
|
||||
if (template == null) {
|
||||
Notification.error(sender, "权限组 " + args[1] + " 不存在");
|
||||
return;
|
||||
}
|
||||
@ -174,7 +174,7 @@ public class TUIs {
|
||||
.append("查看指令帮助");
|
||||
View view = View.create();
|
||||
view.title("Dominion 领地系统")
|
||||
.subtitle("主菜单")
|
||||
.navigator(Line.create().append("主菜单"))
|
||||
.addLine(list)
|
||||
.addLine(group)
|
||||
.addLine(help)
|
||||
@ -191,6 +191,8 @@ public class TUIs {
|
||||
Notification.warn(sender, "你没有任何领地");
|
||||
return;
|
||||
}
|
||||
view.title("我的领地列表");
|
||||
view.navigator(Line.create().append(Button.create("主菜单", "/dominion menu")).append("我的领地"));
|
||||
for (String dominion : dominions) {
|
||||
TextComponent manage = Button.createGreen("管理", "/dominion manage " + dominion);
|
||||
TextComponent delete = Button.createRed("删除", "/dominion delete " + dominion);
|
||||
@ -220,7 +222,11 @@ public class TUIs {
|
||||
}
|
||||
ListView view = ListView.create(6, "/dominion flag_info " + dominion.getName());
|
||||
view.title("领地 " + dominion.getName() + " 默认权限")
|
||||
.subtitle(Button.create("前往管理界面", "/dominion manage " + dominion.getName()));
|
||||
.navigator(Line.create()
|
||||
.append(Button.create("主菜单", "/dominion menu"))
|
||||
.append(Button.create("我的领地", "/dominion list"))
|
||||
.append(Button.create("管理界面", "/dominion manage " + dominion.getName()))
|
||||
.append("权限列表"));
|
||||
if (dominion.getAnchor()) {
|
||||
view.add(Line.create().append("重生锚").append(Button.createRed("禁用", "/dominion set anchor false " + dominion.getName())));
|
||||
} else {
|
||||
@ -432,7 +438,10 @@ public class TUIs {
|
||||
.append("管理玩家特权");
|
||||
View view = View.create();
|
||||
view.title("领地 " + dominion.getName() + " 管理界面")
|
||||
.subtitle(Button.createRed("领地列表", "/dominion list"))
|
||||
.navigator(Line.create()
|
||||
.append(Button.create("主菜单", "/dominion menu"))
|
||||
.append(Button.create("我的领地", "/dominion list"))
|
||||
.append(dominion.getName()))
|
||||
.addLine(size_info)
|
||||
.addLine(flag_info)
|
||||
.addLine(group_info)
|
||||
|
@ -31,6 +31,7 @@ public class DominionFlag {
|
||||
} else {
|
||||
Notification.error(sender, "用法: /dominion set <权限名称> <true/false> [领地名称]");
|
||||
}
|
||||
Notification.info(sender, "设置领地权限 " + args[1] + " 为 " + args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,13 +130,11 @@ public class DominionOperate {
|
||||
}
|
||||
int size = 10;
|
||||
String name = "";
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
size = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "大小格式错误");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
size = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "大小格式错误");
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
name = args[2];
|
||||
@ -171,13 +169,11 @@ public class DominionOperate {
|
||||
}
|
||||
int size = 10;
|
||||
String name = "";
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
size = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "大小格式错误");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
size = Integer.parseInt(args[1]);
|
||||
} catch (Exception e) {
|
||||
Notification.error(sender, "大小格式错误");
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
name = args[2];
|
||||
|
@ -5,6 +5,7 @@ import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
|
||||
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
|
||||
import cn.lunadeer.dominion.utils.Notification;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,17 +40,23 @@ public class Apis {
|
||||
* @param player 玩家
|
||||
* @return 当前所在的领地
|
||||
*/
|
||||
public static DominionDTO getPlayerCurrentDominion(Player player) {
|
||||
public static DominionDTO getPlayerCurrentDominion(Player player, boolean show_warning) {
|
||||
Location location = player.getLocation();
|
||||
List<DominionDTO> dominions = DominionDTO.selectByLocation(location.getWorld().getName(),
|
||||
(int) location.getX(), (int) location.getY(), (int) location.getZ());
|
||||
if (dominions.size() != 1) {
|
||||
Notification.error(player, "你不在一个领地内或在子领地内,无法确定你要操作的领地,请手动指定要操作的领地名称");
|
||||
if (show_warning) {
|
||||
Notification.error(player, "你不在一个领地内或在子领地内,无法确定你要操作的领地,请手动指定要操作的领地名称");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return dominions.get(0);
|
||||
}
|
||||
|
||||
public static DominionDTO getPlayerCurrentDominion(Player player) {
|
||||
return getPlayerCurrentDominion(player, true);
|
||||
}
|
||||
|
||||
|
||||
public static boolean updateTemplateFlag(PrivilegeTemplateDTO privilege, String flag, boolean value) {
|
||||
switch (flag) {
|
||||
@ -151,4 +158,24 @@ public class Apis {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static BlockFace getFace(Player player) {
|
||||
float yaw = player.getYaw();
|
||||
float pitch = player.getPitch();
|
||||
if (pitch > -45 && pitch < 45) {
|
||||
if (yaw > -45 && yaw < 45) {
|
||||
return BlockFace.SOUTH;
|
||||
} else if (yaw > 135 || yaw < -135) {
|
||||
return BlockFace.NORTH;
|
||||
} else if (yaw > 45 && yaw < 135) {
|
||||
return BlockFace.WEST;
|
||||
} else {
|
||||
return BlockFace.EAST;
|
||||
}
|
||||
} else if (pitch > 45) {
|
||||
return BlockFace.UP;
|
||||
} else {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.lunadeer.dominion.controllers;
|
||||
import cn.lunadeer.dominion.Dominion;
|
||||
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||
import cn.lunadeer.dominion.utils.Notification;
|
||||
import cn.lunadeer.dominion.utils.STUI.Pagination;
|
||||
import cn.lunadeer.dominion.utils.Time;
|
||||
import cn.lunadeer.dominion.utils.XLogger;
|
||||
import org.bukkit.Location;
|
||||
@ -11,8 +12,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.lunadeer.dominion.controllers.Apis.getPlayerCurrentDominion;
|
||||
import static cn.lunadeer.dominion.controllers.Apis.notOwner;
|
||||
import static cn.lunadeer.dominion.controllers.Apis.*;
|
||||
|
||||
public class DominionController {
|
||||
|
||||
@ -30,7 +30,7 @@ public class DominionController {
|
||||
* @return 创建的领地
|
||||
*/
|
||||
public static DominionDTO create(Player owner, String name, Location loc1, Location loc2) {
|
||||
DominionDTO parent = getPlayerCurrentDominion(owner);
|
||||
DominionDTO parent = getPlayerCurrentDominion(owner,false);
|
||||
if (parent == null) {
|
||||
return create(owner, name, loc1, loc2, "");
|
||||
} else {
|
||||
@ -149,7 +149,7 @@ public class DominionController {
|
||||
*/
|
||||
public static DominionDTO expand(Player operator, Integer size, String dominion_name) {
|
||||
Location location = operator.getLocation();
|
||||
BlockFace face = operator.getFacing();
|
||||
BlockFace face = getFace(operator);
|
||||
DominionDTO dominion = DominionDTO.select(dominion_name);
|
||||
if (dominion == null) {
|
||||
Notification.error(operator, "领地 " + dominion_name + " 不存在");
|
||||
@ -241,7 +241,7 @@ public class DominionController {
|
||||
*/
|
||||
public static DominionDTO contract(Player operator, Integer size, String dominion_name) {
|
||||
Location location = operator.getLocation();
|
||||
BlockFace face = operator.getFacing();
|
||||
BlockFace face = getFace(operator);
|
||||
DominionDTO dominion = DominionDTO.select(dominion_name);
|
||||
if (dominion == null) {
|
||||
Notification.error(operator, "领地 " + dominion_name + " 不存在");
|
||||
|
@ -77,17 +77,17 @@ public class DominionDTO {
|
||||
}
|
||||
|
||||
public static List<DominionDTO> selectAll() {
|
||||
String sql = "SELECT * FROM dominion WHERE id > 0";
|
||||
String sql = "SELECT * FROM dominion WHERE id > 0;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static List<DominionDTO> selectAll(String world) {
|
||||
String sql = "SELECT * FROM dominion WHERE world = '" + world + "' AND id > 0";
|
||||
String sql = "SELECT * FROM dominion WHERE world = '" + world + "' AND id > 0;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static List<DominionDTO> search(String name) {
|
||||
String sql = "SELECT * FROM dominion WHERE name LIKE '%" + name + "%' AND id > 0";
|
||||
String sql = "SELECT * FROM dominion WHERE name LIKE '%" + name + "%' AND id > 0;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
@ -104,14 +104,14 @@ public class DominionDTO {
|
||||
-2147483648, -2147483648, -2147483648,
|
||||
2147483647, 2147483647, 2147483647, -1);
|
||||
}
|
||||
String sql = "SELECT * FROM dominion WHERE id = " + id;
|
||||
String sql = "SELECT * FROM dominion WHERE id = " + id + " AND id > 0";
|
||||
List<DominionDTO> dominions = query(sql);
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
}
|
||||
|
||||
public static List<DominionDTO> selectByParentId(String world, Integer parentId) {
|
||||
String sql = "SELECT * FROM dominion WHERE world = '" + world + "' AND parent_dom_id = " + parentId + " AND id > 0";
|
||||
String sql = "SELECT * FROM dominion WHERE world = '" + world + "' AND parent_dom_id = " + parentId + " AND id > 0;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
@ -119,12 +119,12 @@ public class DominionDTO {
|
||||
String sql = "SELECT * FROM dominion WHERE world = '" + world + "' AND " +
|
||||
"x1 <= " + x + " AND x2 >= " + x + " AND " +
|
||||
"y1 <= " + y + " AND y2 >= " + y + " AND " +
|
||||
"z1 <= " + z + " AND z2 >= " + z + " AND " + "id > 0";
|
||||
"z1 <= " + z + " AND z2 >= " + z + " AND " + "id > 0;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static DominionDTO select(String name) {
|
||||
String sql = "SELECT * FROM dominion WHERE name = '" + name + "' AND id > 0";
|
||||
String sql = "SELECT * FROM dominion WHERE name = '" + name + "' AND id > 0;";
|
||||
List<DominionDTO> dominions = query(sql);
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
@ -143,14 +143,14 @@ public class DominionDTO {
|
||||
dominion.getX2() + ", " +
|
||||
dominion.getY2() + ", " +
|
||||
dominion.getZ2() +
|
||||
") RETURNING *";
|
||||
") RETURNING *;";
|
||||
List<DominionDTO> dominions = query(sql);
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
}
|
||||
|
||||
public static void delete(DominionDTO dominion) {
|
||||
String sql = "DELETE FROM dominion WHERE id = " + dominion.getId();
|
||||
String sql = "DELETE FROM dominion WHERE id = " + dominion.getId() + ";";
|
||||
query(sql);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ public class DominionDTO {
|
||||
"wither_spawn = " + dominion.getWitherSpawn() + ", " +
|
||||
"harvest = " + dominion.getHarvest() +
|
||||
" WHERE id = " + dominion.getId() +
|
||||
" RETURNING *";
|
||||
" RETURNING *;";
|
||||
List<DominionDTO> dominions = query(sql);
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
|
@ -21,7 +21,7 @@ public class PlayerDTO {
|
||||
}
|
||||
|
||||
public static List<PlayerDTO> all() {
|
||||
String sql = "SELECT * FROM player_name";
|
||||
String sql = "SELECT * FROM player_name;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
@ -49,14 +49,14 @@ public class PlayerDTO {
|
||||
}
|
||||
|
||||
public static PlayerDTO select(UUID uuid) {
|
||||
String sql = "SELECT * FROM player_name WHERE uuid = '" + uuid.toString() + "'";
|
||||
String sql = "SELECT * FROM player_name WHERE uuid = '" + uuid.toString() + "';";
|
||||
List<PlayerDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
public static PlayerDTO select(String name) {
|
||||
String sql = "SELECT * FROM player_name WHERE last_known_name = '" + name + "'";
|
||||
String sql = "SELECT * FROM player_name WHERE last_known_name = '" + name + "';";
|
||||
List<PlayerDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
@ -64,7 +64,7 @@ public class PlayerDTO {
|
||||
|
||||
public static List<PlayerDTO> search(String name) {
|
||||
// 模糊搜索
|
||||
String sql = "SELECT * FROM player_name WHERE last_known_name LIKE '%" + name + "%'";
|
||||
String sql = "SELECT * FROM player_name WHERE last_known_name LIKE '%" + name + "%';";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public class PlayerDTO {
|
||||
String sql = "INSERT INTO player_name (uuid, last_known_name, last_join_at) " +
|
||||
"VALUES" +
|
||||
" ('" + player.getUuid().toString() + "', '" + player.getLastKnownName() + "', CURRENT_TIMESTAMP) " +
|
||||
"RETURNING *";
|
||||
"RETURNING *;";
|
||||
List<PlayerDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
@ -83,7 +83,7 @@ public class PlayerDTO {
|
||||
"last_known_name = '" + player.getLastKnownName() + "', " +
|
||||
"last_join_at = CURRENT_TIMESTAMP " +
|
||||
"WHERE uuid = '" + player.getUuid().toString() + "' " +
|
||||
"RETURNING *";
|
||||
"RETURNING *;";
|
||||
List<PlayerDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
|
@ -16,7 +16,7 @@ public class PlayerPrivilegeDTO {
|
||||
player.getAdmin() + ", " +
|
||||
player.getDomID() + ", " +
|
||||
player.getPrivilegeTemplateID() + ")" +
|
||||
"RETURNING *";
|
||||
"RETURNING *;";
|
||||
List<PlayerPrivilegeDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
@ -24,12 +24,12 @@ public class PlayerPrivilegeDTO {
|
||||
|
||||
public static List<PlayerPrivilegeDTO> select(UUID playerUUID, Integer dom_id) {
|
||||
String sql = "SELECT * FROM player_privilege WHERE player_uuid = '" + playerUUID + "' " +
|
||||
"AND dom_id = " + dom_id;
|
||||
"AND dom_id = " + dom_id + ";";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static PlayerPrivilegeDTO select(Integer dom_id) {
|
||||
String sql = "SELECT * FROM player_privilege WHERE dom_id = " + dom_id;
|
||||
String sql = "SELECT * FROM player_privilege WHERE dom_id = " + dom_id + ";";
|
||||
List<PlayerPrivilegeDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
@ -38,17 +38,17 @@ public class PlayerPrivilegeDTO {
|
||||
public static void delete(UUID player, Integer domID, Integer privilegeTemplateID) {
|
||||
String sql = "DELETE FROM player_privilege WHERE player_uuid = '" + player + "' " +
|
||||
"AND dom_id = " + domID + " " +
|
||||
"AND privilege_template_id = " + privilegeTemplateID;
|
||||
"AND privilege_template_id = " + privilegeTemplateID + ";";
|
||||
query(sql);
|
||||
}
|
||||
|
||||
public static void delete(UUID player) {
|
||||
String sql = "DELETE FROM player_privilege WHERE player_uuid = '" + player + "'";
|
||||
String sql = "DELETE FROM player_privilege WHERE player_uuid = '" + player + "';";
|
||||
query(sql);
|
||||
}
|
||||
|
||||
public static List<PlayerPrivilegeDTO> selectAll() {
|
||||
String sql = "SELECT * FROM player_privilege";
|
||||
String sql = "SELECT * FROM player_privilege;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ public class PlayerPrivilegeDTO {
|
||||
"admin = " + player.getAdmin() + ", " +
|
||||
"dom_id = " + player.getDomID() + ", " +
|
||||
"privilege_template_id = " + player.getPrivilegeTemplateID() + " " +
|
||||
"WHERE id = " + player.getId();
|
||||
"WHERE id = " + player.getId() + ";";
|
||||
List<PlayerPrivilegeDTO> players = query(sql);
|
||||
if (players.size() == 0) return null;
|
||||
return players.get(0);
|
||||
|
@ -12,63 +12,63 @@ import java.util.UUID;
|
||||
public class PrivilegeTemplateDTO {
|
||||
|
||||
public static PrivilegeTemplateDTO insert(PrivilegeTemplateDTO privilege) {
|
||||
String sql = "INSERT INTO privilege_template (name, creator, group) " +
|
||||
String sql = "INSERT INTO privilege_template (name, creator, team) " +
|
||||
"VALUES ('" +
|
||||
privilege.getName() + "', '" +
|
||||
privilege.getCreator().toString() + "', " +
|
||||
privilege.getGroup() + ") " +
|
||||
"RETURNING *";
|
||||
"RETURNING *;";
|
||||
List<PrivilegeTemplateDTO> templates = query(sql);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
}
|
||||
|
||||
public static List<PrivilegeTemplateDTO> selectAll() {
|
||||
String sql = "SELECT * FROM privilege_template";
|
||||
String sql = "SELECT * FROM privilege_template;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static List<PrivilegeTemplateDTO> searchGroup(String name){
|
||||
String sql = "SELECT * FROM privilege_template WHERE name LIKE '%" + name + "%' AND group = true";
|
||||
String sql = "SELECT * FROM privilege_template WHERE name LIKE '%" + name + "%' AND team = true;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static List<PrivilegeTemplateDTO> selectGroup(UUID creator){
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "' AND group = true";
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "' AND team = true;";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static PrivilegeTemplateDTO select(Integer id) {
|
||||
String sql = "SELECT * FROM privilege_template WHERE id = " + id;
|
||||
String sql = "SELECT * FROM privilege_template WHERE id = " + id + ";";
|
||||
List<PrivilegeTemplateDTO> templates = query(sql);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
}
|
||||
|
||||
public static PrivilegeTemplateDTO select(UUID creator, String name) {
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "' AND name = '" + name + "'";
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "' AND name = '" + name + "';";
|
||||
List<PrivilegeTemplateDTO> templates = query(sql);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
}
|
||||
|
||||
public static List<PrivilegeTemplateDTO> search(String name) {
|
||||
String sql = "SELECT * FROM privilege_template WHERE name LIKE '%" + name + "%'";
|
||||
String sql = "SELECT * FROM privilege_template WHERE name LIKE '%" + name + "%';";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static List<PrivilegeTemplateDTO> search(UUID creator) {
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "'";
|
||||
String sql = "SELECT * FROM privilege_template WHERE creator = '" + creator.toString() + "';";
|
||||
return query(sql);
|
||||
}
|
||||
|
||||
public static void delete(PrivilegeTemplateDTO privilege) {
|
||||
String sql = "DELETE FROM privilege_template WHERE id = " + privilege.getId();
|
||||
String sql = "DELETE FROM privilege_template WHERE id = " + privilege.getId() + ";";
|
||||
query(sql);
|
||||
}
|
||||
|
||||
public static void delete(UUID creator, String name) {
|
||||
String sql = "DELETE FROM privilege_template WHERE creator = '" + creator.toString() + "' AND name = '" + name + "'";
|
||||
String sql = "DELETE FROM privilege_template WHERE creator = '" + creator.toString() + "' AND name = '" + name + "';";
|
||||
query(sql);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class PrivilegeTemplateDTO {
|
||||
String sql = "UPDATE privilege_template SET " +
|
||||
"name = '" + privilege.getName() + "', " +
|
||||
"creator = '" + privilege.getCreator().toString() + "', " +
|
||||
"group = " + privilege.getGroup() + ", " +
|
||||
"team = " + privilege.getGroup() + ", " +
|
||||
"anchor = " + privilege.getAnchor() + ", " +
|
||||
"animal_killing = " + privilege.getAnimalKilling() + ", " +
|
||||
"anvil = " + privilege.getAnvil() + ", " +
|
||||
@ -109,7 +109,7 @@ public class PrivilegeTemplateDTO {
|
||||
"vehicle_destroy = " + privilege.getVehicleDestroy() + ", " +
|
||||
"harvest = " + privilege.getHarvest() + " " +
|
||||
"WHERE id = " + privilege.getId() + " " +
|
||||
"RETURNING *";
|
||||
"RETURNING *;";
|
||||
List<PrivilegeTemplateDTO> templates = query(sql);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
@ -118,7 +118,7 @@ public class PrivilegeTemplateDTO {
|
||||
private final Integer id;
|
||||
private String name;
|
||||
private final UUID creator;
|
||||
private final Boolean group;
|
||||
private final Boolean team;
|
||||
private Boolean anchor;
|
||||
private Boolean animalKilling;
|
||||
private Boolean anvil;
|
||||
@ -164,7 +164,7 @@ public class PrivilegeTemplateDTO {
|
||||
}
|
||||
|
||||
public Boolean getGroup() {
|
||||
return group;
|
||||
return team;
|
||||
}
|
||||
|
||||
public Boolean getAnchor() {
|
||||
@ -451,8 +451,8 @@ public class PrivilegeTemplateDTO {
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public PrivilegeTemplateDTO(String name, UUID creator, Boolean group) {
|
||||
this(null, name, creator, group,
|
||||
public PrivilegeTemplateDTO(String name, UUID creator, Boolean team) {
|
||||
this(null, name, creator, team,
|
||||
false, false, false,
|
||||
false, false, false, false, false,
|
||||
false, false, false, false, false,
|
||||
@ -462,7 +462,7 @@ public class PrivilegeTemplateDTO {
|
||||
false, false, false);
|
||||
}
|
||||
|
||||
private PrivilegeTemplateDTO(Integer id, String name, UUID creator, Boolean group,
|
||||
private PrivilegeTemplateDTO(Integer id, String name, UUID creator, Boolean team,
|
||||
Boolean anchor, Boolean animalKilling, Boolean anvil,
|
||||
Boolean beacon, Boolean bed, Boolean brew, Boolean button, Boolean cake,
|
||||
Boolean container, Boolean craft, Boolean diode, Boolean door, Boolean dye,
|
||||
@ -473,7 +473,7 @@ public class PrivilegeTemplateDTO {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.creator = creator;
|
||||
this.group = group;
|
||||
this.team = team;
|
||||
this.anchor = anchor;
|
||||
this.animalKilling = animalKilling;
|
||||
this.anvil = anvil;
|
||||
@ -516,7 +516,7 @@ public class PrivilegeTemplateDTO {
|
||||
rs.getInt("id"),
|
||||
rs.getString("name"),
|
||||
UUID.fromString(rs.getString("creator")),
|
||||
rs.getBoolean("group"),
|
||||
rs.getBoolean("team"),
|
||||
rs.getBoolean("anchor"),
|
||||
rs.getBoolean("animal_killing"),
|
||||
rs.getBoolean("anvil"),
|
||||
|
16
src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java
Normal file
16
src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java
Normal file
@ -0,0 +1,16 @@
|
||||
package cn.lunadeer.dominion.events;
|
||||
|
||||
import cn.lunadeer.dominion.dtos.PlayerDTO;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerEvents implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player bukkitPlayer = event.getPlayer();
|
||||
PlayerDTO player = PlayerDTO.get(bukkitPlayer);
|
||||
player.onJoin(); // update name
|
||||
}
|
||||
}
|
@ -42,10 +42,10 @@ public class Database {
|
||||
// player name
|
||||
sql += "CREATE TABLE IF NOT EXISTS player_name (" +
|
||||
" id SERIAL PRIMARY KEY," +
|
||||
" uuid VARCHAR(36) NOT NULL," +
|
||||
" uuid VARCHAR(36) NOT NULL UNIQUE," +
|
||||
" last_known_name TEXT NOT NULL," +
|
||||
" last_join_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" +
|
||||
")";
|
||||
");";
|
||||
|
||||
// dominion table
|
||||
sql += "CREATE TABLE IF NOT EXISTS dominion (" +
|
||||
@ -103,14 +103,14 @@ public class Database {
|
||||
|
||||
" FOREIGN KEY (owner) REFERENCES player_name(uuid)," +
|
||||
" FOREIGN KEY (parent_dom_id) REFERENCES dominion(id)" +
|
||||
")";
|
||||
");";
|
||||
|
||||
// privilege template
|
||||
sql += "CREATE TABLE IF NOT EXISTS privilege_template (" +
|
||||
" id SERIAL PRIMARY KEY," +
|
||||
" name TEXT NOT NULL," +
|
||||
" creator VARCHAR(36) NOT NULL," +
|
||||
" group BOOLEAN NOT NULL DEFAULT TRUE," +
|
||||
" team BOOLEAN NOT NULL DEFAULT TRUE," +
|
||||
|
||||
" anchor BOOLEAN NOT NULL DEFAULT FALSE," +
|
||||
" animal_killing BOOLEAN NOT NULL DEFAULT FALSE," +
|
||||
@ -145,7 +145,7 @@ public class Database {
|
||||
" harvest BOOLEAN NOT NULL DEFAULT FALSE," +
|
||||
" UNIQUE (name, creator)," +
|
||||
" FOREIGN KEY (creator) REFERENCES player_name(uuid)" +
|
||||
")";
|
||||
");";
|
||||
|
||||
// player dominion privilege
|
||||
sql += "CREATE TABLE IF NOT EXISTS player_dom_privilege (" +
|
||||
@ -157,7 +157,22 @@ public class Database {
|
||||
" FOREIGN KEY (player_uuid) REFERENCES player_name(uuid)," +
|
||||
" FOREIGN KEY (dom_id) REFERENCES dominion(id)," +
|
||||
" FOREIGN KEY (privilege_template_id) REFERENCES privilege_template(id)" +
|
||||
")";
|
||||
");";
|
||||
|
||||
sql += "INSERT INTO player_name (" +
|
||||
"id, uuid, last_known_name" +
|
||||
") VALUES (" +
|
||||
"-1, '00000000-0000-0000-0000-000000000000', 'server'" +
|
||||
") ON CONFLICT DO NOTHING;";
|
||||
|
||||
sql += "INSERT INTO dominion (" +
|
||||
"id, owner, name, world, x1, y1, z1, x2, y2, z2, parent_dom_id, join_message, leave_message" +
|
||||
") VALUES (" +
|
||||
"-1, '00000000-0000-0000-0000-000000000000', '根领地', 'all', " +
|
||||
"-2147483648, -2147483648, -2147483648, " +
|
||||
"2147483647, 2147483647, 2147483647, -1, " +
|
||||
"'欢迎', '再见'" +
|
||||
") ON CONFLICT DO NOTHING;";
|
||||
|
||||
query(sql);
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ import java.util.List;
|
||||
|
||||
|
||||
public class Line {
|
||||
private String d = " - ";
|
||||
private final List<Component> elements = new ArrayList<>();
|
||||
|
||||
private final TextComponent divider = Component.text(" - ", ViewStyles.sub_color);
|
||||
|
||||
public Line() {
|
||||
}
|
||||
|
||||
public TextComponent build() {
|
||||
TextComponent divider = Component.text(d, ViewStyles.sub_color);
|
||||
TextComponent.Builder builder = Component.text();
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
builder.append(elements.get(i));
|
||||
@ -30,11 +30,20 @@ public class Line {
|
||||
return new Line();
|
||||
}
|
||||
|
||||
List<Component> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public Line append(TextComponent component) {
|
||||
elements.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Line setDivider(String d) {
|
||||
this.d = d;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Line append(Component component) {
|
||||
elements.add(component);
|
||||
return this;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lunadeer.dominion.utils.STUI;
|
||||
|
||||
import cn.lunadeer.dominion.utils.Notification;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -76,7 +77,16 @@ public class ListView {
|
||||
}
|
||||
view.addLine(lines.get(i));
|
||||
}
|
||||
view.actionBar(Pagination.create(page, lines.size(), this.command));
|
||||
view.actionBar(Pagination.create(page, lines.size(), page_size, this.command));
|
||||
view.showOn(player);
|
||||
}
|
||||
|
||||
public ListView navigator(Line line) {
|
||||
Line nav = Line.create().setDivider("->").append(Component.text("导航", ViewStyles.main_color));
|
||||
for (Component component : line.getElements()) {
|
||||
nav.append(component);
|
||||
}
|
||||
view.subtitle(nav);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ import static cn.lunadeer.dominion.utils.STUI.ViewStyles.sub_color;
|
||||
|
||||
|
||||
public class Pagination {
|
||||
public static TextComponent create(int page, int item_size, String command) {
|
||||
public static TextComponent create(int page, int item_size, int page_size, String command) {
|
||||
// 第 x/y 页 [上一页] [下一页]
|
||||
int page_size = 4;
|
||||
int page_count = (int) Math.ceil((double) item_size / page_size);
|
||||
if (page_count == 0) {
|
||||
page_count = 1;
|
||||
|
@ -16,11 +16,11 @@ public class View {
|
||||
protected TextComponent line_decorate = Component.text("⌗ ", main_color);
|
||||
protected TextComponent action_decorate = Component.text("▸ ", main_color);
|
||||
protected TextComponent title = Component.text(" ");
|
||||
protected TextComponent subtitle = Component.text("");
|
||||
protected TextComponent subtitle = null;
|
||||
protected List<TextComponent> content_lines = new ArrayList<>();
|
||||
protected TextComponent actionbar = Component.text(" ");
|
||||
protected TextComponent edge = Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color);
|
||||
protected TextComponent divide_line = Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color);
|
||||
protected TextComponent actionbar = null;
|
||||
protected TextComponent edge = Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color);
|
||||
protected TextComponent divide_line = Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color);
|
||||
|
||||
public void showOn(Player player) {
|
||||
player.sendMessage(edge);
|
||||
@ -36,7 +36,7 @@ public class View {
|
||||
builder.append(title_decorate);
|
||||
}
|
||||
player.sendMessage(builder.build());
|
||||
if (subtitle.content().length() > 0) {
|
||||
if (subtitle != null) {
|
||||
player.sendMessage(divide_line);
|
||||
player.sendMessage(Component.text().append(sub_title_decorate).append(subtitle).build());
|
||||
}
|
||||
@ -44,8 +44,10 @@ public class View {
|
||||
for (TextComponent content_line : content_lines) {
|
||||
player.sendMessage(Component.text().append(line_decorate).append(content_line).build());
|
||||
}
|
||||
player.sendMessage(divide_line);
|
||||
player.sendMessage(Component.text().append(action_decorate).append(actionbar).build());
|
||||
if (actionbar != null) {
|
||||
player.sendMessage(divide_line);
|
||||
player.sendMessage(Component.text().append(action_decorate).append(actionbar).build());
|
||||
}
|
||||
player.sendMessage(edge);
|
||||
player.sendMessage(Component.text(" "));
|
||||
}
|
||||
@ -69,11 +71,19 @@ public class View {
|
||||
return this;
|
||||
}
|
||||
|
||||
public View subtitle(Line line){
|
||||
public View subtitle(Line line) {
|
||||
this.subtitle = line.build();
|
||||
return this;
|
||||
}
|
||||
|
||||
public View navigator(Line line) {
|
||||
Line nav = Line.create().setDivider("->").append(Component.text("导航", ViewStyles.main_color));
|
||||
for (Component component : line.getElements()) {
|
||||
nav.append(component);
|
||||
}
|
||||
return this.subtitle(nav);
|
||||
}
|
||||
|
||||
public View subtitle(TextComponent subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user