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);
}
}
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);
}
}
Aggregations