Skip to content
Permalink
Browse files
Only allow admins to fancy others
  • Loading branch information
OttoRocket-LVP committed Jun 24, 2020
1 parent 8850fcd commit e10ce17cf4132b3c3fb94583d51dfdbce8e5771d
Showing 2 changed files with 52 additions and 7 deletions.
@@ -31,25 +31,28 @@ class FancyCommand extends Command {
}

onFancyCommand(player, target, type) {
const subject = target || player;
if(!player.isAdministrator() && player !== target) {
player.sendMessage(Message.COMMAND_ERROR, 'Only administrators can fancy other players.');
return;
}

switch (type) {
case 'none':
this.fancy_.delete(subject);
this.fancy_.delete(target);

pawnInvoke('RemovePlayerAttachedObject', 'ii', subject.id, 0);
pawnInvoke('RemovePlayerAttachedObject', 'ii', target.id, 0);

player.sendMessage(
Message.COMMAND_SUCCESS, subject.name + ' is not fancy anymore :(.');
Message.COMMAND_SUCCESS, target.name + ' is not fancy anymore :(.');
break;

case 'parrot':
case 'cow':
this.fancy_.set(subject, type);
this.onPlayerSpawn({ playerid: subject.id });
this.fancy_.set(target, type);
this.onPlayerSpawn({ playerid: target.id });

player.sendMessage(
Message.COMMAND_SUCCESS, subject.name + ' is now a ' + type + '.');
Message.COMMAND_SUCCESS, target.name + ' is now a ' + type + '.');
break;

default:
@@ -0,0 +1,42 @@
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

import MockPlaygroundCommands from 'features/playground/test/mock_playground_commands.js';

describe('FancyCommand', (it, beforeEach, afterEach) => {
let commands = null;
let gunther = null;

beforeEach(async() => {
commands = new MockPlaygroundCommands();
await commands.loadCommands();

gunther = server.playerManager.getById(0 /* Gunther */);
await gunther.identify();
// Enable |gunther| to use the command by adding an exception.
commands.access.addException('fancy', gunther);
});

afterEach(() => commands.dispose());

it('should not allow players to fancy others', async(assert) => {
const russell = server.playerManager.getById(1 /* Gunther */);
await russell.identify();

assert.isTrue(await gunther.issueCommand('/fancy 1 cow'));
assert.equal(gunther.messages.length, 1);
assert.includes(gunther.messages[0], 'Only administrators can fancy other players.');
});

it('should allow administrators to fancy others', async(assert) => {
const russell = server.playerManager.getById(1 /* Gunther */);
await russell.identify();

gunther.level = Player.LEVEL_ADMINISTRATOR

assert.isTrue(await gunther.issueCommand('/fancy 1 cow'));
assert.equal(gunther.messages.length, 1);
assert.includes(gunther.messages[0], russell.name + ' is now a cow.');
});
});

0 comments on commit e10ce17

Please sign in to comment.