Search in sources :

Example 6 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class FinishSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    if (player.isInMinigame() && player.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR) {
        Minigame minigame = player.getMinigame();
        if (minigame.isSpectator(player) || minigame.getState() == MinigameState.ENDED) {
            return false;
        }
        if (!minigame.getFlags().isEmpty()) {
            if (player.getPlayer().isOnGround()) {
                if (plugin.pdata.checkRequiredFlags(player, minigame.getName(false)).isEmpty()) {
                    if (sign.getLine(2).isEmpty() || sign.getLine(2).equals(player.getMinigame().getName(false))) {
                        if (player.getMinigame().isTeamGame()) {
                            List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(player.getTeam().getPlayers());
                            List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
                            for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
                                if (t != player.getTeam())
                                    l.addAll(t.getPlayers());
                            }
                            plugin.pdata.endMinigame(minigame, w, l);
                        } else {
                            if (minigame.getType() == MinigameType.MULTIPLAYER) {
                                List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
                                w.add(player);
                                List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size());
                                l.addAll(minigame.getPlayers());
                                l.remove(player);
                                plugin.pdata.endMinigame(minigame, w, l);
                            } else
                                plugin.pdata.endMinigame(player);
                        }
                        plugin.pdata.partyMode(player, 3, 10L);
                    }
                } else {
                    List<String> requiredFlags = plugin.pdata.checkRequiredFlags(player, minigame.getName(false));
                    String flags = "";
                    int num = requiredFlags.size();
                    for (int i = 0; i < num; i++) {
                        flags += requiredFlags.get(i);
                        if (i != num - 1) {
                            flags += ", ";
                        }
                    }
                    player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.finish.requireFlags"));
                    player.sendMessage(ChatColor.GRAY + flags);
                }
            }
            return true;
        } else {
            if (player.getPlayer().isOnGround()) {
                if (player.getMinigame().isTeamGame()) {
                    List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(player.getTeam().getPlayers());
                    List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
                    for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
                        if (t != player.getTeam())
                            l.addAll(t.getPlayers());
                    }
                    plugin.pdata.endMinigame(minigame, w, l);
                } else {
                    if (minigame.getType() == MinigameType.MULTIPLAYER) {
                        List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(1);
                        w.add(player);
                        List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(minigame.getPlayers().size());
                        l.addAll(minigame.getPlayers());
                        l.remove(player);
                        plugin.pdata.endMinigame(minigame, w, l);
                    } else
                        plugin.pdata.endMinigame(player);
                }
                plugin.pdata.partyMode(player);
                return true;
            }
        }
    } else if (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) {
        player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyHand"));
    }
    return false;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 7 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class TeamSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    if (player.isInMinigame()) {
        Minigame mgm = player.getMinigame();
        if (mgm.isTeamGame()) {
            if (player.getTeam() != matchTeam(mgm, sign.getLine(2))) {
                if (!mgm.isWaitingForPlayers() && !sign.getLine(2).equals(ChatColor.GRAY + "Neutral")) {
                    Team sm = null;
                    Team nt = matchTeam(mgm, sign.getLine(2));
                    if (nt != null) {
                        if (!nt.isFull()) {
                            for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                if (sm == null || t.getPlayers().size() < sm.getPlayers().size())
                                    sm = t;
                            }
                            if (nt.getPlayers().size() - sm.getPlayers().size() < 1) {
                                MultiplayerType.switchTeam(mgm, player, nt);
                                plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getDisplayName(mgm.usePlayerDisplayNames()), nt.getChatColor() + nt.getDisplayName()), null, player);
                                player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
                            } else {
                                player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.team.noUnbalance"));
                            }
                            player.getPlayer().damage(player.getPlayer().getHealth());
                        } else {
                            player.sendMessage(MinigameUtils.getLang("player.team.full"), "error");
                        }
                    }
                } else if (sign.getLine(2).equals(ChatColor.GRAY + "Neutral") || matchTeam(mgm, sign.getLine(2)) != player.getTeam()) {
                    Team cur = player.getTeam();
                    if (cur != null) {
                        Team nt = matchTeam(mgm, sign.getLine(2));
                        if (nt != null) {
                            if (nt.getPlayers().size() - cur.getPlayers().size() < 2) {
                                MultiplayerType.switchTeam(mgm, player, nt);
                                plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getName(), nt.getChatColor() + nt.getDisplayName()), null, player);
                                player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
                            } else {
                                player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.team.noUnbalance"));
                            }
                        } else {
                            player.removeTeam();
                        }
                    } else {
                        Team nt = matchTeam(mgm, sign.getLine(2));
                        if (nt != null) {
                            if (nt.getPlayers().size() < nt.getMaxPlayers()) {
                                MultiplayerType.switchTeam(mgm, player, nt);
                                plugin.mdata.sendMinigameMessage(mgm, String.format(nt.getGameAssignMessage(), player.getName(), nt.getChatColor() + nt.getDisplayName()), null, player);
                                player.sendMessage(String.format(nt.getAssignMessage(), nt.getChatColor() + nt.getDisplayName()), null);
                            } else {
                                player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("player.team.full"));
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 8 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class Minigames method onDisable.

public void onDisable() {
    if (plugin == null) {
        return;
    }
    PluginDescriptionFile desc = this.getDescription();
    log.info(desc.getName() + " successfully disabled.");
    for (Player p : getServer().getOnlinePlayers()) {
        if (pdata.getMinigamePlayer(p).isInMinigame()) {
            pdata.quitMinigame(pdata.getMinigamePlayer(p), true);
        }
    }
    for (Minigame minigame : mdata.getAllMinigames().values()) {
        if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equals("treasure_hunt") && minigame.isEnabled()) {
            if (minigame.getMinigameTimer() != null)
                minigame.getMinigameTimer().stopTimer();
            TreasureHuntMechanic.removeTreasure(minigame);
        }
    }
    for (Minigame mg : mdata.getAllMinigames().values()) {
        mg.saveMinigame();
    }
    backend.shutdown();
    //		pdata.saveDCPlayers();
    pdata.saveDeniedCommands();
    MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
    if (mdata.hasLoadouts()) {
        for (String loadout : mdata.getLoadouts()) {
            //				}
            for (Integer slot : mdata.getLoadout(loadout).getItems()) {
                globalLoadouts.getConfig().set(loadout + "." + slot, mdata.getLoadout(loadout).getItem(slot));
            }
            if (!mdata.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
                for (PotionEffect eff : mdata.getLoadout(loadout).getAllPotionEffects()) {
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
                }
            } else {
                globalLoadouts.getConfig().set(loadout + ".potions", null);
            }
            if (mdata.getLoadout(loadout).getUsePermissions()) {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
            } else {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
            }
        }
    } else {
        globalLoadouts.getConfig().set("globalloadouts", null);
    }
    globalLoadouts.saveConfig();
    mdata.saveRewardSigns();
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 9 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class Minigames method onEnable.

public void onEnable() {
    try {
        plugin = this;
        PluginDescriptionFile desc = this.getDescription();
        MinigameSave sv = new MinigameSave("lang/" + getConfig().getString("lang"));
        lang = sv.getConfig();
        loadLang();
        lang.setDefaults(defLang);
        getLogger().info("Using lang " + getConfig().getString("lang"));
        String prespath = getDataFolder() + "/presets/";
        String[] presets = { "spleef", "lms", "ctf", "infection" };
        File pres;
        for (String preset : presets) {
            pres = new File(prespath + preset + ".yml");
            if (!pres.exists()) {
                saveResource("presets/" + preset + ".yml", false);
            }
        }
        mdata = new MinigameData();
        pdata = new PlayerData();
        display = new DisplayManager();
        mdata.addMinigameType(new SingleplayerType());
        //		mdata.addMinigameType(new FreeForAllType());
        //		mdata.addMinigameType(new TeamsType());
        mdata.addMinigameType(new MultiplayerType());
        MinigameSave completion = new MinigameSave("completion");
        mdata.addConfigurationFile("completion", completion.getConfig());
        getServer().getPluginManager().registerEvents(new Events(), this);
        getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
        try {
            this.getConfig().load(this.getDataFolder() + "/config.yml");
            List<String> mgs = new ArrayList<String>();
            if (getConfig().contains("minigames")) {
                mgs = getConfig().getStringList("minigames");
            }
            final List<String> allMGS = new ArrayList<String>();
            allMGS.addAll(mgs);
            if (!mgs.isEmpty()) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        for (String minigame : allMGS) {
                            final Minigame game = new Minigame(minigame);
                            try {
                                game.loadMinigame();
                                mdata.addMinigame(game);
                            } catch (Exception e) {
                                getLogger().severe(ChatColor.RED.toString() + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
                                e.printStackTrace();
                            }
                        }
                    }
                }, 1L);
            }
        } catch (FileNotFoundException ex) {
            log.info("Failed to load config, creating one.");
            try {
                this.getConfig().save(this.getDataFolder() + "/config.yml");
            } catch (IOException e) {
                log.log(Level.SEVERE, "Could not save config.yml!");
                e.printStackTrace();
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to load config!");
            e.printStackTrace();
        }
        if (!setupEconomy()) {
            getLogger().info("No Vault plugin found! You may only reward items.");
        }
        backend = new BackendManager(getLogger());
        if (!backend.initialize(getConfig())) {
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        getConfig().options().copyDefaults(true);
        saveConfig();
        Calendar cal = Calendar.getInstance();
        if (cal.get(Calendar.DAY_OF_MONTH) == 21 && cal.get(Calendar.MONTH) == 8 || cal.get(Calendar.DAY_OF_MONTH) == 25 && cal.get(Calendar.MONTH) == 11 || cal.get(Calendar.DAY_OF_MONTH) == 1 && cal.get(Calendar.MONTH) == 0) {
            getLogger().info(ChatColor.GREEN.name() + "Party Mode enabled!");
            pdata.setPartyMode(true);
        }
        //		pdata.loadDCPlayers();
        pdata.loadDeniedCommands();
        MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
        Set<String> keys = globalLoadouts.getConfig().getKeys(false);
        for (String loadout : keys) {
            mdata.addLoadout(loadout);
            Set<String> items = globalLoadouts.getConfig().getConfigurationSection(loadout).getKeys(false);
            //			}
            for (String slot : items) {
                if (slot.matches("[0-9]+"))
                    mdata.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + "." + slot), Integer.parseInt(slot));
            }
            if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
                Set<String> pots = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions").getKeys(false);
                for (String eff : pots) {
                    if (PotionEffectType.getByName(eff) != null) {
                        PotionEffect effect = new PotionEffect(PotionEffectType.getByName(eff), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
                        mdata.getLoadout(loadout).addPotionEffect(effect);
                    }
                }
            }
            if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
                mdata.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
            }
        }
        minigameSigns = new SignBase();
        mdata.loadRewardSigns();
        CommandDispatcher disp = new CommandDispatcher();
        getCommand("minigame").setExecutor(disp);
        getCommand("minigame").setTabCompleter(disp);
        for (Player player : getServer().getOnlinePlayers()) {
            pdata.addMinigamePlayer(player);
        }
        initMetrics();
        log.info(desc.getName() + " successfully enabled.");
    } catch (Throwable e) {
        plugin = null;
        getLogger().log(Level.SEVERE, "Failed to enable Minigames " + getDescription().getVersion() + ": ", e);
        getPluginLoader().disablePlugin(this);
    }
}
Also used : SingleplayerType(au.com.mineauz.minigames.gametypes.SingleplayerType) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) BasicRecorder(au.com.mineauz.minigames.blockRecorder.BasicRecorder) MultiplayerType(au.com.mineauz.minigames.gametypes.MultiplayerType) CommandDispatcher(au.com.mineauz.minigames.commands.CommandDispatcher) Player(org.bukkit.entity.Player) Calendar(java.util.Calendar) IOException(java.io.IOException) BackendManager(au.com.mineauz.minigames.backend.BackendManager) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SignBase(au.com.mineauz.minigames.signs.SignBase) DisplayManager(au.com.mineauz.minigames.display.DisplayManager) Minigame(au.com.mineauz.minigames.minigame.Minigame) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Example 10 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class QuitCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args == null && sender instanceof Player) {
        MinigamePlayer player = plugin.pdata.getMinigamePlayer((Player) sender);
        if (player.isInMinigame()) {
            plugin.pdata.quitMinigame(player, false);
        } else {
            sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.notPlaying"));
        }
        return true;
    } else if (args != null) {
        Player player = null;
        if (sender instanceof Player) {
            player = (Player) sender;
        }
        if (player == null || player.hasPermission("minigame.quit.other")) {
            List<Player> players = plugin.getServer().matchPlayer(args[0]);
            MinigamePlayer ply = null;
            if (args[0].equals("ALL")) {
                if (args.length > 1) {
                    if (plugin.mdata.hasMinigame(args[1])) {
                        Minigame mg = plugin.mdata.getMinigame(args[1]);
                        List<MinigamePlayer> pls = new ArrayList<MinigamePlayer>(mg.getPlayers());
                        for (MinigamePlayer pl : pls) {
                            plugin.pdata.quitMinigame(pl, true);
                        }
                        sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitAllMinigame", mg.getName(true)));
                    } else {
                        sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("minigame.error.noMinigameName", args[1]));
                    }
                } else {
                    for (MinigamePlayer pl : plugin.getPlayerData().getAllMinigamePlayers()) {
                        if (pl.isInMinigame()) {
                            plugin.pdata.quitMinigame(pl, true);
                        }
                    }
                    sender.sendMessage(ChatColor.GRAY + MinigameUtils.getLang("command.quit.quitAll"));
                }
                return true;
            } else if (players.isEmpty()) {
                sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
                return true;
            } else {
                ply = plugin.pdata.getMinigamePlayer(players.get(0));
            }
            if (ply != null && ply.isInMinigame()) {
                plugin.pdata.quitMinigame(ply, false);
                sender.sendMessage(ChatColor.GRAY + MinigameUtils.formStr("command.quit.quitOther", ply.getName()));
            } else {
                sender.sendMessage(ChatColor.RED + MinigameUtils.formStr("command.quit.invalidPlayer", args[0]));
            }
        } else if (player != null) {
            sender.sendMessage(ChatColor.RED + MinigameUtils.getLang("command.quit.noPermissionOther"));
            sender.sendMessage(ChatColor.RED + "minigame.quit.other");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) List(java.util.List) ArrayList(java.util.ArrayList) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)64 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)33 EventHandler (org.bukkit.event.EventHandler)29 ArrayList (java.util.ArrayList)19 Player (org.bukkit.entity.Player)16 Team (au.com.mineauz.minigames.minigame.Team)15 List (java.util.List)7 Location (org.bukkit.Location)7 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)4 Sign (org.bukkit.block.Sign)4 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)3 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 PotionEffect (org.bukkit.potion.PotionEffect)3 CTFFlag (au.com.mineauz.minigames.CTFFlag)2 MinigameData (au.com.mineauz.minigames.MinigameData)2 MultiplayerTimer (au.com.mineauz.minigames.MultiplayerTimer)2 ICommand (au.com.mineauz.minigames.commands.ICommand)2 TakeFlagEvent (au.com.mineauz.minigames.events.TakeFlagEvent)2 ScoreboardDisplay (au.com.mineauz.minigames.minigame.ScoreboardDisplay)2