Search in sources :

Example 1 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class ExcLeave 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.generalHasNoGuild);
        return;
    }
    if (user.isOwner()) {
        player.sendMessage(messages.leaveIsOwner);
        return;
    }
    Guild guild = user.getGuild();
    if (!SimpleEventHandler.handle(new GuildMemberLeaveEvent(EventCause.USER, user, guild, user))) {
        return;
    }
    guild.removeMember(user);
    user.removeGuild();
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, user.getName());
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(user.getName()), new PrefixGlobalUpdatePlayer(player));
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
    player.sendMessage(translator.translate(messages.leaveToUser));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastLeave));
}
Also used : PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) Player(org.bukkit.entity.Player) PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) PrefixGlobalRemovePlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildMemberLeaveEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberLeaveEvent) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 2 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class ExcValidity method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    Guild guild = user.getGuild();
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (config.validityWhen != 0) {
        long c = guild.getValidity();
        long d = c - System.currentTimeMillis();
        if (d > config.validityWhen) {
            long when = d - config.validityWhen;
            player.sendMessage(messages.validityWhen.replace("{TIME}", TimeUtils.getDurationBreakdown(when)));
            return;
        }
    }
    List<ItemStack> requiredItems = config.validityItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.validityItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(EventCause.USER, user, guild, config.validityTime))) {
        return;
    }
    player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
    long c = guild.getValidity();
    if (c == 0) {
        c = System.currentTimeMillis();
    }
    c += config.validityTime;
    guild.setValidity(c);
    player.sendMessage(messages.validityDone.replace("{DATE}", config.dateFormat.format(new Date(c))));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) ItemStack(org.bukkit.inventory.ItemStack) GuildExtendValidityEvent(net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent) Date(java.util.Date)

Example 3 with User

use of net.dzikoysk.funnyguilds.basic.User 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));
}
Also used : Player(org.bukkit.entity.Player) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 4 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcBan method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    } else if (args.length < 2) {
        sender.sendMessage(messages.adminNoBanTimeGiven);
        return;
    } else if (args.length < 3) {
        sender.sendMessage(messages.adminNoReasonGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (guild.isBanned()) {
        sender.sendMessage(messages.adminGuildBanned);
        return;
    }
    long time = Parser.parseTime(args[1]);
    if (time < 1) {
        sender.sendMessage(messages.adminTimeError);
        return;
    }
    StringBuilder reasonBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        reasonBuilder.append(args[i]);
        reasonBuilder.append(" ");
    }
    String reason = reasonBuilder.toString();
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildBanEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time, reason))) {
        return;
    }
    BanUtils.ban(guild, time, reason);
    MessageTranslator translator = new MessageTranslator().register("{GUILD", guild.getName()).register("{TAG}", guild.getTag()).register("{TIME}", args[1]).register("{REASON}", StringUtils.colored(reason));
    sender.sendMessage(translator.translate(messages.adminGuildBan));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastBan));
}
Also used : GuildBanEvent(net.dzikoysk.funnyguilds.event.guild.GuildBanEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 5 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class ExcEnlarge method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (!config.enlargeEnable) {
        return;
    }
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    Region region = Region.get(user.getGuild().getRegion());
    int enlarge = region.getEnlarge();
    if (enlarge > config.enlargeItems.size() - 1) {
        player.sendMessage(messages.enlargeMaxSize);
        return;
    }
    ItemStack need = config.enlargeItems.get(enlarge);
    if (!player.getInventory().containsAtLeast(need, need.getAmount())) {
        StringBuilder messageBuilder = new StringBuilder();
        messageBuilder.append(need.getAmount());
        messageBuilder.append(" ");
        messageBuilder.append(need.getType().toString().toLowerCase());
        player.sendMessage(messages.enlargeItem.replace("{ITEM}", messageBuilder.toString()));
        return;
    }
    if (RegionUtils.isNear(region.getCenter())) {
        player.sendMessage(messages.enlargeIsNear);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildEnlargeEvent(EventCause.USER, user, user.getGuild()))) {
        return;
    }
    player.getInventory().removeItem(need);
    region.setEnlarge(++enlarge);
    region.setSize(region.getSize() + config.enlargeSize);
    String enlargeDoneMessage = messages.enlargeDone.replace("{SIZE}", Integer.toString(region.getSize())).replace("{LEVEL}", Integer.toString(region.getEnlarge()));
    user.getGuild().broadcast(enlargeDoneMessage);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) GuildEnlargeEvent(net.dzikoysk.funnyguilds.event.guild.GuildEnlargeEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Region(net.dzikoysk.funnyguilds.basic.Region) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

User (net.dzikoysk.funnyguilds.basic.User)66 Player (org.bukkit.entity.Player)50 Guild (net.dzikoysk.funnyguilds.basic.Guild)43 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)39 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)25 Region (net.dzikoysk.funnyguilds.basic.Region)13 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)11 EventHandler (org.bukkit.event.EventHandler)10 Location (org.bukkit.Location)8 ItemStack (org.bukkit.inventory.ItemStack)6 ArrayList (java.util.ArrayList)5 Rank (net.dzikoysk.funnyguilds.basic.Rank)5 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)4 Date (java.util.Date)3 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 GuildDeleteEvent (net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent)3