Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
# Use these Java versions
java: [
21,
25,
]
# and run on both Linux and Windows
os: [ubuntu-latest, windows-2022]
Expand All @@ -67,7 +67,7 @@ jobs:
- name: build
run: ./gradlew clean build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
if: ${{ runner.os == 'Linux' && matrix.java == '25' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v7
with:
name: Artifacts
Expand Down
15 changes: 5 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()

// Spigot
// Paper
maven {
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}

// Bungeecord
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
url 'https://repo.papermc.io/repository/maven-public/'
}

// Skript
Expand All @@ -36,11 +31,11 @@ repositories {

dependencies {

//Spigot/Bukkit
implementation (group: 'org.spigotmc', name: 'spigot-api', version: '1.21.11-R0.2-SNAPSHOT')
//Paper/Bukkit (26.1 is the oldest target, later 26.x versions stay compatible)
implementation (group: 'io.papermc.paper', name: 'paper-api', version: '26.1.2.build.74-stable')

//Skript
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.14.3') {
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.16.2') {
transitive = false
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.3.1
version=4.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.skquery.skquery.annotations.Description;
import com.skquery.skquery.annotations.Examples;
import com.skquery.skquery.annotations.Patterns;
import com.skquery.skquery.util.Reflection;

import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -22,8 +21,6 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;

import java.lang.reflect.InvocationTargetException;

@SuppressWarnings("deprecation")
@Name("Spawn Falling Block")
@Description("Summons falling blocks with modifiable properties.")
Expand Down Expand Up @@ -65,12 +62,7 @@ protected void execute(Event event) {
block = location.getWorld().spawnFallingBlock(location, itemstack.getType().createBlockData());
EffSecSpawn.lastSpawned = block;
if (damages) {
try {
Object craftSand = Reflection.getOBCClass("entity.CraftFallingSand").getMethod("getHandle").invoke(block);
craftSand.getClass().getMethod("a", boolean.class).invoke(craftSand, true);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
block.setHurtEntities(true);
}
if (breaks) {
block.setDropItem(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,21 @@
import ch.njol.util.Kleenean;

import com.skquery.skquery.annotations.Patterns;
import com.skquery.skquery.util.Reflection;

import org.bukkit.entity.Player;
import org.bukkit.event.Event;

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


@Patterns("display credits to %player%")
public class EffShowCredits extends Effect {

private Expression<Player> player;

@SuppressWarnings({ "rawtypes" })
@Override
protected void execute(Event event) {
Player p = player.getSingle(event);
if(p == null) return;
try {
Constructor packetConstructor = Reflection.getNMSClass("PacketPlayOutGameStateChange").getConstructor(int.class, int.class);
Object packet = packetConstructor.newInstance(4, 0);
Reflection.sendPacket(packet, p);
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
p.showWinScreen();
}

@Override
Expand Down
80 changes: 0 additions & 80 deletions src/main/java/com/skquery/skquery/util/Reflection.java
Original file line number Diff line number Diff line change
@@ -1,87 +1,7 @@
package com.skquery.skquery.util;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

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

public class Reflection {

public static Class<?> getNMSClass(String nms) {
try {
return Class.forName("net.minecraft.server." + getServerVersion() + "." + nms);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public static Class<?> getOBCClass(String obc) {
try {
return Class.forName("org.bukkit.craftbukkit." + getServerVersion() + "." + obc);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public static Object getHandle(Object obj) {
try {
return getMethod(obj.getClass(), "getHandle").invoke(obj);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public static Field getField(Class<?> clazz, String name) {
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods())
if (m.getName().equals(name) && (args.length == 0 || classesEqual(args, m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
return null;
}

public static boolean classesEqual(Class<?>[] l1, Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length)
return false;
for (int i = 0; i < l1.length; i++)
if (l1[i] != l2[i]) {
equal = false;
break;
}
return equal;
}

public static void sendPacket(Object packet, Player... players) {
try {
for (Player p : players) {
Object craftPlayer = Reflection.getHandle(p);
Object connection = Reflection.getField(craftPlayer.getClass(), "playerConnection").get(craftPlayer);
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}

public static String getServerVersion() {
return Bukkit.getServer().getClass().getPackage().getName().replace(".", "@").split("@")[3];
}

public static Class<?> getCaller() {
try {
return Class.forName(Thread.currentThread().getStackTrace()[3].getClassName(), false, Reflection.class.getClassLoader());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SkQuery
authors: [w00tmast3r, LimeGlass, SkQuery Contributors]
version: @version@
api-version: 1.13
api-version: 1.21.4
depend: [Skript]
main: com.skquery.skquery.SkQuery