@Override public void setGameMode(GameMode gameMode) { player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase())); }
private void updateGameMode( CommandSender sender, Player who, GameMode gameMode, ResourceBundle bundle) { String gameModeName = GameModeUtils.prettyPrint(gameMode, bundle.getLocale()); who.setGameMode(gameMode); if (!sender.equals(who)) { new LocalizedStringImpl("gamemode.done", bundle) .send(sender, who.getDisplayName(), gameModeName); bundle = getBundle(who); // switch to target's locale for gamemode.done.to-you } new LocalizedStringImpl("gamemode.done.to-you", bundle).send(who, gameModeName); }
player.setGameMode(mode);
/** * Sets the user's game mode * @param mode - GameMode */ public void setGameMode(GameMode mode) { player.setGameMode(mode); }
@Override public void run() { player.setGameMode(GameMode.CREATIVE); } }.runTaskLater(plugin, 10L);
@Override public void undo() { player.setGameMode(mode); }
private void resetMode() { if (targetPlayer == null) return; Player player = targetPlayer.get(); if (player == null) return; player.setGameMode(originalMode); }
@Override public void run() { mode = player.getGameMode(); player.setGameMode(GameMode.SURVIVAL); }
if(commandLabel.equalsIgnoreCase("gmspec")){ if(args.length == 0 && sender instanceof Player){//check if the sender is a Player Player p = (Player) sender; p.setGameMode(GameMode.SPECTATOR); p.sendMessage(ChatColor.GREEN + "Your own gamemode has been changed!"); return true; } else{ Player target = Bukkit.getServer().getPlayer(args[0]); //the rest of the code } }
public void setGamemode(GameMode gamemode){ setAllowGamemodeChange(true); player.setGameMode(gamemode); setAllowGamemodeChange(false); }
public void setPlayerGameMode(Player player) { if (this.isSpectator(player) && !(this.getCycle() instanceof BungeeGameCycle && this.getCycle().isEndGameRunning() && BedwarsRel.getInstance().getBooleanConfig("bungeecord.endgame-in-lobby", true))) { player.setAllowFlight(true); player.setFlying(true); player.setGameMode(GameMode.SPECTATOR); } else { if (this.getState().equals(GameState.RUNNING)) { player.setGameMode(GameMode.SURVIVAL); } else if (this.getState().equals(GameState.WAITING)) { Integer gameMode = BedwarsRel.getInstance().getIntConfig("lobby-gamemode", 0); if (gameMode == 0) { player.setGameMode(GameMode.SURVIVAL); } else if (gameMode == 1) { player.setGameMode(GameMode.CREATIVE); } else if (gameMode == 2) { player.setGameMode(GameMode.ADVENTURE); } else if (gameMode == 3) { player.setGameMode(GameMode.SPECTATOR); } } } }
public void setPlayerGameMode(Player player) { if (this.isSpectator(player) && !(this.getCycle() instanceof BungeeGameCycle && this.getCycle().isEndGameRunning() && BedwarsRel.getInstance().getBooleanConfig("bungeecord.endgame-in-lobby", true))) { player.setAllowFlight(true); player.setFlying(true); player.setGameMode(GameMode.SPECTATOR); } else { if (this.getState().equals(GameState.RUNNING)) { player.setGameMode(GameMode.SURVIVAL); } else if (this.getState().equals(GameState.WAITING)) { Integer gameMode = BedwarsRel.getInstance().getIntConfig("lobby-gamemode", 0); if (gameMode == 0) { player.setGameMode(GameMode.SURVIVAL); } else if (gameMode == 1) { player.setGameMode(GameMode.CREATIVE); } else if (gameMode == 2) { player.setGameMode(GameMode.ADVENTURE); } else if (gameMode == 3) { player.setGameMode(GameMode.SPECTATOR); } } } }
@Override public SpellResult perform(CastContext context) { Entity entity = context.getTargetEntity(); if (entity == null) { return SpellResult.NO_TARGET; } if (!(entity instanceof Player)) { return SpellResult.PLAYER_REQUIRED; } Player player = (Player)entity; originalMode = player.getGameMode(); if (originalMode == gameMode) { return SpellResult.NO_TARGET; } player.setGameMode(gameMode); targetPlayer = new WeakReference<>(player); context.registerForUndo(new GameModeUndoAction()); return SpellResult.CAST; }
public void resetHealth(Player p) { p.setGameMode(GameMode.SURVIVAL); CrossVersion.setHealth(p, CrossVersion.getMaxHealth(p)); if (plugin.getConfiguration().areDeveloperOptionsEnabled() && p.getName().length() == 1) { return; } p.setFallDistance(0); p.setFoodLevel(20); p.setExhaustion(0); p.setSaturation(0); p.setHealthScaled(false); p.setAllowFlight(false); p.setFlying(false); for (PotionEffect effect : p.getActivePotionEffects()) { p.removePotionEffect(effect.getType()); } } }
/** * Sends player home * @param player - player */ private void eject(Player player) { player.setGameMode(GameMode.SPECTATOR); // Teleport player to their home if (getIslands().hasIsland(player.getWorld(), player.getUniqueId())) { getIslands().homeTeleport(player.getWorld(), player); } else if (getIslands().getSpawn(player.getWorld()).isPresent()) { // Else, try to teleport him to the world spawn getIslands().spawnTeleport(player.getWorld(), player); } else { // There's nothing much we can do. // We'll try to teleport him to the spawn... player.teleport(player.getWorld().getSpawnLocation()); // Switch him back to the default gamemode. He may die, sorry :( player.setGameMode(getIWM().getDefaultGameMode(player.getWorld())); // Log getPlugin().log("Could not teleport '" + player.getName() + "' back to his island or the spawn."); getPlugin().log("Please consider setting a spawn for this world using the admin setspawn command."); } } }
/** * Applies all saved data besides teleportation location. * <p> * This should be used *after* applying armor contents, in order to ensure that setHealth works correctly. * * @param p Player to apply saved data to */ private void apply(final Player p) { CrossVersion.setHealth(p, health); p.setHealthScale(healthScale); p.setMaxHealth(maxHealth); p.setFallDistance(fallDistance); p.setFoodLevel(foodLevel); p.setExhaustion(exhaustion); p.setSaturation(saturation); p.setAllowFlight(allowFlight); p.setFlying(isFlying); p.setGameMode(gameMode); for (PotionEffect effect : effects) { p.addPotionEffect(effect); } } }
/** * Teleports entity to the safe spot */ private void teleportEntity(final Location loc) { task.cancel(); // Return to main thread and teleport the player Bukkit.getScheduler().runTask(plugin, () -> { if (!portal && entity instanceof Player && homeNumber > 0) { // Set home if so marked plugin.getPlayers().setHomeLocation(User.getInstance(entity), loc, homeNumber); } Vector velocity = entity.getVelocity(); entity.teleport(loc); // Exit spectator mode if in it if (entity instanceof Player) { Player player = (Player)entity; if (overrideGamemode && player.getGameMode().equals(GameMode.SPECTATOR)) { player.setGameMode(plugin.getIWM().getDefaultGameMode(loc.getWorld())); } } else { entity.setVelocity(velocity); } }); }
public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world) { super(plugin, player, world.getWorld()); Game game = Game.getByGameWorld(world); if (game == null) { game = new Game(plugin, DGroup.getByPlayer(player)); } GameRuleProvider rules = game.getRules(); player.setGameMode(GameMode.SURVIVAL); if (!rules.getKeepInventoryOnEnter()) { clearPlayerData(); } if (rules.isLobbyDisabled()) { ready(); } initialLives = rules.getInitialLives(); lives = initialLives; Location teleport = world.getLobbyLocation(); if (teleport == null) { PlayerUtil.secureTeleport(player, world.getWorld().getSpawnLocation()); } else { PlayerUtil.secureTeleport(player, teleport); } }
public void restore() { if (BedwarsRel.getInstance().getBooleanConfig("save-inventory", true)) { this.player.getInventory().setContents(this.inventory); this.player.getInventory().setArmorContents(this.armor); this.player.addPotionEffects(this.effects); this.player.setLevel(this.level); this.player.setExp(this.xp); this.player.setFoodLevel(this.foodLevel); for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.addPotionEffects(this.effects); } this.player.setPlayerListName(this.listName); this.player.setDisplayName(this.displayName); this.player.setGameMode(this.mode); if (this.mode == GameMode.CREATIVE) { this.player.setAllowFlight(true); } this.player.updateInventory(); }
public void restore() { if (BedwarsRel.getInstance().getBooleanConfig("save-inventory", true)) { this.player.getInventory().setContents(this.inventory); this.player.getInventory().setArmorContents(this.armor); this.player.addPotionEffects(this.effects); this.player.setLevel(this.level); this.player.setExp(this.xp); this.player.setFoodLevel(this.foodLevel); for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.addPotionEffects(this.effects); } this.player.setPlayerListName(this.listName); this.player.setDisplayName(this.displayName); this.player.setGameMode(this.mode); if (this.mode == GameMode.CREATIVE) { this.player.setAllowFlight(true); } this.player.updateInventory(); }