Search in sources :

Example 1 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class MapFeature method enable.

@Override
public void enable() {
    // we already set the map externally, no need to do anything of the following, just set the world
    if (map != null) {
        world = Bukkit.getWorld(map.getLoadedName(getPhase().getGame().getUuid()));
        return;
    }
    DefaultGameData gameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    if ((type == Type.LOBBY && gameData.lobbyMap == null) || (type == Type.VOTEWINNER && gameData.voteWinner == null)) {
        throw new GameStartException(getPhase().getGame().getGameMode(), "No map data was stored!");
    }
    String mapName;
    if (type == Type.LOBBY) {
        mapName = gameData.lobbyMap.getWorldName();
    } else if (type == Type.VOTEWINNER) {
        mapName = gameData.voteWinner.getWorldName();
    } else {
        throw new VoxelGameLibException("Unknown maptype");
    }
    try {
        map = worldHandler.loadMap(mapName);
        if (!map.isLoaded(getPhase().getGame().getUuid())) {
            world = worldHandler.loadWorld(map, getPhase().getGame().getUuid(), true);
        } else {
            world = Bukkit.getWorld(map.getLoadedName(getPhase().getGame().getUuid()));
        }
    } catch (Exception ex) {
        throw new GameStartException(getPhase().getGame().getGameMode(), ex);
    }
}
Also used : VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) GameStartException(com.voxelgameslib.voxelgameslib.api.exception.GameStartException) DefaultGameData(com.voxelgameslib.voxelgameslib.api.game.DefaultGameData) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) GameStartException(com.voxelgameslib.voxelgameslib.api.exception.GameStartException)

Example 2 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class EditMode method gui.

@Subcommand("gui")
@CommandPermission("%admin")
public void gui(@Nonnull User sender) {
    if (editMode.contains(sender.getUuid())) {
        // TODO implement paginated invs
        InventoryMenuBuilder builder = new InventoryMenuBuilder().withSize(9).withTitle(Lang.legacy(LangKey.INV_MARKER));
        for (int i = 0; i < mapHandler.getMarkerDefinitions().size(); i++) {
            MarkerDefinition markerDefinition = mapHandler.getMarkerDefinitions().get(i);
            ItemStack is = new ItemBuilder(Material.PLAYER_HEAD).name(markerDefinition.getPrefix()).meta(itemMeta -> {
                char prefix = markerDefinition.getPrefix().toUpperCase().charAt(0);
                Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
                SkullMeta meta = ((SkullMeta) itemMeta);
                meta.setPlayerProfile(textureHandler.getPlayerProfile(skin));
                Objects.requireNonNull(meta.getPlayerProfile()).setName(markerDefinition.getPrefix());
                meta.setOwner(markerDefinition.getPrefix());
            }).build();
            builder.withItem(i, is, (player, clickType, itemStack) -> sender.getPlayer().performCommand("editmode skull " + itemStack.getItemMeta().getDisplayName()), ClickType.LEFT);
        }
        builder.show(sender.getPlayer());
    } else {
        Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
    }
}
Also used : ClickType(org.bukkit.event.inventory.ClickType) User(com.voxelgameslib.voxelgameslib.components.user.User) PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) CommandAlias(co.aikar.commands.annotation.CommandAlias) MapHandler(com.voxelgameslib.voxelgameslib.components.map.MapHandler) Singleton(javax.inject.Singleton) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) TextureHandler(com.voxelgameslib.voxelgameslib.internal.texture.TextureHandler) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) MarkerDefinition(com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition) CommandPermission(co.aikar.commands.annotation.CommandPermission) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) Subcommand(co.aikar.commands.annotation.Subcommand) BaseCommand(co.aikar.commands.BaseCommand) Skin(org.mineskin.data.Skin) UUID(java.util.UUID) Logger(java.util.logging.Logger) Lang(com.voxelgameslib.voxelgameslib.internal.lang.Lang) ItemStack(org.bukkit.inventory.ItemStack) Objects(java.util.Objects) List(java.util.List) ItemBuilder(com.voxelgameslib.voxelgameslib.util.utils.ItemBuilder) Syntax(co.aikar.commands.annotation.Syntax) Optional(java.util.Optional) LangKey(com.voxelgameslib.voxelgameslib.internal.lang.LangKey) Default(co.aikar.commands.annotation.Default) ItemBuilder(com.voxelgameslib.voxelgameslib.util.utils.ItemBuilder) InventoryMenuBuilder(org.inventivetalent.menubuilder.inventory.InventoryMenuBuilder) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) Skin(org.mineskin.data.Skin) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) MarkerDefinition(com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 3 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class PlayerProfileTypeAdapter method deserialize.

@Override
public PlayerProfile deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    Dummy dummy = jsonDeserializationContext.deserialize(jsonElement, Dummy.class);
    PlayerProfile playerProfile;
    if (dummy.id != null) {
        playerProfile = Bukkit.createProfile(dummy.id);
    } else if (dummy.name != null) {
        playerProfile = Bukkit.createProfile(dummy.name);
    } else {
        throw new VoxelGameLibException("Could not parse player profile! " + jsonElement);
    }
    playerProfile.setProperties(dummy.properties);
    playerProfile.setId(dummy.id);
    playerProfile.setName(dummy.name);
    return playerProfile;
}
Also used : PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException)

