Search in sources :

Example 1 with MmoPlayer

use of net.laboulangerie.laboulangeriemmo.player.MmoPlayer in project LaBoulangerieMmo by LaBoulangerie.

the class MmoCommand method onTabComplete.

@Override
@Nullable
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, @NotNull String[] args) {
    if (args.length == 1)
        return Arrays.asList("xp", "reload", "rl", "blockus");
    if (args[0].equalsIgnoreCase("xp")) {
        switch(args.length) {
            default:
            case 2:
                // Lists players
                return null;
            case 3:
                return Arrays.asList("add", "subtract", "see", "set");
            case 4:
                OfflinePlayer player = Bukkit.getOfflinePlayer(Bukkit.getPlayerUniqueId(args[1]));
                MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getOfflinePlayer(player);
                return mmoPlayer.streamTalents().get().map(talent -> talent.getTalentId()).collect(Collectors.toList());
            case 5:
                if (args[2].equalsIgnoreCase("see"))
                    return Arrays.asList("");
                return Arrays.asList("10", "100", "1000");
        }
    }
    if (args[0].equalsIgnoreCase("blockus") && args.length == 2)
        return Arrays.asList("isBlockus", "mark", "unmark");
    return null;
}
Also used : Arrays(java.util.Arrays) CommandSender(org.bukkit.command.CommandSender) BlockusDataHolder(net.laboulangerie.laboulangeriemmo.blockus.BlockusDataHolder) TabCompleter(org.bukkit.command.TabCompleter) IOException(java.io.IOException) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) CommandExecutor(org.bukkit.command.CommandExecutor) OfflinePlayer(org.bukkit.OfflinePlayer) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) Nullable(org.jetbrains.annotations.Nullable) Talent(net.laboulangerie.laboulangeriemmo.player.talent.Talent) List(java.util.List) Block(org.bukkit.block.Block) RayTraceResult(org.bukkit.util.RayTraceResult) Command(org.bukkit.command.Command) NotNull(org.jetbrains.annotations.NotNull) LaBoulangerieMmo(net.laboulangerie.laboulangeriemmo.LaBoulangerieMmo) Bukkit(org.bukkit.Bukkit) Blockus(net.laboulangerie.laboulangeriemmo.blockus.Blockus) OfflinePlayer(org.bukkit.OfflinePlayer) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MmoPlayer

use of net.laboulangerie.laboulangeriemmo.player.MmoPlayer in project LaBoulangerieMmo by LaBoulangerie.

the class MmoExpansion method onRequest.

@Override
public String onRequest(OfflinePlayer player, String params) {
    MmoPlayer mmoPlayer = mmoPlayerManager.getOfflinePlayer(player);
    if (params.equalsIgnoreCase("palier")) {
        return Integer.toString(mmoPlayer.getPalier());
    }
    String talentId = params.split("_")[0];
    Talent talent = mmoPlayer.getTalent(talentId);
    if (talent == null) {
        return null;
    }
    if (params.equals(talentId + "_xp")) {
        return Double.toString(talent.getXp());
    }
    if (params.equals(talentId + "_level")) {
        return Integer.toString(talent.getLevel(LaBoulangerieMmo.XP_MULTIPLIER));
    }
    if (params.equals(talentId + "_xp_in_level")) {
        return Double.toString(talent.getXp() - talent.getLevelXp(LaBoulangerieMmo.XP_MULTIPLIER));
    }
    if (params.equals(talentId + "_xp_to_next_lvl")) {
        return Double.toString(talent.getXpToNextLevel(LaBoulangerieMmo.XP_MULTIPLIER));
    }
    if (params.equals(talentId + "_name")) {
        return talent.getDisplayName();
    }
    // Placeholder is unknown by the Expansion
    return null;
}
Also used : MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) Talent(net.laboulangerie.laboulangeriemmo.player.talent.Talent)

Example 3 with MmoPlayer

use of net.laboulangerie.laboulangeriemmo.player.MmoPlayer in project LaBoulangerieMmo by LaBoulangerie.

the class ServerListener method onRiptideHit.

/**
 * Apply knockback and damages when hitting an entity withe the DODGE ability
 * @param event
 */
