From 72c0be8ac627fcf9e9608812394a701d13ec8379 Mon Sep 17 00:00:00 2001 From: Cube Date: Sun, 4 Jun 2017 19:56:51 +0300 Subject: [PATCH] Convert punishment commands to Kotlin --- .../org/apollo/game/model/entity/Player.java | 17 ++++++ game/src/plugins/cmd/meta.toml | 1 + .../src/plugins/cmd/src/punish-cmd.plugin.kts | 60 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 game/src/plugins/cmd/src/punish-cmd.plugin.kts diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 2a323b10..76c06db9 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -28,6 +28,7 @@ import org.apollo.game.model.entity.attr.AttributeDefinition; import org.apollo.game.model.entity.attr.AttributeMap; import org.apollo.game.model.entity.attr.AttributePersistence; import org.apollo.game.model.entity.attr.NumericalAttribute; +import org.apollo.game.model.entity.attr.BooleanAttribute; import org.apollo.game.model.entity.obj.DynamicGameObject; import org.apollo.game.model.entity.setting.MembershipStatus; import org.apollo.game.model.entity.setting.PrivacyState; @@ -943,6 +944,22 @@ public final class Player extends Mob { this.withdrawingNotes = withdrawingNotes; } + /** + * Ban the player. + */ + public void ban() { + attributes.set("banned", new BooleanAttribute(true)); + } + + /** + * Sets the mute status of a player. + * + * @param muted Whether the player is muted. + */ + public void setMuted(boolean muted) { + attributes.set("muted", new BooleanAttribute(muted)); + } + @Override public void shout(String message, boolean chatOnly) { blockSet.add(SynchronizationBlock.createForceChatBlock(chatOnly ? message : '~' + message)); diff --git a/game/src/plugins/cmd/meta.toml b/game/src/plugins/cmd/meta.toml index 84ece10b..7a255f39 100644 --- a/game/src/plugins/cmd/meta.toml +++ b/game/src/plugins/cmd/meta.toml @@ -4,6 +4,7 @@ dependencies = [ "command_utilities" ] authors = [ "Graham", "Major", + "lare96", "cubeee" ] diff --git a/game/src/plugins/cmd/src/punish-cmd.plugin.kts b/game/src/plugins/cmd/src/punish-cmd.plugin.kts new file mode 100644 index 00000000..619d4674 --- /dev/null +++ b/game/src/plugins/cmd/src/punish-cmd.plugin.kts @@ -0,0 +1,60 @@ + +import org.apollo.game.model.entity.Player +import org.apollo.game.model.entity.setting.PrivilegeLevel + +/** + * Adds a command to mute a player. Admins cannot be muted. + */ +on_command("mute", PrivilegeLevel.MODERATOR) + .then { player -> + val name = arguments.joinToString(" ") + val targetPlayer = player.world.getPlayer(name) + + if (validate(player, targetPlayer)) { + targetPlayer.isMuted = true + player.sendMessage("You have just unmuted ${targetPlayer.username}.") + } + } + +/** + * Adds a command to unmute a player. + */ +on_command("unmute", PrivilegeLevel.MODERATOR) + .then { player -> + val name = arguments.joinToString(" ") + val targetPlayer = player.world.getPlayer(name) + + if (validate(player, targetPlayer)) { + targetPlayer.isMuted = false + player.sendMessage("You have just unmuted ${targetPlayer.username}.") + } + } + +/** + * Adds a command to ban a player. Admins cannot be banned. + */ +on_command("ban", PrivilegeLevel.ADMINISTRATOR) + .then { player -> + val name = arguments.joinToString(" ") + val targetPlayer = player.world.getPlayer(name) + + if (validate(player, targetPlayer)) { + targetPlayer.ban() + targetPlayer.logout() // TODO force logout + player.sendMessage("You have just banned ${targetPlayer.username}.") + } + } + +/** + * Ensures the player isn't null, and that they aren't an Administrator. + */ +fun validate(player: Player, targetPlayer: Player?): Boolean { + if (targetPlayer == null) { + player.sendMessage("That player does not exist.") + return false + } else if (targetPlayer.privilegeLevel == PrivilegeLevel.ADMINISTRATOR) { + player.sendMessage("You cannot perform this action on Administrators.") + return false + } + return true +} \ No newline at end of file