Skip to content

Commit

Permalink
feat: professions refactoring, nominations (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Jun 2, 2021
1 parent a390d3c commit 816d5a9
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 270 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

251 changes: 0 additions & 251 deletions src/profession/commands.ts

This file was deleted.

53 changes: 53 additions & 0 deletions src/profession/commands/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { CommandSender } from 'org.bukkit.command';
import { Player } from 'org.bukkit.entity';
import { errorMessage } from '../../chat/system';
import { Nation, nationById } from '../nation';
import { getProfession } from '../profession';

/**
* Gets the nation that a command should be operating on.
* For most players, it is the nation of their profession. Admins can
* (and probably have to) explicitly set the nation by --valtio argument.
* @param sender Command sender.
* @param args Initial command arguments.
* @returns Arguments with nation argument removed, the nation or undefined if
* no nation could be determined.
*/
export function getContextNation(
sender: CommandSender,
args: string[],
): [string[], Nation | undefined] {
let nation: Nation | undefined;
if (args[0] == '--valtio' && args[1]) {
if (sender.hasPermission('vk.profession.admin')) {
nation = nationById(args[1]);
if (!nation) {
errorMessage(sender, `Valtiota ${args[1]} ei ole olemassa`);
return [args, undefined];
}
args = args.slice(2); // Skip these arguments
} else {
// Overriding nation is admin-only feature
errorMessage(
sender,
'Sinulla ei ole oikeutta ammattien ylläpitokomentoihin.',
);
return [args, undefined];
}
} else {
// Nation not provided as argument, try to get it from player
nation = guessNation(sender);
}
return [args, nation];
}

export function guessNation(sender: CommandSender): Nation | undefined {
if (!(sender instanceof Player)) {
return undefined; // Console doesn't have a nation
}
const profession = getProfession(sender);
if (profession?.type != 'player') {
return undefined; // No profession or system profession (no associated nation)
}
return nationById(profession.nation);
}
Loading

0 comments on commit 816d5a9

Please sign in to comment.