Java Code Examples for org.bukkit.GameMode#CREATIVE
The following examples show how to use
org.bukkit.GameMode#CREATIVE .
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: KitLoading.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void ClassChanger(final PlayerPortalEvent event) { if(Game.isGameRunning() && event.getPlayer().getGameMode() != GameMode.CREATIVE) { AnniPlayer p = AnniPlayer.getPlayer(event.getPlayer().getUniqueId()); if(p != null) { event.setCancelled(true); if(p.getTeam() != null) { final Player pl = event.getPlayer(); pl.teleport(p.getTeam().getRandomSpawn()); Bukkit.getScheduler().runTaskLater(AnnihilationMain.getInstance(), new Runnable(){ @Override public void run() { openKitMap(pl); }}, 40); } } } }
Example 2
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onDeath(final PlayerDeathEvent event) { if (event.getEntity().getGameMode() == GameMode.CREATIVE) { return; } final String playerID = PlayerConverter.getID(event.getEntity()); // check if there is data for this player; NPCs don't have data if (BetonQuest.getInstance().getPlayerData(playerID) == null) return; // this prevents the journal from dropping on death by removing it from // the list of drops final List<ItemStack> drops = event.getDrops(); final ListIterator<ItemStack> litr = drops.listIterator(); while (litr.hasNext()) { final ItemStack stack = litr.next(); if (Journal.isJournal(playerID, stack)) { litr.remove(); } // remove all quest items and add them to backpack if (Utils.isQuestItem(stack)) { BetonQuest.getInstance().getPlayerData(playerID).addItem(stack.clone(), stack.getAmount()); litr.remove(); } } }
Example 3
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onItemFrameClick(final PlayerInteractEntityEvent event) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { return; } // this prevents the journal from being placed inside of item frame if (event.getRightClicked() instanceof ItemFrame) { ItemStack item = null; item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand() : event.getPlayer().getInventory().getItemInOffHand(); final String playerID = PlayerConverter.getID(event.getPlayer()); if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) { event.setCancelled(true); } } }
Example 4
Source File: Splint.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { Player p = e.getPlayer(); // Player is neither burning nor injured if (p.getFireTicks() <= 0 && p.getHealth() >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { return; } if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(e.getItem(), false); } p.getWorld().playSound(p.getLocation(), Sound.ENTITY_SKELETON_HURT, 1, 1); p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0)); e.cancel(); }; }
Example 5
Source File: TableSaw.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public void onInteract(Player p, Block b) { ItemStack log = p.getInventory().getItemInMainHand(); Optional<Material> planks = MaterialConverter.getPlanksFromLog(log.getType()); if (planks.isPresent()) { if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(log, true); } ItemStack output = new ItemStack(planks.get(), 8); Inventory outputChest = findOutputChest(b, output); if (outputChest != null) { outputChest.addItem(output); } else { b.getWorld().dropItemNaturally(b.getLocation(), output); } b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, log.getType()); } }
Example 6
Source File: InventoryLoadingListener.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onLoadComplete(InventoryLoadCompleteEvent event) { switch (event.getCause()) { case WORLD_CHANGE: process.postProcessWorldChange(event.getPlayer()); break; case GAMEMODE_CHANGE: if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { // Sometimes some players get Creative mode, but cannot fly event.getPlayer().setAllowFlight(true); } break; case CHANGED_DEFAULTS: default: break; } }
Example 7
Source File: FaeEvent.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@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 8
Source File: PlayerGameModeChangeListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldDoNothingEventCancelled() { // given PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(mock(Player.class), GameMode.CREATIVE); event.setCancelled(true); // when listener.onPlayerGameModeChange(event); // then verifyZeroInteractions(groupManager); verifyZeroInteractions(playerManager); verifyZeroInteractions(bukkitService); }
Example 9
Source File: CraftInventoryView.java From Thermos with GNU General Public License v3.0 | 5 votes |
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
Example 10
Source File: Areas.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST,ignoreCancelled = true) public void checkBreaks(BlockPlaceEvent e) { if(e.getPlayer().getGameMode() != GameMode.CREATIVE) { Area a = this.getArea(new Loc(e.getBlock().getLocation(),false)); if(a != null) { e.setCancelled(true); } } }
Example 11
Source File: DuctListener.java From Transport-Pipes with MIT License | 5 votes |
private void decreaseHandItem(Player p, EquipmentSlot hand) { if (p.getGameMode() == GameMode.CREATIVE) { return; } ItemStack item = hand == EquipmentSlot.HAND ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand(); if (item != null) { if (item.getAmount() <= 1) { item = null; } else { item.setAmount(item.getAmount() - 1); } if (hand == EquipmentSlot.HAND) p.getInventory().setItemInMainHand(item); else p.getInventory().setItemInOffHand(item); } }
Example 12
Source File: GamemodeTool.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private GameMode getOppositeMode(GameMode mode) { switch (mode) { case CREATIVE: return GameMode.SPECTATOR; case SPECTATOR: return GameMode.CREATIVE; default: return mode; } }
Example 13
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBannerBreak(BlockBreakEvent event) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { return; } if (event.getBlock().getType() == Carbon.injector().freeStandingBannerMat || event.getBlock().getType() == Carbon.injector().wallMountedBannerMat) { net.minecraft.server.v1_7_R4.ItemStack itemStack = null; net.minecraft.server.v1_7_R4.World nmsWolrd = ((CraftWorld) event.getBlock().getWorld()).getHandle(); TileEntity tileEntity = nmsWolrd.getTileEntity(event.getBlock().getX(), event.getBlock().getY(), event.getBlock().getZ()); if (tileEntity instanceof TileEntityBanner) { itemStack = new net.minecraft.server.v1_7_R4.ItemStack(Carbon.injector().standingBannerItem, 1, ((TileEntityBanner) tileEntity).getBaseColor()); NBTTagCompound compound = new NBTTagCompound(); tileEntity.b(compound); compound.remove("x"); compound.remove("y"); compound.remove("z"); compound.remove("id"); itemStack.setTag(new NBTTagCompound()); itemStack.getTag().set("BlockEntityTag", compound); } if (itemStack != null) { event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), CraftItemStack.asCraftMirror(itemStack)); } event.getBlock().setType(Material.AIR); event.setCancelled(true); return; } }
Example 14
Source File: CraftInventoryView.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
Example 15
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); ItemStack tool = player.getInventory().getItemInMainHand(); if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (event.getBlock().getType().getHardness() == 0 && !(tool.getType() == Material.SHEARS || ToolType.HOE.contains(tool.getType()))) { return; } if (!modManager.isToolViable(tool)) { return; } FileConfiguration config = MineTinker.getPlugin().getConfig(); //--------------------------------------EXP-CALCULATIONS-------------------------------------------- if (player.getGameMode() != GameMode.CREATIVE) { long cooldown = MineTinker.getPlugin().getConfig().getLong("BlockExpCooldownInSeconds", 60) * 1000; boolean eligible = true; if (cooldown > 0) { List<MetadataValue> blockPlaced = event.getBlock().getMetadata("blockPlaced"); for(MetadataValue val : blockPlaced) { if (val == null) continue; if (!MineTinker.getPlugin().equals(val.getOwningPlugin())) continue; //Not MTs value Object value = val.value(); if (value instanceof Long) { long time = (long) value; eligible = System.currentTimeMillis() - cooldown > time; break; } } } if (eligible) { int expAmount = config.getInt("ExpPerBlockBreak"); if (!(!config.getBoolean("ExtraExpPerBlock.ApplicableToSilkTouch") && modManager.hasMod(tool, SilkTouch.instance()))) { expAmount += config.getInt("ExtraExpPerBlock." + event.getBlock().getType().toString()); //adds 0 if not in found in config (negative values are also fine) } modManager.addExp(player, tool, expAmount); } } //-------------------------------------------POWERCHECK--------------------------------------------- if (Power.HAS_POWER.get(player).get() && !ToolType.PICKAXE.contains(tool.getType()) && event.getBlock().getDrops(tool).isEmpty() && event.getBlock().getType() != Material.NETHER_WART) { //Necessary for EasyHarvest NetherWard-Break event.setCancelled(true); return; } MTBlockBreakEvent breakEvent = new MTBlockBreakEvent(tool, event); Bukkit.getPluginManager().callEvent(breakEvent); //Event-Trigger for Modifiers }
Example 16
Source File: FightHitbox.java From Hawk with GNU General Public License v3.0 | 4 votes |
private void processDirection(InteractEntityEvent e, float yaw, float pitch) { Entity entity = e.getEntity(); if (!(entity instanceof Player) && !CHECK_OTHER_ENTITIES) return; Player attacker = e.getPlayer(); int ping = ServerUtils.getPing(attacker); if (ping > PING_LIMIT && PING_LIMIT != -1) return; HawkPlayer att = e.getHawkPlayer(); Location attackerEyeLocation = att.getPosition().clone().add(new Vector(0, 1.62, 0)).toLocation(att.getWorld()); Vector attackerDirection = MathPlus.getDirection(yaw, pitch); double maxReach = MAX_REACH; if (attacker.getGameMode() == GameMode.CREATIVE) maxReach += 1.9; Vector victimLocation; if (LAG_COMPENSATION) //No need to add 50ms; the move and attack are already chronologically so close together victimLocation = hawk.getLagCompensator().getHistoryLocation(ping, e.getEntity()).toVector(); else victimLocation = e.getEntity().getLocation().toVector(); Vector eyePos = new Vector(attackerEyeLocation.getX(), attacker.isSneaking() ? attackerEyeLocation.getY() - 0.08 : attackerEyeLocation.getY(), attackerEyeLocation.getZ()); Vector direction = new Vector(attackerDirection.getX(), attackerDirection.getY(), attackerDirection.getZ()); Ray attackerRay = new Ray(eyePos, direction); AABB victimAABB; victimAABB = WrappedEntity.getWrappedEntity(entity).getHitbox(victimLocation); victimAABB.expand(BOX_EPSILON, BOX_EPSILON, BOX_EPSILON); Vector intersectVec3d = victimAABB.intersectsRay(attackerRay, 0, Float.MAX_VALUE); if (DEBUG_HITBOX) { victimAABB.highlight(hawk, attacker.getWorld(), 0.29); } if (DEBUG_RAY) { attackerRay.highlight(hawk, attacker.getWorld(), maxReach, 0.1); } if (intersectVec3d != null) { Location intersect = new Location(attacker.getWorld(), intersectVec3d.getX(), intersectVec3d.getY(), intersectVec3d.getZ()); double interDistance = intersect.distance(attackerEyeLocation); if (interDistance > maxReach) { punish(att, 1, true, e, new Placeholder("type", "Reach: " + MathPlus.round(interDistance, 2) + "m")); return; } if (CHECK_OCCLUSION && interDistance > 1D) { BlockIterator iter = new BlockIterator(attacker.getWorld(), eyePos, attackerDirection, 0, (int) interDistance + 1); while (iter.hasNext()) { Block bukkitBlock = iter.next(); if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid()) continue; WrappedBlock b = WrappedBlock.getWrappedBlock(bukkitBlock, att.getClientVersion()); Vector intersection = b.getHitBox().intersectsRay(new Ray(attackerEyeLocation.toVector(), attackerDirection), 0, Float.MAX_VALUE); if (intersection != null) { if (intersection.distance(eyePos) < interDistance) { punish(att, 1, true, e, new Placeholder("type", "Interacted through " + b.getBukkitBlock().getType())); return; } } } } } else if (CHECK_BOX_INTERSECTION) { punish(att, 1, true, e, new Placeholder("type", "Did not hit hitbox.")); return; } reward(att); //reward player }
Example 17
Source File: GravitationalAxe.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
@Override public void onBlockBreak(BlockBreakEvent event, PlayerDetails details) { Block root = event.getBlock(); if (isLog(root.getType())) { // Initialize some variables: World world = event.getPlayer().getWorld(); Location location = root.getLocation(); Random random = new Random(); Vector vel = event.getPlayer().getLocation().toVector().subtract(location.toVector()).normalize().setY(0).multiply(0.2); // Find the blocks Set<Block> blocks = getTreeBlocks(root); if (blocks.size() > 0) { world.playSound(location, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 0.5f, 1); } double durability = blocks.size()*0.25; // Bring 'em down. for (Block block : blocks) { Material mat = block.getType(); if (random.nextFloat() < 0.1f && isLog(mat)) { world.playSound(block.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 0.6f, 1); block.breakNaturally(); durability += 1; } else if (random.nextFloat() < 0.4f && isLeaves(mat)) { world.playSound(block.getLocation(), Sound.BLOCK_GRASS_BREAK, 0.5f, 1); block.breakNaturally(); durability += 1; } else { FallingBlock fallingBlock = world.spawnFallingBlock(block.getLocation(), block.getBlockData()); fallingBlock.setVelocity(vel.multiply(random.nextFloat()*0.2 + 0.9)); if (isLeaves(mat)) { fallingBlock.setDropItem(false); } block.setType(Material.AIR); } } // Apply durability. if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { UtilsMc.offsetItemStackDamage(details.getItem(), (int) durability); } } }
Example 18
Source File: PlayerTickTask.java From GriefDefender with MIT License | 4 votes |
@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 19
Source File: CommonEntityEventHandler.java From GriefDefender with MIT License | 4 votes |
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); } }