Search in sources :

Example 71 with Minigame

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

the class Minigames method setupMinigames.

private void setupMinigames() {
    this.minigameManager = new MinigameManager();
    this.playerManager = new MinigamePlayerManager();
    this.display = new DisplayManager();
    this.resourceManager = new ResourcePackManager();
    final MinigameSave resources = new MinigameSave("resources");
    this.minigameManager.addConfigurationFile("resources", resources.getConfig());
    this.resourceManager.initialize(resources);
    this.minigameManager.addMinigameType(new SingleplayerType());
    this.minigameManager.addMinigameType(new MultiplayerType());
    final MinigameSave completion = new MinigameSave("completion");
    this.minigameManager.addConfigurationFile("completion", completion.getConfig());
    this.getServer().getPluginManager().registerEvents(new Events(), this);
    this.getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
    try {
        this.getConfig().load(this.getDataFolder() + "/config.yml");
        List<String> mgs = new ArrayList<>();
        if (this.getConfig().contains("minigames")) {
            mgs = this.getConfig().getStringList("minigames");
        }
        this.debug = this.getConfig().getBoolean("debug", false);
        final List<String> allMGS = new ArrayList<>(mgs);
        if (!mgs.isEmpty()) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
                for (final String minigame : allMGS) {
                    final Minigame game = new Minigame(minigame);
                    try {
                        game.loadMinigame();
                        this.minigameManager.addMinigame(game);
                    } catch (final Exception e) {
                        this.getLogger().severe(ChatColor.RED + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
                        e.printStackTrace();
                    }
                }
            }, 1L);
        }
    } catch (final FileNotFoundException ex) {
        log().info("Failed to load config, creating one.");
        try {
            this.getConfig().save(this.getDataFolder() + "/config.yml");
        } catch (final IOException e) {
            log().log(Level.SEVERE, "Could not save config.yml!");
            e.printStackTrace();
        }
    } catch (final Exception e) {
        log().log(Level.SEVERE, "Failed to load config!");
        e.printStackTrace();
    }
}
Also used : MinigamePlayerManager(au.com.mineauz.minigames.managers.MinigamePlayerManager) SingleplayerType(au.com.mineauz.minigames.gametypes.SingleplayerType) BasicRecorder(au.com.mineauz.minigames.blockRecorder.BasicRecorder) MinigameSave(au.com.mineauz.minigames.config.MinigameSave) MultiplayerType(au.com.mineauz.minigames.gametypes.MultiplayerType) MinigameManager(au.com.mineauz.minigames.managers.MinigameManager) DisplayManager(au.com.mineauz.minigames.display.DisplayManager) ResourcePackManager(au.com.mineauz.minigames.managers.ResourcePackManager) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 72 with Minigame

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

