mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-05 11:57:14 +01:00
fix console commands, run parse command in world thread
This commit is contained in:
@@ -35,6 +35,7 @@ import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.command.system.*;
|
||||
import com.hypixel.hytale.server.core.command.system.CommandSender;
|
||||
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
import com.hypixel.hytale.server.core.universe.world.World;
|
||||
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
|
||||
@@ -42,7 +43,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
public final class PlaceholderCommandRouter extends AbstractCommand {
|
||||
|
||||
@Unmodifiable
|
||||
private static final List<PlaceholderCommand> COMMANDS = List.of(new CommandHelp(),
|
||||
@@ -84,10 +85,16 @@ public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// @NotNull
|
||||
// public CompletableFuture<Void> acceptCall(@NotNull final CommandSender sender, @NotNull final ParserContext parserContext,
|
||||
// @NotNull final ParseResult parseResult) {
|
||||
// @NotNull final ParseResult parseResult) {
|
||||
//// if (sender instanceof Player || sender instanceof PlayerRef) {
|
||||
//// return CompletableFuture.completedFuture(null);
|
||||
//// }
|
||||
//
|
||||
// final String[] args = parserContext.getInputString().replace("papi ", "").split(" ");
|
||||
//
|
||||
// if (args.length == 0) {
|
||||
@@ -124,7 +131,7 @@ public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull final CommandContext context, @NotNull final Store<EntityStore> var2, @NotNull final Ref<EntityStore> var3, @NotNull final PlayerRef var4, @NotNull final World var5) {
|
||||
protected @Nullable CompletableFuture<Void> execute(@NotNull final CommandContext context) {
|
||||
final String[] args = context.getInputString().replace("papi ", "").split(" ");
|
||||
final CommandSender sender = context.sender();
|
||||
|
||||
@@ -134,7 +141,7 @@ public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
fallback.evaluate(plugin, sender, "", Collections.emptyList());
|
||||
}
|
||||
|
||||
return;
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
final String search = args[0].toLowerCase(Locale.ROOT);
|
||||
@@ -144,7 +151,7 @@ public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
sender.sendMessage(Message.raw("Unknown command ").color(Color.RED).insert(Message.raw(search).color(Color.GRAY)));
|
||||
|
||||
// Msg.msg(sender, "&cUnknown command &7" + search);
|
||||
return;
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
final String permission = target.getPermission();
|
||||
@@ -152,15 +159,53 @@ public final class PlaceholderCommandRouter extends AbstractPlayerCommand {
|
||||
sender.sendMessage(Message.raw("You do not have permission to do this!").color(Color.RED));
|
||||
|
||||
// Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
return;
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
target
|
||||
.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
|
||||
|
||||
return;
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void execute(@NotNull final CommandContext context, @NotNull final Store<EntityStore> var2, @NotNull final Ref<EntityStore> var3, @NotNull final PlayerRef var4, @NotNull final World var5) {
|
||||
// final String[] args = context.getInputString().replace("papi ", "").split(" ");
|
||||
// final CommandSender sender = context.sender();
|
||||
//
|
||||
// if (args.length == 0) {
|
||||
// final PlaceholderCommand fallback = commands.get("version");
|
||||
// if (fallback != null) {
|
||||
// fallback.evaluate(plugin, sender, "", Collections.emptyList());
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final String search = args[0].toLowerCase(Locale.ROOT);
|
||||
// final PlaceholderCommand target = commands.get(search);
|
||||
//
|
||||
// if (target == null) {
|
||||
// sender.sendMessage(Message.raw("Unknown command ").color(Color.RED).insert(Message.raw(search).color(Color.GRAY)));
|
||||
//
|
||||
//// Msg.msg(sender, "&cUnknown command &7" + search);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final String permission = target.getPermission();
|
||||
// if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) {
|
||||
// sender.sendMessage(Message.raw("You do not have permission to do this!").color(Color.RED));
|
||||
//
|
||||
//// Msg.msg(sender, "&cYou do not have permission to do this!");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// target
|
||||
// .evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
// @Override
|
||||
// @Nullable
|
||||
|
||||
@@ -51,19 +51,38 @@ public final class CommandParse extends PlaceholderCommand {
|
||||
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
|
||||
@NotNull final CommandSender sender, @NotNull final String alias,
|
||||
@NotNull @Unmodifiable final List<String> params) {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
evaluateParseRelation(sender, params);
|
||||
break;
|
||||
case "parse":
|
||||
evaluateParseSingular(sender, params, false, false);
|
||||
break;
|
||||
case "bcparse":
|
||||
evaluateParseSingular(sender, params, true, false);
|
||||
break;
|
||||
case "cmdparse":
|
||||
evaluateParseSingular(sender, params, false, true);
|
||||
break;
|
||||
final Runnable logic = () -> {
|
||||
switch (alias.toLowerCase(Locale.ROOT)) {
|
||||
case "parserel":
|
||||
evaluateParseRelation(sender, params);
|
||||
break;
|
||||
case "parse":
|
||||
evaluateParseSingular(sender, params, false, false);
|
||||
break;
|
||||
case "bcparse":
|
||||
evaluateParseSingular(sender, params, true, false);
|
||||
break;
|
||||
case "cmdparse":
|
||||
evaluateParseSingular(sender, params, false, true);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
final World world;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
world = ((Player) sender).getWorld();
|
||||
} else if (sender instanceof PlayerRef) {
|
||||
UUID uuid = ((PlayerRef) sender).getWorldUuid();
|
||||
world = uuid == null ? Universe.get().getDefaultWorld() : Universe.get().getWorld(uuid);
|
||||
} else {
|
||||
world = Universe.get().getDefaultWorld();
|
||||
}
|
||||
|
||||
if (world != null) {
|
||||
world.execute(logic);
|
||||
} else {
|
||||
logic.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user