mirror of
https://github.com/CarmJos/MoeTeleport.git
synced 2024-09-19 21:35:56 +00:00
[1.2.0] 版本更新
- [R] 使用空格代替制表符进行格式化。 - [F] 修复通过 PlugMan 等第三方插件进行重载时插件功能失效的问题。
This commit is contained in:
parent
55a692243d
commit
aa723087d4
2
pom.xml
2
pom.xml
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>moeteleport</artifactId>
|
<artifactId>moeteleport</artifactId>
|
||||||
<version>1.1.1</version>
|
<version>1.2.0</version>
|
||||||
|
|
||||||
<name>MoeTeleport</name>
|
<name>MoeTeleport</name>
|
||||||
<description>喵喵传送,简单的传送、设置家的插件。</description>
|
<description>喵喵传送,简单的传送、设置家的插件。</description>
|
||||||
|
@ -15,11 +15,13 @@ import cc.carm.plugin.moeteleport.manager.ConfigManager;
|
|||||||
import cc.carm.plugin.moeteleport.manager.RequestManager;
|
import cc.carm.plugin.moeteleport.manager.RequestManager;
|
||||||
import cc.carm.plugin.moeteleport.manager.TeleportManager;
|
import cc.carm.plugin.moeteleport.manager.TeleportManager;
|
||||||
import cc.carm.plugin.moeteleport.manager.UserManager;
|
import cc.carm.plugin.moeteleport.manager.UserManager;
|
||||||
|
import cc.carm.plugin.moeteleport.model.UserData;
|
||||||
import cc.carm.plugin.moeteleport.util.ColorParser;
|
import cc.carm.plugin.moeteleport.util.ColorParser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -27,108 +29,114 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
|
|
||||||
private static Main instance;
|
public static boolean debugMode = true;
|
||||||
public static boolean debugMode = true;
|
private static Main instance;
|
||||||
|
private UserManager userManager;
|
||||||
|
private TeleportManager teleportManager;
|
||||||
|
private RequestManager requestManager;
|
||||||
|
|
||||||
private UserManager userManager;
|
/**
|
||||||
private TeleportManager teleportManager;
|
* 注册监听器
|
||||||
private RequestManager requestManager;
|
*
|
||||||
|
* @param listener 监听器
|
||||||
|
*/
|
||||||
|
public static void regListener(Listener listener) {
|
||||||
|
Bukkit.getPluginManager().registerEvents(listener, getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public static void log(String message) {
|
||||||
public void onEnable() {
|
Bukkit.getConsoleSender().sendMessage(ColorParser.parse("[" + getInstance().getName() + "] " + message));
|
||||||
instance = this;
|
}
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
log("加载配置文件...");
|
public static void error(String message) {
|
||||||
ConfigManager.initConfig();
|
log("&4[ERROR] &r" + message);
|
||||||
|
}
|
||||||
|
|
||||||
log("加载用户管理器...");
|
public static void debug(String message) {
|
||||||
this.userManager = new UserManager(this);
|
if (debugMode) {
|
||||||
|
log("&b[DEBUG] &r" + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log("加载请求管理器...");
|
public static Main getInstance() {
|
||||||
this.requestManager = new RequestManager(this);
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
log("注册监听器...");
|
public static void registerCommand(String commandName,
|
||||||
regListener(new UserListener());
|
@NotNull CommandExecutor executor) {
|
||||||
|
registerCommand(commandName, executor, null);
|
||||||
|
}
|
||||||
|
|
||||||
log("注册指令...");
|
public static void registerCommand(String commandName,
|
||||||
registerCommand("back", new BackCommand());
|
@NotNull CommandExecutor executor,
|
||||||
|
@Nullable TabCompleter tabCompleter) {
|
||||||
|
PluginCommand command = Bukkit.getPluginCommand(commandName);
|
||||||
|
if (command == null) return;
|
||||||
|
command.setExecutor(executor);
|
||||||
|
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
||||||
|
}
|
||||||
|
|
||||||
registerCommand("home", new GoHomeCommand(), new HomeNameCompleter());
|
public static UserManager getUserManager() {
|
||||||
registerCommand("delHome", new DelHomeCommand(), new HomeNameCompleter());
|
return Main.getInstance().userManager;
|
||||||
registerCommand("setHome", new SetHomeCommand());
|
}
|
||||||
registerCommand("listHome", new ListHomeCommand());
|
|
||||||
|
|
||||||
registerCommand("tpa", new TpaCommand(), new PlayerNameCompleter());
|
public static RequestManager getRequestManager() {
|
||||||
registerCommand("tpaHere", new TpaCommand(), new PlayerNameCompleter());
|
return Main.getInstance().requestManager;
|
||||||
registerCommand("tpAccept", new TpHandleCommand(), new TpRequestCompleter());
|
}
|
||||||
registerCommand("tpDeny", new TpHandleCommand(), new TpRequestCompleter());
|
|
||||||
|
|
||||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
}
|
log("加载配置文件...");
|
||||||
|
ConfigManager.initConfig();
|
||||||
|
|
||||||
@Override
|
log("加载用户管理器...");
|
||||||
public void onDisable() {
|
this.userManager = new UserManager(this);
|
||||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||||
long startTime = System.currentTimeMillis();
|
log(" 加载现有用户数据...");
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
UserData data = Main.getUserManager().loadData(player.getUniqueId());
|
||||||
|
Main.getUserManager().getUserDataMap().put(player.getUniqueId(), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getRequestManager().shutdown();
|
log("加载请求管理器...");
|
||||||
|
this.requestManager = new RequestManager(this);
|
||||||
|
|
||||||
log("卸载监听器...");
|
log("注册监听器...");
|
||||||
Bukkit.getServicesManager().unregisterAll(this);
|
regListener(new UserListener());
|
||||||
|
|
||||||
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log("注册指令...");
|
||||||
}
|
registerCommand("back", new BackCommand());
|
||||||
|
|
||||||
/**
|
registerCommand("home", new GoHomeCommand(), new HomeNameCompleter());
|
||||||
* 注册监听器
|
registerCommand("delHome", new DelHomeCommand(), new HomeNameCompleter());
|
||||||
*
|
registerCommand("setHome", new SetHomeCommand());
|
||||||
* @param listener 监听器
|
registerCommand("listHome", new ListHomeCommand());
|
||||||
*/
|
|
||||||
public static void regListener(Listener listener) {
|
|
||||||
Bukkit.getPluginManager().registerEvents(listener, getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void log(String message) {
|
registerCommand("tpa", new TpaCommand(), new PlayerNameCompleter());
|
||||||
Bukkit.getConsoleSender().sendMessage(ColorParser.parse("[" + getInstance().getName() + "] " + message));
|
registerCommand("tpaHere", new TpaCommand(), new PlayerNameCompleter());
|
||||||
}
|
registerCommand("tpAccept", new TpHandleCommand(), new TpRequestCompleter());
|
||||||
|
registerCommand("tpDeny", new TpHandleCommand(), new TpRequestCompleter());
|
||||||
|
|
||||||
public static void error(String message) {
|
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
||||||
log("&4[ERROR] &r" + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void debug(String message) {
|
}
|
||||||
if (debugMode) {
|
|
||||||
log("&b[DEBUG] &r" + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Main getInstance() {
|
@Override
|
||||||
return instance;
|
public void onDisable() {
|
||||||
}
|
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
public static void registerCommand(String commandName,
|
getRequestManager().shutdown();
|
||||||
@NotNull CommandExecutor executor) {
|
|
||||||
registerCommand(commandName, executor, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerCommand(String commandName,
|
log("卸载监听器...");
|
||||||
@NotNull CommandExecutor executor,
|
Bukkit.getServicesManager().unregisterAll(this);
|
||||||
@Nullable TabCompleter tabCompleter) {
|
|
||||||
PluginCommand command = Bukkit.getPluginCommand(commandName);
|
|
||||||
if (command == null) return;
|
|
||||||
command.setExecutor(executor);
|
|
||||||
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UserManager getUserManager() {
|
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
||||||
return Main.getInstance().userManager;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static RequestManager getRequestManager() {
|
|
||||||
return Main.getInstance().requestManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class BackCommand implements CommandExecutor {
|
public class BackCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
if (data.getLastLocation() == null) {
|
if (data.getLastLocation() == null) {
|
||||||
PluginMessages.NO_LAST_LOCATION.send(player);
|
PluginMessages.NO_LAST_LOCATION.send(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
TeleportManager.teleport(player, data.getLastLocation(), false);
|
TeleportManager.teleport(player, data.getLastLocation(), false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,17 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class HomeNameCompleter implements TabCompleter {
|
public class HomeNameCompleter implements TabCompleter {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public java.util.List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
public java.util.List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return ImmutableList.of();
|
if (!(sender instanceof Player)) return ImmutableList.of();
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Main.getUserManager().getData((Player) sender).getHomeLocations().keySet().stream()
|
return Main.getUserManager().getData((Player) sender).getHomeLocations().keySet().stream()
|
||||||
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[0]))
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[0]))
|
||||||
.limit(10).collect(Collectors.toList());
|
.limit(10).collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,32 +16,32 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class PlayerNameCompleter implements TabCompleter {
|
public class PlayerNameCompleter implements TabCompleter {
|
||||||
|
|
||||||
List<Integer> indexes;
|
List<Integer> indexes;
|
||||||
|
|
||||||
public PlayerNameCompleter() {
|
public PlayerNameCompleter() {
|
||||||
this(1);
|
this(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerNameCompleter(Integer index) {
|
public PlayerNameCompleter(Integer index) {
|
||||||
this(new Integer[]{index});
|
this(new Integer[]{index});
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerNameCompleter(Integer[] indexes) {
|
public PlayerNameCompleter(Integer[] indexes) {
|
||||||
this.indexes = Arrays.asList(indexes);
|
this.indexes = Arrays.asList(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public java.util.List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
public java.util.List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
if (args.length >= 1 && indexes.contains(args.length)) {
|
if (args.length >= 1 && indexes.contains(args.length)) {
|
||||||
return Bukkit.getOnlinePlayers().stream()
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
.map(HumanEntity::getName)
|
.map(HumanEntity::getName)
|
||||||
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[args.length - 1]))
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[args.length - 1]))
|
||||||
.limit(10).collect(Collectors.toList());
|
.limit(10).collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,34 +20,34 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class TpRequestCompleter implements TabCompleter {
|
public class TpRequestCompleter implements TabCompleter {
|
||||||
|
|
||||||
List<Integer> indexes;
|
List<Integer> indexes;
|
||||||
|
|
||||||
public TpRequestCompleter() {
|
public TpRequestCompleter() {
|
||||||
this(1);
|
this(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TpRequestCompleter(Integer index) {
|
public TpRequestCompleter(Integer index) {
|
||||||
this(new Integer[]{index});
|
this(new Integer[]{index});
|
||||||
}
|
}
|
||||||
|
|
||||||
public TpRequestCompleter(Integer[] indexes) {
|
public TpRequestCompleter(Integer[] indexes) {
|
||||||
this.indexes = Arrays.asList(indexes);
|
this.indexes = Arrays.asList(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return ImmutableList.of();
|
if (!(sender instanceof Player)) return ImmutableList.of();
|
||||||
if (args.length >= 1 && indexes.contains(args.length)) {
|
if (args.length >= 1 && indexes.contains(args.length)) {
|
||||||
UserData data = Main.getUserManager().getData((Player) sender);
|
UserData data = Main.getUserManager().getData((Player) sender);
|
||||||
return data.getReceivedRequests().keySet().stream()
|
return data.getReceivedRequests().keySet().stream()
|
||||||
.map(Bukkit::getPlayer).filter(Objects::nonNull).map(HumanEntity::getName)
|
.map(Bukkit::getPlayer).filter(Objects::nonNull).map(HumanEntity::getName)
|
||||||
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[args.length - 1]))
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, args[args.length - 1]))
|
||||||
.limit(10).collect(Collectors.toList());
|
.limit(10).collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,26 +14,26 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DelHomeCommand implements CommandExecutor {
|
public class DelHomeCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
if (args.length < 1) return false;
|
if (args.length < 1) return false;
|
||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
String homeName = args[0];
|
String homeName = args[0];
|
||||||
Map.Entry<String, DataLocation> locationInfo = data.getHomeLocation(homeName);
|
Map.Entry<String, DataLocation> locationInfo = data.getHomeLocation(homeName);
|
||||||
if (locationInfo == null) {
|
if (locationInfo == null) {
|
||||||
PluginMessages.Home.NOT_FOUND.sendWithPlaceholders(player);
|
PluginMessages.Home.NOT_FOUND.sendWithPlaceholders(player);
|
||||||
} else {
|
} else {
|
||||||
PluginMessages.Home.REMOVED.sendWithPlaceholders(player,
|
PluginMessages.Home.REMOVED.sendWithPlaceholders(player,
|
||||||
new String[]{"%(name)", "%(location)"},
|
new String[]{"%(name)", "%(location)"},
|
||||||
new Object[]{locationInfo.getKey(), locationInfo.getValue().toFlatString()});
|
new Object[]{locationInfo.getKey(), locationInfo.getValue().toFlatString()});
|
||||||
data.delHomeLocation(homeName);
|
data.delHomeLocation(homeName);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -15,21 +15,21 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class GoHomeCommand implements CommandExecutor {
|
public class GoHomeCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
String homeName = args.length >= 1 ? args[0] : null;
|
String homeName = args.length >= 1 ? args[0] : null;
|
||||||
Map.Entry<String, DataLocation> locationInfo = data.getHomeLocation(homeName);
|
Map.Entry<String, DataLocation> locationInfo = data.getHomeLocation(homeName);
|
||||||
if (locationInfo == null) {
|
if (locationInfo == null) {
|
||||||
PluginMessages.Home.NOT_FOUND.sendWithPlaceholders(player);
|
PluginMessages.Home.NOT_FOUND.sendWithPlaceholders(player);
|
||||||
} else {
|
} else {
|
||||||
TeleportManager.teleport(player, locationInfo.getValue(), false);
|
TeleportManager.teleport(player, locationInfo.getValue(), false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -11,19 +11,19 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class ListHomeCommand implements CommandExecutor {
|
public class ListHomeCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
PluginMessages.Home.HEADER.sendWithPlaceholders(player);
|
PluginMessages.Home.HEADER.sendWithPlaceholders(player);
|
||||||
data.getHomeLocations().forEach((name, loc) -> PluginMessages.Home.LIST_OBJECT
|
data.getHomeLocations().forEach((name, loc) -> PluginMessages.Home.LIST_OBJECT
|
||||||
.sendWithPlaceholders(player,
|
.sendWithPlaceholders(player,
|
||||||
new String[]{"%(id)", "%(location)"},
|
new String[]{"%(id)", "%(location)"},
|
||||||
new Object[]{name, loc.toFlatString()}
|
new Object[]{name, loc.toFlatString()}
|
||||||
));
|
));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,28 +11,28 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class SetHomeCommand implements CommandExecutor {
|
public class SetHomeCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
String homeName = args.length >= 1 ? args[0] : "home";
|
String homeName = args.length >= 1 ? args[0] : "home";
|
||||||
|
|
||||||
int maxHome = Main.getUserManager().getMaxHome(player);
|
int maxHome = Main.getUserManager().getMaxHome(player);
|
||||||
if (data.getHomeLocations().size() >= maxHome && data.getHomeLocation(homeName) == null) {
|
if (data.getHomeLocations().size() >= maxHome && data.getHomeLocation(homeName) == null) {
|
||||||
PluginMessages.Home.OVER_LIMIT.sendWithPlaceholders(sender,
|
PluginMessages.Home.OVER_LIMIT.sendWithPlaceholders(sender,
|
||||||
new String[]{"%(max)"}, new Object[]{maxHome}
|
new String[]{"%(max)"}, new Object[]{maxHome}
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setHomeLocation(homeName, player.getLocation());
|
data.setHomeLocation(homeName, player.getLocation());
|
||||||
PluginMessages.Home.SET.sendWithPlaceholders(player,
|
PluginMessages.Home.SET.sendWithPlaceholders(player,
|
||||||
new String[]{"%(name)"}, new Object[]{homeName}
|
new String[]{"%(name)"}, new Object[]{homeName}
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -15,51 +15,51 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
public class TpHandleCommand implements CommandExecutor {
|
public class TpHandleCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
if (data.getReceivedRequests().isEmpty()) {
|
if (data.getReceivedRequests().isEmpty()) {
|
||||||
PluginMessages.Request.NOT_FOUND.sendWithPlaceholders(player);
|
PluginMessages.Request.NOT_FOUND.sendWithPlaceholders(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String targetName = args.length > 0 ? args[0] : null;
|
String targetName = args.length > 0 ? args[0] : null;
|
||||||
boolean accept = command.getName().equalsIgnoreCase("tpAccept");
|
boolean accept = command.getName().equalsIgnoreCase("tpAccept");
|
||||||
data.setEnableAutoSelect(false);
|
data.setEnableAutoSelect(false);
|
||||||
if (targetName != null) {
|
if (targetName != null) {
|
||||||
Player target = Bukkit.getPlayer(targetName);
|
Player target = Bukkit.getPlayer(targetName);
|
||||||
if (target == null || !data.getReceivedRequests().containsKey(target.getUniqueId())) {
|
if (target == null || !data.getReceivedRequests().containsKey(target.getUniqueId())) {
|
||||||
PluginMessages.Request.NOT_FOUND_PLAYER.sendWithPlaceholders(player,
|
PluginMessages.Request.NOT_FOUND_PLAYER.sendWithPlaceholders(player,
|
||||||
new String[]{"%(player)"},
|
new String[]{"%(player)"},
|
||||||
new Object[]{target == null ? targetName : target.getName()}
|
new Object[]{target == null ? targetName : target.getName()}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
handle(data.getReceivedRequests().get(target.getUniqueId()), accept); // 交给Manager处理
|
handle(data.getReceivedRequests().get(target.getUniqueId()), accept); // 交给Manager处理
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (data.getReceivedRequests().size() == 1 || data.isEnableAutoSelect()) {
|
if (data.getReceivedRequests().size() == 1 || data.isEnableAutoSelect()) {
|
||||||
data.getReceivedRequests().values().stream()
|
data.getReceivedRequests().values().stream()
|
||||||
.min(Comparator.comparingLong(TeleportRequest::getActiveTime))
|
.min(Comparator.comparingLong(TeleportRequest::getActiveTime))
|
||||||
.ifPresent(request -> handle(request, accept));
|
.ifPresent(request -> handle(request, accept));
|
||||||
} else {
|
} else {
|
||||||
PluginMessages.Request.MULTI.sendWithPlaceholders(player,
|
PluginMessages.Request.MULTI.sendWithPlaceholders(player,
|
||||||
new String[]{"%(num)", "%(command)"},
|
new String[]{"%(num)", "%(command)"},
|
||||||
new Object[]{data.getReceivedRequests().size(), command.getName()}
|
new Object[]{data.getReceivedRequests().size(), command.getName()}
|
||||||
);
|
);
|
||||||
data.setEnableAutoSelect(true);
|
data.setEnableAutoSelect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handle(TeleportRequest request, boolean accept) {
|
private void handle(TeleportRequest request, boolean accept) {
|
||||||
if (accept) {
|
if (accept) {
|
||||||
Main.getRequestManager().acceptRequest(request);
|
Main.getRequestManager().acceptRequest(request);
|
||||||
} else {
|
} else {
|
||||||
Main.getRequestManager().denyRequest(request);
|
Main.getRequestManager().denyRequest(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,32 +12,32 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class TpaCommand implements CommandExecutor {
|
public class TpaCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
@NotNull String label, @NotNull String[] args) {
|
@NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player) || args.length < 1) return false;
|
if (!(sender instanceof Player) || args.length < 1) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
Player target = Bukkit.getPlayer(args[0]);
|
Player target = Bukkit.getPlayer(args[0]);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
PluginMessages.NOT_ONLINE.sendWithPlaceholders(player);
|
PluginMessages.NOT_ONLINE.sendWithPlaceholders(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TeleportRequest request = Main.getUserManager().getData(target).getReceivedRequests().get(player.getUniqueId());
|
TeleportRequest request = Main.getUserManager().getData(target).getReceivedRequests().get(player.getUniqueId());
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
PluginMessages.Request.DUPLICATE.sendWithPlaceholders(sender,
|
PluginMessages.Request.DUPLICATE.sendWithPlaceholders(sender,
|
||||||
new String[]{"%(player)", "%(expire)"},
|
new String[]{"%(player)", "%(expire)"},
|
||||||
new Object[]{target.getName(), request.getRemainSeconds()}
|
new Object[]{target.getName(), request.getRemainSeconds()}
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (command.getName().equalsIgnoreCase("tpa")) {
|
if (command.getName().equalsIgnoreCase("tpa")) {
|
||||||
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA);
|
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA);
|
||||||
} else {
|
} else {
|
||||||
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA_HERE);
|
Main.getRequestManager().sendRequest(player, target, TeleportRequest.RequestType.TPA_HERE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,24 +6,24 @@ import cc.carm.plugin.moeteleport.configuration.values.ConfigValueMap;
|
|||||||
|
|
||||||
public class PluginConfig {
|
public class PluginConfig {
|
||||||
|
|
||||||
public static final ConfigValueMap<Integer, String> PERMISSIONS = new ConfigValueMap<>(
|
public static final ConfigValueMap<Integer, String> PERMISSIONS = new ConfigValueMap<>(
|
||||||
"permissions", Integer::parseInt, String.class
|
"permissions", Integer::parseInt, String.class
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ConfigValueList<String> DANGEROUS_TYPES = new ConfigValueList<>(
|
public static final ConfigValueList<String> DANGEROUS_TYPES = new ConfigValueList<>(
|
||||||
"dangerous-blocks", String.class, new String[]{"LAVA"}
|
"dangerous-blocks", String.class, new String[]{"LAVA"}
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ConfigValue<Integer> EXPIRE_TIME = new ConfigValue<>(
|
public static final ConfigValue<Integer> EXPIRE_TIME = new ConfigValue<>(
|
||||||
"expireTime", Integer.class, 30
|
"expireTime", Integer.class, 30
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ConfigValue<Integer> DEFAULT_HOME = new ConfigValue<>(
|
public static final ConfigValue<Integer> DEFAULT_HOME = new ConfigValue<>(
|
||||||
"defaultHome", Integer.class, 1
|
"defaultHome", Integer.class, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final ConfigValue<Boolean> DEATH_GO_BACK = new ConfigValue<>(
|
public static final ConfigValue<Boolean> DEATH_GO_BACK = new ConfigValue<>(
|
||||||
"death-back", Boolean.class, true
|
"death-back", Boolean.class, true
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,53 +5,53 @@ import cc.carm.plugin.moeteleport.configuration.message.ConfigMessageList;
|
|||||||
|
|
||||||
public class PluginMessages {
|
public class PluginMessages {
|
||||||
|
|
||||||
public static final ConfigMessageList NO_LAST_LOCATION = new ConfigMessageList("no-last-location");
|
public static final ConfigMessageList NO_LAST_LOCATION = new ConfigMessageList("no-last-location");
|
||||||
|
|
||||||
public static final ConfigMessageList NOT_ONLINE = new ConfigMessageList("not-online");
|
public static final ConfigMessageList NOT_ONLINE = new ConfigMessageList("not-online");
|
||||||
|
|
||||||
public static final ConfigMessageList TPA = new ConfigMessageList("tpa");
|
public static final ConfigMessageList TPA = new ConfigMessageList("tpa");
|
||||||
public static final ConfigMessageList TPA_HERE = new ConfigMessageList("tpahere");
|
public static final ConfigMessageList TPA_HERE = new ConfigMessageList("tpahere");
|
||||||
|
|
||||||
public static final ConfigMessageList TP_ACCEPT = new ConfigMessageList("tpaccept");
|
public static final ConfigMessageList TP_ACCEPT = new ConfigMessageList("tpaccept");
|
||||||
public static final ConfigMessageList TP_DENY = new ConfigMessageList("tpdeny");
|
public static final ConfigMessageList TP_DENY = new ConfigMessageList("tpdeny");
|
||||||
|
|
||||||
public static final ConfigMessageList ACCEPTED = new ConfigMessageList("accepted");
|
public static final ConfigMessageList ACCEPTED = new ConfigMessageList("accepted");
|
||||||
public static final ConfigMessageList DENIED = new ConfigMessageList("denied");
|
public static final ConfigMessageList DENIED = new ConfigMessageList("denied");
|
||||||
|
|
||||||
public static final ConfigMessageList TELEPORTING = new ConfigMessageList("teleporting");
|
public static final ConfigMessageList TELEPORTING = new ConfigMessageList("teleporting");
|
||||||
public static final ConfigMessageList DANGEROUS = new ConfigMessageList("dangerous");
|
public static final ConfigMessageList DANGEROUS = new ConfigMessageList("dangerous");
|
||||||
public static final ConfigMessageList DANGEROUS_HERE = new ConfigMessageList("dangerous-here");
|
public static final ConfigMessageList DANGEROUS_HERE = new ConfigMessageList("dangerous-here");
|
||||||
|
|
||||||
public static final ConfigMessageList NOT_AVAILABLE = new ConfigMessageList("notAvailable");
|
public static final ConfigMessageList NOT_AVAILABLE = new ConfigMessageList("notAvailable");
|
||||||
|
|
||||||
public static final ConfigMessageList DEATH_BACK = new ConfigMessageList("death-back");
|
public static final ConfigMessageList DEATH_BACK = new ConfigMessageList("death-back");
|
||||||
|
|
||||||
public static class Request {
|
public static class Request {
|
||||||
public static final ConfigMessageList DUPLICATE = new ConfigMessageList("request-duplicate");
|
public static final ConfigMessageList DUPLICATE = new ConfigMessageList("request-duplicate");
|
||||||
public static final ConfigMessageList OFFLINE = new ConfigMessageList("offline");
|
public static final ConfigMessageList OFFLINE = new ConfigMessageList("offline");
|
||||||
|
|
||||||
public static final ConfigMessageList SENT = new ConfigMessageList("request-sent");
|
public static final ConfigMessageList SENT = new ConfigMessageList("request-sent");
|
||||||
public static final ConfigMessageList MULTI = new ConfigMessageList("multi-requests");
|
public static final ConfigMessageList MULTI = new ConfigMessageList("multi-requests");
|
||||||
public static final ConfigMessageList SENT_TIMEOUT = new ConfigMessageList("request-sent-timeout");
|
public static final ConfigMessageList SENT_TIMEOUT = new ConfigMessageList("request-sent-timeout");
|
||||||
public static final ConfigMessageList RECEIVED_TIMEOUT = new ConfigMessageList("request-received-timeout");
|
public static final ConfigMessageList RECEIVED_TIMEOUT = new ConfigMessageList("request-received-timeout");
|
||||||
|
|
||||||
public static final ConfigMessageList NOT_FOUND = new ConfigMessageList("no-request");
|
public static final ConfigMessageList NOT_FOUND = new ConfigMessageList("no-request");
|
||||||
public static final ConfigMessageList NOT_FOUND_PLAYER = new ConfigMessageList("no-request-player");
|
public static final ConfigMessageList NOT_FOUND_PLAYER = new ConfigMessageList("no-request-player");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Home {
|
public static class Home {
|
||||||
public static final ConfigMessageList HEADER = new ConfigMessageList("home-list-header");
|
public static final ConfigMessageList HEADER = new ConfigMessageList("home-list-header");
|
||||||
public static final ConfigMessage LIST_OBJECT = new ConfigMessage("home-list-object");
|
public static final ConfigMessage LIST_OBJECT = new ConfigMessage("home-list-object");
|
||||||
|
|
||||||
public static final ConfigMessageList OVER_LIMIT = new ConfigMessageList("home-over-limit");
|
public static final ConfigMessageList OVER_LIMIT = new ConfigMessageList("home-over-limit");
|
||||||
|
|
||||||
|
|
||||||
public static final ConfigMessageList NOT_FOUND = new ConfigMessageList("home-not-found");
|
public static final ConfigMessageList NOT_FOUND = new ConfigMessageList("home-not-found");
|
||||||
public static final ConfigMessageList SET = new ConfigMessageList("home-set");
|
public static final ConfigMessageList SET = new ConfigMessageList("home-set");
|
||||||
|
|
||||||
public static final ConfigMessageList REMOVED = new ConfigMessageList("home-removed");
|
public static final ConfigMessageList REMOVED = new ConfigMessageList("home-removed");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,55 +10,55 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class FileConfig {
|
public class FileConfig {
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
|
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin) {
|
public FileConfig(final JavaPlugin plugin) {
|
||||||
this(plugin, "config.yml");
|
this(plugin, "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin, final String name) {
|
public FileConfig(final JavaPlugin plugin, final String name) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.fileName = name;
|
this.fileName = name;
|
||||||
initFile();
|
initFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFile() {
|
private void initFile() {
|
||||||
this.file = new File(plugin.getDataFolder(), fileName);
|
this.file = new File(plugin.getDataFolder(), fileName);
|
||||||
if (!this.file.exists()) {
|
if (!this.file.exists()) {
|
||||||
if (!this.file.getParentFile().exists()) {
|
if (!this.file.getParentFile().exists()) {
|
||||||
boolean success = this.file.getParentFile().mkdirs();
|
boolean success = this.file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
plugin.saveResource(fileName, true);
|
plugin.saveResource(fileName, true);
|
||||||
}
|
}
|
||||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
getConfig().save(getFile());
|
getConfig().save(getFile());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
if (getFile().exists()) {
|
if (getFile().exists()) {
|
||||||
this.config = YamlConfiguration.loadConfiguration(getFile());
|
this.config = YamlConfiguration.loadConfiguration(getFile());
|
||||||
} else {
|
} else {
|
||||||
initFile();
|
initFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,160 +13,158 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class DataLocation implements Cloneable {
|
public class DataLocation implements Cloneable {
|
||||||
|
|
||||||
public static final DecimalFormat format = new DecimalFormat("0.00");
|
public static final DecimalFormat format = new DecimalFormat("0.00");
|
||||||
private String worldName;
|
private final String worldName;
|
||||||
private double x;
|
private double x;
|
||||||
private double y;
|
private double y;
|
||||||
private double z;
|
private double z;
|
||||||
private float yaw;
|
private float yaw;
|
||||||
private float pitch;
|
private float pitch;
|
||||||
|
|
||||||
public DataLocation(Location location) {
|
public DataLocation(Location location) {
|
||||||
this(location.getWorld() != null ? location.getWorld().getName() : "", location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
this(location.getWorld() != null ? location.getWorld().getName() : "", location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataLocation(final String worldName, final double x, final double y, final double z) {
|
public DataLocation(final String worldName, final double x, final double y, final double z) {
|
||||||
this(worldName, x, y, z, 0, 0);
|
this(worldName, x, y, z, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
public DataLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorldName() {
|
public static DataLocation deserializeText(String s) {
|
||||||
return worldName;
|
if (s == null || !s.contains(";")) return null;
|
||||||
}
|
String[] args = StringUtils.split(s, ";");
|
||||||
|
if (args.length < 4) return null;
|
||||||
|
try {
|
||||||
|
String worldName = args[0];
|
||||||
|
double x = NumberConversions.toDouble(args[1]);
|
||||||
|
double y = NumberConversions.toDouble(args[2]);
|
||||||
|
double z = NumberConversions.toDouble(args[3]);
|
||||||
|
float yaw = 0;
|
||||||
|
float pitch = 0;
|
||||||
|
if (args.length == 6) {
|
||||||
|
yaw = NumberConversions.toFloat(args[4]);
|
||||||
|
pitch = NumberConversions.toFloat(args[5]);
|
||||||
|
}
|
||||||
|
return new DataLocation(worldName, x, y, z, yaw, pitch);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public double getX() {
|
@Deprecated
|
||||||
return x;
|
public static DataLocation parseString(String s) {
|
||||||
}
|
return deserializeText(s);
|
||||||
|
}
|
||||||
|
|
||||||
public void setX(double x) {
|
public String getWorldName() {
|
||||||
this.x = x;
|
return worldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getY() {
|
public double getX() {
|
||||||
return y;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setY(double y) {
|
public void setX(double x) {
|
||||||
this.y = y;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getZ() {
|
public double getY() {
|
||||||
return z;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZ(double z) {
|
public void setY(double y) {
|
||||||
this.z = z;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getYaw() {
|
public double getZ() {
|
||||||
return yaw;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setYaw(float yaw) {
|
public void setZ(double z) {
|
||||||
this.yaw = yaw;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPitch() {
|
public float getYaw() {
|
||||||
return pitch;
|
return yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPitch(float pitch) {
|
public void setYaw(float yaw) {
|
||||||
this.pitch = pitch;
|
this.yaw = yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getPitch() {
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull Location getBukkitLocation(World world) {
|
public void setPitch(float pitch) {
|
||||||
return new Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Location getBukkitLocation(World world) {
|
||||||
|
return new Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable Location getBukkitLocation() {
|
public @Nullable Location getBukkitLocation() {
|
||||||
World world = Bukkit.getWorld(getWorldName());
|
World world = Bukkit.getWorld(getWorldName());
|
||||||
if (world == null) return null;
|
if (world == null) return null;
|
||||||
else return new Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
else return new Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
try {
|
try {
|
||||||
return super.clone();
|
return super.clone();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof DataLocation)) return false;
|
if (!(o instanceof DataLocation)) return false;
|
||||||
DataLocation that = (DataLocation) o;
|
DataLocation that = (DataLocation) o;
|
||||||
return that.worldName.equals(worldName)
|
return that.worldName.equals(worldName)
|
||||||
&& Double.compare(that.x, x) == 0
|
&& Double.compare(that.x, x) == 0
|
||||||
&& Double.compare(that.y, y) == 0
|
&& Double.compare(that.y, y) == 0
|
||||||
&& Double.compare(that.z, z) == 0
|
&& Double.compare(that.z, z) == 0
|
||||||
&& Float.compare(that.pitch, pitch) == 0
|
&& Float.compare(that.pitch, pitch) == 0
|
||||||
&& Float.compare(that.yaw, yaw) == 0;
|
&& Float.compare(that.yaw, yaw) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(x, y, z, yaw, pitch);
|
return Objects.hash(x, y, z, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return worldName + " " + x + " " + y + " " + z + " " + yaw + " " + pitch;
|
return worldName + " " + x + " " + y + " " + z + " " + yaw + " " + pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFlatString() {
|
public String toFlatString() {
|
||||||
return worldName + "@" + format.format(x) + ", " + format.format(y) + ", " + format.format(z);
|
return worldName + "@" + format.format(x) + ", " + format.format(y) + ", " + format.format(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String toSerializedString() {
|
public String toSerializedString() {
|
||||||
return serializeToText();
|
return serializeToText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String serializeToText() {
|
public String serializeToText() {
|
||||||
if (getYaw() != 0 || getPitch() != 0) {
|
if (getYaw() != 0 || getPitch() != 0) {
|
||||||
return worldName + ";" + x + ";" + y + ";" + z + ";" + yaw + ";" + pitch;
|
return worldName + ";" + x + ";" + y + ";" + z + ";" + yaw + ";" + pitch;
|
||||||
} else {
|
} else {
|
||||||
return worldName + ";" + x + ";" + y + ";" + z;
|
return worldName + ";" + x + ";" + y + ";" + z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataLocation deserializeText(String s) {
|
|
||||||
if (s == null || !s.contains(";")) return null;
|
|
||||||
String[] args = StringUtils.split(s, ";");
|
|
||||||
if (args.length < 4) return null;
|
|
||||||
try {
|
|
||||||
String worldName = args[0];
|
|
||||||
double x = NumberConversions.toDouble(args[1]);
|
|
||||||
double y = NumberConversions.toDouble(args[2]);
|
|
||||||
double z = NumberConversions.toDouble(args[3]);
|
|
||||||
float yaw = 0;
|
|
||||||
float pitch = 0;
|
|
||||||
if (args.length == 6) {
|
|
||||||
yaw = NumberConversions.toFloat(args[4]);
|
|
||||||
pitch = NumberConversions.toFloat(args[5]);
|
|
||||||
}
|
|
||||||
return new DataLocation(worldName, x, y, z, yaw, pitch);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static DataLocation parseString(String s) {
|
|
||||||
return deserializeText(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -9,24 +9,24 @@ import java.util.Collections;
|
|||||||
|
|
||||||
public class ConfigMessage extends ConfigValue<String> {
|
public class ConfigMessage extends ConfigValue<String> {
|
||||||
|
|
||||||
public ConfigMessage(String configSection) {
|
public ConfigMessage(String configSection) {
|
||||||
this(configSection, null);
|
this(configSection, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(String configSection, String defaultValue) {
|
public ConfigMessage(String configSection, String defaultValue) {
|
||||||
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
MessageUtil.send(sender, get());
|
MessageUtil.send(sender, get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendWithPlaceholders(CommandSender sender) {
|
public void sendWithPlaceholders(CommandSender sender) {
|
||||||
MessageUtil.sendWithPlaceholders(sender, get());
|
MessageUtil.sendWithPlaceholders(sender, get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendWithPlaceholders(CommandSender sender, String[] params, Object[] values) {
|
public void sendWithPlaceholders(CommandSender sender, String[] params, Object[] values) {
|
||||||
MessageUtil.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
MessageUtil.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,23 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class ConfigMessageList extends ConfigValueList<String> {
|
public class ConfigMessageList extends ConfigValueList<String> {
|
||||||
|
|
||||||
public ConfigMessageList(String configSection) {
|
public ConfigMessageList(String configSection) {
|
||||||
super(ConfigManager.getMessageConfig(), configSection, String.class);
|
super(ConfigManager.getMessageConfig(), configSection, String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(String configSection, String[] defaultValue) {
|
public ConfigMessageList(String configSection, String[] defaultValue) {
|
||||||
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender) {
|
public void send(@Nullable CommandSender sender) {
|
||||||
MessageUtil.send(sender, get());
|
MessageUtil.send(sender, get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendWithPlaceholders(@Nullable CommandSender sender) {
|
public void sendWithPlaceholders(@Nullable CommandSender sender) {
|
||||||
MessageUtil.sendWithPlaceholders(sender, get());
|
MessageUtil.sendWithPlaceholders(sender, get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendWithPlaceholders(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public void sendWithPlaceholders(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||||
MessageUtil.sendWithPlaceholders(sender, get(), params, values);
|
MessageUtil.sendWithPlaceholders(sender, get(), params, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,63 +9,63 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigValueList<V> {
|
public class ConfigValueList<V> {
|
||||||
FileConfig source;
|
FileConfig source;
|
||||||
String configSection;
|
String configSection;
|
||||||
Class<V> clazz;
|
Class<V> clazz;
|
||||||
|
|
||||||
V[] defaultValue;
|
V[] defaultValue;
|
||||||
|
|
||||||
public ConfigValueList(String configSection, Class<V> clazz) {
|
public ConfigValueList(String configSection, Class<V> clazz) {
|
||||||
this(ConfigManager.getPluginConfig(), configSection, clazz);
|
this(ConfigManager.getPluginConfig(), configSection, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(String configSection, Class<V> clazz, V[] defaultValue) {
|
public ConfigValueList(String configSection, Class<V> clazz, V[] defaultValue) {
|
||||||
this(ConfigManager.getPluginConfig(), configSection, clazz, defaultValue);
|
this(ConfigManager.getPluginConfig(), configSection, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz) {
|
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz) {
|
||||||
this(configuration, configSection, clazz, null);
|
this(configuration, configSection, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz, V[] defaultValue) {
|
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz, V[] defaultValue) {
|
||||||
this.source = configuration;
|
this.source = configuration;
|
||||||
this.configSection = configSection;
|
this.configSection = configSection;
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfiguration() {
|
public FileConfiguration getConfiguration() {
|
||||||
return this.source.getConfig();
|
return this.source.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<V> get() {
|
public ArrayList<V> get() {
|
||||||
List<?> list = getConfiguration().getList(this.configSection);
|
List<?> list = getConfiguration().getList(this.configSection);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
return new ArrayList<>(Arrays.asList(defaultValue));
|
return new ArrayList<>(Arrays.asList(defaultValue));
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ArrayList<V> result = new ArrayList<>();
|
ArrayList<V> result = new ArrayList<>();
|
||||||
|
|
||||||
for (Object object : list) {
|
for (Object object : list) {
|
||||||
if (this.clazz.isInstance(object)) {
|
if (this.clazz.isInstance(object)) {
|
||||||
result.add(this.clazz.cast(object));
|
result.add(this.clazz.cast(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(ArrayList<V> value) {
|
public void set(ArrayList<V> value) {
|
||||||
getConfiguration().set(this.configSection, value);
|
getConfiguration().set(this.configSection, value);
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
this.source.save();
|
this.source.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,66 +14,66 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class ConfigValueMap<K, V> {
|
public class ConfigValueMap<K, V> {
|
||||||
|
|
||||||
@NotNull FileConfig source;
|
@NotNull FileConfig source;
|
||||||
@NotNull String configSection;
|
@NotNull String configSection;
|
||||||
|
|
||||||
@NotNull Function<String, K> keyCast;
|
@NotNull Function<String, K> keyCast;
|
||||||
@NotNull Class<V> valueClazz;
|
@NotNull Class<V> valueClazz;
|
||||||
|
|
||||||
@Nullable LinkedHashMap<K, V> valueCache;
|
@Nullable LinkedHashMap<K, V> valueCache;
|
||||||
|
|
||||||
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
||||||
@NotNull Class<V> valueClazz) {
|
@NotNull Class<V> valueClazz) {
|
||||||
this(ConfigManager.getPluginConfig(), configSection, keyCast, valueClazz);
|
this(ConfigManager.getPluginConfig(), configSection, keyCast, valueClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueMap(@NotNull FileConfig configuration, @NotNull String configSection,
|
public ConfigValueMap(@NotNull FileConfig configuration, @NotNull String configSection,
|
||||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||||
this.source = configuration;
|
this.source = configuration;
|
||||||
this.configSection = configSection;
|
this.configSection = configSection;
|
||||||
this.keyCast = keyCast;
|
this.keyCast = keyCast;
|
||||||
this.valueClazz = valueClazz;
|
this.valueClazz = valueClazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public @NotNull FileConfiguration getConfiguration() {
|
public @NotNull FileConfiguration getConfiguration() {
|
||||||
return this.source.getConfig();
|
return this.source.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
this.valueCache = null;
|
this.valueCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Map<K, V> get() {
|
public Map<K, V> get() {
|
||||||
if (valueCache != null) return valueCache;
|
if (valueCache != null) return valueCache;
|
||||||
ConfigurationSection section = getConfiguration().getConfigurationSection(this.configSection);
|
ConfigurationSection section = getConfiguration().getConfigurationSection(this.configSection);
|
||||||
if (section == null) return new LinkedHashMap<>();
|
if (section == null) return new LinkedHashMap<>();
|
||||||
Set<String> keys = section.getKeys(false);
|
Set<String> keys = section.getKeys(false);
|
||||||
if (keys.isEmpty()) return new LinkedHashMap<>();
|
if (keys.isEmpty()) return new LinkedHashMap<>();
|
||||||
else {
|
else {
|
||||||
LinkedHashMap<K, V> result = new LinkedHashMap<>();
|
LinkedHashMap<K, V> result = new LinkedHashMap<>();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
K finalKey = keyCast.apply(key);
|
K finalKey = keyCast.apply(key);
|
||||||
Object val = section.get(key);
|
Object val = section.get(key);
|
||||||
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
||||||
if (finalKey != null && finalValue != null) {
|
if (finalKey != null && finalValue != null) {
|
||||||
result.put(finalKey, finalValue);
|
result.put(finalKey, finalValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.valueCache = result;
|
this.valueCache = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(LinkedHashMap<K, V> valuesMap) {
|
public void set(LinkedHashMap<K, V> valuesMap) {
|
||||||
this.valueCache = valuesMap;
|
this.valueCache = valuesMap;
|
||||||
getConfiguration().createSection(this.configSection, valuesMap);
|
getConfiguration().createSection(this.configSection, valuesMap);
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
this.source.save();
|
this.source.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,28 +15,28 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class UserListener implements Listener {
|
public class UserListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
UserData data = Main.getUserManager().loadData(uuid);
|
UserData data = Main.getUserManager().loadData(uuid);
|
||||||
Main.getUserManager().getUserDataMap().put(uuid, data);
|
Main.getUserManager().getUserDataMap().put(uuid, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerQuitEvent event) {
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Main.getRequestManager().cancelAllRequests(player);
|
Main.getRequestManager().cancelAllRequests(player);
|
||||||
Main.getUserManager().getData(player).save(); //保存
|
Main.getUserManager().getData(player).save(); //保存
|
||||||
Main.getUserManager().getUserDataMap().remove(player.getUniqueId());
|
Main.getUserManager().getUserDataMap().remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(PlayerDeathEvent event) {
|
public void onDeath(PlayerDeathEvent event) {
|
||||||
if (PluginConfig.DEATH_GO_BACK.get()) {
|
if (PluginConfig.DEATH_GO_BACK.get()) {
|
||||||
Player player = event.getEntity();
|
Player player = event.getEntity();
|
||||||
Main.getUserManager().getData(player).setLastLocation(player.getLocation());
|
Main.getUserManager().getData(player).setLastLocation(player.getLocation());
|
||||||
PluginMessages.DEATH_BACK.send(player);
|
PluginMessages.DEATH_BACK.send(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,32 +6,32 @@ import cc.carm.plugin.moeteleport.configuration.file.FileConfig;
|
|||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
|
|
||||||
private static FileConfig config;
|
private static FileConfig config;
|
||||||
private static FileConfig messageConfig;
|
private static FileConfig messageConfig;
|
||||||
|
|
||||||
public static void initConfig() {
|
public static void initConfig() {
|
||||||
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
||||||
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "messages.yml");
|
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "messages.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileConfig getPluginConfig() {
|
public static FileConfig getPluginConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileConfig getMessageConfig() {
|
public static FileConfig getMessageConfig() {
|
||||||
return messageConfig;
|
return messageConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
getPluginConfig().reload();
|
getPluginConfig().reload();
|
||||||
getMessageConfig().reload();
|
getMessageConfig().reload();
|
||||||
PluginConfig.PERMISSIONS.clearCache();
|
PluginConfig.PERMISSIONS.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveConfig() {
|
public static void saveConfig() {
|
||||||
getPluginConfig().save();
|
getPluginConfig().save();
|
||||||
getMessageConfig().save();
|
getMessageConfig().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,127 +14,127 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class RequestManager {
|
public class RequestManager {
|
||||||
|
|
||||||
public BukkitRunnable checkRunnable;
|
public BukkitRunnable checkRunnable;
|
||||||
|
|
||||||
public RequestManager(Main main) {
|
public RequestManager(Main main) {
|
||||||
this.checkRunnable = new BukkitRunnable() {
|
this.checkRunnable = new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
checkRequests();
|
checkRequests();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.checkRunnable.runTaskTimerAsynchronously(main, 100L, 20L);
|
this.checkRunnable.runTaskTimerAsynchronously(main, 100L, 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (!this.checkRunnable.isCancelled()) {
|
if (!this.checkRunnable.isCancelled()) {
|
||||||
this.checkRunnable.cancel();
|
this.checkRunnable.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkRequests() {
|
public void checkRequests() {
|
||||||
Main.getUserManager().getUserDataMap().values()
|
Main.getUserManager().getUserDataMap().values()
|
||||||
.forEach(data -> data.getReceivedRequests().entrySet().stream()
|
.forEach(data -> data.getReceivedRequests().entrySet().stream()
|
||||||
.filter(entry -> entry.getValue().isExpired())
|
.filter(entry -> entry.getValue().isExpired())
|
||||||
.peek(entry -> PluginMessages.Request.SENT_TIMEOUT.sendWithPlaceholders(
|
.peek(entry -> PluginMessages.Request.SENT_TIMEOUT.sendWithPlaceholders(
|
||||||
entry.getValue().getSender(), new String[]{"%(player)"},
|
entry.getValue().getSender(), new String[]{"%(player)"},
|
||||||
new Object[]{entry.getValue().getReceiver().getName()}))
|
new Object[]{entry.getValue().getReceiver().getName()}))
|
||||||
.peek(entry -> PluginMessages.Request.RECEIVED_TIMEOUT.sendWithPlaceholders(
|
.peek(entry -> PluginMessages.Request.RECEIVED_TIMEOUT.sendWithPlaceholders(
|
||||||
entry.getValue().getReceiver(), new String[]{"%(player)"},
|
entry.getValue().getReceiver(), new String[]{"%(player)"},
|
||||||
new Object[]{entry.getValue().getSender().getName()}))
|
new Object[]{entry.getValue().getSender().getName()}))
|
||||||
.peek(entry -> Main.getUserManager()
|
.peek(entry -> Main.getUserManager()
|
||||||
.getData(entry.getValue().getSender()).getSentRequests()
|
.getData(entry.getValue().getSender()).getSentRequests()
|
||||||
.remove(entry.getKey()))
|
.remove(entry.getKey()))
|
||||||
.forEach(entry -> data.getReceivedRequests().remove(entry.getKey()))
|
.forEach(entry -> data.getReceivedRequests().remove(entry.getKey()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRequest(Player sender, Player receiver, TeleportRequest.RequestType type) {
|
public void sendRequest(Player sender, Player receiver, TeleportRequest.RequestType type) {
|
||||||
int expireTime = PluginConfig.EXPIRE_TIME.get();
|
int expireTime = PluginConfig.EXPIRE_TIME.get();
|
||||||
|
|
||||||
PluginMessages.Request.SENT.sendWithPlaceholders(sender,
|
PluginMessages.Request.SENT.sendWithPlaceholders(sender,
|
||||||
new String[]{"%(player)", "%(expire)"},
|
new String[]{"%(player)", "%(expire)"},
|
||||||
new Object[]{receiver.getName(), expireTime}
|
new Object[]{receiver.getName(), expireTime}
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TPA: {
|
case TPA: {
|
||||||
PluginMessages.TPA.sendWithPlaceholders(receiver,
|
PluginMessages.TPA.sendWithPlaceholders(receiver,
|
||||||
new String[]{"%(player)", "%(expire)"},
|
new String[]{"%(player)", "%(expire)"},
|
||||||
new Object[]{sender.getName(), expireTime}
|
new Object[]{sender.getName(), expireTime}
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TPA_HERE: {
|
case TPA_HERE: {
|
||||||
PluginMessages.TPA_HERE.sendWithPlaceholders(receiver,
|
PluginMessages.TPA_HERE.sendWithPlaceholders(receiver,
|
||||||
new String[]{"%(player)", "%(expire)"},
|
new String[]{"%(player)", "%(expire)"},
|
||||||
new Object[]{sender.getName(), expireTime}
|
new Object[]{sender.getName(), expireTime}
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TeleportRequest request = new TeleportRequest(sender, receiver, type);
|
TeleportRequest request = new TeleportRequest(sender, receiver, type);
|
||||||
Main.getUserManager().getData(receiver).getReceivedRequests().put(sender.getUniqueId(), request);
|
Main.getUserManager().getData(receiver).getReceivedRequests().put(sender.getUniqueId(), request);
|
||||||
Main.getUserManager().getData(sender).getSentRequests().add(receiver.getUniqueId());
|
Main.getUserManager().getData(sender).getSentRequests().add(receiver.getUniqueId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptRequest(TeleportRequest request) {
|
public void acceptRequest(TeleportRequest request) {
|
||||||
PluginMessages.ACCEPTED.sendWithPlaceholders(request.getSender(),
|
PluginMessages.ACCEPTED.sendWithPlaceholders(request.getSender(),
|
||||||
new String[]{"%(player)"},
|
new String[]{"%(player)"},
|
||||||
new Object[]{request.getReceiver().getName()}
|
new Object[]{request.getReceiver().getName()}
|
||||||
);
|
);
|
||||||
PluginMessages.TP_ACCEPT.sendWithPlaceholders(request.getReceiver(),
|
PluginMessages.TP_ACCEPT.sendWithPlaceholders(request.getReceiver(),
|
||||||
new String[]{"%(player)"},
|
new String[]{"%(player)"},
|
||||||
new Object[]{request.getSender().getName()}
|
new Object[]{request.getSender().getName()}
|
||||||
);
|
);
|
||||||
TeleportManager.teleport(request.getTeleportPlayer(), request.getTeleportLocation(), true);
|
TeleportManager.teleport(request.getTeleportPlayer(), request.getTeleportLocation(), true);
|
||||||
removeRequests(request);
|
removeRequests(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void denyRequest(TeleportRequest request) {
|
public void denyRequest(TeleportRequest request) {
|
||||||
PluginMessages.DENIED.sendWithPlaceholders(request.getSender(),
|
PluginMessages.DENIED.sendWithPlaceholders(request.getSender(),
|
||||||
new String[]{"%(player)"},
|
new String[]{"%(player)"},
|
||||||
new Object[]{request.getReceiver().getName()}
|
new Object[]{request.getReceiver().getName()}
|
||||||
);
|
);
|
||||||
PluginMessages.TP_DENY.sendWithPlaceholders(request.getReceiver(),
|
PluginMessages.TP_DENY.sendWithPlaceholders(request.getReceiver(),
|
||||||
new String[]{"%(player)"},
|
new String[]{"%(player)"},
|
||||||
new Object[]{request.getSender().getName()}
|
new Object[]{request.getSender().getName()}
|
||||||
);
|
);
|
||||||
removeRequests(request);
|
removeRequests(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRequests(TeleportRequest request) {
|
public void removeRequests(TeleportRequest request) {
|
||||||
Main.getUserManager().getData(request.getSender())
|
Main.getUserManager().getData(request.getSender())
|
||||||
.getSentRequests()
|
.getSentRequests()
|
||||||
.remove(request.getReceiver().getUniqueId());
|
.remove(request.getReceiver().getUniqueId());
|
||||||
Main.getUserManager().getData(request.getReceiver())
|
Main.getUserManager().getData(request.getReceiver())
|
||||||
.getReceivedRequests()
|
.getReceivedRequests()
|
||||||
.remove(request.getSender().getUniqueId());
|
.remove(request.getSender().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelAllRequests(Player player) {
|
public void cancelAllRequests(Player player) {
|
||||||
UUID playerUUID = player.getUniqueId();
|
UUID playerUUID = player.getUniqueId();
|
||||||
UserData data = Main.getUserManager().getData(player);
|
UserData data = Main.getUserManager().getData(player);
|
||||||
data.getReceivedRequests().keySet().stream()
|
data.getReceivedRequests().keySet().stream()
|
||||||
.peek(senderUUID -> PluginMessages.Request.OFFLINE.sendWithPlaceholders(
|
.peek(senderUUID -> PluginMessages.Request.OFFLINE.sendWithPlaceholders(
|
||||||
Bukkit.getPlayer(senderUUID),
|
Bukkit.getPlayer(senderUUID),
|
||||||
new String[]{"%(player)"}, new Object[]{player.getName()}
|
new String[]{"%(player)"}, new Object[]{player.getName()}
|
||||||
)).map(senderUUID -> Main.getUserManager().getData(senderUUID))
|
)).map(senderUUID -> Main.getUserManager().getData(senderUUID))
|
||||||
.filter(Objects::nonNull).map(UserData::getSentRequests)
|
.filter(Objects::nonNull).map(UserData::getSentRequests)
|
||||||
.forEach(receivers -> receivers.remove(playerUUID));
|
.forEach(receivers -> receivers.remove(playerUUID));
|
||||||
|
|
||||||
data.getSentRequests().stream()
|
data.getSentRequests().stream()
|
||||||
.peek(receiverUUID -> PluginMessages.Request.OFFLINE.sendWithPlaceholders(
|
.peek(receiverUUID -> PluginMessages.Request.OFFLINE.sendWithPlaceholders(
|
||||||
Bukkit.getPlayer(receiverUUID),
|
Bukkit.getPlayer(receiverUUID),
|
||||||
new String[]{"%(player)"}, new Object[]{player.getName()}
|
new String[]{"%(player)"}, new Object[]{player.getName()}
|
||||||
)).map(receiverUUID -> Main.getUserManager().getData(receiverUUID))
|
)).map(receiverUUID -> Main.getUserManager().getData(receiverUUID))
|
||||||
.filter(Objects::nonNull).map(UserData::getReceivedRequests)
|
.filter(Objects::nonNull).map(UserData::getReceivedRequests)
|
||||||
.forEach(senders -> senders.remove(playerUUID));
|
.forEach(senders -> senders.remove(playerUUID));
|
||||||
|
|
||||||
data.getSentRequests().clear();
|
data.getSentRequests().clear();
|
||||||
data.getReceivedRequests().clear();
|
data.getReceivedRequests().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,51 +11,51 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class TeleportManager {
|
public class TeleportManager {
|
||||||
|
|
||||||
public static void teleport(Player player, DataLocation targetLocation, boolean onlySafety) {
|
public static void teleport(Player player, DataLocation targetLocation, boolean onlySafety) {
|
||||||
Location location = targetLocation.getBukkitLocation();
|
Location location = targetLocation.getBukkitLocation();
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
|
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
|
||||||
new String[]{"%(location)"},
|
new String[]{"%(location)"},
|
||||||
new Object[]{targetLocation.toFlatString()}
|
new Object[]{targetLocation.toFlatString()}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
teleport(player, location, onlySafety);
|
teleport(player, location, onlySafety);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void teleport(Player player, Location targetLocation, boolean onlySafety) {
|
public static void teleport(Player player, Location targetLocation, boolean onlySafety) {
|
||||||
if (targetLocation.isWorldLoaded()) {
|
if (targetLocation.isWorldLoaded()) {
|
||||||
if (!onlySafety || TeleportManager.isSafeLocation(targetLocation)) {
|
if (!onlySafety || TeleportManager.isSafeLocation(targetLocation)) {
|
||||||
Main.getUserManager().getData(player).setLastLocation(player.getLocation());
|
Main.getUserManager().getData(player).setLastLocation(player.getLocation());
|
||||||
player.teleport(targetLocation);
|
player.teleport(targetLocation);
|
||||||
PluginMessages.TELEPORTING.sendWithPlaceholders(player,
|
PluginMessages.TELEPORTING.sendWithPlaceholders(player,
|
||||||
new String[]{"%(location)"},
|
new String[]{"%(location)"},
|
||||||
new Object[]{new DataLocation(targetLocation).toFlatString()}
|
new Object[]{new DataLocation(targetLocation).toFlatString()}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
PluginMessages.DANGEROUS.send(player);
|
PluginMessages.DANGEROUS.send(player);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
|
PluginMessages.NOT_AVAILABLE.sendWithPlaceholders(player,
|
||||||
new String[]{"%(location)"},
|
new String[]{"%(location)"},
|
||||||
new Object[]{new DataLocation(targetLocation).toFlatString()}
|
new Object[]{new DataLocation(targetLocation).toFlatString()}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSafeLocation(Location location) {
|
public static boolean isSafeLocation(Location location) {
|
||||||
Block leg = location.getBlock();
|
Block leg = location.getBlock();
|
||||||
if (!leg.getType().isAir()) {
|
if (!leg.getType().isAir()) {
|
||||||
return false; // not transparent (will suffocate)
|
return false; // not transparent (will suffocate)
|
||||||
}
|
}
|
||||||
Block head = leg.getRelative(BlockFace.UP);
|
Block head = leg.getRelative(BlockFace.UP);
|
||||||
if (!head.getType().isAir()) {
|
if (!head.getType().isAir()) {
|
||||||
return false; // not transparent (will suffocate)
|
return false; // not transparent (will suffocate)
|
||||||
}
|
}
|
||||||
Block ground = leg.getRelative(BlockFace.DOWN);
|
Block ground = leg.getRelative(BlockFace.DOWN);
|
||||||
return ground.getType().isSolid()
|
return ground.getType().isSolid()
|
||||||
&& !PluginConfig.DANGEROUS_TYPES.get().contains(ground.getType().name());
|
&& !PluginConfig.DANGEROUS_TYPES.get().contains(ground.getType().name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,51 +14,51 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class UserManager {
|
public class UserManager {
|
||||||
|
|
||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
|
|
||||||
private final HashMap<UUID, UserData> userDataMap = new HashMap<>();
|
private final HashMap<UUID, UserData> userDataMap = new HashMap<>();
|
||||||
|
|
||||||
public UserManager(Main main) {
|
public UserManager(Main main) {
|
||||||
this.dataFolder = new File(main.getDataFolder() + "/data");
|
this.dataFolder = new File(main.getDataFolder() + "/data");
|
||||||
if (!dataFolder.isDirectory() || !dataFolder.exists()) {
|
if (!dataFolder.isDirectory() || !dataFolder.exists()) {
|
||||||
boolean success = dataFolder.mkdir();
|
boolean success = dataFolder.mkdir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public UserData loadData(UUID userUUID) {
|
public UserData loadData(UUID userUUID) {
|
||||||
return new UserData(getDataFolder(), userUUID);
|
return new UserData(getDataFolder(), userUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public UserData getData(UUID userUUID) {
|
public UserData getData(UUID userUUID) {
|
||||||
return getUserDataMap().get(userUUID);
|
return getUserDataMap().get(userUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public UserData getData(Player player) {
|
public UserData getData(Player player) {
|
||||||
return getUserDataMap().get(player.getUniqueId());
|
return getUserDataMap().get(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxHome(Player player) {
|
public int getMaxHome(Player player) {
|
||||||
Map<Integer, String> permissions = PluginConfig.PERMISSIONS.get();
|
Map<Integer, String> permissions = PluginConfig.PERMISSIONS.get();
|
||||||
int current = PluginConfig.DEFAULT_HOME.get();
|
int current = PluginConfig.DEFAULT_HOME.get();
|
||||||
|
|
||||||
for (Map.Entry<Integer, String> entry : permissions.entrySet()) {
|
for (Map.Entry<Integer, String> entry : permissions.entrySet()) {
|
||||||
if (entry.getKey() > current && player.hasPermission(
|
if (entry.getKey() > current && player.hasPermission(
|
||||||
Main.getInstance().getName() + "." + entry.getValue()
|
Main.getInstance().getName() + "." + entry.getValue()
|
||||||
)) {
|
)) {
|
||||||
current = entry.getKey();
|
current = entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<UUID, UserData> getUserDataMap() {
|
public HashMap<UUID, UserData> getUserDataMap() {
|
||||||
return userDataMap;
|
return userDataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getDataFolder() {
|
public File getDataFolder() {
|
||||||
return dataFolder;
|
return dataFolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,65 +7,65 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class TeleportRequest {
|
public class TeleportRequest {
|
||||||
|
|
||||||
final @NotNull Player sender;
|
final @NotNull Player sender;
|
||||||
final @NotNull Player receiver;
|
final @NotNull Player receiver;
|
||||||
final @NotNull RequestType type;
|
final @NotNull RequestType type;
|
||||||
|
|
||||||
final long createTime;
|
final long createTime;
|
||||||
|
|
||||||
public TeleportRequest(@NotNull Player sender,
|
public TeleportRequest(@NotNull Player sender,
|
||||||
@NotNull Player receiver,
|
@NotNull Player receiver,
|
||||||
@NotNull RequestType type) {
|
@NotNull RequestType type) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.createTime = System.currentTimeMillis();
|
this.createTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Player getSender() {
|
public @NotNull Player getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Player getReceiver() {
|
public @NotNull Player getReceiver() {
|
||||||
return receiver;
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Player getTeleportPlayer() {
|
public @NotNull Player getTeleportPlayer() {
|
||||||
return getType() == RequestType.TPA ? getSender() : getReceiver();
|
return getType() == RequestType.TPA ? getSender() : getReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Location getTeleportLocation() {
|
public @NotNull Location getTeleportLocation() {
|
||||||
return getType() == RequestType.TPA_HERE ? getSender().getLocation() : getReceiver().getLocation();
|
return getType() == RequestType.TPA_HERE ? getSender().getLocation() : getReceiver().getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull RequestType getType() {
|
public @NotNull RequestType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCreateTime() {
|
public long getCreateTime() {
|
||||||
return createTime;
|
return createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getActiveTime() {
|
public long getActiveTime() {
|
||||||
return System.currentTimeMillis() - getCreateTime();
|
return System.currentTimeMillis() - getCreateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getRemainTime() {
|
public long getRemainTime() {
|
||||||
return PluginConfig.EXPIRE_TIME.get() * 1000 - getActiveTime();
|
return PluginConfig.EXPIRE_TIME.get() * 1000 - getActiveTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getRemainSeconds() {
|
public long getRemainSeconds() {
|
||||||
return getRemainTime() / 1000;
|
return getRemainTime() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return getActiveTime() > PluginConfig.EXPIRE_TIME.get() * 1000;
|
return getActiveTime() > PluginConfig.EXPIRE_TIME.get() * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RequestType {
|
public enum RequestType {
|
||||||
TPA,
|
TPA,
|
||||||
TPA_HERE
|
TPA_HERE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,122 +15,118 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public class UserData {
|
public class UserData {
|
||||||
|
|
||||||
private final @NotNull File dataFile;
|
private final @NotNull File dataFile;
|
||||||
private final @NotNull FileConfiguration dataConfig;
|
private final @NotNull FileConfiguration dataConfig;
|
||||||
|
private final HashSet<UUID/*receiverUUID*/> sentRequests = new HashSet<>(); // 记录发出的请求
|
||||||
|
private final ConcurrentHashMap<UUID/*senderUUID*/, TeleportRequest> receivedRequests = new ConcurrentHashMap<>(); // 记录收到的传送请求
|
||||||
|
public boolean enableAutoSelect = false;
|
||||||
|
private @Nullable Location lastLocation;
|
||||||
|
private LinkedHashMap<String, DataLocation> homeLocations;
|
||||||
|
|
||||||
private @Nullable Location lastLocation;
|
public UserData(@NotNull File dataFolder, @NotNull UUID uuid) {
|
||||||
|
this(new File(dataFolder, uuid + ".yml"));
|
||||||
|
}
|
||||||
|
|
||||||
private LinkedHashMap<String, DataLocation> homeLocations;
|
public UserData(@NotNull File file) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
try {
|
||||||
|
boolean success = file.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Main.error("在加载用户 " + file.getName() + " 的数据时出现异常。");
|
||||||
|
Main.error(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dataFile = file;
|
||||||
|
this.dataConfig = YamlConfiguration.loadConfiguration(dataFile);
|
||||||
|
loadHomeData();
|
||||||
|
}
|
||||||
|
|
||||||
private final HashSet<UUID/*receiverUUID*/> sentRequests = new HashSet<>(); // 记录发出的请求
|
public void loadHomeData() {
|
||||||
private final ConcurrentHashMap<UUID/*senderUUID*/, TeleportRequest> receivedRequests = new ConcurrentHashMap<>(); // 记录收到的传送请求
|
LinkedHashMap<String, DataLocation> data = new LinkedHashMap<>();
|
||||||
|
Optional.ofNullable(getDataConfig().getConfigurationSection("homes"))
|
||||||
|
.ifPresent(section -> section.getKeys(false).forEach(homeName -> {
|
||||||
|
DataLocation location = DataLocation.deserializeText(section.getString(homeName));
|
||||||
|
if (location != null) data.put(homeName, location);
|
||||||
|
}));
|
||||||
|
this.homeLocations = data;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean enableAutoSelect = false;
|
public LinkedHashMap<String, DataLocation> getHomeLocations() {
|
||||||
|
return homeLocations;
|
||||||
|
}
|
||||||
|
|
||||||
public UserData(@NotNull File dataFolder, @NotNull UUID uuid) {
|
public void setHomeLocation(String homeName, Location location) {
|
||||||
this(new File(dataFolder, uuid + ".yml"));
|
delHomeLocation(homeName);
|
||||||
}
|
getHomeLocations().put(homeName, new DataLocation(location));
|
||||||
|
}
|
||||||
|
|
||||||
public UserData(@NotNull File file) {
|
public void delHomeLocation(String homeName) {
|
||||||
if (!file.exists()) {
|
Map.Entry<String, DataLocation> lastLocation = getHomeLocation(homeName);
|
||||||
try {
|
if (lastLocation != null) getHomeLocations().remove(lastLocation.getKey());
|
||||||
boolean success = file.createNewFile();
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
Main.error("在加载用户 " + file.getName() + " 的数据时出现异常。");
|
|
||||||
Main.error(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.dataFile = file;
|
|
||||||
this.dataConfig = YamlConfiguration.loadConfiguration(dataFile);
|
|
||||||
loadHomeData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadHomeData() {
|
public Map.Entry<String, DataLocation> getHomeLocation(@Nullable String homeName) {
|
||||||
LinkedHashMap<String, DataLocation> data = new LinkedHashMap<>();
|
LinkedHashMap<String, DataLocation> homes = getHomeLocations();
|
||||||
Optional.ofNullable(getDataConfig().getConfigurationSection("homes"))
|
if (homeName == null) {
|
||||||
.ifPresent(section -> section.getKeys(false).forEach(homeName -> {
|
if (homes.containsKey("home")) {
|
||||||
DataLocation location = DataLocation.deserializeText(section.getString(homeName));
|
return new AbstractMap.SimpleEntry<>("home", homes.get("home"));
|
||||||
if (location != null) data.put(homeName, location);
|
} else {
|
||||||
}));
|
return homes.entrySet().stream().findFirst().orElse(null);
|
||||||
this.homeLocations = data;
|
}
|
||||||
}
|
} else {
|
||||||
|
return homes.entrySet().stream()
|
||||||
|
.filter(entry -> entry.getKey().equalsIgnoreCase(homeName))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LinkedHashMap<String, DataLocation> getHomeLocations() {
|
public @Nullable Location getLastLocation() {
|
||||||
return homeLocations;
|
return lastLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHomeLocation(String homeName, Location location) {
|
public void setLastLocation(@Nullable Location lastLocation) {
|
||||||
delHomeLocation(homeName);
|
this.lastLocation = lastLocation;
|
||||||
getHomeLocations().put(homeName, new DataLocation(location));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void delHomeLocation(String homeName) {
|
public HashSet<UUID> getSentRequests() {
|
||||||
Map.Entry<String, DataLocation> lastLocation = getHomeLocation(homeName);
|
return sentRequests;
|
||||||
if (lastLocation != null) getHomeLocations().remove(lastLocation.getKey());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Map.Entry<String, DataLocation> getHomeLocation(@Nullable String homeName) {
|
public ConcurrentHashMap<UUID, TeleportRequest> getReceivedRequests() {
|
||||||
LinkedHashMap<String, DataLocation> homes = getHomeLocations();
|
return receivedRequests;
|
||||||
if (homeName == null) {
|
}
|
||||||
if (homes.containsKey("home")) {
|
|
||||||
return new AbstractMap.SimpleEntry<>("home", homes.get("home"));
|
|
||||||
} else {
|
|
||||||
return homes.entrySet().stream().findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return homes.entrySet().stream()
|
|
||||||
.filter(entry -> entry.getKey().equalsIgnoreCase(homeName))
|
|
||||||
.findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable Location getLastLocation() {
|
public boolean isEnableAutoSelect() {
|
||||||
return lastLocation;
|
return enableAutoSelect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastLocation(@Nullable Location lastLocation) {
|
public void setEnableAutoSelect(boolean enableAutoSelect) {
|
||||||
this.lastLocation = lastLocation;
|
this.enableAutoSelect = enableAutoSelect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<UUID> getSentRequests() {
|
public @NotNull File getDataFile() {
|
||||||
return sentRequests;
|
return dataFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentHashMap<UUID, TeleportRequest> getReceivedRequests() {
|
public @NotNull FileConfiguration getDataConfig() {
|
||||||
return receivedRequests;
|
return dataConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnableAutoSelect(boolean enableAutoSelect) {
|
public LinkedHashMap<String, String> saveToMap() {
|
||||||
this.enableAutoSelect = enableAutoSelect;
|
LinkedHashMap<String, DataLocation> homeLocations = getHomeLocations();
|
||||||
}
|
LinkedHashMap<String, String> data = new LinkedHashMap<>();
|
||||||
|
if (homeLocations.isEmpty()) return data;
|
||||||
|
homeLocations.forEach((name, loc) -> data.put(name, loc.serializeToText()));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnableAutoSelect() {
|
public void save() {
|
||||||
return enableAutoSelect;
|
try {
|
||||||
}
|
getDataConfig().createSection("homes", saveToMap());
|
||||||
|
getDataConfig().save(getDataFile());
|
||||||
public @NotNull File getDataFile() {
|
} catch (Exception ex) {
|
||||||
return dataFile;
|
Main.error("在保存 " + getDataFile().getName() + " 时出现异常。");
|
||||||
}
|
Main.error(ex.getLocalizedMessage());
|
||||||
|
}
|
||||||
public @NotNull FileConfiguration getDataConfig() {
|
}
|
||||||
return dataConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedHashMap<String, String> saveToMap() {
|
|
||||||
LinkedHashMap<String, DataLocation> homeLocations = getHomeLocations();
|
|
||||||
LinkedHashMap<String, String> data = new LinkedHashMap<>();
|
|
||||||
if (homeLocations.isEmpty()) return data;
|
|
||||||
homeLocations.forEach((name, loc) -> data.put(name, loc.serializeToText()));
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
try {
|
|
||||||
getDataConfig().createSection("homes", saveToMap());
|
|
||||||
getDataConfig().save(getDataFile());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Main.error("在保存 " + getDataFile().getName() + " 时出现异常。");
|
|
||||||
Main.error(ex.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package cc.carm.plugin.moeteleport.util;
|
package cc.carm.plugin.moeteleport.util;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -7,8 +6,7 @@ import java.util.regex.Pattern;
|
|||||||
public class ColorParser {
|
public class ColorParser {
|
||||||
|
|
||||||
public static String parse(String text) {
|
public static String parse(String text) {
|
||||||
text = parseHexColor(text);
|
return parseColor(parseHexColor(text));
|
||||||
return parseColor(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseColor(final String text) {
|
public static String parseColor(final String text) {
|
||||||
|
@ -10,67 +10,67 @@ import java.util.*;
|
|||||||
|
|
||||||
public class MessageUtil {
|
public class MessageUtil {
|
||||||
|
|
||||||
public static boolean hasPlaceholderAPI() {
|
public static boolean hasPlaceholderAPI() {
|
||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
for (String s : messages) {
|
for (String s : messages) {
|
||||||
sender.sendMessage(ColorParser.parse(s));
|
sender.sendMessage(ColorParser.parse(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, String... messages) {
|
public static void send(@Nullable CommandSender sender, String... messages) {
|
||||||
send(sender, Arrays.asList(messages));
|
send(sender, Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages));
|
send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages));
|
||||||
} else {
|
} else {
|
||||||
send(sender, messages);
|
send(sender, messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
|
||||||
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
||||||
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
|
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
|
||||||
if (params.length != values.length) return messages;
|
if (params.length != values.length) return messages;
|
||||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
paramsMap.put(params[i], values[i]);
|
paramsMap.put(params[i], values[i]);
|
||||||
}
|
}
|
||||||
return setCustomParams(messages, paramsMap);
|
return setCustomParams(messages, paramsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
for (String message : messages) {
|
for (String message : messages) {
|
||||||
String afterMessage = message;
|
String afterMessage = message;
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||||
}
|
}
|
||||||
list.add(afterMessage);
|
list.add(afterMessage);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user