Search in sources :

Example 6 with DimensionType

use of org.spongepowered.api.world.DimensionType in project SpongeCommon by SpongePowered.

the class MixinWorldInfo method readSpongeNbt.

@Override
public void readSpongeNbt(NBTTagCompound nbt) {
    final UUID nbtUniqueId = nbt.getUniqueId(NbtDataUtil.UUID);
    if (nbtUniqueId.equals(UUID.fromString("00000000-0000-0000-0000-000000000000"))) {
        return;
    }
    this.uuid = nbtUniqueId;
    this.dimensionId = nbt.getInteger(NbtDataUtil.DIMENSION_ID);
    final String dimensionTypeId = nbt.getString(NbtDataUtil.DIMENSION_TYPE);
    final DimensionType dimensionType = (org.spongepowered.api.world.DimensionType) (Object) WorldManager.getDimensionType(this.dimensionId).orElse(null);
    this.setDimensionType(dimensionType != null ? dimensionType : DimensionTypeRegistryModule.getInstance().getById(dimensionTypeId).orElseThrow(FunctionalUtil.invalidArgument("Could not find a DimensionType registered for world '" + this.getWorldName() + "' with dim id: " + this.dimensionId)));
    this.generateBonusChest = nbt.getBoolean(NbtDataUtil.GENERATE_BONUS_CHEST);
    this.portalAgentType = PortalAgentRegistryModule.getInstance().validatePortalAgent(nbt.getString(NbtDataUtil.PORTAL_AGENT_TYPE), this.levelName);
    this.trackedUniqueIdCount = 0;
    if (nbt.hasKey(NbtDataUtil.WORLD_SERIALIZATION_BEHAVIOR)) {
        short saveBehavior = nbt.getShort(NbtDataUtil.WORLD_SERIALIZATION_BEHAVIOR);
        if (saveBehavior == 1) {
            this.serializationBehavior = SerializationBehaviors.AUTOMATIC;
        } else if (saveBehavior == 0) {
            this.serializationBehavior = SerializationBehaviors.MANUAL;
        } else {
            this.serializationBehavior = SerializationBehaviors.NONE;
        }
    }
    if (nbt.hasKey(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, NbtDataUtil.TAG_LIST)) {
        final NBTTagList playerIdList = nbt.getTagList(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, NbtDataUtil.TAG_COMPOUND);
        for (int i = 0; i < playerIdList.tagCount(); i++) {
            final NBTTagCompound playerId = playerIdList.getCompoundTagAt(i);
            final UUID playerUuid = playerId.getUniqueId(NbtDataUtil.UUID);
            final Integer playerIndex = this.playerUniqueIdMap.inverse().get(playerUuid);
            if (playerIndex == null) {
                this.playerUniqueIdMap.put(this.trackedUniqueIdCount++, playerUuid);
            } else {
                playerIdList.removeTag(i);
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DimensionType(org.spongepowered.api.world.DimensionType) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID)

Example 7 with DimensionType

use of org.spongepowered.api.world.DimensionType in project SpongeCommon by SpongePowered.

the class DimensionTypeRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    WorldManager.registerVanillaTypesAndDimensions();
    for (net.minecraft.world.DimensionType dimensionType : WorldManager.getDimensionTypes()) {
        final DimensionType apiDimensionType = (DimensionType) (Object) dimensionType;
        this.dimensionTypeMappings.put(apiDimensionType.getId(), apiDimensionType);
    }
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType)

Example 8 with DimensionType

use of org.spongepowered.api.world.DimensionType in project ProjectWorlds by trentech.

the class CommandCreate method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("create")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length <= 1) {
        return list;
    }
    String arg = args[args.length - 1];
    if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-dimension")) {
        for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("-generator")) {
        for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-gm") || arg.equalsIgnoreCase("-gamemode")) {
        for (Gamemode type : Gamemode.values()) {
            list.add(Integer.toString(type.getIndex()));
            list.add(type.getGameMode().getName());
        }
    } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("-modifier")) {
        for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-df") || arg.equalsIgnoreCase("-difficulty")) {
        for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
        list.add("true");
        list.add("false");
    } else {
        String parent = args[args.length - 2];
        if (parent.equalsIgnoreCase("-d") || parent.equalsIgnoreCase("-dimension")) {
            for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-g") || parent.equalsIgnoreCase("-generator")) {
            for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-gm") || parent.equalsIgnoreCase("-gamemode")) {
            for (Gamemode type : Gamemode.values()) {
                if (type.getGameMode().getName().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getGameMode().getName());
                }
            }
        } else if (parent.equalsIgnoreCase("-m") || parent.equalsIgnoreCase("-modifier")) {
            for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-df") || parent.equalsIgnoreCase("-difficulty")) {
            for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
            if ("true".startsWith(arg.toLowerCase())) {
                list.add("true");
            }
            if ("false".startsWith(arg.toLowerCase())) {
                list.add("false");
            }
        }
    }
    return list;
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Gamemode(com.gmail.trentech.pjw.utils.Gamemode) ArrayList(java.util.ArrayList) GeneratorType(org.spongepowered.api.world.GeneratorType)

Example 9 with DimensionType

use of org.spongepowered.api.world.DimensionType in project ProjectWorlds by trentech.

