Search in sources :

Example 1 with MinigameType

use of au.com.mineauz.minigames.gametypes.MinigameType in project Minigames by AddstarMC.

the class PlayerData method joinMinigame.

public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
    MinigameType type = minigame.getType();
    JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    boolean canStart = minigame.getMechanic().checkCanStart(minigame, player);
    if (!event.isCancelled()) {
        if ((minigame.isEnabled() || player.getPlayer().hasPermission("minigame.join.disabled")) && (minigame.getState() == MinigameState.IDLE || minigame.getState() == MinigameState.OCCUPIED || minigame.getState() == MinigameState.WAITING || (minigame.getState() == MinigameState.STARTED && minigame.canLateJoin())) && /*!minigame.isRegenerating() && 
					(!minigame.isNotWaitingForPlayers() || (minigame.canLateJoin() && minigame.getMpTimer().getPlayerWaitTimeLeft() == 0)) &&*/
        (minigame.getStartLocations().size() > 0 || (minigame.isTeamGame() && TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) && minigame.getEndPosition() != null && minigame.getQuitPosition() != null && (minigame.getType() == MinigameType.SINGLEPLAYER || minigame.getLobbyPosition() != null) && ((type == MinigameType.SINGLEPLAYER && !minigame.isSpMaxPlayers()) || minigame.getPlayers().size() < minigame.getMaxPlayers()) && minigame.getMechanic().validTypes().contains(minigame.getType()) && canStart) {
            //Do betting stuff
            if (isBetting) {
                if (minigame.getMpBets() == null && (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR || betAmount != 0)) {
                    minigame.setMpBets(new MultiplayerBets());
                }
                MultiplayerBets pbet = minigame.getMpBets();
                ItemStack item = player.getPlayer().getInventory().getItemInMainHand().clone();
                if (pbet != null && ((betAmount != 0 && pbet.canBet(player, betAmount) && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) >= betAmount) || (pbet.canBet(player, item) && item.getType() != Material.AIR && pbet.betValue(item.getType()) > 0))) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.plyMsg"), null);
                    if (betAmount == 0) {
                        pbet.addBet(player, item);
                    } else {
                        pbet.addBet(player, betAmount);
                        plugin.getEconomy().withdrawPlayer(player.getPlayer().getPlayer(), betAmount);
                    }
                    player.getPlayer().getInventory().removeItem(new ItemStack(item.getType(), 1));
                } else if (item.getType() == Material.AIR && betAmount == 0) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.plyNoBet"), "error");
                    return;
                } else if (betAmount != 0 && !pbet.canBet(player, betAmount)) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.incorrectAmount"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.incorrectAmountInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
                    return;
                } else if (betAmount != 0 && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) < betAmount) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.notEnoughMoney"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.notEnoughMoneyInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
                    return;
                } else {
                    player.sendMessage(MinigameUtils.getLang("player.bet.incorrectItem"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.incorrectItemInfo", 1, minigame.getMpBets().highestBetName()), "error");
                    return;
                }
            }
            //Try teleport the player to their designated area.
            boolean tpd = false;
            if (type == MinigameType.SINGLEPLAYER) {
                List<Location> locs = new ArrayList<Location>(minigame.getStartLocations());
                Collections.shuffle(locs);
                tpd = player.teleport(locs.get(0));
                if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() && player.getPlayer().hasPermission("minigame.set.start")) {
                    player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Join location is across worlds! This may cause some server performance issues!", "error");
                }
            } else {
                tpd = player.teleport(minigame.getLobbyPosition());
                if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != minigame.getLobbyPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.lobby")) {
                    player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Lobby location is across worlds! This may cause some server performance issues!", "error");
                }
            }
            if (!tpd) {
                player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
                return;
            }
            //Give them the game type name
            if (minigame.getGametypeName() == null)
                player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), "win");
            else
                player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), "win");
            //Give them the objective
            if (minigame.getObjective() != null) {
                player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
                player.sendMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
                player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
            }
            //Prepare regeneration region for rollback.
            if (minigame.getBlockRecorder().hasRegenArea() && !minigame.getBlockRecorder().hasCreatedRegenBlocks()) {
                RecorderData d = minigame.getBlockRecorder();
                d.setCreatedRegenBlocks(true);
                Location cur = new Location(minigame.getRegenArea1().getWorld(), 0, 0, 0);
                for (double y = d.getRegenMinY(); y <= d.getRegenMaxY(); y++) {
                    cur.setY(y);
                    for (double x = d.getRegenMinX(); x <= d.getRegenMaxX(); x++) {
                        cur.setX(x);
                        for (double z = d.getRegenMinZ(); z <= d.getRegenMaxZ(); z++) {
                            cur.setZ(z);
                            d.addBlock(cur.getBlock(), null);
                        }
                    }
                }
            }
            //Standardize player
            player.storePlayerData();
            player.setMinigame(minigame);
            minigame.addPlayer(player);
            WeatherTimeModule.getMinigameModule(minigame).applyCustomTime(player);
            WeatherTimeModule.getMinigameModule(minigame).applyCustomWeather(player);
            player.setCheckpoint(player.getPlayer().getLocation());
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setWalkSpeed(0.2f);
            player.setStartTime(Calendar.getInstance().getTimeInMillis());
            player.setGamemode(minigame.getDefaultGamemode());
            if (minigame.getType() == MinigameType.SINGLEPLAYER) {
                if (!minigame.isAllowedFlight()) {
                    player.setCanFly(false);
                } else {
                    player.setCanFly(true);
                    if (minigame.isFlightEnabled())
                        player.getPlayer().setFlying(true);
                }
            } else {
                player.getPlayer().setAllowFlight(false);
            }
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            //Hide Spectators
            for (MinigamePlayer pl : minigame.getSpectators()) {
                player.getPlayer().hidePlayer(pl.getPlayer());
            }
            if (minigame.getPlayers().size() == 1) {
                //Register regen recorder events
                if (minigame.getBlockRecorder().hasRegenArea())
                    Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
                WeatherTimeModule.getMinigameModule(minigame).startTimeLoop();
            }
            //Call Type specific join
            mdata.minigameType(type).joinMinigame(player, minigame);
            //Call Mechanic specific join
            minigame.getMechanic().joinMinigame(minigame, player);
            //Send other players the join message.
            mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
            player.updateInventory();
            if (minigame.canDisplayScoreboard()) {
                player.getPlayer().setScoreboard(minigame.getScoreboardManager());
                minigame.setScore(player, 1);
                minigame.setScore(player, 0);
            }
        } else if (!minigame.isEnabled()) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.notEnabled"), "error");
        } else if (minigame.getState() == MinigameState.REGENERATING) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.regenerating"), "error");
        } else if (minigame.getState() == MinigameState.STARTED && !minigame.canLateJoin()) {
            player.sendMessage(MinigameUtils.getLang("minigame.started"), "error");
        } else if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin() && minigame.getPlayers().size() != minigame.getMaxPlayers()) {
            player.sendMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()), null);
        } else if (minigame.getStartLocations().size() == 0 || (minigame.isTeamGame() && !TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noStart"), "error");
        } else if (minigame.getEndPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), "error");
        } else if (minigame.getQuitPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), "error");
        } else if (minigame.getLobbyPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noLobby"), "error");
        } else if (minigame.getPlayers().size() >= minigame.getMaxPlayers()) {
            player.sendMessage(MinigameUtils.getLang("minigame.full"), "error");
        } else if (!minigame.getMechanic().validTypes().contains(minigame.getType())) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.invalidMechanic"), "error");
        } else if (!canStart) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.mechanicStartFail"), "error");
        }
    }
}
Also used : RecorderData(au.com.mineauz.minigames.blockRecorder.RecorderData) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) JoinMinigameEvent(au.com.mineauz.minigames.events.JoinMinigameEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 2 with MinigameType

use of au.com.mineauz.minigames.gametypes.MinigameType in project Minigames by AddstarMC.

the class Minigame method displayMenu.

public void displayMenu(MinigamePlayer player) {
    Menu main = new Menu(6, getName(false), player);
    Menu playerMenu = new Menu(6, getName(false), player);
    Menu loadouts = new Menu(6, getName(false), player);
    Menu flags = new Menu(6, getName(false), player);
    Menu lobby = new Menu(6, getName(false), player);
    List<MenuItem> itemsMain = new ArrayList<>();
    itemsMain.add(enabled.getMenuItem("Enabled", Material.PAPER));
    itemsMain.add(usePermissions.getMenuItem("Use Permissions", Material.PAPER));
    List<String> mgTypes = new ArrayList<>();
    for (MinigameType val : MinigameType.values()) {
        mgTypes.add(MinigameUtils.capitalize(val.toString().replace("_", " ")));
    }
    itemsMain.add(new MenuItemList("Game Type", Material.PAPER, getTypeCallback(), mgTypes));
    List<String> scoreTypes = new ArrayList<>();
    for (GameMechanicBase val : GameMechanics.getGameMechanics()) {
        scoreTypes.add(MinigameUtils.capitalize(val.getMechanic()));
    }
    itemsMain.add(new MenuItemList("Game Mechanic", MinigameUtils.stringToList("Multiplayer Only"), Material.ROTTEN_FLESH, new Callback<String>() {

        @Override
        public String getValue() {
            return MinigameUtils.capitalize(mechanic.getFlag());
        }

        @Override
        public void setValue(String value) {
            mechanic.setFlag(value.toLowerCase());
        }
    }, scoreTypes));
    final MenuItemCustom mechSettings = new MenuItemCustom("Game Mechanic Settings", Material.PAPER);
    final Minigame mgm = this;
    final Menu fmain = main;
    mechSettings.setClick(object -> {
        if (getMechanic().displaySettings(mgm) != null && getMechanic().displaySettings(mgm).displayMechanicSettings(fmain))
            return null;
        return mechSettings.getItem();
    });
    itemsMain.add(mechSettings);
    MenuItemString obj = (MenuItemString) objective.getMenuItem("Objective Description", Material.DIAMOND);
    obj.setAllowNull(true);
    itemsMain.add(obj);
    obj = (MenuItemString) gametypeName.getMenuItem("Gametype Description", Material.OAK_WALL_SIGN);
    obj.setAllowNull(true);
    itemsMain.add(obj);
    obj = (MenuItemString) displayName.getMenuItem("Display Name", Material.OAK_WALL_SIGN);
    obj.setAllowNull(true);
    itemsMain.add(obj);
    itemsMain.add(new MenuItemNewLine());
    itemsMain.add(minScore.getMenuItem("Min. Score", Material.STONE_SLAB, MinigameUtils.stringToList("Multiplayer " + "Only")));
    itemsMain.add(maxScore.getMenuItem("Max. Score", Material.STONE, MinigameUtils.stringToList("Multiplayer Only")));
    itemsMain.add(minPlayers.getMenuItem("Min. Players", Material.STONE_SLAB, MinigameUtils.stringToList("Multiplayer Only")));
    itemsMain.add(maxPlayers.getMenuItem("Max. Players", Material.STONE, MinigameUtils.stringToList("Multiplayer Only")));
    itemsMain.add(spMaxPlayers.getMenuItem("Enable Singleplayer Max Players", Material.IRON_BARS));
    itemsMain.add(displayScoreboard.getMenuItem("Display Scoreboard", Material.OAK_SIGN));
    itemsMain.add(new MenuItemPage("Lobby Settings", MinigameUtils.stringToList("Multiplayer Only"), Material.OAK_DOOR, lobby));
    itemsMain.add(new MenuItemNewLine());
    itemsMain.add(new MenuItemTime("Time Length", MinigameUtils.stringToList("Multiplayer Only"), Material.CLOCK, new Callback<Integer>() {

        @Override
        public Integer getValue() {
            return timer.getFlag();
        }

        @Override
        public void setValue(Integer value) {
            timer.setFlag(value);
        }
    }, 0, null));
    itemsMain.add(useXPBarTimer.getMenuItem("Use XP bar as Timer", Material.ENDER_PEARL));
    itemsMain.add(new MenuItemTime("Start Wait Time", MinigameUtils.stringToList("Multiplayer Only"), Material.CLOCK, new Callback<Integer>() {

        @Override
        public Integer getValue() {
            return startWaitTime.getFlag();
        }

        @Override
        public void setValue(Integer value) {
            startWaitTime.setFlag(value);
        }
    }, 3, null));
    itemsMain.add(showCompletionTime.getMenuItem("Show completion time", Material.PAPER));
    itemsMain.add(lateJoin.getMenuItem("Allow Late Join", Material.DEAD_BUSH, MinigameUtils.stringToList("Multiplayer Only")));
    itemsMain.add(randomizeStart.getMenuItem("Randomize Start Point", Material.LIGHT_BLUE_GLAZED_TERRACOTTA, MinigameUtils.stringToList("The location will be; chosen at random;from global or team lists.")));
    itemsMain.add(new MenuItemDisplayWhitelist("Block Whitelist/Blacklist", MinigameUtils.stringToList("Blocks that can/can't;be broken"), Material.CHEST, getBlockRecorder().getWBBlocks(), getBlockRecorder().getWhitelistModeCallback()));
    itemsMain.add(new MenuItemNewLine());
    List<String> floorDegenDes = new ArrayList<>();
    floorDegenDes.add("Mainly used to prevent");
    floorDegenDes.add("islanding in spleef Minigames.");
    List<String> floorDegenOpt = new ArrayList<>();
    floorDegenOpt.add("Inward");
    floorDegenOpt.add("Circle");
    floorDegenOpt.add("Random");
    itemsMain.add(new MenuItemList("Floor Degenerator Type", floorDegenDes, Material.SNOW_BLOCK, new Callback<String>() {

        @Override
        public String getValue() {
            return MinigameUtils.capitalize(degenType.getFlag());
        }

        @Override
        public void setValue(String value) {
            degenType.setFlag(value.toLowerCase());
        }
    }, floorDegenOpt));
    List<String> degenRandDes = new ArrayList<>();
    degenRandDes.add("Chance of block being");
    degenRandDes.add("removed on random");
    degenRandDes.add("degeneration.");
    itemsMain.add(degenRandomChance.getMenuItem("Random Floor Degen Chance", Material.SNOW, degenRandDes, 1, 100));
    itemsMain.add(floorDegenTime.getMenuItem("Floor Degenerator Delay", Material.CLOCK, 1, null));
    itemsMain.add(new MenuItemTime("Regeneration Delay", MinigameUtils.stringToList("Time in seconds before;" + "Minigame regeneration starts"), Material.CLOCK, new Callback<Integer>() {

        @Override
        public Integer getValue() {
            return regenDelay.getFlag();
        }

        @Override
        public void setValue(Integer value) {
            regenDelay.setFlag(value);
        }
    }, 0, null));
    itemsMain.add(new MenuItemNewLine());
    itemsMain.add(new MenuItemPage("Player Settings", Material.SKELETON_SKULL, playerMenu));
    List<String> thDes = new ArrayList<>();
    thDes.add("Treasure hunt related");
    thDes.add("settings.");
    // itemsMain.add(new MenuItemPage("Treasure Hunt Settings", thDes, Material.CHEST, treasureHunt));
    // MenuItemDisplayLoadout defLoad = new MenuItemDisplayLoadout("Default Loadout", Material.DIAMOND_SWORD, LoadoutModule.getMinigameModule(this).getDefaultPlayerLoadout(), this);
    // defLoad.setAllowDelete(false);
    // itemsMain.add(defLoad);
    itemsMain.add(new MenuItemPage("Loadouts", Material.CHEST, loadouts));
    itemsMain.add(canSpectateFly.getMenuItem("Allow Spectator Fly", Material.FEATHER));
    List<String> rndChstDes = new ArrayList<>();
    rndChstDes.add("Randomize items in");
    rndChstDes.add("chest upon first opening");
    itemsMain.add(randomizeChests.getMenuItem("Randomize Chests", Material.CHEST, rndChstDes));
    rndChstDes.clear();
    rndChstDes.add("Min. item randomization");
    itemsMain.add(minChestRandom.getMenuItem("Min. Chest Random", Material.OAK_STAIRS, rndChstDes, 0, null));
    rndChstDes.clear();
    rndChstDes.add("Max. item randomization");
    itemsMain.add(maxChestRandom.getMenuItem("Max. Chest Random", Material.STONE, rndChstDes, 0, null));
    itemsMain.add(new MenuItemStatisticsSettings(this, "Stat Settings", Material.WRITABLE_BOOK));
    itemsMain.add(new MenuItemNewLine());
    // --------------//
    // Loadout Settings
    // --------------//
    List<MenuItem> mi = new ArrayList<>();
    List<String> des = new ArrayList<>();
    des.add("Shift + Right Click to Delete");
    for (String ld : LoadoutModule.getMinigameModule(this).getLoadouts()) {
        Material item = Material.GLASS_PANE;
        if (LoadoutModule.getMinigameModule(this).getLoadout(ld).getItems().size() != 0) {
            item = LoadoutModule.getMinigameModule(this).getLoadout(ld).getItem((Integer) LoadoutModule.getMinigameModule(this).getLoadout(ld).getItems().toArray()[0]).getType();
        }
        if (LoadoutModule.getMinigameModule(this).getLoadout(ld).isDeleteable())
            mi.add(new MenuItemDisplayLoadout(ld, des, item, LoadoutModule.getMinigameModule(this).getLoadout(ld), this));
        else
            mi.add(new MenuItemDisplayLoadout(ld, item, LoadoutModule.getMinigameModule(this).getLoadout(ld), this));
    }
    loadouts.addItem(new MenuItemLoadoutAdd("Add Loadout", MenuUtility.getCreateMaterial(), LoadoutModule.getMinigameModule(this).getLoadoutMap(), this), 53);
    loadouts.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), main), loadouts.getSize() - 9);
    loadouts.addItems(mi);
    main.addItems(itemsMain);
    main.addItem(new MenuItemSaveMinigame("Save " + getName(false), MenuUtility.getSaveMaterial(), this), main.getSize() - 1);
    // ----------------------//
    // Minigame Player Settings
    // ----------------------//
    List<MenuItem> itemsPlayer = new ArrayList<>(20);
    List<String> gmopts = new ArrayList<>();
    for (GameMode gm : GameMode.values()) {
        gmopts.add(MinigameUtils.capitalize(gm.toString()));
    }
    itemsPlayer.add(new MenuItemList("Players Gamemode", Material.CRAFTING_TABLE, getDefaultGamemodeCallback(), gmopts));
    itemsPlayer.add(allowEnderpearls.getMenuItem("Allow Enderpearls", Material.ENDER_PEARL));
    itemsPlayer.add(itemDrops.getMenuItem("Allow Item Drops", Material.DIAMOND_SWORD));
    itemsPlayer.add(deathDrops.getMenuItem("Allow Death Drops", Material.SKELETON_SKULL));
    itemsPlayer.add(itemPickup.getMenuItem("Allow Item Pickup", Material.DIAMOND));
    itemsPlayer.add(blockBreak.getMenuItem("Allow Block Break", Material.DIAMOND_PICKAXE));
    itemsPlayer.add(blockPlace.getMenuItem("Allow Block Place", Material.STONE));
    itemsPlayer.add(blocksdrop.getMenuItem("Allow Block Drops", Material.COBBLESTONE));
    itemsPlayer.add(lives.getMenuItem("Lives", Material.APPLE, null));
    itemsPlayer.add(paintBallMode.getMenuItem("Paintball Mode", Material.SNOWBALL));
    itemsPlayer.add(paintBallDamage.getMenuItem("Paintball Damage", Material.ARROW, 1, null));
    itemsPlayer.add(unlimitedAmmo.getMenuItem("Unlimited Ammo", Material.SNOW_BLOCK));
    itemsPlayer.add(allowMPCheckpoints.getMenuItem("Enable Multiplayer Checkpoints", Material.OAK_SIGN));
    itemsPlayer.add(saveCheckpoints.getMenuItem("Save Checkpoints", Material.OAK_SIGN, MinigameUtils.stringToList("Singleplayer Only")));
    itemsPlayer.add(new MenuItemPage("Flags", MinigameUtils.stringToList("Singleplayer flags"), Material.OAK_SIGN, flags));
    itemsPlayer.add(allowFlight.getMenuItem("Allow Flight", Material.FEATHER, MinigameUtils.stringToList("Allow flight to;be toggled")));
    itemsPlayer.add(enableFlight.getMenuItem("Enable Flight", Material.FEATHER, MinigameUtils.stringToList("Start players;in flight;(Must have Allow;Flight)")));
    itemsPlayer.add(allowDragonEggTeleport.getMenuItem("Allow Dragon Egg Teleport", Material.DRAGON_EGG));
    itemsPlayer.add(usePlayerDisplayNames.getMenuItem("Use Players Display Names", Material.POTATO, MinigameUtils.stringToList("Use Player Nicks or Real Names")));
    itemsPlayer.add(showPlayerBroadcasts.getMenuItem("Show Join/Exit Broadcasts", Material.PAPER, MinigameUtils.stringToList("Show Join and Exit broadcasts; Plus other Player broadcasts")));
    playerMenu.addItems(itemsPlayer);
    playerMenu.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), main), main.getSize() - 9);
    // --------------//
    // Minigame Flags//
    // --------------//
    List<MenuItem> itemsFlags = new ArrayList<>(getFlags().size());
    for (String flag : getFlags()) {
        itemsFlags.add(new MenuItemFlag(Material.OAK_WALL_SIGN, flag, getFlags()));
    }
    flags.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), playerMenu), flags.getSize() - 9);
    flags.addItem(new MenuItemAddFlag("Add Flag", MenuUtility.getCreateMaterial(), this), flags.getSize() - 1);
    flags.addItems(itemsFlags);
    // --------------//
    // Lobby Settings//
    // --------------//
    List<MenuItem> itemsLobby = new ArrayList<>(4);
    itemsLobby.add(new MenuItemBoolean("Can Interact on Player Wait", Material.STONE_BUTTON, LobbySettingsModule.getMinigameModule(this).getCanInteractPlayerWaitCallback()));
    itemsLobby.add(new MenuItemBoolean("Can Interact on Start Wait", Material.STONE_BUTTON, LobbySettingsModule.getMinigameModule(this).getCanInteractStartWaitCallback()));
    itemsLobby.add(new MenuItemBoolean("Can Move on Player Wait", Material.ICE, LobbySettingsModule.getMinigameModule(this).getCanMovePlayerWaitCallback()));
    itemsLobby.add(new MenuItemBoolean("Can Move on Start Wait", Material.ICE, LobbySettingsModule.getMinigameModule(this).getCanMoveStartWaitCallback()));
    itemsLobby.add(new MenuItemBoolean("Teleport After Player Wait", MinigameUtils.stringToList("Should players be teleported;after player wait time?"), Material.ENDER_PEARL, LobbySettingsModule.getMinigameModule(this).getTeleportOnPlayerWaitCallback()));
    itemsLobby.add(new MenuItemBoolean("Teleport on Start", MinigameUtils.stringToList("Should players teleport;to the start position;after lobby?"), Material.ENDER_PEARL, LobbySettingsModule.getMinigameModule(this).getTeleportOnStartCallback()));
    itemsLobby.add(new MenuItemInteger("Waiting for Players Time", MinigameUtils.stringToList("The time in seconds;the game will wait for;more players to join.;A value of 0 will use;the config setting"), Material.CLOCK, LobbySettingsModule.getMinigameModule(this).getPlayerWaitTimeCallback(), 0, Integer.MAX_VALUE));
    lobby.addItems(itemsLobby);
    lobby.addItem(new MenuItemPage("Back", MenuUtility.getBackMaterial(), main), lobby.getSize() - 9);
    for (MinigameModule mod : getModules()) {
        mod.addEditMenuOptions(main);
    }
    main.displayMenu(player);
}
Also used : MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) MenuItemStatisticsSettings(au.com.mineauz.minigames.menu.MenuItemStatisticsSettings) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MenuItemAddFlag(au.com.mineauz.minigames.menu.MenuItemAddFlag) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) MenuItemSaveMinigame(au.com.mineauz.minigames.menu.MenuItemSaveMinigame) MenuItemLoadoutAdd(au.com.mineauz.minigames.menu.MenuItemLoadoutAdd) MenuItemTime(au.com.mineauz.minigames.menu.MenuItemTime) Menu(au.com.mineauz.minigames.menu.Menu) MenuItemInteger(au.com.mineauz.minigames.menu.MenuItemInteger) MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) MenuItemNewLine(au.com.mineauz.minigames.menu.MenuItemNewLine) MenuItem(au.com.mineauz.minigames.menu.MenuItem) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) Material(org.bukkit.Material) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MenuItemInteger(au.com.mineauz.minigames.menu.MenuItemInteger) MenuItemDisplayLoadout(au.com.mineauz.minigames.menu.MenuItemDisplayLoadout) GameMode(org.bukkit.GameMode) GameMechanicBase(au.com.mineauz.minigames.mechanics.GameMechanicBase) Callback(au.com.mineauz.minigames.menu.Callback) FutureCallback(com.google.common.util.concurrent.FutureCallback) MenuItemDisplayWhitelist(au.com.mineauz.minigames.menu.MenuItemDisplayWhitelist) MenuItemList(au.com.mineauz.minigames.menu.MenuItemList) MenuItemBoolean(au.com.mineauz.minigames.menu.MenuItemBoolean) MenuItemSaveMinigame(au.com.mineauz.minigames.menu.MenuItemSaveMinigame) MenuItemFlag(au.com.mineauz.minigames.menu.MenuItemFlag)

