Java Code Examples for org.bukkit.GameMode#SPECTATOR

The following examples show how to use org.bukkit.GameMode#SPECTATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonEntityEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
    if (user == null) {
        return;
    }
    final Player player = user.getOnlinePlayer();
    if (player == null || !player.isInvulnerable()) {
        // Most likely Citizens NPC
        return;
    }
    if (!GDOptions.isOptionEnabled(Options.PLAYER_DENY_GODMODE)) {
        return;
    }

    final GDPlayerData playerData = user.getInternalPlayerData();
    final GameMode gameMode = player.getGameMode();
    if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR || !player.isInvulnerable()) {
        return;
    }

    final Boolean noGodMode = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_GODMODE, toClaim);
    final boolean bypassOption = playerData.userOptionBypassPlayerDenyGodmode;
    if (!bypassOption && noGodMode) {
        player.setInvulnerable(false);
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_GODMODE);
    }
}
 
Example 2
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChestInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return;
    if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    if (p.getGameMode() == GameMode.SPECTATOR) return;
    //noinspection deprecation
    if (p.isSneaking() && p.getItemInHand() != null
            && (p.getItemInHand().getType().isBlock() || p.getItemInHand().getType() == ITEM_FRAME)
            && p.getItemInHand().getType() != Material.AIR)
        return;
    Block block = e.getClickedBlock();
    if (block == null) return;
    if (block.getType() == ENDER_CHEST) {
        e.setCancelled(true);
        p.openInventory(p.getEnderChest());
        return;
    }
    if (!(block.getType() == CHEST || block.getType() == TRAPPED_CHEST
            || plugin.getVersionUtil().isOneDotXOrHigher(11) && shulkerBoxes.contains(block.getType())))
        return;
    StateInfo stateInfo = StateInfo.extract(p);
    playerStateInfoMap.put(p, stateInfo);
    p.setGameMode(GameMode.SPECTATOR);
}
 
Example 3
Source File: BalrogEvent.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onMine(BlockBreakEvent event) {

    if (event.isCancelled()) return;
    if (!EliteMobs.validWorldList.contains(event.getPlayer().getWorld())) return;
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
    if (!event.getPlayer().hasPermission("elitemobs.events.balrog")) return;
    if (event.getPlayer().getInventory().getItemInMainHand().hasItemMeta() &&
            event.getPlayer().getInventory().getItemInMainHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH))
        return;
    if (!(event.getBlock().getType().equals(Material.DIAMOND_ORE) || event.getBlock().getType().equals(Material.IRON_ORE) ||
            event.getBlock().getType().equals(Material.COAL_ORE) || event.getBlock().getType().equals(Material.REDSTONE_ORE) ||
            event.getBlock().getType().equals(Material.LAPIS_ORE) || event.getBlock().getType().equals(Material.GOLD_ORE))) return;
    if (ThreadLocalRandom.current().nextDouble() > ConfigValues.eventsConfig.getDouble(EventsConfig.BALROG_CHANCE_ON_MINE)) return;

    Balrog.spawnBalrog(event.getBlock().getLocation());

}
 
Example 4
Source File: KrakenEvent.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onFishingStart(PlayerFishEvent event) {

    if (event.isCancelled()) return;
    if (!currentVersionIsUnder(13, 0)) return;
    if (!EliteMobs.validWorldList.contains(event.getPlayer().getWorld())) return;
    if (!event.getPlayer().hasPermission("elitemobs.events.kraken")) return;
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().getGameMode() == GameMode.SPECTATOR)
        return;
    if (event.getHook().getLocation().getBlock().isEmpty() || !event.getHook().getLocation().getBlock().isEmpty() &&
            !event.getHook().getLocation().getBlock().getType().equals(Material.WATER)) return;
    if (ThreadLocalRandom.current().nextDouble() > ConfigValues.eventsConfig.getDouble(EventsConfig.KRAKEN_CHANCE_ON_FISH))
        return;

    Kraken.spawnKraken(event.getHook().getLocation());

}
 
