Java Code Examples for org.bukkit.GameMode#SURVIVAL
The following examples show how to use
org.bukkit.GameMode#SURVIVAL .
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: ToolMenuEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockHit(PlayerInteractEvent e) { if (e == null || e.getClickedBlock() == null || e.getAction() != Action.LEFT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL) { return; } Player player = e.getPlayer(); if (!plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld()) || !isTool(e.getItem())) { return; } // We are in a skyworld, a block has been hit, with the tool Material block = e.getClickedBlock().getType(); short data = e.getClickedBlock().getData(); String itemId = ItemStackUtil.asString(new ItemStack(block, 1, data)); if (commandMap.containsKey(itemId)) { doCmd(e, player, itemId); } if (!e.isCancelled()) { itemId = ItemStackUtil.asString(new ItemStack(block, 1)); if (commandMap.containsKey(itemId)) { doCmd(e, player, itemId); } } }
Example 2
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockHit(PlayerInteractEvent e) { Player player = e.getPlayer(); if (e.getPlayer() == null || e.getClickedBlock() == null || e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL || !isSign(e.getClickedBlock().getType()) || !player.hasPermission("usb.island.signs.use") || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) { return; } if (e.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) e.getClickedBlock().getState(); String firstLine = FormatUtil.stripFormatting(sign.getLine(0)).trim(); if (firstLine.startsWith("/")) { e.setCancelled(true); player.performCommand(firstLine.substring(1)); } } }
Example 3
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void getGroupFromWorldWhereExists() { // given groupManager.clearGroups(); // Clear any existing groups String name = "test"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; groupManager.addGroup(name, worlds, gameMode); // when Group result = groupManager.getGroupFromWorld("test"); // then Group expected = mockGroup(name, worlds, gameMode); assertThat(result.getName(), equalTo(expected.getName())); assertThat(result.getWorlds(), equalTo(expected.getWorlds())); assertThat(result.getGameMode(), equalTo(expected.getGameMode())); }
Example 4
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void addGroupWithUppercaseNameLowercaseGet() { // given groupManager.clearGroups(); // Clear any existing groups String name = "TeSt"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; // when groupManager.addGroup(name, worlds, gameMode); // then Group expected = mockGroup(name, worlds, gameMode); Group actual = groupManager.getGroup("test"); assertThat(actual.getName(), equalTo(expected.getName())); assertThat(actual.getWorlds(), equalTo(expected.getWorlds())); assertThat(actual.getGameMode(), equalTo(expected.getGameMode())); }
Example 5
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void addGroupWithLowercaseName() { // given groupManager.clearGroups(); // Clear any existing groups String name = "test"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; // when groupManager.addGroup(name, worlds, gameMode); // then Group expected = mockGroup(name, worlds, gameMode); Group actual = groupManager.getGroup("test"); assertThat(actual.getName(), equalTo(expected.getName())); assertThat(actual.getWorlds(), equalTo(expected.getWorlds())); assertThat(actual.getGameMode(), equalTo(expected.getGameMode())); }
Example 6
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void getGroupFromWorldWhereExists() { // given groupManager.clearGroups(); // Clear any existing groups String name = "test"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; groupManager.addGroup(name, worlds, gameMode); // when Group result = groupManager.getGroupFromWorld("test"); // then Group expected = mockGroup(name, worlds, gameMode); assertThat(result.getName(), equalTo(expected.getName())); assertThat(result.getWorlds(), equalTo(expected.getWorlds())); assertThat(result.getGameMode(), equalTo(expected.getGameMode())); }
Example 7
Source File: GroupManager.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
/** * Get a group by the name of a world. This method iterates through the groups * and checks if each one contains the name of the given world. If no groups contain * the world, a new group will be created and returned. * * @param world The name of the world in the group. * @return The group that contains the given world. */ public Group getGroupFromWorld(String world) { Group result = null; for (Group group : this.groups.values()) { if (group.containsWorld(world)) { result = group; } } if (result == null) { // If true, world was not defined in worlds.yml Set<String> worlds = new HashSet<>(); worlds.add(world); worlds.add(world + "_nether"); worlds.add(world + "_the_end"); result = new Group(world, worlds, GameMode.SURVIVAL, false); groups.put(world.toLowerCase(), result); } return result; }
Example 8
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void addGroupWithUppercaseName() { // given groupManager.clearGroups(); // Clear any existing groups String name = "TeSt"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; // when groupManager.addGroup(name, worlds, gameMode); // then Group expected = mockGroup(name, worlds, gameMode); Group actual = groupManager.getGroup("TeSt"); assertThat(actual.getName(), equalTo(expected.getName())); assertThat(actual.getWorlds(), equalTo(expected.getWorlds())); assertThat(actual.getGameMode(), equalTo(expected.getGameMode())); }
Example 9
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void getGroupFromWorldWhereNotExists() { // given groupManager.clearGroups(); // Clear any existing groups String name = "test"; Set<String> worlds = new HashSet<>(); worlds.add(name); worlds.add(name + "_nether"); worlds.add(name + "_the_end"); GameMode gameMode = GameMode.SURVIVAL; // when Group result = groupManager.getGroupFromWorld("test"); // then Group expected = mockGroup(name, worlds, gameMode); assertNotNull(result); assertThat(result.getName(), equalTo(expected.getName())); assertThat(result.getWorlds(), equalTo(expected.getWorlds())); assertThat(result.getGameMode(), equalTo(expected.getGameMode())); }
Example 10
Source File: GroupManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void addGroupWithLowercaseName() { // given groupManager.clearGroups(); // Clear any existing groups String name = "test"; Set<String> worlds = new HashSet<>(); worlds.add(name); GameMode gameMode = GameMode.SURVIVAL; // when groupManager.addGroup(name, worlds, gameMode); // then Group expected = mockGroup(name, worlds, gameMode); Group actual = groupManager.getGroup("test"); assertThat(actual.getName(), equalTo(expected.getName())); assertThat(actual.getWorlds(), equalTo(expected.getWorlds())); assertThat(actual.getGameMode(), equalTo(expected.getGameMode())); }
Example 11
Source File: BackpackCommand.java From MarriageMaster with GNU General Public License v3.0 | 5 votes |
private void openBackpack(MarriagePlayer opener, MarriagePlayer partner) { Player sender = opener.getPlayerOnline(); if(sender.getGameMode() == GameMode.SURVIVAL || sender.hasPermission(Permissions.BYPASS_BACKPACK_GAME_MODE)) //TODO use minepacks settings { Player partnerPlayer = partner.getPlayerOnline(); if(partnerPlayer == null || !partnerPlayer.isOnline()) { ((MarriageMaster) getMarriagePlugin()).messagePartnerOffline.send(sender); } else if(partner.isSharingBackpack()) { if(getMarriagePlugin().isInRangeSquared(sender, partnerPlayer, range)) { ((MarriageMaster) getMarriagePlugin()).getBackpacksIntegration().openBackpack(sender, partnerPlayer, true); messageOpened.send(partnerPlayer); } else { ((MarriageMaster) getMarriagePlugin()).messagePartnerNotInRange.send(sender); } } else { messageShareDenied.send(sender); } } else { messageOnlyInSurvival.send(sender); } }
Example 12
Source File: GroupManager.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Loads the groups defined in a 'worlds.yml' file into memory. * * @param config The contents of the configuration file. */ public void loadGroupsToMemory(FileConfiguration config) { groups.clear(); for (String key : config.getConfigurationSection("groups.").getKeys(false)) { List<String> worlds; if (config.contains("groups." + key + ".worlds")) { worlds = config.getStringList("groups." + key + ".worlds"); } else { worlds = config.getStringList("groups." + key); config.set("groups." + key, null); config.set("groups." + key + ".worlds", worlds); if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) { config.set("groups." + key + ".default-gamemode", "SURVIVAL"); } } if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) { GameMode gameMode = GameMode.SURVIVAL; if (config.getString("groups." + key + ".default-gamemode") != null) { gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase()); } addGroup(key, worlds, gameMode); } else { addGroup(key, worlds); } setDefaultsFile(key); } }
Example 13
Source File: PlayerCustomItemDamage.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void gamemodeCheck(PlayerCustomItemDamageEvent event) { GameMode gm = event.getPlayer().getGameMode(); if (gm != GameMode.SURVIVAL && gm != GameMode.ADVENTURE) { event.setCancelled(true); } if (event.getDamage() == 0) { event.setCancelled(true); } }
Example 14
Source File: BlockListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private void handleMaxBuildingHeight(BlockPlaceEvent e){ if (maxBuildingHeight < 0 || e.getPlayer().getGameMode() != GameMode.SURVIVAL) return; if (e.getBlock().getY() > maxBuildingHeight){ e.setCancelled(true); e.getPlayer().sendMessage(Lang.PLAYERS_BUILD_HEIGHT); } }
Example 15
Source File: LifeskillingListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Mining gives enhancement stone. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onChopping(BlockBreakEvent e) { Player player = e.getPlayer(); if (player.getGameMode() != GameMode.SURVIVAL) { return; } if (DropManager.getChopping().contains(e.getBlock().getType())) if (DropManager.choppingChance > random.nextDouble()) { DropManager.randomDrop(player, DropManager.choppingLootTable); } }
Example 16
Source File: LifeskillingListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Mining gives enhancement stone. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onMining(BlockBreakEvent e) { Player player = e.getPlayer(); if (player.getGameMode() != GameMode.SURVIVAL) { return; } if (DropManager.getMining().contains(e.getBlock().getType())) if (DropManager.miningChance > random.nextDouble()) { DropManager.randomDrop(player, DropManager.miningLootTable); } }
Example 17
Source File: BlockBreakSpeedSurvival.java From Hawk with GNU General Public License v3.0 | 5 votes |
private void tickDig(HawkPlayer pp) { Block target = targetBlockMap.get(pp.getUuid()); if(target != null && pp.getPlayer().getGameMode() == GameMode.SURVIVAL) { float accumulatedDamage = blockDamageCumulativeMap.getOrDefault(pp.getUuid(), 0F); float damage = getDamage(target, pp); blockDamageCumulativeMap.put(pp.getUuid(), accumulatedDamage + damage); } }
Example 18
Source File: AsynchronousJoin.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
/** * Processes the given player that has just joined. * * @param player the player to process */ public void processJoin(final Player player) { final String name = player.getName().toLowerCase(); final String ip = PlayerUtils.getPlayerIp(player); if (service.getProperty(RestrictionSettings.UNRESTRICTED_NAMES).contains(name)) { return; } if (service.getProperty(RestrictionSettings.FORCE_SURVIVAL_MODE) && player.getGameMode() != GameMode.SURVIVAL && !service.hasPermission(player, PlayerStatePermission.BYPASS_FORCE_SURVIVAL)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> player.setGameMode(GameMode.SURVIVAL)); } if (service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) { pluginHookService.setEssentialsSocialSpyStatus(player, false); } if (!validationService.fulfillsNameRestrictions(player)) { handlePlayerWithUnmetNameRestriction(player, ip); return; } if (!validatePlayerCountForIp(player, ip)) { return; } final boolean isAuthAvailable = database.isAuthAvailable(name); if (isAuthAvailable) { // Protect inventory if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { ProtectInventoryEvent ev = bukkitService.createAndCallEvent( isAsync -> new ProtectInventoryEvent(player, isAsync)); if (ev.isCancelled()) { player.updateInventory(); logger.fine("ProtectInventoryEvent has been cancelled for " + player.getName() + "..."); } } // Session logic if (sessionService.canResumeSession(player)) { service.send(player, MessageKey.SESSION_RECONNECTION); // Run commands bukkitService.scheduleSyncTaskFromOptionallyAsyncTask( () -> commandManager.runCommandsOnSessionLogin(player)); bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player)); return; } } else if (!service.getProperty(RegistrationSettings.FORCE)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> { welcomeMessageConfiguration.sendWelcomeMessage(player); }); // Skip if registration is optional return; } processJoinSync(player, isAuthAvailable); }
Example 19
Source File: Phase.java From Hawk with GNU General Public License v3.0 | 4 votes |
@Override protected void check(MoveEvent event) { Location locTo = event.getTo(); Location locFrom = event.getFrom(); Player p = event.getPlayer(); HawkPlayer pp = event.getHawkPlayer(); if(!locFrom.getWorld().equals(locTo.getWorld())) return; //this stops an NPE double distanceSquared = locFrom.distanceSquared(locTo); if (distanceSquared == 0) return; double horizDistanceSquared = Math.pow(locTo.getX() - locFrom.getX(), 2) + Math.pow(locTo.getZ() - locFrom.getZ(), 2); double vertDistance = Math.abs(locTo.getY() - locFrom.getY()); Vector moveDirection = new Vector(locTo.getX() - locFrom.getX(), locTo.getY() - locFrom.getY(), locTo.getZ() - locFrom.getZ()); AABB playerFrom = WrappedEntity.getWrappedEntity(p).getCollisionBox(locFrom.toVector()); playerFrom.shrink(SIDE_EPSILON, 0, SIDE_EPSILON); playerFrom.getMin().setY(playerFrom.getMin().getY() + BOTTOM_EPSILON); playerFrom.getMax().setY(playerFrom.getMax().getY() - TOP_EPSILON); AABB playerTo = playerFrom.clone(); playerTo.translate(moveDirection); Vector minBigBox = new Vector(Math.min(playerFrom.getMin().getX(), playerTo.getMin().getX()), Math.min(playerFrom.getMin().getY(), playerTo.getMin().getY()), Math.min(playerFrom.getMin().getZ(), playerTo.getMin().getZ())); Vector maxBigBox = new Vector(Math.max(playerFrom.getMax().getX(), playerTo.getMax().getX()), Math.max(playerFrom.getMax().getY(), playerTo.getMax().getY()), Math.max(playerFrom.getMax().getZ(), playerTo.getMax().getZ())); AABB bigBox = new AABB(minBigBox, maxBigBox); AABB selection = bigBox.clone(); selection.getMin().setY(selection.getMin().getY() - 0.6); //we need to grab blocks below us too, such as fences Set<Location> ignored = pp.getIgnoredBlockCollisions(); GameMode gm = p.getGameMode(); if(gm == GameMode.SURVIVAL || gm == GameMode.ADVENTURE || gm == GameMode.CREATIVE) { for (int x = selection.getMin().getBlockX(); x <= selection.getMax().getBlockX(); x++) { for (int y = selection.getMin().getBlockY(); y <= selection.getMax().getBlockY(); y++) { for (int z = selection.getMin().getBlockZ(); z <= selection.getMax().getBlockZ(); z++) { Location blockLoc = new Location(locTo.getWorld(), x, y, z); //Skip block if it updated within player AABB (only if they move slowly) if(ignored.contains(blockLoc) && horizDistanceSquared <= HORIZONTAL_DISTANCE_THRESHOLD && vertDistance <= VERTICAL_DISTANCE_THRESHOLD) continue; Block bukkitBlock = ServerUtils.getBlockAsync(blockLoc); if (bukkitBlock == null) continue; WrappedBlock block = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion()); if (!block.isSolid()) continue; if(bukkitBlock.getType() == Material.PISTON_MOVING_PIECE) { continue; } if (bukkitBlock.getState().getData() instanceof Openable && horizDistanceSquared <= HORIZONTAL_DISTANCE_THRESHOLD && vertDistance <= VERTICAL_DISTANCE_THRESHOLD) { continue; } for (AABB test : block.getCollisionBoxes()) { //check if "test" box is even in "bigBox" if (!test.isColliding(bigBox)) continue; boolean xCollide = collides2d(test.getMin().getZ(), test.getMax().getZ(), test.getMin().getY(), test.getMax().getY(), playerFrom.getMin().getZ(), playerFrom.getMax().getZ(), playerFrom.getMin().getY(), playerFrom.getMax().getY(), moveDirection.getZ(), moveDirection.getY()); boolean yCollide = collides2d(test.getMin().getX(), test.getMax().getX(), test.getMin().getZ(), test.getMax().getZ(), playerFrom.getMin().getX(), playerFrom.getMax().getX(), playerFrom.getMin().getZ(), playerFrom.getMax().getZ(), moveDirection.getX(), moveDirection.getZ()); boolean zCollide = collides2d(test.getMin().getX(), test.getMax().getX(), test.getMin().getY(), test.getMax().getY(), playerFrom.getMin().getX(), playerFrom.getMax().getX(), playerFrom.getMin().getY(), playerFrom.getMax().getY(), moveDirection.getX(), moveDirection.getY()); if (xCollide && yCollide && zCollide) { punish(pp, false, event, new Placeholder("block", bukkitBlock.getType())); tryRubberband(event); return; } } } } } } reward(pp); }
Example 20
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onShovelUse(PlayerInteractEvent event) { Player player = event.getPlayer(); if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.SHOVEL.contains(tool.getType())) { return; } if (!modManager.isToolViable(tool)) { return; } boolean apply = false; if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) { if (event.getClickedBlock().getType() == Material.GRASS_BLOCK) apply = true; Block b = player.getWorld().getBlockAt(event.getClickedBlock().getLocation().add(0, 1, 0)); if (b.getType() != Material.AIR && b.getType() != Material.CAVE_AIR) //Case Block is on top of clicked Block -> No Path created -> no Exp apply = false; } if (!apply) { return; } if (!modManager.durabilityCheck(event, player, tool)) { return; } modManager.addExp(player, tool, MineTinker.getPlugin().getConfig().getInt("ExpPerBlockBreak")); MTPlayerInteractEvent interactEvent = new MTPlayerInteractEvent(tool, event); Bukkit.getPluginManager().callEvent(interactEvent); }