Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump io.papermc.paper:paper-api from 1.20.1-R0.1-SNAPSHOT to 1.20.2-R0.1-SNAPSHOT #6072

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.0'

implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.20.1-R0.1-SNAPSHOT'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.20.2-R0.1-SNAPSHOT'
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
implementation group: 'com.sk89q.worldguard', name: 'worldguard-legacy', version: '7.0.0-SNAPSHOT'
Expand Down Expand Up @@ -246,7 +246,7 @@ void createTestTask(String name, String desc, String environments, int javaVersi
}
}

def latestEnv = 'java17/paper-1.20.1.json'
def latestEnv = 'java17/paper-1.20.2.json'
def latestJava = 17
def oldestJava = 8

Expand Down Expand Up @@ -389,7 +389,6 @@ task nightlyRelease(type: ShadowJar) {

javadoc {
dependsOn nightlyResources

source = sourceSets.main.allJava

exclude("ch/njol/skript/conditions/**")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ groupid=ch.njol
name=skript
version=2.7.1
jarName=Skript.jar
testEnv=java17/paper-1.20.1
testEnv=java17/paper-1.20.2
testEnvJavaVersion=17
157 changes: 112 additions & 45 deletions src/main/java/ch/njol/skript/entity/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@
*/
package ch.njol.skript.entity;

import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.RegionAccessor;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAPIException;
import ch.njol.skript.bukkitutil.EntityUtils;
Expand All @@ -44,37 +66,40 @@
import ch.njol.util.coll.iterator.SingleItemIterator;
import ch.njol.yggdrasil.Fields;
import ch.njol.yggdrasil.YggdrasilSerializable.YggdrasilExtendedSerializable;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* @author Peter Güttinger
*/
@SuppressWarnings("rawtypes")
public abstract class EntityData<E extends Entity> implements SyntaxElement, YggdrasilExtendedSerializable {// TODO extended horse support, zombie villagers // REMIND unit

/*
* In 1.20.2 Spigot deprecated org.bukkit.util.Consumer.
* From the class header: "API methods which use this consumer will be remapped to Java's consumer at runtime, resulting in an error."
* But in 1.13-1.16 the only way to use a consumer was World#spawn(Location, Class, org.bukkit.util.Consumer).
*/
@Nullable
protected static Method WORLD_1_13_CONSUMER_METHOD;
protected static final boolean WORLD_1_13_CONSUMER = Skript.methodExists(World.class, "spawn", Location.class, Class.class, org.bukkit.util.Consumer.class);

@Nullable
protected static Method WORLD_1_17_CONSUMER_METHOD;
protected static boolean WORLD_1_17_CONSUMER;

static {
try {
if (WORLD_1_13_CONSUMER) {
WORLD_1_13_CONSUMER_METHOD = World.class.getDeclaredMethod("spawn", Location.class, Class.class, org.bukkit.util.Consumer.class);
} else if (Skript.classExists("org.bukkit.RegionAccessor")) {
if (WORLD_1_17_CONSUMER = Skript.methodExists(RegionAccessor.class, "spawn", Location.class, Class.class, org.bukkit.util.Consumer.class))
WORLD_1_17_CONSUMER_METHOD = RegionAccessor.class.getDeclaredMethod("spawn", Location.class, Class.class, org.bukkit.util.Consumer.class);
}
} catch (NoSuchMethodException | SecurityException ignored) { /* We already checked if the method exists */ }
}

public final static String LANGUAGE_NODE = "entities";

public final static Message m_age_pattern = new Message(LANGUAGE_NODE + ".age pattern");
public final static Adjective m_baby = new Adjective(LANGUAGE_NODE + ".age adjectives.baby"),
m_adult = new Adjective(LANGUAGE_NODE + ".age adjectives.adult");

// must be here to be initialised before 'new SimpleLiteral' is called in the register block below
private final static List<EntityDataInfo<EntityData<?>>> infos = new ArrayList<>();

Expand Down Expand Up @@ -312,7 +337,7 @@ public final boolean init(final Expression<?>[] exprs, final int matchedPattern,

/**
* Returns the super type of this entity data, e.g. 'wolf' for 'angry wolf'.
*
*
* @return The supertype of this entity data. Must not be null.
*/
public abstract EntityData getSuperType();
Expand Down Expand Up @@ -401,7 +426,7 @@ public static EntityDataInfo<?> getInfo(final String codeName) {

/**
* Prints errors.
*
*
* @param s String with optional indefinite article at the beginning
* @return The parsed entity data
*/
Expand All @@ -416,23 +441,17 @@ public static EntityData<?> parse(String s) {

/**
* Prints errors.
*
*
* @param s
* @return The parsed entity data
*/
@SuppressWarnings("null")
@Nullable
public static EntityData<?> parseWithoutIndefiniteArticle(String s) {
if (!REGEX_PATTERN.matcher(s).matches())
return null;
Iterator<EntityDataInfo<EntityData<?>>> it = infos.iterator();
return SkriptParser.parseStatic(s, it, null);
}

@Nullable
public final E spawn(Location loc) {
return spawn(loc, null);
}

private E apply(E entity) {
if (baby.isTrue()) {
Expand All @@ -444,24 +463,54 @@ private E apply(E entity) {
return entity;
}

/**
* Spawn this entity data at a location.
*
* @param location The {@link Location} to spawn the entity at.
* @return The Entity object that is spawned.
*/
@Nullable
public final E spawn(Location location) {
return spawn(location, (Consumer<E>) null);
}

/**
* Spawn this entity data at a location.
* The consumer allows for modiciation to the entity before it actually gets spawned.
* <p>
* Bukkit's own {@link org.bukkit.util.Consumer} is deprecated.
* Use {@link #spawn(Location, Consumer)}
*
* @param location The {@link Location} to spawn the entity at.
* @param consumer A {@link Consumer} to apply the entity changes to.
* @return The Entity object that is spawned.
*/
@Nullable
@Deprecated
@SuppressWarnings("deprecation")
public E spawn(Location location, org.bukkit.util.@Nullable Consumer<E> consumer) {
return spawn(location, (Consumer<E>) e -> consumer.accept(e));
}

/**
* Spawn this entity data at a location.
* The consumer allows for modiciation to the entity before it actually gets spawned.
*
* @param location The {@link Location} to spawn the entity at.
* @param consumer A {@link Consumer} to apply the entity changes to.
* @return The Entity object that is spawned.
*/
@Nullable
@SuppressWarnings("unchecked")
public E spawn(Location location, @Nullable Consumer<E> consumer) {
assert location != null;
try {
if (consumer != null) {
return location.getWorld().spawn(location, (Class<E>) getType(), e -> consumer.accept(apply(e)));
} else {
return apply(location.getWorld().spawn(location, getType()));
}
} catch (IllegalArgumentException e) {
if (Skript.testing())
Skript.error("Can't spawn " + getType().getName());
return null;
if (consumer != null) {
return EntityData.spawn(location, getType(), e -> consumer.accept(this.apply(e)));
} else {
return apply(location.getWorld().spawn(location, getType()));
}
}
@SuppressWarnings({"null", "unchecked"})

@SuppressWarnings("unchecked")
public E[] getAll(final World... worlds) {
assert worlds != null && worlds.length > 0 : Arrays.toString(worlds);
final List<E> list = new ArrayList<>();
Expand Down Expand Up @@ -598,4 +647,22 @@ protected boolean deserialize(final String s) {
return false;
}

@SuppressWarnings({"unchecked", "deprecation"})
protected static <E extends Entity> @Nullable E spawn(Location location, Class<E> type, Consumer<E> consumer) {
try {
if (WORLD_1_17_CONSUMER) {
return (@Nullable E) WORLD_1_17_CONSUMER_METHOD.invoke(location.getWorld(), location, type,
(org.bukkit.util.Consumer<E>) consumer::accept);
} else if (WORLD_1_13_CONSUMER) {
return (@Nullable E) WORLD_1_13_CONSUMER_METHOD.invoke(location.getWorld(), location, type,
(org.bukkit.util.Consumer<E>) consumer::accept);
}
} catch (InvocationTargetException | IllegalAccessException e) {
if (Skript.testing())
Skript.exception(e, "Can't spawn " + type.getName());
return null;
}
return location.getWorld().spawn(location, type, consumer);
}

}
8 changes: 3 additions & 5 deletions src/main/java/ch/njol/skript/entity/FallingBlockData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
package ch.njol.skript.entity;

import java.util.Arrays;

import java.util.Iterator;
import java.util.function.Consumer;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
Expand All @@ -42,9 +43,6 @@
import org.skriptlang.skript.lang.converter.Converters;
import ch.njol.util.coll.CollectionUtils;

/**
* @author Peter Güttinger
*/
public class FallingBlockData extends EntityData<FallingBlock> {
static {
EntityData.register(FallingBlockData.class, "falling block", FallingBlock.class, "falling block");
Expand Down Expand Up @@ -117,11 +115,11 @@ public FallingBlock spawn(Location loc, @Nullable Consumer<FallingBlock> consume
ItemType t = types == null ? new ItemType(Material.STONE) : CollectionUtils.getRandom(types);
assert t != null;
Material material = t.getMaterial();

if (!material.isBlock()) {
assert false : t;
return null;
}

FallingBlock fallingBlock = loc.getWorld().spawnFallingBlock(loc, material.createBlockData());
if (consumer != null)
consumer.accept(fallingBlock);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/ch/njol/skript/entity/ThrownPotionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
package ch.njol.skript.entity;

import java.util.Arrays;
import java.util.function.Consumer;

import org.bukkit.Location;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
Expand All @@ -40,9 +40,6 @@
import org.skriptlang.skript.lang.converter.Converters;
import ch.njol.util.coll.CollectionUtils;

/**
* @author Peter Güttinger
*/
public class ThrownPotionData extends EntityData<ThrownPotion> {
static {
EntityData.register(ThrownPotionData.class, "thrown potion", ThrownPotion.class, "thrown potion");
Expand Down Expand Up @@ -103,9 +100,9 @@ protected boolean match(ThrownPotion entity) {
return true;
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public @Nullable ThrownPotion spawn(Location loc, @Nullable Consumer<ThrownPotion> consumer) {
@SuppressWarnings({"unchecked", "rawtypes"})
public @Nullable ThrownPotion spawn(Location location, @Nullable Consumer<ThrownPotion> consumer) {
ItemType t = CollectionUtils.getRandom(types);
assert t != null;
ItemStack i = t.getRandom();
Expand All @@ -114,11 +111,14 @@ protected boolean match(ThrownPotion entity) {

Class<ThrownPotion> thrownPotionClass = (Class) (LINGER_POTION.isOfType(i) ? LINGERING_POTION_ENTITY_CLASS : ThrownPotion.class);
ThrownPotion potion;
if (consumer != null)
potion = loc.getWorld().spawn(loc, thrownPotionClass, consumer);
else
potion = loc.getWorld().spawn(loc, thrownPotionClass);
if (consumer != null) {
potion = EntityData.spawn(location, thrownPotionClass, consumer);
} else {
potion = location.getWorld().spawn(location, thrownPotionClass);
}

if (potion == null)
return null;
potion.setItem(i);
return potion;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/ch/njol/skript/entity/XpOrbData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
*/
package ch.njol.skript.entity;

import java.util.function.Consumer;

import org.bukkit.Location;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.localization.ArgsMessage;

/**
* @author Peter Güttinger
*/
public class XpOrbData extends EntityData<ExperienceOrb> {
static {
EntityData.register(XpOrbData.class, "xporb", ExperienceOrb.class, "xp-orb");
Expand Down
Loading