Example 3 with MinigameType

use of au.com.mineauz.minigames.gametypes.MinigameType in project Minigames by AddstarMC.

the class CreateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        Player player = (Player) sender;
        String mgmName = args[0];
        if (MinigameUtils.sanitizeYamlString(mgmName) == null) {
            throw new CommandException("Name is not valid for use in a Config.");
        }
        if (!plugin.getMinigameManager().hasMinigame(mgmName)) {
            MinigameType type = MinigameType.SINGLEPLAYER;
            if (args.length >= 2) {
                if (MinigameType.hasValue(args[1].toUpperCase())) {
                    type = MinigameType.valueOf(args[1].toUpperCase());
                } else {
                    MessageManager.sendMessage(player, MinigameMessageType.ERROR, null, "command.createMinigame.noName", args[1]);
                }
            }
            Minigame mgm = new Minigame(mgmName, type, player.getLocation());
            MessageManager.sendMessage(player, MinigameMessageType.INFO, null, "command.create.success", args[0]);
            List<String> mgs = null;
            if (plugin.getConfig().contains("minigames")) {
                mgs = plugin.getConfig().getStringList("minigames");
            } else {
                mgs = new ArrayList<>();
            }
            mgs.add(mgmName);
            plugin.getConfig().set("minigames", mgs);
            plugin.saveConfig();
            mgm.saveMinigame();
            plugin.getMinigameManager().addMinigame(mgm);
        } else {
            MessageManager.sendMessage(sender, MinigameMessageType.ERROR, null, "command.create.nameexists");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) CommandException(org.bukkit.command.CommandException) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 4 with MinigameType

