Search in sources :

Example 1 with MagicBlock

use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.

the class Arena method finish.

protected void finish() {
    ArenaStage currentStage = getCurrentStage();
    if (currentStage != null) {
        currentStage.finish();
    }
    runCommands(endCommands);
    if (magicBlocks != null) {
        for (String magicBlockKey : magicBlocks) {
            MagicBlock magicBlock = controller.getMagic().getMagicBlock(magicBlockKey);
            if (magicBlock == null) {
                controller.getMagic().getLogger().warning("Invalid magic block: " + magicBlockKey + " in arena config " + getKey());
                continue;
            }
            magicBlock.disable();
        }
    }
    state = ArenaState.LOBBY;
    exitPlayers();
    hideRespawnBossBar();
    clearPlayers();
    // Check for a new start
    checkStart();
}
Also used : MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock)

Example 2 with MagicBlock

use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.

the class Arena method start.

public void start() {
    if (!isValid())
        return;
    state = ArenaState.ACTIVE;
    started = System.currentTimeMillis();
    lastTick = started;
    currentStage = 0;
    for (ArenaStage stage : stages) {
        stage.reset();
    }
    runCommands(startCommands);
    if (magicBlocks != null) {
        for (String magicBlockKey : magicBlocks) {
            MagicBlock magicBlock = controller.getMagic().getMagicBlock(magicBlockKey);
            if (magicBlock == null) {
                controller.getMagic().getLogger().warning("Invalid magic block: " + magicBlockKey + " in arena config " + getKey());
                continue;
            }
            magicBlock.enable();
        }
    }
    if (borderMax > 0 && duration > 0) {
        World world = getCenter().getWorld();
        WorldBorder border = world.getWorldBorder();
        border.setSize(borderMax);
        border.setSize(borderMin, duration / 1000);
    }
    while (queue.size() > 0 && players.size() < maxPlayers) {
        ArenaPlayer queuedPlayer = queue.remove();
        if (queuedPlayer.isValid() && !queuedPlayer.isDead()) {
            players.add(queuedPlayer);
        }
    }
    if (players.size() < minPlayers) {
        queue.addAll(players);
        players.clear();
        state = ArenaState.LOBBY;
        messagePlayers(ChatColor.RED + " the match did not have enough players to start.");
        return;
    }
    spawnPlayers(new ArrayList<>(this.players));
    ArenaStage currentStage = getCurrentStage();
    if (currentStage != null) {
        currentStage.start();
    }
    messageNextRoundPlayerList(getMessage("next"));
}
Also used : MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) WorldBorder(org.bukkit.WorldBorder) World(org.bukkit.World)

Example 3 with MagicBlock

use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.

the class ArenaCommandExecutor method onTabComplete.

