Search in sources :

Example 6 with MinigamePlayer

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

the class Events method playerRightClickEntity.

@EventHandler(ignoreCancelled = true)
private void playerRightClickEntity(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    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().onEntityRightClick(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) ItemStack(org.bukkit.inventory.ItemStack) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 7 with MinigamePlayer

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

the class Events method manualItemEntry.

@EventHandler
private void manualItemEntry(AsyncPlayerChatEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply.isInMenu() && ply.getNoClose() && ply.getManualEntry() != null) {
        event.setCancelled(true);
        ply.setNoClose(false);
        ply.getManualEntry().checkValidEntry(event.getMessage());
        ply.setManualEntry(null);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) EventHandler(org.bukkit.event.EventHandler)

Example 8 with MinigamePlayer

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

the class Events method playerSpawn.

@EventHandler(priority = EventPriority.HIGHEST)
private void playerSpawn(PlayerRespawnEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        final WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(ply.getMinigame());
        if (mod != null && mod.isUsingCustomWeather()) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> ply.getPlayer().setPlayerWeather(mod.getCustomWeather()));
        }
        if (ply.getMinigame().getState() == MinigameState.ENDED) {
            plugin.getPlayerManager().quitMinigame(ply, true);
        }
    }
    if (ply.isRequiredQuit()) {
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, ply::restorePlayerData);
        event.setRespawnLocation(ply.getQuitPos());
        ply.setRequiredQuit(false);
        ply.setQuitPos(null);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) WeatherTimeModule(au.com.mineauz.minigames.minigame.modules.WeatherTimeModule) EventHandler(org.bukkit.event.EventHandler)

Example 9 with MinigamePlayer

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

the class Events method onFlyToggle.

@EventHandler(ignoreCancelled = true)
public void onFlyToggle(PlayerToggleFlightEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && (!ply.getMinigame().isSpectator(ply) || !ply.getMinigame().canSpectateFly()) && !ply.canFly()) {
        event.setCancelled(true);
        pdata.quitMinigame(ply, true);
        event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noFly"));
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) EventHandler(org.bukkit.event.EventHandler)

Example 10 with MinigamePlayer

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

the class Events method playerShoot.

@EventHandler(ignoreCancelled = true)
private void playerShoot(ProjectileLaunchEvent event) {
    if (event.getEntityType() == EntityType.SNOWBALL) {
        Snowball snowball = (Snowball) event.getEntity();
        if (snowball.getShooter() != null && snowball.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) snowball.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ItemStack mainhand = ply.getPlayer().getInventory().getItemInMainHand();
                if (mainhand.getType() == Material.SNOW_BLOCK) {
                    mainhand.setAmount(16);
                    // todo
                    ply.getPlayer().updateInventory();
                } else {
                    ply.getPlayer().getInventory().addItem(new ItemStack(Material.SNOWBALL, 1));
                }
            }
        }
    } else if (event.getEntityType() == EntityType.EGG) {
        Egg egg = (Egg) event.getEntity();
        if (egg.getShooter() != null && egg.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) egg.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ply.getPlayer().getInventory().addItem(new ItemStack(Material.EGG));
            }
        }
    }
}
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) ItemStack(org.bukkit.inventory.ItemStack) 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