org.spongepowered.api.world.storage.WorldProperties Java Examples

The following examples show how to use org.spongepowered.api.world.storage.WorldProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerLogin(ClientConnectionEvent.Login event) {
    GDTimings.PLAYER_LOGIN_EVENT.startTimingIfSync();
    User player = event.getTargetUser();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getToTransform().getExtent().getUniqueId())) {
        GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
        return;
    }

    final WorldProperties worldProperties = event.getToTransform().getExtent().getProperties();
    final UUID playerUniqueId = player.getUniqueId();
    final GDClaimManager claimWorldManager = this.dataStore.getClaimWorldManager(worldProperties.getUniqueId());
    final Instant dateNow = Instant.now();
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        if (claim.getType() != ClaimTypes.ADMIN && claim.getOwnerUniqueId().equals(playerUniqueId)) {
            claim.getData().setDateLastActive(dateNow);
            for (Claim subdivision : ((GDClaim) claim).children) {
                subdivision.getData().setDateLastActive(dateNow);
            }
            ((GDClaim) claim).getInternalClaimData().setRequiresSave(true);
            ((GDClaim) claim).getInternalClaimData().save();
        }
    }
    GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
}
 
Example #2
Source File: ImportWorldCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    String name = (String) args.getOne("name").get();

    Path path = Sponge.getGame().getSavesDirectory();
    if (!(Files.exists(path.resolve(name.toLowerCase())) || Files.exists(path.resolve(name)) || Sponge.getServer().getAllWorldProperties().stream().anyMatch(x -> x.getWorldName().equalsIgnoreCase(name)))) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.import.notfound", "%world%", name));
    }

    Messages.send(sender, "world.command.world.import.starting", "%name%", name);

    WorldProperties props;
    try {
        props = Sponge.getServer().createWorldProperties(name, WorldArchetype.builder().build(name.toLowerCase(), name));
    } catch (IOException e) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.import.fileerror", "%error%", e.getMessage()));
    }
    Sponge.getServer().saveWorldProperties(props);
    World world = Sponge.getServer().loadWorld(props).orElseThrow(() -> new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.import.loaderror")));
    Messages.send(sender, "world.command.world.import.success", "%name%", world.getName());
    return CommandResult.success();
}
 
Example #3
Source File: CachedWorld.java    From Web-API with MIT License 6 votes vote down vote up
private void saveWorldProperties(WorldProperties props) {
    this.uuid = UUID.fromString(props.getUniqueId().toString());
    this.name = props.getWorldName();
    this.loaded = false;

    this.loadOnStartup = props.loadOnStartup();
    this.keepSpawnLoaded = props.doesKeepSpawnLoaded();
    this.allowCommands = props.areCommandsAllowed();
    this.generateBonusChests = props.doesGenerateBonusChest();
    this.mapFeaturesEnabled = props.usesMapFeatures();
    this.border = new CachedWorldBorder(props);
    this.difficulty = new CachedCatalogType<>(props.getDifficulty());
    this.dimensionType = new CachedCatalogType<>(props.getDimensionType());
    this.gameMode = new CachedCatalogType<>(props.getGameMode());
    this.gameRules = new HashMap<>(props.getGameRules());
    this.generatorType = new CachedCatalogType<>(props.getGeneratorType());
    this.seed = props.getSeed();
    this.spawn = props.getSpawnPosition();
    this.time = props.getWorldTime();
}
 
Example #4
Source File: DeleteCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to delete a region."))
            .arguments(
                    GenericArguments.optional(GenericArguments.string(Text.of("regionName"))),
                    GenericArguments.optional(GenericArguments.world(Text.of("world")))
            )
            .permission("redprotect.command.delete")
            .executor((src, args) -> {
                if (!(src instanceof Player)) {
                    HandleHelpPage(src, 1);
                } else {
                    Player player = (Player) src;

                    if (args.hasAny("regionName")) {
                        handleDeleteName(player, args.<String>getOne("regionName").get(), "");
                    } else if (args.hasAny("world")) {
                        handleDeleteName(player, args.<String>getOne("regionName").get(), args.<WorldProperties>getOne("world").get().getWorldName());
                    } else {
                        handleDelete(player);
                    }

                }
                return CommandResult.success();
            }).build();
}
 
Example #5
Source File: WorldServlet.java    From Web-API with MIT License 6 votes vote down vote up
@DELETE
@Path("/{world}")
@Permission("delete")
@ApiOperation(
        value = "Delete a world",
        notes = "Deletes an existing world. **The world must be unloaded before deleting it**")
