Search in sources :

Example 31 with User

use of org.neo4j.ogm.domain.gh368.User in project Village_Defense by Plajer.

the class ArenaEvents method onDeath.

private void onDeath(final Player player, Arena arena) {
    if (arena.getArenaState() == ArenaState.STARTING) {
        player.teleport(arena.getStartLocation());
        return;
    }
    if (arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) {
        player.getInventory().clear();
        player.setFlying(false);
        player.setAllowFlight(false);
        User user = UserManager.getUser(player.getUniqueId());
        user.setInt("orbs", 0);
        player.teleport(arena.getEndLocation());
        return;
    }
    User user = UserManager.getUser(player.getUniqueId());
    arena.addStat(player, "deaths");
    arena.teleportToStartLocation(player);
    user.setSpectator(true);
    player.setGameMode(GameMode.SURVIVAL);
    user.setFakeDead(true);
    user.setInt("orbs", 0);
    ArenaUtils.hidePlayer(player, arena);
    player.setAllowFlight(true);
    player.getInventory().clear();
    MessageHandler.sendTitle(player, ChatColor.stripColor(ChatManager.formatMessage(arena, "In-Game.Death-Screen")), 0, 5 * 20, 0, ChatColor.RED);
    if (plugin.is1_9_R1() || plugin.is1_11_R1() || plugin.is1_12_R1()) {
        new BukkitRunnable() {

            @Override
            public void run() {
                if (user.isSpectator())
                    player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatManager.formatMessage(arena, ChatManager.colorMessage("In-Game.Died-Respawn-In-Next-Wave"))));
                else
                    this.cancel();
            }
        }.runTaskTimer(plugin, 20, 20);
    }
    ChatManager.broadcastDeathMessage(arena, player);
    arena.teleportToStartLocation(player);
    player.setAllowFlight(true);
    player.setFlying(true);
    ItemStack spectatorItem = new ItemStack(Material.COMPASS, 1);
    ItemMeta spectatorMeta = spectatorItem.getItemMeta();
    spectatorMeta.setDisplayName(ChatManager.colorMessage("In-Game.Spectator.Spectator-Item-Name"));
    spectatorItem.setItemMeta(spectatorMeta);
    player.getInventory().setItem(0, spectatorItem);
    player.getInventory().setItem(8, SpecialItemManager.getSpecialItem("Leave").getItemStack());
    // tryin to untarget dead player bcuz they will still target him
    for (Zombie zombie : arena.getZombies()) {
        if (zombie.getTarget() != null) {
            if (zombie.getTarget().equals(player)) {
                // set new target as villager so zombies won't stay still waiting for nothing
                for (Villager villager : arena.getVillagers()) {
                    zombie.setTarget(villager);
                }
            }
        }
    }
}
Also used : User(pl.plajer.villagedefense3.User) Zombie(org.bukkit.entity.Zombie) Villager(org.bukkit.entity.Villager) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 32 with User

use of org.neo4j.ogm.domain.gh368.User in project Village_Defense by Plajer.

the class Arena method joinAttempt.

/**
 * Attempts player to join arena.
 * Calls VillageGameJoinAttemptEvent.
 * Can be cancelled only via above-mentioned event
 *
 * @param p player to join
 * @see VillageGameJoinAttemptEvent
 */
