Java Code Examples for org.bukkit.GameMode

The following are top voted examples for showing how to use org.bukkit.GameMode. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: HCFCore   File: ModeratorMode.java   Source Code and License 8 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
  Player player = event.getPlayer();
  if ((modMode.contains(player)) && (player.getGameMode().equals(GameMode.CREATIVE))) {
    event.setCancelled(true);
  }
}
 
Example 2
Project: Arcadia-Spigot   File: GameManager.java   Source Code and License 7 votes vote down vote up
/**
 * Toggles whether a player is in Spectator Mode.
 * @param player
 * @param toggle
 */
public void setSpectating(Player player, boolean toggle) {
    if(toggle && spec.contains(player)) return;
    if(!toggle && !spec.contains(player)) return;
    if(toggle) {
        player.setAllowFlight(true);
        player.setFlying(true);
        player.setGameMode(GameMode.SPECTATOR);
        spec.add(player);
    } else {
        player.setGameMode(GameMode.ADVENTURE);
        spec.remove(player);
    }
    this.setAlive(player, false);
    Bukkit.getServer().getPluginManager().callEvent(new PlayerAliveStatusEvent(player, false, toggle));
}
 
Example 3
Project: PA   File: GamemodeCMD.java   Source Code and License 7 votes vote down vote up
private GameMode parseGamemode(String gamemode) {
    switch (gamemode) {
        case "creativo":
        case "1":
        case "c":
            return GameMode.CREATIVE;
        case "survival":
        case "0":
        case "s":
            return GameMode.SURVIVAL;
        case "adventura":
        case "2":
        case "a":
            return GameMode.ADVENTURE;
        case "espectador":
        case "3":
        case "e":
            return GameMode.SPECTATOR;
        default:
            return GameMode.SURVIVAL;
    }
}
 
Example 4
Project: UHC   File: JoinQuitHandlers.java   Source Code and License 7 votes vote down vote up
@EventHandler
public void leave(final PlayerQuitEvent event) {
    if(GameState.current() != GameState.LOBBY && event.getPlayer().getGameMode() != GameMode.SPECTATOR){
        event.setQuitMessage(colour("&6" + event.getPlayer().getName() + " has quit! " +
                "They have " + UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds() + "s to reconnect."));

        bukkitRunnable(() -> disqualified(event.getPlayer().getUniqueId(), event.getPlayer().getName(),
                event.getPlayer().getLocation(), event.getPlayer().getInventory())).runTaskLater(UHC.getInstance(),
                TimeUnit.MILLISECONDS.convert(UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds(), TimeUnit.SECONDS));

        //Zombie Spawning
        Zombie zombie = (Zombie) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.ZOMBIE);
        zombie.setCustomName(event.getPlayer().getName());
        zombie.setCustomNameVisible(true);
        //TODO Make no AI and invulnerable cough cough Proxi cough cough
        deadRepresentatives.put(event.getPlayer().getUniqueId(), zombie);
    }
}
 
Example 5
Project: NoDaylight   File: PlayerMoveListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (!event.getFrom().getWorld().getName().equalsIgnoreCase("cave")) {
        return;
    }

    if (event.getTo().getBlock().getLightFromSky() == 0) {
        return;
    }

    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        return;
    }

    event.getPlayer().setHealth(0.0D);

    TextComponent message = new TextComponent("DU VOLLIDIOT! SONNE IST GEFÄHRLICH! HOFFE DU LERNST DARAUS");
    message.setColor(ChatColor.DARK_RED);

    event.getPlayer().spigot().sendMessage(message);
}
 
Example 6
Project: Warzone   File: MatchManager.java   Source Code and License 6 votes vote down vote up
public void endMatch(MatchTeam winningTeam) {
    List<MatchTeam> losers = new ArrayList<>();
    for (MatchTeam matchTeam : TGM.get().getModule(TeamManagerModule.class).getTeams()) {
        if (!matchTeam.isSpectator()) {
            matchTeam.getMembers().forEach(playerContext -> {
                playerContext.getPlayer().setGameMode(GameMode.ADVENTURE);
                playerContext.getPlayer().setAllowFlight(true);
                playerContext.getPlayer().setVelocity(new Vector(playerContext.getPlayer().getVelocity().getX(),
                        playerContext.getPlayer().getVelocity().getZ() + 1.0, playerContext.getPlayer().getVelocity().getZ()));
                playerContext.getPlayer().setFlying(true);
            });

            if (matchTeam != winningTeam) {
                losers.add(matchTeam);
            }
        }
    }
    match.disable();

    Bukkit.getPluginManager().callEvent(new MatchResultEvent(match, winningTeam, losers));
}
 
