Search in sources :

Example 41 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.

the class MalmoMod method safeSendToAll.

public static void safeSendToAll(MalmoMessageType malmoMessage, Map<String, String> data) {
    // network.sendToAll() is buggy - race conditions result in the message getting trashed if there is more than one client.
    if (data == null) {
        safeSendToAll(malmoMessage);
        return;
    }
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    for (Object player : server.getPlayerList().getPlayers()) {
        if (player != null && player instanceof EntityPlayerMP) {
            // Must construct a new message for each client:
            Map<String, String> dataCopy = new HashMap<String, String>();
            dataCopy.putAll(data);
            network.sendTo(new MalmoMod.MalmoMessage(malmoMessage, 0, dataCopy), (EntityPlayerMP) player);
        }
    }
}
Also used : HashMap(java.util.HashMap) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 42 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project EnderIO by SleepyTrousers.

the class PacketRemoteInvPanel method onMessage.

@Override
public IMessage onMessage(PacketRemoteInvPanel message, MessageContext ctx) {
    EntityPlayerMP player = ctx.getServerHandler().player;
    ItemStack heldItem = player.getHeldItem(message.hand);
    if (heldItem == null || !(heldItem.getItem() instanceof ItemRemoteInvAccess)) {
        return null;
    }
    if (!REMOTE_X.hasTag(heldItem)) {
        return null;
    }
    int x = REMOTE_X.getInt(heldItem);
    int y = REMOTE_Y.getInt(heldItem);
    int z = REMOTE_Z.getInt(heldItem);
    int d = REMOTE_D.getInt(heldItem);
    ItemRemoteInvAccessType type = ItemRemoteInvAccessType.fromStack(heldItem);
    if (!type.inRange(d, x, y, z, player.getEntityWorld().provider.getDimension(), (int) player.posX, (int) player.posY, (int) player.posZ)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.outofrange")), true);
        return null;
    }
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null) {
        return null;
    }
    WorldServer world = server.getWorld(d);
    if (world == null) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtarget")), true);
        return null;
    }
    final BlockPos pos = new BlockPos(x, y, z);
    if (!world.isBlockLoaded(pos)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.notloaded")), true);
        return null;
    }
    TileEntity tileEntity = player.getEntityWorld().getTileEntity(pos);
    if (!(tileEntity instanceof TileInventoryPanel)) {
        player.sendStatusMessage(new TextComponentString(EnderIO.lang.localize("remoteinv.chat.invalidtarget")), true);
        return null;
    }
    Container c = player.openContainer;
    player.interactionManager.processRightClickBlock(player, player.world, null, EnumHand.MAIN_HAND, pos, EnumFacing.UP, 0f, 0f, 0f);
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileInventoryPanel(crazypants.enderio.machine.invpanel.TileInventoryPanel) Container(net.minecraft.inventory.Container) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 43 with MinecraftServer

use of net.minecraft.server.MinecraftServer 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 44 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Minestuck by mraof.

the class ServerEditHandler method onCommandEvent.

