Java Code Examples for org.bukkit.entity.Player#setHealth()

The following examples show how to use org.bukkit.entity.Player#setHealth() . 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: TitleRespawn.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if (!(event.getEntity() instanceof Player)) return;
    Player player = (Player) event.getEntity();
    double finalHealth = player.getHealth() - event.getFinalDamage();
    if (finalHealth > 0.01) return;
    player.setMaxHealth(20);
    player.setHealth(player.getMaxHealth());
    event.setDamage(1);
    player.setLastDamageCause(event);
    if (event.getActor() instanceof Player) {
        killPlayer(player, (Player)event.getActor(), event.getCause());
    } else if (event.getActor() instanceof Projectile && ((Projectile) event.getActor()).getShooter() instanceof Player) {
        killPlayer(player, (Player)((Projectile) event.getActor()).getShooter(), event.getCause());
    } else {
        killPlayer(player, null, event.getCause());
    }
}
 
Example 2
Source File: HealingShovel.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
    EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
    if (e.getDamager() == player && e.getEntity() instanceof Player) {
        Player damaged = (Player) e.getEntity();
        e.setDamage(0);
        EffectManager.playSound(damaged.getLocation(), "ENTITY_GENERIC_DRINK", 0.5f, 1f);
        EffectManager.playSound(damaged.getLocation(), "BLOCK_ANVIL_LAND", 0.5f, 2f);
        short currentDur = player.getItemInHand().getDurability();

        if (((Damageable) damaged).getHealth() + Heal <= ((Damageable) damaged).getMaxHealth()) {
            damaged.setHealth(((Damageable) damaged).getHealth() + Heal);
        } else {
            damaged.setHealth(((Damageable) damaged).getMaxHealth());
        }

        if (currentDur + Heal < player.getItemInHand().getType().getMaxDurability()) {
            player.getItemInHand().setDurability((short) (currentDur + Heal));
        } else {
            player.setItemInHand(new ItemStack(Material.AIR, 1));
            EffectManager.playSound(player.getLocation(), "ENTITY_ITEM_BREAK", 0.1f, 0.3f);
        }
        return true;
    }
    return false;
}
 
Example 3
Source File: KitMenuItem.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@Override
public void onItemClick(ItemClickEvent event)
{
	final Player player = event.getPlayer();
	if(player != null)
	{
		event.setWillClose(true);
		final AnniPlayer anniplayer = AnniPlayer.getPlayer(player.getUniqueId());
		if(kit != null && anniplayer != null)
		{
			if(kit.hasPermission(player))
			{
				if(Game.isGameRunning() && anniplayer.getKit() != null)
					anniplayer.getKit().cleanup(player);
				anniplayer.setKit(kit);
				player.sendMessage(ChatColor.DARK_PURPLE+kit.getName()+" selected.");
				if(Game.isGameRunning() && anniplayer.getTeam() != null)
					player.setHealth(0);
			}
			else player.sendMessage(Lang.CANT_SELECT_KIT.toString());
		}
	}	
}
 
Example 4
Source File: AchievementHunter.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
private void onGameStart(UhcGameStateChangedEvent e){
    if (e.getNewGameState() != GameState.PLAYING){
        return;
    }

    for (UhcPlayer uhcPlayer : e.getPlayersManager().getAllPlayingPlayers()){
        try {
            Player player = uhcPlayer.getPlayer();
            player.setHealth(healthAtStart);
            VersionUtils.getVersionUtils().setPlayerMaxHealth(player, healthAtStart);
        }catch (UhcPlayerNotOnlineException ex){
            // Don't set max health for offline players.
        }
    }
}
 
Example 5
Source File: LobbyMap.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public void sendToSpawn(final Player player)
{
	if(spawn != null && player != null)
	{
		player.getInventory().clear();
		player.getInventory().setArmorContents(null);
		player.setHealth(player.getMaxHealth());
		player.setFoodLevel(20);
		player.setGameMode(GameVars.getDefaultGamemode());
		player.getInventory().addItem(CustomItem.KITMAP.toItemStack());
		player.getInventory().addItem(CustomItem.TEAMMAP.toItemStack());
		if(GameVars.getVoting())
			player.getInventory().addItem(CustomItem.VOTEMAP.toItemStack());
		player.teleport(getSpawn());
	}
}
 