Example 7
Project: Warzone   File: SpawnPointHandlerModule.java   Source Code and License 6 votes vote down vote up
public void spawnPlayer(PlayerContext playerContext, MatchTeam matchTeam, boolean teleport) {
    Players.reset(playerContext.getPlayer(), true);

    if (matchTeam.isSpectator()) {
        spectatorModule.applySpectatorKit(playerContext);
        if (teleport) {
            playerContext.getPlayer().teleport(getTeamSpawn(matchTeam).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
        }
    } else {
        matchTeam.getKits().forEach(kit -> kit.apply(playerContext.getPlayer(), matchTeam));
        playerContext.getPlayer().updateInventory();

        if (teleport) {
            playerContext.getPlayer().teleport(getTeamSpawn(matchTeam).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
            playerContext.getPlayer().setGameMode(GameMode.SURVIVAL);
        }
    }
}
 
Example 8
Project: HCFCore   File: BookDeenchantListener.java   Source Code and License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
        // The player didn't click an enchantment table, Creative players will instantly destroy.
        Player player = event.getPlayer();
        if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {

            // The player didn't click with an enchanted book.
            ItemStack stack = event.getItem();
            if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
                ItemMeta meta = stack.getItemMeta();
                if (meta instanceof EnchantmentStorageMeta) {
                    EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
                    for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
                        enchantmentStorageMeta.removeStoredEnchant(enchantment);
                    }

                    event.setCancelled(true);
                    player.setItemInHand(EMPTY_BOOK);
                    player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
                }
            }
        }
    }
}
 
Example 9
Project: UHC   File: Message.java   Source Code and License 6 votes vote down vote up
public void message(CommandContext context) {
    String targetString = context.getArgs().get(0);
    Player target = Bukkit.getPlayer(targetString);
    if (target == null) {
        context.send(colour("&cNobody was found with name '" + targetString + "'."));
        return;
    }

    if (context.getSender() instanceof Player &&
            Conditionals.ofBoth(((Player) context.getSender()).getGameMode(), target.getGameMode(), GameMode.SURVIVAL, GameMode.SPECTATOR)) {
        context.send(colour("&cGhosting is not allowed!"));
        return;
    }

    String finalMessage = String.join(" ", context.getArgs().subList(1, context.getArgs().size()));

    target.sendMessage(colour("&f<" + context.getSender().getName() + "&f -> Me&f> ") + finalMessage);
    context.send(colour("&f<Me -> " + target.getName() + "&f> ") + finalMessage);

    Bukkit.getOnlinePlayers().stream().filter(it -> UserManager.getInstance().getUser(it.getUniqueId()).orElseThrow(() -> new RuntimeException("An offline player is in Bukkit#getOnlinePlayers.")).getParticipation() == Participation.ADMIN)
            .forEach(it -> it.sendMessage(colour("&f<" + context.getSender().getName() + " -> " + target.getName() + "> ") + finalMessage));

    lastMessaged.put(context.getSender(), target);
}
 
Example 10
Project: AntiCheat   File: BlockHitManager.java   Source Code and License 6 votes vote down vote up
public static boolean hitBlock(Player player, Block block) {
    if (player.getGameMode() == GameMode.CREATIVE)
        return true;

    PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);

    if (playerBlockTracking.isBlock(block)) {
        return true;
    }

    long time = playerBlockTracking.getTimeDifference();
    playerBlockTracking.incrementHackingIndicator();
    playerBlockTracking.setBlock(block);
    playerBlockTracking.updateTime();

    int decrement = (int) (time / OrebfuscatorConfig.AntiHitHackDecrementFactor);
    playerBlockTracking.decrementHackingIndicator(decrement);

    if (playerBlockTracking.getHackingIndicator() == OrebfuscatorConfig.AntiHitHackMaxViolation)
        playerBlockTracking.incrementHackingIndicator(OrebfuscatorConfig.AntiHitHackMaxViolation);

    if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
        return false;

    return true;
}
 
Example 11
Project: Debuggery   File: InputFormatterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testGameMode() throws InputException {
    Class[] inputTypes = {GameMode.class, GameMode.class};
    String[] input = {"1", "adventure"};

    Object[] output = InputFormatter.getTypesFromInput(inputTypes, Arrays.asList(input), null);

    // First let's make sure we didn't lose anything, or get anything
    assertEquals(inputTypes.length, output.length);

    // Next let's make sure everything is the right type
    for (Object object : output) {
        assertTrue(object instanceof GameMode);
    }

    // Finally, let's make sure the values are correct
    assertSame(output[0], GameMode.CREATIVE);
    assertSame(output[1], GameMode.ADVENTURE);
}
 
Example 12
Project: SamaGamesCore   File: ModerationJoinHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void onModerationJoin(Player player)
{
    player.sendMessage(ChatColor.GOLD + "Vous avez rejoint cette arène en mode modération.");
    player.setGameMode(GameMode.SPECTATOR);

    List<Player> players = new ArrayList<>();
    players.addAll(Bukkit.getOnlinePlayers());
    players.stream().filter(gamePlayer -> !gamePlayer.getName().equals(player.getName())).forEach(gamePlayer -> {
        gamePlayer.hidePlayer(player);
    });

    if (teleportTargets.containsKey(player.getUniqueId()))
    {
        UUID target = teleportTargets.get(player.getUniqueId());
        Player tar = Bukkit.getPlayer(target);
        if (tar != null)
            player.teleport(tar);
        teleportTargets.remove(player.getUniqueId());
    }
}
 