use of au.com.mineauz.minigames.gametypes.MinigameType in project Minigames by AddstarMC.

the class MinigamePlayerManager method joinMinigame.

public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
    MinigameType type = minigame.getType();
    JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        Minigames.log.info("Start Event was cancelled..: " + event.toString());
        return;
    }
    if (!mgManager.minigameStartStateCheck(minigame, player))
        return;
    // Do betting stuff
    if (isBetting)
        handleBets(minigame, player, betAmount);
    // Try teleport the player to their designated area.
    ResourcePack pack = getResourcePack(minigame);
    if (pack != null && pack.isValid()) {
        if (player.applyResourcePack(pack))
            player.sendInfoMessage(MinigameUtils.getLang("minigame.resourcepack.apply"));
    }
    // Check if Minigame is full
    if (minigame.isGameFull()) {
        player.sendMessage(MinigameUtils.getLang("minigame.full"), MinigameMessageType.ERROR);
        return;
    }
    if (!mgManager.teleportPlayerOnJoin(minigame, player)) {
        player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), MinigameMessageType.ERROR);
        return;
    }
    // Give them the game type name
    if (minigame.getGametypeName() == null)
        player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), MinigameMessageType.WIN);
    else
        player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), MinigameMessageType.WIN);
    // Give them the objective
    if (minigame.getObjective() != null) {
        player.sendUnprefixedMessage(ChatColor.GREEN + "----------------------------------------------------");
        player.sendInfoMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
        player.sendUnprefixedMessage(ChatColor.GREEN + "----------------------------------------------------");
    }
    // Prepare regeneration region for rollback.
    mgManager.addBlockRecorderData(minigame);
    // Standardize player
    player.storePlayerData();
    player.setMinigame(minigame);
    minigame.addPlayer(player);
    WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(minigame);
    if (mod != null) {
        mod.applyCustomTime(player);
        mod.applyCustomWeather(player);
    }
    player.setCheckpoint(player.getPlayer().getLocation());
    player.getPlayer().setFallDistance(0);
    player.getPlayer().setWalkSpeed(0.2f);
    player.setStartTime(Calendar.getInstance().getTimeInMillis());
    player.setGamemode(minigame.getDefaultGamemode());
    player.getPlayer().setAllowFlight(false);
    for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
        player.getPlayer().removePotionEffect(potion.getType());
    }
    // Hide Spectators
    for (MinigamePlayer pl : minigame.getSpectators()) {
        player.getPlayer().hidePlayer(plugin, pl.getPlayer());
    }
    if (minigame.getPlayers().size() == 1) {
        // Register regen recorder events
        if (minigame.getBlockRecorder().hasRegenArea())
            Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
        if (mod != null)
            mod.startTimeLoop();
    }
    // Call Type specific join
    mgManager.minigameType(type).joinMinigame(player, minigame);
    // Call Mechanic specific join
    minigame.getMechanic().onJoinMinigame(minigame, player);
    // Send other players the join message.
    mgManager.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
    player.updateInventory();
    if (minigame.canDisplayScoreboard()) {
        player.getPlayer().setScoreboard(minigame.getScoreboardManager());
        minigame.setScore(player, 1);
        minigame.setScore(player, 0);
    }
    if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin()) {
        player.sendInfoMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()));
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) PotionEffect(org.bukkit.potion.PotionEffect) ResourcePack(au.com.mineauz.minigames.objects.ResourcePack) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType)

