mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>punishment</id>
|
||||
<version>1</version>
|
||||
<name>Punishment commands</name>
|
||||
<description>Adds various punishment commands, such as banning or muting a player.</description>
|
||||
<authors>
|
||||
<author>lare96</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>punish.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
@@ -0,0 +1,53 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
# Adds a command to mute a player. Admins cannot be muted.
|
||||
on :command, :mute, RIGHTS_MOD do |player, command|
|
||||
name = command.arguments.to_a.join(' ')
|
||||
on_player = $world.get_player(name)
|
||||
|
||||
if validate(player, on_player)
|
||||
on_player.muted = true
|
||||
on_player.send_message('You have just been muted.')
|
||||
player.send_message("You have just muted #{on_player.get_username}.")
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a command to unmute a player.
|
||||
on :command, :unmute, RIGHTS_MOD do |player, command|
|
||||
name = command.arguments.to_a.join(' ')
|
||||
on_player = $world.get_player(name)
|
||||
|
||||
if validate(player, on_player)
|
||||
on_player.muted = false
|
||||
on_player.send_message('You are no longer muted.')
|
||||
player.send_message("You have just unmuted #{on_player.get_username}.")
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a command to ban a player. Admins cannot be banned.
|
||||
on :command, :ban, RIGHTS_ADMIN do |player, command|
|
||||
name = command.arguments.to_a.join(' ')
|
||||
on_player = $world.get_player(name)
|
||||
|
||||
if validate(player, on_player)
|
||||
on_player.banned = true
|
||||
on_player.logout # TODO force logout
|
||||
player.send_message("You have just banned #{on_player.get_username}.")
|
||||
end
|
||||
end
|
||||
|
||||
# Ensures the player isn't nil, and that they aren't an Administrator.
|
||||
def validate(player, on_player)
|
||||
if on_player.nil?
|
||||
player.send_message('That player does not exist.')
|
||||
return false
|
||||
elsif on_player.get_privilege_level == RIGHTS_ADMIN
|
||||
player.send_message('You cannot perform this action on Administrators.')
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
@@ -162,6 +162,10 @@ public final class BinaryPlayerSerializer extends PlayerSerializer {
|
||||
|
||||
Map<String, Attribute<?>> attributes = readAttributes(in);
|
||||
attributes.forEach(player::setAttribute);
|
||||
|
||||
if (player.isBanned()) {
|
||||
return new PlayerLoaderResponse(LoginConstants.STATUS_ACCOUNT_DISABLED);
|
||||
}
|
||||
|
||||
return new PlayerLoaderResponse(LoginConstants.STATUS_OK, player);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ public final class ChatMessageHandler extends MessageHandler<ChatMessage> {
|
||||
|
||||
@Override
|
||||
public void handle(Player player, ChatMessage message) {
|
||||
if (player.isMuted()) {
|
||||
message.terminate();
|
||||
return;
|
||||
}
|
||||
player.getBlockSet().add(SynchronizationBlock.createChatBlock(player, message));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.apollo.game.message.impl.UpdateRunEnergyMessage;
|
||||
import org.apollo.game.model.Appearance;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.World.RegistrationStatus;
|
||||
import org.apollo.game.model.entity.attr.Attribute;
|
||||
import org.apollo.game.model.entity.attr.AttributeDefinition;
|
||||
import org.apollo.game.model.entity.attr.AttributeMap;
|
||||
@@ -65,9 +64,14 @@ import com.google.common.base.Preconditions;
|
||||
public final class Player extends Mob {
|
||||
|
||||
static {
|
||||
// TODO this should be a time rather than a flag
|
||||
AttributeMap.define("muted", AttributeDefinition.forBoolean(false, AttributePersistence.PERSISTENT));
|
||||
|
||||
AttributeMap.define("banned", AttributeDefinition.forBoolean(false, AttributePersistence.PERSISTENT));
|
||||
AttributeMap.define("run_energy", AttributeDefinition.forInt(100, AttributePersistence.PERSISTENT));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This player's bank.
|
||||
*/
|
||||
@@ -457,6 +461,22 @@ public final class Player extends Mob {
|
||||
return energy.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this player is banned or not.
|
||||
*/
|
||||
public boolean isBanned() {
|
||||
Attribute<Boolean> banned = attributes.get("banned");
|
||||
return banned.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this player is muted or not.
|
||||
*/
|
||||
public boolean isMuted() {
|
||||
Attribute<Boolean> muted = attributes.get("muted");
|
||||
return muted.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this player's {@link ScreenBrightness}.
|
||||
*
|
||||
@@ -719,6 +739,10 @@ public final class Player extends Mob {
|
||||
send(new IdAssignmentMessage(index, members));
|
||||
sendMessage("Welcome to RuneScape.");
|
||||
|
||||
if (isMuted()) {
|
||||
sendMessage("You are currently muted. Other players will not see your chat messages.");
|
||||
}
|
||||
|
||||
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
|
||||
for (int tab = 0; tab < tabs.length; tab++) {
|
||||
send(new SwitchTabInterfaceMessage(tab, tabs[tab]));
|
||||
|
||||
Reference in New Issue
Block a user