Browse Source

graceful client side dependency fail

Kajetan Johannes Hammerle 3 years ago
parent
commit
d5785ce4a8

+ 5 - 0
build.gradle

@@ -34,6 +34,11 @@ minecraft {
     }
 }
 
+apply plugin: 'java'
+compileJava {
+    options.compilerArgs << '--release' << '8'
+}
+
 dependencies {
     minecraft 'net.minecraftforge:forge:1.15.2-31.2.21'
     

+ 5 - 2
src/main/java/me/km/ClassLoaderUtils.java

@@ -1,20 +1,23 @@
 package me.km;
 
 import java.io.File;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.ClassLoader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 
 public class ClassLoaderUtils {
     public static void loadDependencies() {
-        URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
-
         try {
+            URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
             Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
             method.setAccessible(true);
             method.invoke(sysloader, getURL("mods/libs/SnuviScriptRecoded.jar"));
             method.invoke(sysloader, getURL("mods/libs/mysql-connector-java.jar"));
+        } catch(ClassCastException ex) {
+            System.out.println("system class loader is not of type URLClassLoader");
         } catch(Throwable t) {
             t.printStackTrace();
         }

+ 13 - 0
src/main/java/me/km/CommonEvents.java

@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import me.hammerle.snuviscript.code.ScriptManager;
 import me.km.utils.Location;
 import me.km.utils.Mapper;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.entity.player.ServerPlayerEntity;
 import net.minecraft.item.ItemStack;
 import net.minecraft.particles.*;
 import net.minecraft.world.server.ServerWorld;
@@ -33,6 +35,17 @@ public class ParticleCommands {
             double offZ = in.length >= 7 ? in[6].getDouble(sc) : 0.0;
             ((ServerWorld) l.getWorld()).spawnParticle(data, l.getX(), l.getY(), l.getZ(), count, offX, offY, offZ, speed);
         });
+        sm.registerConsumer("particle.spawnplayer", (sc, in) -> {
+            Location l = ((Location) in[0].get(sc));
+            IParticleData data = ((IParticleData) in[1].get(sc));
+            ServerPlayerEntity p = (ServerPlayerEntity) in[2].get(sc);
+            int count = in.length >= 4 ? in[3].getInt(sc) : 1;
+            double speed = in.length >= 5 ? in[4].getDouble(sc) : 0.0;
+            double offX = in.length >= 6 ? in[5].getDouble(sc) : 0.0;
+            double offY = in.length >= 7 ? in[6].getDouble(sc) : 0.0;
+            double offZ = in.length >= 8 ? in[7].getDouble(sc) : 0.0;
+            ((ServerWorld) l.getWorld()).spawnParticle(p, data, true, l.getX(), l.getY(), l.getZ(), count, offX, offY, offZ, speed);
+        });
         sm.registerConsumer("particle.spawncircle", (sc, in) -> {
             Location l = ((Location) in[0].get(sc));
             IParticleData data = ((IParticleData) in[1].get(sc));

+ 0 - 0
src/main/java/me/km/snuviscript/commands/PermissionCommands.java