Example 13
Project: Arcadia-Spigot   File: KingOfTheHillGame.java   Source Code and License 6 votes vote down vote up
@Override
public void onPreStart() {
    Location spawnLocation = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
    MaterialData materialData = Utils.parseMaterialData((String) this.getGameMap().fetchSetting("item"));
    ItemStack itemStack = new ItemStack(materialData.getItemType(), 1, materialData.getData());
    itemStack.addUnsafeEnchantment(Enchantment.KNOCKBACK,
        Integer.parseInt((String) this.getGameMap().fetchSetting("knockbackAmount")));
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(spawnLocation);
        player.setGameMode(GameMode.ADVENTURE);
        player.getInventory().addItem(itemStack);
    }
    this.hill = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsA")),
        Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsB")));
}
 
Example 14
Project: SamaGamesAPI   File: Game.java   Source Code and License 6 votes vote down vote up
/**
 * Override this to execute something when a moderator joins the game.
 *
 * You need to call the {@code super} method at the beginning of your own one.
 *
 * @param player The player who logged in.
 */
public void handleModeratorLogin(Player player)
{
    for (GamePlayer gamePlayer : this.gamePlayers.values())
    {
        Player p = gamePlayer.getPlayerIfOnline();

        if (p != null)
            p.hidePlayer(player);
    }

    this.gameModerators.add(player.getUniqueId());

    player.setGameMode(GameMode.SPECTATOR);
    player.sendMessage(ChatColor.GREEN + "Vous êtes invisibles aux yeux de tous, attention à vos actions !");
}
 
Example 15
Project: FastSpawn   File: Teams.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static void JoinTeam(Player player,String area){
	
	String worldconfig = plugin.getConfig().getString("area."+area+".world");
	World world = Bukkit.getServer().getWorld(worldconfig);
	String Location = plugin.getConfig().getString("area."+area+".Location");
	String[] location = Location.split(",");
	int x = Integer.parseInt(location[0]);
	int y = Integer.parseInt(location[1]);
	int z = Integer.parseInt(location[2]);
	
	Location location2 = new Location(world, x, y, z);
	player.teleport(location2);
	player.setGameMode(GameMode.SURVIVAL);
	
	Team team = board.getTeam(area);
	PlayerInWhereArea.put(player, team);
	team.addPlayer(player);
	player.playSound(player.getLocation(), Sound.CLICK, 2F, 15F);
	player.sendMessage(ChatColor.BLUE + "�A�[�J�F�C��");
	
}
 
Example 16
Project: Chambers   File: GameManager.java   Source Code and License 6 votes vote down vote up
/**
 * Finally starts the game after the countdown
 * 
 * You have to load the chunk because the player could probably spawn in the
 * ground if the chunk is not loaded when the player is teleported
 */
public void finallyStart() {
	game.setStatus(GameStatus.INGAME);
	Chambers.getInstance().getTeamManager().getAllPlayerTeams().stream().forEach(team -> {
		if (!team.getHome().getChunk().isLoaded()) {
			team.getHome().getChunk().load();
		}
		team.getOnlinePlayers().stream().forEach(player -> {
			giveStartingItems(player);
			player.setGameMode(GameMode.SURVIVAL);
			player.setAllowFlight(false);
			player.setFlying(false);
			player.teleport(team.getHome());
		});
	});
	new GameTask().runTaskTimerAsynchronously(Chambers.getInstance(), 0L, 20L);
	Bukkit.broadcastMessage(" ");
	Bukkit.broadcastMessage(ChatColor.YELLOW + "The game has now started! Good luck!");
	Bukkit.broadcastMessage(" ");
}
 
Example 17
Project: ZorahPractice   File: PlayerListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onInventoryMove(InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();
    PracticeProfile profile = ManagerHandler.getPlayerManager().getPlayerProfile(player);

    if (profile.getStatus() == PlayerStatus.EDITING_KITS || profile.getStatus() == PlayerStatus.PLAYING) {
        return;
    }

    if ((player.hasPermission("practice.admin") || player.isOp()) && player.getGameMode() == GameMode.CREATIVE) {
        return;
    }

    event.setCancelled(true);
}
 
Example 18
Project: SkywarsSeries   File: PlayerJoin.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    event.setJoinMessage(null);

    if (!Skywars.getInstance().isSingleServerMode()) {
        player.setGameMode(GameMode.ADVENTURE);
        player.getInventory().clear();
        player.setMaxHealth(20);
        player.setHealth(player.getMaxHealth());
        player.setFoodLevel(25);

        player.teleport(Skywars.getInstance().getLobbyPoint());
    }
}
 
Example 19
Project: kaosEssentials   File: Core.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority=EventPriority.LOWEST)
public void customDeathNonPlayerFallback(EntityDamageEvent e){
	if(e.getCause().equals(DamageCause.FALL)) return;
	if(e.getEntity() instanceof Player){
		Player p = (Player) e.getEntity();
		if(e.getCause().equals(DamageCause.ENTITY_ATTACK)){
			// no need to do anything here, this part is controlled in the customDeath method
		}else{
			if(e.getFinalDamage() >= p.getHealth()){
				e.setCancelled(true);
				Bukkit.getServer().broadcastMessage(ChatColor.GRAY + p.getName() + " died");
				// Set statistics
				//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
				// Reset health, so they dont die
				p.setHealth(p.getMaxHealth());
				// Inventory clearing
				p.getInventory().clear();
				ItemStack air = new ItemStack(Material.AIR);
				p.getInventory().setHelmet(air);
				p.getInventory().setChestplate(air);
				p.getInventory().setLeggings(air);
				p.getInventory().setBoots(air);
				// Clear potion effects
				for(PotionEffect pe : p.getActivePotionEffects()){
					p.removePotionEffect(pe.getType());
				}
				// Stop infinite kill glitch
				p.setGameMode(GameMode.SPECTATOR);
				p.setGameMode(GameMode.ADVENTURE);
				// send them to the SPAWN of the world
				p.teleport(p.getWorld().getSpawnLocation());
				p.setFireTicks(0);
			}
		}
	}
}
 
