Skip to content

Commit

Permalink
Merge branch 'dev/feature' into stormy-whether
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Jun 28, 2024
2 parents f68385b + ccc9373 commit b15ce76
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 61 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/archive-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Archive documentation

on:
release:
types: [published]
workflow_dispatch:

jobs:
archive-docs:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
needs: release-docs
runs-on: ubuntu-latest
steps:
- name: Configure workflow
id: configuration
run: |
echo "BRANCH_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "DOCS_OUTPUT_DIR=${GITHUB_WORKSPACE}/skript-docs/docs/archives/${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "DOCS_REPO_DIR=${GITHUB_WORKSPACE}/skript-docs" >> $GITHUB_OUTPUT
echo "SKRIPT_REPO_DIR=${GITHUB_WORKSPACE}/skript" >> $GITHUB_OUTPUT
- name: Checkout Skript
uses: actions/checkout@v4
with:
submodules: recursive
path: skript
- name: Setup documentation environment
uses: ./skript/.github/workflows/docs/setup-docs
with:
docs_deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
- name: Generate documentation
uses: ./skript/.github/workflows/docs/generate-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
is_release: true
generate_javadocs: true
- name: Push archive documentation
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Archive Docs Bot
git_email: [email protected]
git_commit_message: "Update ${{ steps.configuration.outputs.BRANCH_NAME }} archive docs"
4 changes: 2 additions & 2 deletions .github/workflows/docs/generate-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ runs:
cd $SKRIPT_REPO_DIR
if [[ "${IS_RELEASE}" == "true" ]]; then
./gradlew genReleaseDocs releaseJavadoc
./gradlew genReleaseDocs javadoc
elif [[ "${GENERATE_JAVADOCS}" == "true" ]]; then
./gradlew genNightlyDocs javadoc
else
./gradlew genNightlyDocs
fi
if [ -d "${DOCS_OUTPUT_DIR}" ]; then
if [[ "${GENERATE_JAVADOCS}" == "true" ]]; then
if [[ "${GENERATE_JAVADOCS}" == "true" ]] || [[ "${IS_RELEASE}" == "true" ]] ; then
mkdir -p "${SKRIPT_DOCS_OUTPUT_DIR}/javadocs" && cp -a "./build/docs/javadoc/." "$_"
fi
Expand Down
39 changes: 2 additions & 37 deletions .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Release documentation
on:
release:
types: [published]
workflow_dispatch:

jobs:
release-docs:
Expand Down Expand Up @@ -33,6 +34,7 @@ jobs:
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
is_release: true
generate_javadocs: true
cleanup_pattern: "!(nightly|archives|templates)"
- name: Push release documentation
uses: ./skript/.github/workflows/docs/push-docs
Expand All @@ -41,40 +43,3 @@ jobs:
git_name: Release Docs Bot
git_email: [email protected]
git_commit_message: "Update release docs to ${{ steps.configuration.outputs.BRANCH_NAME }}"

archive-docs:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
needs: release-docs
runs-on: ubuntu-latest
steps:
- name: Configure workflow
id: configuration
run: |
echo "BRANCH_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "DOCS_OUTPUT_DIR=${GITHUB_WORKSPACE}/skript-docs/docs/archives/${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "DOCS_REPO_DIR=${GITHUB_WORKSPACE}/skript-docs" >> $GITHUB_OUTPUT
echo "SKRIPT_REPO_DIR=${GITHUB_WORKSPACE}/skript" >> $GITHUB_OUTPUT
- name: Checkout Skript
uses: actions/checkout@v4
with:
submodules: recursive
path: skript
- name: Setup documentation environment
uses: ./skript/.github/workflows/docs/setup-docs
with:
docs_deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
- name: Generate documentation
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
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Archive Docs Bot
git_email: [email protected]
git_commit_message: "Update ${{ steps.configuration.outputs.BRANCH_NAME }} archive docs"
18 changes: 4 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,6 @@ publishing {
}
}

task releaseJavadoc(type: Javadoc) {
title = project.name + ' ' + project.property('version')
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options.encoding = 'UTF-8'
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}

// Task to check that test scripts are named correctly
tasks.register('testNaming') {
doLast {
Expand Down Expand Up @@ -188,7 +179,7 @@ void createTestTask(String name, String desc, String environments, int javaVersi
if (junit) {
artifact += 'Skript-JUnit.jar'
} else if (releaseDocs) {
artifact += 'Skript-github.jar'
artifact += 'Skript-' + version + '.jar'
} else {
artifact += 'Skript-nightly.jar'
}
Expand Down Expand Up @@ -367,7 +358,7 @@ task nightlyResources(type: ProcessResources) {
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-nightly', // SkriptLang build, automatically done by CI
'release-channel' : 'prerelease', // No update checking, but these are VERY unstable
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No autoupdates for now
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No auto updates for now
'release-source' : '',
'release-download': 'null'
]
Expand All @@ -389,8 +380,8 @@ task nightlyRelease(type: ShadowJar) {
}

javadoc {
dependsOn nightlyResources

mustRunAfter(tasks.withType(ProcessResources))
title = 'Skript ' + project.property('version')
source = sourceSets.main.allJava

exclude("ch/njol/skript/conditions/**")
Expand All @@ -409,4 +400,3 @@ javadoc {
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}

17 changes: 11 additions & 6 deletions src/main/java/ch/njol/skript/classes/data/DefaultOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ch.njol.skript.util.Date;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Timespan.TimePeriod;
import ch.njol.skript.util.Utils;
import ch.njol.util.Math2;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -85,9 +86,9 @@ public class DefaultOperations {
});

// Timespan - Timespan
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, (left, right) -> new Timespan(Math2.addClamped(left.getMilliSeconds(), right.getMilliSeconds())));
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, (left, right) -> new Timespan(Math.max(0, left.getMilliSeconds() - right.getMilliSeconds())));
Arithmetics.registerDifference(Timespan.class, (left, right) -> new Timespan(Math.abs(left.getMilliSeconds() - right.getMilliSeconds())));
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, (left, right) -> new Timespan(Math2.addClamped(left.getAs(TimePeriod.MILLISECOND), right.getAs(TimePeriod.MILLISECOND))));
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, (left, right) -> new Timespan(Math.max(0, left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
Arithmetics.registerDifference(Timespan.class, (left, right) -> new Timespan(Math.abs(left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
Arithmetics.registerDefaultValue(Timespan.class, Timespan::new);

// Timespan - Number
Expand All @@ -96,20 +97,24 @@ public class DefaultOperations {
long scalar = right.longValue();
if (scalar < 0)
return null;
return new Timespan(Math2.multiplyClamped(left.getMilliSeconds(), scalar));
return new Timespan(Math2.multiplyClamped(left.getAs(TimePeriod.MILLISECOND), scalar));
}, (left, right) -> {
long scalar = left.longValue();
if (scalar < 0)
return null;
return new Timespan(scalar * right.getMilliSeconds());
return new Timespan(scalar * right.getAs(TimePeriod.MILLISECOND));
});
Arithmetics.registerOperation(Operator.DIVISION, Timespan.class, Number.class, (left, right) -> {
long scalar = right.longValue();
if (scalar <= 0)
return null;
return new Timespan(left.getMilliSeconds() / scalar);
return new Timespan(left.getAs(TimePeriod.MILLISECOND) / scalar);
});

// Timespan / Timespan = Number
Arithmetics.registerOperation(Operator.DIVISION, Timespan.class, Timespan.class, Number.class,
(left, right) -> left.getAs(TimePeriod.MILLISECOND) / (double) right.getAs(TimePeriod.MILLISECOND));

// Date - Timespan
Arithmetics.registerOperation(Operator.ADDITION, Date.class, Timespan.class, Date::plus);
Arithmetics.registerOperation(Operator.SUBTRACTION, Date.class, Timespan.class, Date::minus);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/structures/StructCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ private void scheduleCommandSync() {
if (SYNC_COMMANDS.get()) {
SYNC_COMMANDS.set(false);
if (DELAY_COMMAND_SYNCING) {
Bukkit.getScheduler().runTask(Skript.getInstance(), this::forceCommandSync);
// if the plugin is disabled, the server is likely closing and delaying will cause an error.
if (Bukkit.getPluginManager().isPluginEnabled(Skript.getInstance()))
Bukkit.getScheduler().runTask(Skript.getInstance(), this::forceCommandSync);
} else {
forceCommandSync();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/util/Timespan.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Timespan implements YggdrasilSerializable, Comparable<Timespan> { /

public enum TimePeriod {

MILLISECOND(1L),
TICK(50L),
SECOND(1000L),
MINUTE(SECOND.time * 60L),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ tree types:

# -- Time --
time:
millisecond: millisecond¦s
tick: tick¦s
second: second¦s
minute: minute¦s
Expand Down
8 changes: 7 additions & 1 deletion src/test/skript/tests/syntaxes/expressions/ExprArithmetic.sk
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ test "timespan arithmetic":
assert (2 * {_t1}) is (2 seconds) with "2 * 1 second is not 2 seconds"
assert (2 / {_t1}) is not set with "number divided by timespan is set"

assert ({_t1} + 2) is not set with "timespan plus number is set"
assert ({_t1} + 2) is not set with "timespan plus number is set"

assert {_t1} / {_t2} is 0.5 with "timespan / timespan failed"
assert {_t1} / 1 tick is 20 with "timespan / timespan of different units failed"
assert 0 seconds / {_t2} is 0 with "0 timespan / timespan failed"
assert {_t1} / 0 seconds is infinity value with "timespan / 0 timespan failed"
assert isNaN(0 seconds / 0 ticks) is true with "0 timespan / 0 timespan failed", expected NaN value, got (0 seconds / 0 ticks)

test "date arithmetic":
set {_d1} to now
Expand Down

0 comments on commit b15ce76

Please sign in to comment.