Example 6
Source File: Game.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void playerWin(Player p) {
	if (GameMode.DISABLED == mode) return;
	Player win = activePlayers.get(0);
	// clearInv(p);
	win.teleport(SettingsManager.getInstance().getLobbySpawn());
	restoreInv(win);
	msgmgr.broadcastFMessage(PrefixType.INFO, "game.playerwin","arena-"+gameID, "victim-"+p.getName(), "player-"+win.getName());
	LobbyManager.getInstance().display(new String[] {
			win.getName(), "", "Won the ", "Survival Games!"
	}, gameID);

	mode = GameMode.FINISHING;
	if(config.getBoolean("reward.enabled", false)) {
		List<String> items = config.getStringList("reward.contents");
		for(int i=0; i<=(items.size() - 1); i++) {
			ItemStack item = ItemReader.read(items.get(i));
			win.getInventory().addItem(item);
		}
	}

	clearSpecs();
	win.setHealth(p.getMaxHealth());
	win.setFoodLevel(20);
	win.setFireTicks(0);
	win.setFallDistance(0);

	sm.playerWin(win, gameID, new Date().getTime() - startTime);
	sm.saveGame(gameID, win, getActivePlayers() + getInactivePlayers(), new Date().getTime() - startTime);

	activePlayers.clear();
	inactivePlayers.clear();
	spawns.clear();
	playerJoinTimes.clear();

	loadspawns();
	LobbyManager.getInstance().updateWall(gameID);
	MessageManager.getInstance().broadcastFMessage(PrefixType.INFO, "broadcast.gameend", "arena-"+gameID);

}
 
Example 7
Source File: SpigotStuff.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void sendPlayerSkin(Player player, SkinDataWrapper skindata) {
	Connection connection = ProtocolSupportAPI.getConnection(player);
	EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
	connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityPlayer));
	DimensionManager dimThing = null;
	switch (player.getWorld().getEnvironment()) {
	case NETHER:
		dimThing = DimensionManager.NETHER;
		break;
	case NORMAL:
		dimThing = DimensionManager.OVERWORLD;
		break;
	case THE_END:
		dimThing = DimensionManager.THE_END;
		break;
	}
	connection.sendPacket(new PacketPlayOutRespawn(dimThing, entityPlayer.world.getDifficulty(), WorldType.NORMAL, EnumGamemode.getById(player.getGameMode().getValue())));
	player.setHealth(player.getHealth());
	player.setMaxHealth(player.getMaxHealth());
	player.setFlying(player.isFlying());
	player.teleport(player.getLocation());
	player.setLevel(player.getLevel());
	player.setExp(player.getExp());
	player.updateInventory();
	connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer));
}
 
Example 8
Source File: PlayersManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public void setPlayerStartPlaying(UhcPlayer uhcPlayer){

		Player player;
		MainConfiguration cfg = GameManager.getGameManager().getConfiguration();

		if(!uhcPlayer.getHasBeenTeleportedToLocation()){
			uhcPlayer.setState(PlayerState.PLAYING);
			uhcPlayer.selectDefaultGlobalChat();

			try {
				player = uhcPlayer.getPlayer();
				clearPlayerInventory(player);
				player.setFireTicks(0);

				for(PotionEffect effect : player.getActivePotionEffects())
				{
					player.removePotionEffect(effect.getType());
				}
				player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 999999, 1), false);
				player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 999999, 40), false);
				player.setGameMode(GameMode.SURVIVAL);
				if(cfg.getEnableExtraHalfHearts()){
					VersionUtils.getVersionUtils().setPlayerMaxHealth(player, 20+((double) cfg.getExtraHalfHearts()));
					player.setHealth(20+((double) cfg.getExtraHalfHearts()));
				}
				UhcItems.giveGameItemTo(player, GameItem.COMPASS_ITEM);
				UhcItems.giveGameItemTo(player, GameItem.CUSTOM_CRAFT_BOOK);
				KitsManager.giveKitTo(player);

				if (!uhcPlayer.getStoredItems().isEmpty()){
					player.getInventory().addItem(uhcPlayer.getStoredItems().toArray(new ItemStack[]{}));
					uhcPlayer.getStoredItems().clear();
				}
			} catch (UhcPlayerNotOnlineException e) {
				// Nothing done
			}
		}
	}
 
Example 9
Source File: KillCommand.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
	
	if (!(sender instanceof Player)) {
		CivMessage.sendError(sender, "Only a player can execute this command.");
		return false;
	}
	
	Player player = (Player)sender;
	player.setHealth(0);
	
	CivMessage.send(sender, CivColor.Yellow+CivColor.BOLD+"You couldn't take it anymore.");
	
	return true;
}
 
Example 10
Source File: ChallengeHandler.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Teleport a player out of the arena
 * @param player the player to teleport
 * @param challenge the challenge they are part of
 */
public void exitArena(Player player, GuildChallenge challenge, Guilds guilds) {
    String location = getAllPlayersAlive(challenge).get(player.getUniqueId());
    if (location != null) {
        player.teleport(ACFBukkitUtil.stringToLocation(location));
        guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.WAR__TELEPORTED_BACK);
        player.setHealth(player.getMaxHealth());
    }
}
 