public CachedWorld deleteWorld(
        @PathParam("world") @ApiParam("The uuid of the world to delete") CachedWorld world) {
    boolean deleted = WebAPI.runOnMain(() -> {
        Optional<WorldProperties> optLive = world.getLiveProps();
        if (!optLive.isPresent())
            throw new InternalServerErrorException("Could not get live world properties");

        WorldProperties live = optLive.get();
        try {
            return Sponge.getServer().deleteWorld(live).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new InternalServerErrorException(e.getMessage());
        }
    });

    cacheService.removeWorld(world.getUUID());
    return world;
}
 
Example #6
Source File: CacheService.java    From Web-API with MIT License 6 votes vote down vote up
/**
 * Gets a specific world by UUID.
 *
 * @param uuid The UUID of the world.
 * @return An optional containing the world, or empty if not found.
 */
public Optional<CachedWorld> getWorld(UUID uuid) {
    if (!worlds.containsKey(uuid)) {
        return Optional.empty();
    }

    final CachedWorld res = worlds.get(uuid);
    if (res.isExpired()) {
        return Optional.of(WebAPI.runOnMain(() -> {
            Optional<World> world = Sponge.getServer().getWorld(uuid);
            if (world.isPresent())
                return updateWorld(world.get());
            Optional<WorldProperties> props = Sponge.getServer().getWorldProperties(uuid);
            if (!props.isPresent())
                throw new InternalServerErrorException("Could not get world properties");
            return updateWorld(props.get());
        }));
    } else {
        return Optional.of(res);
    }
}
 
Example #7
Source File: FlatFileDataStore.java    From GriefPrevention with MIT License 6 votes vote down vote up
public void unloadWorldData(WorldProperties worldProperties) {
    GPClaimManager claimWorldManager = this.getClaimWorldManager(worldProperties);
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        ((GPClaim) claim).unload();
    }
    // Task must be cancelled before removing the claimWorldManager reference to avoid a memory leak
    Task cleanupTask = cleanupClaimTasks.get(worldProperties.getUniqueId());
    if (cleanupTask != null) {
       cleanupTask.cancel();
       cleanupClaimTasks.remove(worldProperties.getUniqueId());
    }

    claimWorldManager.unload();
    this.claimWorldManagers.remove(worldProperties.getUniqueId());
    DataStore.dimensionConfigMap.remove(worldProperties.getUniqueId());
    DataStore.worldConfigMap.remove(worldProperties.getUniqueId());
}
 
Example #8
Source File: SpongePlugin.java    From BlueMap with MIT License 6 votes vote down vote up
@Listener
public void onServerStart(GameStartingServerEvent evt) {
	asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this);
	
	//save all world properties to generate level_sponge.dat files
	for (WorldProperties properties : Sponge.getServer().getAllWorldProperties()) {
		Sponge.getServer().saveWorldProperties(properties);
	}
	
	//register commands
	for(SpongeCommandProxy command : commands.getRootCommands()) {
		Sponge.getCommandManager().register(this, command, command.getLabel());
	}
	
	asyncExecutor.execute(() -> {
		try {
			Logger.global.logInfo("Loading...");
			bluemap.load();
			if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!");
		} catch (Throwable t) {
			Logger.global.logError("Failed to load!", t);
		}
	});
}
 
Example #9
Source File: CommandClaimList.java    From GriefPrevention with MIT License 5 votes vote down vote up
private Consumer<CommandSource> createClaimListConsumer(Player src, User user, String type, WorldProperties worldProperties) {
    return consumer -> {
        if (type.equalsIgnoreCase("ALL")) {
            this.displayOwned = false;
        } else {
            this.displayOwned = true;
        }
        showClaimList(src, user, null, worldProperties);
    };
}
 
