Compare commits

...

18 Commits

Author SHA1 Message Date
cd9f4549b2 尝试增加tab列表对齐功能(暂未成功) 2024-08-23 17:53:05 +08:00
6937a15225 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pom.xml
2024-08-23 10:31:49 +08:00
937f9fcd8f 实现了tab papi功能
Some checks failed
Java CI-CD with Maven / build (push) Failing after 4m10s
2024-08-23 10:30:49 +08:00
06aeb33f50 修复了warp在不指定传送点时没有提示而是报错问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 13m24s
2024-08-18 12:25:06 +08:00
6381d51950 测试完成聊天前缀
All checks were successful
Java CI-CD with Maven / build (push) Successful in 11m3s
2024-08-11 12:00:40 +08:00
b44e5a658b Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pom.xml
#	src/main/java/cn/lunadeer/essentialsd/events/ChatPrefixEvent.java
2024-08-11 11:58:41 +08:00
6a7e8b066a 测试了聊天前缀功能
All checks were successful
Java CI-CD with Maven / build (push) Successful in 14m28s
2024-08-11 11:57:19 +08:00
43dc8f0abc 更新 api 版本至 1.21.1 2024-08-11 02:34:39 +08:00
2da5d164d7 更新版本 2024-08-10 23:33:50 +08:00
b71fec6329 实现了prefix功能(未测试) 2024-08-10 20:22:01 +08:00
50c8d8812a 新增 warp 功能
All checks were successful
Java CI-CD with Maven / build (push) Successful in 21m25s
2024-08-09 11:45:32 +08:00
ad8fc39ab8 补充注释 2024-08-08 23:54:53 +08:00
37b773c6c3 新增warp功能 2024-08-08 23:52:40 +08:00
e50f0d035c rtp强制传送到主世界 2024-08-08 22:39:29 +08:00
cbf9718fb0 修复 god fly inspect指令异常问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 6m15s
2024-08-01 13:45:11 +08:00
f19d8de23d 修复了tpahere无法接受请求的问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 8m23s
2024-07-18 20:09:12 +08:00
440c4c9fa6 新增权限节点支持,移除配置文件的commands
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m14s
2024-07-16 14:16:29 +08:00
cb9716e7b0 修复登录记录数据库错误问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m29s
2024-06-17 14:51:43 +08:00
47 changed files with 940 additions and 335 deletions

View File

@ -15,10 +15,10 @@ jobs:
fetch-depth: 0
- name: "Set up Maven"
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
- name: "Set up JDK 17"
- name: "Set up JDK 21"
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'zulu'
cache: maven
- name: "Build with Maven"

View File

@ -7,7 +7,7 @@ EssentialsX其中D代表Deer。
## 支持版本
- 1.20.1+ (Folia)
- 1.21.1+ (Folia)
## 安装方法

