Search in sources :

Example 1 with MinigameTool

use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.

the class MinigameUtils method giveMinigameTool.

/**
	 * Gives the defined player a Minigame tool.
	 * @param player - The player to give the tool to.
	 * @return The Minigame Tool
	 */
public static MinigameTool giveMinigameTool(MinigamePlayer player) {
    Material toolMat = Material.getMaterial(Minigames.plugin.getConfig().getString("tool"));
    if (toolMat == null) {
        toolMat = Material.BLAZE_ROD;
        player.sendMessage("Invalid material type! Please check the configuration to see if it has been typed correctly! Default type given instead.", "error");
    }
    ItemStack tool = new ItemStack(toolMat);
    MinigameTool mgTool = new MinigameTool(tool);
    player.getPlayer().getInventory().addItem(mgTool.getTool());
    return mgTool;
}
Also used : MinigameTool(au.com.mineauz.minigames.tool.MinigameTool) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with MinigameTool

use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.

the class NodeToolMode method onSetMode.

@Override
public void onSetMode(final MinigamePlayer player, MinigameTool tool) {
    tool.addSetting("Node", "None");
    final Menu m = new Menu(2, "Node Selection", player);
    if (player.isInMenu()) {
        m.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, player.getMenu()), m.getSize() - 9);
    }
    final MinigameTool ftool = tool;
    m.addItem(new MenuItemString("Node Name", Material.PAPER, new Callback<String>() {

        @Override
        public void setValue(String value) {
            ftool.changeSetting("Node", value);
        }

        @Override
        public String getValue() {
            return ftool.getSetting("Node");
        }
    }));
    if (tool.getMinigame() != null) {
        // Node selection menu
        RegionModule module = RegionModule.getMinigameModule(tool.getMinigame());
        Menu nodeMenu = new Menu(6, "Nodes", player);
        List<MenuItem> items = new ArrayList<MenuItem>();
        for (final Node node : module.getNodes()) {
            MenuItemCustom item = new MenuItemCustom(node.getName(), Material.STONE_BUTTON);
            // Set the node and go back to the main menu
            item.setClick(new InteractionInterface() {

                @Override
                public Object interact(Object object) {
                    ftool.changeSetting("Node", node.getName());
                    m.displayMenu(player);
                    return object;
                }
            });
            items.add(item);
        }
        nodeMenu.addItems(items);
        nodeMenu.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, m), nodeMenu.getSize() - 9);
        m.addItem(new MenuItemPage("Edit Node", Material.STONE_BUTTON, nodeMenu));
    }
    m.displayMenu(player);
}
Also used : MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) MinigameTool(au.com.mineauz.minigames.tool.MinigameTool) ArrayList(java.util.ArrayList) MenuItem(au.com.mineauz.minigames.menu.MenuItem) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) Callback(au.com.mineauz.minigames.menu.Callback) InteractionInterface(au.com.mineauz.minigames.menu.InteractionInterface) Menu(au.com.mineauz.minigames.menu.Menu)

Example 3 with MinigameTool

use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.

the class MenuItemToolMode method onClick.

