Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ Lukas Planz <lukas.planz@web.de>
granny <contact@granny.dev>
mja00 <me@mja00.dev>
roro1506HD <16260475+roro1506HD@users.noreply.github.com>
Strokkur24 <strokkur.24@gmail.com>
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.damage.DamageEffect;
import org.bukkit.damage.DamageSource;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scoreboard.ScoreHolder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -100,4 +101,12 @@ class Holder {
Component defaultMannequinDescription();

<MODERN, LEGACY> GameRule<LEGACY> legacyGameRuleBridge(GameRule<MODERN> rule, Function<LEGACY, MODERN> fromLegacyToModern, Function<MODERN, LEGACY> toLegacyFromModern, Class<LEGACY> legacyClass);

/**
* Creates a wrapping score holder
*
* @param entry the entry to wrap
* @return a wrapping ScoreHolder
*/
ScoreHolder scoreHolderOf(String entry);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.papermc.paper.command.brigadier.argument;

import com.mojang.brigadier.arguments.ArgumentType;
import io.papermc.paper.command.brigadier.argument.operation.ScoreboardOperation;
import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate;
import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
Expand All @@ -10,21 +11,22 @@
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ObjectiveResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ScoreHolderResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.TeamResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import io.papermc.paper.entity.LookAnchor;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import java.util.Set;
import java.util.UUID;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Axis;
import org.bukkit.GameMode;
import org.bukkit.HeightMap;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -367,6 +369,53 @@ public static ArgumentType<Criteria> objectiveCriteria() {
return provider().objectiveCriteria();
}

/**
* Represents a selector that can capture any single
* score holder.
*
* @return argument
*/
public static ArgumentType<ScoreHolderResolver> scoreHolder() {
return provider().scoreHolder();
}

/**
* Represents a selector that can capture multiple
* score holders.
*
* @return argument
*/
public static ArgumentType<ScoreHolderResolver> scoreHolders() {
return provider().scoreHolders();
}

/**
* An operation argument.
*
* @return argument
*/
public static ArgumentType<ScoreboardOperation> operation() {
return provider().operation();
}

/**
* An objective argument.
*
* @return argument
*/
public static ArgumentType<ObjectiveResolver> objective() {
return provider().objective();
}

/**
* A team argument.
*
* @return argument
*/
public static ArgumentType<TeamResolver> team() {
return provider().team();
}

/**
* An entity anchor argument.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.papermc.paper.command.brigadier.argument;

import com.mojang.brigadier.arguments.ArgumentType;
import io.papermc.paper.command.brigadier.argument.operation.ScoreboardOperation;
import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate;
import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate;
import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider;
Expand All @@ -10,8 +11,11 @@
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ObjectiveResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.ScoreHolderResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.TeamResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import io.papermc.paper.entity.LookAnchor;
Expand Down Expand Up @@ -90,6 +94,16 @@ static VanillaArgumentProvider provider() {

ArgumentType<DisplaySlot> scoreboardDisplaySlot();

ArgumentType<ScoreHolderResolver> scoreHolder();

ArgumentType<ScoreHolderResolver> scoreHolders();

ArgumentType<ScoreboardOperation> operation();

ArgumentType<ObjectiveResolver> objective();

ArgumentType<TeamResolver> team();

ArgumentType<NamespacedKey> namespacedKey();

// include both key types as we are slowly moving to use adventure's key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.papermc.paper.command.brigadier.argument.operation;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

/**
* Represents a simple arithmetic operation between two integers.
* A {@link ScoreboardOperation} backs an operator.
* Most arithmetic operators (like {@code +=, -=, /=, etc.}) are
* supported, alongside certain conditional operators ({@code >=, <=, ==, etc.}).
* <p>
* Note that conditional operators, instead of yielding a boolean value, return the value
* that matches the operation.
* For example, the {@code <=} operator always returns the <strong>smaller</strong> value
* of two given values.
*/
@ApiStatus.Experimental
@NullMarked
public interface ScoreboardOperation {

/**
* Applies this operation to a pair of integers.
* <p>
* Arithmetic between two integers always follows this pattern:
* <pre>
* return left &lt;operator&gt; right
* </pre>
* On certain operators, such as division, the order matters.
* {@code 20 %= 10} yields a different result than {@code 10 %= 20}.
*
* @param left left side of the expression
* @param right right side of the expression
* @return result of this operation
* @see Result
*/
Result apply(int left, int right) throws CommandSyntaxException;

/**
* Represents the result of a {@link ScoreboardOperation}.
* <p>
* For arithmetical operations (+=, -=, /=, *=), {@link #result()} will yield the mathemtical result.
* {@link #other()} will return the right input integer.
* <p>
* For any conditional operations or the swap operation, {@link #result()} will yield the left side
* and {@link #other()} will yield the right side of the operation.
*/
interface Result {

/**
* Get the left side of the result.
*
* @return result
*/
int result();

/**
* Get the right side of the result.
*
* @return other
*/
int other();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.papermc.paper.command.brigadier.argument.resolvers;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

/**
* A resolver that's capable of resolving
* an {@link Objective} value using a {@link Scoreboard} and {@link CommandSourceStack}.
*
* @see ArgumentTypes#objective()
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
@NullMarked
public interface ObjectiveResolver {

/**
* Resolves the argument with the given command source stack.
* <p>
* This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with
* the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()} and {@code false}.
*
* @param sourceStack source stack
* @return resolved objective
*/
default Objective resolve(CommandSourceStack sourceStack) throws CommandSyntaxException {
return resolve(sourceStack, Bukkit.getScoreboardManager().getMainScoreboard(), false);
}

/**
* Resolves the argument with the given command source stack.
* <p>
* This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with
* the provided scoreboard and {@code false}.
*
* @param sourceStack source stack
* @param scoreboard scoreboard to get the objective from
* @return resolved objective
*/
default Objective resolve(CommandSourceStack sourceStack, Scoreboard scoreboard) throws CommandSyntaxException {
return resolve(sourceStack, scoreboard, false);
}

/**
* Resolves the argument with the given command source stack.
* <p>
* This method is the same as calling {@link #resolve(CommandSourceStack, Scoreboard, boolean)} with
* the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()}.
*
* @param sourceStack source stack
* @param onlyWritable whether to only retrieve modifiable objectives
* @return resolved objective
*/
default Objective resolve(CommandSourceStack sourceStack, boolean onlyWritable) throws CommandSyntaxException {
return resolve(sourceStack, Bukkit.getScoreboardManager().getMainScoreboard(), onlyWritable);
}

/**
* Resolves the argument with the given command source stack.
*
* @param sourceStack source stack
* @param scoreboard scoreboard to get the objective from
* @param onlyWritable whether to only retrieve modifiable objectives
* @return resolved objective
*/
Objective resolve(CommandSourceStack sourceStack, Scoreboard scoreboard, boolean onlyWritable) throws CommandSyntaxException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.papermc.paper.command.brigadier.argument.resolvers;

import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import org.bukkit.scoreboard.ScoreHolder;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.List;

/**
* An {@link ArgumentResolver} that's capable of resolving
* an argument value using a {@link CommandSourceStack} into a
* list of {@link ScoreHolder}s.
*
* @see ArgumentTypes#scoreHolders()
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface ScoreHolderResolver extends ArgumentResolver<List<ScoreHolder>> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.papermc.paper.command.brigadier.argument.resolvers;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

/**
* A resolver that's capable of resolving
* a {@link Team} value using a {@link Scoreboard} and {@link CommandSourceStack}.
*
* @see ArgumentTypes#team()
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
@NullMarked
public interface TeamResolver {

/**
* Resolves the argument with the given command source stack.
* <p>
* This method is the same as calling {@link #resolve(Scoreboard, CommandSourceStack)} with
* the scoreboard retrieved from {@code Bukkit.getScoreboardManager().getMainScoreboard()}.
*
* @param sourceStack source stack
* @return resolved team
* @see #resolve(Scoreboard, CommandSourceStack)
* @see ScoreboardManager#getMainScoreboard()
*/
default Team resolve(CommandSourceStack sourceStack) throws CommandSyntaxException {
return resolve(Bukkit.getScoreboardManager().getMainScoreboard(), sourceStack);
}

/**
* Resolves the argument with the given scoreboard and command source stack.
*
* @param scoreboard scoreboard to get the team from
* @param sourceStack source stack
* @return resolved team
*/
Team resolve(Scoreboard scoreboard, CommandSourceStack sourceStack) throws CommandSyntaxException;
}
3 changes: 2 additions & 1 deletion paper-api/src/main/java/org/bukkit/OfflinePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.entity.Player;
import org.bukkit.permissions.ServerOperator;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.scoreboard.ScoreHolder;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
Expand All @@ -22,7 +23,7 @@
* player needing to be online.
*/
@NullMarked
public interface OfflinePlayer extends ServerOperator, AnimalTamer, ConfigurationSerializable, io.papermc.paper.persistence.PersistentDataViewHolder, PlayerHeadObjectContents.SkinSource { // Paper - Add Offline PDC API
public interface OfflinePlayer extends ServerOperator, AnimalTamer, ConfigurationSerializable, io.papermc.paper.persistence.PersistentDataViewHolder, PlayerHeadObjectContents.SkinSource, ScoreHolder {

/**
* Checks if this player is currently online
Expand Down
3 changes: 2 additions & 1 deletion paper-api/src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.material.Directional;
import org.bukkit.metadata.Metadatable;
import org.bukkit.persistence.PersistentDataHolder;
import org.bukkit.scoreboard.ScoreHolder;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -37,7 +38,7 @@
* Not all methods are guaranteed to work/may have side effects when
* {@link #isInWorld()} is false.
*/
public interface Entity extends Metadatable, CommandSender, Nameable, PersistentDataHolder, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowEntity>, net.kyori.adventure.sound.Sound.Emitter, DataComponentView { // Paper
public interface Entity extends Metadatable, CommandSender, Nameable, PersistentDataHolder, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowEntity>, net.kyori.adventure.sound.Sound.Emitter, DataComponentView, ScoreHolder { // Paper

/**
* Gets the entity's current position
Expand Down
Loading
Loading