Here are the examples of the java api org.bukkit.GameMode.SURVIVAL taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
52 Examples
19
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void getGameMode_Default_Survival() {
replacedertEquals(GameMode.SURVIVAL, player.getGameMode());
}
19
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void simulateBlockDamage_Survival_BlockDamaged() {
player.setGameMode(GameMode.SURVIVAL);
BlockMock block = server.addSimpleWorld("world").getBlockAt(0, 0, 0);
replacedertTrue(player.simulateBlockDamage(block));
}
19
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void replacedertGameMode_CorrectGameMode_DoesNotreplacedert() {
player.replacedertGameMode(GameMode.SURVIVAL);
}
19
Source : GridHandler.java
with GNU General Public License v3.0
from OmerBenGera
with GNU General Public License v3.0
from OmerBenGera
@Override
public void cancelIslandPreview(SuperiorPlayer superiorPlayer) {
IslandPreview islandPreview = islandPreviews.remove(superiorPlayer.getUniqueId());
if (islandPreview != null && superiorPlayer.isOnline()) {
Executor.ensureMain(() -> superiorPlayer.teleport(plugin.getGrid().getSpawnIsland(), teleportResult -> {
if (teleportResult)
superiorPlayer.asPlayer().setGameMode(GameMode.SURVIVAL);
}));
PlayerChat.remove(superiorPlayer.asPlayer());
}
}
19
Source : Game.java
with GNU General Public License v3.0
from Dseym
with GNU General Public License v3.0
from Dseym
private void tpToSpawn() {
for (int i = 0; i < players.size(); i++) {
players.get(i).getPlayer().teleport(map.getSpawns().get(i));
players.get(i).getPlayer().setGameMode(GameMode.SURVIVAL);
}
}
19
Source : Cameras.java
with GNU General Public License v3.0
from Dseym
with GNU General Public License v3.0
from Dseym
public void exit(PlayerGame player) {
if (!players.containsKey(player))
return;
player.getPlayer().teleport(locPlayers.get(player));
player.getPlayer().setFlying(false);
player.getPlayer().setGameMode(GameMode.SURVIVAL);
player.setAction(null);
player.getPlayer().getInventory().sereplacedem(8, null);
player.getPlayer().getInventory().setHeldItemSlot(0);
players.remove(player);
locPlayers.remove(player);
}
19
Source : ObserverListener.java
with MIT License
from Avicus
with MIT License
from Avicus
@EventHandler
public void onPlayerSpawn(PlayerSpawnBeginEvent event) {
boolean observing = event.getGroup().isObserving();
// Spigot
event.getPlayer().spigot().setCollidesWithEnreplacedies(!observing);
// Todo?
if (!VersionUtil.isCombatUpdate()) {
event.getPlayer().spigot().setAffectsSpawning(!observing);
}
if (observing) {
event.getPlayer().setGameMode(GameMode.SURVIVAL);
event.getPlayer().setAllowFlight(true);
event.getPlayer().setFlying(true);
// todo: twice is necessary for some reason? still the case?
event.getPlayer().setAllowFlight(true);
event.getPlayer().setFlying(true);
}
}
18
Source : GameModeUtilities.java
with GNU General Public License v3.0
from tr7zw
with GNU General Public License v3.0
from tr7zw
@NotNull
public static GameMode fromNMS(@NotNull net.minecraft.world.GameMode gameMode) {
switch(gameMode) {
case SURVIVAL:
return GameMode.SURVIVAL;
case CREATIVE:
return GameMode.CREATIVE;
case ADVENTURE:
return GameMode.ADVENTURE;
case SPECTATOR:
return GameMode.SPECTATOR;
default:
throw new IllegalArgumentException("Invalid GameMode state!");
}
}
18
Source : ListenerGameMode.java
with GNU General Public License v3.0
from SirBlobman
with GNU General Public License v3.0
from SirBlobman
private GameMode parseGameMode(String string) {
try {
String value = string.toUpperCase();
return GameMode.valueOf(value);
} catch (IllegalArgumentException | NullPointerException ex) {
return GameMode.SURVIVAL;
}
}
18
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void testSimulateBlockPlaceValid() {
Location location = new Location(player.getWorld(), 0, 100, 0);
GameMode originalGM = player.getGameMode();
player.setGameMode(GameMode.SURVIVAL);
boolean worked = player.simulateBlockPlace(Material.STONE, location);
player.setGameMode(originalGM);
replacedertTrue(worked);
}
18
Source : GamePlayer.java
with GNU Lesser General Public License v3.0
from ScreamingSandals
with GNU Lesser General Public License v3.0
from ScreamingSandals
public void resetLife() {
this.player.setAllowFlight(false);
this.player.setFlying(false);
this.player.setExp(0.0F);
this.player.setLevel(0);
this.player.setSneaking(false);
this.player.setSprinting(false);
this.player.setFoodLevel(20);
this.player.setSaturation(10);
this.player.setExhaustion(0);
this.player.setMaxHealth(20D);
this.player.setHealth(this.player.getMaxHealth());
this.player.setFireTicks(0);
this.player.setFallDistance(0);
this.player.setGameMode(GameMode.SURVIVAL);
if (this.player.isInsideVehicle()) {
this.player.leaveVehicle();
}
for (PotionEffect e : this.player.getActivePotionEffects()) {
this.player.removePotionEffect(e.getType());
}
}
18
Source : BridgingAnalyzer.java
with GNU General Public License v2.0
from SakuraKoi
with GNU General Public License v2.0
from SakuraKoi
public static void teleportCheckPoint(Player p) {
p.setFallDistance(0);
clearInventory(p);
p.getInventory().addItem(blockSkinProvider.provide(p));
p.setFoodLevel(20);
p.setHealth(20);
p.setNoDamageTicks(10);
getCounter(p).teleportCheckPoint();
p.setGameMode(GameMode.SURVIVAL);
}
18
Source : GameModeItem.java
with MIT License
from Avicus
with MIT License
from Avicus
@Override
public void onClick(final ClickType type) {
final GameMode mode = this.viewer.getGameMode();
switch(mode) {
case SURVIVAL:
this.viewer.setGameMode(GameMode.SPECTATOR);
break;
case SPECTATOR:
this.viewer.setGameMode(GameMode.SURVIVAL);
this.viewer.setAllowFlight(true);
this.viewer.setFlying(true);
break;
}
this.parent.update(false);
}
17
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void simulateBlockDamage_NotInstaBreak_NotBroken() {
TestPlugin plugin = MockBukkit.load(TestPlugin.clreplaced);
player.setGameMode(GameMode.SURVIVAL);
AtomicBoolean wasBroken = new AtomicBoolean();
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onBlockDamage(BlockDamageEvent event) {
event.setInstaBreak(false);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
wasBroken.set(true);
}
}, plugin);
BlockMock block = server.addSimpleWorld("world").getBlockAt(0, 0, 0);
block.setType(Material.STONE);
replacedumeTrue(player.simulateBlockDamage(block));
replacedertFalse("BlockBreakEvent was fired", wasBroken.get());
block.replacedertType(Material.STONE);
}
17
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void simulateBlockBreak_Survival_BlockBroken() {
MockBukkit.load(TestPlugin.clreplaced);
player.setGameMode(GameMode.SURVIVAL);
BlockMock block = server.addSimpleWorld("world").getBlockAt(0, 0, 0);
block.setType(Material.STONE);
replacedertTrue(player.simulateBlockBreak(block));
server.getPluginManager().replacedertEventFired(BlockDamageEvent.clreplaced);
server.getPluginManager().replacedertEventFired(BlockBreakEvent.clreplaced);
block.replacedertType(Material.AIR);
}
17
Source : PlayerInventory.java
with GNU General Public License v2.0
from PatoTheBest
with GNU General Public License v2.0
from PatoTheBest
public void clearPlayer() {
player.setAllowFlight(false);
player.setFlying(false);
player.setMaxHealth(20.0);
player.setHealth(20.0);
player.setFoodLevel(20);
player.getInventory().setArmorContents(null);
player.getInventory().clear();
player.updateInventory();
player.setLevel(0);
player.setExp(0.0f);
player.setGameMode(GameMode.SURVIVAL);
// player.setVelocity(new org.bukkit.util.Vector(0, 0, 0));
player.setFallDistance(0);
for (final PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
}
17
Source : InventoryUtil.java
with Apache License 2.0
from jiangdashao
with Apache License 2.0
from jiangdashao
/**
* @Description
* 重置玩家,会重置hp food inventory potions
*
* @param player 玩家对象
*/
public static void reset(Player player) {
// 设置游戏模式
player.setGameMode(GameMode.SURVIVAL);
// 重置背包
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.updateInventory();
// 设置HP和饥饿值
player.setHealth(20);
player.setMaxHealth(20);
player.setFoodLevel(20);
// 去除药水效果
player.getActivePotionEffects().stream().map(PotionEffect::getType).forEach(player::removePotionEffect);
// 去除火焰
player.setFireTicks(0);
}
16
Source : EntitySelector.java
with GNU General Public License v3.0
from yuttyann
with GNU General Public License v3.0
from yuttyann
@Nullable
private static GameMode getMode(@NotNull String value) {
if (value.equalsIgnoreCase("0") || value.equalsIgnoreCase("s") || value.equalsIgnoreCase("survival")) {
return GameMode.SURVIVAL;
}
if (value.equalsIgnoreCase("1") || value.equalsIgnoreCase("c") || value.equalsIgnoreCase("creative")) {
return GameMode.CREATIVE;
}
if (value.equalsIgnoreCase("2") || value.equalsIgnoreCase("a") || value.equalsIgnoreCase("adventure")) {
return GameMode.ADVENTURE;
}
if (value.equalsIgnoreCase("3") || value.equalsIgnoreCase("sp") || value.equalsIgnoreCase("spectator")) {
return GameMode.SPECTATOR;
}
return null;
}
16
Source : GracePhase.java
with MIT License
from VoxelGamesLib
with MIT License
from VoxelGamesLib
@Override
public void init() {
setName("GracePhase");
super.init();
setAllowJoin(false);
setAllowSpectate(true);
setTicks(60 * GameConstants.TPS);
MapFeature mapFeature = getGame().createFeature(MapFeature.clreplaced, this);
mapFeature.setShouldUnload(false);
addFeature(mapFeature);
SpawnFeature spawnFeature = getGame().createFeature(SpawnFeature.clreplaced, this);
addFeature(spawnFeature);
MapInfoFeature mapInfoFeature = getGame().createFeature(MapInfoFeature.clreplaced, this);
addFeature(mapInfoFeature);
ScoreboardFeature scoreboardFeature = getGame().createFeature(ScoreboardFeature.clreplaced, this);
addFeature(scoreboardFeature);
NoBlockBreakFeature noBlockBreakFeature = getGame().createFeature(NoBlockBreakFeature.clreplaced, this);
addFeature(noBlockBreakFeature);
NoBlockPlaceFeature noBlockPlaceFeature = getGame().createFeature(NoBlockPlaceFeature.clreplaced, this);
addFeature(noBlockPlaceFeature);
ClearInventoryFeature clearInventoryFeature = getGame().createFeature(ClearInventoryFeature.clreplaced, this);
addFeature(clearInventoryFeature);
NoDamageFeature noDamageFeature = getGame().createFeature(NoDamageFeature.clreplaced, this);
addFeature(noDamageFeature);
HealFeature healFeature = getGame().createFeature(HealFeature.clreplaced, this);
addFeature(healFeature);
GameModeFeature gameModeFeature = getGame().createFeature(GameModeFeature.clreplaced, this);
gameModeFeature.setGameMode(GameMode.SURVIVAL);
addFeature(gameModeFeature);
MobFeature mobFeature = getGame().createFeature(MobFeature.clreplaced, this);
addFeature(mobFeature);
SpectatorFeature spectatorFeature = getGame().createFeature(SpectatorFeature.clreplaced, this);
addFeature(spectatorFeature);
}
16
Source : SurvivalGamesPhase.java
with MIT License
from VoxelGamesLib
with MIT License
from VoxelGamesLib
@Override
public void init() {
setName("SurvivalGamesPhase");
setTicks(2 * 60 * GameConstants.TPS);
super.init();
setAllowJoin(false);
setAllowSpectate(true);
MapFeature mapFeature = getGame().createFeature(MapFeature.clreplaced, this);
mapFeature.setShouldUnload(true);
addFeature(mapFeature);
SpawnFeature spawnFeature = getGame().createFeature(SpawnFeature.clreplaced, this);
spawnFeature.setRespawn(false);
spawnFeature.setInitialSpawn(false);
addFeature(spawnFeature);
GameModeFeature gameModeFeature = getGame().createFeature(GameModeFeature.clreplaced, this);
gameModeFeature.setGameMode(GameMode.SURVIVAL);
addFeature(gameModeFeature);
SurvivalGamesFeature survivalgamesFeature = getGame().createFeature(SurvivalGamesFeature.clreplaced, this);
addFeature(survivalgamesFeature);
AutoRespawnFeature autoRespawnFeature = getGame().createFeature(AutoRespawnFeature.clreplaced, this);
addFeature(autoRespawnFeature);
MobFeature mobFeature = getGame().createFeature(MobFeature.clreplaced, this);
addFeature(mobFeature);
SpectatorFeature spectatorFeature = getGame().createFeature(SpectatorFeature.clreplaced, this);
addFeature(spectatorFeature);
NoBlockBreakFeature noBlockBreakFeature = getGame().createFeature(NoBlockBreakFeature.clreplaced, this);
noBlockBreakFeature.setWhitelist(new Material[] { Material.ACACIA_LEAVES, Material.BIRCH_LEAVES, Material.DARK_OAK_LEAVES, Material.JUNGLE_LEAVES, Material.OAK_LEAVES, Material.SPRUCE_LEAVES, Material.SUNFLOWER, Material.ROSE_BUSH, Material.ROSE_RED, Material.DANDELION_YELLOW, Material.DANDELION, Material.VINE, Material.BROWN_MUSHROOM, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK, Material.RED_MUSHROOM, Material.MELON, Material.MELON_STEM, Material.PUMPKIN_STEM, Material.WHEAT, Material.PUMPKIN });
addFeature(noBlockBreakFeature);
}
16
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void simulateBlockBreak_InstaBreak_BreakEventOnlyFiredOnce() {
TestPlugin plugin = MockBukkit.load(TestPlugin.clreplaced);
player.setGameMode(GameMode.SURVIVAL);
AtomicInteger brokenCount = new AtomicInteger();
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onBlockDamage(BlockDamageEvent event) {
event.setInstaBreak(true);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
brokenCount.incrementAndGet();
}
}, plugin);
BlockMock block = server.addSimpleWorld("world").getBlockAt(0, 0, 0);
block.setType(Material.STONE);
replacedumeTrue(player.simulateBlockBreak(block));
replacedertEquals("BlockBreakEvent was not fired only once", 1, brokenCount.get());
block.replacedertType(Material.AIR);
}
16
Source : PlayerMockTest.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Test
public void simulateBlockDamage_InstaBreak_Broken() {
TestPlugin plugin = MockBukkit.load(TestPlugin.clreplaced);
player.setGameMode(GameMode.SURVIVAL);
AtomicInteger brokenCount = new AtomicInteger();
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onBlockDamage(BlockDamageEvent event) {
event.setInstaBreak(true);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
brokenCount.incrementAndGet();
}
}, plugin);
BlockMock block = server.addSimpleWorld("world").getBlockAt(0, 0, 0);
block.setType(Material.STONE);
replacedumeTrue(player.simulateBlockDamage(block));
replacedertEquals("BlockBreakEvent was not fired only once", 1, brokenCount.get());
block.replacedertType(Material.AIR);
}
16
Source : SpigotUtils.java
with MIT License
from Nicbo
with MIT License
from Nicbo
/**
* Clears players data (effects, health, inventory, etc.)
*
* @param player the player to be cleared
*/
public static void clear(Player player) {
for (PotionEffect potion : player.getActivePotionEffects()) {
player.removePotionEffect(potion.getType());
}
player.setGameMode(GameMode.SURVIVAL);
player.setMaximumNoDamageTicks(20);
player.setFoodLevel(20);
player.setHealth(20);
player.setFireTicks(0);
player.setFallDistance(0.0f);
player.setAllowFlight(false);
player.setFlying(false);
clearInventory(player);
}
14
Source : GamePlayerData.java
with GNU General Public License v3.0
from ShaneBeeStudios
with GNU General Public License v3.0
from ShaneBeeStudios
/**
* Freeze a player
*
* @param player Player to freeze
*/
public void freeze(Player player) {
player.setGameMode(GameMode.SURVIVAL);
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 23423525, -10, false, false));
player.setWalkSpeed(0.0001F);
player.setFoodLevel(1);
player.setAllowFlight(false);
player.setFlying(false);
player.setInvulnerable(true);
}
14
Source : ArenaEvents.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
Arena arena = ArenaRegistry.getArena(e.getPlayer());
if (arena == null || !arena.getPlayers().contains(e.getPlayer())) {
return;
}
Player player = e.getPlayer();
player.setAllowFlight(true);
player.setFlying(true);
User user = plugin.getUserManager().getUser(player);
if (!user.isSpectator()) {
user.setSpectator(true);
player.setGameMode(GameMode.SURVIVAL);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
player.removePotionEffect(PotionEffectType.SPEED);
user.setStat(StatsStorage.StatisticType.ORBS, 0);
}
e.setRespawnLocation(arena.getStartLocation());
}
13
Source : GamePlayerData.java
with GNU General Public License v3.0
from ShaneBeeStudios
with GNU General Public License v3.0
from ShaneBeeStudios
/**
* Put a player into spectator for this game
*
* @param spectator The player to spectate
*/
public void spectate(Player spectator) {
UUID uuid = spectator.getUniqueId();
spectator.teleport(game.gameArenaData.getSpawns().get(0));
if (playerManager.hasPlayerData(uuid)) {
playerManager.transferPlayerDataToSpectator(uuid);
} else {
playerManager.addSpectatorData(new PlayerData(spectator, game));
}
this.spectators.add(uuid);
spectator.setGameMode(GameMode.SURVIVAL);
spectator.setCollidable(false);
if (Config.spectateFly)
spectator.setAllowFlight(true);
if (Config.spectateHide) {
for (UUID u : players) {
Player player = Bukkit.getPlayer(u);
if (player == null)
continue;
player.hidePlayer(plugin, spectator);
}
for (UUID u : spectators) {
Player player = Bukkit.getPlayer(u);
if (player == null)
continue;
player.hidePlayer(plugin, spectator);
}
}
game.getGameBarData().addPlayer(spectator);
game.gameArenaData.board.setBoard(spectator);
spectator.getInventory().sereplacedem(0, plugin.gereplacedemStackManager().getSpectatorCompreplaced());
}
13
Source : ArenaEvents.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@EventHandler(priority = EventPriority.HIGH)
public void onRespawn(PlayerRespawnEvent e) {
Player player = e.getPlayer();
Arena arena = ArenaRegistry.getArena(player);
if (arena == null) {
return;
}
if (arena.getArenaState() == ArenaState.STARTING || arena.getArenaState() == ArenaState.WAITING_FOR_PLAYERS) {
e.setRespawnLocation(arena.getLobbyLocation());
return;
} else if (arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) {
e.setRespawnLocation(arena.getEndLocation());
return;
}
if (arena.getPlayers().contains(player)) {
User user = plugin.getUserManager().getUser(player);
if (player.getLocation().getWorld().equals(arena.getPlayerSpawnPoints().get(0).getWorld())) {
e.setRespawnLocation(player.getLocation());
} else {
e.setRespawnLocation(arena.getPlayerSpawnPoints().get(0));
}
player.setAllowFlight(true);
player.setFlying(true);
user.setSpectator(true);
ArenaUtils.hidePlayer(player, arena);
player.setCollidable(false);
player.setGameMode(GameMode.SURVIVAL);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
user.setStat(StatsStorage.StatisticType.LOCAL_GOLD, 0);
plugin.getRewardsHandler().performReward(player, Reward.RewardType.DEATH);
}
}
13
Source : Alive.java
with GNU Affero General Public License v3.0
from OvercastNetwork
with GNU Affero General Public License v3.0
from OvercastNetwork
@Override
public void enterState() {
super.enterState();
player.reset();
player.setSpawned(true);
player.refreshInteraction();
// Fire Bukkit's event
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(player.getBukkit(), location, false);
player.getMatch().callEvent(respawnEvent);
// Fire our event
ParticipantSpawnEvent spawnEvent = new ParticipantSpawnEvent(player, respawnEvent.getRespawnLocation());
player.getMatch().callEvent(spawnEvent);
// Teleport the player
player.getBukkit().teleport(spawnEvent.getLocation());
// Return kept items
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
player.facetMaybe(ItemKeepPlayerFacet.clreplaced).ifPresent(ItemKeepPlayerFacet::restoreKeptInventory);
player.setVisible(true);
player.refreshVisibility();
bukkit.setGameMode(GameMode.SURVIVAL);
// Apply spawn kit
for (Kit kit : smm.getPlayerKits()) {
player.facet(KitPlayerFacet.clreplaced).applyKit(kit, false);
}
spawn.applyKit(player);
// Apply clreplaced kit(s)
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
match.module(ClreplacedMatchModule.clreplaced).ifPresent(cmm -> cmm.giveClreplacedKits(player));
// Give kill rewards earned while dead
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
match.module(KillRewardMatchModule.clreplaced).ifPresent(krmm -> krmm.giveDeadPlayerRewards(player));
// Apply kit injections from KitMutationModules
match.module(MutationMatchModule.clreplaced).ifPresent(mmm -> {
for (MutationModule module : mmm.getMutationModules()) {
if (module instanceof KitMutationModule) {
KitMutationModule kitModule = ((KitMutationModule) module);
for (Kit kit : kitModule.getKits()) {
player.facet(KitPlayerFacet.clreplaced).applyKit(kit, kitModule.isForceful());
}
}
}
});
player.getBukkit().updateInventory();
if (match.hreplacedtarted()) {
match.callEvent(new ParticipantReleaseEvent(player, false));
} else {
frozenPlayer = freezer.freeze(bukkit);
}
}
13
Source : GridHandler.java
with GNU General Public License v3.0
from OmerBenGera
with GNU General Public License v3.0
from OmerBenGera
@Override
public void createIsland(SuperiorPlayer superiorPlayer, String schemName, BigDecimal bonusWorth, BigDecimal bonusLevel, Biome biome, String islandName, boolean offset) {
if (!Bukkit.isPrimaryThread()) {
Executor.sync(() -> createIsland(superiorPlayer, schemName, bonusWorth, bonusLevel, biome, islandName, offset));
return;
}
SuperiorSkyblockPlugin.debug("Action: Create Island, Target: " + superiorPlayer.getName() + ", Schematic: " + schemName + ", Bonus Worth: " + bonusWorth + ", Bonus Level: " + bonusLevel + ", Biome: " + biome + ", Name: " + islandName + ", Offset: " + offset);
// Removing any active previews for the player.
boolean updateGamemode = islandPreviews.remove(superiorPlayer.getUniqueId()) != null;
if (!EventsCaller.callPreIslandCreateEvent(superiorPlayer, islandName))
return;
UUID islandUUID = generateIslandUUID();
Location islandLocation = plugin.getProviders().getNextLocation(lastIsland.parse().clone(), plugin.getSettings().islandsHeight, plugin.getSettings().maxIslandSize, superiorPlayer.getUniqueId(), islandUUID);
SuperiorSkyblockPlugin.debug("Action: Calculate Next Island, Location: " + LocationUtils.getLocation(islandLocation));
Island island = plugin.getFactory().createIsland(superiorPlayer, islandUUID, islandLocation.add(0.5, 0, 0.5), islandName, schemName);
EventResult<Boolean> event = EventsCaller.callIslandCreateEvent(superiorPlayer, island, schemName);
if (!event.isCancelled()) {
pendingCreationTasks.add(superiorPlayer.getUniqueId());
Schematic schematic = plugin.getSchematics().getSchematic(schemName);
long startTime = System.currentTimeMillis();
schematic.pasteSchematic(island, islandLocation.getBlock().getRelative(BlockFace.DOWN).getLocation(), () -> {
Set<ChunkPosition> loadedChunks = ((BaseSchematic) schematic).getLoadedChunks();
islands.add(superiorPlayer.getUniqueId(), island);
setLastIsland(SBlockPosition.of(islandLocation));
plugin.getDataHandler().insertIsland(island);
pendingCreationTasks.remove(superiorPlayer.getUniqueId());
island.setBonusWorth(offset ? island.getRawWorth().negate() : bonusWorth);
island.setBonusLevel(offset ? island.getRawLevel().negate() : bonusLevel);
island.setBiome(biome);
island.setTeleportLocation(((BaseSchematic) schematic).getTeleportLocation(islandLocation));
if (superiorPlayer.isOnline()) {
Locale.CREATE_ISLAND.send(superiorPlayer, SBlockPosition.of(islandLocation), System.currentTimeMillis() - startTime);
if (event.getResult()) {
if (updateGamemode)
superiorPlayer.asPlayer().setGameMode(GameMode.SURVIVAL);
superiorPlayer.teleport(island, result -> {
if (result)
Executor.sync(() -> IslandUtils.resetChunksExcludedFromList(island, loadedChunks), 10L);
});
}
}
plugin.getProviders().finishIslandCreation(islandLocation, superiorPlayer.getUniqueId(), islandUUID);
}, ex -> {
pendingCreationTasks.remove(superiorPlayer.getUniqueId());
plugin.getProviders().finishIslandCreation(islandLocation, superiorPlayer.getUniqueId(), islandUUID);
ex.printStackTrace();
Locale.CREATE_ISLAND_FAILURE.send(superiorPlayer);
});
}
}
13
Source : EventListener.java
with GNU General Public License v3.0
from Incendo
with GNU General Public License v3.0
from Incendo
@EventHandler
public void onWorldChange(final PlayerChangedWorldEvent event) {
final Player player = event.getPlayer();
final HyperWorld hyperWorld = this.worldManager.getWorld(player.getWorld());
if (hyperWorld == null) {
return;
}
if (hyperConfiguration.shouldGroupProfiles()) {
final HyperWorld from = this.worldManager.getWorld(event.getFrom());
// Only load player data if the worlds belong to different groups
if (from == null || !from.getFlag(ProfileGroupFlag.clreplaced).equals(hyperWorld.getFlag(ProfileGroupFlag.clreplaced))) {
final Path newWorldDirectory = hyperverse.getDataFolder().toPath().resolve("profiles").resolve(hyperWorld.getFlag(ProfileGroupFlag.clreplaced));
if (!Files.exists(newWorldDirectory)) {
try {
Files.createDirectories(newWorldDirectory);
} catch (IOException e) {
e.printStackTrace();
}
}
final Path playerData = newWorldDirectory.resolve(String.format("%s.nbt", player.getUniqueId().toString()));
if (Files.exists(playerData)) {
final GameMode originalGameMode = player.getGameMode();
nms.readPlayerData(event.getPlayer(), playerData, () -> Bukkit.getScheduler().runTaskLater(hyperverse, () -> {
// We need to trick Bukkit into updating the gamemode
final GameMode worldGameMode = hyperWorld.getFlag(GamemodeFlag.clreplaced);
if (worldGameMode != GameMode.ADVENTURE) {
player.setGameMode(GameMode.ADVENTURE);
} else {
player.setGameMode(GameMode.SURVIVAL);
}
player.setGameMode(GameMode.SPECTATOR);
if (!this.setDefaultGameMode(player, hyperWorld)) {
player.setGameMode(originalGameMode);
}
// Apply any other flags here
}, 1L));
} else {
// The player has no stored data. Reset everything
player.setBedSpawnLocation(player.getWorld().getSpawnLocation(), true);
player.getInventory().clear();
player.getEnderChest().clear();
player.setTotalExperience(0);
for (final PotionEffectType potionEffectType : PotionEffectType.values()) {
player.removePotionEffect(potionEffectType);
}
player.setVelocity(new Vector(0, 0, 0));
player.setTicksLived(1);
player.setFireTicks(1);
player.getInventory().setHeldItemSlot(0);
for (final Attribute attribute : Attribute.values()) {
final AttributeInstance attributeInstance = player.getAttribute(attribute);
if (attributeInstance != null) {
attributeInstance.setBaseValue(attributeInstance.getDefaultValue());
for (final AttributeModifier attributeModifier : attributeInstance.getModifiers()) {
attributeInstance.removeModifier(attributeModifier);
}
}
}
this.setDefaultGameMode(player, hyperWorld);
}
}
} else {
this.setDefaultGameMode(player, hyperWorld);
}
}
13
Source : PlayerUtils.java
with GNU General Public License v3.0
from AustinLMayes
with GNU General Public License v3.0
from AustinLMayes
/**
* Reset a player to the default state they would be in if they joined a vanilla server.
*
* @param player to reset
*/
public static void reset(Player player) {
// Attributes
clearAttributes(player);
// Game mode
player.setGameMode(GameMode.SURVIVAL);
// Health/Food
resetHealth(player);
resetFood(player);
// Movement
disableFlight(player);
resetSpeed(player);
resetVelocity(player);
// Vehicles
fullyEject(player);
// Items/Effects
clearInventory(player);
clearEffects(player);
clearXP(player);
// Enreplacedy Data
player.setFireTicks(0);
player.setRemainingAir(20);
player.setCanPickupItems(true);
// Fake Weather/Time
player.resetPlayerWeather();
player.resetPlayerTime();
// Remove arrows
player.setArrowsStuck(0);
// Spigot
player.spigot().setCollidesWithEnreplacedies(true);
player.spigot().setAffectsSpawning(true);
// Skins
resetSkin(player);
}
12
Source : ArenaEvents.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDie(PlayerDeathEvent e) {
Arena arena = ArenaRegistry.getArena(e.getEnreplacedy());
if (arena == null) {
return;
}
if (e.getEnreplacedy().isDead()) {
e.getEnreplacedy().setHealth(e.getEnreplacedy().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
}
e.setDeathMessage("");
e.getDrops().clear();
e.setDroppedExp(0);
plugin.getHolidayManager().applyHolidayDeathEffects(e.getEnreplacedy());
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> e.getEnreplacedy().spigot().respawn(), 5);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Player player = e.getEnreplacedy();
player.spigot().respawn();
User user = plugin.getUserManager().getUser(player);
if (arena.getArenaState() == ArenaState.STARTING) {
player.teleport(arena.getStartLocation());
return;
} else if (arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) {
player.getInventory().clear();
player.setFlying(false);
player.setAllowFlight(false);
user.setStat(StatsStorage.StatisticType.ORBS, 0);
player.teleport(arena.getEndLocation());
return;
}
plugin.getUserManager().addStat(player, StatsStorage.StatisticType.DEATHS);
player.teleport(arena.getStartLocation());
user.setSpectator(true);
player.setGameMode(GameMode.SURVIVAL);
user.setStat(StatsStorage.StatisticType.ORBS, 0);
ArenaUtils.hidePlayer(player, arena);
player.setAllowFlight(true);
player.setFlying(true);
player.getInventory().clear();
Utils.sendreplacedle(player, 0, 5 * 20, 0, plugin.getChatManager().colorMessage(Messages.DEATH_SCREEN), null);
sendSpectatorActionBar(user, arena);
plugin.getChatManager().broadcastAction(arena, player, ChatManager.ActionType.DEATH);
// running in a scheduler of 1 tick due to respawn bug
Bukkit.getScheduler().runTaskLater(plugin, () -> {
for (SpecialItem item : plugin.getSpecialItemManager().getSpecialItems()) {
if (item.getDisplayStage() != SpecialItem.DisplayStage.SPECTATOR) {
continue;
}
player.getInventory().sereplacedem(item.getSlot(), item.gereplacedemStack());
}
}, 1);
untargetPlayerFromZombies(player, arena);
}, 10);
}
12
Source : ArenaEvents.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDie(PlayerDeathEvent e) {
Arena arena = ArenaRegistry.getArena(e.getEnreplacedy());
if (arena == null) {
return;
}
e.setDeathMessage("");
e.getDrops().clear();
e.setDroppedExp(0);
plugin.getCorpseHandler().spawnCorpse(e.getEnreplacedy(), arena);
e.getEnreplacedy().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 3 * 20, 0));
Player player = e.getEnreplacedy();
if (arena.getArenaState() == ArenaState.STARTING) {
return;
} else if (arena.getArenaState() == ArenaState.ENDING || arena.getArenaState() == ArenaState.RESTARTING) {
player.getInventory().clear();
player.setFlying(false);
player.setAllowFlight(false);
plugin.getUserManager().getUser(player).setStat(StatsStorage.StatisticType.LOCAL_GOLD, 0);
return;
}
if (Role.isRole(Role.MURDERER, player) && arena.lastAliveMurderer()) {
ArenaUtils.onMurdererDeath(arena);
}
if (Role.isRole(Role.ANY_DETECTIVE, player) && arena.lastAliveDetective()) {
arena.setDetectiveDead(true);
if (Role.isRole(Role.FAKE_DETECTIVE, player)) {
arena.setCharacter(Arena.CharacterType.FAKE_DETECTIVE, null);
}
ArenaUtils.dropBowAndAnnounce(arena, player);
}
User user = plugin.getUserManager().getUser(player);
user.addStat(StatsStorage.StatisticType.DEATHS, 1);
user.setSpectator(true);
player.setCollidable(false);
player.setGameMode(GameMode.SURVIVAL);
user.setStat(StatsStorage.StatisticType.LOCAL_GOLD, 0);
ArenaUtils.hidePlayer(player, arena);
player.setAllowFlight(true);
player.setFlying(true);
player.getInventory().clear();
chatManager.broadcastAction(arena, player, ChatManager.ActionType.DEATH);
if (arena.getArenaState() != ArenaState.ENDING && arena.getArenaState() != ArenaState.RESTARTING) {
arena.addDeathPlayer(player);
}
// we must call it ticks later due to instant respawn bug
Bukkit.getScheduler().runTaskLater(plugin, () -> {
e.getEnreplacedy().spigot().respawn();
player.getInventory().sereplacedem(0, new ItemBuilder(XMaterial.COMPreplaced.parseItem()).name(chatManager.colorMessage("In-Game.Spectator.Spectator-Item-Name", player)).build());
player.getInventory().sereplacedem(4, new ItemBuilder(XMaterial.COMPARATOR.parseItem()).name(chatManager.colorMessage("In-Game.Spectator.Settings-Menu.Item-Name", player)).build());
player.getInventory().sereplacedem(8, SpecialItemManager.getSpecialItem("Leave").gereplacedemStack());
}, 5);
}
12
Source : ProtectionsTests.java
with GNU General Public License v3.0
from Multitallented
with GNU General Public License v3.0
from Multitallented
@Test
public void blockBreakInProtectionShouldBeCancelled() {
RegionsTests.loadRegionTypeCobble();
Player player = mock(Player.clreplaced);
when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
UUID uuid = new UUID(1, 2);
when(player.getUniqueId()).thenReturn(uuid);
Player player2 = mock(Player.clreplaced);
when(player2.getGameMode()).thenReturn(GameMode.SURVIVAL);
UUID uuid2 = new UUID(1, 3);
when(player2.getUniqueId()).thenReturn(uuid2);
HashMap<UUID, String> owners = new HashMap<>();
owners.put(uuid2, Constants.OWNER);
Location regionLocation = new Location(Bukkit.getWorld("world"), 0, 0, 0);
HashMap<String, String> effects = new HashMap<>();
effects.put("block_break", null);
effects.put("block_build", null);
RegionManager.getInstance().addRegion(new Region("cobble", owners, regionLocation, RegionsTests.getRadii(), effects, 0));
ProtectionHandler protectionHandler = new ProtectionHandler();
BlockBreakEvent event = new BlockBreakEvent(TestUtil.block3, player);
protectionHandler.onBlockBreak(event);
replacedertTrue(event.isCancelled());
}
12
Source : ForagingAbilities.java
with MIT License
from Archy-X
with MIT License
from Archy-X
public void lumberjack(Player player, Block block) {
if (OptionL.isEnabled(Skill.FORAGING)) {
if (plugin.getAbilityManager().isEnabled(Ability.LUMBERJACK)) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
PlayerSkill skill = SkillLoader.playerSkills.get(player.getUniqueId());
if (skill.getAbilityLevel(Ability.LUMBERJACK) > 0) {
if (r.nextDouble() < ((getValue(Ability.LUMBERJACK, skill)) / 100)) {
for (ItemStack item : block.getDrops()) {
PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUMBERJACK);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.gereplacedemStack());
}
}
}
}
}
}
}
}
11
Source : Main.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@Override
public void onDisable() {
if (forceDisable) {
return;
}
Debugger.debug("System disable initialized");
long start = System.currentTimeMillis();
Bukkit.getLogger().removeHandler(exceptionLogHandler);
saveAllUserStatistics();
if (configPreferences.getOption(ConfigPreferences.Option.DATABASE_ENABLED)) {
getMysqlDatabase().shutdownConnPool();
}
for (ArmorStand armorStand : HologramManager.getArmorStands()) {
armorStand.remove();
armorStand.setCustomNameVisible(false);
}
HologramManager.getArmorStands().clear();
for (Arena arena : ArenaRegistry.getArenas()) {
arena.getScoreboardManager().stopAllScoreboards();
for (Player player : arena.getPlayers()) {
arena.doBarAction(Arena.BarAction.REMOVE, player);
arena.teleportToEndLocation(player);
player.setFlySpeed(0.1f);
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.getActivePotionEffects().forEach(pe -> player.removePotionEffect(pe.getType()));
player.setWalkSpeed(0.2f);
player.setGameMode(GameMode.SURVIVAL);
if (configPreferences.getOption(ConfigPreferences.Option.INVENTORY_MANAGER_ENABLED)) {
InventorySerializer.loadInventory(this, player);
}
}
arena.teleportAllToEndLocation();
arena.cleanUpArena();
}
Debugger.debug("System disable finished took {0}ms", System.currentTimeMillis() - start);
}
11
Source : Alive.java
with GNU Affero General Public License v3.0
from PGMDev
with GNU Affero General Public License v3.0
from PGMDev
@Override
public void enterState() {
super.enterState();
player.reset();
player.setDead(false);
player.resetInteraction();
// Fire Bukkit's event
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(player.getBukkit(), location, false);
player.getMatch().callEvent(respawnEvent);
// Fire our event
ParticipantSpawnEvent spawnEvent = new ParticipantSpawnEvent(player, respawnEvent.getRespawnLocation());
player.getMatch().callEvent(spawnEvent);
// Teleport the player
player.getBukkit().teleport(spawnEvent.getLocation());
// Return kept items
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
ItemKeepMatchModule ikmm = player.getMatch().getModule(ItemKeepMatchModule.clreplaced);
if (ikmm != null) {
ikmm.restoreKeptArmor(player);
ikmm.restoreKeptInventory(player);
}
player.setVisible(true);
player.resetVisibility();
player.setGameMode(GameMode.SURVIVAL);
bukkit.setAllowFlight(false);
// Apply spawn kit
spawn.applyKit(player);
// Apply clreplaced kit(s)
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
ClreplacedMatchModule cmm = player.getMatch().getModule(ClreplacedMatchModule.clreplaced);
if (cmm != null) {
cmm.giveClreplacedKits(player);
}
// Give kill rewards earned while dead
// TODO: Module should do this itself, maybe from ParticipantSpawnEvent
KillRewardMatchModule kwmm = player.getMatch().getModule(KillRewardMatchModule.clreplaced);
if (kwmm != null) {
kwmm.giveDeadPlayerRewards(player);
}
player.getBukkit().updateInventory();
}
11
Source : FarmingAbilities.java
with MIT License
from Archy-X
with MIT License
from Archy-X
public void bountifulHarvest(Player player, Block block) {
if (OptionL.isEnabled(Skill.FARMING)) {
if (plugin.getAbilityManager().isEnabled(Ability.BOUNTIFUL_HARVEST)) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
PlayerSkill skill = SkillLoader.playerSkills.get(player.getUniqueId());
if (skill.getAbilityLevel(Ability.BOUNTIFUL_HARVEST) > 0) {
if (r.nextDouble() < (getValue(Ability.BOUNTIFUL_HARVEST, skill)) / 100) {
for (ItemStack item : block.getDrops()) {
PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BOUNTIFUL_HARVEST);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.gereplacedemStack());
}
}
}
}
}
}
}
}
10
Source : Main.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@Override
public void onDisable() {
if (forceDisable)
return;
Debugger.debug("System disabling...");
Bukkit.getLogger().removeHandler(exceptionLogHandler);
for (BaseArena arena : ArenaRegistry.getArenas()) {
for (Player player : arena.getPlayers()) {
arena.getScoreboardManager().stopAllScoreboards();
arena.doBarAction(BaseArena.BarAction.REMOVE, player);
arena.teleportToEndLocation(player);
player.setGameMode(GameMode.SURVIVAL);
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.getActivePotionEffects().forEach(pe -> player.removePotionEffect(pe.getType()));
if (configPreferences.getOption(ConfigPreferences.Option.INVENTORY_MANAGER_ENABLED)) {
InventorySerializer.loadInventory(this, player);
}
}
arena.getPlotManager().getPlots().forEach(Plot::fullyResetPlot);
arena.teleportAllToEndLocation();
}
saveAllUserStatistics();
if (configPreferences.getOption(ConfigPreferences.Option.DATABASE_ENABLED)) {
getMysqlDatabase().shutdownConnPool();
}
}
10
Source : AtrioListener.java
with MIT License
from Avicus
with MIT License
from Avicus
public void resetPlayer(Player player) {
player.teleport(this.spawn.getRegion().getRandomPosition(this.random).toLocation(AtrioPlugin.getInstance().getWorld(), this.spawn.getYaw(), this.spawn.getPitch()));
player.setVelocity(this.spawn.getVelocity());
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false);
player.setHealth(20);
player.setFoodLevel(20);
player.getInventory().clear();
PlayerInventory inventory = player.getInventory();
if (AtrioConfig.Inventory.ServerMenu.isEnabled()) {
inventory.sereplacedem(AtrioConfig.Inventory.ServerMenu.getSlot(), Servers.createMenuOpener(player));
}
if (AtrioConfig.Inventory.Backpack.isEnabled()) {
inventory.sereplacedem(AtrioConfig.Inventory.Backpack.getSlot(), createBackpackOpener(player));
}
if (AtrioConfig.Inventory.Store.isEnabled()) {
inventory.sereplacedem(AtrioConfig.Inventory.Store.getSlot(), Credits.createGadgetStoreOpener(player));
}
if (this.book.isPresent()) {
inventory.sereplacedem(AtrioConfig.Inventory.Book.getSlot(), this.book.get());
}
MaterialData helmet = toMaterial(AtrioConfig.Inventory.Armor.getHelmet().replace(' ', '_').toUpperCase());
MaterialData chestplate = toMaterial(AtrioConfig.Inventory.Armor.getChestplate().replace(' ', '_').toUpperCase());
MaterialData leggings = toMaterial(AtrioConfig.Inventory.Armor.getLeggings().replace(' ', '_').toUpperCase());
MaterialData boots = toMaterial(AtrioConfig.Inventory.Armor.getBoots().replace(' ', '_').toUpperCase());
inventory.setHelmet(helmet.toItemStack(1));
inventory.setChestplate(chestplate.toItemStack(1));
inventory.setLeggings(leggings.toItemStack(1));
inventory.setBoots(boots.toItemStack(1));
}
10
Source : MiningAbilities.java
with MIT License
from Archy-X
with MIT License
from Archy-X
public void luckyMiner(Player player, Block block) {
if (OptionL.isEnabled(Skill.MINING)) {
if (plugin.getAbilityManager().isEnabled(Ability.LUCKY_MINER)) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
if (SkillLoader.playerSkills.containsKey(player.getUniqueId())) {
PlayerSkill skill = SkillLoader.playerSkills.get(player.getUniqueId());
if (skill.getAbilityLevel(Ability.LUCKY_MINER) > 0) {
if (r.nextDouble() < (getValue(Ability.LUCKY_MINER, skill) / 100)) {
ItemStack tool = player.getInventory().gereplacedemInMainHand();
Material mat = block.getType();
if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
if (mat.equals(Material.DIAMOND_ORE) || mat.equals(Material.LAPIS_ORE) || mat.equals(Material.REDSTONE_ORE) || mat.name().equals("GLOWING_REDSTONE_ORE") || mat.equals(Material.EMERALD_ORE) || mat.equals(Material.COAL_ORE) || mat.equals(XMaterial.NETHER_QUARTZ_ORE.parseMaterial()) || mat.equals(XMaterial.NETHER_GOLD_ORE.parseMaterial())) {
return;
}
}
Collection<ItemStack> drops = block.getDrops(tool);
for (ItemStack item : drops) {
PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCKY_MINER);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.gereplacedemStack());
}
}
}
}
}
}
}
}
}
10
Source : FarmingAbilities.java
with MIT License
from Archy-X
with MIT License
from Archy-X
public void tripleHarvest(Player player, Block block) {
if (OptionL.isEnabled(Skill.FARMING)) {
if (plugin.getAbilityManager().isEnabled(Ability.TRIPLE_HARVEST)) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
PlayerSkill playerSkill = SkillLoader.playerSkills.get(player.getUniqueId());
if (playerSkill != null) {
if (playerSkill.getAbilityLevel(Ability.TRIPLE_HARVEST) > 0) {
if (r.nextDouble() < (getValue(Ability.TRIPLE_HARVEST, playerSkill)) / 100) {
for (ItemStack item : block.getDrops()) {
ItemStack droppedItem = item.clone();
droppedItem.setAmount(2);
PlayerLootDropEvent event = new PlayerLootDropEvent(player, droppedItem, block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.TRIPLE_HARVEST);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.gereplacedemStack());
}
}
}
}
}
}
}
}
}
9
Source : Lobby.java
with GNU General Public License v3.0
from Dseym
with GNU General Public License v3.0
from Dseym
public void leave(Player player, boolean disconnect) {
if (!disconnect && game != null && game.isStart()) {
player.sendMessage(Main.tagPlugin + Messages.isGameStart);
return;
}
LobbyPlayerLeaveEvent playerLeave = new LobbyPlayerLeaveEvent(this, player);
Bukkit.getPluginManager().callEvent(playerLeave);
time = 60;
player.sendMessage(Main.tagPlugin + Messages.plLeaveFromLobby);
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
player.teleport(locPlayers.get(player));
player.setGameMode(GameMode.SURVIVAL);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
player.getInventory().clear();
player.getInventory().setHeldItemSlot(0);
locPlayers.remove(player);
players.remove(player);
if (owner.equals(player))
owner = null;
if (players.size() != 0)
owner = players.get(0);
reloadSb();
for (Player _player : players) _player.sendMessage(Main.tagPlugin + "§e" + Messages.plLeaveFromLobbyMessPlayers.replace("@player@", player.getDisplayName()).replace("@countPlayers@", "" + players.size()));
}
8
Source : ArenaUtils.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
public static void bringDeathPlayersBack(Arena arena) {
for (Player player : arena.getPlayers()) {
if (arena.getPlayersLeft().contains(player)) {
continue;
}
User user = plugin.getUserManager().getUser(player);
if (!plugin.getConfigPreferences().getOption(ConfigPreferences.Option.INGAME_JOIN_RESPAWN) && user.isPermanentSpectator()) {
continue;
}
user.setSpectator(false);
player.teleport(arena.getStartLocation());
player.setFlying(false);
player.setAllowFlight(false);
// the default fly speed
player.setFlySpeed(0.1f);
player.setGameMode(GameMode.SURVIVAL);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
player.removePotionEffect(PotionEffectType.SPEED);
player.getInventory().clear();
ArenaUtils.showPlayer(player, arena);
user.getKit().giveKireplacedems(player);
player.updateInventory();
player.sendMessage(plugin.getChatManager().colorMessage(Messages.BACK_IN_GAME));
}
}
8
Source : DeathmatchHandler.java
with GNU General Public License v3.0
from Mezy
with GNU General Public License v3.0
from Mezy
private void teleportTeam(UhcTeam team, Location spawnLocation, Location spectateLocation) {
for (UhcPlayer player : team.getMembers()) {
Player bukkitPlayer;
try {
bukkitPlayer = player.getPlayer();
} catch (UhcPlayerNotOnlineException e) {
// Ignore offline players
continue;
}
if (player.getState().equals(PlayerState.PLAYING)) {
if (config.get(MainConfig.DEATHMATCH_ADVENTURE_MODE)) {
bukkitPlayer.setGameMode(GameMode.ADVENTURE);
} else {
bukkitPlayer.setGameMode(GameMode.SURVIVAL);
}
player.freezePlayer(spawnLocation);
bukkitPlayer.teleport(spawnLocation);
} else {
bukkitPlayer.teleport(spectateLocation);
}
}
}
7
Source : ArenaUtils.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
public static void resetPlayerAfterGame(Player player) {
for (Player players : plugin.getServer().getOnlinePlayers()) {
MiscUtils.showPlayer(plugin, players, player);
MiscUtils.showPlayer(plugin, player, players);
}
player.setGlowing(false);
player.setGameMode(GameMode.SURVIVAL);
player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));
player.setFlying(false);
player.setAllowFlight(false);
player.getInventory().clear();
player.getInventory().setArmorContents(null);
MiscUtils.getEnreplacedyAttribute(player, Attribute.GENERIC_MAX_HEALTH).ifPresent(ai -> {
ai.setBaseValue(20.0);
player.setHealth(ai.getValue());
});
player.setFireTicks(0);
player.setFoodLevel(20);
if (plugin.getConfigPreferences().getOption(ConfigPreferences.Option.INVENTORY_MANAGER_ENABLED)) {
InventorySerializer.loadInventory(plugin, player);
}
}
7
Source : Luck.java
with MIT License
from Archy-X
with MIT License
from Archy-X
@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("deprecation")
public void onBlockBreak(BlockBreakEvent event) {
if (OptionL.getBoolean(Option.LUCK_DOUBLE_DROP_ENABLED) && !event.isCancelled()) {
Player player = event.getPlayer();
Block block = event.getBlock();
// Checks if in blocked or disabled world
if (plugin.getWorldManager().isInBlockedWorld(block.getLocation())) {
return;
}
// Checks if in blocked region
if (plugin.isWorldGuardEnabled()) {
if (plugin.getWorldGuardSupport().isInBlockedRegion(block.getLocation())) {
return;
}
}
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
if (!event.getBlock().hasMetadata("skillsPlaced")) {
if (SkillLoader.playerStats.containsKey(event.getPlayer().getUniqueId())) {
PlayerStat stat = SkillLoader.playerStats.get(event.getPlayer().getUniqueId());
Material mat = block.getType();
if (mat.equals(Material.STONE) || mat.equals(Material.COBBLESTONE) || mat.equals(Material.SAND) || mat.equals(Material.GRAVEL) || mat.equals(Material.DIRT) || mat.equals(XMaterial.GRreplaced_BLOCK.parseMaterial()) || mat.equals(XMaterial.ANDESITE.parseMaterial()) || mat.equals(XMaterial.DIORITE.parseMaterial()) || mat.equals(XMaterial.GRANITE.parseMaterial())) {
// Calculate chance
double chance = stat.getStatLevel(Stat.LUCK) * OptionL.getDouble(Option.LUCK_DOUBLE_DROP_MODIFIER);
if (chance * 100 > OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX)) {
chance = OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX);
}
if (r.nextDouble() < chance) {
ItemStack tool = player.getInventory().gereplacedemInMainHand();
for (ItemStack item : block.getDrops(tool)) {
// If silk touch
if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
if (mat.equals(Material.STONE)) {
if (!XMaterial.isNewVersion()) {
if (block.getData() == 0) {
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.gereplacedemStack());
}
}
} else {
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.gereplacedemStack());
}
}
} else if (mat.equals(XMaterial.GRreplaced_BLOCK.parseMaterial())) {
Material grreplacedBlock = XMaterial.GRreplaced_BLOCK.parseMaterial();
if (grreplacedBlock != null) {
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(grreplacedBlock), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.gereplacedemStack());
}
}
}
} else // Drop regular item if not silk touch
{
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.gereplacedemStack());
}
}
}
}
}
}
}
}
}
}
4
Source : ArenaManager.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
/**
* Attempts player to join arena.
* Calls VillageGameJoinAttemptEvent.
* Can be cancelled only via above-mentioned event
*
* @param player player to join
* @param arena arena to join
* @see VillageGameJoinAttemptEvent
*/
public static void joinAttempt(@NotNull Player player, @NotNull Arena arena) {
Debugger.debug("[{0}] Initial join attempt for {1}", arena.getId(), player.getName());
if (!canJoinArenaAndMessage(player, arena) || !checkFullGamePermission(player, arena)) {
return;
}
Debugger.debug("[{0}] Checked join attempt for {1}", arena.getId(), player.getName());
long start = System.currentTimeMillis();
if (ArenaRegistry.isInArena(player)) {
player.sendMessage(plugin.getChatManager().getPrefix() + plugin.getChatManager().colorMessage(Messages.ALREADY_PLAYING));
return;
}
// check if player is in party and send party members to the game
if (plugin.getPartyHandler().isPlayerInParty(player)) {
GameParty party = plugin.getPartyHandler().getParty(player);
if (player == party.getLeader()) {
if (arena.getMaximumPlayers() - arena.getPlayers().size() >= party.getPlayers().size()) {
for (Player partyPlayer : party.getPlayers()) {
if (partyPlayer == player) {
continue;
}
if (ArenaRegistry.isInArena(partyPlayer)) {
if (ArenaRegistry.getArena(partyPlayer).getArenaState() == ArenaState.IN_GAME) {
continue;
}
leaveAttempt(partyPlayer, ArenaRegistry.getArena(partyPlayer));
}
partyPlayer.sendMessage(plugin.getChatManager().getPrefix() + plugin.getChatManager().formatMessage(arena, plugin.getChatManager().colorMessage(Messages.JOIN_AS_PARTY_MEMBER), partyPlayer));
joinAttempt(partyPlayer, arena);
}
} else {
player.sendMessage(plugin.getChatManager().getPrefix() + plugin.getChatManager().formatMessage(arena, plugin.getChatManager().colorMessage(Messages.NOT_ENOUGH_SPACE_FOR_PARTY), player));
return;
}
}
}
arena.getPlayers().add(player);
User user = plugin.getUserManager().getUser(player);
arena.getScoreboardManager().createScoreboard(user);
if ((arena.getArenaState() == ArenaState.IN_GAME || (arena.getArenaState() == ArenaState.STARTING && arena.getTimer() <= 3) || arena.getArenaState() == ArenaState.ENDING)) {
if (!plugin.getConfigPreferences().getOption(ConfigPreferences.Option.INGAME_JOIN_RESPAWN)) {
user.setPermanentSpectator(true);
}
if (plugin.getConfigPreferences().getOption(ConfigPreferences.Option.INVENTORY_MANAGER_ENABLED)) {
InventorySerializer.saveInventoryToFile(plugin, player);
}
player.teleport(arena.getStartLocation());
player.sendMessage(plugin.getChatManager().colorMessage(Messages.YOU_ARE_SPECTATOR));
player.getInventory().clear();
for (SpecialItem item : plugin.getSpecialItemManager().getSpecialItems()) {
if (item.getDisplayStage() == SpecialItem.DisplayStage.SPECTATOR) {
player.getInventory().sereplacedem(item.getSlot(), item.gereplacedemStack());
}
}
player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
MiscUtils.getEnreplacedyAttribute(player, Attribute.GENERIC_MAX_HEALTH).ifPresent(ai -> {
ai.setBaseValue(ai.getValue() + arena.getOption(ArenaOption.ROTTEN_FLESH_LEVEL));
player.setHealth(ai.getValue());
});
player.setFoodLevel(20);
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
player.setFlying(true);
user.setSpectator(true);
user.setStat(StatsStorage.StatisticType.ORBS, 0);
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
ArenaUtils.hidePlayer(player, arena);
for (Player spectator : arena.getPlayers()) {
if (plugin.getUserManager().getUser(spectator).isSpectator()) {
MiscUtils.hidePlayer(plugin, player, spectator);
} else {
MiscUtils.showPlayer(plugin, player, spectator);
}
}
Debugger.debug("[{0}] Final join attempt as spectator for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start);
return;
}
if (plugin.getConfigPreferences().getOption(ConfigPreferences.Option.INVENTORY_MANAGER_ENABLED)) {
InventorySerializer.saveInventoryToFile(plugin, player);
}
player.teleport(arena.getLobbyLocation());
MiscUtils.getEnreplacedyAttribute(player, Attribute.GENERIC_MAX_HEALTH).ifPresent(ai -> player.setHealth(ai.getValue()));
player.setFoodLevel(20);
player.getInventory().setArmorContents(new ItemStack[] { new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR) });
player.setFlying(false);
player.setAllowFlight(false);
player.getInventory().clear();
arena.doBarAction(Arena.BarAction.ADD, player);
if (!plugin.getUserManager().getUser(player).isSpectator()) {
plugin.getChatManager().broadcastAction(arena, player, ChatManager.ActionType.JOIN);
}
user.setKit(KitRegistry.getDefaultKit());
for (SpecialItem item : plugin.getSpecialItemManager().getSpecialItems()) {
if (item.getDisplayStage() == SpecialItem.DisplayStage.LOBBY) {
player.getInventory().sereplacedem(item.getSlot(), item.gereplacedemStack());
}
}
player.updateInventory();
for (Player arenaPlayer : arena.getPlayers()) {
ArenaUtils.showPlayer(arenaPlayer, arena);
arenaPlayer.setExp(1);
arenaPlayer.setLevel(0);
}
plugin.getSignManager().updateSigns();
Debugger.debug("[{0}] Final join attempt as player for {1} took {2}ms", arena.getId(), player.getName(), System.currentTimeMillis() - start);
}
3
Source : AsynchronousJoin.java
with Apache License 2.0
from isstac
with Apache License 2.0
from isstac
/**
* 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) && !service.hasPermission(player, PlayerStatePermission.BYPreplaced_FORCE_SURVIVAL)) {
bukkitService.runTask(() -> 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();
ConsoleLogger.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);
}
2
Source : StartingState.java
with GNU General Public License v3.0
from Plugily-Projects
with GNU General Public License v3.0
from Plugily-Projects
@Override
public void handleCall(Arena arena) {
arena.getGameBar().setreplacedle(plugin.getChatManager().colorMessage(Messages.BOSSBAR_STARTING_IN).replace("%time%", String.valueOf(arena.getTimer())));
arena.getGameBar().setProgress(arena.getTimer() / plugin.getConfig().getDouble("Starting-Waiting-Time", 60));
for (Player player : arena.getPlayers()) {
player.setExp((float) (arena.getTimer() / plugin.getConfig().getDouble("Starting-Waiting-Time", 60)));
player.setLevel(arena.getTimer());
}
if (arena.getPlayers().size() < arena.getMinimumPlayers() && !arena.isForceStart()) {
arena.getGameBar().setreplacedle(plugin.getChatManager().colorMessage(Messages.BOSSBAR_WAITING_FOR_PLAYERS));
arena.getGameBar().setProgress(1.0);
plugin.getChatManager().broadcastMessage(arena, plugin.getChatManager().formatMessage(arena, plugin.getChatManager().colorMessage(Messages.LOBBY_MESSAGES_WAITING_FOR_PLAYERS), arena.getMinimumPlayers()));
arena.setArenaState(ArenaState.WAITING_FOR_PLAYERS);
Bukkit.getPluginManager().callEvent(new VillageGameStartEvent(arena));
arena.setTimer(15);
for (Player player : arena.getPlayers()) {
player.setExp(1);
player.setLevel(0);
}
return;
}
if (arena.getTimer() == 0 || arena.isForceStart()) {
arena.spawnVillagers();
Bukkit.getPluginManager().callEvent(new VillageGameStartEvent(arena));
arena.setArenaState(ArenaState.IN_GAME);
arena.getGameBar().setProgress(1.0);
arena.setTimer(5);
for (Player player : arena.getPlayers()) {
player.teleport(arena.getStartLocation());
player.setExp(0);
player.setLevel(0);
player.getInventory().clear();
player.setGameMode(GameMode.SURVIVAL);
User user = plugin.getUserManager().getUser(player);
user.setStat(StatsStorage.StatisticType.ORBS, plugin.getConfig().getInt("Orbs-Starting-Amount", 20));
plugin.getUserManager().getUser(player).getKit().giveKireplacedems(player);
player.updateInventory();
plugin.getUserManager().addExperience(player, 10);
arena.setTimer(plugin.getConfig().getInt("Cooldown-Before-Next-Wave", 25));
player.sendMessage(plugin.getChatManager().getPrefix() + plugin.getChatManager().colorMessage(Messages.LOBBY_MESSAGES_GAME_STARTED));
}
arena.setFighting(false);
}
if (arena.isForceStart()) {
arena.setForceStart(false);
}
arena.setTimer(arena.getTimer() - 1);
}
See More Examples