Skip to content

Commit

Permalink
Merge branch 'dev/feature' into ench/timespan-improve
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Mar 19, 2024
2 parents 1b845c7 + ae1f465 commit 001c9e3
Show file tree
Hide file tree
Showing 224 changed files with 6,748 additions and 3,332 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +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: [email protected]
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
24 changes: 10 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ dependencies {
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.2'

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.800'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.20.4-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'
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'
}

implementation fileTree(dir: 'lib', include: '*.jar')

testShadow group: 'junit', name: 'junit', version: '4.13.2'
testShadow group: 'org.easymock', name: 'easymock', version: '5.2.0'
testShadow group: 'org.easymock', name: 'easymock', version: '5.0.1'
}

task checkAliases {
Expand Down Expand Up @@ -250,7 +250,7 @@ void createTestTask(String name, String desc, String environments, int javaVersi
}
}

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

Expand Down Expand Up @@ -295,10 +295,8 @@ task githubResources(type: ProcessResources) {
include '**'
version = project.property('version')
def channel = 'stable'
if (version.contains('alpha'))
channel = 'alpha'
else if (version.contains('beta'))
channel = 'beta'
if (version.contains('pre'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
Expand Down Expand Up @@ -330,10 +328,8 @@ task spigotResources(type: ProcessResources) {
include '**'
version = project.property('version')
def channel = 'stable'
if (version.contains('alpha'))
channel = 'alpha'
else if (version.contains('beta'))
channel = 'beta'
if (version.contains('pre'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
Expand Down Expand Up @@ -369,7 +365,7 @@ task nightlyResources(type: ProcessResources) {
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-nightly', // SkriptLang build, automatically done by CI
'release-channel' : 'alpha', // No update checking, but these are VERY unstable
'release-channel' : 'prerelease', // No update checking, but these are VERY unstable
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No autoupdates for now
'release-source' : '',
'release-download': 'null'
Expand Down
4 changes: 3 additions & 1 deletion code-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ If we need to remove or alter contributed code due to a licensing issue we will
- Static constant fields should be named in `UPPER_SNAKE_CASE`
* Localised messages should be named in `lower_snake_case`
- And that is the only place where snake_case is acceptable
* Use prefixes only where their use has been already estabilished (such as `ExprSomeRandomThing`)
* Use prefixes only where their use has been already established (such as `ExprSomeRandomThing`)
- Otherwise, use postfixes where necessary
- Common occurrences include: Struct (Structure), Sec (Section), EffSec (EffectSection), Eff (Effect), Cond (Condition), Expr (Expression)
* Ensure variable/field names are descriptive. Avoid using shorthand names like `e`, or `c`.
- e.g. Event should be `event`, not `e`. `e` is ambiguous and could mean a number of things.

### Comments
* Prefer to comment *why* you're doing things instead of how you're doing them
Expand Down
4 changes: 2 additions & 2 deletions 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-dev
version=2.8.3
jarName=Skript.jar
testEnv=java17/paper-1.20.2
testEnv=java17/paper-1.20.4
testEnvJavaVersion=17
2 changes: 1 addition & 1 deletion skript-aliases
35 changes: 33 additions & 2 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ch.njol.skript.classes.data.DefaultComparators;
import ch.njol.skript.classes.data.DefaultConverters;
import ch.njol.skript.classes.data.DefaultFunctions;
import ch.njol.skript.classes.data.DefaultOperations;
import ch.njol.skript.classes.data.JavaClasses;
import ch.njol.skript.classes.data.SkriptClasses;
import ch.njol.skript.command.Commands;
Expand Down Expand Up @@ -82,6 +83,7 @@
import ch.njol.util.Kleenean;
import ch.njol.util.NullableChecker;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.CollectionUtils;
import ch.njol.util.coll.iterator.CheckedIterator;
import ch.njol.util.coll.iterator.EnumerationIterable;
import com.google.common.collect.Lists;
Expand All @@ -106,6 +108,7 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.skriptlang.skript.lang.comparator.Comparator;
Expand Down Expand Up @@ -147,7 +150,6 @@
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -534,6 +536,7 @@ public void onEnable() {
new DefaultComparators();
new DefaultConverters();
new DefaultFunctions();
new DefaultOperations();

ChatMessages.registerListeners();

Expand Down Expand Up @@ -690,6 +693,9 @@ protected void afterErrors() {
long milliseconds = 0, tests = 0, fails = 0, ignored = 0, size = 0;
try {
List<Class<?>> classes = Lists.newArrayList(Utils.getClasses(Skript.getInstance(), "org.skriptlang.skript.test", "tests"));
// Don't attempt to run inner/anonymous classes as tests
classes.removeIf(Class::isAnonymousClass);
classes.removeIf(Class::isLocalClass);
// Test that requires package access. This is only present when compiling with src/test.
classes.add(Class.forName("ch.njol.skript.variables.FlatFileStorageTest"));
size = classes.size();
Expand All @@ -703,6 +709,23 @@ protected void afterErrors() {
Result junit = JUnitCore.runClasses(clazz);
TestTracker.testStarted("JUnit: '" + test + "'");

/**
* Usage of @After is pointless if the JUnit class requires delay. As the @After will happen instantly.
* The JUnit must override the 'cleanup' method to avoid Skript automatically cleaning up the test data.
*/
boolean overrides = false;
for (Method method : clazz.getDeclaredMethods()) {
if (!method.isAnnotationPresent(After.class))
continue;
if (SkriptJUnitTest.getShutdownDelay() > 1)
warning("Using @After in JUnit classes, happens instantaneously, and JUnit class '" + test + "' requires a delay. Do your test cleanup in the script junit file or 'cleanup' method.");
if (method.getName().equals("cleanup"))
overrides = true;
}
if (SkriptJUnitTest.getShutdownDelay() > 1 && !overrides)
error("The JUnit class '" + test + "' does not override the method 'cleanup' thus the test data will instantly be cleaned up. " +
"This JUnit test requires longer shutdown time: " + SkriptJUnitTest.getShutdownDelay());

// Collect all data from the current JUnit test.
shutdownDelay = Math.max(shutdownDelay, SkriptJUnitTest.getShutdownDelay());
tests += junit.getRunCount();
Expand Down Expand Up @@ -1134,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
14 changes: 6 additions & 8 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ public class SkriptConfig {
.setter(t -> {
ReleaseChannel channel;
switch (t) {
case "alpha": // Everything goes in alpha channel
channel = new ReleaseChannel((name) -> true, t);
break;
case "alpha":
case "beta":
channel = new ReleaseChannel((name) -> !name.contains("alpha"), t);
Skript.warning("'alpha' and 'beta' are no longer valid release channels. Use 'prerelease' instead.");
case "prerelease": // All development builds are valid
channel = new ReleaseChannel((name) -> true, t);
break;
case "stable":
channel = new ReleaseChannel((name) -> !name.contains("alpha") && !name.contains("beta"), t);
// TODO a better option would be to check that it is not a pre-release through GH API
channel = new ReleaseChannel((name) -> !name.contains("pre"), t);
break;
case "none":
channel = new ReleaseChannel((name) -> false, t);
Expand All @@ -116,9 +117,6 @@ public class SkriptConfig {
}
SkriptUpdater updater = Skript.getInstance().getUpdater();
if (updater != null) {
if (updater.getCurrentRelease().flavor.contains("spigot") && !t.equals("stable")) {
Skript.error("Only stable Skript versions are uploaded to Spigot resources.");
}
updater.setReleaseChannel(channel);
}
});
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
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));
}
}

}
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/classes/Arithmetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @param <A> the type of the absolute value
* @param <R> the type of the relative value
*/
@Deprecated
public interface Arithmetic<A, R> {

public R difference(A first, A second);
Expand Down
Loading

0 comments on commit 001c9e3

Please sign in to comment.