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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations