Skip to content

Commit

Permalink
Merge branch 'dev/feature' into cancelled-events-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Apr 7, 2024
2 parents 0ed7f6e + e454a10 commit e52234c
Show file tree
Hide file tree
Showing 27 changed files with 630 additions and 151 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.3
version=2.8.4
jarName=Skript.jar
testEnv=java17/paper-1.20.4
testEnvJavaVersion=17
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = 'Skript'
19 changes: 14 additions & 5 deletions src/main/java/ch/njol/skript/aliases/ItemData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemFlag;
Expand Down Expand Up @@ -188,15 +189,23 @@ public ItemData(ItemStack stack) {
this(stack, BlockCompat.INSTANCE.getBlockValues(stack));
this.itemForm = true;
}

public ItemData(BlockState block) {
this.type = ItemUtils.asItem(block.getType());

/**
* @deprecated Use {@link ItemData#ItemData(BlockData)} instead
*/
@Deprecated
public ItemData(BlockState blockState) {
this(blockState.getBlockData());
}

public ItemData(BlockData blockData) {
this.type = blockData.getMaterial();
this.stack = new ItemStack(type);
this.blockValues = BlockCompat.INSTANCE.getBlockValues(block);
this.blockValues = BlockCompat.INSTANCE.getBlockValues(blockData);
}

public ItemData(Block block) {
this(block.getState());
this(block.getBlockData());
}

/**
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/ch/njol/skript/aliases/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -184,10 +185,16 @@ public ItemType(ItemStack i) {
add_(new ItemData(i));
}

public ItemType(BlockState b) {
// amount = 1;
add_(new ItemData(b));
// TODO metadata - spawners, skulls, etc.
/**
* @deprecated Use {@link #ItemType(BlockData)} instead
*/
@Deprecated
public ItemType(BlockState blockState) {
this(blockState.getBlockData());
}

public ItemType(BlockData blockData) {
add_(new ItemData(blockData));
}

/**
Expand All @@ -211,7 +218,7 @@ public void setTo(ItemType i) {
}

public ItemType(Block block) {
this(block.getState());
this(block.getBlockData());
}

/**
Expand Down Expand Up @@ -272,17 +279,25 @@ public boolean isOfType(@Nullable ItemStack item) {
return isOfType(new ItemData(item));
}

public boolean isOfType(@Nullable BlockState block) {
if (block == null)
/**
* @deprecated Use {@link #isOfType(BlockData)} instead
*/
@Deprecated
public boolean isOfType(@Nullable BlockState blockState) {
return blockState != null && isOfType(blockState.getBlockData());
}

public boolean isOfType(@Nullable BlockData blockData) {
if (blockData == null)
return isOfType(Material.AIR, null);

return isOfType(new ItemData(block));
return isOfType(new ItemData(blockData));
}

public boolean isOfType(@Nullable Block block) {
if (block == null)
return isOfType(Material.AIR, null);
return isOfType(block.getState());
return isOfType(block.getBlockData());
}

public boolean isOfType(ItemData type) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public static Material asBlock(Material type) {
return null;
}
}