Example 5
Source File: SentinelTargetingHelper.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Returns whether an entity is not able to be targeted at all.
 */
public static boolean isUntargetable(Entity e) {
    if (e == null) {
        return true;
    }
    if (e.isDead()) {
        return true;
    }
    if (e instanceof Player) {
        GameMode mode = ((Player) e).getGameMode();
        if (mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: Esp.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onGameModeChange(PlayerGameModeChangeEvent event)
{
    if (event.getNewGameMode() == GameMode.SPECTATOR) {
        final User spectator = UserManager.getUser(event.getPlayer().getUniqueId());

        // Not bypassed
        if (User.isUserInvalid(spectator, this.getModuleType())) {
            return;
        }

        // Spectators can see everyone and can be seen by everyone (let vanilla handle this)
        for (User user : UserManager.getUsersUnwrapped()) {
            updatePairHideMode(spectator, user, HideMode.NONE);
        }
    }
}
 
Example 7
Source File: PlayerUtils.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public static boolean canEat(Player p, Material food) {
	GameMode gm = p.getGameMode();
	if (gm == GameMode.CREATIVE || gm == GameMode.SPECTATOR)
		return false; // Can't eat anything in those gamemodes
	
	boolean edible = food.isEdible();
	if (!edible)
		return false;
	boolean special;
	switch (food) {
		case GOLDEN_APPLE:
		case CHORUS_FRUIT:
			special = true;
			break;
			//$CASES-OMITTED$
		default:
			special = false;
	}
	if (p.getFoodLevel() < 20 || special)
		return true;
	
	return false;
}
 
Example 8
Source File: CitizensNpcFactory.java    From helper with MIT License 5 votes vote down vote up
private void tickNpcs() {
    for (NPC npc : this.npcRegistry) {
        if (!npc.isSpawned() || !npc.hasTrait(ClickableTrait.class)) continue;

        Npc helperNpc = npc.getTrait(ClickableTrait.class).npc;

        // ensure npcs stay in the same position
        Location loc = npc.getEntity().getLocation();
        if (loc.getBlockX() != helperNpc.getInitialSpawn().getBlockX() || loc.getBlockZ() != helperNpc.getInitialSpawn().getBlockZ()) {
            npc.teleport(helperNpc.getInitialSpawn().clone(), PlayerTeleportEvent.TeleportCause.PLUGIN);
        }

        // don't let players stand near npcs
        for (Entity entity : npc.getStoredLocation().getWorld().getNearbyEntities(npc.getStoredLocation(), 1.0, 1.0, 1.0)) {
            if (!(entity instanceof Player) || this.npcRegistry.isNPC(entity)) continue;

            final Player p = (Player) entity;

            if (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR) {
                continue;
            }

            if (npc.getEntity().getLocation().distance(p.getLocation()) < 3.5) {
                p.setVelocity(p.getLocation().getDirection().multiply(-0.5).setY(0.4));
            }
        }
    }
}
 
Example 9
Source File: Checker.java    From Harbor with MIT License 5 votes vote down vote up
private static boolean isExcluded(final Player player) {
    final boolean excludedByAdventure = Config.getBoolean("exclusions.exclude-adventure")
            && player.getGameMode() == GameMode.ADVENTURE;
    final boolean excludedByCreative = Config.getBoolean("exclusions.exclude-creative")
            && player.getGameMode() == GameMode.CREATIVE;
    final boolean excludedBySpectator = Config.getBoolean("exclusions.exclude-spectator")
            && player.getGameMode() == GameMode.SPECTATOR;
    final boolean excludedByPermission = Config.getBoolean("exclusions.ignored-permission")
            && player.hasPermission("harbor.ignored");
    final boolean excludedByVanish = Config.getBoolean("exclusions.exclude-vanished")
            && isVanished(player);

    return excludedByAdventure || excludedByCreative || excludedBySpectator || excludedByPermission ||
            excludedByVanish || Afk.isAfk(player) || player.isSleepingIgnored();
}
 
Example 10
Source File: GamemodeTool.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private GameMode getOppositeMode(GameMode mode) {
  switch (mode) {
    case CREATIVE:
      return GameMode.SPECTATOR;
    case SPECTATOR:
      return GameMode.CREATIVE;
    default:
      return mode;
  }
}
 
Example 11
Source File: GamemodeTool.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public void toggleObserverGameMode(MatchPlayer player) {
  player.setGameMode(getOppositeMode(player.getGameMode()));
  if (player.getGameMode() == GameMode.SPECTATOR) {
    player.sendWarning(getToggleMessage());
  } else if (isCreative(player)) {
    // Note: When WorldEdit is present, this executes a command to ensure the player is not stuck
    if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
      player.getBukkit().performCommand("worldedit:!");
    }
  }
}
 
Example 12
Source File: FaeEvent.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
    public void onTreeFell(BlockBreakEvent event) {

        if (event.isCancelled()) return;
        if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
        if (!(event.getBlock().getType().equals(Material.LOG) || event.getBlock().getType().equals(Material.LOG_2)))
            return;
//        if (!event.getPlayer().hasPermission("elitemobs.events.fae")) return;
        if (ThreadLocalRandom.current().nextDouble() > ConfigValues.eventsConfig.getDouble(EventsConfig.FAE_CHANCE_ON_CHOP))
            return;

        Fae.spawnFae(event.getBlock().getLocation());

    }
 
Example 13
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onGameModeChange(PlayerGameModeChangeEvent e) {
    Player p = e.getPlayer();
    if (playerStateInfoMap.containsKey(p) && e.getNewGameMode() != GameMode.SPECTATOR) {
        // Don't let low-priority event listeners cancel the gamemode change
        if (e.isCancelled()) e.setCancelled(false);
    }
}
 
Example 14
Source File: MainListener.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSlimeInteract(PlayerInteractEntityEvent event) {
	if (event.getRightClicked().getType() != EntityType.SLIME) {
		return;
	}
		
	Player clicker = event.getPlayer();
	if (clicker.getGameMode() == GameMode.SPECTATOR) {
		return;
	}
	
	NMSEntityBase entityBase = nmsManager.getNMSEntityBase(event.getRightClicked());
	if (entityBase == null || !(entityBase.getHologramLine() instanceof CraftTouchSlimeLine)) {
		return;
	}
	
	CraftTouchSlimeLine touchSlime = (CraftTouchSlimeLine) entityBase.getHologramLine();
	if (touchSlime.getTouchablePiece().getTouchHandler() == null || !touchSlime.getParent().getVisibilityManager().isVisibleTo(clicker)) {
		return;
	}
	
	Long lastClick = anticlickSpam.get(clicker);
	if (lastClick != null && System.currentTimeMillis() - lastClick.longValue() < 100) {
		return;
	}
	
	anticlickSpam.put(event.getPlayer(), System.currentTimeMillis());
	
	try {
		touchSlime.getTouchablePiece().getTouchHandler().onTouch(event.getPlayer());
	} catch (Throwable t) {
		Plugin plugin = touchSlime.getParent() instanceof PluginHologram ? ((PluginHologram) touchSlime.getParent()).getOwner() : HolographicDisplays.getInstance();
		ConsoleLogger.log(Level.WARNING, "The plugin " + plugin.getName() + " generated an exception when the player " + event.getPlayer().getName() + " touched a hologram.", t);
	}
}
 
Example 15
Source File: ArmorStand.java    From TAB with Apache License 2.0 4 votes vote down vote up
public boolean getVisibility() {
	if (Configs.SECRET_armorstands_always_visible) return true;
	return !owner.hasInvisibility() && player.getGameMode() != GameMode.SPECTATOR && !TABAPI.hasHiddenNametag(owner.getUniqueId()) && property.get().length() > 0;
}
 
Example 16
Source File: PlayerTickTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@Override
public void run() {
    for (World world : Bukkit.getServer().getWorlds()) {
        for (Player player : world.getPlayers()) {
            if (player.isDead()) {
                continue;
            }
            final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
            // send queued visuals
            int count = 0;
            final Iterator<BlockSnapshot> iterator = playerData.queuedVisuals.iterator();
            while (iterator.hasNext()) {
                final BlockSnapshot snapshot = iterator.next();
                if (count > GriefDefenderPlugin.getGlobalConfig().getConfig().visual.clientVisualsPerTick) {
                    break;
                }
                NMSUtil.getInstance().sendBlockChange(player, snapshot);
                iterator.remove();
                count++;
            }

            // chat capture
            playerData.updateRecordChat();
            // health regen
            if (world.getFullTime() % 100 == 0L) {
                final GameMode gameMode = player.getGameMode();
                // Handle player health regen
                if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR && GDOptions.isOptionEnabled(Options.PLAYER_HEALTH_REGEN)) {
                    final double maxHealth = player.getMaxHealth();
                    if (player.getHealth() < maxHealth) {
                        final double regenAmount = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_HEALTH_REGEN, claim);
                        if (regenAmount > 0) {
                            final double newHealth = player.getHealth() + regenAmount;
                            if (newHealth > maxHealth) {
                                player.setHealth(maxHealth);
                            } else {
                                player.setHealth(newHealth);
                            }
                        }
                    }
                }
            }
            // teleport delay
            if (world.getFullTime() % 20 == 0L) {
                if (playerData.teleportDelay > 0) {
                    final int delay = playerData.teleportDelay - 1;
                    if (delay == 0) {
                        playerData.teleportDelay = 0;
                        player.teleport(playerData.teleportLocation);
                        playerData.teleportLocation = null;
                        playerData.teleportSourceLocation = null;
                        continue;
                    }
                    TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.TELEPORT_DELAY_NOTICE, 
                            ImmutableMap.of("delay", TextComponent.of(delay, TextColor.GOLD))));
                    playerData.teleportDelay = delay;
                }
            }
        }
    }
}
 