Example #10
Source File: CommandAdjustBonusClaimBlocks.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandCompletion("@gdplayers @gddummy")
@CommandAlias("acb|adjustclaimblocks")
@Description("Updates a player's accrued claim block total")
@Syntax("<player> <amount>")
@Subcommand("player adjustbonusblocks")
public void execute(CommandSource src, User user, int amount, @Optional String world) {
    WorldProperties worldProperties = world == null ? null : Sponge.getServer().getWorldProperties(world).orElse(null);
    if (worldProperties == null) {
        if (src instanceof Player) {
            worldProperties = ((Player) src).getWorld().getProperties();
        } else {
            worldProperties = Sponge.getServer().getDefaultWorld().get();
        }
    }
    if (worldProperties == null || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(worldProperties.getUniqueId())) {
        GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().CLAIM_DISABLED_WORLD);
        return;
    }

    // parse the adjustment amount
    int adjustment = amount;
    //User user = args.<User>getOne("user").get();

    // give blocks to player
    GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(worldProperties.getUniqueId(), user.getUniqueId());
    playerData.setBonusClaimBlocks(playerData.getBonusClaimBlocks() + adjustment);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ADJUST_BONUS_BLOCKS_SUCCESS, ImmutableMap.of(
            "player", user.getName(),
            "amount", adjustment,
            "total", playerData.getBonusClaimBlocks()));
    TextAdapter.sendComponent(src, message);
    GriefDefenderPlugin.getInstance().getLogger().info(
            src.getName() + " adjusted " + user.getName() + "'s bonus claim blocks by " + adjustment + ".");
}
 
Example #11
Source File: GPApiProvider.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Override
public Optional<PlayerData> getGlobalPlayerData(UUID playerUniqueId) {
    final WorldProperties worldProperties = Sponge.getServer().getDefaultWorld().orElse(null);
    if (worldProperties == null) {
        return Optional.empty();
    }

    return this.getWorldPlayerData(worldProperties, playerUniqueId);
}
 
Example #12
Source File: GPClaimManager.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void createWildernessClaim(WorldProperties worldProperties) {
    World world = Sponge.getServer().getWorld(worldProperties.getUniqueId()).get();
    Location<World> lesserCorner = new Location<World>(world, -30000000, 0, -30000000);
    Location<World> greaterCorner = new Location<World>(world, 29999999, 255, 29999999);
    // Use world UUID as wilderness claim ID
    GPClaim wilderness = new GPClaim(lesserCorner, greaterCorner, worldProperties.getUniqueId(), ClaimType.WILDERNESS, null, false);
    wilderness.setOwnerUniqueId(GriefPreventionPlugin.WORLD_USER_UUID);
    wilderness.initializeClaimData(null);
    DATASTORE.writeClaimToStorage(wilderness);
    this.theWildernessClaim = wilderness;
    this.claimUniqueIdMap.put(wilderness.getUniqueId(), wilderness);
}
 
Example #13
Source File: DataStore.java    From GriefPrevention with MIT License 5 votes vote down vote up
public GPClaimManager getClaimWorldManager(WorldProperties worldProperties) {
    GPClaimManager claimWorldManager = null;
    if (worldProperties == null) {
        worldProperties = Sponge.getServer().getDefaultWorld().get();
    }
    claimWorldManager = this.claimWorldManagers.get(worldProperties.getUniqueId());

    if (claimWorldManager == null) {
        registerWorld(worldProperties);
        claimWorldManager = this.claimWorldManagers.get(worldProperties.getUniqueId());
    }
    return claimWorldManager;
}
 
Example #14
Source File: CommandClaimAbandonWorld.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandCompletion("@gdworlds @gddummy")
@CommandAlias("abandonworld")
@Description("Special admin command used to abandon ALL user claims in world")
@Subcommand("abandon world")
@Syntax("[<world>]")
public void execute(Player player, @Optional String worldName) {
    WorldProperties world = player.getWorld().getProperties();
    if (worldName != null) {
        world = Sponge.getServer().getWorldProperties(worldName).orElse(null);
        if (world == null) {
            TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_WORLD_NOT_FOUND,
                    ImmutableMap.of("world", worldName)));
            return;
        }
    }
    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(player.getWorld().getUniqueId());
    if (claimWorldManager.getWorldClaims().size() == 0) {
        try {
            throw new CommandException(MessageCache.getInstance().CLAIM_NO_CLAIMS);
        } catch (CommandException e) {
            TextAdapter.sendComponent(player, e.getText());
            return;
        }
    }

    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ABANDON_WORLD_WARNING, ImmutableMap.of(
            "world", TextComponent.of(world.getWorldName())));
    final Component confirmationText = TextComponent.builder()
            .append(message)
            .append(TextComponent.builder()
                .append("\n[")
                .append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
                .append("]\n")
                .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(player, createConfirmationConsumer(player, world), true)))
                .hoverEvent(HoverEvent.showText(MessageCache.getInstance().UI_CLICK_CONFIRM)).build())
            .build();
    TextAdapter.sendComponent(player, confirmationText);
}
 
