Skip to content

Commit

Permalink
Update to 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Matocolotoe committed Oct 9, 2020
1 parent 32f36a6 commit e8fbc12
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 165 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
groupid=ch.njol
name=skript
version=2.5-beta2
version=2.5
3 changes: 1 addition & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
rootProject.name = 'Skript'
include 'skript-worldguard6'
//include 'skript-worldguard7fawe' // Maven repositories are broken
include 'skript-worldguard6'
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/aliases/AliasesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void put(String key, Variation value) {
}

/**
* Contains all variations. {@link #loadVariedAlias} uses this.
* Contains all variations.
*/
private final Map<String, VariationGroup> variations;

Expand Down Expand Up @@ -210,7 +210,7 @@ public int applyTags(ItemStack stack, Map<String, Object> tags) {
}

/**
* Name of an alias used by {@link #addAlias(String, String, Map, Map)}
* Name of an alias used by {@link #addAlias(AliasName, String, Map, Map)}
* for registration.
*/
public static class AliasName {
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/ch/njol/skript/aliases/ItemData.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.potion.PotionData;
import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -77,6 +79,8 @@ public static class OldItemData {

static final MaterialRegistry materialRegistry;

private static final boolean SPAWN_EGG_META_EXISTS = Skript.classExists("org.bukkit.inventory.meta.SpawnEggMeta");

// Load or create material registry
static {
Gson gson = new GsonBuilder().serializeNulls().create();
Expand Down Expand Up @@ -335,7 +339,7 @@ public MatchQuality matchAlias(ItemData item) {
}
}

/**
/*
* Initially, expect exact match. Lower expectations as new differences
* between items are discovered.
*/
Expand Down Expand Up @@ -427,13 +431,23 @@ private static MatchQuality compareItemMetas(ItemMeta first, ItemMeta second) {

// Potion data
if (second instanceof PotionMeta) {
if (!(first instanceof PotionMeta)) {
return MatchQuality.DIFFERENT; // Second is a potion, first is clearly not
}
// Compare potion type, including extended and level 2 attributes
// Second is a potion, first is clearly not
if (!(first instanceof PotionMeta))
return MatchQuality.DIFFERENT;
return !Objects.equals(first, second) ? MatchQuality.SAME_MATERIAL : quality;
}

// Only check spawn egg data on 1.12 and below. See issue #3167
if (!MaterialRegistry.newMaterials && SPAWN_EGG_META_EXISTS && second instanceof SpawnEggMeta) {
if (!(first instanceof SpawnEggMeta)) {
return MatchQuality.DIFFERENT; // Second is a spawn egg, first is clearly not
}
// Compare spawn egg spawned type
EntityType ourSpawnedType = ((SpawnEggMeta) first).getSpawnedType();
EntityType theirSpawnedType = ((SpawnEggMeta) second).getSpawnedType();
return !Objects.equals(ourSpawnedType, theirSpawnedType) ? MatchQuality.SAME_MATERIAL : quality;
}

return quality;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/aliases/MaterialRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class MaterialRegistry {

private static final boolean newMaterials = Skript.isRunningMinecraft(1, 13);
static final boolean newMaterials = Skript.isRunningMinecraft(1, 13);

/**
* Loads a material registry from an array of strings. New materials will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,60 @@
package ch.njol.skript.conditions;

import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Is Block Redstone Powered")
@Description("Checks if a block is powered by redstone")
@Description("Checks if a block is indirectly or directly powered by redstone")
@Examples({"if clicked block is redstone powered:",
"\tsend \"This block is well-powered by redstone!\""})
"\tsend \"This block is well-powered by redstone!\"",
"if clicked block is indirectly redstone powered:",
"\tsend \"This block is indirectly redstone powered.\""})
@Since("2.5")
public class CondIsBlockRedstonePowered extends PropertyCondition<Block> {
public class CondIsBlockRedstonePowered extends Condition {

static {
register(CondIsBlockRedstonePowered.class, "redstone powered", "blocks");
Skript.registerCondition(CondIsBlockRedstonePowered.class,
"%blocks% (is|are) redstone powered",
"%blocks% (is|are) indirectly redstone powered",
"%blocks% (is|are)(n't| not) redstone powered",
"%blocks% (is|are)(n't| not) indirectly redstone powered");
}

@SuppressWarnings("null")
private Expression<Block> blocks;
private boolean isIndirectlyPowered;

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
blocks = (Expression<Block>) exprs[0];
isIndirectlyPowered = matchedPattern % 2 == 1;
setNegated(matchedPattern > 1);
return true;
}

@Override
public boolean check(Block b) {
return b.isBlockPowered();
public boolean check(Event e) {
return isIndirectlyPowered
? blocks.check(e, Block::isBlockIndirectlyPowered, isNegated())
: blocks.check(e, Block::isBlockPowered, isNegated());
}

@Override
protected String getPropertyName() {
return "redstone powered";
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyCondition.PropertyType.BE, e, debug, blocks, (isIndirectlyPowered ? "indirectly " : "") + "powered");
}

}
80 changes: 66 additions & 14 deletions src/main/java/ch/njol/skript/conditions/CondIsLoaded.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,90 @@
*/
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Direction;
import ch.njol.util.Kleenean;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

@Name("Is Loaded")
@Description("Checks whether or not a chunk/world is loaded")
@Examples("if chunk at {home::%player's uuid%} is loaded:")
@Since("2.3")
public class CondIsLoaded extends PropertyCondition<Object> {
@Description("Checks whether or not a chunk/world is loaded. 'chunk at 1, 1' uses chunk coords, which are location coords divided by 16.")
@Examples({"if chunk at {home::%player's uuid%} is loaded:",
"if chunk 1, 10 in world \"world\" is loaded:",
"if world(\"lobby\") is loaded:"})
@Since("2.3, 2.5 (revamp with chunk at location/coords)")
public class CondIsLoaded extends Condition {

static {
register(CondIsLoaded.class, "loaded", "worlds/chunks");
Skript.registerCondition(CondIsLoaded.class,
"chunk[s] %directions% [%locations%] (is|are)[(1¦(n't| not))] loaded",
"chunk [at] %number%, %number% (in|of) [world] %world% is[(1¦(n't| not))] loaded",
"[world[s]] %worlds% (is|are)[(1¦(n't| not))] loaded");
}

@Nullable
private Expression<Location> locations;
@Nullable
private Expression<Number> x,z;
@Nullable
private Expression<World> world;
private int pattern;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
pattern = matchedPattern;
locations = pattern == 0 ? Direction.combine((Expression<? extends Direction>) exprs[0], (Expression<? extends Location>) exprs[1]) : null;
x = pattern == 1 ? (Expression<Number>) exprs[0] : null;
z = pattern == 1 ? (Expression<Number>) exprs[1] : null;
world = pattern == 1 ? (Expression<World>) exprs[2] : pattern == 2 ? (Expression<World>) exprs[0] : null;
setNegated(parseResult.mark == 1);
return true;
}

@SuppressWarnings("null")
@Override
public boolean check(Object o) {
if (o instanceof Chunk)
return ((Chunk) o).isLoaded();
else if (o instanceof World)
return Bukkit.getWorld(((World) o).getName()) != null;
public boolean check(Event e) {
switch (pattern) {
case 0:
return locations.check(e, location -> {
World world = location.getWorld();
if (world != null)
return world.isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4);
return false;
}, isNegated());
case 1:
return world.check(e, world -> {
Number x = this.x.getSingle(e);
Number z = this.z.getSingle(e);
if (x == null || z == null)
return false;
return world.isChunkLoaded(x.intValue(), z.intValue());
}, isNegated());
case 2:
return world.check(e, world -> Bukkit.getWorld(world.getName()) != null, isNegated());
}
return false;
}

@SuppressWarnings("null")
@Override
protected String getPropertyName() {
return "loaded";
public String toString(@Nullable Event e, boolean d) {
String neg = isNegated() ? " not " : " ";
String chunk = pattern == 0 ? "chunk[s] at " + locations.toString(e, d) + (locations.isSingle() ? " is" : " are") + neg + "loaded" : "";
String chunkC = pattern == 1 ? "chunk (x:" + x.toString(e, d) + ",z:" + z.toString(e, d) + ",w:" + world.toString(e,d) + ") is" + neg + "loaded" : "";
String world = pattern == 2 ? "world[s] " + this.world.toString(e, d) + (this.world.isSingle() ? " is" : " are") + neg + "loaded" : "";
return chunk + chunkC + world;
}

}
23 changes: 17 additions & 6 deletions src/main/java/ch/njol/skript/entity/SimpleEntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.bukkit.entity.Horse;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Husk;
import org.bukkit.entity.Illager;
import org.bukkit.entity.Illusioner;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.ItemFrame;
Expand All @@ -81,6 +82,7 @@
import org.bukkit.entity.Phantom;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Piglin;
import org.bukkit.entity.PiglinBrute;
import org.bukkit.entity.Pillager;
import org.bukkit.entity.PolarBear;
import org.bukkit.entity.Projectile;
Expand All @@ -98,6 +100,7 @@
import org.bukkit.entity.Snowball;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.SpectralArrow;
import org.bukkit.entity.Spellcaster;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Stray;
Expand Down Expand Up @@ -263,6 +266,9 @@ public boolean equals(final @Nullable Object obj) {
types.add(new SimpleEntityDataInfo("vindicator", Vindicator.class));
}

if (Skript.classExists("org.bukkit.entity.Illusioner")) // Added in 1.12
types.add(new SimpleEntityDataInfo("illusioner", Illusioner.class));

if (Skript.isRunningMinecraft(1, 13)) { // More subtypes, more supertypes - changes needed
types.add(new SimpleEntityDataInfo("dolphin", Dolphin.class));
types.add(new SimpleEntityDataInfo("phantom", Phantom.class));
Expand All @@ -278,21 +284,19 @@ public boolean equals(final @Nullable Object obj) {
if (Skript.isRunningMinecraft(1, 14)) {
types.add(new SimpleEntityDataInfo("pillager", Pillager.class));
types.add(new SimpleEntityDataInfo("ravager", Ravager.class));

types.add(new SimpleEntityDataInfo("wandering trader", WanderingTrader.class));
types.add(new SimpleEntityDataInfo("raider", Raider.class, true));
}

if (Skript.isRunningMinecraft(1, 16)) {
types.add(new SimpleEntityDataInfo("piglin", Piglin.class));
types.add(new SimpleEntityDataInfo("hoglin", Hoglin.class));
types.add(new SimpleEntityDataInfo("zoglin", Zoglin.class));
types.add(new SimpleEntityDataInfo("strider", Strider.class));

}
if (Skript.classExists("org.bukkit.entity.Illusioner")) {
types.add(new SimpleEntityDataInfo("illusioner", Illusioner.class));
}

if (Skript.classExists("org.bukkit.entity.PiglinBrute")) // Added in 1.16.2
types.add(new SimpleEntityDataInfo("piglin brute", PiglinBrute.class));

// Register zombie after Husk and Drowned to make sure both work
types.add(new SimpleEntityDataInfo("zombie", Zombie.class));

Expand All @@ -315,6 +319,13 @@ public boolean equals(final @Nullable Object obj) {
types.add(new SimpleEntityDataInfo("fish" , Fish.class, true));

types.add(new SimpleEntityDataInfo("any fireball", Fireball.class, true));

if (Skript.classExists("org.bukkit.entity.Illager")) { // Introduced in Spigot 1.12
types.add(new SimpleEntityDataInfo("illager", Illager.class, true));
types.add(new SimpleEntityDataInfo("spellcaster", Spellcaster.class, true));
}
if (Skript.classExists("org.bukkit.entity.Raider")) // Introduced in Spigot 1.14
types.add(new SimpleEntityDataInfo("raider", Raider.class, true));
}

static {
Expand Down
Loading

0 comments on commit e8fbc12

Please # to comment.