Java Code Examples for org.bukkit.GameMode#ADVENTURE

The following examples show how to use org.bukkit.GameMode#ADVENTURE . 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: ListenerPlayerJump.java    From TabooLib with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onJump(PlayerMoveEvent e) {
    // 不是飞行
    if (!e.getPlayer().isFlying()
            // 生存或冒险模式
            && (e.getPlayer().getGameMode() == GameMode.SURVIVAL || e.getPlayer().getGameMode() == GameMode.ADVENTURE)
            // 坐标计算
            && (e.getFrom().getY() + 0.5D != e.getTo().getY())
            && (e.getFrom().getY() + 0.419D < e.getTo().getY())
            // 不在冷却
            && !cooldown.isCooldown(e.getPlayer().getName())) {

        new PlayerJumpEvent(e.getPlayer()).call().ifCancelled(() -> {
            // 返回位置
            e.setTo(e.getFrom());
            // 重置冷却
            cooldown.reset(e.getPlayer().getName());
        });
    }
}
 
Example 2
Source File: GeneralizingListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void detectBlockPunch(PlayerAnimationEvent event) {
  if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) return;
  if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) return;

  // Client will not punch blocks in adventure mode, so we detect it ourselves and fire a
  // BlockPunchEvent.
  // We do this in the kit module only because its the one that is responsible for putting players
  // in adventure mode.
  // A few other modules rely on this, including StaminaModule and BlockDropsModule.
  RayBlockIntersection hit = event.getPlayer().getTargetedBlock(true, false);
  if (hit == null) return;

  pm.callEvent(new BlockPunchEvent(event.getPlayer(), hit));
}
 
Example 3
Source File: GeneralizingListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void detectBlockTrample(CoarsePlayerMoveEvent event) {
  if (!event.getPlayer().isOnGround()) return;
  if (event.getPlayer().getGameMode() != GameMode.ADVENTURE) return;

  Block block = event.getBlockTo().getBlock();
  if (!block.getType().isSolid()) {
    block = block.getRelative(BlockFace.DOWN);
    if (!block.getType().isSolid()) return;
  }

  pm.callEvent(new BlockTrampleEvent(event.getPlayer(), block));
}
 
Example 4
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 5
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void detectBlockPunch(PlayerAnimationEvent event) {
    if(event.getAnimationType() != PlayerAnimationType.ARM_SWING) return;
    if(event.getPlayer().getGameMode() != GameMode.ADVENTURE) return;

    // Client will not punch blocks in adventure mode, so we detect it ourselves and fire a BlockPunchEvent.
    // We do this in the kit module only because its the one that is responsible for putting players in adventure mode.
    // A few other modules rely on this, including StaminaModule and BlockDropsModule.
    RayBlockIntersection hit = event.getPlayer().getTargetedBlock(true, false);
    if(hit == null) return;

    eventBus.callEvent(new BlockPunchEvent(event.getPlayer(), hit));
}
 
Example 6
Source File: PlayerCustomItemDamage.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@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 7
Source File: ClassesTest.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
	final Object[] random = {
			// Java
			(byte) 127, (short) 2000, -1600000, 1L << 40, -1.5f, 13.37,
			"String",
			
			// Skript
			SkriptColor.BLACK, StructureType.RED_MUSHROOM, WeatherType.THUNDER,
			new Date(System.currentTimeMillis()), new Timespan(1337), new Time(12000), new Timeperiod(1000, 23000),
			new Experience(15), new Direction(0, Math.PI, 10), new Direction(new double[] {0, 1, 0}),
			new EntityType(new SimpleEntityData(HumanEntity.class), 300),
			new CreeperData(),
			new SimpleEntityData(Snowball.class),
			new HorseData(Variant.SKELETON_HORSE),
			new WolfData(),
			new XpOrbData(50),
			
			// Bukkit - simple classes only
			GameMode.ADVENTURE, InventoryType.CHEST, DamageCause.FALL,
			
			// there is also at least one variable for each class on my test server which are tested whenever the server shuts down.
	};
	
	for (final Object o : random) {
		Classes.serialize(o); // includes a deserialisation test
	}
}
 
