Search in sources :

Example 1 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class Events method onPlayerDisconnect.

@EventHandler
public void onPlayerDisconnect(PlayerQuitEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply.isInMinigame()) {
        if (ply.getPlayer().isDead()) {
            ply.getOfflineMinigamePlayer().setLoginLocation(ply.getMinigame().getQuitPosition());
            ply.getOfflineMinigamePlayer().savePlayerData();
        }
        pdata.quitMinigame(pdata.getMinigamePlayer(event.getPlayer()), false);
    } else if (ply.isRequiredQuit()) {
        ply.getOfflineMinigamePlayer().setLoginLocation(ply.getQuitPos());
        ply.getOfflineMinigamePlayer().savePlayerData();
    }
    pdata.removeMinigamePlayer(event.getPlayer());
    plugin.display.removeAll(event.getPlayer());
    if (Bukkit.getServer().getOnlinePlayers().isEmpty()) {
        for (String mgm : mdata.getAllMinigames().keySet()) {
            if (mdata.getMinigame(mgm).getType() == MinigameType.GLOBAL) {
                if (mdata.getMinigame(mgm).getMinigameTimer() != null)
                    mdata.getMinigame(mgm).getMinigameTimer().stopTimer();
            }
        }
    }
    ply.saveClaimedRewards();
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class MinigameTimer method runTimer.

private void runTimer() {
    time -= 1;
    if (minigame.isUsingXPBarTimer()) {
        float timeper = ((Integer) time).floatValue() / ((Integer) otime).floatValue();
        int level = 0;
        if (time / 60 > 0)
            level = time / 60;
        else
            level = time;
        for (MinigamePlayer ply : minigame.getPlayers()) {
            if (timeper < 0) {
                ply.getPlayer().setExp(0);
                ply.getPlayer().setLevel(0);
            } else {
                ply.getPlayer().setExp(timeper);
                ply.getPlayer().setLevel(level);
            }
        }
    }
    if (timeMsg.contains(time) && broadcastTime) {
        PlayMGSound.playSound(minigame, MGSounds.getSound("timerTick"));
        plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameUtils.formStr("minigame.timeLeft", MinigameUtils.convertTime(time)));
    }
    if (time <= 0) {
        Bukkit.getServer().getPluginManager().callEvent(new TimerExpireEvent(minigame));
        stopTimer();
    }
    if (time > 0)
        Bukkit.getPluginManager().callEvent(new MinigameTimerTickEvent(minigame, minigame.getMinigameTimer()));
}
Also used : TimerExpireEvent(au.com.mineauz.minigames.events.TimerExpireEvent) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigameTimerTickEvent(au.com.mineauz.minigames.events.MinigameTimerTickEvent)

Example 3 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class Minigames method initMetrics.

private void initMetrics() {
    this.metrics = new Metrics(this, 1190);
    final Metrics.MultiLineChart chart = new Metrics.MultiLineChart("Players_in_Minigames", () -> {
        final Map<String, Integer> result = new HashMap<>();
        result.put("Total_Players", this.playerManager.getAllMinigamePlayers().size());
        for (final MinigamePlayer pl : this.playerManager.getAllMinigamePlayers()) {
            if (pl.isInMinigame()) {
                int count = result.getOrDefault(pl.getMinigame().getType().getName(), 0);
                result.put(pl.getMinigame().getType().getName(), count + 1);
            }
        }
        return result;
    });
    final Metrics.SimpleBarChart barChart = new Metrics.SimpleBarChart("Modules_v_Servers", () -> {
        final Map<String, Integer> result = new HashMap<>();
        for (final Class module : this.minigameManager.getModules()) {
            result.put(module.getCanonicalName(), 1);
        }
        return result;
    });
    this.metrics.addCustomChart(chart);
    this.metrics.addCustomChart(barChart);
}
Also used : Metrics(org.bstats.bukkit.Metrics) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer)

Example 4 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class Events method onTeleportAway.

@EventHandler
public void onTeleportAway(PlayerTeleportEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && (event.getCause() == TeleportCause.COMMAND || event.getCause() == TeleportCause.PLUGIN || (!ply.getMinigame().isAllowedEnderpearls() && event.getCause() == TeleportCause.ENDER_PEARL))) {
        if (!ply.getAllowTeleport()) {
            Location from = event.getFrom();
            Location to = event.getTo();
            if (from.getWorld() != to.getWorld() || from.distance(to) > 2) {
                event.setCancelled(true);
                event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noTeleport"));
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class Events method itemPickup.

@EventHandler(ignoreCancelled = true)
public void itemPickup(EntityPickupItemEvent event) {
    if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        MinigamePlayer ply = pdata.getMinigamePlayer(player);
        if (ply.isInMinigame()) {
            Minigame mgm = ply.getMinigame();
            if (!mgm.hasItemPickup() || mgm.isSpectator(ply)) {
                event.setCancelled(true);
            }
        }
    }
}
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) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)134 EventHandler (org.bukkit.event.EventHandler)46 Minigame (au.com.mineauz.minigames.minigame.Minigame)40 ArrayList (java.util.ArrayList)25 Team (au.com.mineauz.minigames.minigame.Team)24 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)15 Player (org.bukkit.entity.Player)15 Location (org.bukkit.Location)11 ItemStack (org.bukkit.inventory.ItemStack)8 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)7 Menu (au.com.mineauz.minigames.menu.Menu)5 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)5 List (java.util.List)5 PotionEffect (org.bukkit.potion.PotionEffect)5 ResourcePack (au.com.mineauz.minigames.objects.ResourcePack)4 Material (org.bukkit.Material)4 Sign (org.bukkit.block.Sign)4 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)3 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)2