Example 20
Project: HCFCore   File: BlockJumpGlitchFixListener.java   Source Code and License 6 votes vote down vote up
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onBlockBreak(BlockPlaceEvent event) {
    if (event.isCancelled()) {
        Player player = event.getPlayer();
        if (player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) {
            return;
        }

        Block block = event.getBlockPlaced();
        if (block.getType().isSolid() && !(block.getState() instanceof Sign)) {
            int playerY = player.getLocation().getBlockY();
            int blockY = block.getLocation().getBlockY();
            if (playerY > blockY) {
                Vector vector = player.getVelocity();
                vector.setX(-0.1);
                vector.setZ(-0.1);
                player.setVelocity(vector.setY(vector.getY() - 0.41999998688697815D)); // Magic number acquired from EntityLiving#bj()
            }
        }
    }
}
 
Example 21
Project: SurvivalPlus   File: FoodDiversityConsume.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsumeCake(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
	{
		Block cake = event.getClickedBlock();
		if(cake.getType().equals(Material.CAKE_BLOCK))
		{
			if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE))
			{
				addStats(player, carbon, 171);
				addStats(player, protein, 114);
				addStats(player, salts, 3);
			}
		}
	}
}
 
Example 22
Project: UHC   File: JoinQuitHandlers.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void playerJoin(final PlayerJoinEvent event) {
    Optional<User> joinedUser;
    if ((joinedUser = UserManager.getInstance().getUser(event.getPlayer().getUniqueId())).isPresent()) {
        if(joinedUser.get().getParticipation() != Participation.SPECTATOR && GameState.current() != GameState.LOBBY){
            event.setJoinMessage(colour("&b" + event.getPlayer().getName() + " has reconnected."));
            deadRepresentatives.get(event.getPlayer().getUniqueId()).remove();
            deadRepresentatives.remove(event.getPlayer().getUniqueId());
        }
        return;
    }

    User user = new User(event.getPlayer(), GameState.current() == GameState.LOBBY ? Participation.PARTICIPATOR :
        Participation.SPECTATOR);

    if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().isOp()) {
        user.setParticipation(Participation.ADMIN);
    } else if(GameState.current() != GameState.LOBBY) event.getPlayer().setGameMode(GameMode.SPECTATOR);

    UserManager.getInstance().addUser(user);
}
 
Example 23
Project: Hub   File: CommandFly.java   Source Code and License 6 votes vote down vote up
@Override
public boolean doAction(Player player, Command command, String s, String[] args)
{
    if (!SamaGamesAPI.get().getPermissionsManager().hasPermission(player, "hub.fly"))
    {
        player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.RED + "Vous n'avez pas le grade nécéssaire pour utiliser cette commande.");
        return true;
    }

    if (player.getGameMode() != GameMode.ADVENTURE || this.hub.getPlayerManager().isBusy(player))
    {
        player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.RED + "Vous ne pouvez pas utiliser cette commande actuellement.");
        return true;
    }

    boolean now = !player.getAllowFlight();
    player.setAllowFlight(now);

    if (now)
        player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.GREEN + "Vous pouvez maintenant voler.");
    else
        player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.GREEN + "Vous ne pouvez plus voler.");

    return true;
}
 
Example 24
Project: RPGInventory   File: InventoryLocker.java   Source Code and License 6 votes vote down vote up
public static void lockSlots(Player player, boolean force) {
    if (!force && player.getGameMode() == GameMode.CREATIVE) {
        return;
    }

    if (isEnabled()) {
        int maxSlot = getSlots(player) + 8;
        for (int i = 35; i > maxSlot; i--) {
            player.getInventory().setItem(i, lockedSlot);
        }

        if (maxSlot < 35) {
            player.getInventory().setItem(maxSlot + 1, getBuyableSlotForLine(getLine(maxSlot + 1)));
        }
    }

    InventoryManager.lockQuickSlots(player);
    InventoryManager.lockEmptySlots(player);
}
 