Example 11
Source File: ListenerCustomDeath.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onJoin(PlayerJoinEvent e) {
    Player player = e.getPlayer();
    YamlConfiguration playerData = this.plugin.getDataFile(player);
    if(!playerData.getBoolean("kill-on-join")) return;

    add(player);
    player.setHealth(0.0D);
}
 
Example 12
Source File: AnnihilationMain.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onGameStart(GameStartEvent event)
{
       //Bukkit.getLogger().info("WELL WE GOT HERE!!!!");
	if(Game.getGameMap() != null)
	{
		for(AnniTeam t : AnniTeam.Teams)
		{
			t.setHealth(75);
		}
		GameMap map = Game.getGameMap();
		for(final AnniPlayer p : AnniPlayer.getPlayers())
		{
			final Player player = p.getPlayer();
			if(player != null && p.getTeam() != null)
			{
				player.setHealth(player.getHealth());
				player.setFoodLevel(20);
				player.setGameMode(GameVars.getDefaultGamemode());
				player.getInventory().clear();
				player.getInventory().setArmorContents(null);
				player.teleport(p.getTeam().getRandomSpawn());
				p.getKit().onPlayerSpawn(player);
				//Do the thing where we announce that the game has started
			}
		}
           AnnounceBar.getInstance().countDown(new Announcement(Lang.PHASEBAR.toStringReplacement(1) + " - {#}").setTime(map.getPhaseTime()).setCallback(new StandardPhaseHandler()));
		//MessageBar.countDown(Lang.PHASEBAR.toStringReplacement(1) + " - {#}", map.getPhaseTime(), new StandardPhaseHandler());
		map.setPhase(1);
		map.setCanDamageNexus(false);
	}
}
 
Example 13
Source File: NoEntryExpansion.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public final void preventEntry(Cancellable e, Player player, Location fromLoc, Location toLoc) {
    ICombatManager combatManager = getPlugin().getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    LivingEntity enemy = combatManager.getEnemy(player);
    sendNoEntryMessage(player, enemy);

    BukkitScheduler scheduler = Bukkit.getScheduler();
    NoEntryHandler handler = getNoEntryHandler();
    NoEntryMode noEntryMode = handler.getNoEntryMode();
    switch(noEntryMode) {
        case KILL:
            player.setHealth(0.0D);
            break;

        case CANCEL:
            e.setCancelled(true);
            break;

        case TELEPORT:
            if(enemy != null) player.teleport(enemy);
            else e.setCancelled(true);
            break;

        case KNOCKBACK:
            e.setCancelled(true);
            scheduler.runTaskLater(getPlugin().getPlugin(), () -> knockbackPlayer(player, fromLoc, toLoc), 1L);
            break;

        case VULNERABLE:
        case NOTHING:
        default:
            break;
    }
}
 
Example 14
Source File: PlayerDeath.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onDeath(PlayerDeathEvent event) {
    event.setDeathMessage(null);
    event.getDrops().clear();
    event.setDroppedExp(0);
    final Player player = event.getEntity();
    player.setHealth(20); // Do not show the respawn screen
    player.getInventory().clear();

    final GameArena gameArena = PLUGIN.getGameArena();

    if (!gameArena.isGameRunning()) {
        player.teleport(PLUGIN.getServerSpawn());
        return;
    }

    if (gameArena.isHuman(player)) {
        gameArena.addZombie(player);
        player.getInventory().setHelmet(new ItemStack(Material.JACK_O_LANTERN));
        gameArena.giveKit(player);

        if (player.getKiller() != null) {
            Profile zombieProfile = PLUGIN.getProfile(player.getKiller());
            if (zombieProfile != null) {
                zombieProfile.setHumanKills(zombieProfile.getHumanKills() + 1);
            }
        }
    } else if (gameArena.isZombie(player)) {
        new BukkitRunnable() {
            @Override
            public void run() {
                gameArena.teleportCheckpoint(player);
                gameArena.giveKit(player);
                player.setFireTicks(0);
                player.setHealth(20);
            }
        }.runTaskLater(PLUGIN, 10);
    }

    if (gameArena.isGameRunning()) {
        if (gameArena.shouldEnd()) {
            gameArena.endGame();
        }
    }
}
 
Example 15
Source File: HealthKit.java    From CardinalPGM with MIT License 4 votes vote down vote up
@Override
public void apply(Player player, Boolean force) {
    if(health != -1 && (force || health > player.getHealth())) player.setHealth(health);
    if(hunger != -1 && (force || hunger > player.getFoodLevel())) player.setFoodLevel(hunger);
    if(saturation != 0 && (force || saturation > player.getSaturation())) player.setSaturation(saturation);
}
 