public ItemStack onClick() {
    MinigamePlayer ply = getContainer().getViewer();
    if (MinigameUtils.hasMinigameTool(ply)) {
        MinigameTool tool = MinigameUtils.getMinigameTool(ply);
        if (tool.getMode() != null)
            tool.getMode().onUnsetMode(ply, tool);
        tool.setMode(mode);
        tool.getMode().onSetMode(ply, tool);
    }
    return getItem();
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MinigameTool(au.com.mineauz.minigames.tool.MinigameTool)

Example 4 with MinigameTool

use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.

the class MenuItemToolTeam method onClick.

@Override
public ItemStack onClick() {
    super.onClick();
    MinigamePlayer ply = getContainer().getViewer();
    if (MinigameUtils.hasMinigameTool(ply)) {
        MinigameTool tool = MinigameUtils.getMinigameTool(ply);
        tool.setTeam(TeamColor.matchColor(value.getValue().replace(" ", "_")));
    }
    return getItem();
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MinigameTool(au.com.mineauz.minigames.tool.MinigameTool)

Example 5 with MinigameTool

use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.

the class Events method playerInterract.

@EventHandler
public void playerInterract(PlayerInteractEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && !ply.canInteract()) {
        event.setCancelled(true);
        return;
    }
    if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.DRAGON_EGG) {
        if (!ply.getMinigame().allowDragonEggTeleport()) {
            event.setCancelled(true);
            return;
        }
    }
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.getPlayer().hasPermission("minigame.sign.use.details")) {
        Block cblock = event.getClickedBlock();
        if (cblock.getState() instanceof Sign && !event.isCancelled()) {
            Sign sign = (Sign) cblock.getState();
            if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Minigame]")) {
                if ((sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Join") || sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Bet")) && !ply.isInMinigame()) {
                    Minigame mgm = mdata.getMinigame(sign.getLine(2));
                    if (mgm != null && (!mgm.getUsePermissions() || event.getPlayer().hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
                        if (!mgm.isEnabled()) {
                            event.getPlayer().sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.notEnabled"));
                        } else {
                            event.getPlayer().sendMessage(ChatColor.GREEN + MinigameUtils.getLang("minigame.info.description"));
                            String status = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.status.title");
                            if (!mgm.hasPlayers()) {
                                status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.empty");
                            } else if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() > 0) {
                                status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.waitingForPlayers");
                            } else {
                                status += " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.status.started");
                            }
                            if (mgm.getType() != MinigameType.SINGLEPLAYER) {
                                event.getPlayer().sendMessage(status);
                                if (mgm.canLateJoin())
                                    event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.lateJoin.enabled"));
                                else
                                    event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.lateJoin.disabled"));
                            }
                            if (mgm.getMinigameTimer() != null) {
                                event.getPlayer().sendMessage(ChatColor.AQUA + "Time left: " + MinigameUtils.convertTime(mgm.getMinigameTimer().getTimeLeft()));
                            }
                            if (mgm.isTeamGame()) {
                                String sc = "";
                                int c = 0;
                                for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                    c++;
                                    sc += t.getColor().getColor().toString() + " " + t.getScore() + ChatColor.WHITE;
                                    if (c != TeamsModule.getMinigameModule(mgm).getTeams().size()) {
                                        sc += " : ";
                                    }
                                }
                                event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.score") + sc);
                            }
                            String playerCount = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.playerCount") + " " + ChatColor.GRAY;
                            String players = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.players.msg") + " ";
                            if (mgm.hasPlayers()) {
                                playerCount += mgm.getPlayers().size();
                                if (mgm.getType() != MinigameType.SINGLEPLAYER) {
                                    playerCount += "/" + mgm.getMaxPlayers();
                                }
                                List<String> plyList = new ArrayList<String>();
                                for (MinigamePlayer pl : mgm.getPlayers()) {
                                    plyList.add(pl.getName());
                                }
                                players += MinigameUtils.listToString(plyList);
                            } else {
                                playerCount += "0";
                                if (mgm.getType() != MinigameType.SINGLEPLAYER) {
                                    playerCount += "/" + mgm.getMaxPlayers();
                                }
                                players += ChatColor.GRAY + MinigameUtils.getLang("minigame.info.players.none");
                            }
                            event.getPlayer().sendMessage(playerCount);
                            event.getPlayer().sendMessage(players);
                        }
                    } else if (mgm == null) {
                        event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noMinigame"));
                    } else if (mgm.getUsePermissions()) {
                        event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.formStr("minigame.error.noPermission", "minigame.join." + mgm.getName(false).toLowerCase()));
                    }
                }
            }
        }
    }
    ItemStack item = event.getItem();
    if (item != null && MinigameUtils.isMinigameTool(item) && ply.getPlayer().hasPermission("minigame.tool")) {
        MinigameTool tool = new MinigameTool(item);
        event.setCancelled(true);
        if (event.getPlayer().isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
            tool.openMenu(ply);
            event.setCancelled(true);
        } else if (event.getClickedBlock() != null && (event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST)) {
            Sign sign = (Sign) event.getClickedBlock().getState();
            if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("[Minigame]") && ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase("Join")) {
                Minigame minigame = mdata.getMinigame(sign.getLine(2));
                tool.setMinigame(minigame);
                ply.sendMessage("Tools Minigame has been set to " + minigame, null);
                event.setCancelled(true);
            }
        } else if (tool.getMode() != null && tool.getMinigame() != null) {
            Minigame mg = tool.getMinigame();
            if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                tool.getMode().onRightClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
            } else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
                tool.getMode().onLeftClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
            }
        } else if (tool.getMinigame() == null) {
            ply.sendMessage("Please select a minigame. Click on the join sign, or /mg tool minigame <minigame>", null);
        } else if (tool.getMode() == null) {
            ply.sendMessage("Please select a tool mode. Shift + Right click", null);
        }
    }
    //Spectator disables:
    if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) {
        event.setCancelled(true);
    }
}
Also used : ArrayList(java.util.ArrayList) MinigameTool(au.com.mineauz.minigames.tool.MinigameTool) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)8 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)4 ArrayList (java.util.ArrayList)3 Callback (au.com.mineauz.minigames.menu.Callback)2 InteractionInterface (au.com.mineauz.minigames.menu.InteractionInterface)2 Menu (au.com.mineauz.minigames.menu.Menu)2 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)2 MenuItemPage (au.com.mineauz.minigames.menu.MenuItemPage)2 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 ItemStack (org.bukkit.inventory.ItemStack)2 Team (au.com.mineauz.minigames.minigame.Team)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 Sign (org.bukkit.block.Sign)1 EventHandler (org.bukkit.event.EventHandler)1