Example 25
Project: DynamicAC   File: Flight.java   Source Code and License 5 votes vote down vote up
public static void runCheck(Player player, Distance distance) {
    if (distance.getYDifference() > 400 || player.isFlying() || player.getGameMode().equals(GameMode.CREATIVE)) {
        return; //This is to prevent a player using /fly getting AC'd
    }

    final double y1 = distance.fromY();
    final double y2 = distance.toY();
    if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities
            .cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock()
            .getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material
            .COBBLE_WALL})) { //prevents fancy minecraft magicky crap
        for(double i = player.getLocation().getY(); new Location(player.getWorld(),player
                .getLocation().getX(),i,
                player.getLocation().getZ()).getBlock().getType() != Material.AIR; i--) {
            if(player.getVelocity().getY() >= 0 && player.getLocation()
                    .add(0,-2,0).getBlock().getType() != Material.AIR) {
                repeated.put(player,repeated.containsKey(player)?repeated.put(player,repeated.get(player) + 1)
                        :repeated.put(player,1));
            }
        }
        if (repeated.containsKey(player) && repeated.get(player) > MagicNumbers.MAX_FLY){
            for (Player pla : DynamicAC.instance.onlinestaff) {
                pla.sendMessage(DynamicAC.prefix + player.getName() + " failed Fly!");
            }
            DACManager.getUserManager().incrementUser(DACManager.getUserManager().getUser(player.getName()),
                    "Flight");
        }
    }
}
 
Example 26
Project: PA   File: BackInTime.java   Source Code and License 5 votes vote down vote up
public void spell(TOAUser u) {
    l = u.getLoc();

    u.getPlayer().setGameMode(GameMode.SPECTATOR);

    plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
        u.teleport(l);
        u.getPlayer().setGameMode(GameMode.ADVENTURE);
    }, 100);
}
 
Example 27
Project: Warzone   File: SpectatorModule.java   Source Code and License 5 votes vote down vote up
public void applySpectatorKit(PlayerContext playerContext) {
    Players.reset(playerContext.getPlayer(), false);
    playerContext.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100000, 255, false, false));
    playerContext.getPlayer().setGameMode(GameMode.ADVENTURE);
    playerContext.getPlayer().setAllowFlight(true);
    playerContext.getPlayer().setFlying(true);

    playerContext.getPlayer().setInvulnerable(true);
    playerContext.getPlayer().setCanPickupItems(false);
    playerContext.getPlayer().setCollidable(false);

    playerContext.getPlayer().getInventory().setItem(0, compassItem);
    playerContext.getPlayer().getInventory().setItem(2, teamSelectionItem);
}
 
Example 28
Project: VanillaPlus   File: VPPlayer.java   Source Code and License 5 votes vote down vote up
public void setGameMode(GameMode gameMode) {
	if(isOnline()){
		player.setGameMode(gameMode);
	}else{
		this.gameMode = gameMode;
	}
}
 
Example 29
Project: Warzone   File: InfectionModule.java   Source Code and License 5 votes vote down vote up
private void refresh(PlayerContext playerContext, MatchTeam matchTeam) {
    Players.reset(playerContext.getPlayer(), true);

    matchTeam.getKits().forEach(kit -> kit.apply(playerContext.getPlayer(), matchTeam));
    playerContext.getPlayer().updateInventory();
    playerContext.getPlayer().teleport(matchTeam.getSpawnPoints().get(0).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
    playerContext.getPlayer().setGameMode(GameMode.ADVENTURE);
    playerContext.getPlayer().addPotionEffects(Collections.singleton(new PotionEffect(PotionEffectType.JUMP, 10000, 2, true, false)));

}
 
Example 30
Project: Warzone   File: InfectionModule.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onTeamChange(TeamChangeEvent event) {
    if (teamManager.getTeamById("humans").getMembers().size() == 0 && match.getMatchStatus().equals(MatchStatus.MID)) {
        TGM.get().getMatchManager().endMatch(teamManager.getTeamById("infected"));
    }
    event.getPlayerContext().getPlayer().setGameMode(GameMode.ADVENTURE);

    if (event.getTeam().getId().equalsIgnoreCase("infected")) {
        event.getPlayerContext().getPlayer().addPotionEffects(Collections.singleton(new PotionEffect(PotionEffectType.JUMP, 50000, 1, true, false)));
    }
}
 
Example 31
Project: MiniWynn   File: PlayerListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void on(PlayerJoinEvent event){
    Player player = event.getPlayer();
    player.setGameMode(GameMode.ADVENTURE);

    ItemStack item = itemFactory.getWeapon(AirBow.class);
    player.getInventory().setItemInMainHand(item);
}
 
Example 32
Project: FastSpawn   File: Teams.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void QuitTeam(Player player){
	
	String worldconfig = plugin.getConfig().getString("lobby.world");
	World world = Bukkit.getServer().getWorld(worldconfig);
	
	String Location = plugin.getConfig().getString("lobby.Location");
	String[] location = Location.split(",");
	int x = Integer.parseInt(location[0]);
	int y = Integer.parseInt(location[1]);
	int z = Integer.parseInt(location[2]);
	
	Location location2 = new Location(world, x, y, z);
	player.teleport(location2);
	
	Team team = PlayerInWhereArea.get(player);
	team.removePlayer(player);
	PlayerInWhereArea.remove(player);
	
	player.sendMessage(ChatColor.BLUE + "�A�h�X�F�C��");
	player.playSound(player.getLocation(), Sound.NOTE_PIANO, 2F, 15F);
	
	player.setGameMode(GameMode.SURVIVAL);
	
	Spawn.cancel(player);
	Spawn2.cancel(player);
}
 
Example 33
Project: Uranium   File: CraftInventoryView.java   Source Code and License 5 votes vote down vote up
@Override
public InventoryType getType() {
    InventoryType type = viewing.getType();
    if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) {
        return InventoryType.CREATIVE;
    }
    return type;
}
 