/**
* Gets an item material corresponding to given block material, which might
* be the given material.
* @param type Material.
* @return Item version of material or null.
* @deprecated This just returns itself and has no use
*/
@Deprecated
public static Material asItem(Material type) {
// Assume (naively) that all types are valid items
return type;
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/ch/njol/skript/bukkitutil/block/BlockCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.FallingBlock;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemFlags;

/**
Expand All @@ -42,13 +42,15 @@ public interface BlockCompat {
BlockCompat INSTANCE = new NewBlockCompat();

static final BlockSetter SETTER = INSTANCE.getSetter();

/**
* Gets block values from a block state. They can be compared to other
* values if needed, but cannot be used to retrieve any other data.
* @param block Block state to retrieve value from.
* @return Block values.
* @deprecated Use {@link #getBlockValues(BlockData)} instead
*/
@Deprecated
@Nullable
BlockValues getBlockValues(BlockState block);

Expand All @@ -60,8 +62,11 @@ public interface BlockCompat {
*/
@Nullable
default BlockValues getBlockValues(Block block) {
return getBlockValues(block.getState());
return getBlockValues(block.getBlockData());
}

@Nullable
BlockValues getBlockValues(BlockData blockData);

/**
* Gets block values from a item stack. They can be compared to other values
Expand All @@ -71,17 +76,19 @@ default BlockValues getBlockValues(Block block) {
*/
@Nullable
BlockValues getBlockValues(ItemStack stack);

/**
* Creates a block state from a falling block.
* @param entity Falling block entity
* @return Block state.
* @deprecated This shouldn't be used
*/
@Deprecated
BlockState fallingBlockToState(FallingBlock entity);

@Nullable
default BlockValues getBlockValues(FallingBlock entity) {
return getBlockValues(fallingBlockToState(entity));
return getBlockValues(entity.getBlockData());
}

/**
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,23 @@ public void sendBlockChange(Player player, Location location, Material type, @Nu
}

private NewBlockSetter setter = new NewBlockSetter();


/**
* @deprecated Use {@link #getBlockValues(BlockData)} instead
*/
@Deprecated
@Nullable
@Override
public BlockValues getBlockValues(BlockState block) {
// If block doesn't have useful data, data field of type is MaterialData
if (block.getType().isBlock())
return new NewBlockValues(block.getType(), block.getBlockData(), false);
return null;
public BlockValues getBlockValues(BlockState blockState) {
return getBlockValues(blockState.getBlockData());
}


@Nullable
@Override
public BlockValues getBlockValues(BlockData blockData) {
return new NewBlockValues(blockData.getMaterial(), blockData, false);
}

@Override
@Nullable
public BlockValues getBlockValues(ItemStack stack) {
Expand All @@ -345,15 +352,16 @@ public BlockValues getBlockValues(ItemStack stack) {
}
return null;
}

@Override
public BlockSetter getSetter() {
return setter;
}

@Deprecated
@Override
public BlockState fallingBlockToState(FallingBlock entity) {
BlockState state = entity.getWorld().getBlockAt(0, 0, 0).getState();
BlockState state = entity.getLocation().getBlock().getState();
state.setBlockData(entity.getBlockData());
return state;
}
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,28 @@ public Location[] execute(FunctionEvent<?> e, Object[][] params) {
}
}.description("Creates a location from a world and 3 coordinates, with an optional yaw and pitch.",
"If for whatever reason the world is not found, it will fallback to the server's main world.")
.examples("location(0, 128, 0)",
"location(player's x-coordinate, player's y-coordinate + 5, player's z-coordinate, player's world, 0, 90)",
"location(0, 64, 0, world \"world_nether\")",
"location(100, 110, -145, world(\"my_custom_world\"))")
.examples("# TELEPORTING",
"teleport player to location(1,1,1, world \"world\")",
"teleport player to location(1,1,1, world \"world\", 100, 0)",
"teleport player to location(1,1,1, world \"world\", yaw of player, pitch of player)",
"teleport player to location(1,1,1, world of player)",
"teleport player to location(1,1,1, world(\"world\"))",
"teleport player to location({_x}, {_y}, {_z}, {_w}, {_yaw}, {_pitch})",
"# SETTING BLOCKS",
"set block at location(1,1,1, world \"world\") to stone",
"set block at location(1,1,1, world \"world\", 100, 0) to stone",
"set block at location(1,1,1, world of player) to stone",
"set block at location(1,1,1, world(\"world\")) to stone",
"set block at location({_x}, {_y}, {_z}, {_w}) to stone",
"# USING VARIABLES",
"set {_l1} to location(1,1,1)",
"set {_l2} to location(10,10,10)",
"set blocks within {_l1} and {_l2} to stone",
"if player is within {_l1} and {_l2}:",
"# OTHER",
"kill all entities in radius 50 around location(1,65,1, world \"world\")",
"delete all entities in radius 25 around location(50,50,50, world \"world_nether\")",
"ignite all entities in radius 25 around location(1,1,1, world of player)")
.since("2.2"));

Functions.registerFunction(new SimpleJavaFunction<Date>("date", new Parameter[] {
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsPathfinding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
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;

import com.destroystokyo.paper.entity.Pathfinder;
import com.destroystokyo.paper.entity.Pathfinder.PathResult;

import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

@Name("Is Pathfinding")
@Description({
"Checks whether living entities are pathfinding.",
"Can only be a living entity that is a Mob."
})
@Examples({
"make {_entity} pathfind to {_location} at speed 2",
"while {_entity} is pathfinding",
"\twait a second",
"launch flickering trailing burst firework colored red at location of {_entity}",
"subtract 10 from {defence::tower::health}",
"clear entity within {_entity}"
})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class CondIsPathfinding extends Condition {

static {
if (Skript.classExists("org.bukkit.entity.Mob") && Skript.methodExists(Mob.class, "getPathfinder"))
PropertyCondition.register(CondIsPathfinding.class, "pathfinding [to[wards] %-livingentity/location%]", "livingentities");
}

private Expression<LivingEntity> entities;
private Expression<?> target;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<LivingEntity>) expressions[0];
target = expressions[1];
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(Event event) {
return entities.check(event, entity -> {
if (!(entity instanceof Mob))
return false;
Pathfinder pathfind = ((Mob) entity).getPathfinder();
if (target == null)
return pathfind.hasPath();

PathResult current = pathfind.getCurrentPath();
Object target = this.target.getSingle(event);
if (target == null || current == null)
return false;
Location location = current.getFinalPoint();
if (target instanceof Location)
return location.equals(target);
assert target instanceof LivingEntity;
LivingEntity entityTarget = (LivingEntity) target;
return location.distance(((Mob) entityTarget).getLocation()) < 1;
}, isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return PropertyCondition.toString(this, PropertyType.BE, event, debug, entities, "pathfinding" +
target == null ? "" : " to " + target.toString(event, debug));
}

}
Loading

0 comments on commit e52234c

Please sign in to comment.