Search in sources :

Example 1 with BuildingTownHall

use of com.minecolonies.coremod.colony.buildings.BuildingTownHall in project minecolonies by Minecolonies.

the class TeleportToColony method teleportPlayer.

/**
 * Method used to teleport the player.
 *
 * @param colID            the senders colony ID.
 * @param playerToTeleport the player which shall be teleported.
 */
private static void teleportPlayer(final EntityPlayer playerToTeleport, final int colID, final ICommandSender sender) {
    final Colony colony = ColonyManager.getColony(colID);
    final BuildingTownHall townHall = colony.getBuildingManager().getTownHall();
    if (townHall == null) {
        sender.sendMessage(new TextComponentString(NO_TOWNHALL));
        return;
    }
    playerToTeleport.sendMessage(new TextComponentString("We got places to go, kid..."));
    final BlockPos position = townHall.getLocation();
    final int dimension = playerToTeleport.getEntityWorld().provider.getDimension();
    final int colonyDimension = townHall.getColony().getDimension();
    if (colID < MIN_COLONY_ID) {
        playerToTeleport.sendMessage(new TextComponentString(CANT_FIND_COLONY));
        return;
    }
    final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) sender;
    if (dimension != colonyDimension) {
        playerToTeleport.sendMessage(new TextComponentString("Buckle up buttercup, this ain't no joy ride!!!"));
        final MinecraftServer server = sender.getEntityWorld().getMinecraftServer();
        final WorldServer worldServer = server.getWorld(colonyDimension);
        // Vanilla does that as well.
        entityPlayerMP.connection.sendPacket(new SPacketEffect(SOUND_TYPE, BlockPos.ORIGIN, 0, false));
        entityPlayerMP.addExperience(0);
        entityPlayerMP.setPlayerHealthUpdated();
        playerToTeleport.sendMessage(new TextComponentString("Hold onto your pants, we're going Inter-Dimensional!"));
        worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, colonyDimension, new Teleporter(worldServer));
        if (dimension == 1) {
            worldServer.spawnEntity(playerToTeleport);
            worldServer.updateEntityWithOptionalForce(playerToTeleport, false);
        }
    }
    entityPlayerMP.connection.setPlayerLocation(position.getX(), position.getY() + 2.0, position.getZ(), entityPlayerMP.rotationYaw, entityPlayerMP.rotationPitch);
}
Also used : SPacketEffect(net.minecraft.network.play.server.SPacketEffect) Teleporter(net.minecraft.world.Teleporter) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BuildingTownHall(com.minecolonies.coremod.colony.buildings.BuildingTownHall) TextComponentString(net.minecraft.util.text.TextComponentString) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with BuildingTownHall

use of com.minecolonies.coremod.colony.buildings.BuildingTownHall in project minecolonies by Minecolonies.

the class RecallTownhallMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final RecallTownhallMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        // Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final BuildingTownHall building = colony.getBuildingManager().getTownHall();
        if (building != null) {
            final BlockPos location = building.getLocation();
            final World world = colony.getWorld();
            for (final CitizenData citizenData : colony.getCitizenManager().getCitizens()) {
                Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
                if (!optionalEntityCitizen.isPresent()) {
                    Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
                    citizenData.updateCitizenEntityIfNecessary();
                    optionalEntityCitizen = citizenData.getCitizenEntity();
                }
                if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), world, location)) {
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
                }
            }
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) World(net.minecraft.world.World) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) Nullable(org.jetbrains.annotations.Nullable) BuildingTownHall(com.minecolonies.coremod.colony.buildings.BuildingTownHall)

Aggregations

Colony (com.minecolonies.coremod.colony.Colony)2 BuildingTownHall (com.minecolonies.coremod.colony.buildings.BuildingTownHall)2 BlockPos (net.minecraft.util.math.BlockPos)2 IColony (com.minecolonies.api.colony.IColony)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 SPacketEffect (net.minecraft.network.play.server.SPacketEffect)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 Teleporter (net.minecraft.world.Teleporter)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1 Nullable (org.jetbrains.annotations.Nullable)1