18
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>EssentialsD</artifactId>
<version>1.22.0</version>
<version>2.3.1</version>
<packaging>jar</packaging>
<name>EssentialsD</name>
@ -70,13 +70,17 @@
<id>lunadeer-repo</id>
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -90,5 +94,11 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -5,9 +5,24 @@ import cn.lunadeer.essentialsd.commands.home.DelHome;
import cn.lunadeer.essentialsd.commands.home.Home;
import cn.lunadeer.essentialsd.commands.home.Homes;
import cn.lunadeer.essentialsd.commands.home.SetHome;
import cn.lunadeer.essentialsd.commands.time.Day;
import cn.lunadeer.essentialsd.commands.time.Night;
import cn.lunadeer.essentialsd.commands.time.Noon;
import cn.lunadeer.essentialsd.commands.tp.Back;
import cn.lunadeer.essentialsd.commands.tp.Rtp;
import cn.lunadeer.essentialsd.commands.tp.Tpa;
import cn.lunadeer.essentialsd.commands.tp.TpaHere;
import cn.lunadeer.essentialsd.commands.warp.DelWarp;
import cn.lunadeer.essentialsd.commands.warp.SetWarp;
import cn.lunadeer.essentialsd.commands.warp.Warp;
import cn.lunadeer.essentialsd.commands.warp.Warps;
import cn.lunadeer.essentialsd.commands.weather.Rain;
import cn.lunadeer.essentialsd.commands.weather.Storm;
import cn.lunadeer.essentialsd.commands.weather.Sun;
import cn.lunadeer.essentialsd.events.*;
import cn.lunadeer.essentialsd.managers.ConfigManager;
import cn.lunadeer.essentialsd.managers.DatabaseTables;
import cn.lunadeer.essentialsd.managers.TabListUpdater;
import cn.lunadeer.essentialsd.managers.TeleportManager;
import cn.lunadeer.essentialsd.recipes.*;
import cn.lunadeer.minecraftpluginutils.*;
@ -24,7 +39,6 @@ public final class EssentialsD extends JavaPlugin {
instance = this;
new XLogger(instance);
config = new ConfigManager(instance);
XLogger.setDebug(config.isDebug());
new Notification(instance);
database = new DatabaseManager(this,
DatabaseManager.TYPE.valueOf(config.getDbType().toUpperCase()),
@ -37,6 +51,16 @@ public final class EssentialsD extends JavaPlugin {
new Scheduler(this);
tpManager = new TeleportManager();
if (config.getPrefixEnable()) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
Bukkit.getPluginManager().registerEvents(new ChatPrefixEvent(), this);
new TabListUpdater(); // 更新 TabList
} else {
XLogger.warn("未找到 PlaceholderAPI 插件, 无法使用聊天前缀功能, 已自动关闭前缀功能");
config.setPrefixEnable(false);
}
}
Bukkit.getPluginManager().registerEvents(new InvisibleItemFrameEvent(), this);
Bukkit.getPluginManager().registerEvents(new ChairEvent(), this);
Bukkit.getPluginManager().registerEvents(new ArmorStandHandsEvent(), this);
@ -64,13 +88,21 @@ public final class EssentialsD extends JavaPlugin {
Objects.requireNonNull(Bukkit.getPluginCommand("hat")).setExecutor(new Hat());
Objects.requireNonNull(Bukkit.getPluginCommand("showitem")).setExecutor(new ShowItem());
Objects.requireNonNull(Bukkit.getPluginCommand("skull")).setExecutor(new Skull());
// tp
Objects.requireNonNull(Bukkit.getPluginCommand("tpa")).setExecutor(new Tpa());
Objects.requireNonNull(Bukkit.getPluginCommand("tpahere")).setExecutor(new TpaHere());
Objects.requireNonNull(Bukkit.getPluginCommand("rtp")).setExecutor(new Rtp());
Objects.requireNonNull(Bukkit.getPluginCommand("back")).setExecutor(new Back());
// home
Objects.requireNonNull(Bukkit.getPluginCommand("home")).setExecutor(new Home());
Objects.requireNonNull(Bukkit.getPluginCommand("homes")).setExecutor(new Homes());
Objects.requireNonNull(Bukkit.getPluginCommand("sethome")).setExecutor(new SetHome());
Objects.requireNonNull(Bukkit.getPluginCommand("delhome")).setExecutor(new DelHome());
// warp
Objects.requireNonNull(Bukkit.getPluginCommand("setwarp")).setExecutor(new SetWarp());
Objects.requireNonNull(Bukkit.getPluginCommand("delwarp")).setExecutor(new DelWarp());
Objects.requireNonNull(Bukkit.getPluginCommand("warp")).setExecutor(new Warp());
Objects.requireNonNull(Bukkit.getPluginCommand("warps")).setExecutor(new Warps());
if (config.getRecipesCrowbar()) {

View File

@ -2,7 +2,8 @@ package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -10,26 +11,6 @@ import java.util.List;
import java.util.stream.Collectors;
public class Apis {
/**
* 判断 CommandSender 是否为 OP 玩家
*
* @param sender CommandSender
* @return 如果是 OP 玩家则返回 Player 对象否则返回 null
*/
public static Player getIfOP(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
XLogger.warn("玩家 %s 被拒绝执行命令", player.getName());
Notification.warn(player, "你没有权限使用此命令");
return null;
}
return player;
}
Notification.warn(sender, "只有玩家才能使用此命令");
return null;
}
/**
* 获取命令操作的玩家 如果没有指定玩家则返回命令发送者
*
@ -37,43 +18,35 @@ public class Apis {
* @param args 命令参数
* @return 如果指定了玩家则返回玩家对象否则返回命令发送者
*/
public static Player opCommandGetPlayer(CommandSender sender, String[] args) {
Player target;
if (args.length == 1) {
target = EssentialsD.instance.getServer().getPlayer(args[0]);
if (target == null) {
Notification.warn(sender, "玩家 %s 不在线", args[0]);
public static Player getPlayerFromArg(CommandSender sender, String[] args, int pos) {
if (args.length <= pos) {
if (sender instanceof Player) {
return (Player) sender;
} else {
Notification.error(sender, "以控制台身份执行时,必须指定玩家");
return null;
}
} else {
if (!(sender instanceof Player)) {
Notification.warn(sender, "请指定要操作的玩家");
return null;
}
target = (Player) sender;
}
Player target = EssentialsD.instance.getServer().getPlayer(args[pos]);
if (target == null) {
Notification.warn(sender, "玩家 %s 不在线", args[0]);
return null;
}
return target;
}
/**
* 判断是否为 OP 玩家或控制台
*
* @param sender 命令发送者
* @return 如果是 OP 玩家或控制台则返回 true否则返回 false
*/
public static boolean notOpOrConsole(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
XLogger.warn("玩家 %s 被拒绝执行命令", player.getName());
Notification.warn(player, "你没有权限使用此命令");
return true;
}
}
return false;
}
public static List<String> playerNames() {
return EssentialsD.instance.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
}
public static void setOverWorldTime(CommandSender sender, long time) {
Scheduler.runTask(() -> {
EssentialsD.instance.getServer().getWorlds().forEach(world -> {
if (world.getEnvironment() == World.Environment.NORMAL) {
world.setTime(time);
Notification.info(sender, "设置 %s 时间为 %d", world.getName(), time);
}
});
});
}
}

View File

@ -18,10 +18,6 @@ public class EnderChest implements CommandExecutor {
Notification.error(sender, "只有玩家才能使用这个命令");
return false;
}
if (!EssentialsD.config.getCommandsEnderchest()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
// 打开玩家的末影箱
Player player = (Player) sender;
Inventory chest = player.getEnderChest();

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.command.Command;
@ -9,17 +8,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.opCommandGetPlayer;
import static cn.lunadeer.essentialsd.commands.Apis.getPlayerFromArg;
public class Fly implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
if (!(sender instanceof Player) && args.length < 1) {
Notification.error(sender, "以控制台身份执行时,必须指定玩家:/fly <player>");
return false;
}
Scheduler.runTask(() -> {
Player target = opCommandGetPlayer(sender, args);
Player target = getPlayerFromArg(sender, args, 0);
if (target == null) {
return;
}

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.command.Command;
@ -9,17 +8,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.opCommandGetPlayer;
import static cn.lunadeer.essentialsd.commands.Apis.getPlayerFromArg;
public class God implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
if (!(sender instanceof Player) && args.length < 1) {
Notification.error(sender, "以控制台身份执行时,必须指定玩家:/god <player>");
return false;
}
Scheduler.runTask(() -> {
Player target = opCommandGetPlayer(sender, args);
Player target = getPlayerFromArg(sender, args, 0);
if (target == null) {
return;
}

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -17,10 +16,6 @@ public class Hat implements CommandExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsHat()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
PlayerInventory inventory = player.getInventory();
ItemStack right_hand_item = inventory.getItemInMainHand();

View File

@ -1,9 +1,7 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -11,8 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.opCommandGetPlayer;
import static cn.lunadeer.essentialsd.commands.Apis.getPlayerFromArg;
public class Inspect implements CommandExecutor {
/**
@ -34,11 +31,8 @@ public class Inspect implements CommandExecutor {
return false;
}
Player op = (Player) sender;
if (notOpOrConsole(sender)) {
return false;
}
Scheduler.runTask(() -> {
Player target = opCommandGetPlayer(sender, args);
Player target = getPlayerFromArg(op, args, 0);
if (target == null) {
return;
}

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -11,16 +10,15 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map;
import static cn.lunadeer.essentialsd.commands.Apis.getIfOP;
public class More implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = getIfOP(sender);
if (player == null) {
return false;
if (!(sender instanceof Player)) {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
int amount = 64;
Player player = (Player) sender;
int amount = 63;
if (args.length > 0) {
try {
amount = Integer.parseInt(args[0]);

View File

@ -8,7 +8,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
public class Save implements CommandExecutor {
/**
@ -25,9 +24,6 @@ public class Save implements CommandExecutor {
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
return false;
}
// 保存服务器存档
Notification.info(sender, "正在保存服务器存档...");
EssentialsD.instance.getServer().savePlayers();

View File

@ -27,10 +27,6 @@ public class ShowItem implements CommandExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsShowItem()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
if (args.length == 1) {
openView(player, args[0]);

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.Material;
import org.bukkit.command.Command;
@ -23,10 +22,6 @@ public class Skull implements CommandExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsSkull()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
PlayerInventory backpack = player.getInventory();
Map<Integer, ? extends ItemStack> creeper_skulls = backpack.all(Material.CREEPER_HEAD);

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -16,10 +15,6 @@ public class Suicide implements CommandExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsSuicide()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
player.setHealth(0.0);
player.setKiller(player);

View File

@ -1,6 +1,5 @@
package cn.lunadeer.essentialsd.commands.home;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.dtos.HomeInfo;
import cn.lunadeer.essentialsd.tuis.HomeList;
import cn.lunadeer.minecraftpluginutils.Notification;
@ -21,10 +20,6 @@ public class DelHome implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsHome()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
String homeName;
if (args.length == 0) {

View File

@ -20,10 +20,6 @@ public class Home implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsHome()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
List<HomeInfo> homes = HomeInfo.getHomesOf(player.getUniqueId());
String homeName;

View File

@ -1,8 +1,6 @@
package cn.lunadeer.essentialsd.commands.home;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.tuis.HomeList;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@ -14,10 +12,6 @@ import java.util.List;
public class Homes implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!EssentialsD.config.getCommandsHome()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
HomeList.show(sender, args);
return true;
}

View File

@ -20,10 +20,6 @@ public class SetHome implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsHome()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
List<HomeInfo> homes = HomeInfo.getHomesOf(((Player) sender).getUniqueId());
if (homes.size() > EssentialsD.config.getHomeLimitAmount()) {

View File

@ -1,15 +1,12 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.time;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.setOverWorldTime;
public class Day implements CommandExecutor {
/**
@ -26,19 +23,8 @@ public class Day implements CommandExecutor {
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
return false;
}
// set time to 1000
Scheduler.runTask(() -> {
if (sender instanceof Player) {
((Player) sender).getWorld().setTime(1000);
Notification.info(sender, "设置 %s 时间为白天", ((Player) sender).getWorld().getName());
} else {
EssentialsD.instance.getServer().getWorlds().forEach(world -> world.setTime(1000));
Notification.info(sender, "设置时间为白天");
}
});
setOverWorldTime(sender, 1000);
return true;
}
}

View File

@ -1,15 +1,11 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.time;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.setOverWorldTime;
public class Night implements CommandExecutor {
/**
@ -26,19 +22,7 @@ public class Night implements CommandExecutor {
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
return false;
}
// set time to 13000
Scheduler.runTask(() -> {
if (sender instanceof Player) {
((Player) sender).getWorld().setTime(13000);
Notification.info(sender, "设置 %s 时间为夜晚", ((Player) sender).getWorld().getName());
} else {
EssentialsD.instance.getServer().getWorlds().forEach(world -> world.setTime(13000));
Notification.info(sender, "设置时间为夜晚");
}
});
setOverWorldTime(sender, 13000);
return true;
}
}

View File

@ -1,15 +1,12 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.time;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.notOpOrConsole;
import static cn.lunadeer.essentialsd.commands.Apis.setOverWorldTime;
public class Noon implements CommandExecutor {
/**
@ -26,19 +23,7 @@ public class Noon implements CommandExecutor {
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (notOpOrConsole(sender)) {
return false;
}
// set time to 6000
Scheduler.runTask(() -> {
if (sender instanceof Player) {
((Player) sender).getWorld().setTime(6000);
Notification.info(sender, "设置 %s 时间为正午", ((Player) sender).getWorld().getName());
} else {
EssentialsD.instance.getServer().getWorlds().forEach(world -> world.setTime(6000));
Notification.info(sender, "设置时间为正午");
}
});
setOverWorldTime(sender, 6000);
return true;
}
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.tp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
@ -18,10 +18,6 @@ public class Back implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsBack()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
EssentialsD.tpManager.back(player);
return true;

View File

@ -1,4 +1,4 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.tp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
@ -18,10 +18,6 @@ public class Rtp implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsRtp()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
EssentialsD.tpManager.rtp(player);
return true;

View File

@ -1,4 +1,4 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.tp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
@ -20,10 +20,6 @@ public class Tpa implements TabExecutor {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
if (!EssentialsD.config.getCommandsTpa()) {
Notification.error(sender, "这个命令已被管理员禁用");
return false;
}
Player player = (Player) sender;
if (args.length == 1) {
Player target = EssentialsD.instance.getServer().getPlayer(args[0]);
@ -31,7 +27,7 @@ public class Tpa implements TabExecutor {
Notification.warn(player, "玩家 %s 不在线", args[0]);
return true;
}
EssentialsD.tpManager.request(player, target);
EssentialsD.tpManager.tpaRequest(player, target);
return true;
} else if (args.length == 2) {
if (args[0].equals("accept")) {

View File

@ -0,0 +1,49 @@
package cn.lunadeer.essentialsd.commands.tp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
public class TpaHere implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
Notification.warn(sender, "只有玩家可以使用此命令");
return true;
}
Player player = (Player) sender;
if (args.length == 1) {
Player target = EssentialsD.instance.getServer().getPlayer(args[0]);
if (target == null) {
Notification.warn(player, "玩家 %s 不在线", args[0]);
return true;
}
EssentialsD.tpManager.tpahereRequest(player, target);
return true;
} else {
Notification.error(player, "参数错误");
return false;
}
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
Collection<? extends Player> players = EssentialsD.instance.getServer().getOnlinePlayers();
List<String> result = new java.util.ArrayList<>();
for (Player player : players) {
result.add(player.getName());
}
return result;
}
return null;
}
}

View File

@ -0,0 +1,38 @@
package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class DelWarp implements TabExecutor {
/**
* /delwarp <name>
*/
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (strings.length != 1) {
Notification.error(commandSender, "用法: /delwarp <name>");
return true;
}
WarpPoint point = WarpPoint.selectByName(strings[0]);
if (point == null) {
Notification.error(commandSender, "传送点 %s 不存在", strings[0]);
return true;
}
WarpPoint.delete(point);
Notification.info(commandSender, "传送点 %s 已删除", strings[0]);
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return WarpPoint.selectAllNames();
}
}

View File

@ -0,0 +1,86 @@
package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class SetWarp implements TabExecutor {
/**
* /setwarp <name>
* /setwarp <name> <world> <x> <y> <z>
*/
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (strings.length != 1 && strings.length != 5) {
Notification.error(commandSender, "用法: /setwarp <name> 或 /setwarp <name> <world> <x> <y> <z>");
return true;
}
String name = strings[0];
Location location;
if (strings.length == 1) {
if (commandSender instanceof Player) {
location = ((Player) commandSender).getLocation();
} else {
Notification.error(commandSender, "请指定坐标 /setwarp <name> <world> <x> <y> <z>");
return true;
}
} else {
try {
double x = Double.parseDouble(strings[1]);
double y = Double.parseDouble(strings[2]);
double z = Double.parseDouble(strings[3]);
World world = EssentialsD.instance.getServer().getWorld(strings[0]);
if (world == null) {
Notification.error(commandSender, "世界 %s 不存在", strings[0]);
return true;
}
location = new Location(world, x, y, z);
} catch (NumberFormatException e) {
Notification.error(commandSender, "坐标必须是数字");
return true;
}
}
WarpPoint existing = WarpPoint.selectByName(name);
if (existing != null) {
Notification.error(commandSender, "传送点 %s 已存在", name);
return true;
}
WarpPoint point = new WarpPoint(name, location);
WarpPoint.insert(point);
Notification.info(commandSender, "传送点 %s 已设置", name);
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
List<String> res = new ArrayList<>();
if (args.length == 1) {
res.add("传送点名称");
}
if (args.length == 2) {
res.add("世界名称");
}
if (args.length == 3) {
res.add("x");
}
if (args.length == 4) {
res.add("y");
}
if (args.length == 5) {
res.add("z");
}
return res;
}
}

View File

@ -0,0 +1,52 @@
package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class Warp implements TabExecutor {
/**
* /warp <name>
*/
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!(commandSender instanceof Player)) {
Notification.warn(commandSender, "只有玩家可以使用此命令");
return true;
}
Player player = (Player) commandSender;
if (strings.length != 1) {
Notification.error(commandSender, "用法: /warp <name>");
return true;
}
WarpPoint point = WarpPoint.selectByName(strings[0]);
if (point == null) {
Notification.error(commandSender, "传送点 %s 不存在", strings[0]);
return true;
}
try {
EssentialsD.tpManager.doTeleportDelayed(player, point.getLocation(), EssentialsD.config.getTpDelay(), () -> {
Notification.info(player, "正在传送到 %s", strings[0]);
}, () -> {
Notification.info(player, "已传送到 %s", strings[0]);
});
} catch (RuntimeException e) {
Notification.error(player, e.getMessage());
}
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return WarpPoint.selectAllNames();
}
}

View File

@ -0,0 +1,15 @@
package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.tuis.WarpList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class Warps implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
WarpList.show(commandSender, strings);
return true;
}
}

View File

@ -1,28 +1,26 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.weather;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.getIfOP;
public class Rain implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = getIfOP(sender);
if (player == null) {
return true;
}
// 设置天气为雨天
Scheduler.runTask(() -> {
player.getWorld().setStorm(true);
player.getWorld().setThundering(false);
Notification.info(player, "设置 %s 天气为雨天", player.getWorld().getName());
EssentialsD.instance.getServer().getWorlds().forEach(world -> {
if (world.getEnvironment() == World.Environment.NORMAL) {
world.setStorm(true);
world.setThundering(false);
Notification.info(sender, "设置 %s 天气为雨天", world.getName());
}
});
});
return true;
}

