use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent in project FunnyGuilds by FunnyGuilds.
the class AxcAdd method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
if (args.length < 1) {
sender.sendMessage(messages.generalNoTagGiven);
return;
}
if (!GuildUtils.tagExists(args[0])) {
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]);
if (user.hasGuild()) {
sender.sendMessage(messages.generalUserHasGuild);
return;
}
Guild guild = GuildUtils.getByTag(args[0]);
if (guild == null) {
sender.sendMessage(messages.generalNoGuildFound);
return;
}
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
return;
}
guild.addMember(user);
user.setGuild(guild);
// IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(user.getName()));
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
Player player = user.getPlayer();
Player owner = guild.getOwner().getPlayer();
if (player != null) {
player.sendMessage(translator.translate(messages.joinToMember));
}
if (owner != null) {
owner.sendMessage(translator.translate(messages.joinToOwner));
}
Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
}
use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent in project FunnyGuilds by FunnyGuilds.
the class ExcJoin method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
User user = User.get(player);
if (user.hasGuild()) {
player.sendMessage(messages.joinHasGuild);
return;
}
List<InvitationList.Invitation> invitations = InvitationList.getInvitationsFor(player);
if (invitations.size() == 0) {
player.sendMessage(messages.joinHasNotInvitation);
return;
}
if (args.length < 1) {
String guildNames = StringUtils.toString(InvitationList.getInvitationGuildNames(player), false);
for (String msg : messages.joinInvitationList) {
player.sendMessage(msg.replace("{GUILDS}", guildNames));
}
return;
}
String tag = args[0];
Guild guild = GuildUtils.getByTag(tag);
if (guild == null) {
player.sendMessage(messages.joinTagExists);
return;
}
if (!InvitationList.hasInvitationFrom(player, GuildUtils.getByTag(tag))) {
player.sendMessage(messages.joinHasNotInvitationTo);
return;
}
List<ItemStack> requiredItems = Settings.getConfig().joinItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.joinItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
if (!SimpleEventHandler.handle(new GuildMemberAcceptInviteEvent(EventCause.USER, user, guild, user))) {
return;
}
InvitationList.expireInvitation(guild, player);
if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(EventCause.USER, user, guild, user))) {
return;
}
guild.addMember(user);
user.setGuild(guild);
player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
// IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(user.getName()));
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", player.getName());
player.sendMessage(translator.translate(messages.joinToMember));
Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
Player owner = guild.getOwner().getPlayer();
if (owner != null) {
owner.sendMessage(translator.translate(messages.joinToOwner));
}
}
Aggregations