@EventHandler
public void onRiptideHit(EntityDamageByEntityEvent event) {
    if (!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof LivingEntity))
        return;
    Player player = (Player) event.getDamager();
    if (!player.isRiptiding())
        return;
    MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getPlayer(player);
    if (mmoPlayer == null) {
        // Shouldn't be possible but why not
        LaBoulangerieMmo.PLUGIN.getLogger().warning("Player : " + player.getName() + " doesn't have a MmoPlayer instance!");
        return;
    }
    if (// 1 is the duration of the spin attack TODO: Change when real cooldown is set
    !mmoPlayer.getCooldowns().hasUsed(Abilities.DODGING) || mmoPlayer.getCooldowns().getCooldown(Abilities.DODGING) >= 1)
        return;
    if (Utils.getAttackDamage(player, player.getInventory().getItemInMainHand()) > 0)
        event.setDamage(Utils.getAttackDamage(player, player.getInventory().getItemInMainHand()));
    ((LivingEntity) event.getEntity()).setVelocity(player.getLocation().getDirection().multiply(1));
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 4 with MmoPlayer

use of net.laboulangerie.laboulangeriemmo.player.MmoPlayer in project LaBoulangerieMmo by LaBoulangerie.

the class Combo method onCommand.

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, @NotNull String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage("§4This command is reserved to players!");
        return true;
    }
    MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getPlayer((Player) sender);
    Boolean state;
    if (args.length == 0) {
        // we want to do the toggle behavior if no parameter is passed
        args = new String[1];
        args[0] = "toggle";
    }
    if (args.length == 1 && !Arrays.asList("on", "off", "toggle").contains(args[0])) {
        return false;
    }
    state = args[0].equals("on") ? true : args[0].equals("off") ? false : !mmoPlayer.hasEnabledCombo();
    mmoPlayer.setEnableCombo(state);
    HashMap<String, String> placeholders = new HashMap<>();
    placeholders.put("state", state == true ? "activé" : "désactivé");
    sender.sendMessage(MiniMessage.get().parse(LaBoulangerieMmo.PLUGIN.getConfig().getString("lang.prefix")).append(MiniMessage.get().parse(LaBoulangerieMmo.PLUGIN.getConfig().getString("lang.messages.combo_toggle"), placeholders)));
    return true;
}
Also used : Player(org.bukkit.entity.Player) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) HashMap(java.util.HashMap) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer)

Example 5 with MmoPlayer

use of net.laboulangerie.laboulangeriemmo.player.MmoPlayer in project LaBoulangerieMmo by LaBoulangerie.

