Search in sources :

Example 1 with XSound

use of com.cryptomorin.xseries.XSound in project LevelTools by byteful.

the class LevelToolsXPListener method handle.

protected void handle(LevelToolsItem tool, Player player, double modifier) {
    double newXp = LevelToolsUtil.round(tool.getXp() + modifier, 1);
    final LevelToolsXPIncreaseEvent xpEvent = new LevelToolsXPIncreaseEvent(tool, player, newXp, false);
    Bukkit.getPluginManager().callEvent(xpEvent);
    if (xpEvent.isCancelled()) {
        return;
    }
    tool.setXp(xpEvent.getNewXp());
    if (LevelToolsPlugin.getInstance().getConfig().getBoolean("actionBar.enabled")) {
        final String text = Text.colorize(LevelToolsPlugin.getInstance().getConfig().getString("actionBar.display").replace("{progress_bar}", LevelToolsUtil.createDefaultProgressBar(tool.getXp(), tool.getMaxXp())).replace("{xp}", String.valueOf(tool.getXp())).replace("{max_xp}", String.valueOf(tool.getMaxXp())));
        // player
        // .spigot()
        // .sendMessage(                                  DOESN'T WORK ON 1.8
        // ChatMessageType.ACTION_BAR,
        // TextComponent.fromLegacyText(text));
        ActionBar.sendActionBar(player, text);
    }
    if (tool.getXp() >= tool.getMaxXp()) {
        int newLevel = tool.getLevel() + 1;
        final LevelToolsLevelIncreaseEvent levelEvent = new LevelToolsLevelIncreaseEvent(tool, player, newLevel, false);
        if (levelEvent.isCancelled()) {
            return;
        }
        tool.setXp(LevelToolsUtil.round(Math.abs(tool.getXp() - tool.getMaxXp()), 1));
        tool.setLevel(levelEvent.getNewLevel());
        LevelToolsUtil.handleReward(tool, player);
        final ConfigurationSection soundCs = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("level_up_sound");
        final String sound = soundCs.getString("sound", null);
        if (sound == null) {
            return;
        }
        final XSound parsed = XSound.matchXSound(sound).orElse(null);
        if (parsed != null && parsed.isSupported()) {
            player.playSound(player.getLocation(), parsed.parseSound(), (float) soundCs.getDouble("pitch"), (float) soundCs.getDouble("volume"));
        }
    }
    LevelToolsUtil.setHand(player, tool.getItemStack());
}
Also used : XSound(com.cryptomorin.xseries.XSound) LevelToolsXPIncreaseEvent(me.byteful.plugin.leveltools.api.event.LevelToolsXPIncreaseEvent) LevelToolsLevelIncreaseEvent(me.byteful.plugin.leveltools.api.event.LevelToolsLevelIncreaseEvent) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

XSound (com.cryptomorin.xseries.XSound)1 LevelToolsLevelIncreaseEvent (me.byteful.plugin.leveltools.api.event.LevelToolsLevelIncreaseEvent)1 LevelToolsXPIncreaseEvent (me.byteful.plugin.leveltools.api.event.LevelToolsXPIncreaseEvent)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1