Java Code Examples for net.minecraft.entity.player.EntityPlayerMP#setGameType()

The following examples show how to use net.minecraft.entity.player.EntityPlayerMP#setGameType() . 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: ServerStateMachine.java    From malmo with MIT License 6 votes vote down vote up
private void resetPlayerGameTypes()
{
    // Go through and set all the players to their correct game type:
    for (Map.Entry<String, String> entry : this.usernameToAgentnameMap.entrySet())
    {
        AgentSection as = getAgentSectionFromAgentName(entry.getValue());
        EntityPlayerMP player = getPlayerFromUsername(entry.getKey());
        if (as != null && player != null)
        {
            player.setGameType(GameType.getByName(as.getMode().name().toLowerCase()));
            // Also make sure we haven't accidentally left the player flying:
            player.capabilities.isFlying = false;
            player.sendPlayerAbilities();
        }
    }
}
 
Example 2
Source File: EntityNBTPacket.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(EntityPlayerMP player) {
	Entity e = player.worldObj.getEntityByID(entityID);
	if (e != null) {
		try {
			GameType preGameType = player.theItemInWorldManager.getGameType();
			e.readFromNBT(tag);
			NBTEdit.log(Level.FINE, player.getCommandSenderName() + " edited a tag -- Entity ID #" + entityID);
			NBTEdit.logTag(tag);
			if (e == player) { //Update player info
				player.sendContainerToPlayer(player.inventoryContainer);
				GameType type = player.theItemInWorldManager.getGameType();
				if (preGameType != type)
					player.setGameType(type);
				player.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
				player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
				player.sendPlayerAbilities();
			}
			sendMessageToPlayer(player, "Your changes have been saved");
		} 
		catch(Throwable t) {
			sendMessageToPlayer(player, SECTION_SIGN + "cSave Failed - Invalid NBT format for Entity");
			NBTEdit.log(Level.WARNING, player.getCommandSenderName() + " edited a tag and caused an exception");
			NBTEdit.logTag(tag);
			NBTEdit.throwing("EntityNBTPacket", "handleServerSide", t);
		}
	}
}
 
Example 3
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
private void initialisePlayer(String username, String agentname)
{
    AgentSection as = getAgentSectionFromAgentName(agentname);
    EntityPlayerMP player = getPlayerFromUsername(username);

    if (player != null && as != null)
    {
        if ((player.getHealth() <= 0 || player.isDead || !player.isEntityAlive()))
        {
            player.markPlayerActive();
            player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().recreatePlayerEntity(player, player.dimension, false);
            player.connection.playerEntity = player;
        }

        // Reset their food and health:
        player.setHealth(player.getMaxHealth());
        player.getFoodStats().addStats(20, 40);
        player.maxHurtResistantTime = 1; // Set this to a low value so that lava will kill the player straight away.
        disablePlayerGracePeriod(player);   // Otherwise player will be invulnerable for the first 60 ticks.
        player.extinguish();	// In case the player was left burning.

        // Set their initial position and speed:
        PosAndDirection pos = as.getAgentStart().getPlacement();
        if (pos != null) {
            player.rotationYaw = pos.getYaw().floatValue();
            player.rotationPitch = pos.getPitch().floatValue();
            player.setPositionAndUpdate(pos.getX().doubleValue(),pos.getY().doubleValue(),pos.getZ().doubleValue());
            player.onUpdate();	// Needed to force scene to redraw
        }
        player.setVelocity(0, 0, 0);	// Minimise chance of drift!

        // Set their inventory:
        if (as.getAgentStart().getInventory() != null)
            initialiseInventory(player, as.getAgentStart().getInventory());
        // And their Ender inventory:
        if (as.getAgentStart().getEnderBoxInventory() != null)
            initialiseEnderInventory(player, as.getAgentStart().getEnderBoxInventory());

        // Set their game mode to spectator for now, to protect them while we wait for the rest of the cast to assemble:
        player.setGameType(GameType.SPECTATOR);
    }
}