Search in sources :

Example 31 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class EntityInteract method onInteract.

@EventHandler
public void onInteract(PlayerInteractEntityEvent event) {
    PluginConfig config = Settings.getConfig();
    Player eventCaller = event.getPlayer();
    Entity clickedEntity = event.getRightClicked();
    if (clickedEntity instanceof Player) {
        Player clickedPlayer = (Player) clickedEntity;
        if (!config.infoPlayerEnabled || (config.infoPlayerSneaking && !eventCaller.isSneaking()) || informationMessageCooldowns.cooldown(eventCaller, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
            return;
        }
        new ExcPlayer().execute(eventCaller, new String[] { clickedPlayer.getName() });
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Entity(org.bukkit.entity.Entity) ExcPlayer(net.dzikoysk.funnyguilds.command.ExcPlayer) Player(org.bukkit.entity.Player) ExcPlayer(net.dzikoysk.funnyguilds.command.ExcPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 32 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig 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 33 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig 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)

Example 34 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class FlatGuild method deserialize.

public static Guild deserialize(File file) {
    PluginConfig config = Settings.getConfig();
    Yamler pc = new Yamler(file);
    String id = pc.getString("uuid");
    String name = pc.getString("name");
    String tag = pc.getString("tag");
    String os = pc.getString("owner");
    String dp = pc.getString("deputy");
    String hs = pc.getString("home");
    String region = pc.getString("region");
    List<String> ms = pc.getStringList("members");
    List<String> rgs = pc.getStringList("regions");
    List<String> als = pc.getStringList("allies");
    List<String> ens = pc.getStringList("enemies");
    boolean pvp = pc.getBoolean("pvp");
    long born = pc.getLong("born");
    long validity = pc.getLong("validity");
    long attacked = pc.getLong("attacked");
    long ban = pc.getLong("ban");
    int lives = pc.getInt("lives");
    if (name == null) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild! Caused by: name is null");
        return null;
    } else if (tag == null) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: tag is null");
        return null;
    } else if (os == null) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: owner is null");
        return null;
    } else if (region == null && config.regionsEnabled) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region is null");
        return null;
    }
    Region rg = RegionUtils.get(region);
    if (rg == null && config.regionsEnabled) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region (object) is null");
        return null;
    }
    UUID uuid = UUID.randomUUID();
    if (id != null) {
        uuid = UUID.fromString(id);
    }
    User owner = User.get(os);
    List<User> deputies = new ArrayList<>();
    if (dp != null && !dp.isEmpty()) {
        deputies = UserUtils.getUsers(StringUtils.fromString(dp));
    }
    Location home = null;
    if (rg != null) {
        home = rg.getCenter();
        if (hs != null) {
            home = Parser.parseLocation(hs);
        }
    }
    if (ms == null || ms.isEmpty()) {
        ms = new ArrayList<>();
        ms.add(os);
    }
    List<User> members = UserUtils.getUsers(ms);
    List<String> regions = new ArrayList<>();
    if (rgs != null) {
        for (String n : rgs) {
            if (RegionUtils.get(n) != null) {
                regions.add(n);
            }
        }
    }
    List<Guild> allies = new ArrayList<>();
    if (als != null) {
        for (String s : als) {
            Guild guild = GuildUtils.getByName(s);
            if (guild != null) {
                allies.add(guild);
            }
        }
    }
    List<Guild> enemies = new ArrayList<>();
    if (ens != null) {
        for (String s : ens) {
            Guild guild = GuildUtils.getByName(s);
            if (guild != null) {
                enemies.add(guild);
            }
        }
    }
    if (born == 0) {
        born = System.currentTimeMillis();
    }
    if (validity == 0) {
        validity = System.currentTimeMillis() + config.validityStart;
    }
    if (lives == 0) {
        lives = config.warLives;
    }
    Object[] values = new Object[17];
    values[0] = uuid;
    values[1] = name;
    values[2] = tag;
    values[3] = owner;
    values[4] = home;
    values[5] = region;
    values[6] = members;
    values[7] = regions;
    values[8] = allies;
    values[9] = enemies;
    values[10] = born;
    values[11] = validity;
    values[12] = attacked;
    values[13] = lives;
    values[14] = ban;
    values[15] = deputies;
    values[16] = pvp;
    return DeserializationUtils.deserializeGuild(values);
}
Also used : User(net.dzikoysk.funnyguilds.basic.User) ArrayList(java.util.ArrayList) Guild(net.dzikoysk.funnyguilds.basic.Guild) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Region(net.dzikoysk.funnyguilds.basic.Region) UUID(java.util.UUID) Yamler(net.dzikoysk.funnyguilds.util.Yamler) Location(org.bukkit.Location)

Example 35 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class PlayerInteract method onInteract.

@EventHandler
public void onInteract(PlayerInteractEvent event) {
    Action eventAction = event.getAction();
    Player p = event.getPlayer();
    if (eventAction == Action.RIGHT_CLICK_BLOCK || eventAction == Action.LEFT_CLICK_BLOCK) {
        Block clicked = event.getClickedBlock();
        if (RegionUtils.isIn(clicked.getLocation())) {
            Region region = RegionUtils.getAt(clicked.getLocation());
            Block heart = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
            if (clicked.equals(heart)) {
                Guild g = region.getGuild();
                if (SecuritySystem.getSecurity().checkPlayer(p, g)) {
                    return;
                }
                if (eventAction == Action.LEFT_CLICK_BLOCK) {
                    WarSystem.getInstance().attack(p, g);
                    event.setCancelled(true);
                    return;
                } else if (eventAction == Action.RIGHT_CLICK_BLOCK) {
                    PluginConfig config = Settings.getConfig();
                    if (config.informationMessageCooldowns.cooldown(p, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
                        return;
                    }
                    new ExcInfo().execute(p, new String[] { g.getTag() });
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (ProtectionUtils.action(eventAction, event.getClickedBlock())) {
        event.setCancelled(false);
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Action(org.bukkit.event.block.Action) Player(org.bukkit.entity.Player) ExcInfo(net.dzikoysk.funnyguilds.command.ExcInfo) Block(org.bukkit.block.Block) Region(net.dzikoysk.funnyguilds.basic.Region) Guild(net.dzikoysk.funnyguilds.basic.Guild) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)36 User (net.dzikoysk.funnyguilds.basic.User)25 Player (org.bukkit.entity.Player)25 Guild (net.dzikoysk.funnyguilds.basic.Guild)19 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)17 Region (net.dzikoysk.funnyguilds.basic.Region)13 EventHandler (org.bukkit.event.EventHandler)8 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)6 Block (org.bukkit.block.Block)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 Rank (net.dzikoysk.funnyguilds.basic.Rank)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DummyGlobalUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest)2 RankUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest)2 Manager (net.dzikoysk.funnyguilds.data.Manager)2 Messages (net.dzikoysk.funnyguilds.data.Messages)2 Settings (net.dzikoysk.funnyguilds.data.Settings)2