Example #15
Source File: BaseStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
public GDClaimManager getClaimWorldManager(UUID worldUniqueId) {
    GDClaimManager claimWorldManager = null;
    if (worldUniqueId == null) {
        worldUniqueId = Sponge.getServer().getDefaultWorld().get().getUniqueId();
    }
    claimWorldManager = this.claimWorldManagers.get(worldUniqueId);

    if (claimWorldManager == null) {
        final WorldProperties defaultWorldProperties = Sponge.getServer().getDefaultWorld().get();
        final World world = Sponge.getServer().getWorld(worldUniqueId).orElse(Sponge.getServer().getWorld(defaultWorldProperties.getUniqueId()).get());
        registerWorld(world);
        claimWorldManager = this.claimWorldManagers.get(world.getUniqueId());
    }
    return claimWorldManager;
}
 
Example #16
Source File: CacheService.java    From Web-API with MIT License 5 votes vote down vote up
public void updateWorlds() {
    WebAPI.runOnMain(() -> {
        worlds.clear();

        // The worlds that are loaded on server start are overwritten by the world load event later
        // TODO: Sponge has a bug that makes the "getAllWorldProperties" method cache the world properties
        Collection<WorldProperties> unloadedWorlds = Sponge.getServer().getAllWorldProperties();
        for (WorldProperties world : unloadedWorlds) {
            updateWorld(world);
        }
    });
}
 
Example #17
Source File: CommandClaimDeleteAllAdmin.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandAlias("deletealladmin")
@Description("Deletes all administrative claims.")
@Subcommand("delete alladmin")
public void execute(Player player, @Optional String worldName) {
    WorldProperties worldProperties = null;
    if (worldName != null) {
        worldProperties = Sponge.getServer().getWorldProperties(worldName).orElse(null);
        if (worldProperties == null) {
            TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.COMMAND_WORLD_NOT_FOUND,
                    ImmutableMap.of("world", worldName)));
            return;
        }
    }

    Component message = null;
    if (worldProperties != null) {
        message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.DELETE_ALL_TYPE_WARNING_WORLD, ImmutableMap.of(
                "type", TextComponent.of("ADMIN").color(TextColor.RED),
                "world", worldProperties.getWorldName()));
    } else {
        message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.DELETE_ALL_TYPE_WARNING, ImmutableMap.of(
                "type", TextComponent.of("ADMIN").color(TextColor.RED)));
    }
    final Component confirmationText = TextComponent.builder("")
            .append(message)
            .append(TextComponent.builder()
                .append("\n[")
                .append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
                .append("]\n")
                .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(player, createConfirmationConsumer(player, worldProperties), true)))
                .hoverEvent(HoverEvent.showText(MessageCache.getInstance().UI_CLICK_CONFIRM)).build())
            .build();
    TextAdapter.sendComponent(player, confirmationText);
}
 
Example #18
Source File: GPPlayerData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public GPPlayerData(WorldProperties worldProperties, UUID playerUniqueId, PlayerStorageData playerStorage, GriefPreventionConfig<?> activeConfig, Set<Claim> claims) {
    this.worldProperties = worldProperties;
    this.playerID = playerUniqueId;
    this.playerStorage = playerStorage;
    this.claimList = claims;
    this.refreshPlayerOptions();
}
 
Example #19
Source File: CommandAdjustBonusClaimBlocks.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    WorldProperties worldProperties = args.<WorldProperties> getOne("world").orElse(Sponge.getServer().getDefaultWorld().get());

    if (worldProperties == null) {
        if (src instanceof Player) {
            worldProperties = ((Player) src).getWorld().getProperties();
        } else {
            worldProperties = Sponge.getServer().getDefaultWorld().get();
        }
    }
    if (worldProperties == null || !GriefPreventionPlugin.instance.claimsEnabledForWorld(worldProperties)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.claimDisabledWorld.toText());
        return CommandResult.success();
    }

    // parse the adjustment amount
    int adjustment = args.<Integer>getOne("amount").get();
    User user = args.<User>getOne("user").get();

    // give blocks to player
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(worldProperties, user.getUniqueId());
    playerData.setBonusClaimBlocks(playerData.getBonusClaimBlocks() + adjustment);
    playerData.getStorageData().save();
    final Text message = GriefPreventionPlugin.instance.messageData.adjustBlocksSuccess
            .apply(ImmutableMap.of(
            "player", Text.of(user.getName()),
            "adjustment", Text.of(adjustment),
            "total", Text.of(playerData.getBonusClaimBlocks()))).build();
    GriefPreventionPlugin
            .sendMessage(src, message);
    GriefPreventionPlugin.addLogEntry(
            src.getName() + " adjusted " + user.getName() + "'s bonus claim blocks by " + adjustment + ".",
            CustomLogEntryTypes.AdminActivity);

    return CommandResult.success();
}
 