@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = false)
public void onCommandEvent(CommandEvent event) {
    if (list.isEmpty())
        return;
    try {
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        if (commands.contains(event.getCommand().getName())) {
            String c = event.getCommand().getName();
            EntityPlayer target;
            if (c.equals("kill") || (c.equals("clear") || c.equals("spawnpoint")) && event.getParameters().length == 0 || c.equals("tp") && event.getParameters().length != 2 && event.getParameters().length != 4 || c.equals("setworldspawn") && (event.getParameters().length == 0 || event.getParameters().length == 3))
                target = CommandBase.getCommandSenderAsPlayer(event.getSender());
            else if (c.equals("defaultgamemode") && server.getForceGamemode()) {
                for (EditData data : (EditData[]) list.toArray()) reset(data);
                return;
            } else if (c.equals("spreadplayers")) {
                ArrayList<EntityPlayer> targets = new ArrayList<EntityPlayer>();
                for (int i = 5; i < event.getParameters().length; i++) {
                    String s = event.getParameters()[i];
                    if (EntitySelector.isSelector(s)) {
                        Entity[] list = (Entity[]) EntitySelector.matchEntities(event.getSender(), s, Entity.class).toArray();
                        if (list.length == 0)
                            return;
                        for (Entity e : list) if (e instanceof EntityPlayer)
                            targets.add((EntityPlayer) e);
                    } else {
                        EntityPlayer player = server.getPlayerList().getPlayerByUsername(s);
                        if (player == null)
                            return;
                        targets.add(player);
                    }
                }
                for (EntityPlayer player : targets) if (getData(player) != null) {
                    reset(getData(player));
                }
                return;
            } else if (c.equals("gamemode") || c.equals("xp"))
                target = event.getParameters().length >= 2 ? CommandBase.getPlayer(server, event.getSender(), event.getParameters()[1]) : CommandBase.getCommandSenderAsPlayer(event.getSender());
            else
                target = CommandBase.getPlayer(server, event.getSender(), event.getParameters()[0]);
            if (target != null && getData(target) != null)
                reset(getData(target));
        }
    } catch (CommandException e) {
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 45 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project minecolonies by Minecolonies.

the class ItemScanTool method saveStructure.

/**
 * Scan the structure and save it to the disk.
 *
 * @param world  Current world.
 * @param from   First corner.
 * @param to     Second corner.
 * @param player causing this action.
 * @param name the name of it.
 */
public static void saveStructure(@Nullable final World world, @Nullable final BlockPos from, @Nullable final BlockPos to, @NotNull final EntityPlayer player, final String name) {
    if (world == null || from == null || to == null) {
        throw new IllegalArgumentException("Invalid method call, arguments can't be null. Contact a developer.");
    }
    final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
    final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
    final BlockPos size = blockpos1.subtract(blockpos).add(1, 1, 1);
    if (size.getX() * size.getY() * size.getZ() > MAX_SCHEMATIC_SIZE) {
        LanguageHandler.sendPlayerMessage(player, MAX_SCHEMATIC_SIZE_REACHED, MAX_SCHEMATIC_SIZE);
        return;
    }
    final WorldServer worldserver = (WorldServer) world;
    final MinecraftServer minecraftserver = world.getMinecraftServer();
    final TemplateManager templatemanager = worldserver.getStructureTemplateManager();
    final long currentMillis = System.currentTimeMillis();
    final String currentMillisString = Long.toString(currentMillis);
    final String prefix = "/minecolonies/scans/";
    final String fileName;
    if (name == null || name.isEmpty()) {
        fileName = LanguageHandler.format("item.scepterSteel.scanFormat", "", currentMillisString);
    } else {
        fileName = name;
    }
    final Template template = templatemanager.getTemplate(minecraftserver, new ResourceLocation(prefix + fileName + ".nbt"));
    template.takeBlocksFromWorld(world, blockpos, size, true, Blocks.STRUCTURE_VOID);
    template.setAuthor(Constants.MOD_ID);
    MineColonies.getNetwork().sendTo(new SaveScanMessage(template.writeToNBT(new NBTTagCompound()), fileName), (EntityPlayerMP) player);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) SaveScanMessage(com.minecolonies.coremod.network.messages.SaveScanMessage) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)186 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)42 WorldServer (net.minecraft.world.WorldServer)35 BlockPos (net.minecraft.util.math.BlockPos)34 Player (org.spongepowered.api.entity.living.player.Player)30 PlayerConnection (org.spongepowered.api.network.PlayerConnection)30 CommandException (net.minecraft.command.CommandException)19 TextComponentString (net.minecraft.util.text.TextComponentString)18 World (net.minecraft.world.World)18 Template (net.minecraft.world.gen.structure.template.Template)18 ICommandSender (net.minecraft.command.ICommandSender)15 Entity (net.minecraft.entity.Entity)15 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)15 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ResourceLocation (net.minecraft.util.ResourceLocation)14 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)13 Rotation (net.minecraft.util.Rotation)12 RCConfig (ivorius.reccomplex.RCConfig)11 TileEntity (net.minecraft.tileentity.TileEntity)11