Search in sources :

Example 81 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ValkyrienWarfareMod method serverStart.

@EventHandler
public void serverStart(FMLServerStartingEvent event) {
    MinecraftServer server = event.getServer();
    ModCommands.registerCommands(server);
}
Also used : MinecraftServer(net.minecraft.server.MinecraftServer) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler)

Example 82 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project SecurityCraft by Geforce132.

the class GuiRetinalScannerSetup method actionPerformed.

protected void actionPerformed(GuiButton guibutton) {
    switch(guibutton.id) {
        case 0:
            String players = this.textboxAllowedPlayers.getText();
            World W = Minecraft.getMinecraft().theWorld;
            MinecraftServer minecraftserver = MinecraftServer.getServer();
            try {
                if (this.mc.isSingleplayer()) {
                // String string = "saves/" + BlockRetinalScanner.worldObj.getSaveHandler().getWorldDirectoryName() + "/SecurityCraft/retScanner/players/" + BlockRetinalScanner.lastScannerX + "-" + BlockRetinalScanner.lastScannerY + "-" + BlockRetinalScanner.lastScannerZ;
                // File file = new File(string);
                // file.mkdirs();
                // file.createNewFile();
                // PrintWriter out = new PrintWriter("saves/" + BlockRetinalScanner.worldObj.getSaveHandler().getWorldDirectoryName() + "/SecurityCraft/retScanner/players/" + BlockRetinalScanner.lastScannerX + "-" + BlockRetinalScanner.lastScannerY + "-" + BlockRetinalScanner.lastScannerZ + "/players.txt");
                // out.println(players);
                // out.close();
                } else {
                // String string = minecraftserver.getWorldName() + "/SecurityCraft/retScanner/players/" + BlockRetinalScanner.lastScannerX + "-" + BlockRetinalScanner.lastScannerY + "-" + BlockRetinalScanner.lastScannerZ;
                // File file = new File(string);
                // file.mkdirs();
                // file.createNewFile();
                // PrintWriter out = new PrintWriter(minecraftserver.getWorldName() + "/SecurityCraft/retScanner/players/" + BlockRetinalScanner.lastScannerX + "-" + BlockRetinalScanner.lastScannerY + "-" + BlockRetinalScanner.lastScannerZ + "/players.txt");
                // out.println(players);
                // out.close();
                }
                if (this.mc.isSingleplayer()) {
                    EntityClientPlayerMP P = Minecraft.getMinecraft().thePlayer;
                    P.closeScreen();
                    P.openGui(mod_SecurityCraft.instance, 3, W, (int) P.posX, (int) P.posY, (int) P.posZ);
                } else {
                // HelpfulMethods.closePlayerScreen(BlockRetinalScanner.playerObj);
                // BlockRetinalScanner.playerObj.openGui(mod_SecurityCraft.instance, 3, W, (int) BlockRetinalScanner.playerObj.posX, (int) BlockRetinalScanner.playerObj.posY, (int) BlockRetinalScanner.playerObj.posZ);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
    }
}
Also used : EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 83 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project VanillaTeleporter by dyeo.

the class TeleporterUtility method transferPlayerToDimension.

/**
	 * Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
	 */
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension) {
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
    if (dstWorld != null) {
        // fire player change dimension event and check that action is valid before continuing
        if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension))
            return false;
        // (hard) set the player's dimension to the destination dimension
        player.dimension = dimension;
        // send a player respawn packet to the destination dimension so the player respawns there
        player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
        // remove the original player entity
        srcWorld.removeEntity(player);
        // make sure the player isn't dead (removeEntity sets player as dead)
        player.isDead = false;
        PlayerList playerList = player.mcServer.getPlayerList();
        // set player's location (net server handler)
        setPlayerPosition(player, posX, posY, posZ, yaw, pitch);
        // spawn the player in the new world
        dstWorld.spawnEntity(player);
        // update the entity (do not force)
        dstWorld.updateEntityWithOptionalForce(player, false);
        // set the player's world to the new world
        player.setWorld(dstWorld);
        // add the player into the appropriate player list
        playerList.preparePlayer(player, srcWorld);
        // set item in world manager's world to the same as the player
        player.interactionManager.setWorld(dstWorld);
        // update time and weather for the player so that it's the same as the world
        playerList.updateTimeAndWeatherForPlayer(player, dstWorld);
        // sync the player's inventory
        playerList.syncPlayerInventory(player);
        // add no experience (syncs experience)
        player.addExperience(0);
        // update player's health
        player.setPlayerHealthUpdated();
        // fire the dimension changed event so that minecraft swithces dimensions properly
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, srcWorld.provider.getDimension(), dstWorld.provider.getDimension());
        return true;
    } else {
        return false;
    }
}
Also used : PlayerList(net.minecraft.server.management.PlayerList) WorldServer(net.minecraft.world.WorldServer) SPacketRespawn(net.minecraft.network.play.server.SPacketRespawn) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 84 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project SpongeCommon by SpongePowered.

