Search in sources :

Example 1 with GuildMemberDeputyEvent

use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent in project FunnyGuilds by FunnyGuilds.

the class AxcDeputy method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.generalNoNickGiven);
        return;
    }
    if (!UserUtils.playedBefore(args[1])) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User user = User.get(args[1]);
    Player player = user.getPlayer();
    if (!guild.getMembers().contains(user)) {
        sender.sendMessage(messages.adminUserNotMemberOf);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildMemberDeputyEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
        return;
    }
    MessageTranslator translator = new MessageTranslator().register("{PLAYER}", user.getName());
    if (user.isDeputy()) {
        guild.removeDeputy(user);
        sender.sendMessage(messages.deputyRemove);
        if (player != null) {
            player.sendMessage(messages.deputyMember);
        }
        String message = translator.translate(messages.deputyNoLongerMembers);
        for (User member : guild.getOnlineMembers()) {
            member.getPlayer().sendMessage(message);
        }
        return;
    }
    guild.addDeputy(user);
    sender.sendMessage(messages.deputySet);
    if (player != null) {
        player.sendMessage(messages.deputyOwner);
    }
    String message = translator.translate(messages.deputyMembers);
    for (User member : guild.getOnlineMembers()) {
        member.getPlayer().sendMessage(message);
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMemberDeputyEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 2 with GuildMemberDeputyEvent

use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent in project FunnyGuilds by FunnyGuilds.

the class ExcDeputy method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User owner = User.get(player);
    if (!owner.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!owner.isOwner()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoNickGiven);
        return;
    }
    String name = args[0];
    if (!UserUtils.playedBefore(name)) {
        player.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User deputyUser = User.get(name);
    if (owner.equals(deputyUser)) {
        player.sendMessage(messages.deputyMustBeDifferent);
        return;
    }
    Guild guild = owner.getGuild();
    Player deputyPlayer = deputyUser.getPlayer();
    if (!guild.getMembers().contains(deputyUser)) {
        player.sendMessage(messages.generalIsNotMember);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildMemberDeputyEvent(EventCause.USER, owner, guild, deputyUser))) {
        return;
    }
    if (deputyUser.isDeputy()) {
        guild.removeDeputy(deputyUser);
        ;
        player.sendMessage(messages.deputyRemove);
        if (deputyPlayer != null) {
            deputyPlayer.sendMessage(messages.deputyMember);
        }
        return;
    }
    guild.addDeputy(deputyUser);
    player.sendMessage(messages.deputySet);
    if (deputyPlayer != null) {
        deputyPlayer.sendMessage(messages.deputyOwner);
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMemberDeputyEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)2 User (net.dzikoysk.funnyguilds.basic.User)2 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)2 GuildMemberDeputyEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberDeputyEvent)2 Player (org.bukkit.entity.Player)2 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)1