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