public void joinAttempt(Player p) {
    VillageGameJoinAttemptEvent villageGameJoinAttemptEvent = new VillageGameJoinAttemptEvent(p, this);
    Bukkit.getPluginManager().callEvent(villageGameJoinAttemptEvent);
    if (!isReady) {
        p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Arena-Not-Configured"));
        return;
    }
    if (villageGameJoinAttemptEvent.isCancelled()) {
        p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Join-Cancelled-Via-API"));
        return;
    }
    if (!plugin.isBungeeActivated()) {
        if (!(p.hasPermission(PermissionsManager.getJoinPerm().replaceAll("<arena>", "*")) || p.hasPermission(PermissionsManager.getJoinPerm().replaceAll("<arena>", this.getID())))) {
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Join-No-Permission"));
            return;
        }
    }
    if (Main.isDebugged()) {
        System.out.println("[Village Debugger] Player " + p.getName() + " attemping to join arena!");
    }
    if ((getArenaState() == ArenaState.IN_GAME || (getArenaState() == ArenaState.STARTING && getTimer() <= 3) || getArenaState() == ArenaState.ENDING)) {
        if (plugin.isInventoryManagerEnabled()) {
            p.setLevel(0);
            plugin.getInventoryManager().saveInventoryToFile(p);
        }
        this.teleportToStartLocation(p);
        p.sendMessage(ChatManager.colorMessage("In-Game.You-Are-Spectator"));
        p.getInventory().clear();
        ItemStack spectatorItem = new ItemStack(Material.COMPASS, 1);
        ItemMeta spectatorMeta = spectatorItem.getItemMeta();
        spectatorMeta.setDisplayName(ChatManager.colorMessage("In-Game.Spectator.Spectator-Item-Name"));
        spectatorItem.setItemMeta(spectatorMeta);
        p.getInventory().setItem(0, spectatorItem);
        p.getInventory().setItem(8, SpecialItemManager.getSpecialItem("Leave").getItemStack());
        for (PotionEffect potionEffect : p.getActivePotionEffects()) {
            p.removePotionEffect(potionEffect.getType());
        }
        this.addPlayer(p);
        p.setMaxHealth(p.getMaxHealth() + rottenFleshLevel);
        p.setHealth(p.getMaxHealth());
        p.setFoodLevel(20);
        p.setGameMode(GameMode.SURVIVAL);
        p.setAllowFlight(true);
        p.setFlying(true);
        User user = UserManager.getUser(p.getUniqueId());
        user.setSpectator(true);
        user.setFakeDead(true);
        user.setInt("orbs", 0);
        p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1));
        ArenaUtils.hidePlayer(p, this);
        for (Player spectator : this.getPlayers()) {
            if (UserManager.getUser(spectator.getUniqueId()).isSpectator()) {
                p.hidePlayer(spectator);
            } else {
                p.showPlayer(spectator);
            }
        }
        ArenaUtils.hidePlayersOutsideTheGame(p, this);
        return;
    }
    if (plugin.isInventoryManagerEnabled()) {
        p.setLevel(0);
        plugin.getInventoryManager().saveInventoryToFile(p);
    }
    teleportToLobby(p);
    this.addPlayer(p);
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20);
    p.getInventory().setArmorContents(new ItemStack[] { new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR) });
    p.setFlying(false);
    p.setAllowFlight(false);
    p.getInventory().clear();
    showPlayers();
    if (plugin.isBossbarEnabled()) {
        gameBar.addPlayer(p);
    }
    if (!UserManager.getUser(p.getUniqueId()).isSpectator())
        ChatManager.broadcastJoinMessage(this, p);
    User user = UserManager.getUser(p.getUniqueId());
    user.setKit(KitRegistry.getDefaultKit());
    plugin.getKitManager().giveKitMenuItem(p);
    if (getArenaState() == ArenaState.STARTING || getArenaState() == ArenaState.WAITING_FOR_PLAYERS)
        p.getInventory().setItem(SpecialItemManager.getSpecialItem("Leave").getSlot(), SpecialItemManager.getSpecialItem("Leave").getItemStack());
    p.updateInventory();
    for (Player player : getPlayers()) {
        ArenaUtils.showPlayer(player, this);
    }
    showPlayers();
}
Also used : Player(org.bukkit.entity.Player) User(pl.plajer.villagedefense3.User) VillageGameJoinAttemptEvent(pl.plajer.villagedefense3.villagedefenseapi.VillageGameJoinAttemptEvent) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 33 with User

use of org.neo4j.ogm.domain.gh368.User in project Village_Defense by Plajer.

the class Arena method addStat.

void addStat(Player player, String stat) {
    User user = UserManager.getUser(player.getUniqueId());
    user.addInt(stat, 1);
    ArenaUtils.updateLevelStat(player, this);
}
Also used : User(pl.plajer.villagedefense3.User)

Example 34 with User

