Search in sources :

Example 11 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomToolTipsCommand method canCommandSenderUseCommand.

@Override
public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) {
    if (pCommandSender instanceof EntityPlayerMP) {
        EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender;
        boolean tPlayerOpped = MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile());
        // && tIncreative;
        return tPlayerOpped;
    } else if (pCommandSender instanceof MinecraftServer)
        return true;
    else
        return false;
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 12 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project NewHorizonsCoreMod by GTNewHorizons.

the class HazardousItemsCommand method canCommandSenderUseCommand.

/*
    private void ProcessRemoveItemCommand(EntityPlayer pPlayer, ItemStack pInHand, String[] pArgs)
    {
        boolean bFlag = false;
        if (pArgs.length == 2)
        {
            String pSecondArg = pArgs[1];
            if (pSecondArg.equalsIgnoreCase("all")) bFlag = true;
        }

        if (!MainRegistry.Module_HazardousItems.RemoveItemFromList(pInHand,bFlag))
        {
            PlayerChatHelper.SendWarn(pPlayer, "Nothing removed. Either there was no such item,");
            PlayerChatHelper.SendWarn(pPlayer, "or an error occurred");
        } else
            PlayerChatHelper.SendInfo(pPlayer, "Item(s) removed. Don't forget to save");
    }

    private void ProcessAddDamageEffectCommand(EntityPlayer pPlayer, ItemStack pInHand, String[] pArgs)
    {
        try
        {
            String tDmgSource = pArgs[1];
            float tDmgAmount = Float.parseFloat(pArgs[2]);

            if (!DamageTypeHelper.IsValidDamageSource(tDmgSource))
                PlayerChatHelper.SendError(pPlayer, "This damagesource is invalid");
            else
            {
                if (MainRegistry.Module_HazardousItems.AddDamageEffectToItem(pInHand, tDmgSource, tDmgAmount))
                    PlayerChatHelper.SendInfo(pPlayer, "Effect added to item. Don't forget to save");
                else
                    PlayerChatHelper.SendError(pPlayer, "Unable to add item. Please check your logfile");
            }
        } catch (Exception e)
        {
            PlayerChatHelper.SendError(pPlayer,
                    "Error in your command. Check your syntax");
        }
    }

    private void ProcessAddPotionEffectCommand(EntityPlayer pPlayer, ItemStack pInHand, String[] pArgs)
    {
        try
        {
            int tPotionID = Integer.parseInt(pArgs[1]);
            int tTickDuration = Integer.parseInt(pArgs[2]);
            int tLevel = Integer.parseInt(pArgs[3]);

            if (!PotionHelper.IsValidPotionID(tPotionID)) PlayerChatHelper
                    .SendError(pPlayer, "This potion ID is invalid");
            else
            {
                if (MainRegistry.Module_HazardousItems.AddPotionEffectToItem(pInHand, tPotionID, tTickDuration, tLevel))
                    PlayerChatHelper.SendInfo(pPlayer, "Effect added to item. Don't forget to save");
                else
                    PlayerChatHelper.SendError(pPlayer, "Unable to add item. Please check your logfile");
            }
        } catch (Exception e)
        {
            PlayerChatHelper.SendError(pPlayer, "Error in your command. Check your syntax");
        }
    }
*/
/*
     * Make sure only an op/admin can execute this command
     */
@Override
public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) {
    if (pCommandSender instanceof EntityPlayerMP) {
        EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender;
        boolean tPlayerOpped = MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile());
        // && tIncreative;
        return tPlayerOpped;
    } else if (pCommandSender instanceof MinecraftServer)
        return true;
    else
        return false;
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 13 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.