@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
    List<String> options = new ArrayList<>();
    if (args.length < 2) {
        options.addAll(Arrays.asList(SUB_COMMANDS));
    } else if (args.length == 2 && args[0].equalsIgnoreCase("leave")) {
        options.addAll(arenaController.getMagic().getPlayerNames());
    } else if (args.length == 2) {
        if (args[0].equalsIgnoreCase("add")) {
            Set<String> unusedTemplates = new HashSet<>(controller.getArenaTemplateKeys());
            unusedTemplates.removeAll(arenaController.getArenaKeys());
            options.addAll(unusedTemplates);
        } else {
            Collection<Arena> arenas = arenaController.getArenas();
            for (Arena arena : arenas) {
                options.add(arena.getKey());
            }
            if (args[0].equalsIgnoreCase("reset")) {
                options.add("ALL");
            }
        }
    } else if (args.length == 3 && args[0].equalsIgnoreCase("add")) {
        options.addAll(controller.getArenaTemplateKeys());
    } else if (args.length == 3 && args[0].equalsIgnoreCase("stage")) {
        options.addAll(Arrays.asList(STAGE_COMMANDS));
    } else if (args.length == 3 && args[0].equalsIgnoreCase("configure")) {
        options.addAll(Arrays.asList(ARENA_PROPERTIES));
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && (args[2].equalsIgnoreCase("add") || args[2].equalsIgnoreCase("remove"))) {
        options.addAll(Arrays.asList(ARENA_LISTS));
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && args[2].equalsIgnoreCase("randomize")) {
        options.addAll(Arrays.asList(ARENA_RANDOMIZE));
    } else if (args.length == 4 && args[0].equalsIgnoreCase("stage") && args[2].equalsIgnoreCase("configure")) {
        options.addAll(Arrays.asList(STAGE_PROPERTIES));
    } else if (args.length == 5 && args[0].equalsIgnoreCase("stage") && args[2].equalsIgnoreCase("configure") && (args[3].equalsIgnoreCase("add") || args[3].equalsIgnoreCase("remove"))) {
        options.addAll(Arrays.asList(STAGE_LISTS));
    } else if (args.length == 5 && args[0].equalsIgnoreCase("stage") && args[2].equalsIgnoreCase("configure") && args[3].equalsIgnoreCase("randomize")) {
        options.addAll(Arrays.asList(STAGE_RANDOMIZE));
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && (args[2].equalsIgnoreCase("keep_inventory") || args[2].equalsIgnoreCase("keep_level") || args[2].equalsIgnoreCase("item_wear") || args[2].equalsIgnoreCase("allow_consuming") || args[2].equalsIgnoreCase("op_check") || args[2].equalsIgnoreCase("allow_interrupt") || args[2].equalsIgnoreCase("allow_melee") || args[2].equalsIgnoreCase("allow_projectiles") || args[2].equalsIgnoreCase("heal"))) {
        options.addAll(Arrays.asList(BOOLEAN_PROPERTIES));
    } else if (args.length == 3 && args[0].equalsIgnoreCase("configure") && args[2].equalsIgnoreCase("template")) {
        for (String templateKey : arenaController.getArenaTemplateKeys()) {
            options.add(templateKey);
        }
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && (args[2].equalsIgnoreCase("add") || args[2].equalsIgnoreCase("remove")) && args[3].equalsIgnoreCase("magic_block")) {
        for (MagicBlock magicBlock : controller.getMagicBlocks()) {
            options.add(magicBlock.getName());
        }
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && args[2].equalsIgnoreCase("sudden_death_effect")) {
        for (PotionEffectType pt : PotionEffectType.values()) {
            if (pt == null)
                continue;
            String name = pt.getName();
            if (name == null)
                continue;
            options.add(name.toLowerCase());
        }
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && args[2].equalsIgnoreCase("spell_start")) {
        Collection<SpellTemplate> spells = arenaController.getMagic().getSpellTemplates();
        for (SpellTemplate spell : spells) {
            options.add(spell.getKey());
        }
    } else if (args.length == 3 && (args[0].equalsIgnoreCase("join") || args[0].equalsIgnoreCase("stats") || args[0].equalsIgnoreCase("reset"))) {
        options.addAll(arenaController.getMagic().getPlayerNames());
    } else if (args.length == 6 && args[0].equalsIgnoreCase("stage") && args[2].equalsIgnoreCase("configure") && args[3].equalsIgnoreCase("add") && args[4].equalsIgnoreCase("mob")) {
        options.addAll(arenaController.getMagic().getMobKeys());
        for (EntityType entityType : EntityType.values()) {
            if (entityType.isAlive() && entityType.isSpawnable()) {
                options.add(entityType.name().toLowerCase());
            }
        }
    } else if (args.length == 6 && args[0].equalsIgnoreCase("stage") && args[2].equalsIgnoreCase("configure") && args[3].equalsIgnoreCase("remove") && args[4].equalsIgnoreCase("mob")) {
        Arena arena = arenaController.getArena(args[1]);
        if (arena != null) {
            EditingStage stage = arena.getIfEditingStage();
            if (stage != null) {
                for (EntityData mob : stage.getSpawns()) {
                    String key = mob.getKey();
                    if (key != null && !key.isEmpty()) {
                        options.add(key);
                    }
                }
            }
        }
    } else if (args.length == 4 && args[0].equalsIgnoreCase("configure") && args[2].equalsIgnoreCase("leaderboard_sign_type")) {
        for (Material sign : arenaController.getMagic().getMaterialSetManager().getMaterialSet("signs").getMaterials()) {
            options.add(sign.name().toLowerCase());
        }
    }
    return options;
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) EntityData(com.elmakers.mine.bukkit.api.entity.EntityData) EditingStage(com.elmakers.mine.bukkit.arena.EditingStage) Material(org.bukkit.Material) Arena(com.elmakers.mine.bukkit.arena.Arena) EntityType(org.bukkit.entity.EntityType) MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) Collection(java.util.Collection) HashSet(java.util.HashSet) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 4 with MagicBlock

use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.

the class MagicBlockRule method onHandle.

@Override
@Nonnull
public BlockResult onHandle(Block block, Random random, Player cause) {
    if (replace != null && !replace.testBlock(block)) {
        return BlockResult.SKIP;
    }
    String templateKey = RandomUtils.weightedRandom(templateProbability);
    if (templateKey.equalsIgnoreCase("none")) {
        return BlockResult.SKIP;
    }
    try {
        BlockResult result = BlockResult.valueOf(templateKey.toUpperCase());
        return result;
    } catch (Exception ignore) {
    }
    Mage mage = controller.getMage(cause);
    Location location = block.getLocation();
    MagicBlock magicBlock = controller.addMagicBlock(location, templateKey, mage.getId(), mage.getName(), parameters);
    String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
    if (magicBlock == null) {
        message = "Failed to create" + message;
    } else {
        message = "Created" + message;
    }
    controller.info(message);
    return magicBlock == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
Also used : MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) BlockResult(com.elmakers.mine.bukkit.world.BlockResult) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Location(org.bukkit.Location) Nonnull(javax.annotation.Nonnull)

Example 5 with MagicBlock

use of com.elmakers.mine.bukkit.api.block.magic.MagicBlock in project MagicPlugin by elBukkit.

the class CreateMagicBlockAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Location location = context.getTargetBlock().getLocation();
    MagicBlock magicBlock = controller.addMagicBlock(location, templateKey, mage.getId(), mage.getName(), parameters);
    return magicBlock == null ? SpellResult.FAIL : SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Location(org.bukkit.Location)

Aggregations

MagicBlock (com.elmakers.mine.bukkit.api.block.magic.MagicBlock)8 Location (org.bukkit.Location)5 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 BlockResult (com.elmakers.mine.bukkit.world.BlockResult)2 Material (org.bukkit.Material)2 EntityData (com.elmakers.mine.bukkit.api.entity.EntityData)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 Arena (com.elmakers.mine.bukkit.arena.Arena)1 ArenaPlayer (com.elmakers.mine.bukkit.arena.ArenaPlayer)1 ArenaTemplate (com.elmakers.mine.bukkit.arena.ArenaTemplate)1 EditingStage (com.elmakers.mine.bukkit.arena.EditingStage)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Nonnull (javax.annotation.Nonnull)1 World (org.bukkit.World)1 WorldBorder (org.bukkit.WorldBorder)1 EntityType (org.bukkit.entity.EntityType)1 Player (org.bukkit.entity.Player)1