Skip to content

Commit

Permalink
chore: merge api-14 for additions
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
  • Loading branch information
gabizou committed Feb 8, 2025
2 parents 700c16b + c4ed14f commit f78b07f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.VirtualComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.flattener.ComponentFlattener;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.registry.DefaultedRegistryReference;

import java.util.function.Consumer;
import java.util.function.Function;

/**
* Additional SpongeAPI-specific methods for working with {@link Component}s and related.
Expand Down Expand Up @@ -111,6 +114,17 @@ public static ComponentFlattener flattener() {
return SpongeComponents.factory().flattener();
}

/**
* Creates a new {@link VirtualComponent} that will be used to
* render each {@link Audience} their own version of
* the received message.
*
* @return The virtual component
*/
public static VirtualComponent receiverVirtualComponent(final Function<Audience, ComponentLike> apply) {
return SpongeComponents.factory().receiverVirtualComponent(apply);
}

private static Factory factory() {
return Sponge.game().factoryProvider().provide(Factory.class);
}
Expand All @@ -137,5 +151,6 @@ Component render(

ComponentFlattener flattener();

VirtualComponent receiverVirtualComponent(Function<Audience, ComponentLike> apply);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.data;

import org.spongepowered.api.data.value.CollectionValue;

import java.util.Collection;

public interface CollectionDataProvider<E, V extends Collection<E>, C extends CollectionValue<E, V>> extends DataProvider<C, V> {

DataTransactionResult offerSingle(DataHolder.Mutable dataHolder, E element);

DataTransactionResult removeSingle(DataHolder.Mutable dataHolder, E element);
}
28 changes: 24 additions & 4 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,32 @@ public final class Keys {
public static final Key<MapValue<EntityType<?>, Double>> CUSTOM_ATTACK_DAMAGE = Keys.mapKey(ResourceKey.sponge("custom_attack_damage"), new TypeToken<EntityType<?>>() {}, TypeToken.get(Double.class));

/**
* The resource pack model index of an {@link ItemStack}.
* List of floats used by items model definitions.
*
* <p>Resource packs can use the same index in their files to replace the
* item model of an ItemStack.</p>
* @see <a href="https://minecraft.wiki/w/Items_model_definition">Items model definition</a>
*/
public static final Key<Value<Integer>> CUSTOM_MODEL_DATA = Keys.key(ResourceKey.sponge("custom_model_data"), Integer.class);
public static final Key<ListValue<Float>> CUSTOM_MODEL_DATA_FLOATS = Keys.listKey(ResourceKey.sponge("custom_model_data_floats"), Float.class);

/**
* List of booleans used by items model definitions.
*
* @see <a href="https://minecraft.wiki/w/Items_model_definition">Items model definition</a>
*/
public static final Key<ListValue<Boolean>> CUSTOM_MODEL_DATA_FLAGS = Keys.listKey(ResourceKey.sponge("custom_model_data_flags"), Boolean.class);

/**
* List of strings used by items model definitions.
*
* @see <a href="https://minecraft.wiki/w/Items_model_definition">Items model definition</a>
*/
public static final Key<ListValue<String>> CUSTOM_MODEL_DATA_STRINGS = Keys.listKey(ResourceKey.sponge("custom_model_data_strings"), String.class);

/**
* List of colors used by items model definitions.
*
* @see <a href="https://minecraft.wiki/w/Items_model_definition">Items model definition</a>
*/
public static final Key<ListValue<Color>> CUSTOM_MODEL_DATA_COLORS = Keys.listKey(ResourceKey.sponge("custom_model_data_colors"), Color.class);

/**
* The custom name of an {@link Entity}, {@link ItemStack} or {@link BlockEntity}.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/spongepowered/api/entity/living/player/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.api.entity.living.player;

import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.Server;
import org.spongepowered.api.block.entity.EnderChest;
import org.spongepowered.api.data.DataHolder;
import org.spongepowered.api.data.Keys;
Expand Down Expand Up @@ -203,4 +204,13 @@ default Value.Mutable<VanishState> vanishState() {
return this.requireValue(Keys.VANISH_STATE).asMutable();
}

/**
* Gets if the {@link User} has played on the {@link Server} before. Added
* as a utility.
*
* @return True if played before, false otherwise
*/
default boolean hasPlayedBefore() {
return !this.firstJoined().map(Value::get).equals(this.lastJoined().map(Value::get));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ default Value.Mutable<Boolean> hasViewedCredits() {
* @return True if played before, false otherwise
*/
default boolean hasPlayedBefore() {
return !this.firstJoined().equals(this.lastPlayed());
return !this.firstJoined().map(Value::get).equals(this.lastJoined().map(Value::get));
}

/**
Expand Down

0 comments on commit f78b07f

Please sign in to comment.