mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Fix various things and it now works
This commit is contained in:
1 parent
982f78f75c
commit
a768171e32
4 files changed
+57
-42
No files matched your search
@@ -79,7 +79,9 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
<additionalJOption>-Xdoclint:none</additionalJOption>
|
<additionalJOption>-Xdoclint:none</additionalJOption>
|
||||||
<staleDataPath>${project.build.directory}/javadoc-bundle-options/maven-javadoc-plugin-stale-data.txt</staleDataPath>
|
<staleDataPath>
|
||||||
|
${project.build.directory}/javadoc-bundle-options/maven-javadoc-plugin-stale-data.txt
|
||||||
|
</staleDataPath>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
// Fetch spawn location if set
|
// Fetch spawn location if set
|
||||||
SettingHandler.fetchSpawnLocation();
|
SettingHandler.fetchSpawnLocation();
|
||||||
|
|
||||||
// Setup the map integration with the correct plugin
|
// Set up the map integration with the correct plugin
|
||||||
if (HuskHomes.getSettings().doMapIntegration()) {
|
if (HuskHomes.getSettings().doMapIntegration()) {
|
||||||
String mapPlugin = HuskHomes.getSettings().getMapPlugin();
|
String mapPlugin = HuskHomes.getSettings().getMapPlugin();
|
||||||
switch (mapPlugin) {
|
switch (mapPlugin) {
|
||||||
|
|||||||
@@ -44,32 +44,37 @@ public class TpCommand extends CommandBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
TpCommandInputHandler.HandlerResponse response = null;
|
||||||
for (TpCommandInputHandler inputHandler : inputHandlers) {
|
for (TpCommandInputHandler inputHandler : inputHandlers) {
|
||||||
switch (inputHandler.handleInput(args, sender)) {
|
response = inputHandler.handleInput(args, sender);
|
||||||
|
switch (response) {
|
||||||
case CAN_HANDLE -> {
|
case CAN_HANDLE -> {
|
||||||
inputHandler.executeTeleport(sender);
|
inputHandler.executeTeleport(sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case CANNOT_HANDLE_BY_CONSOLE -> {
|
|
||||||
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_syntax",
|
|
||||||
getClosestUsage(true, args))).toComponent());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case CANNOT_HANDLE_INVALID_WORLD -> {
|
|
||||||
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_world")).toComponent());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case CANNOT_HANDLE_INVALID_PLAYER -> {
|
|
||||||
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_player")).toComponent());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case CANNOT_HANDLE_HANDLED_BY_TP_HERE -> {
|
case CANNOT_HANDLE_HANDLED_BY_TP_HERE -> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert response != null;
|
||||||
|
switch (response) {
|
||||||
|
case CANNOT_HANDLE_BY_CONSOLE -> {
|
||||||
|
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_syntax",
|
||||||
|
"/tp " + getClosestUsage(true, sender, args))).toComponent());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case CANNOT_HANDLE_INVALID_WORLD -> {
|
||||||
|
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_tp_invalid_world")).toComponent());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case CANNOT_HANDLE_INVALID_PLAYER -> {
|
||||||
|
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_player")).toComponent());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_syntax",
|
sender.spigot().sendMessage(new MineDown(MessageManager.getRawMessage("error_invalid_syntax",
|
||||||
getClosestUsage((!(sender instanceof Player)), args))).toComponent());
|
"/tp " + getClosestUsage((!(sender instanceof Player)), sender, args))).toComponent());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +86,7 @@ public class TpCommand extends CommandBase {
|
|||||||
public static class Tab implements TabCompleter {
|
public static class Tab implements TabCompleter {
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||||
String[] closestArgs = getClosestArgs(false, args);
|
String[] closestArgs = getClosestArgs(false, sender, args);
|
||||||
final int currentArgIndex = Math.max(args.length - 1, 0);
|
final int currentArgIndex = Math.max(args.length - 1, 0);
|
||||||
if (currentArgIndex >= closestArgs.length) {
|
if (currentArgIndex >= closestArgs.length) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -123,25 +128,28 @@ public class TpCommand extends CommandBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getClosestUsage(boolean filterOnlyConsoleExecutable, String... inputArgs) {
|
public static String getClosestUsage(boolean filterOnlyConsoleExecutable, CommandSender sender, String... inputArgs) {
|
||||||
StringJoiner joiner = new StringJoiner(" ");
|
StringJoiner joiner = new StringJoiner(" ");
|
||||||
for (String argument : getClosestArgs(filterOnlyConsoleExecutable, inputArgs)) {
|
for (String argument : getClosestArgs(filterOnlyConsoleExecutable, sender, inputArgs)) {
|
||||||
joiner.add(argument);
|
joiner.add(argument);
|
||||||
}
|
}
|
||||||
return joiner.toString();
|
return joiner.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getClosestArgs(boolean filterOnlyConsoleExecutable, String... inputArgs) {
|
public static String[] getClosestArgs(boolean filterOnlyConsoleExecutable, CommandSender sender, String... inputArgs) {
|
||||||
String[] closestArgs = new String[]{"<target/coordinates>"};
|
String[] closestArgs = new String[]{"<target/coordinates>"};
|
||||||
int lengthDifference = Integer.MAX_VALUE;
|
int difference = Integer.MAX_VALUE;
|
||||||
for (TpCommandInputHandler handler : inputHandlers) {
|
for (TpCommandInputHandler handler : inputHandlers) {
|
||||||
if (filterOnlyConsoleExecutable) {
|
if (filterOnlyConsoleExecutable) {
|
||||||
if (!handler.consoleExecutable) {
|
if (!handler.consoleExecutable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int argLengthDifference = inputArgs.length - handler.arguments.length;
|
int argLengthDifference = handler.arguments.length - inputArgs.length;
|
||||||
if (argLengthDifference < lengthDifference) {
|
if (argLengthDifference < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (argLengthDifference < difference) {
|
||||||
closestArgs = handler.arguments;
|
closestArgs = handler.arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,26 +183,31 @@ public class TpCommand extends CommandBase {
|
|||||||
return HandlerResponse.CANNOT_HANDLE_BY_CONSOLE;
|
return HandlerResponse.CANNOT_HANDLE_BY_CONSOLE;
|
||||||
}
|
}
|
||||||
if (inputArguments.length == arguments.length) {
|
if (inputArguments.length == arguments.length) {
|
||||||
int argumentIndex = 0;
|
return getHandleable(inputArguments, inputExecutor);
|
||||||
for (String inputArgument : inputArguments) {
|
|
||||||
final HandlerResponse argumentResponse = handleArg(inputArgument, argumentIndex, inputExecutor);
|
|
||||||
if (argumentResponse != HandlerResponse.CAN_HANDLE) {
|
|
||||||
return argumentResponse;
|
|
||||||
}
|
|
||||||
argumentIndex++;
|
|
||||||
}
|
|
||||||
if (player == null) {
|
|
||||||
if (inputExecutor instanceof Player commandDispatcher) {
|
|
||||||
player = commandDispatcher;
|
|
||||||
} else {
|
|
||||||
return HandlerResponse.CANNOT_HANDLE_BY_CONSOLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HandlerResponse.CAN_HANDLE;
|
|
||||||
}
|
}
|
||||||
return HandlerResponse.CANNOT_HANDLE_SYNTAX_LENGTH_MISMATCH;
|
return HandlerResponse.CANNOT_HANDLE_SYNTAX_LENGTH_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HandlerResponse getHandleable(String[] inputArguments, CommandSender inputExecutor) {
|
||||||
|
int argumentIndex = 0;
|
||||||
|
for (String inputArgument : inputArguments) {
|
||||||
|
if (argumentIndex >= arguments.length) break;
|
||||||
|
final HandlerResponse argumentResponse = handleArg(inputArgument, argumentIndex, inputExecutor);
|
||||||
|
if (argumentResponse != HandlerResponse.CAN_HANDLE) {
|
||||||
|
return argumentResponse;
|
||||||
|
}
|
||||||
|
argumentIndex++;
|
||||||
|
}
|
||||||
|
if (player == null) {
|
||||||
|
if (inputExecutor instanceof Player commandDispatcher) {
|
||||||
|
player = commandDispatcher;
|
||||||
|
} else {
|
||||||
|
return HandlerResponse.CANNOT_HANDLE_BY_CONSOLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HandlerResponse.CAN_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
public void executeTeleport(CommandSender sender) {
|
public void executeTeleport(CommandSender sender) {
|
||||||
// Handle teleportation to a target player
|
// Handle teleportation to a target player
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
@@ -219,7 +232,7 @@ public class TpCommand extends CommandBase {
|
|||||||
(z != null ? z : player.getLocation().getZ()),
|
(z != null ? z : player.getLocation().getZ()),
|
||||||
(yaw != null ? yaw : player.getLocation().getYaw()),
|
(yaw != null ? yaw : player.getLocation().getYaw()),
|
||||||
(pitch != null ? pitch : player.getLocation().getPitch()),
|
(pitch != null ? pitch : player.getLocation().getPitch()),
|
||||||
serverId != null || !HuskHomes.getSettings().doBungee() ? serverId : HuskHomes.getSettings().getServerID());
|
serverId != null || HuskHomes.getSettings().doBungee() ? serverId : HuskHomes.getSettings().getServerID());
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
TeleportManager.teleportPlayer(player, teleportationPoint);
|
TeleportManager.teleportPlayer(player, teleportationPoint);
|
||||||
if (sender instanceof Player sendingPlayer) {
|
if (sender instanceof Player sendingPlayer) {
|
||||||
|
|||||||
@@ -156,6 +156,6 @@ public class TeleportationPoint {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return x + ", " + y + ", " + z + " (" + worldName + (HuskHomes.getSettings().getServerID().equalsIgnoreCase(server) ? "/" + server : "") + ")";
|
return x + ", " + y + ", " + z + " (" + worldName + (HuskHomes.getSettings().doBungee() ? "/" + server : "") + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user