From 0fb81f69b50e598a48a747cb5d7d714b337ff256 Mon Sep 17 00:00:00 2001 From: JRoy Date: Sun, 18 Oct 2020 15:03:42 -0400 Subject: [PATCH 1/4] Update gradle buildscript * Added shadow plugin to shade and relocate dependencies * Added central variable for paper version * Added PaperLib as a shaded/relocated dependency --- build.gradle | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index b0a1979d9d1..f6d9c05119d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,15 +2,20 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { id "com.github.hierynomus.license" version "0.14.0" + id "com.github.johnrengelman.shadow" version "5.2.0" } apply plugin: 'java' apply plugin: 'maven-publish' +ext { + paperVersion = '1.16.3-R0.1-SNAPSHOT' // NOTICE: Edit this when updating to a new MC Version +} + // Substitute dependencies' versions of Bukkit with latest Paper API configurations.all { resolutionStrategy.dependencySubstitution { - substitute module('org.bukkit:bukkit') with module('com.destroystokyo.paper:paper-api:1.14-R0.1-SNAPSHOT') + substitute module('org.bukkit:bukkit') with module("com.destroystokyo.paper:paper-api:${paperVersion}") } } @@ -28,7 +33,7 @@ allprojects { } maven { - url 'https://repo.destroystokyo.com/repository/maven-public//' + url 'https://papermc.io/repo/repository/maven-public/' } maven { @@ -50,8 +55,10 @@ allprojects { configurations { ecj + shade + implementation.extendsFrom(shade) } - + dependencies { ecj 'org.eclipse.jdt:ecj:3.15.0' } @@ -70,7 +77,7 @@ allprojects { } dependencies { - implementation 'com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT' + implementation "com.destroystokyo.paper:paper-api:${paperVersion}" implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0' implementation 'com.google.code.findbugs:findbugs:3.0.1' implementation 'com.sk89q.worldguard:worldguard-legacy:7.0.0-SNAPSHOT' @@ -78,6 +85,7 @@ dependencies { implementation('net.milkbowl.vault:Vault:1.7.1') { exclude group: 'org.bstats', module: 'bstats-bukkit' } + shade 'io.papermc:paperlib:1.0.5' testImplementation 'junit:junit:4.12' testImplementation 'org.easymock:easymock:3.6' @@ -97,23 +105,40 @@ processResources { ] } -jar { +task jar(overwrite: true, type: ShadowJar) { archiveName System.getenv('SKRIPT_JAR_NAME') == null ? 'Skript.jar' : System.getenv("SKRIPT_JAR_NAME") + from sourceSets.main.output +} + +//jar.dependsOn shadowJar +tasks.withType(ShadowJar) { + configurations = [project.configurations.shade] + dependencies { + include (dependency('io.papermc:paperlib')) + } + relocate 'io.papermc.lib', 'ch.njol.skript.paperlib' manifest { attributes("Name": "ch/njol/skript", - "Sealed": "true") + "Sealed": "true") } from('skript-aliases') { into('aliases-english') // Change this if we get aliases in other languages } - + // Include all modules of Skript from 'skript-worldguard6/build/classes/java/main' from 'skript-worldguard7fawe/build/classes/java/main' } +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation +task relocateShadowJar(type: ConfigureShadowRelocation) { + target = tasks.shadowJar +} +tasks.shadowJar.dependsOn tasks.relocateShadowJar + license { header file('licenseheader.txt') exclude('**/Metrics.java') // Not under GPLv3 @@ -236,7 +261,7 @@ task githubResources(type: ProcessResources) { into 'build/resources/main' } -task githubRelease(type: Jar) { +task githubRelease(type: ShadowJar) { from sourceSets.main.output dependsOn githubResources archiveName = 'Skript-github.jar' @@ -278,7 +303,7 @@ task spigotResources(type: ProcessResources) { into 'build/resources/main' } -task spigotRelease(type: Jar) { +task spigotRelease(type: ShadowJar) { from sourceSets.main.output dependsOn spigotResources archiveName = 'Skript-spigot.jar' @@ -315,7 +340,7 @@ task nightlyResources(type: ProcessResources) { into 'build/resources/main' } -task nightlyRelease(type: Jar) { +task nightlyRelease(type: ShadowJar) { from sourceSets.main.output dependsOn nightlyResources dependsOn licenseMain From d4c6caacf27698c9135d8565aeba7d01606a598c Mon Sep 17 00:00:00 2001 From: JRoy Date: Sun, 18 Oct 2020 15:14:04 -0400 Subject: [PATCH 2/4] Use PaperLib in teleport effect to avoid chunk loads --- .../ch/njol/skript/effects/EffTeleport.java | 88 +++++++++++++++---- 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffTeleport.java b/src/main/java/ch/njol/skript/effects/EffTeleport.java index a97fd04656e..2fbcfba1d86 100644 --- a/src/main/java/ch/njol/skript/effects/EffTeleport.java +++ b/src/main/java/ch/njol/skript/effects/EffTeleport.java @@ -35,8 +35,13 @@ import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.Trigger; +import ch.njol.skript.lang.TriggerItem; +import ch.njol.skript.timings.SkriptTimings; import ch.njol.skript.util.Direction; +import ch.njol.skript.variables.Variables; import ch.njol.util.Kleenean; +import io.papermc.lib.PaperLib; @Name("Teleport") @Description("Teleport an entity to a specific location.") @@ -61,28 +66,75 @@ public boolean init(final Expression[] exprs, final int matchedPattern, final location = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); return true; } - + + @Nullable @Override - protected void execute(final Event e) { - Location to = location.getSingle(e); - if (to == null) - return; - if (Math.abs(to.getX() - to.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(to.getZ() - to.getBlockZ() - 0.5) < Skript.EPSILON) { - final Block on = to.getBlock().getRelative(BlockFace.DOWN); - if (on.getType() != Material.AIR) { - to = to.clone(); - // TODO 1.13 block height stuff - //to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData())); + protected TriggerItem walk(Event e) { + debug(e, true); + TriggerItem next = getNext(); + + Delay.addDelayedEvent(e); + + final Location loc = location.getSingle(e); + if (loc == null) { + Object timing = null; + if (next != null) { + if (SkriptTimings.enabled()) { + Trigger trigger = getTrigger(); + if (trigger != null) { + timing = SkriptTimings.start(trigger.getDebugLabel()); + } + } + + TriggerItem.walk(next, e); } + Variables.removeLocals(e); // Clean up local vars, we may be exiting now + SkriptTimings.stop(timing); + return null; } - for (final Entity entity : entities.getArray(e)) { - to.getChunk().load(); - if (e instanceof PlayerRespawnEvent && entity.equals(((PlayerRespawnEvent) e).getPlayer()) && !Delay.isDelayed(e)) { - ((PlayerRespawnEvent) e).setRespawnLocation(to); - } else { - entity.teleport(to); + final Entity[] entityArray = entities.getArray(e); // We have to fetch this before possible async execution to avoid async local variable access. + + //This will either fetch the chunk instantly if on spigot or already loaded or fetch it async if on paper. + PaperLib.getChunkAtAsync(loc).thenAccept(chunk -> { + // The following is now on the main thread + Location toLoc = loc; + if (Math.abs(toLoc.getX() - toLoc.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(toLoc.getZ() - toLoc.getBlockZ() - 0.5) < Skript.EPSILON) { + final Block on = toLoc.getBlock().getRelative(BlockFace.DOWN); + if (on.getType() != Material.AIR) { + toLoc = toLoc.clone(); + // TODO 1.13 block height stuff + //to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData())); + } } - } + for (final Entity entity : entityArray) { + if (e instanceof PlayerRespawnEvent && entity.equals(((PlayerRespawnEvent) e).getPlayer()) && !Delay.isDelayed(e)) { + ((PlayerRespawnEvent) e).setRespawnLocation(toLoc); + } else { + entity.teleport(toLoc); + } + } + + // Continue the rest of the trigger if there is one + Object timing = null; + if (next != null) { + if (SkriptTimings.enabled()) { + Trigger trigger = getTrigger(); + if (trigger != null) { + timing = SkriptTimings.start(trigger.getDebugLabel()); + } + } + + TriggerItem.walk(next, e); + } + Variables.removeLocals(e); // Clean up local vars, we may be exiting now + SkriptTimings.stop(timing); + }); + return null; + } + + @Override + protected void execute(final Event e) { + // Nothing needs to happen here, we're executing in walk } @Override From 00f80584a3f2f80c801c64f632a9f08ac7e926a8 Mon Sep 17 00:00:00 2001 From: JRoy Date: Tue, 3 Nov 2020 11:36:07 -0500 Subject: [PATCH 3/4] Fix regression for PlayerRespawnEvent and cleanup code --- .../ch/njol/skript/effects/EffTeleport.java | 84 +++++++++---------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffTeleport.java b/src/main/java/ch/njol/skript/effects/EffTeleport.java index 2fbcfba1d86..e609bbee49b 100644 --- a/src/main/java/ch/njol/skript/effects/EffTeleport.java +++ b/src/main/java/ch/njol/skript/effects/EffTeleport.java @@ -72,66 +72,64 @@ public boolean init(final Expression[] exprs, final int matchedPattern, final protected TriggerItem walk(Event e) { debug(e, true); TriggerItem next = getNext(); - + boolean delayed = Delay.isDelayed(e); Delay.addDelayedEvent(e); final Location loc = location.getSingle(e); - if (loc == null) { - Object timing = null; - if (next != null) { - if (SkriptTimings.enabled()) { - Trigger trigger = getTrigger(); - if (trigger != null) { - timing = SkriptTimings.start(trigger.getDebugLabel()); - } - } - - TriggerItem.walk(next, e); - } - Variables.removeLocals(e); // Clean up local vars, we may be exiting now - SkriptTimings.stop(timing); + final Entity[] entityArray = entities.getArray(e); // We have to fetch this before possible async execution to avoid async local variable access. + final boolean respawnEvent = !delayed && e instanceof PlayerRespawnEvent && entityArray.length == 1 && entityArray[0].equals(((PlayerRespawnEvent) e).getPlayer()); + + if (respawnEvent && loc != null) { + ((PlayerRespawnEvent) e).setRespawnLocation(getSafeLocation(loc)); + } + + if (respawnEvent || loc == null) { + continueWalk(next, e); return null; } - final Entity[] entityArray = entities.getArray(e); // We have to fetch this before possible async execution to avoid async local variable access. //This will either fetch the chunk instantly if on spigot or already loaded or fetch it async if on paper. PaperLib.getChunkAtAsync(loc).thenAccept(chunk -> { // The following is now on the main thread - Location toLoc = loc; - if (Math.abs(toLoc.getX() - toLoc.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(toLoc.getZ() - toLoc.getBlockZ() - 0.5) < Skript.EPSILON) { - final Block on = toLoc.getBlock().getRelative(BlockFace.DOWN); - if (on.getType() != Material.AIR) { - toLoc = toLoc.clone(); - // TODO 1.13 block height stuff - //to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData())); - } - } for (final Entity entity : entityArray) { - if (e instanceof PlayerRespawnEvent && entity.equals(((PlayerRespawnEvent) e).getPlayer()) && !Delay.isDelayed(e)) { - ((PlayerRespawnEvent) e).setRespawnLocation(toLoc); - } else { - entity.teleport(toLoc); - } + entity.teleport(getSafeLocation(loc)); } // Continue the rest of the trigger if there is one - Object timing = null; - if (next != null) { - if (SkriptTimings.enabled()) { - Trigger trigger = getTrigger(); - if (trigger != null) { - timing = SkriptTimings.start(trigger.getDebugLabel()); - } - } - - TriggerItem.walk(next, e); - } - Variables.removeLocals(e); // Clean up local vars, we may be exiting now - SkriptTimings.stop(timing); + continueWalk(next, e); }); return null; } + private void continueWalk(@Nullable TriggerItem next, Event e) { + Object timing = null; + if (next != null) { + if (SkriptTimings.enabled()) { + Trigger trigger = getTrigger(); + if (trigger != null) { + timing = SkriptTimings.start(trigger.getDebugLabel()); + } + } + + TriggerItem.walk(next, e); + } + Variables.removeLocals(e); // Clean up local vars, we may be exiting now + SkriptTimings.stop(timing); + } + + private Location getSafeLocation(Location loc) { + Location toLoc = loc; + if (Math.abs(toLoc.getX() - toLoc.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(toLoc.getZ() - toLoc.getBlockZ() - 0.5) < Skript.EPSILON) { + final Block on = toLoc.getBlock().getRelative(BlockFace.DOWN); + if (on.getType() != Material.AIR) { + toLoc = toLoc.clone(); + // TODO 1.13 block height stuff + //to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData())); + } + } + return toLoc; + } + @Override protected void execute(final Event e) { // Nothing needs to happen here, we're executing in walk From 6cf1fdeddda7e9b456b902a311454bddc337e4ed Mon Sep 17 00:00:00 2001 From: Shane Bee Date: Sat, 28 Nov 2020 12:55:26 -0800 Subject: [PATCH 4/4] Update build.gradle change 1.16.3 -> 1.16.4 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c2f0bda1322..36fa2ebc12f 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ apply plugin: 'java' apply plugin: 'maven-publish' ext { - paperVersion = '1.16.3-R0.1-SNAPSHOT' // NOTICE: Edit this when updating to a new MC Version + paperVersion = '1.16.4-R0.1-SNAPSHOT' // NOTICE: Edit this when updating to a new MC Version } // Substitute dependencies' versions of Bukkit with latest Paper API