Skip to content

Commit

Permalink
Use Paper's kick function for kick command if using Paper. (#2482)
Browse files Browse the repository at this point in the history
* Allow colors/translatables/etc. to be use in kick messages.

* Remove whitespace

* Add default kick reason

* Remove paper support check
  • Loading branch information
BreadcrumbIsTaken committed Jun 4, 2023
1 parent 8fc8b98 commit 4c020a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
Expand Up @@ -328,4 +328,9 @@ public String getText(TextDisplay textDisplay) {
public void setText(TextDisplay textDisplay, String text) {
textDisplay.text(PaperModule.parseFormattedText(text, ChatColor.WHITE));
}

@Override
public void kickPlayer(Player player, String message) {
player.kick(PaperModule.parseFormattedText(message, ChatColor.WHITE));
}
}
@@ -1,12 +1,9 @@
package com.denizenscript.denizen.scripts.commands.player;

import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.utilities.PaperAPITools;
import com.denizenscript.denizencore.scripts.commands.generator.*;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;

import java.util.List;
Expand All @@ -18,6 +15,7 @@ public KickCommand() {
setSyntax("kick [<player>|...] (reason:<text>)");
setRequiredArguments(1, 2);
isProcedural = false;
autoCompile();
}

// <--[command]
Expand Down Expand Up @@ -48,33 +46,11 @@ public KickCommand() {
// - kick <[player]> "reason:Because I can."
// -->

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (arg.matchesPrefix("reason")) {
scriptEntry.addObject("reason", arg.asElement());
}
else if (arg.matchesPrefix("targets", "target", "players")
|| arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
}
}
scriptEntry.defaultObject("reason", new ElementTag("Kicked."));
if (!scriptEntry.hasObject("targets")) {
throw new InvalidArgumentsException("Must specify target(s).");
}
}

@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag reason = scriptEntry.getElement("reason");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("targets", targets), reason);
}
public static void autoExecute(@ArgName("targets") @ArgLinear @ArgSubType(PlayerTag.class) List<PlayerTag> targets,
@ArgName("reason") @ArgPrefixed @ArgDefaultText("Kicked.") String reason) {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
player.getPlayerEntity().kickPlayer(reason.toString());
PaperAPITools.instance.kickPlayer(player.getPlayerEntity(), reason);
}
}
}
Expand Down
Expand Up @@ -174,4 +174,8 @@ public String getText(TextDisplay textDisplay) {
public void setText(TextDisplay textDisplay, String text) {
textDisplay.setText(text);
}

public void kickPlayer(Player player, String message) {
player.kickPlayer(message);
}
}

0 comments on commit 4c020a0

Please sign in to comment.