use of org.neo4j.ogm.domain.gh368.User in project Village_Defense by Plajer.

the class Arena method run.

public void run() {
    User.handleCooldowns();
    ArenaUtils.updateScoreboard(this);
    switch(getArenaState()) {
        case WAITING_FOR_PLAYERS:
            if (plugin.isBungeeActivated())
                plugin.getServer().setWhitelist(false);
            if (getPlayers().size() < getMinimumPlayers()) {
                if (getTimer() <= 0) {
                    setTimer(15);
                    String message = ChatManager.formatMessage(this, ChatManager.colorMessage("In-Game.Messages.Lobby-Messages.Waiting-For-Players"), getMinimumPlayers());
                    for (Player player1 : getPlayers()) {
                        player1.sendMessage(ChatManager.PLUGIN_PREFIX + message);
                    }
                    return;
                }
            } else {
                if (plugin.isBossbarEnabled()) {
                    gameBar.setTitle(ChatManager.colorMessage("Bossbar.Waiting-For-Players"));
                }
                for (Player p : getPlayers()) {
                    p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Lobby-Messages.Enough-Players-To-Start"));
                }
                setArenaState(ArenaState.STARTING);
                setTimer(Main.STARTING_TIMER_TIME);
                this.showPlayers();
            }
            setTimer(getTimer() - 1);
            break;
        case STARTING:
            if (plugin.isBossbarEnabled()) {
                gameBar.setTitle(ChatManager.colorMessage("Bossbar.Starting-In").replaceAll("%time%", String.valueOf(getTimer())));
                gameBar.setProgress(getTimer() / plugin.getConfig().getDouble("Starting-Waiting-Time"));
            }
            if (getTimer() == 0) {
                VillageGameStartEvent villageGameStartEvent = new VillageGameStartEvent(this);
                Bukkit.getPluginManager().callEvent(villageGameStartEvent);
                setArenaState(ArenaState.IN_GAME);
                if (plugin.isBossbarEnabled()) {
                    gameBar.setProgress(1.0);
                }
                setTimer(5);
                teleportAllToStartLocation();
                for (Player player : getPlayers()) {
                    player.getInventory().clear();
                    player.setGameMode(GameMode.SURVIVAL);
                    UserManager.getUser(player.getUniqueId()).setInt("orbs", plugin.getConfig().getInt("Orbs-Starting-Amount"));
                    ArenaUtils.hidePlayersOutsideTheGame(player, this);
                    if (UserManager.getUser(player.getUniqueId()).getKit() != null) {
                        UserManager.getUser(player.getUniqueId()).getKit().giveKitItems(player);
                    } else {
                        KitRegistry.getDefaultKit().giveKitItems(player);
                    }
                    player.updateInventory();
                    addStat(player, "gamesplayed");
                    addExperience(player, 10);
                    setTimer(25);
                    player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Lobby-Messages.Game-Started"));
                }
                isFighting = false;
            }
            setTimer(getTimer() - 1);
            break;
        case IN_GAME:
            if (plugin.isBossbarEnabled()) {
                if (barToggle > 5) {
                    gameBar.setTitle(ChatManager.colorMessage("Bossbar.In-Game-Wave").replaceAll("%wave%", String.valueOf(getWave())));
                    barToggle++;
                    if (barToggle > 10) {
                        barToggle = 0;
                    }
                } else {
                    gameBar.setTitle(ChatManager.colorMessage("Bossbar.In-Game-Info").replaceAll("%wave%", String.valueOf(getWave())));
                    barToggle++;
                }
            }
            if (plugin.isBungeeActivated()) {
                if (getMaximumPlayers() <= getPlayers().size()) {
                    plugin.getServer().setWhitelist(true);
                } else {
                    plugin.getServer().setWhitelist(false);
                }
            }
            zombieChecker++;
            if (zombieChecker >= 60) {
                List<Villager> remove = new ArrayList<>();
                for (Villager villager : getVillagers()) {
                    if (villager.isDead())
                        remove.add(villager);
                }
                for (Villager villager : remove) {
                    removeVillager(villager);
                }
                remove.clear();
                zombieChecker = 0;
                List<Zombie> removeAfterLoop = new ArrayList<>();
                for (Zombie zombie : getZombies()) {
                    if (zombie.isDead()) {
                        removeAfterLoop.add(zombie);
                        continue;
                    }
                    if (glitchedZombies.contains(zombie) && zombie.getLocation().distance(zombieCheckerLocations.get(zombie)) <= 1) {
                        removeAfterLoop.add(zombie);
                        zombieCheckerLocations.remove(zombie);
                        zombie.remove();
                    }
                    if (zombieCheckerLocations.get(zombie) == null) {
                        zombieCheckerLocations.put(zombie, zombie.getLocation());
                    } else {
                        Location location = zombieCheckerLocations.get(zombie);
                        if (zombie.getLocation().distance(location) <= 1) {
                            zombie.teleport(zombieSpawns.get(random.nextInt(zombieSpawns.size() - 1)));
                            zombieCheckerLocations.put(zombie, zombie.getLocation());
                            glitchedZombies.add(zombie);
                        }
                    }
                }
                for (Zombie zombie : removeAfterLoop) {
                    removeZombie(zombie);
                }
                removeAfterLoop.clear();
            }
            if (getVillagers().size() <= 0 || getPlayersLeft().size() <= 0) {
                clearZombies();
                this.setArenaState(ArenaState.ENDING);
                this.stopGame(false);
                if (getVillagers().size() <= 0) {
                    showPlayers();
                    this.setTimer(10);
                } else
                    this.setTimer(5);
                return;
            }
            if (isFighting) {
                if (getZombiesLeft() <= 0) {
                    isFighting = false;
                    endWave();
                }
                if (zombiesToSpawn > 0) {
                    spawnZombies();
                    setTimer(500);
                } else {
                    if (getTimer() == 0) {
                        if (getZombiesLeft() <= 5) {
                            clearZombies();
                            zombiesToSpawn = 0;
                            for (Player p : getPlayers()) {
                                p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Zombie-Got-Stuck-In-The-Map"));
                            }
                        } else {
                            getZombies().clear();
                            for (int i = getZombiesLeft(); i > 0; i++) {
                                spawnFastZombie(random);
                            }
                        }
                    }
                }
                if (zombiesToSpawn < 0)
                    zombiesToSpawn = 0;
                setTimer(getTimer() - 1);
            } else {
                if (getTimer() <= 0) {
                    isFighting = true;
                    startWave();
                }
            }
            setTimer(getTimer() - 1);
            break;
        case ENDING:
            if (plugin.isBungeeActivated())
                plugin.getServer().setWhitelist(false);
            if (getTimer() <= 0) {
                if (plugin.isBossbarEnabled()) {
                    gameBar.setTitle(ChatManager.colorMessage("Bossbar.Game-Ended"));
                }
                clearVillagers();
                clearZombies();
                clearGolems();
                clearWolfs();
                for (Player player : getPlayers()) {
                    UserManager.getUser(player.getUniqueId()).removeScoreboard();
                    player.setGameMode(GameMode.SURVIVAL);
                    for (Player players : Bukkit.getOnlinePlayers()) {
                        player.showPlayer(players);
                        players.hidePlayer(player);
                    }
                    for (PotionEffect effect : player.getActivePotionEffects()) {
                        player.removePotionEffect(effect.getType());
                    }
                    player.setFlying(false);
                    player.setAllowFlight(false);
                    player.getInventory().clear();
                    ArmorHelper.clearArmor(player);
                    if (plugin.isBossbarEnabled()) {
                        gameBar.removePlayer(player);
                    }
                    player.setMaxHealth(20.0);
                    player.setHealth(player.getMaxHealth());
                    player.setFireTicks(0);
                    player.setFoodLevel(20);
                    for (Player players : plugin.getServer().getOnlinePlayers()) {
                        if (ArenaRegistry.getArena(players) != null)
                            players.showPlayer(player);
                        player.showPlayer(players);
                    }
                }
                teleportAllToEndLocation();
                if (plugin.isInventoryManagerEnabled()) {
                    for (Player player : getPlayers()) {
                        plugin.getInventoryManager().loadInventory(player);
                    }
                }
                for (Player p : getPlayers()) {
                    p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.Teleported-To-The-Lobby"));
                }
                setArenaState(ArenaState.RESTARTING);
                for (User user : UserManager.getUsers(this)) {
                    user.setSpectator(false);
                    user.setInt("orbs", 0);
                    user.setFakeDead(false);
                }
                plugin.getRewardsHandler().performEndGameRewards(this);
                clearPlayers();
                if (plugin.isBungeeActivated()) {
                    if (ConfigurationManager.getConfig("bungee").getBoolean("Shutdown-When-Game-Ends"))
                        plugin.getServer().shutdown();
                }
            }
            setTimer(getTimer() - 1);
            break;
        case RESTARTING:
            clearVillagers();
            this.restoreMap();
            getPlayers().clear();
            setArenaState(ArenaState.WAITING_FOR_PLAYERS);
            wave = 1;
            if (plugin.isBungeeActivated()) {
                for (Player player : plugin.getServer().getOnlinePlayers()) {
                    this.addPlayer(player);
                }
            }
            break;
        default:
            // o.o?
            break;
    }
}
Also used : Player(org.bukkit.entity.Player) VillageGameStartEvent(pl.plajer.villagedefense3.villagedefenseapi.VillageGameStartEvent) User(pl.plajer.villagedefense3.User) Zombie(org.bukkit.entity.Zombie) PotionEffect(org.bukkit.potion.PotionEffect) Villager(org.bukkit.entity.Villager) ArrayList(java.util.ArrayList) Location(org.bukkit.Location)