Example #20
Source File: CommandSetAccruedClaimBlocks.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    WorldProperties worldProperties = args.<WorldProperties> getOne("world").orElse(null);
    Player player = src instanceof Player ? (Player)src : null;
    if (worldProperties == null) {
        if (player != null) {
            worldProperties = player.getWorld().getProperties();
        } else {
            src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No valid world could be found!"));
            return CommandResult.success();
        }
    }

    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(worldProperties)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.claimDisabledWorld.toText());
        return CommandResult.success();
    }

    // parse the adjustment amount
    int newAmount = args.<Integer>getOne("amount").get();
    User user = args.<User>getOne("user").get();

    // set player's blocks
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(worldProperties, user.getUniqueId());
    if (!playerData.setAccruedClaimBlocks(newAmount)) {
        if (player != null) {
            player.sendMessage(Text.of(TextColors.RED, "User " + user.getName() + " has a total of " + playerData.getAccruedClaimBlocks() + " and will exceed the maximum allowed accrued claim blocks if granted an additional " + newAmount + " blocks. ",
                    "Either lower the amount or have an admin grant the user with an override."));
        }
        return CommandResult.success();
    }

    playerData.getStorageData().save();
    GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.commandAcbSuccess.toText());
    GriefPreventionPlugin.addLogEntry(src.getName() + " set " + user.getName() + "'s accrued claim blocks to " + newAmount + ".",
            CustomLogEntryTypes.AdminActivity);
    return CommandResult.success();
}
 
Example #21
Source File: InfoCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to see info about regions."))
            .arguments(
                    GenericArguments.optional(GenericArguments.string(Text.of("region"))),
                    GenericArguments.optional(GenericArguments.world(Text.of("world"))))
            .permission("redprotect.command.info")
            .executor((src, args) -> {
                if (!(src instanceof Player) && args.hasAny("region") && args.hasAny("world")) {
                    if (Sponge.getServer().getWorld(args.<WorldProperties>getOne("world").get().getWorldName()).isPresent()) {
                        Region r = RedProtect.get().rm.getRegion(args.<String>getOne("region").get(), args.<WorldProperties>getOne("world").get().getWorldName());
                        if (r != null) {
                            src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("general.color") + "-----------------------------------------"));
                            src.sendMessage(r.info());
                            src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("general.color") + "-----------------------------------------"));
                        } else {
                            src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("correct.usage") + "&eInvalid region: " + args.<String>getOne("region").get()));
                        }
                    } else {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("correct.usage") + " " + "&eInvalid World: " + args.<WorldProperties>getOne("world").get().getWorldName()));
                    }
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    if (args.hasAny("region") && args.hasAny("world")) {
                        handleInfo(player, args.<String>getOne("region").get(), args.<WorldProperties>getOne("world").get().getWorldName());
                    } else if (args.hasAny("region")) {
                        handleInfo(player, args.<String>getOne("region").get(), "");
                    } else {
                        handleInfoTop(player);
                    }
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "info", true);
                return CommandResult.success();
            }).build();
}
 
Example #22
Source File: RemoveMemberCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to remove members to regions."))
            .arguments(GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.removemember")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.removemember")))
            .permission("redprotect.command.removemember")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleRemoveMember(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleRemoveMember(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "removemember", true);
                return CommandResult.success();
            }).build();
}
 
Example #23
Source File: AddLeaderCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to add leaders to regions."))
            .arguments(GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.addleader")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.addleader")))
            .permission("redprotect.command.addleader")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleAddLeader(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleAddLeader(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "addleader", true);
                return CommandResult.success();
            }).build();
}
 
Example #24
Source File: RemoveAdminCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to remove admins to regions."))
            .arguments(GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.removeadmin")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.removeadmin")))
            .permission("redprotect.command.removeadmin")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleRemoveAdmin(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleRemoveAdmin(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "removeadmin", true);
                return CommandResult.success();
            }).build();
}
 