Example 17
Source File: SitListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onClickBlock(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && !event.hasItem()) {
        Block block = event.getClickedBlock();
        BlockFace face = event.getBlockFace();
        if (face == BlockFace.DOWN || block.isLiquid() || !plugin.cfg.sit_blocks.contains(block.getType())) {
            return;
        }
        Block relative = block.getRelative(0, 1, 0);
        Player player = event.getPlayer();
        if (messageCooldown.getIfPresent(player.getUniqueId()) != null) {
            return;
        }
        messageCooldown.put(player.getUniqueId(), true);
        if (!player.hasPermission("nu.sit") || !enabledPlayers.contains(player.getUniqueId()) || player.isInsideVehicle() || !player.getPassengers().isEmpty() || player.getGameMode() == GameMode.SPECTATOR || !player.isOnGround()) {
            return;
        }
        if (relative.isLiquid() || !(relative.isEmpty() || relative.isPassable())) {
            player.sendMessage(I18n.format("user.sit.invalid_location"));
            return;
        }
        Vector vector = block.getBoundingBox().getCenter().clone();
        Location loc = vector.setY(block.getBoundingBox().getMaxY()).toLocation(player.getWorld()).clone();
        for (SitLocation sl : plugin.cfg.sit_locations.values()) {
            if (sl.blocks != null && sl.x != null && sl.y != null && sl.z != null && sl.blocks.contains(block.getType().name())) {
                loc.add(sl.x, sl.y, sl.z);
            }
        }
        if (block.getBlockData() instanceof Directional) {
            face = ((Directional) block.getBlockData()).getFacing();
            if (face == BlockFace.EAST) {
                loc.setYaw(90);
            } else if (face == BlockFace.WEST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(-180);
            }
        } else {
            if (face == BlockFace.WEST) {
                loc.setYaw(90);
            } else if (face == BlockFace.EAST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(-180);
            } else {
                loc.setYaw(player.getEyeLocation().getYaw());
            }
        }
        for (Entity e : loc.getWorld().getNearbyEntities(loc, 0.5, 0.7, 0.5)) {
            if (e instanceof LivingEntity) {
                if (e.hasMetadata(metadata_key) || (e instanceof Player && e.isInsideVehicle() && e.getVehicle().hasMetadata(metadata_key))) {
                    player.sendMessage(I18n.format("user.sit.invalid_location"));
                    return;
                }
            }
        }
        Location safeLoc = player.getLocation().clone();
        ArmorStand armorStand = loc.getWorld().spawn(loc, ArmorStand.class, (e) -> {
            e.setVisible(false);
            e.setPersistent(false);
            e.setCanPickupItems(false);
            e.setBasePlate(false);
            e.setArms(false);
            e.setMarker(true);
            e.setInvulnerable(true);
            e.setGravity(false);
        });
        if (armorStand != null) {
            armorStand.setMetadata(metadata_key, new FixedMetadataValue(plugin, true));
            if (armorStand.addPassenger(player)) {
                safeLocations.put(player.getUniqueId(), safeLoc);
            } else {
                armorStand.remove();
            }
        }
    }
}
 