Example 34
Project: HCFCore   File: AutoSmeltOreListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() != GameMode.CREATIVE) {
        if (player.hasPermission("hcf.listener.autosmeltore")) {
            ItemStack stack = player.getItemInHand();
            if (stack != null && stack.getType() != Material.AIR
                    && !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
                Block block = event.getBlock();
                Material dropType = null;
                switch (block.getType()) {
                    case IRON_ORE: {
                        dropType = Material.IRON_INGOT;
                        break;
                    }
                    case GOLD_ORE: {
                        dropType = Material.GOLD_INGOT;
                        break;
                    }
                    default: {
                        return;
                    }
                }
                 Location location = block.getLocation();
                 World world = location.getWorld();
                 ItemStack drop = new ItemStack(dropType, 1);
                world.dropItemNaturally(location, drop);
                block.setType(Material.AIR);
                block.getState().update();
            }
        }
    }
}
 
Example 35
Project: AntiCheat   File: BlockHitManager.java   Source Code and License 5 votes vote down vote up
public static void breakBlock(Player player, Block block) {
    if (player.getGameMode() == GameMode.CREATIVE)
        return;

    PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
    if (playerBlockTracking.isBlock(block)) {
        playerBlockTracking.decrementHackingIndicator(2);
    }
}
 
Example 36
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    PlayerDataRPG pd = plugin.getPD(event.getPlayer());
    if (pd == null)
        event.setCancelled(true);
    if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
}
 
Example 37
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
    PlayerDataRPG pd = plugin.getPD(event.getPlayer());
    if (pd == null)
        event.setCancelled(true);
    if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
    event.getPlayer().updateInventory();
}
 
Example 38
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onBucketFill(PlayerBucketFillEvent event) {
    PlayerDataRPG pd = plugin.getPD(event.getPlayer());
    if (pd == null)
        event.setCancelled(true);
    if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
    event.getPlayer().updateInventory();
}
 
Example 39
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onHangingBreak(HangingBreakByEntityEvent event) {
    if (!(event.getRemover() instanceof Player))
        event.setCancelled(true);
    PlayerDataRPG pd = plugin.getPD((Player) event.getRemover());
    if (pd == null)
        event.setCancelled(true);
    if (((Player) event.getRemover()).getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
}
 
Example 40
Project: Kineticraft   File: Flight.java   Source Code and License 5 votes vote down vote up
/**
 * Is the player in a state or situation that we should deem them not flying?
 * @param player
 * @return immune
 */
private static boolean isImmune(Player player) {
    return player.getGameMode() != GameMode.SURVIVAL
            || Utils.getRank(player).isAtLeast(EnumRank.MEDIA) // Don't bypass this check.
            || player.isGliding() // Not using Elytra
            || player.hasPotionEffect(PotionEffectType.LEVITATION) // Doesn't have a levitation potion
            || player.getVehicle() != null // Not in a vehicle
            || player.getVelocity().getY() > 0 // Not being launched up
            || player.getNearbyEntities(1, 2, 1).stream().anyMatch(e -> e.getType() == EntityType.BOAT) // Not standing on a boat.
            || player.getLocation().getBlock().isLiquid(); // Not in water.
}
 
Example 41
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onItemFrameInteract(PlayerInteractEntityEvent event) {
    Player p = event.getPlayer();
    Entity e = event.getRightClicked();
    if (e instanceof ItemFrame && p.getGameMode() != GameMode.CREATIVE) {
        event.setCancelled(true);
    }
}
 
Example 42
Project: ZentrelaRPG   File: GamemodeCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void executePlayer(final Player p, PlayerDataRPG pd, String[] args) {
    if (p.getGameMode() == GameMode.ADVENTURE) {
        p.setGameMode(GameMode.CREATIVE);
    } else {
        p.setGameMode(GameMode.ADVENTURE);
    }
    p.sendMessage(ChatColor.GREEN + "You are now in " + p.getGameMode().toString() + ".");
}
 
Example 43
Project: ZentrelaRPG   File: TrinketManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerClickTrinket(InventoryClickEvent event) {
    if (event.getInventory() instanceof CraftInventoryCrafting && event.getRawSlot() == 45) { //offhand slot
        event.setCancelled(true);
        if (event.getWhoClicked().getGameMode() != GameMode.ADVENTURE && event.getWhoClicked().getGameMode() != GameMode.SURVIVAL) {
            event.getWhoClicked().getInventory().setItemInOffHand(null);
        }
        if (event.getWhoClicked() instanceof Player)
            ((Player) event.getWhoClicked()).updateInventory();
    }
}
 
Example 44
Project: ZentrelaRPG   File: TrinketManager.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerClickTrinket2(InventoryDragEvent event) {
    if (event.getRawSlots().contains(45)) {
        event.setCancelled(true);
        if (event.getWhoClicked().getGameMode() != GameMode.ADVENTURE && event.getWhoClicked().getGameMode() != GameMode.SURVIVAL) {
            event.getWhoClicked().getInventory().setItemInOffHand(null);
        }
        if (event.getWhoClicked() instanceof Player)
            ((Player) event.getWhoClicked()).updateInventory();
    }
}
 
Example 45
Project: Arcadia-Spigot   File: SpleefGame.java   Source Code and License 5 votes vote down vote up
@Override
public void onPreStart() {
    Location spawnLocation = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
    ItemStack itemStack = new ItemStack(Material.DIAMOND_SPADE, 1);
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(spawnLocation);
        player.setGameMode(GameMode.SURVIVAL);
        player.getInventory().addItem(itemStack);
    }
}
 
