Skip to content

Commit

Permalink
Merge branch 'dev/feature' into feature/equip-items
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky authored Apr 5, 2024
2 parents a39277d + e454a10 commit 0b78b7a
Show file tree
Hide file tree
Showing 93 changed files with 1,414 additions and 362 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# .git-blame-ignore-revs

# cleanup lang package - mostly renaming variables
98abf5d7773df11c65d66e4e9485d0f1e3ef8821
2 changes: 1 addition & 1 deletion .github/workflows/java-17-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-8-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/junit-17-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/junit-8-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
- name: Push release documentation
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Release Docs Bot
git_email: releasedocs@skriptlang.org
Expand Down Expand Up @@ -69,6 +68,7 @@ jobs:
uses: ./skript/.github/workflows/docs/generate-docs
with:
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
is_release: true
- name: Push archive documentation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
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'
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.1', {
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.3', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
}

Expand Down
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.0-pre2
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'
2 changes: 1 addition & 1 deletion skript-aliases
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,15 @@ public void onPluginDisable(PluginDisableEvent event) {
try {
// Spigot removed the mapping for this method in 1.18, so its back to obfuscated method
// 1.19 mapping is u and 1.18 is v
String isRunningMethod = Skript.isRunningMinecraft(1, 19) ? "u" : Skript.isRunningMinecraft(1, 18) ? "v" :"isRunning";
String isRunningMethod = "isRunning";

if (Skript.isRunningMinecraft(1, 20)) {
isRunningMethod = "v";
} else if (Skript.isRunningMinecraft(1, 19)) {
isRunningMethod = "u";
} else if (Skript.isRunningMinecraft(1, 18)) {
isRunningMethod = "v";
}
IS_RUNNING = MC_SERVER.getClass().getMethod(isRunningMethod);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/ch/njol/skript/aliases/AliasesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.Map;

import ch.njol.skript.Skript;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -42,6 +44,9 @@
* Provides aliases on Bukkit/Spigot platform.
*/
public class AliasesProvider {

// not supported on Spigot versions older than 1.18
private static final boolean FASTER_SET_SUPPORTED = Skript.classExists("it.unimi.dsi.fastutil.objects.ObjectOpenHashSet");

/**
* When an alias is not found, it will requested from this provider.
Expand Down Expand Up @@ -173,7 +178,12 @@ public AliasesProvider(int expectedCount, @Nullable AliasesProvider parent) {
this.aliases = new HashMap<>(expectedCount);
this.variations = new HashMap<>(expectedCount / 20);
this.aliasesMap = new AliasesMap();
this.materials = new ObjectOpenHashSet<>();

if (FASTER_SET_SUPPORTED) {
this.materials = new ObjectOpenHashSet<>();
} else {
this.materials = new HashSet<>();
}

this.gson = new Gson();
}
Expand Down
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
33 changes: 30 additions & 3 deletions src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
*/
package ch.njol.skript.bukkitutil;

import ch.njol.skript.Skript;
import ch.njol.util.Math2;
import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Damageable;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HealthUtils {

Expand Down Expand Up @@ -107,9 +115,28 @@ public static double getFinalDamage(EntityDamageEvent e) {
public static void setDamage(EntityDamageEvent e, double damage) {
e.setDamage(damage * 2);
}


@Nullable
private static final Constructor<EntityDamageEvent> OLD_DAMAGE_EVENT_CONSTRUCTOR;

static {
Constructor<EntityDamageEvent> constructor = null;
try {
constructor = EntityDamageEvent.class.getConstructor(Damageable.class, DamageCause.class, double.class);
} catch (NoSuchMethodException ignored) { }
OLD_DAMAGE_EVENT_CONSTRUCTOR = constructor;
}

public static void setDamageCause(Damageable e, DamageCause cause) {
e.setLastDamageCause(new EntityDamageEvent(e, cause, 0));
if (OLD_DAMAGE_EVENT_CONSTRUCTOR != null) {
try {
e.setLastDamageCause(OLD_DAMAGE_EVENT_CONSTRUCTOR.newInstance(e, cause, 0));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
Skript.exception("Failed to set last damage cause");
}
} else {
e.setLastDamageCause(new EntityDamageEvent(e, cause, DamageSource.builder(DamageType.GENERIC).build(), 0));
}
}

}
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
Loading

0 comments on commit 0b78b7a

Please sign in to comment.