Search in sources :

Example 56 with User

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

the class WarSystem method conquer.

public void conquer(Guild conqueror, Guild loser, User attacker) {
    if (!SimpleEventHandler.handle(new GuildDeleteEvent(EventCause.SYSTEM, attacker, loser))) {
        loser.addLive();
        return;
    }
    String message = WarUtils.getWinMessage(conqueror, loser);
    for (User user : conqueror.getMembers()) {
        Player player = user.getPlayer();
        if (player != null) {
            player.sendMessage(message);
        }
    }
    message = WarUtils.getLoseMessage(conqueror, loser);
    for (User user : loser.getMembers()) {
        Player player = user.getPlayer();
        if (player != null) {
            player.sendMessage(message);
        }
    }
    GuildUtils.deleteGuild(loser);
    conqueror.addLive();
    message = WarUtils.getBroadcastMessage(conqueror, loser);
    Bukkit.broadcastMessage(message);
}
Also used : GuildDeleteEvent(net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User)

Example 57 with User

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

the class EntityDamage method onDamage.

@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    Entity damager = event.getDamager();
    if (!(entity instanceof Player)) {
        return;
    }
    Player attacker = null;
    if (damager instanceof Player) {
        attacker = (Player) damager;
    } else if (damager instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) damager).getShooter();
        if (shooter instanceof Player) {
            attacker = (Player) shooter;
        }
    }
    if (attacker == null) {
        return;
    }
    PluginConfig config = Settings.getConfig();
    User victimUser = User.get((Player) event.getEntity());
    User attackerUser = User.get(attacker);
    if (victimUser.hasGuild() && attackerUser.hasGuild()) {
        if (victimUser.getUUID().equals(attackerUser.getUUID())) {
            return;
        }
        if (victimUser.getGuild().equals(attackerUser.getGuild())) {
            if (!victimUser.getGuild().getPvP()) {
                event.setCancelled(true);
                return;
            }
        }
        if (victimUser.getGuild().getAllies().contains(attackerUser.getGuild())) {
            if (!config.damageAlly) {
                event.setCancelled(true);
                return;
            }
        }
    }
    if (config.assistEnable && !event.isCancelled()) {
        victimUser.addDamage(attackerUser, event.getDamage());
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 58 with User

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

the class PlayerChat method onChat.

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    User user = User.get(player);
    PluginConfig c = Settings.getConfig();
    if (user.hasGuild()) {
        Guild guild = user.getGuild();
        String message = event.getMessage();
        if (chat(event, message, c, player, guild)) {
            return;
        }
    }
    int points = user.getRank().getPoints();
    String format = event.getFormat();
    format = StringUtils.replace(format, "{RANK}", StringUtils.replace(c.chatRank, "{RANK}", String.valueOf(user.getRank().getPosition())));
    format = StringUtils.replace(format, "{POINTS}", c.chatPoints);
    format = StringUtils.replace(format, "{POINTS-FORMAT}", IntegerRange.inRange(points, c.pointsFormat));
    format = StringUtils.replace(format, "{POINTS}", String.valueOf(points));
    if (user.hasGuild()) {
        format = StringUtils.replace(format, "{TAG}", StringUtils.replace(c.chatGuild, "{TAG}", user.getGuild().getTag()));
        format = StringUtils.replace(format, "{POS}", StringUtils.replace(c.chatPosition, "{POS}", getPositionString(user, c)));
    } else {
        format = StringUtils.replace(format, "{TAG}", "");
        format = StringUtils.replace(format, "{POS}", "");
    }
    event.setFormat(format);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Guild(net.dzikoysk.funnyguilds.basic.Guild) EventHandler(org.bukkit.event.EventHandler)

Example 59 with User

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

the class PlayerChat method ally.

private boolean ally(AsyncPlayerChatEvent event, String message, PluginConfig c, Player player, Guild guild) {
    String ally = c.chatAlly;
    int length = ally.length();
    if (message.length() > length && message.substring(0, length).equals(ally)) {
        String format = c.chatAllyDesign;
        format = StringUtils.replace(format, "{PLAYER}", player.getName());
        format = StringUtils.replace(format, "{TAG}", guild.getTag());
        format = StringUtils.replace(format, "{POS}", StringUtils.replace(c.chatPosition, "{POS}", getPositionString(User.get(player), c)));
        String subMessage = event.getMessage().substring(length);
        this.spy(player, subMessage);
        format = StringUtils.replace(format, "{MESSAGE}", subMessage);
        for (User u : guild.getMembers()) {
            Player p = u.getPlayer();
            if (p != null) {
                p.sendMessage(format);
            }
        }
        for (Guild g : guild.getAllies()) {
            this.sendMessageToGuild(g, player, format);
        }
        event.setCancelled(true);
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 60 with User

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

the class PlayerJoin method onJoin.

@EventHandler
public void onJoin(PlayerJoinEvent e) {
    Player player = e.getPlayer();
    User user = User.get(player);
    PluginConfig config = Settings.getConfig();
    if (config.playerlistEnable && !AbstractTablist.hasTablist(player)) {
        AbstractTablist.createTablist(config.playerList, config.playerListHeader, config.playerListFooter, config.playerListPing, player);
    }
    user.getScoreboard();
    /*
        IndependentThread.actions(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
        IndependentThread.actions(ActionType.DUMMY_GLOBAL_UPDATE_USER, user);
        IndependentThread.actions(ActionType.RANK_UPDATE_USER, user);
         */
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player), new DummyGlobalUpdateUserRequest(user), new RankUpdateUserRequest(user));
    this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
        PacketExtension.registerPlayer(player);
        Version.isNewAvailable(player, false);
        Region region = RegionUtils.getAt(player.getLocation());
        if (region == null || region.getGuild() == null) {
            return;
        }
        if (config.createEntityType != null) {
            EntityUtil.spawn(region.getGuild(), player);
        }
    }, 30L);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) 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) RankUpdateUserRequest(net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest) Region(net.dzikoysk.funnyguilds.basic.Region) DummyGlobalUpdateUserRequest(net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest) EventHandler(org.bukkit.event.EventHandler)

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