Example 46
Project: Arc-v2   File: PlayerListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onGameModeChange(PlayerGameModeChangeEvent event) {
    GameMode gameMode = event.getPlayer().getGameMode();
    // check if we switch to survival from an exempt GameMode and update.
    if (Arc.COMPATIBILITY) {
        if ((gameMode == GameMode.CREATIVE && event.getNewGameMode() == GameMode.SURVIVAL)) {
            MovingData.getData(event.getPlayer()).setLastGameModeChange(System.currentTimeMillis());
        }
    } else {
        if ((gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR) && event.getNewGameMode() == GameMode.SURVIVAL) {
            MovingData.getData(event.getPlayer()).setLastGameModeChange(System.currentTimeMillis());
        }
    }
}
 
Example 47
Project: Arcadia-Spigot   File: WingRushGame.java   Source Code and License 5 votes vote down vote up
@Override
public void onPreStart() {
    this.startLocationCenter = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPositionCenter"));
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(startLocationCenter);
        player.setGameMode(GameMode.ADVENTURE);
        player.getInventory().setChestplate(new ItemStack(Material.ELYTRA, 1));
        player.setGliding(true);
        freezeList.add(new Freeze(player));
    }
}
 
Example 48
Project: Arcadia-Spigot   File: TrampolinioGame.java   Source Code and License 5 votes vote down vote up
@Override
public void onPreStart() {
    Location spawnLocation = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(spawnLocation);
        player.setGameMode(GameMode.ADVENTURE);
    }
    Cuboid pointSpawn = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("pointBoundsA")),
            Utils.parseLocation((String) this.getGameMap().fetchSetting("pointBoundsB")));
    Iterator<Block> pointSpawns = pointSpawn.iterator();
    while(pointSpawns.hasNext()) {
        this.spawnLocations.add(pointSpawns.next().getLocation());
    }
}
 
Example 49
Project: Absorption   File: InteractionListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
	if(e.getPlayer().getGameMode() != GameMode.CREATIVE)
		e.setCancelled(true);
	
	GamePlayer player = Absorption.getPlayer(e.getPlayer());
	if(player == null) return;
	
	if(e.getPlayer().getItemInHand().getType() == Material.AIR) return;
	
	if(player.getState() == PlayerState.WAITING) {
		
	} else if(player.getState() == PlayerState.PLAYING) {
		int slot = e.getPlayer().getInventory().getHeldItemSlot();
		if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
			if(slot == 0) {
				player.getKit().onLeftClick(player);
			} else if(slot == 1) {
				player.getKit().getSecondaryWeapon().onLeftClick(player);
			} else if(slot == 2) {
				player.getKit().getSpecialWeapon().onLeftClick(player);
			}
		} else if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
			if(slot == 0) {
				player.getKit().onRightClick(player);
			} else if(slot == 1) {
				player.getKit().getSecondaryWeapon().onRightClick(player);
			} else if(slot == 2) {
				player.getKit().getSpecialWeapon().onRightClick(player);
			}
		}
	} else if(player.getState() == PlayerState.RESPAWNING) {
		
	} else if(player.getState() == PlayerState.END) {
		// Nothing
	}
}
 
Example 50
Project: Kineticraft   File: CutsceneStatus.java   Source Code and License 5 votes vote down vote up
/**
 * Finish the cutscene for the given player.
 * @param p
 */
public void finish(Player p) {
    Cutscenes.removeState(p);
    p.setGameMode(GameMode.SURVIVAL);
    Utils.safeTp(p, getStartLocation());
    getPlayers().remove(p);
}
 
Example 51
Project: MultiLineAPI   File: VisibilityUtil.java   Source Code and License 5 votes vote down vote up
public static boolean isViewable(Player viewer, Entity target, boolean bypassGameMode) {
    if (target instanceof Player) {
        if (vanishNoPacket) {
            if (manager.isVanished((Player) target)) return false;
        }
        if (!viewer.canSee((Player) target)) return false;
        if (((Player) target).getGameMode() == GameMode.SPECTATOR) return false;
    }
    if (target instanceof LivingEntity) {
        if (((LivingEntity) target).hasPotionEffect(PotionEffectType.INVISIBILITY)) return false;
    }
    return !(viewer.getGameMode() == GameMode.SPECTATOR && !bypassGameMode);
}
 
Example 52
Project: MultiLineAPI   File: EventListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onGameMode(PlayerGameModeChangeEvent e) {
    if (e.getNewGameMode().equals(GameMode.SPECTATOR) && !e.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) {
        packet.despawnAllStacks(e.getPlayer());
    } else if (!e.getNewGameMode().equals(GameMode.SPECTATOR) &&
            e.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) {
        packet.spawnAllStacks(e.getPlayer());
    }
}
 