the class Events method onPlayerDeath.

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getEntity().getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        Minigame mgm = ply.getMinigame();
        if (!mgm.hasDeathDrops()) {
            event.getDrops().clear();
        }
        String msg = "";
        msg = event.getDeathMessage();
        event.setDeathMessage(null);
        event.setDroppedExp(0);
        ply.addDeath();
        ply.addRevert();
        pdata.partyMode(ply);
        if (ply.getPlayer().getKiller() != null) {
            MinigamePlayer killer = pdata.getMinigamePlayer(ply.getPlayer().getKiller());
            if (killer != null)
                killer.addKill();
        }
        if (!msg.equals("")) {
            mdata.sendMinigameMessage(mgm, msg, MinigameMessageType.ERROR);
        }
        if (mgm.getState() == MinigameState.STARTED) {
            if (mgm.getLives() > 0 && mgm.getLives() <= ply.getDeaths()) {
                ply.sendMessage(MinigameUtils.getLang("player.quit.plyOutOfLives"), MinigameMessageType.ERROR);
                if (!event.getDrops().isEmpty() && mgm.getPlayers().size() == 1) {
                    event.getDrops().clear();
                }
                pdata.quitMinigame(ply, false);
            } else if (mgm.getLives() > 0) {
                ply.sendInfoMessage(MinigameUtils.formStr("minigame.livesLeft", mgm.getLives() - ply.getDeaths()));
            }
        } else if (mgm.getState() == MinigameState.ENDED) {
            plugin.getPlayerManager().quitMinigame(ply, true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 73 with Minigame

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

the class Events method entityDamageEntity.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void entityDamageEntity(EntityDamageByEntityEvent event) {
    if (event.getEntity() instanceof Player) {
        if (event.getDamager() instanceof Snowball) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getEntity());
            if (ply == null)
                return;
            Snowball sb = (Snowball) event.getDamager();
            if (ply.isInMinigame() && ply.getMinigame().hasPaintBallMode()) {
                if (sb.getShooter() instanceof Player) {
                    MinigamePlayer shooter = pdata.getMinigamePlayer((Player) sb.getShooter());
                    Minigame mgm = ply.getMinigame();
                    if (shooter == null)
                        return;
                    if (shooter.isInMinigame() && shooter.getMinigame().equals(ply.getMinigame())) {
                        if (!shooter.canPvP()) {
                            event.setCancelled(true);
                            return;
                        }
                        Team plyTeam = ply.getTeam();
                        Team atcTeam = shooter.getTeam();
                        if (!mgm.isTeamGame() || plyTeam != atcTeam) {
                            int damage = mgm.getPaintBallDamage();
                            event.setDamage(damage);
                        }
                    }
                }
            }
        } else if (event.getDamager() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getDamager());
            if (ply == null)
                return;
            if (ply.isInMinigame() && !ply.canPvP())
                event.setCancelled(true);
            else if (ply.isInMinigame() && ply.getMinigame().getState() == MinigameState.ENDED && GameOverModule.getMinigameModule(ply.getMinigame()).isHumiliationMode() && GameOverModule.getMinigameModule(ply.getMinigame()).getLosers().contains(ply)) {
                event.setCancelled(true);
            }
        } else if (event.getDamager() instanceof Arrow) {
            Arrow arrow = (Arrow) event.getDamager();
            if (arrow.getShooter() instanceof Player) {
                Player ply = (Player) arrow.getShooter();
                MinigamePlayer mgpl = pdata.getMinigamePlayer(ply);
                if (mgpl == null)
                    return;
                if (mgpl.isInMinigame() && !mgpl.canPvP())
                    event.setCancelled(true);
            }
        }
    }
    if (event.getDamager() instanceof Player) {
        Player player = (Player) event.getDamager();
        MinigamePlayer ply = pdata.getMinigamePlayer(player);
        ItemStack item = player.getEquipment().getItemInMainHand();
        if (MinigameUtils.isMinigameTool(item) && player.hasPermission("minigame.tool")) {
            if (ply.isInMinigame()) {
                ply.sendInfoMessage("Quit the game to use the tool at this time");
                return;
            }
            MinigameTool tool = new MinigameTool(item);
            if (player.isSneaking()) {
                tool.openMenu(ply);
                event.setCancelled(true);
            } else {
                checkTool(tool, ply);
                if (tool.getMinigame() != null && tool.getMode() != null) {
                    Minigame mg = tool.getMinigame();
                    tool.getMode().onEntityLeftClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
                }
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) MinigameTool(au.com.mineauz.minigames.tool.MinigameTool) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 74 with Minigame

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

the class Events method onPlayerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConnect(PlayerJoinEvent event) {
    pdata.addMinigamePlayer(event.getPlayer());
    File pldata = new File(plugin.getDataFolder() + "/playerdata/inventories/" + event.getPlayer().getUniqueId().toString() + ".yml");
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (pldata.exists()) {
        ply.setOfflineMinigamePlayer(new OfflineMinigamePlayer(event.getPlayer().getUniqueId()));
        Location floc = ply.getOfflineMinigamePlayer().getLoginLocation();
        ply.setRequiredQuit(true);
        ply.setQuitPos(floc);
        if (!ply.getPlayer().isDead() && ply.isRequiredQuit()) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, ply::restorePlayerData);
            ply.teleport(ply.getQuitPos());
            ply.setRequiredQuit(false);
            ply.setQuitPos(null);
        }
        plugin.getLogger().info(ply.getName() + "'s data has been restored from file.");
    }
    ply.loadClaimedRewards();
    if (Bukkit.getServer().getOnlinePlayers().size() == 1) {
        for (Minigame mgm : mdata.getAllMinigames().values()) {
            if (mgm != null && mgm.getType() == MinigameType.GLOBAL) {
                if (mgm.getMinigameTimer() != null)
                    mgm.getMinigameTimer().startTimer();
            }
        }
    // for(String mgm : mdata.getAllMinigames().keySet()){
    // if(mdata.getMinigame(mgm).getType() == MinigameType.GLOBAL){
    // if(minigameManager.getMinigame(mgm).getThTimer() != null){
    // minigameManager.getMinigame(mgm).getThTimer().pauseTimer(false);
    // }
    // if(mdata.getMinigame(mgm).getMinigameTimer() != null)
    // mdata.getMinigame(mgm).getMinigameTimer().startTimer();
    // }
    // }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) File(java.io.File) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 75 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame 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 (ply.isInMenu() && ply.getNoClose() && ply.getManualEntry() != null) {
        event.setCancelled(true);
        ply.setNoClose(false);
        if (event.getClickedBlock() != null) {
            ply.getManualEntry().checkValidEntry(event.getClickedBlock().getBlockData().getAsString());
        }
        ply.setManualEntry(null);
        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()) {
                                StringBuilder sc = new StringBuilder();
                                int c = 0;
                                for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                    c++;
                                    sc.append(t.getColor().getColor().toString()).append(" ").append(t.getScore()).append(ChatColor.WHITE);
                                    if (c != TeamsModule.getMinigameModule(mgm).getTeams().size()) {
                                        sc.append(" : ");
                                    }
                                }
                                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<>();
                                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.OAK_WALL_SIGN || event.getClickedBlock().getType() == Material.OAK_SIGN)) {
            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.sendInfoMessage("Tools Minigame has been set to " + minigame);
                event.setCancelled(true);
            }
        } else {
            checkTool(tool, ply);
            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);
                }
            }
        }
    }
    // Spectator disables:
    if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) {
        event.setCancelled(true);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) 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

Minigame (au.com.mineauz.minigames.minigame.Minigame)75 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)42 EventHandler (org.bukkit.event.EventHandler)32 ArrayList (java.util.ArrayList)18 Team (au.com.mineauz.minigames.minigame.Team)16 Player (org.bukkit.entity.Player)14 Location (org.bukkit.Location)7 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)6 List (java.util.List)6 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)4 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)4 RegionModule (au.com.mineauz.minigamesregions.RegionModule)4 Sign (org.bukkit.block.Sign)4 ItemStack (org.bukkit.inventory.ItemStack)4 MinigameManager (au.com.mineauz.minigames.managers.MinigameManager)3 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)3 Block (org.bukkit.block.Block)3 PotionEffect (org.bukkit.potion.PotionEffect)3 MultiplayerTimer (au.com.mineauz.minigames.MultiplayerTimer)2 ICommand (au.com.mineauz.minigames.commands.ICommand)2