Example 5 with MinigameType

use of au.com.mineauz.minigames.gametypes.MinigameType in project Minigames by AddstarMC.

the class SetTypeCommand method getParameters.

@Override
public String[] getParameters() {
    String[] mgtypes = new String[plugin.getMinigameManager().getMinigameTypes().size() + 1];
    int inc = 0;
    for (MinigameType type : MinigameType.values()) {
        mgtypes[inc] = type.toString();
        inc++;
    }
    return mgtypes;
}
Also used : MinigameType(au.com.mineauz.minigames.gametypes.MinigameType)

Aggregations

MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)5 PotionEffect (org.bukkit.potion.PotionEffect)2 RecorderData (au.com.mineauz.minigames.blockRecorder.RecorderData)1 JoinMinigameEvent (au.com.mineauz.minigames.events.JoinMinigameEvent)1 GameMechanicBase (au.com.mineauz.minigames.mechanics.GameMechanicBase)1 Callback (au.com.mineauz.minigames.menu.Callback)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemAddFlag (au.com.mineauz.minigames.menu.MenuItemAddFlag)1 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemDisplayLoadout (au.com.mineauz.minigames.menu.MenuItemDisplayLoadout)1 MenuItemDisplayWhitelist (au.com.mineauz.minigames.menu.MenuItemDisplayWhitelist)1 MenuItemFlag (au.com.mineauz.minigames.menu.MenuItemFlag)1 MenuItemInteger (au.com.mineauz.minigames.menu.MenuItemInteger)1 MenuItemList (au.com.mineauz.minigames.menu.MenuItemList)1 MenuItemLoadoutAdd (au.com.mineauz.minigames.menu.MenuItemLoadoutAdd)1 MenuItemNewLine (au.com.mineauz.minigames.menu.MenuItemNewLine)1 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)1 MenuItemSaveMinigame (au.com.mineauz.minigames.menu.MenuItemSaveMinigame)1