Skip to content

Commit

Permalink
Merge branch 'dev/patch' into dev/feature
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed Jun 16, 2024
2 parents 1743000 + 7fc699e commit 7dcf34a
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 100 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel=true

groupid=ch.njol
name=skript
version=2.8.6
version=2.8.7
jarName=Skript.jar
testEnv=java21/paper-1.20.6
testEnvJavaVersion=21
32 changes: 6 additions & 26 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package ch.njol.skript.classes.data;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -664,34 +661,17 @@ public LivingEntity[] get(AreaEffectCloudApplyEvent event) {
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(AreaEffectCloudApplyEvent.class, PotionEffectType.class, new Getter<PotionEffectType, AreaEffectCloudApplyEvent>() {
@Nullable
private final MethodHandle BASE_POTION_DATA_HANDLE;

{
MethodHandle basePotionDataHandle = null;
if (Skript.methodExists(AreaEffectCloud.class, "getBasePotionData")) {
try {
basePotionDataHandle = MethodHandles.lookup().findVirtual(AreaEffectCloud.class, "getBasePotionData", MethodType.methodType(PotionData.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
Skript.exception(e, "Failed to load legacy potion data support. Potions may not work as expected.");
}
}
BASE_POTION_DATA_HANDLE = basePotionDataHandle;
}

private final boolean HAS_POTION_TYPE_METHOD = Skript.methodExists(AreaEffectCloud.class, "getBasePotionType");
@Override
@Nullable
public PotionEffectType get(AreaEffectCloudApplyEvent e) {
if (BASE_POTION_DATA_HANDLE != null) {
try {
return ((PotionData) BASE_POTION_DATA_HANDLE.invoke(e.getEntity())).getType().getEffectType();
} catch (Throwable ex) {
throw Skript.exception(ex, "An error occurred while trying to invoke legacy area effect cloud potion effect support.");
}
} else {
// TODO needs to be reworked to support multiple values (there can be multiple potion effects)
if (HAS_POTION_TYPE_METHOD) {
PotionType base = e.getEntity().getBasePotionType();
if (base != null) // TODO this is deprecated... this should become a multi-value event value
if (base != null)
return base.getEffectType();
} else {
return e.getEntity().getBasePotionData().getType().getEffectType();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ public String toVariableNameString(final Experience xp) {
.usage(VisualEffects.getAllNames())
.since("2.1")
.user("(visual|particle) effects?")
.after("itemtype")
.parser(new Parser<VisualEffect>() {
@Override
@Nullable
Expand Down
36 changes: 27 additions & 9 deletions src/main/java/ch/njol/skript/entity/SimpleEntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.ArrayList;
import java.util.List;

import ch.njol.util.Kleenean;
import org.bukkit.World;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Allay;
import org.bukkit.entity.Animals;
Expand Down Expand Up @@ -155,15 +157,13 @@ public final static class SimpleEntityDataInfo {
final String codeName;
final Class<? extends Entity> c;
final boolean isSupertype;
final Kleenean allowSpawning;

SimpleEntityDataInfo(final String codeName, final Class<? extends Entity> c) {
this(codeName, c, false);
}

SimpleEntityDataInfo(final String codeName, final Class<? extends Entity> c, final boolean isSupertype) {
SimpleEntityDataInfo(String codeName, Class<? extends Entity> c, boolean isSupertype, Kleenean allowSpawning) {
this.codeName = codeName;
this.c = c;
this.isSupertype = isSupertype;
this.allowSpawning = allowSpawning;
}

@Override
Expand Down Expand Up @@ -191,11 +191,18 @@ public boolean equals(final @Nullable Object obj) {
private final static List<SimpleEntityDataInfo> types = new ArrayList<>();

private static void addSimpleEntity(String codeName, Class<? extends Entity> entityClass) {
types.add(new SimpleEntityDataInfo(codeName, entityClass));
addSimpleEntity(codeName, entityClass, Kleenean.UNKNOWN);
}

/**
* @param allowSpawning Whether to override the default {@link #canSpawn(World)} behavior and allow this entity to be spawned.
*/
private static void addSimpleEntity(String codeName, Class<? extends Entity> entityClass, Kleenean allowSpawning) {
types.add(new SimpleEntityDataInfo(codeName, entityClass, false, allowSpawning));
}

private static void addSuperEntity(String codeName, Class<? extends Entity> entityClass) {
types.add(new SimpleEntityDataInfo(codeName, entityClass, true));
types.add(new SimpleEntityDataInfo(codeName, entityClass, true, Kleenean.UNKNOWN));
}
static {
// Simple Entities
Expand Down Expand Up @@ -238,7 +245,9 @@ private static void addSuperEntity(String codeName, Class<? extends Entity> enti
addSimpleEntity("witch", Witch.class);
addSimpleEntity("wither", Wither.class);
addSimpleEntity("wither skull", WitherSkull.class);
addSimpleEntity("firework", Firework.class);
// bukkit marks fireworks as not spawnable
// see https://hub.spigotmc.org/jira/browse/SPIGOT-7677
addSimpleEntity("firework", Firework.class, Kleenean.TRUE);
addSimpleEntity("endermite", Endermite.class);
addSimpleEntity("armor stand", ArmorStand.class);
addSimpleEntity("shulker", Shulker.class);
Expand Down Expand Up @@ -449,7 +458,16 @@ protected boolean equals_i(final EntityData<?> obj) {
final SimpleEntityData other = (SimpleEntityData) obj;
return info.equals(other.info);
}


@Override
public boolean canSpawn(@Nullable World world) {
if (info.allowSpawning.isUnknown()) // unspecified, refer to default behavior
return super.canSpawn(world);
if (world == null)
return false;
return info.allowSpawning.isTrue();
}

@Override
public Fields serialize() throws NotSerializableException {
final Fields f = super.serialize();
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/ch/njol/skript/expressions/ExprStringCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,28 @@ public Class<? extends String> getReturnType() {
}

@Override
public String toString(@Nullable Event e, boolean debug) {
public String toString(@Nullable Event event, boolean debug) {
String mode = "";
switch (type) {
case 0: // Basic Case Change
return (casemode == 1) ? "uppercase" : "lowercase";
mode = (casemode == 1) ? "uppercase" : "lowercase";
break;
case 1: // Proper Case
return ((casemode == 3) ? "strict" : "lenient") + " proper case";
mode = ((casemode == 3) ? "strict" : "lenient") + " proper case";
break;
case 2: // Camel Case
return ((casemode == 3) ? "strict" : "lenient") + " camel case";
mode = ((casemode == 3) ? "strict" : "lenient") + " camel case";
break;
case 3: // Pascal Case
return ((casemode == 3) ? "strict" : "lenient") + " pascal case";
mode = ((casemode == 3) ? "strict" : "lenient") + " pascal case";
break;
case 4: // Snake Case
return ((casemode == 0) ? "" : ((casemode == 1)) ? "upper " : "lower ") + "snake case";
mode = ((casemode == 0) ? "" : ((casemode == 1)) ? "upper " : "lower ") + "snake case";
break;
case 5: // Kebab Case
return ((casemode == 0) ? "" : ((casemode == 1)) ? "upper " : "lower ") + "kebab case";
mode = ((casemode == 0) ? "" : ((casemode == 1)) ? "upper " : "lower ") + "kebab case";
}
return ""; // Shouldn't reach here anyways
return mode + " " + expr.toString(event, debug);
}

@SuppressWarnings("null")
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/ch/njol/skript/structures/StructCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
@Since("1.0")
public class StructCommand extends Structure {

// Paper versions with the new command system need a delay before syncing commands or a CME will occur.
private static final boolean DELAY_COMMAND_SYNCING = Skript.classExists("io.papermc.paper.command.brigadier.Commands");

public static final Priority PRIORITY = new Priority(500);

private static final Pattern COMMAND_PATTERN = Pattern.compile("(?i)^command\\s+/?(\\S+)\\s*(\\s+(.+))?$");
Expand Down Expand Up @@ -318,7 +321,7 @@ public boolean load() {

@Override
public boolean postLoad() {
attemptCommandSync();
scheduleCommandSync();
return true;
}

Expand All @@ -331,20 +334,28 @@ public void unload() {

@Override
public void postUnload() {
attemptCommandSync();
scheduleCommandSync();
}

private void attemptCommandSync() {
private void scheduleCommandSync() {
if (SYNC_COMMANDS.get()) {
SYNC_COMMANDS.set(false);
if (CommandReloader.syncCommands(Bukkit.getServer())) {
Skript.debug("Commands synced to clients");
if (DELAY_COMMAND_SYNCING) {
Bukkit.getScheduler().runTask(Skript.getInstance(), this::forceCommandSync);
} else {
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
forceCommandSync();
}
}
}

private void forceCommandSync() {
if (CommandReloader.syncCommands(Bukkit.getServer())) {
Skript.debug("Commands synced to clients");
} else {
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
}
}

@Override
public Priority getPriority() {
return PRIORITY;
Expand Down
41 changes: 13 additions & 28 deletions src/main/java/ch/njol/skript/util/PotionEffectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package ch.njol.skript.util;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -346,20 +343,7 @@ else if (HAS_SUSPICIOUS_META && meta instanceof SuspiciousStewMeta)
itemType.setItemMeta(meta);
}

@Nullable
private static final MethodHandle BASE_POTION_DATA_HANDLE;

static {
MethodHandle basePotionDataHandle = null;
if (Skript.methodExists(PotionMeta.class, "getBasePotionData")) {
try {
basePotionDataHandle = MethodHandles.lookup().findVirtual(PotionMeta.class, "getBasePotionData", MethodType.methodType(PotionData.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
Skript.exception(e, "Failed to load legacy potion data support. Potions may not work as expected.");
}
}
BASE_POTION_DATA_HANDLE = basePotionDataHandle;
}
private static final boolean HAS_POTION_TYPE_METHOD = Skript.methodExists(PotionMeta.class, "hasBasePotionType");

/**
* Get all the PotionEffects of an ItemType
Expand All @@ -374,21 +358,22 @@ public static List<PotionEffect> getEffects(ItemType itemType) {
ItemMeta meta = itemType.getItemMeta();
if (meta instanceof PotionMeta) {
PotionMeta potionMeta = ((PotionMeta) meta);
effects.addAll(potionMeta.getCustomEffects());
if (BASE_POTION_DATA_HANDLE != null) {
try {
effects.addAll(PotionDataUtils.getPotionEffects((PotionData) BASE_POTION_DATA_HANDLE.invoke(meta)));
} catch (Throwable e) {
throw Skript.exception(e, "An error occurred while trying to invoke legacy potion data support.");
if (potionMeta.hasCustomEffects())
effects.addAll(potionMeta.getCustomEffects());
if (HAS_POTION_TYPE_METHOD) {
if (potionMeta.hasBasePotionType()) {
//noinspection ConstantConditions - checked via hasBasePotionType
effects.addAll(potionMeta.getBasePotionType().getPotionEffects());
}
} else { // use deprecated method
PotionData data = potionMeta.getBasePotionData();
if (data != null) {
effects.addAll(PotionDataUtils.getPotionEffects(data));
}
} else if (potionMeta.hasBasePotionType()) {
//noinspection ConstantConditions - checked via hasBasePotionType
effects.addAll(potionMeta.getBasePotionType().getPotionEffects());
}

} else if (HAS_SUSPICIOUS_META && meta instanceof SuspiciousStewMeta)
effects.addAll(((SuspiciousStewMeta) meta).getCustomEffects());
return effects;
}

}
Loading

0 comments on commit 7dcf34a

Please sign in to comment.