예제 #1
0
  public JsonMappackTeam(JsonObject json) throws MappackConfigurationException {
    if (!json.has("id"))
      throw new MappackConfigurationException("Invalid team. Team doesn't have an id");
    if (!json.has("name"))
      throw new MappackConfigurationException("Invalid team. Team doesn't have a name");
    if (!json.has("color"))
      throw new MappackConfigurationException("Invalid team. Team doesn't have a color");

    id = json.get("id").getAsString();
    name = json.get("name").getAsString();
    color = ChatColor.getByName(json.get("color").getAsString());
    friendlyFire = !json.has("friendlyFire") || json.get("friendlyFire").getAsBoolean();
    friendlyInvisiblesInvisible =
        !json.has("friendlyInvisiblesInvisible")
            || json.get("friendlyInvisiblesInvisible").getAsBoolean();
    nameTagVisibility =
        json.has("nameTagsVisible")
            ? Visibility.getByName(json.get("nameTagsVisible").getAsString())
            : Visibility.ALWAYS;
    deathMessageVisibility =
        json.has("deathMessagesVisible")
            ? Visibility.getByName(json.get("deathMessagesVisible").getAsString())
            : Visibility.ALWAYS;

    if (color == null)
      throw new MappackConfigurationException(
          "Invalid team color '" + json.get("color").getAsString() + "'");
  }
  protected void deserialize(
      @Nonnull JsonObject object,
      @Nonnull BaseComponent component,
      @Nonnull JsonDeserializationContext context) {
    if (object.has("color")) {
      component.setColor(ChatColor.valueOf(object.get("color").getAsString().toUpperCase()));
    }
    if (object.has("bold")) {
      component.setBold(object.get("bold").getAsBoolean());
    }
    if (object.has("italic")) {
      component.setItalic(object.get("italic").getAsBoolean());
    }
    if (object.has("underlined")) {
      component.setUnderlined(object.get("underlined").getAsBoolean());
    }
    if (object.has("strikethrough")) {
      component.setUnderlined(object.get("strikethrough").getAsBoolean());
    }
    if (object.has("obfuscated")) {
      component.setUnderlined(object.get("obfuscated").getAsBoolean());
    }
    if (object.has("extra")) {
      component.setExtra(
          Arrays.asList(
              context.<BaseComponent[]>deserialize(object.get("extra"), BaseComponent[].class)));
    }

    // Events
    if (object.has("clickEvent")) {
      JsonObject event = object.getAsJsonObject("clickEvent");
      component.setClickEvent(
          new ClickEvent(
              ClickEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()),
              event.get("value").getAsString()));
    }
    if (object.has("hoverEvent")) {
      JsonObject event = object.getAsJsonObject("hoverEvent");
      BaseComponent[] res;
      if (event.get("value").isJsonArray()) {
        res = context.deserialize(event.get("value"), BaseComponent[].class);
      } else {
        res =
            new BaseComponent[] {
              context.<BaseComponent>deserialize(event.get("value"), BaseComponent.class)
            };
      }
      component.setHoverEvent(
          new HoverEvent(
              HoverEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()), res));
    }
  }