the class EntityUtil method handleDisplaceEntityPortalEvent.

@Nullable
public static MoveEntityEvent.Teleport.Portal handleDisplaceEntityPortalEvent(Entity entityIn, int targetDimensionId, @Nullable Teleporter teleporter) {
    SpongeImplHooks.registerPortalAgentType(teleporter);
    final MinecraftServer mcServer = SpongeImpl.getServer();
    final IMixinPlayerList mixinPlayerList = (IMixinPlayerList) mcServer.getPlayerList();
    final IMixinEntity mixinEntity = (IMixinEntity) entityIn;
    final Transform<World> fromTransform = mixinEntity.getTransform();
    final WorldServer fromWorld = ((WorldServer) entityIn.world);
    final IMixinWorldServer fromMixinWorld = (IMixinWorldServer) fromWorld;
    boolean sameDimension = entityIn.dimension == targetDimensionId;
    // handle the end
    if (targetDimensionId == 1 && fromWorld.provider instanceof WorldProviderEnd) {
        targetDimensionId = 0;
    }
    WorldServer toWorld = mcServer.getWorld(targetDimensionId);
    // not being loaded then short-circuit to prevent unnecessary logic from running
    if (!sameDimension && fromWorld == toWorld) {
        return null;
    }
    if (teleporter == null) {
        teleporter = toWorld.getDefaultTeleporter();
    }
    final Map<String, String> portalAgents = fromMixinWorld.getActiveConfig().getConfig().getWorld().getPortalAgents();
    String worldName = "";
    String teleporterClassName = teleporter.getClass().getName();
    // check for new destination in config
    if (teleporterClassName.equals("net.minecraft.world.Teleporter")) {
        worldName = portalAgents.get("minecraft:default_" + toWorld.provider.getDimensionType().getName().toLowerCase(Locale.ENGLISH));
        if (worldName == null && toWorld.provider instanceof WorldProviderHell) {
            worldName = portalAgents.get("minecraft:default_nether");
        }
    } else {
        // custom
        worldName = portalAgents.get("minecraft:" + teleporter.getClass().getSimpleName());
    }
    if (worldName != null && !worldName.equals("")) {
        for (WorldProperties worldProperties : Sponge.getServer().getAllWorldProperties()) {
            if (worldProperties.getWorldName().equalsIgnoreCase(worldName)) {
                Optional<World> spongeWorld = Sponge.getServer().loadWorld(worldProperties);
                if (spongeWorld.isPresent()) {
                    toWorld = (WorldServer) spongeWorld.get();
                    teleporter = toWorld.getDefaultTeleporter();
                    if (fromWorld.provider.isNether() || toWorld.provider.isNether()) {
                        ((IMixinTeleporter) teleporter).setNetherPortalType(true);
                    } else {
                        ((IMixinTeleporter) teleporter).setNetherPortalType(false);
                    }
                }
            }
        }
    }
    adjustEntityPostionForTeleport(mixinPlayerList, entityIn, fromWorld, toWorld);
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
        TeleportingContext context = EntityPhase.State.CHANGING_DIMENSION.createPhaseContext().setTargetWorld(toWorld).buildAndSwitch()) {
        Sponge.getCauseStackManager().pushCause(teleporter);
        Sponge.getCauseStackManager().pushCause(mixinEntity);
        Sponge.getCauseStackManager().addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.PORTAL);
        if (entityIn.isEntityAlive() && !(fromWorld.provider instanceof WorldProviderEnd)) {
            fromWorld.profiler.startSection("placing");
            // Note: We must always use placeInPortal to support mods.
            if (!((IMixinTeleporter) teleporter).isVanilla() || entityIn.getLastPortalVec() != null) {
                teleporter.placeInPortal(entityIn, entityIn.rotationYaw);
            }
            fromWorld.profiler.endSection();
        }
        // Complete phases, just because we need to. The phases don't actually do anything, because the processing resides here.
        // Grab the exit location of entity after being placed into portal
        final Transform<World> portalExitTransform = mixinEntity.getTransform().setExtent((World) toWorld);
        // Use setLocationAndAngles to avoid firing MoveEntityEvent to plugins
        mixinEntity.setLocationAndAngles(fromTransform);
        final MoveEntityEvent.Teleport.Portal event = SpongeEventFactory.createMoveEntityEventTeleportPortal(Sponge.getCauseStackManager().getCurrentCause(), fromTransform, portalExitTransform, (PortalAgent) teleporter, mixinEntity, true);
        SpongeImpl.postEvent(event);
        final Vector3i chunkPosition = mixinEntity.getLocation().getChunkPosition();
        final IMixinTeleporter toMixinTeleporter = (IMixinTeleporter) teleporter;
        final List<BlockSnapshot> capturedBlocks = context.getCapturedBlocks();
        final Transform<World> toTransform = event.getToTransform();
        if (event.isCancelled()) {
            // We need to make sure to only restore the location if
            if (!portalExitTransform.getExtent().getUniqueId().equals(mixinEntity.getLocation().getExtent().getUniqueId())) {
                // update cache
                ((IMixinTeleporter) teleporter).removePortalPositionFromCache(ChunkPos.asLong(chunkPosition.getX(), chunkPosition.getZ()));
                if (!capturedBlocks.isEmpty()) {
                    for (BlockSnapshot original : Lists.reverse(capturedBlocks)) {
                        original.restore(true, BlockChangeFlags.NONE);
                    }
                    capturedBlocks.clear();
                }
                mixinEntity.setLocationAndAngles(fromTransform);
            } else {
                // Call setTransform to let plugins know mods changed the position
                // Guarantees plugins such as Nucleus can track changed locations properly
                mixinEntity.setTransform(mixinEntity.getTransform());
            }
            return event;
        }
        if (!portalExitTransform.equals(toTransform)) {
            // if plugin set to same world, just set the transform
            if (fromWorld == toTransform.getExtent()) {
                // force cancel so we know to skip remaining logic
                event.setCancelled(true);
                // update cache
                toMixinTeleporter.removePortalPositionFromCache(ChunkPos.asLong(chunkPosition.getX(), chunkPosition.getZ()));
                // Undo created portal
                if (!capturedBlocks.isEmpty()) {
                    for (BlockSnapshot original : Lists.reverse(capturedBlocks)) {
                        original.restore(true, BlockChangeFlags.NONE);
                    }
                }
                capturedBlocks.clear();
                mixinEntity.setLocationAndAngles(toTransform);
                return event;
            }
        } else {
            if (toWorld.provider instanceof WorldProviderEnd) {
                BlockPos blockpos = entityIn.world.getTopSolidOrLiquidBlock(toWorld.getSpawnPoint());
                entityIn.moveToBlockPosAndAngles(blockpos, entityIn.rotationYaw, entityIn.rotationPitch);
            }
        }
        if (!capturedBlocks.isEmpty() && !TrackingUtil.processBlockCaptures(capturedBlocks, EntityPhase.State.CHANGING_DIMENSION, context)) {
            toMixinTeleporter.removePortalPositionFromCache(ChunkPos.asLong(chunkPosition.getX(), chunkPosition.getZ()));
        }
        if (!event.getKeepsVelocity()) {
            entityIn.motionX = 0;
            entityIn.motionY = 0;
            entityIn.motionZ = 0;
        }
        return event;
    }
}
Also used : IMixinPlayerList(org.spongepowered.common.interfaces.IMixinPlayerList) WorldProviderEnd(net.minecraft.world.WorldProviderEnd) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) IMixinTeleporter(org.spongepowered.common.interfaces.world.IMixinTeleporter) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(org.spongepowered.api.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Vector3i(com.flowpowered.math.vector.Vector3i) WorldProviderHell(net.minecraft.world.WorldProviderHell) TeleportingContext(org.spongepowered.common.event.tracking.phase.entity.TeleportingContext) BlockPos(net.minecraft.util.math.BlockPos) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Nullable(javax.annotation.Nullable)

Example 85 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project SpongeCommon by SpongePowered.

the class SpongeInternalListeners method onWorldSave.

@Listener
public void onWorldSave(SaveWorldEvent event) {
    if (Sponge.getServer().getDefaultWorld().isPresent()) {
        if (event.getTargetWorld().getUniqueId().equals(Sponge.getServer().getDefaultWorld().get().getUniqueId())) {
            SpongeUsernameCache.save();
            final MinecraftServer server = SpongeImpl.getServer();
            ((IMixinPlayerProfileCache) server.getPlayerProfileCache()).setCanSave(true);
            server.getPlayerProfileCache().save();
            ((IMixinPlayerProfileCache) server.getPlayerProfileCache()).setCanSave(false);
        }
    }
}
Also used : IMixinPlayerProfileCache(org.spongepowered.common.interfaces.server.management.IMixinPlayerProfileCache) MinecraftServer(net.minecraft.server.MinecraftServer) Listener(org.spongepowered.api.event.Listener)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)166 WorldServer (net.minecraft.world.WorldServer)35 BlockPos (net.minecraft.util.math.BlockPos)34 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)31 Player (org.spongepowered.api.entity.living.player.Player)30 PlayerConnection (org.spongepowered.api.network.PlayerConnection)30 CommandException (net.minecraft.command.CommandException)19 World (net.minecraft.world.World)18 Template (net.minecraft.world.gen.structure.template.Template)18 TextComponentString (net.minecraft.util.text.TextComponentString)16 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 Rotation (net.minecraft.util.Rotation)12 RCConfig (ivorius.reccomplex.RCConfig)11 TileEntity (net.minecraft.tileentity.TileEntity)11 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)10