Example 18
Source File: CommonEntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
private void checkPlayerFlight(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
    if (user == null) {
        return;
    }
    final Player player = user.getOnlinePlayer();
    if (player == null || !player.isFlying()) {
        // Most likely Citizens NPC
        return;
    }
    if (!GDOptions.isOptionEnabled(Options.PLAYER_DENY_FLIGHT)) {
        return;
    }

    final GDPlayerData playerData = user.getInternalPlayerData();
    final GameMode gameMode = player.getGameMode();
    if (gameMode == GameMode.SPECTATOR) {
        return;
    }
    if (gameMode == GameMode.CREATIVE) {
        if (playerData.inPvpCombat() && !GriefDefenderPlugin.getActiveConfig(player.getWorld().getUID()).getConfig().pvp.allowFly) {
            player.setAllowFlight(false);
            player.setFlying(false);
            playerData.ignoreFallDamage = true;
            GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_FLIGHT);
            return;
        }
        return;
    }

    final Boolean noFly = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_FLIGHT, toClaim);
    final boolean adminFly = playerData.userOptionBypassPlayerDenyFlight;
    boolean trustFly = false;
    if (toClaim.isBasicClaim() || (toClaim.parent != null && toClaim.parent.isBasicClaim()) || toClaim.isInTown()) {
        // check owner
        if (playerData.userOptionPerkFlyOwner && toClaim.allowEdit(player) == null) {
            trustFly = true;
        } else {
            if (playerData.userOptionPerkFlyAccessor && toClaim.isUserTrusted(player, TrustTypes.ACCESSOR)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyBuilder && toClaim.isUserTrusted(player, TrustTypes.BUILDER)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyContainer && toClaim.isUserTrusted(player, TrustTypes.CONTAINER)) {
                trustFly = true;
            } else if (playerData.userOptionPerkFlyManager && toClaim.isUserTrusted(player, TrustTypes.MANAGER)) {
                trustFly = true;
            }
         }
    }

    if (trustFly) {
        return;
    }
    if (!adminFly && noFly) {
        player.setAllowFlight(false);
        player.setFlying(false);
        playerData.ignoreFallDamage = true;
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_FLIGHT);
    }
}
 
Example 19
Source File: MagnetTask.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean isValid() {
    return super.isValid() && p.getGameMode() != GameMode.SPECTATOR;
}