Example 8
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onSpectatorClick(InventoryClickEvent e) {
    if (!(e.getWhoClicked() instanceof Player))
        return;
    Player p = (Player) e.getWhoClicked();
    if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return;
    if (!playerStateInfoMap.containsKey(p)) return;
    if (p.getGameMode() != GameMode.SURVIVAL && p.getGameMode() != GameMode.ADVENTURE
            && p.getGameMode() != GameMode.CREATIVE) {
        e.setCancelled(false);
    }
}
 
Example 9
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHoeUse(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.HOE.contains(tool.getType())) {
		return;
	}

	if (!modManager.isToolViable(tool)) {
		return;
	}

	Block block = event.getClickedBlock();

	boolean apply = false;

	if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block != null) {
		if (block.getType() == Material.GRASS_BLOCK || block.getType() == Material.DIRT)
			apply = true;

		Block b = player.getWorld().getBlockAt(block.getLocation().add(0, 1, 0));
		if (b.getType() != Material.AIR && b.getType() != Material.CAVE_AIR) //Case Block is on top of clicked Block -> No Soil Tilt -> 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);
}
 
Example 10
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 11
Source File: Phase.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@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 12
Source File: User.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Checks if the {@link User} is in {@link GameMode#ADVENTURE} or {@link GameMode#SURVIVAL}
 */
public boolean inAdventureOrSurvivalMode()
{
    return this.player.getGameMode() == GameMode.ADVENTURE || this.player.getGameMode() == GameMode.SURVIVAL;
}
 
Example 13
Source File: GameVars.java    From AnnihilationPro with MIT License 4 votes vote down vote up
public static void loadGameVars(ConfigurationSection config)
	{
		if(config != null)
		{
			useMOTD = config.getBoolean("useMOTD");
			endOfGameCountdown = config.getInt("End-Of-Game-Countdown");
			String command = config.getString("EndGameCommand");
			if(command != null)
				endGameCommand = command.trim();
			//killOnLeave = config.getBoolean("Kill-On-Leave");
			ConfigurationSection gameVars = config.getConfigurationSection("GameVars");
			if(gameVars != null)
			{		
				ConfigurationSection auto = gameVars.getConfigurationSection("AutoStart");
				AutoStart = auto.getBoolean("On");//auto.set("On", false);
				PlayerstoStart = auto.getInt("PlayersToStart");//auto.set("PlayersToStart", 4);
				CountdowntoStart = auto.getInt("CountdownTime");
				
				ConfigurationSection mapload = gameVars.getConfigurationSection("MapLoading");
				Voting = mapload.getBoolean("Voting");//mapload.set("Voting", true);
				maxVotingMaps = mapload.getInt("Max-Maps-For-Voting");
				Map = mapload.getString("UseMap");//mapload.set("UseMap", "plugins/Annihilation/Worlds/Test");
				
				ConfigurationSection autorestart = gameVars.getConfigurationSection("AutoRestart");
				AutoReStart = autorestart.getBoolean("On");//autorestart.set("On", false);
				PlayersToRestart = autorestart.getInt("PlayersToAutoRestart");//autorestart.set("PlayersToAutoRestart", 0);
				CountdowntoRestart = autorestart.getInt("CountdownTime");
				
				ConfigurationSection balance = gameVars.getConfigurationSection("Team-Balancing");
				useTeamBalance = balance.getBoolean("On");//autorestart.set("On", false);
				balanceTolerance = balance.getInt("Tolerance");//autorestart.set("PlayersToAutoRestart", 0);

                ConfigurationSection antilog = gameVars.getConfigurationSection("Anti-Log-System");
                useAntiLog = antilog.getBoolean("On");//autorestart.set("On", false);
                npcTimeout = antilog.getInt("NPC-Time");//autorestart.set("PlayersToAutoRestart", 0);
			
				String gamemode = gameVars.getString("DefaultGameMode");
				if(gamemode != null)
				{
					try
					{
						defaultGamemode = GameMode.valueOf(gamemode.toUpperCase());
					}
					catch(Exception e)
					{
						defaultGamemode = GameMode.ADVENTURE;
					}
				}
			}
		}
		File worldFolder = new File(AnnihilationMain.getInstance().getDataFolder().getAbsolutePath()+"/Worlds");
		if(!worldFolder.exists())
			worldFolder.mkdir();
//		tempWorldPath = AnnihilationMain.getInstance().getDataFolder().getAbsolutePath()+"/TempWorld";
//		worldFolder = new File(tempWorldPath);
//		if(!worldFolder.exists())
//			worldFolder.mkdir();
	}