@Override public JsonElement serialize(ScoreComponent component, Type type, JsonSerializationContext context) { JsonObject root = new JsonObject(); serialize( root, component, context ); JsonObject json = new JsonObject(); json.addProperty( "name", component.getName() ); json.addProperty( "objective", component.getObjective() ); json.addProperty( "value", component.getValue() ); root.add( "score", json ); return root; } }
/** * Creates a score component from the original to clone it. * * @param original the original for the new score component */ public ScoreComponent(ScoreComponent original) { super( original ); setName( original.getName() ); setObjective( original.getObjective() ); setValue( original.getValue() ); }
/** * Transform a ScoreComponent by replacing the name and value with the * appropriate values. * * @param player the player to use for the component's name * @param component the component to transform */ private void transformScoreComponent(ProxiedPlayer player, ScoreComponent component) { Preconditions.checkArgument( !isSelectorPattern( component.getName() ), "Cannot transform entity selector patterns" ); if ( component.getValue() != null && !component.getValue().isEmpty() ) { return; // pre-defined values override scoreboard values } // check for '*' wildcard if ( component.getName().equals( "*" ) ) { component.setName( player.getName() ); } if ( player.getScoreboard().getObjective( component.getObjective() ) != null ) { Score score = player.getScoreboard().getScore( component.getName() ); if ( score != null ) { component.setValue( Integer.toString( score.getValue() ) ); } } }