Example 16
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 17
Source File: AchievementHunter.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private void addHeart(Player player){
    VersionUtils.getVersionUtils().setPlayerMaxHealth(player, player.getMaxHealth() + healthAdded);
    player.setHealth(player.getHealth() + healthAdded);
}
 
Example 18
Source File: PlayerData.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void restore(boolean playerQuit) {
if (!beingRestored) {
	beingRestored = true;
       final Player player = this.getPlayer();
       if (player == null) {
           return;
       }
       
	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Restoring " + player.getName());
   	}
   	PlayerStat pStats = PlayerStat.getPlayerStats(player);
       player.closeInventory();
       player.setGameMode(GameMode.SURVIVAL);
       if (SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
       	if (pStats != null) { Util.get().setPlayerExperience(player, pStats.getXp()); }
       }
       Util.get().clear(player);
       player.getInventory().clear();
       player.getInventory().setContents(inv.getContents());
       SkyWarsReloaded.getNMS().setMaxHealth(player, 20);
       if (health <= 0 || health > 20) {
		player.setHealth(20);
	} else {
		player.setHealth(health);
	}
       player.setFoodLevel(food);
       player.setSaturation(sat);
       player.resetPlayerTime();
       player.resetPlayerWeather();
       player.setAllowFlight(false);
       player.setFlying(false);
	if (!SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
		player.setExp(xp);
	}
       
       player.setFireTicks(0);
       player.setScoreboard(sb);
       if (SkyWarsReloaded.getCfg().lobbyBoardEnabled() && !SkyWarsReloaded.getCfg().bungeeMode()) {
        PlayerStat.updateScoreboard(player);
       }
       
       final Location respawn = SkyWarsReloaded.getCfg().getSpawn();
       if (SkyWarsReloaded.get().isEnabled()) {
           if (playerQuit) {
                     player.teleport(respawn, TeleportCause.END_PORTAL);
                 } else {
                     new BukkitRunnable() {
                         @Override
                         public void run() {
                             player.teleport(respawn, TeleportCause.END_PORTAL);
                         }
                     }.runTaskLater(SkyWarsReloaded.get(), 2);
                 }
	} else {
		player.teleport(respawn, TeleportCause.END_PORTAL);
	}

       
   	if (SkyWarsReloaded.getCfg().debugEnabled()) {
       	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Finished restoring " + player.getName() + ". Teleporting to Spawn");
   	}
	if (SkyWarsReloaded.getCfg().bungeeMode()) {
		new BukkitRunnable() {
			@Override
			public void run() {
				String uuid = player.getUniqueId().toString();
				SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", SkyWarsReloaded.getCfg().getBungeeLobby());
				PlayerStat remove = PlayerStat.getPlayerStats(uuid);
				PlayerStat.getPlayers().remove(remove);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 5);
	}
}
  }
 
Example 19
Source File: DebugCommand.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void heal_cmd() throws CivException {
	Player player = getPlayer();
	player.setHealth(player.getMaxHealth());
	player.setFoodLevel(50);
	CivMessage.send(player, "Healed....");
}
 
Example 20
Source File: MatchPlayerImpl.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void reset() {
  getMatch().callEvent(new PlayerResetEvent(this));

  setFrozen(false);
  Player bukkit = getBukkit();
  bukkit.closeInventory();
  resetInventory();
  bukkit.setArrowsStuck(0);
  bukkit.setExhaustion(0);
  bukkit.setFallDistance(0);
  bukkit.setFireTicks(0);
  bukkit.setFoodLevel(20); // full
  bukkit.setHealth(bukkit.getMaxHealth());
  bukkit.setLevel(0);
  bukkit.setExp(0); // clear xp
  bukkit.setSaturation(5); // default
  bukkit.setAllowFlight(false);
  bukkit.setFlying(false);
  bukkit.setSneaking(false);
  bukkit.setSprinting(false);
  bukkit.setFlySpeed(0.1f);
  bukkit.setKnockbackReduction(0);
  bukkit.setWalkSpeed(WalkSpeedKit.BUKKIT_DEFAULT);

  for (PotionEffect effect : bukkit.getActivePotionEffects()) {
    if (effect.getType() != null) {
      bukkit.removePotionEffect(effect.getType());
    }
  }

  for (Attribute attribute : ATTRIBUTES) {
    AttributeInstance attributes = bukkit.getAttribute(attribute);
    if (attributes == null) continue;

    for (AttributeModifier modifier : attributes.getModifiers()) {
      attributes.removeModifier(modifier);
    }
  }

  NMSHacks.setAbsorption(bukkit, 0);

  // we only reset bed spawn here so people don't have to see annoying messages when they respawn
  bukkit.setBedSpawnLocation(null);
}