Example 4 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class LangFormatter method handleClick.

@Nonnull
private static ClickEvent handleClick(@Nonnull String token) {
    String[] args = token.split(":");
    ClickEvent clickEvent;
    if (args.length < 2)
        throw new VoxelGameLibException("Can't parse click action (too few args) " + token);
    switch(args[1]) {
        case "run_command":
            clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, token.replace("click:run_command:", ""));
            break;
        case "suggest_command":
            clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, token.replace("click:suggest_command:", ""));
            break;
        case "open_url":
            clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, token.replace("click:open_url:", ""));
            break;
        case "change_page":
            clickEvent = new ClickEvent(ClickEvent.Action.CHANGE_PAGE, token.replace("click:change_page:", ""));
            break;
        default:
            throw new VoxelGameLibException("Can't parse click action (invalid type " + args[1] + ") " + token);
    }
    return clickEvent;
}
Also used : ClickEvent(net.kyori.text.event.ClickEvent) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) Nonnull(javax.annotation.Nonnull)

Example 5 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class LangFormatter method handleHover.

@Nonnull
private static HoverEvent handleHover(@Nonnull String token) {
    String[] args = token.split(":");
    HoverEvent hoverEvent;
    if (args.length < 2)
        throw new VoxelGameLibException("Can't parse hover action (too few args) " + token);
    switch(args[1]) {
        case "show_text":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, parseFormat(token.replace("hover:show_text:", "")));
            break;
        case "show_item":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ITEM, parseFormat(token.replace("hover:show_item:", "")));
            break;
        case "show_entity":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ENTITY, parseFormat(token.replace("hover:show_entity:", "")));
            break;
        default:
            throw new VoxelGameLibException("Can't parse hover action (invalid type " + args[1] + ") " + token);
    }
    return hoverEvent;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) Nonnull(javax.annotation.Nonnull)

Aggregations

VoxelGameLibException (com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException)7 Nonnull (javax.annotation.Nonnull)4 PlayerProfile (com.destroystokyo.paper.profile.PlayerProfile)2 User (com.voxelgameslib.voxelgameslib.components.user.User)2 BaseCommand (co.aikar.commands.BaseCommand)1 CommandAlias (co.aikar.commands.annotation.CommandAlias)1 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Default (co.aikar.commands.annotation.Default)1 Subcommand (co.aikar.commands.annotation.Subcommand)1 Syntax (co.aikar.commands.annotation.Syntax)1 VictoryCondition (com.voxelgameslib.voxelgameslib.api.condition.VictoryCondition)1 EmptyVictoryCondition (com.voxelgameslib.voxelgameslib.api.condition.conditions.EmptyVictoryCondition)1 GameStartException (com.voxelgameslib.voxelgameslib.api.exception.GameStartException)1 DefaultGameData (com.voxelgameslib.voxelgameslib.api.game.DefaultGameData)1 MapHandler (com.voxelgameslib.voxelgameslib.components.map.MapHandler)1 MarkerDefinition (com.voxelgameslib.voxelgameslib.components.map.MarkerDefinition)1 Team (com.voxelgameslib.voxelgameslib.components.team.Team)1 Lang (com.voxelgameslib.voxelgameslib.internal.lang.Lang)1 LangKey (com.voxelgameslib.voxelgameslib.internal.lang.LangKey)1 TextureHandler (com.voxelgameslib.voxelgameslib.internal.texture.TextureHandler)1