Example 35 with User

use of org.neo4j.ogm.domain.gh368.User in project Village_Defense by Plajer.

the class QuitEvent method onQuitSaveStats.

@EventHandler
public void onQuitSaveStats(PlayerQuitEvent event) {
    if (ArenaRegistry.getArena(event.getPlayer()) != null) {
        ArenaRegistry.getArena(event.getPlayer()).leaveAttempt(event.getPlayer());
    }
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());
    final Player player = event.getPlayer();
    if (plugin.isDatabaseActivated()) {
        Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
            for (final String s : FileStats.STATISTICS) {
                int i;
                try {
                    i = plugin.getMySQLDatabase().getStat(player.getUniqueId().toString(), s);
                } catch (NullPointerException npe) {
                    i = 0;
                    System.out.print("COULDN'T GET STATS FROM PLAYER: " + player.getName());
                    npe.printStackTrace();
                    BigTextUtils.errorOccured();
                    Bukkit.getConsoleSender().sendMessage("Cannot get stats from MySQL database!");
                    Bukkit.getConsoleSender().sendMessage("Check configuration of mysql.yml file or disable mysql option in config.yml");
                }
                if (i > user.getInt(s)) {
                    plugin.getMySQLDatabase().setStat(player.getUniqueId().toString(), s, user.getInt(s) + i);
                } else {
                    plugin.getMySQLDatabase().setStat(player.getUniqueId().toString(), s, user.getInt(s));
                }
            }
        });
    } else {
        for (String s : FileStats.STATISTICS) {
            plugin.getFileStats().saveStat(player, s);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(pl.plajer.villagedefense3.User) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (pl.plajer.villagedefense3.User)30 Player (org.bukkit.entity.Player)18 User (org.gluu.oxtrust.model.scim2.User)17 Test (org.junit.Test)17 User (org.openstack4j.model.identity.v3.User)13 EventHandler (org.bukkit.event.EventHandler)11 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)10 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)10 Date (java.util.Date)9 Arena (pl.plajer.villagedefense3.arena.Arena)8 User (me.zhanghai.android.douya.network.api.info.apiv2.User)7 User (com.google.api.ads.admanager.axis.v202202.User)6 SimpleUser (me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser)6 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)6 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)5 Path (javax.ws.rs.Path)5 User (org.apache.archiva.redback.rest.api.model.v2.User)5 UserInfo (org.apache.archiva.redback.rest.api.model.v2.UserInfo)5 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)5