Example #25
Source File: AddMemberCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to add members to regions."))
            .arguments(GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.addmember")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.addmember")))
            .permission("redprotect.command.addmember")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleAddMember(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleAddMember(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "addmember", true);
                return CommandResult.success();
            }).build();
}
 
Example #26
Source File: RemoveLeaderCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to remove leaders to regions."))
            .arguments(GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.removeleader")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.removeleader")))
            .permission("redprotect.command.removeleader")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleRemoveLeader(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleRemoveLeader(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "removeleader", true);
                return CommandResult.success();
            }).build();
}
 
Example #27
Source File: AddAdminCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to add admins to regions."))
            .arguments(
                    GenericArguments.string(Text.of("player")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.addadmin")),
                    GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.addadmin")))
            .permission("redprotect.command.addadmin")
            .executor((src, args) -> {
                if (args.hasAny("region") && args.hasAny("world")) {
                    String region = args.<String>getOne("region").get();
                    WorldProperties worldProperties = args.<WorldProperties>getOne("world").get();

                    if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld")));
                        return CommandResult.success();
                    }
                    Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName());
                    if (r == null) {
                        src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region));
                        return CommandResult.success();
                    }
                    handleAddAdmin(src, args.<String>getOne("player").get(), r);
                    return CommandResult.success();
                } else if (src instanceof Player) {
                    Player player = (Player) src;
                    handleAddAdmin(player, args.<String>getOne("player").get(), null);
                    return CommandResult.success();
                }

                RedProtect.get().lang.sendCommandHelp(src, "addadmin", true);
                return CommandResult.success();
            }).build();
}
 
Example #28
Source File: InfoWorldCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    WorldProperties world;
    if (!args.hasAny("world")) {
        checkIfPlayer(src);
        Player p = (Player) src;
        world = p.getWorld().getProperties();
    } else {
        world = args.<WorldProperties>getOne("world").get();
    }
    Messages.send(src, "world.command.world.info.single.title", "%world%", world.getWorldName());
    Messages.send(src, "world.command.world.info.single.id-uuid", "%id%", world.getUniqueId().toString());
    String numeric;
    try {
        numeric = world.getAdditionalProperties().getView(DataQuery.of("SpongeData")).get().get(DataQuery.of("dimensionId")).get().toString();
    } catch (Exception ex) {
        numeric = "?";
    }
    Messages.send(src, "world.command.world.info.single.id-numeric", "%id%", numeric);
    Messages.send(src, "world.command.world.info.single.enabled", "%enabled%", world.loadOnStartup() ? Messages.getFormatted(src, "world.enabled") : Messages.getFormatted(src, "world.disabled"));
    Messages.send(src, "world.command.world.info.single.difficulty", "%difficulty%", world.getDifficulty().getName());
    Messages.send(src, "world.command.world.info.single.gamemode", "%gamemode%", world.getGameMode().getName());
    Messages.send(src, "world.command.world.info.single.hardcore", "%hardcore%", world.isHardcore() ? Messages.getFormatted(src, "world.enabled") : Messages.getFormatted(src, "world.disabled"));
    Messages.send(src, "world.command.world.info.single.pvp", "%pvp%", world.isPVPEnabled() ? Messages.getFormatted(src, "world.enabled") : Messages.getFormatted(src, "world.disabled"));
    src.sendMessage(Messages.getFormatted(src, "world.command.world.info.single.gamerules").toBuilder().onClick(TextActions.runCommand("/world gamerule " + world.getWorldName())).build());
    return CommandResult.success();
}
 
Example #29
Source File: EnableWorldCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    WorldProperties world = (WorldProperties) args.getOne("world").get();
    world.setLoadOnStartup(true);
    Sponge.getServer().loadWorld(world);
    Messages.send(src, "world.command.world.enable.success", "%world%", world.getWorldName());
    return CommandResult.success();
}
 
Example #30
Source File: WorldPropertiesArgument.java    From UltimateCore with MIT License 5 votes vote down vote up
@Nullable
@Override
public WorldProperties parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    Optional<WorldProperties> t = Sponge.getServer().getWorldProperties(value);
    if (t.isPresent()) {
        return t.get();
    } else {
        throw args.createError(Messages.getFormatted("core.worldnotfound", "%world%", value));
    }
}