Example 53
Project: HCFCore   File: AutoSmeltOreListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() != GameMode.CREATIVE) {
        if (player.hasPermission("hcf.listener.autosmeltore")) {
            ItemStack stack = player.getItemInHand();
            if (stack != null && stack.getType() != Material.AIR
                    && !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
                Block block = event.getBlock();
                Material dropType = null;
                switch (block.getType()) {
                    case IRON_ORE: {
                        dropType = Material.IRON_INGOT;
                        break;
                    }
                    case GOLD_ORE: {
                        dropType = Material.GOLD_INGOT;
                        break;
                    }
                    default: {
                        return;
                    }
                }
                 Location location = block.getLocation();
                 World world = location.getWorld();
                 ItemStack drop = new ItemStack(dropType, 1);
                world.dropItemNaturally(location, drop);
                block.setType(Material.AIR);
                block.getState().update();
            }
        }
    }
}
 
Example 54
Project: Locked   File: PlayerListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (!(player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)) {
        if (BlockListener.inMineLocation(player.getLocation())) {
            if (player.getGameMode() != GameMode.SURVIVAL) {
                player.setGameMode(GameMode.SURVIVAL);
            }
        } else {
            if (player.getGameMode() != GameMode.ADVENTURE) {
                player.setGameMode(GameMode.ADVENTURE);
            }
        }
    }
}
 
Example 55
Project: Kineticraft   File: CommandCheck.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCommand(CommandSender sender, String[] args) {
    Player p = (Player) sender;
    boolean hasReturn = MetadataManager.hasMetadata(p, "checkGm");

    if (args.length > 0) {
        if (!Utils.isVisible(sender, args[0]))
            return;

        if (!hasReturn) {
            MetadataManager.setMetadata(p, "checkGm", p.getGameMode());
            MetadataManager.setMetadata(p, "checkLocation", p.getLocation());
        }
        Player target = Bukkit.getPlayer(args[0]);
        p.setGameMode(GameMode.SPECTATOR);
        p.teleport(target);
        Bukkit.getScheduler().runTask(Core.getInstance(), () -> p.setSpectatorTarget(target));
        return;
    }

    if (!hasReturn) {
        sender.sendMessage(ChatColor.RED + "No previous state to return to.");
        return;
    }

    p.teleport((Location) MetadataManager.removeMetadata(p, "checkLocation"));
    p.setGameMode(MetadataManager.getEnum(p, "checkGm", GameMode.class));
}
 
Example 56
Project: NameTagChanger   File: ChannelPacketHandler.java   Source Code and License 5 votes vote down vote up
private Object getEnumGameMode(GameMode bukkitGameMode) {
    int id = 0;
    switch (bukkitGameMode) {
        case CREATIVE:
            id = 1;
            break;
        case ADVENTURE:
            id = 2;
            break;
        case SPECTATOR:
            id = 3;
            break;
    }
    return ReflectUtil.invokeMethod(null, GET_BY_ID, id).getOrThrow();
}
 
Example 57
Project: ProjectAres   File: Alive.java   Source Code and License 5 votes vote down vote up
public void die(@Nullable ParticipantState killer) {
    player.setDead(true);

    // Setting a player's gamemode resets their fall distance.
    // We need the fall distance for the death message.
    // We set the fall distance back to 0 when we refresh the player.
    float fallDistance = bukkit.getFallDistance();
    bukkit.setGameMode(GameMode.CREATIVE);
    bukkit.setFallDistance(fallDistance);

    playDeathEffect(killer);

    transition(new Dead(player));
}
 
Example 58
Project: Chambers   File: PlayerDeathListener.java   Source Code and License 5 votes vote down vote up
private void reset(Player player) {
	Bukkit.getOnlinePlayers().stream().filter(other -> other != player).forEach(other -> other.hidePlayer(player));
	player.setGameMode(GameMode.CREATIVE);
       player.setHealth(20.0);
       player.setFoodLevel(20);
       player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
       player.setAllowFlight(true);
       player.setFlying(true);
       player.setVelocity(player.getVelocity().setY(1.1));
       player.getInventory().clear();
       player.getInventory().setArmorContents(null);
}
 
Example 59
Project: HCFCore   File: CreativeClickListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakCreative(BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() == GameMode.CREATIVE && !player.hasPermission("base.command.gamemode")) {
        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!");
        player.setGameMode(GameMode.SURVIVAL);
    }
}
 
Example 60
Project: ProjectAres   File: BlockDropsMatchModule.java   Source Code and License 5 votes vote down vote up
private void dropItems(BlockDrops drops, @Nullable MatchPlayer player, Location location, double yield) {
    if(player == null || player.getBukkit().getGameMode() != GameMode.CREATIVE) {
        Random random = getMatch().getRandom();
        for (Pair<Double, ItemStack> entry : drops.items) {
            if (random.nextFloat() < yield * entry.first) {
                location.getWorld().dropItemNaturally(BlockUtils.center(location), entry.second);
            }
        }
    }
}