the class CommandImport method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("import")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length == 1) {
        for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
            if (world.getWorldName().equalsIgnoreCase(args[0])) {
                for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
                    list.add(type.getId());
                }
                return list;
            }
            if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
                list.add(world.getWorldName());
            }
        }
    }
    if (args.length == 2) {
        for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
            if (type.getId().equalsIgnoreCase(args[1])) {
                for (GeneratorType genType : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
                    list.add(genType.getId());
                }
                return list;
            }
            if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
                list.add(type.getId());
            }
        }
    }
    if (args.length == 3) {
        for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
            if (type.getId().equalsIgnoreCase(args[1])) {
                for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
                    list.add(modType.getId());
                }
                return list;
            }
            if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
                list.add(type.getId());
            }
        }
    }
    if (args.length >= 4) {
        for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
            if (type.getId().equalsIgnoreCase(args[1])) {
                for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
                    list.add(modType.getId());
                }
                return list;
            }
            if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
                list.add(type.getId());
            }
        }
    }
    return list;
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) GeneratorType(org.spongepowered.api.world.GeneratorType)

Example 10 with DimensionType

use of org.spongepowered.api.world.DimensionType in project ProjectWorlds by trentech.

the class CommandImport method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("import")) {
        throw new CommandException(getHelp().getUsageText());
    }
    String[] args = arguments.split(" ");
    if (args[args.length - 1].equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    String worldName;
    String genType;
    String dimType;
    try {
        worldName = args[0];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    if (Sponge.getServer().getWorld(worldName).isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, worldName, " is already loaded"), false);
    }
    WorldData worldData = new WorldData(worldName);
    if (!worldData.exists()) {
        throw new CommandException(Text.of(TextColors.RED, worldName, " is not a valid world"), false);
    }
    SpongeData spongeData = new SpongeData(worldName);
    if (spongeData.exists()) {
        source.sendMessage(Text.of(TextColors.RED, "Sponge world detected"));
        source.sendMessage(Text.builder().color(TextColors.YELLOW).onHover(TextActions.showText(Text.of("Click command for more information "))).onClick(TextActions.runCommand("/pjw:world load")).append(Text.of(" /world load")).build());
        return CommandResult.success();
    }
    try {
        dimType = args[1];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    Optional<DimensionType> optionalDimensionType = Sponge.getRegistry().getType(DimensionType.class, dimType);
    if (!optionalDimensionType.isPresent()) {
        source.sendMessage(Text.of(TextColors.YELLOW, dimType, " is not a valid DimensionType"));
        throw new CommandException(getHelp().getUsageText());
    }
    DimensionType dimensionType = optionalDimensionType.get();
    try {
        genType = args[2];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    Optional<GeneratorType> optionalGeneratorType = Sponge.getRegistry().getType(GeneratorType.class, genType);
    if (!optionalGeneratorType.isPresent()) {
        source.sendMessage(Text.of(TextColors.YELLOW, genType, " is not a valid GeneratorType"));
        throw new CommandException(getHelp().getUsageText());
    }
    GeneratorType generatorType = optionalGeneratorType.get();
    WorldArchetype.Builder builder = WorldArchetype.builder().dimension(dimensionType).generator(generatorType).enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true);
    Collection<WorldGeneratorModifier> modifiers = Collections.<WorldGeneratorModifier>emptyList();
    if (args.length >= 4) {
        for (int i = 3; i < args.length - 3; i++) {
            Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, args[i]);
            if (!optionalModifier.isPresent()) {
                source.sendMessage(Text.of(TextColors.YELLOW, args[i], " is not a valid WorldGeneratorModifier"));
                throw new CommandException(getHelp().getUsageText());
            }
            modifiers.add(optionalModifier.get());
        }
    }
    WorldArchetype settings = builder.build(worldName, worldName);
    WorldProperties properties;
    try {
        properties = Sponge.getServer().createWorldProperties(worldName, settings);
        properties.setGeneratorModifiers(modifiers);
    } catch (IOException e) {
        e.printStackTrace();
        throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
    }
    Sponge.getServer().saveWorldProperties(properties);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, worldName, " imported successfully"));
    return CommandResult.success();
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) SpongeData(com.gmail.trentech.pjw.io.SpongeData) CommandException(org.spongepowered.api.command.CommandException) WorldData(com.gmail.trentech.pjw.io.WorldData) IOException(java.io.IOException) IOException(java.io.IOException) CommandException(org.spongepowered.api.command.CommandException) GeneratorType(org.spongepowered.api.world.GeneratorType) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) WorldArchetype(org.spongepowered.api.world.WorldArchetype) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

DimensionType (org.spongepowered.api.world.DimensionType)11 GeneratorType (org.spongepowered.api.world.GeneratorType)8 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)7 ArrayList (java.util.ArrayList)5 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)5 WorldArchetype (org.spongepowered.api.world.WorldArchetype)4 Difficulty (org.spongepowered.api.world.difficulty.Difficulty)4 IOException (java.io.IOException)3 CommandException (org.spongepowered.api.command.CommandException)3 Gamemode (com.gmail.trentech.pjw.utils.Gamemode)2 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 SpongeTimingsFactory (co.aikar.timings.SpongeTimingsFactory)1 Timings (co.aikar.timings.Timings)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 Help (com.gmail.trentech.pjc.help.Help)1 Usage (com.gmail.trentech.pjc.help.Usage)1 SpongeData (com.gmail.trentech.pjw.io.SpongeData)1 WorldData (com.gmail.trentech.pjw.io.WorldData)1