the class CommandSanity method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "silent", "short");
    boolean sane = true;
    if (StructureRegistry.INSTANCE.ids().isEmpty()) {
        commandSender.sendMessage(new TextComponentString("No registered structures!"));
        sane = false;
    }
    if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
        sane = false;
    }
    for (ModContainer mod : Loader.instance().getModList()) {
        String domain = mod.getModId();
        Path path = null;
        try {
            path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
        } catch (RCFiles.ResourceLocationLoadException e) {
            RecurrentComplex.logger.error(e);
            commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
            commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
            sane = false;
        }
        if (path != null && !Files.isReadable(path)) {
            commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
            sane = false;
        }
    }
    if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
        sane = false;
    }
    if (!parameters.has("short")) {
        sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
        sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
        sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
    }
    if (sane && !parameters.has("silent"))
        commandSender.sendMessage(new TextComponentString("No specific problems found!"));
}
Also used : Path(java.nio.file.Path) CommandSearchStructure(ivorius.reccomplex.commands.structure.CommandSearchStructure) ivorius.reccomplex.world.gen.feature.structure.generic.generation(ivorius.reccomplex.world.gen.feature.structure.generic.generation) Loader(net.minecraftforge.fml.common.Loader) PriorityQueue(java.util.PriorityQueue) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) RCConfig(ivorius.reccomplex.RCConfig) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) BiPredicate(java.util.function.BiPredicate) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RCFiles(ivorius.reccomplex.files.RCFiles) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) StructureSelector(ivorius.reccomplex.world.gen.feature.selector.StructureSelector) Path(java.nio.file.Path) DimensionManager(net.minecraftforge.common.DimensionManager) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) World(net.minecraft.world.World) IRegistry(net.minecraft.util.registry.IRegistry) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) ConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.ConnectorStrategy) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) Stream(java.util.stream.Stream) ICommandSender(net.minecraft.command.ICommandSender) ResourceLocation(net.minecraft.util.ResourceLocation) ModContainer(net.minecraftforge.fml.common.ModContainer) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Biome(net.minecraft.world.biome.Biome) ModContainer(net.minecraftforge.fml.common.ModContainer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ResourceLocation(net.minecraft.util.ResourceLocation) RCFiles(ivorius.reccomplex.files.RCFiles)

Example 14 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project RecurrentComplex by Ivorforce.

the class SpawnCommandLogic method trigger.

public void trigger(World worldIn) {
    if (!worldIn.isRemote) {
        MinecraftServer minecraftserver = this.getServer();
        if (minecraftserver != null && minecraftserver.isAnvilFileSet() && minecraftserver.isCommandBlockEnabled()) {
            ICommandManager icommandmanager = minecraftserver.getCommandManager();
            ICommandListener cachedAdmin = null;
            if (!RCConfig.notifyAdminOnBlockCommands) {
                cachedAdmin = RCAccessorCommandBase.getCommandAdmin();
                CommandBase.setCommandListener(null);
            }
            try {
                icommandmanager.executeCommand(this, this.commandStored);
            } catch (Exception ex) {
                CrashReport crashreport = CrashReport.makeCrashReport(ex, "Executing command block");
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Command to be executed");
                crashreportcategory.addDetail("Command", this::getCommand);
                crashreportcategory.addDetail("Name", this::getName);
                throw new ReportedException(crashreport);
            }
            if (!RCConfig.notifyAdminOnBlockCommands)
                CommandBase.setCommandListener(cachedAdmin);
        }
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) CrashReportCategory(net.minecraft.crash.CrashReportCategory) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 15 with MinecraftServer

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

the class TeleporterUtility method transferEntityToDimension.

/**
	 * Transfers an entity to a different dimension and location, as if it was being teleported by a dimension portal
	 */
private static boolean transferEntityToDimension(Entity entity, double x, double y, double z, float yaw, float pitch, int dimension) {
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(entity.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
    if (dstWorld != null) {
        NBTTagCompound nbttagcompound = entity.writeToNBT(new NBTTagCompound());
        nbttagcompound.removeTag("Dimension");
        srcWorld.removeEntity(entity);
        Entity newEntity = EntityList.newEntity(entity.getClass(), dstWorld);
        newEntity.readFromNBT(nbttagcompound);
        setEntityPosition(newEntity, x, y, z, yaw, pitch);
        dstWorld.spawnEntity(newEntity);
        dstWorld.updateEntityWithOptionalForce(newEntity, false);
        return true;
    } else {
        return false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)32 BlockPos (net.minecraft.util.math.BlockPos)13 Template (net.minecraft.world.gen.structure.template.Template)9 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)8 World (net.minecraft.world.World)6 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 Mirror (net.minecraft.util.Mirror)5 Rotation (net.minecraft.util.Rotation)5 WorldServer (net.minecraft.world.WorldServer)5 RCConfig (ivorius.reccomplex.RCConfig)4 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)4 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)4 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)4 List (java.util.List)4 Nullable (javax.annotation.Nullable)4 IBlockState (net.minecraft.block.state.IBlockState)4 CommandBase (net.minecraft.command.CommandBase)4 CommandException (net.minecraft.command.CommandException)4 ICommandSender (net.minecraft.command.ICommandSender)4