the class MmoCommand method onCommand.

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String alias, @NotNull String[] args) {
    if (args.length == 0)
        return false;
    if (args[0].equalsIgnoreCase("xp") && args.length >= 4) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(Bukkit.getPlayerUniqueId(args[1]));
        if (player == null || LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getOfflinePlayer(player) == null) {
            sender.sendMessage("§4Impossible de récupérer le joueur: " + args[1]);
            return false;
        }
        MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager().getOfflinePlayer(player);
        Talent talent = mmoPlayer.getTalent(args[3]);
        if (talent == null) {
            sender.sendMessage("§4" + args[1] + " n'as pas le talent " + args[3]);
            return false;
        }
        if (args[2].equalsIgnoreCase("see")) {
            sender.sendMessage("§a" + args[1] + ": §b" + args[3] + ": §rlvl §e" + talent.getLevel(LaBoulangerieMmo.XP_MULTIPLIER) + "§r, xp §e" + (talent.getXp() - talent.getLevelXp(LaBoulangerieMmo.XP_MULTIPLIER)) + "§r, total xp §e" + talent.getXp() + "§r/§e" + talent.getLevelXp(LaBoulangerieMmo.XP_MULTIPLIER));
            return true;
        }
        if (args.length < 5)
            return false;
        Double amount = null;
        try {
            amount = Double.parseDouble(args[4]);
        } catch (Exception e) {
            sender.sendMessage("§4L'argument §e" + args[4] + " §4n'est pas un nombre décimal valide.");
            return true;
        }
        if (args[2].equalsIgnoreCase("add")) {
            talent.incrementXp(amount);
            sender.sendMessage("§aVous avez ajouté §e" + args[4] + "§axp au talent §e" + talent.getDisplayName() + "§a de §e" + args[1]);
            return true;
        }
        if (args[2].equalsIgnoreCase("subtract")) {
            talent.decrementXp(amount);
            sender.sendMessage("§aVous avez retiré §e" + args[4] + "§axp au talent §e" + talent.getDisplayName() + "§a de §e" + args[1]);
            return true;
        }
        if (args[2].equalsIgnoreCase("set")) {
            talent.setXp(amount);
            sender.sendMessage("§aVous avez mis à §e" + args[4] + "§axp le talent §e" + talent.getDisplayName() + "§a de §e" + args[1]);
            return true;
        }
    }
    if (args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("rl")) {
        sender.sendMessage("§bWriting blockuses...");
        try {
            LaBoulangerieMmo.PLUGIN.getBlockusDataManager().writeBlockuses();
        } catch (IOException e) {
            e.printStackTrace();
        }
        sender.sendMessage("§bReloading config");
        LaBoulangerieMmo.PLUGIN.reloadConfig();
        sender.sendMessage("§aReload complete");
        return true;
    }
    if (args[0].equalsIgnoreCase("blockus")) {
        if (args.length < 2) {
            sender.sendMessage("§bIl y a §e" + LaBoulangerieMmo.PLUGIN.getBlockusDataManager().getBlockusDataHolder().getBlockuses().size() + " §bblockus");
            return true;
        }
        if (!(sender instanceof Player)) {
            sender.sendMessage("§4Vous devez être en jeu pour exécuter la commande");
            return true;
        }
        Player player = (Player) sender;
        RayTraceResult result = player.rayTraceBlocks(5);
        if (result == null) {
            player.sendMessage("§4Vous ne regardez pas un bloc dans un rayon de 5 blocs");
            return true;
        }
        Block block = result.getHitBlock();
        if (args[1].equalsIgnoreCase("isBlockus")) {
            player.sendMessage(block.hasMetadata("laboulangerie:placed") ? "§aLe bloc visé est un blockus" : "§eLe bloc visé n'est pas un blockus");
            return true;
        }
        if (args[1].equalsIgnoreCase("mark")) {
            Blockus blockus = new Blockus(block);
            blockus.putMetadata("laboulangerie:placed", player.getUniqueId());
            blockus.markAsBlockus();
            LaBoulangerieMmo.PLUGIN.getBlockusDataManager().getBlockusDataHolder().addBlockus(blockus);
            player.sendMessage("§aLe bloc visé est maintenant un blockus");
            return true;
        }
        if (args[1].equalsIgnoreCase("unmark")) {
            if (!block.hasMetadata("laboulangerie:placed")) {
                sender.sendMessage("§eLe bloc visé n'est pas un blockus impossible de le dé-marquer");
                return true;
            }
            block.removeMetadata("laboulangerie:placed", LaBoulangerieMmo.PLUGIN);
            BlockusDataHolder dataHolder = LaBoulangerieMmo.PLUGIN.getBlockusDataManager().getBlockusDataHolder();
            dataHolder.removeBlockus(dataHolder.getBlockus(block));
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) RayTraceResult(org.bukkit.util.RayTraceResult) OfflinePlayer(org.bukkit.OfflinePlayer) Block(org.bukkit.block.Block) Blockus(net.laboulangerie.laboulangeriemmo.blockus.Blockus) IOException(java.io.IOException) MmoPlayer(net.laboulangerie.laboulangeriemmo.player.MmoPlayer) Talent(net.laboulangerie.laboulangeriemmo.player.talent.Talent) IOException(java.io.IOException) BlockusDataHolder(net.laboulangerie.laboulangeriemmo.blockus.BlockusDataHolder)

Aggregations

MmoPlayer (net.laboulangerie.laboulangeriemmo.player.MmoPlayer)14 Player (org.bukkit.entity.Player)12 LaBoulangerieMmo (net.laboulangerie.laboulangeriemmo.LaBoulangerieMmo)8 EventHandler (org.bukkit.event.EventHandler)8 ComboCompletedEvent (net.laboulangerie.laboulangeriemmo.events.ComboCompletedEvent)7 Listener (org.bukkit.event.Listener)7 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)7 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)7 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)7 PlayerInteractEntityEvent (org.bukkit.event.player.PlayerInteractEntityEvent)7 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)7 PlayerItemConsumeEvent (org.bukkit.event.player.PlayerItemConsumeEvent)7 Talent (net.laboulangerie.laboulangeriemmo.player.talent.Talent)4 OfflinePlayer (org.bukkit.OfflinePlayer)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Blockus (net.laboulangerie.laboulangeriemmo.blockus.Blockus)2 BlockusDataHolder (net.laboulangerie.laboulangeriemmo.blockus.BlockusDataHolder)2 Block (org.bukkit.block.Block)2 RayTraceResult (org.bukkit.util.RayTraceResult)2