View File

@ -1,28 +1,26 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.weather;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.getIfOP;
public class Storm implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = getIfOP(sender);
if (player == null) {
return true;
}
// 设置天气为雷雨
Scheduler.runTask(() -> {
player.getWorld().setStorm(true);
player.getWorld().setThundering(true);
Notification.info(player, "设置 %s 天气为雷雨", player.getWorld().getName());
EssentialsD.instance.getServer().getWorlds().forEach(world -> {
if (world.getEnvironment() == World.Environment.NORMAL) {
world.setStorm(true);
world.setThundering(true);
Notification.info(sender, "设置 %s 天气为雷雨", world.getName());
}
});
});
return true;
}

View File

@ -1,28 +1,26 @@
package cn.lunadeer.essentialsd.commands;
package cn.lunadeer.essentialsd.commands.weather;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static cn.lunadeer.essentialsd.commands.Apis.getIfOP;
public class Sun implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = getIfOP(sender);
if (player == null) {
return true;
}
Scheduler.runTask(() -> {
// 设置天气为晴朗
player.getWorld().setStorm(false);
player.getWorld().setThundering(false);
Notification.info(player, "设置 %s 天气为晴朗", player.getWorld().getName());
EssentialsD.instance.getServer().getWorlds().forEach(world -> {
if (world.getEnvironment() == World.Environment.NORMAL) {
world.setStorm(false);
world.setThundering(false);
Notification.info(sender, "设置 %s 天气为晴朗", world.getName());
}
});
});
return true;
}

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import java.net.InetSocketAddress;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.UUID;
public class LoginRecord {
@ -32,8 +33,8 @@ public class LoginRecord {
} else {
ip = address.getAddress().getHostAddress();
}
long login_time = player.getLastLogin();
long logout_time = System.currentTimeMillis();
Timestamp login_time = new Timestamp(player.getLastLogin());
Timestamp logout_time = new Timestamp(System.currentTimeMillis());
String logout_location = LocationUtils.Serialize(player.getLocation());
String sql = "INSERT INTO login_record (uuid, ip, login_time, logout_location, logout_time) " +
"VALUES (?, ?, ?, ?, ?);";

View File

@ -0,0 +1,100 @@
package cn.lunadeer.essentialsd.dtos;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.utils.LocUtil;
import org.bukkit.Location;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class WarpPoint {
private Integer id;
private final String name;
private final Location location;
public WarpPoint(Integer id, String name, Location location) {
this.id = id;
this.name = name;
this.location = location;
}
public WarpPoint(String name, Location location) {
this.name = name;
this.location = location;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public Location getLocation() {
return location;
}
public static void insert(WarpPoint point) {
String sql = "INSERT INTO warp_point (warp_name, location) VALUES (?, ?);";
try (ResultSet rs = EssentialsD.database.query(sql, point.getName(), LocUtil.toString(point.getLocation()))) {
if (rs == null) return;
} catch (Exception e) {
EssentialsD.database.handleDatabaseError("插入传送点失败", e, sql);
}
}
public static void delete(WarpPoint point) {
String sql = "DELETE FROM warp_point WHERE warp_name = ?;";
try (ResultSet rs = EssentialsD.database.query(sql, point.getName())) {
if (rs == null) return;
} catch (Exception e) {
EssentialsD.database.handleDatabaseError("删除传送点失败", e, sql);
}
}
public static WarpPoint selectByName(String name) {
String sql = "SELECT * FROM warp_point WHERE warp_name = ?;";
try (ResultSet rs = EssentialsD.database.query(sql, name)) {
if (rs == null) return null;
if (rs.next()) {
return new WarpPoint(rs.getInt("id"), rs.getString("warp_name"), LocUtil.fromString(rs.getString("location")));
}
} catch (Exception e) {
EssentialsD.database.handleDatabaseError("查询传送点失败", e, sql);
return null;
}
return null;
}
public static List<String> selectAllNames() {
List<String> names = new ArrayList<>();
String sql = "SELECT DISTINCT warp_name FROM warp_point;";
try (ResultSet rs = EssentialsD.database.query(sql)) {
if (rs == null) return names;
while (rs.next()) {
names.add(rs.getString("warp_name"));
}
} catch (Exception e) {
EssentialsD.database.handleDatabaseError("查询传送点名字失败", e, sql);
return names;
}
return names;
}
public static List<WarpPoint> selectAll() {
List<WarpPoint> points = new ArrayList<>();
String sql = "SELECT * FROM warp_point;";
try (ResultSet rs = EssentialsD.database.query(sql)) {
if (rs == null) return points;
while (rs.next()) {
points.add(new WarpPoint(rs.getInt("id"), rs.getString("warp_name"), LocUtil.fromString(rs.getString("location"))));
}
} catch (Exception e) {
EssentialsD.database.handleDatabaseError("查询传送点失败", e, sql);
return points;
}
return points;
}
}

View File

@ -16,11 +16,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.util.Vector;
import org.spigotmc.event.entity.EntityDismountEvent;
public class ChairEvent implements Listener {

View File

@ -0,0 +1,19 @@
package cn.lunadeer.essentialsd.events;
import cn.lunadeer.essentialsd.EssentialsD;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatPrefixEvent implements Listener {
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
event.setCancelled(true);
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixChatFormat());
formated += event.getMessage();
EssentialsD.instance.getServer().broadcastMessage(formated);
}
}

View File

@ -23,6 +23,7 @@ public class ConfigManager {
_plugin.reloadConfig();
_file = _plugin.getConfig();
_debug = _file.getBoolean("Debug", false);
XLogger.setDebug(isDebug());
_check_update = _file.getBoolean("CheckUpdate", true);
_exp_bottle_ratio = (float) _file.getDouble("ExpBottleRatio", 1.0);
_combine_exp_orbs_enable = _file.getBoolean("CombineExpOrbs.Enable", false);
@ -30,15 +31,6 @@ public class ConfigManager {
_no_exp_cool_down = _file.getBoolean("NoExpCoolDown", false);
_force_load_chunks = _file.getStringList("ForceLoadChunks");
_chunk_operate_delay = _file.getInt("ChunkOperateDelay", 10);
_commands_tpa = _file.getBoolean("Commands.Tpa", true);
_commands_rtp = _file.getBoolean("Commands.Rtp", true);
_commands_back = _file.getBoolean("Commands.Back", true);
_commands_enderchest = _file.getBoolean("Commands.EnderChest", true);
_commands_suicide = _file.getBoolean("Commands.Suicide", true);
_commands_hat = _file.getBoolean("Commands.Hat", true);
_commands_showitem = _file.getBoolean("Commands.ShowItem", true);
_commands_skull = _file.getBoolean("Commands.Skull", true);
_commands_home = _file.getBoolean("Commands.Home", true);
_tp_delay = _file.getInt("Teleport.Delay", 0);
_tp_cool_down = _file.getInt("Teleport.CoolDown", 0);
_tp_tpa_expire = _file.getInt("Teleport.TpaExpire", 30);
@ -64,6 +56,46 @@ public class ConfigManager {
_db_name = _file.getString("Database.Name", "dominion");
_db_user = _file.getString("Database.User", "postgres");
_db_pass = _file.getString("Database.Pass", "postgres");
_prefix_enable = _file.getBoolean("Prefix.Enable", true);
_prefix_chat_format = _file.getString("Prefix.ChatFormat", "<%player_name%> ");
_prefix_tab_format = _file.getString("Prefix.TabFormat", "%player_name%");
saveAll(); // save all to make sure all values are valid
}
private void saveAll() {
_file.set("Debug", _debug);
_file.set("CheckUpdate", _check_update);
_file.set("ExpBottleRatio", _exp_bottle_ratio);
_file.set("CombineExpOrbs.Enable", _combine_exp_orbs_enable);
_file.set("CombineExpOrbs.Radius", _combine_exp_orbs_radius);
_file.set("NoExpCoolDown", _no_exp_cool_down);
_file.set("ForceLoadChunks", _force_load_chunks);
_file.set("ChunkOperateDelay", _chunk_operate_delay);
_file.set("Teleport.Delay", _tp_delay);
_file.set("Teleport.CoolDown", _tp_cool_down);
_file.set("Teleport.TpaExpire", _tp_tpa_expire);
_file.set("Teleport.RtpRadius", _tp_rtp_radius);
_file.set("Teleport.WorldBlackList", _tp_world_blacklist);
_file.set("Chair.Enable", _chair_enable);
_file.set("Chair.MaxWidth", _chair_max_width);
_file.set("Chair.SignCheck", _chair_sign_check);
_file.set("Chair.SitHeight", _chair_sit_height);
_file.set("Recipes.CrowBar", _recipes_crowbar);
_file.set("Recipes.InvisibleItemFrame", _recipes_invisible_item_frame);
_file.set("Recipes.LightBlock", _recipes_light_block);
_file.set("Recipes.StackedEnchantBook", _recipes_stacked_enchant_book);
_file.set("HomeLimit.Amount", _home_limit_amount);
_file.set("HomeLimit.WorldBlacklist", _home_world_blacklist);
_file.set("Database.Type", _db_type);
_file.set("Database.Host", _db_host);
_file.set("Database.Port", _db_port);
_file.set("Database.Name", _db_name);
_file.set("Database.User", _db_user);
_file.set("Database.Pass", _db_pass);
_file.set("Prefix.Enable", _prefix_enable);
_file.set("Prefix.ChatFormat", _prefix_chat_format);
_file.set("Prefix.TabFormat", _prefix_tab_format);
_plugin.saveConfig();
}
public Boolean isDebug() {
@ -157,43 +189,6 @@ public class ConfigManager {
return _tp_world_blacklist;
}
public Boolean getCommandsTpa() {
return _commands_tpa;
}
public Boolean getCommandsRtp() {
return _commands_rtp;
}
public Boolean getCommandsBack() {
return _commands_back;
}
public Boolean getCommandsEnderchest() {
return _commands_enderchest;
}
public Boolean getCommandsSuicide() {
return _commands_suicide;
}
public Boolean getCommandsHat() {
return _commands_hat;
}
public Boolean getCommandsShowItem() {
return _commands_showitem;
}
public Boolean getCommandsSkull() {
return _commands_skull;
}
public Boolean getCommandsHome() {
return _commands_home;
}
public Boolean getChairEnable() {
return _chair_enable;
}
@ -320,6 +315,36 @@ public class ConfigManager {
return _db_pass;
}
public Boolean getPrefixEnable() {
return _prefix_enable;
}
public void setPrefixEnable(Boolean enable) {
_prefix_enable = enable;
_file.set("Prefix.Enable", enable);
_plugin.saveConfig();
}
public String getPrefixChatFormat() {
return _prefix_chat_format;
}
public void setPrefixChatFormat(String format) {
_prefix_chat_format = format;
_file.set("Prefix.Format", format);
_plugin.saveConfig();
}
public String getPrefixTabFormat() {
return _prefix_tab_format;
}
public void setPrefixTabFormat(String format) {
_prefix_tab_format = format;
_file.set("Prefix.TabFormat", format);
_plugin.saveConfig();
}
private final EssentialsD _plugin;
private FileConfiguration _file;
@ -340,16 +365,6 @@ public class ConfigManager {
private Boolean _chair_sign_check;
private Float _chair_sit_height;
private Boolean _check_update;
// commands
private Boolean _commands_tpa;
private Boolean _commands_rtp;
private Boolean _commands_back;
private Boolean _commands_enderchest;
private Boolean _commands_suicide;
private Boolean _commands_hat;
private Boolean _commands_showitem;
private Boolean _commands_skull;
private Boolean _commands_home;
// recipes
private Boolean _recipes_crowbar;
private Boolean _recipes_invisible_item_frame;
@ -367,4 +382,9 @@ public class ConfigManager {
private String _db_user;
private String _db_pass;
private String _db_name;
// prefix
private Boolean _prefix_enable;
private String _prefix_chat_format;
private String _prefix_tab_format;
}

View File

@ -84,5 +84,13 @@ public class DatabaseTables {
" FOREIGN KEY (uuid) REFERENCES player_name(uuid) ON DELETE CASCADE" +
");";
EssentialsD.database.query(sql);
// warp info
sql = "CREATE TABLE IF NOT EXISTS warp_point (" +
" id SERIAL PRIMARY KEY," +
" warp_name TEXT NOT NULL," +
" location TEXT NOT NULL" +
");";
EssentialsD.database.query(sql);
}
}

View File

@ -0,0 +1,67 @@
package cn.lunadeer.essentialsd.managers;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class TabListUpdater {
public static TabListUpdater instance;
public TabListUpdater() {
instance = this;
Scheduler.runTaskRepeatAsync(this::update, 0, 40);
}
private void update() {
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
Map<UUID, String> formatedNames = new HashMap<>();
int longestFormatedStringLength = 0;
for (Player player : players) {
String formated = PlaceholderAPI.setPlaceholders(player, EssentialsD.config.getPrefixTabFormat());
if (length(formated) > longestFormatedStringLength) {
longestFormatedStringLength = length(formated);
}
formatedNames.put(player.getUniqueId(), formated);
}
// <span> 将会被替换为填充空格 " " 用于保证长度一致
for (Player player : players) {
String formated = formatedNames.get(player.getUniqueId());
int formatedLength = length(formated);
int spaceLength = longestFormatedStringLength - formatedLength;
StringBuilder space = new StringBuilder();
for (int i = 0; i < spaceLength; i++) {
space.append(" ");
}
player.setPlayerListName(formated.replace("<span>", space.toString()));
}
}
private static int length(String value) {
int valueLength = 0;
String chinese = "[\u0391-\uFFE5]";
/* 获取字段值的长度如果含中文字符则每个中文字符长度为2否则为1 */
for (int i = 0; i < value.length(); i++) {
/* 获取一个字符 */
String temp = value.substring(i, i + 1);
/* 判断是否为中文字符 */
if (temp.matches(chinese)) {
/* 中文字符长度为2 */
valueLength += 2;
} else {
/* 其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;
}
}

View File

@ -7,7 +7,9 @@ import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -32,25 +34,30 @@ public class TeleportManager {
public Player initiator;
public Player target;
public UUID taskId;
public Boolean tpahere = false;
}
public void request(Player initiator, Player target) {
private boolean tpReqCheckFail(Player initiator, Player target) {
if (initiator == target) {
Notification.error(initiator, "不能传送到自己的位置");
return;
Notification.error(initiator, "不能传送到同一个位置");
return true;
}
if (!target.isOnline()) {
Notification.error(initiator, "玩家 " + target.getName() + " 不在线");
return;
return true;
}
if (EssentialsD.config.getTpWorldBlackList().contains(target.getWorld().getName())) {
Notification.error(initiator, "目的地所在世界 " + initiator.getWorld().getName() + " 不允许传送");
return;
return true;
}
if (CoolingDown(initiator)) return;
return CoolingDown(initiator);
}
public void tpaRequest(Player initiator, Player target) {
if (tpReqCheckFail(initiator, target)) return;
TpTask task = new TpTask();
task.initiator = initiator;
@ -62,11 +69,36 @@ public class TeleportManager {
TextComponent acceptBtn = Button.createGreen("接受").setExecuteCommand("/tpa accept " + task.taskId).build();
TextComponent denyBtn = Button.createRed("拒绝").setExecuteCommand("/tpa deny " + task.taskId).build();
Notification.info(target, Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color));
Notification.info(target, Component.text(" ", Style.style(main_color, TextDecoration.STRIKETHROUGH)));
Notification.info(target, Component.text("| 玩家 " + initiator.getName() + " 请求传送到你的位置", main_color));
Notification.info(target, Component.text("| 此请求将在 " + EssentialsD.config.getTpTpaExpire() + " 秒后失效", main_color));
Notification.info(target, Component.text("| ", main_color).append(acceptBtn).append(Component.text(" ", main_color)).append(denyBtn));
Notification.info(target, Component.text("━━━━━━━━━━━━━━━━━━━━━━━━━━━━", main_color));
Notification.info(target, Component.text(" ", Style.style(main_color, TextDecoration.STRIKETHROUGH)));
Scheduler.runTaskLater(() -> {
_tasks.remove(task.taskId);
}, 20L * EssentialsD.config.getTpTpaExpire());
}
public void tpahereRequest(Player initiator, Player target) {
if (tpReqCheckFail(initiator, target)) return;
TpTask task = new TpTask();
task.initiator = initiator;
task.target = target;
task.taskId = UUID.randomUUID();
task.tpahere = true;
_tasks.put(task.taskId, task);
Notification.info(initiator, "已向 " + target.getName() + " 发送传送请求");
TextComponent acceptBtn = Button.createGreen("接受").setExecuteCommand("/tpa accept " + task.taskId).build();
TextComponent denyBtn = Button.createRed("拒绝").setExecuteCommand("/tpa deny " + task.taskId).build();
Notification.info(target, Component.text(" ", Style.style(main_color, TextDecoration.STRIKETHROUGH)));
Notification.info(target, Component.text("| 玩家 " + initiator.getName() + " 请求传送你到他的位置", main_color));
Notification.info(target, Component.text("| 此请求将在 " + EssentialsD.config.getTpTpaExpire() + " 秒后失效", main_color));
Notification.info(target, Component.text("| ", main_color).append(acceptBtn).append(Component.text(" ", main_color)).append(denyBtn));
Notification.info(target, Component.text(" ", Style.style(main_color, TextDecoration.STRIKETHROUGH)));
Scheduler.runTaskLater(() -> {
_tasks.remove(task.taskId);
@ -110,15 +142,28 @@ public class TeleportManager {
Notification.info(task.target, "已接受 " + task.initiator.getName() + " 的传送请求");
Notification.info(task.initiator, "玩家 " + task.target.getName() + " 已接受你的传送请求");
try {
doTeleportDelayed(task.initiator, task.target.getLocation(), EssentialsD.config.getTpDelay(), () -> {
Notification.info(task.initiator, "正在传送到 " + task.initiator.getName() + " 的位置");
}, () -> {
Notification.info(task.initiator, "已传送到 " + task.initiator.getName() + " 的位置");
Notification.info(task.target, "玩家 " + task.initiator.getName() + " 已传送到你的位置");
});
} catch (RuntimeException e) {
Notification.error(player, e.getMessage());
if (!task.tpahere) {
try {
doTeleportDelayed(task.initiator, task.target.getLocation(), EssentialsD.config.getTpDelay(), () -> {
Notification.info(task.initiator, "正在传送到 " + task.initiator.getName() + " 的位置");
}, () -> {
Notification.info(task.initiator, "已传送到 " + task.initiator.getName() + " 的位置");
Notification.info(task.target, "玩家 " + task.initiator.getName() + " 已传送到你的位置");
});
} catch (RuntimeException e) {
Notification.error(player, e.getMessage());
}
} else {
try {
doTeleportDelayed(task.target, task.initiator.getLocation(), EssentialsD.config.getTpDelay(), () -> {
Notification.info(task.target, "正在传送到 " + task.initiator.getName() + " 的位置");
}, () -> {
Notification.info(task.target, "已传送到 " + task.initiator.getName() + " 的位置");
Notification.info(task.initiator, "玩家 " + task.target.getName() + " 已传送到你的位置");
});
} catch (RuntimeException e) {
Notification.error(player, e.getMessage());
}
}
}
@ -154,7 +199,18 @@ public class TeleportManager {
}
if (CoolingDown(player)) return;
int radius = EssentialsD.config.getTpRtpRadius();
World world = player.getWorld();
// get main world
World world = null;
for (World w : EssentialsD.instance.getServer().getWorlds()) {
if (w.getEnvironment() == World.Environment.NORMAL) {
world = w;
break;
}
}
if (world == null) {
Notification.error(player, "未找到主世界");
return;
}
int x = (int) (Math.random() * radius * 2) - radius + (int) player.getLocation().getX();
int z = (int) (Math.random() * radius * 2) - radius + (int) player.getLocation().getZ();
XLogger.debug("RTP: " + x + " " + z);
@ -174,22 +230,38 @@ public class TeleportManager {
doTeleportDelayed(player, location, delay.longValue(), before, after);
}
public void doTeleportDelayed(Player player, Location location, Long delay, Runnable before, Runnable after) {
if (EssentialsD.config.getTpWorldBlackList().contains(location.getWorld().getName())) {
Notification.error(player, "目的地所在世界 %s 不允许传送", location.getWorld().getName());
public void doTeleportDelayed(Player player, Location to, Long delay, Runnable before, Runnable after) {
if (EssentialsD.config.getTpWorldBlackList().contains(to.getWorld().getName())) {
Notification.error(player, "目的地所在世界 %s 不允许传送", to.getWorld().getName());
return;
}
if (CoolingDown(player)) return;
if (delay > 0) {
Notification.info(player, "将在 %d 秒后执行传送", EssentialsD.config.getTpDelay());
Notification.info(player, "将在 %d 秒后执行传送", delay);
Scheduler.runTaskAsync(() -> {
long i = delay;
while (i > 0) {
if (!player.isOnline()) {
return;
}
Notification.actionBar(player, "传送倒计时 %d 秒", i);
i--;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
XLogger.warn(e.getMessage());
return;
}
}
});
Scheduler.runTaskLater(() -> {
before.run();
doTeleportSafely(player, location);
doTeleportSafely(player, to);
after.run();
}, 20L * delay);
} else {
before.run();
doTeleportSafely(player, location);
doTeleportSafely(player, to);
after.run();
}
}
@ -200,7 +272,7 @@ public class TeleportManager {
if (next_time != null) {
if (now.isBefore(next_time)) {
long secs_until_next = now.until(next_time, java.time.temporal.ChronoUnit.SECONDS);
Notification.warn(player, "请等待 %d 秒后再次传送", secs_until_next);
Notification.warn(player, "请等待 %d 秒后再次执行传送请求", secs_until_next);
return true;
}
}

View File

@ -1,6 +1,7 @@
package cn.lunadeer.essentialsd.recipes;
import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.XLogger;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;

View File

@ -19,7 +19,7 @@ public class HomeList {
}
Player player = (Player) sender;
List<HomeInfo> homes = HomeInfo.getHomesOf(((Player) sender).getUniqueId());
if (homes.size() == 0) {
if (homes.isEmpty()) {
Notification.warn(player, "你还没有设置家");
return;
}

View File

@ -0,0 +1,45 @@
package cn.lunadeer.essentialsd.tuis;
import cn.lunadeer.essentialsd.dtos.HomeInfo;
import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.essentialsd.utils.LocUtil;
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 org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class WarpList {
public static void show(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
Notification.warn(sender, "只有玩家可以使用此命令");
return;
}
Player player = (Player) sender;
List<WarpPoint> points = WarpPoint.selectAll();
if (points.isEmpty()) {
Notification.warn(player, "没有传送点");
return;
}
int page = 1;
if (args.length == 1) {
try {
page = Integer.parseInt(args[0]);
} catch (Exception ignored) {
}
}
ListView view = ListView.create(5, "/warps");
view.title("Warp 列表");
for (WarpPoint point : points) {
Line line = Line.create()
.append(Component.text(point.getName()).hoverEvent(Component.text(LocUtil.toString(point.getLocation()))))
.append(Button.create("传送").setExecuteCommand("/warp " + point.getName()).build());
view.add(line);
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,23 @@
package cn.lunadeer.essentialsd.utils;
import org.bukkit.Location;
public class LocUtil {
public static String toString(Location loc) {
return String.format("[%s, %.2f, %.2f, %.2f, %.2f, %.2f]", loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
}
public static Location fromString(String str) {
String[] parts = str.substring(1, str.length() - 1).split(", ");
return new Location(
org.bukkit.Bukkit.getWorld(parts[0]),
Double.parseDouble(parts[1]),
Double.parseDouble(parts[2]),
Double.parseDouble(parts[3]),
Float.parseFloat(parts[4]),
Float.parseFloat(parts[5])
);
}
}

View File

@ -35,18 +35,6 @@ Recipes:
LightBlock: true # 光源方块
StackedEnchantBook: true # 附魔书堆叠
# 扩展指令
Commands:
EnderChest: true # 快速末影箱
Suicide: true # 自杀
Hat: true # 把东西戴在头上
ShowItem: true # 展示手中物品
Skull: true # 获取头颅
Tpa: true # 传送到其他玩家
Rtp: true # 随机传送到附近
Back: true # 回到上一个传送位置
Home: true # home相关指令 包含 sethome delhome home homes
# 传送
Teleport:
Delay: 0 # 传送延迟 秒
@ -67,6 +55,12 @@ HomeLimit:
Amount: 5 # 数量限制
WorldBlackList: [ ] # 不允许设置 home 的世界
# prefix (需要 PlaceholderAPI 支持)
Prefix:
Enable: false
ChatFormat: '<%player_name%> '
TabFormat: '%player_name%'
Debug: false
CheckUpdate: true

View File

@ -1,78 +1,197 @@
name: EssentialsD
version: '${project.version}'
main: cn.lunadeer.essentialsd.EssentialsD
api-version: '1.20'
api-version: '1.21'
description: Deer's Essentials
website: https://lunadeer.cn
load: POSTWORLD
load: STARTUP
folia-supported: true
softdepend:
- LuckPerms
- PlaceholderAPI
permissions:
essd.*:
default: op
description: 允许使用 EssentialsD 的所有功能
essd.suicide:
default: true
essd.hat:
default: true
essd.showitem:
default: true
essd.skull:
default: true
essd.god:
default: op
essd.fly:
default: op
essd.time:
default: op
essd.save:
default: op
essd.more:
default: op
essd.weather:
default: op
essd.enderchest:
default: true
essd.tp.*:
default: true
children:
essd.tp.tpa: true
essd.tp.tpahere: true
essd.tp.rtp: true
essd.tp.back: true
essd.inspect:
default: op
essd.home:
default: true
essd.setwarp:
default: op
essd.delwarp:
default: op
essd.warp:
default: true
commands:
suicide:
description: 自杀
usage: /suicide
permission: essd.suicide
permission-message: 你不被允许自杀,快说“谢谢管理员”。
hat:
description: 将主手持的物品放在头部
usage: /hat
permission: essd.hat
permission-message: 管理员不允许你随便在头上放东西(没权限)。
showItem:
description: 展示主手持的物品
usage: /showitem
permission: essd.showitem
permission-message: 不要什么都想拿出来啊喂!(没权限)
skull:
description: 使用任意头颅交换获得一个自己的头颅
usage: /skull
permission: essd.skull
permission-message: 禁止献祭(没权限)。
god:
description: 无敌模式
usage: /god [player]
permission: essd.god
permission-message: 禁止成仙(没权限)。
fly:
description: 飞行模式
usage: /fly [player]
permission: essd.fly
permission-message: 禁止起飞(没权限)。
day:
description: 设置时间为白天
usage: /day
permission: essd.time
permission-message: 起床失败(没权限)。
noon:
description: 设置时间为中午
usage: /noon
permission: essd.time
permission-message: 午休失败(没权限)。
night:
description: 设置时间为晚上
usage: /night
permission: essd.time
permission-message: 禁止熬夜(没权限)。
save:
description: 保存
usage: /save
permission: essd.save
permission-message: 保存失败(没权限)。
more:
description: 获取更多手持物品
usage: /more [amount]
permission: essd.more
permission-message: more不出来了没权限
sun:
description: 设置天气为晴天
usage: /sun
permission: essd.weather
permission-message: 禁止晒太阳(没权限)。
rain:
description: 设置天气为雨天
usage: /rain
permission: essd.weather
permission-message: 求雨失败(没权限)。
storm:
description: 设置天气为雷雨
usage: /storm
permission: essd.weather
permission-message: (没权限)。
enderchest:
description: 通过指令打开末影箱
usage: /enderchest
permission: essd.enderchest
permission-message: 你没有权限快速打开末影箱。
tpa:
description: 发起传送请求
usage: /tpa <player>
permission: essd.tp.tpa
permission-message: 你没有权限发起传送请求。
tpahere:
description: 发起传送到自己的请求
usage: /tpahere <player>
permission: essd.tp.tpahere
permission-message: 你没有权限发起传送请求。
rtp:
description: 随机传送到附近
usage: /rtp
permission: essd.tp.rtp
permission-message: 你没有权限随机传送。
back:
description: 回到上一个传送点
usage: /back
permission: essd.tp.back
permission-message: 你没有权限回到上一个传送点。
inspect:
description: 检查玩家背包
usage: /inspect <player>
permission: essd.inspect
permission-message: 禁止偷窥(没权限)。
home:
description: 回家
usage: /home [名称]
permission: essd.home
permission-message: 你没有权限使用home。
homes:
description: 查看家列表
usage: /homes
permission: essd.home
permission-message: 你没有权限使用home。
sethome:
description: 设置家
usage: /sethome [名称]
permission: essd.home
permission-message: 你没有权限使用home。
delhome:
description: 删除家
usage: /delhome <名称>
usage: /delhome <名称>
permission: essd.home
permission-message: 你没有权限使用home。
setwarp:
description: 设置传送点
usage: /setwarp <名称>
permission: essd.setwarp
permission-message: 你没有权限设置传送点。
delwarp:
description: 删除传送点
usage: /delwarp <名称>
permission: essd.delwarp
permission-message: 你没有权限删除传送点。
warp:
description: 传送到传送点
usage: /warp <名称>
permission: essd.warp
permission-message: 你没有权限传送到传送点。
warps:
description: 查看传送点列表
usage: /warps
permission: essd.warp
permission-message: 你没有权限查看传送点列表。