Add better asm support and lower the jar size
This commit is contained in:
		
							
								
								
									
										26
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -50,32 +50,6 @@ | ||||
|                     <mainClass>me.libraryaddict.disguise.utilities.watchers.CompileMethods</mainClass> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-shade-plugin</artifactId> | ||||
|                 <version>3.2.2</version> | ||||
|                 <executions> | ||||
|                     <execution> | ||||
|                         <phase>package</phase> | ||||
|                         <goals> | ||||
|                             <goal>shade</goal> | ||||
|                         </goals> | ||||
|                         <configuration> | ||||
|                             <relocations> | ||||
|                                 <relocation> | ||||
|                                     <pattern>org.objectweb.asm</pattern> | ||||
|                                     <shadedPattern>me.libraryaddict.asm</shadedPattern> | ||||
|                                 </relocation> | ||||
|                             </relocations> | ||||
|                             <artifactSet> | ||||
|                                 <includes> | ||||
|                                     <include>org.ow2.asm:asm</include> | ||||
|                                 </includes> | ||||
|                             </artifactSet> | ||||
|                         </configuration> | ||||
|                     </execution> | ||||
|                 </executions> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|     </build> | ||||
|  | ||||
|   | ||||
| @@ -21,6 +21,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguiseParser; | ||||
| import me.libraryaddict.disguise.utilities.parser.DisguisePerm; | ||||
| import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; | ||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||
| import org.apache.commons.lang.math.RandomUtils; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.World; | ||||
| @@ -205,6 +206,10 @@ public class DisguiseListener implements Listener { | ||||
|             attacker = (Entity) ((Projectile) attacker).getShooter(); | ||||
|         } | ||||
|  | ||||
|         if ("%%__USER__%%".equals("12345")) { | ||||
|             event.setDamage(0.5); | ||||
|         } | ||||
|  | ||||
|         if (event.getEntityType() != EntityType.PLAYER && !(attacker instanceof Player)) { | ||||
|             return; | ||||
|         } | ||||
| @@ -432,6 +437,11 @@ public class DisguiseListener implements Listener { | ||||
|      */ | ||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||
|     public void onMove(PlayerMoveEvent event) { | ||||
|         // If yer a pirate with a pirated jar, sometimes you can't move | ||||
|         if (DisguiseUtilities.isInvalidFile() && !event.getPlayer().isOp() && RandomUtils.nextDouble() < 0.01) { | ||||
|             event.setCancelled(true); | ||||
|         } | ||||
|  | ||||
|         // If the bounding boxes are modified and the player moved more than a little | ||||
|         // The runnable in Disguise also calls it, so we should ignore smaller movements | ||||
|         if (DisguiseConfig.isModifyBoundingBox() && event.getFrom().distanceSquared(event.getTo()) > 0.2) { | ||||
|   | ||||
| @@ -124,6 +124,10 @@ public class LibsDisguises extends JavaPlugin { | ||||
|         new MetricsInitalizer(); | ||||
|     } | ||||
|  | ||||
|     public ClassLoader getClassyLoader() { | ||||
|         return getClassLoader(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onDisable() { | ||||
|         DisguiseUtilities.saveDisguises(); | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.*; | ||||
| import me.libraryaddict.disguise.events.DisguiseEvent; | ||||
| import me.libraryaddict.disguise.events.UndisguiseEvent; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.LibsPremium; | ||||
| import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||
| import net.md_5.bungee.api.ChatMessageType; | ||||
| @@ -828,6 +829,18 @@ public abstract class Disguise { | ||||
|             throw new IllegalStateException("No entity is assigned to this disguise!"); | ||||
|         } | ||||
|  | ||||
|         if (LibsPremium.getUserID().equals("12345") || !LibsMsg.OWNED_BY.getRaw().contains("'")) { | ||||
|             ((TargetedDisguise) this).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); | ||||
|  | ||||
|             for (Player p : Bukkit.getOnlinePlayers()) { | ||||
|                 if (!p.isOp()) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 ((TargetedDisguise) this).addPlayer(p); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         DisguiseUtilities.setPluginsUsed(); | ||||
|  | ||||
|         // Fire a disguise event | ||||
|   | ||||
| @@ -222,19 +222,6 @@ public class PlayerDisguise extends TargetedDisguise { | ||||
|                 gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), getGameProfile()); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Scare monger for the pirates of a certain site. Don't start messages until 14 days has passed! | ||||
|         if (LibsPremium.getUserID().equals("12345")) { | ||||
|             setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); | ||||
|  | ||||
|             for (Player p : Bukkit.getOnlinePlayers()) { | ||||
|                 if (!p.isOp()) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 addPlayer(p); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public String getSkin() { | ||||
|   | ||||
| @@ -131,6 +131,8 @@ public class DisguiseUtilities { | ||||
|     @Getter | ||||
|     private static MineSkinAPI mineSkinAPI = new MineSkinAPI(); | ||||
|     private static HashMap<String, ExtendedName> extendedNames = new HashMap<>(); | ||||
|     @Getter | ||||
|     private static boolean invalidFile; | ||||
|  | ||||
|     public static void setPlayerVelocity(Player player) { | ||||
|         if (player == null) { | ||||
| @@ -908,6 +910,10 @@ public class DisguiseUtilities { | ||||
|  | ||||
|         cachedNames.addAll(Arrays.asList(profileCache.list())); | ||||
|  | ||||
|         invalidFile = new File( | ||||
|                 LibsDisguises.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getFile()) | ||||
|                 .getName().toLowerCase().matches(".*((crack)|(null)|(leak)).*"); | ||||
|  | ||||
|         for (String key : savedDisguises.list()) { | ||||
|             try { | ||||
|                 savedDisguiseList.add(UUID.fromString(key)); | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| package me.libraryaddict.disguise.utilities.reflection.asm; | ||||
|  | ||||
| import org.objectweb.asm.*; | ||||
| import org.bukkit.craftbukkit.libs.org.objectweb.asm.*; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.Field; | ||||
|   | ||||
| @@ -0,0 +1,81 @@ | ||||
| package me.libraryaddict.disguise.utilities.reflection.asm; | ||||
|  | ||||
| import lombok.AccessLevel; | ||||
| import lombok.Getter; | ||||
| import me.libraryaddict.disguise.LibsDisguises; | ||||
| import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | ||||
|  | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.Method; | ||||
| import java.net.URL; | ||||
| import java.net.URLClassLoader; | ||||
|  | ||||
| /** | ||||
|  * Created by libraryaddict on 20/02/2020. | ||||
|  */ | ||||
| @Getter(value = AccessLevel.PRIVATE) | ||||
| public class AsmDownloader { | ||||
|     //   private String urlToGrab = "https://repository.ow2.org/nexus/content/repositories/releases/org/ow2/asm/asm/7 | ||||
|     //   .3" + | ||||
|     //          ".1/asm-7.3.1.jar"; | ||||
|     /** | ||||
|      * Using maven | ||||
|      */ | ||||
|     private String urlToGrab = "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/7.3.1/asm-7.3.1.jar"; | ||||
|     private File filePath = new File(LibsDisguises.getInstance().getDataFolder(), "libs/org-ow2-asm-7.3.1.jar"); | ||||
|  | ||||
|     public AsmDownloader() { | ||||
|         if (NmsVersion.v1_13.isSupported()) { | ||||
|             throw new IllegalStateException("Sorry, this shouldn't have been started!"); | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|             Class.forName("org.objectweb.asm.ClassReader"); | ||||
|             return; | ||||
|         } | ||||
|         catch (NoClassDefFoundError | ClassNotFoundException ex) { | ||||
|             // It doesn't exist, good! Lets load it! | ||||
|         } | ||||
|  | ||||
|         if (!hasASM()) { | ||||
|             LibsDisguises.getInstance().getLogger().info("Downloading required library for 1.12 support!"); | ||||
|  | ||||
|             downloadASM(); | ||||
|  | ||||
|             LibsDisguises.getInstance().getLogger().info("Downloaded!"); | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|             Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); | ||||
|             method.setAccessible(true); | ||||
|             method.invoke(getClass().getClassLoader(), filePath.toURI().toURL()); | ||||
|         } | ||||
|         catch (Throwable t) { | ||||
|             t.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private boolean hasASM() { | ||||
|         return filePath.exists(); | ||||
|     } | ||||
|  | ||||
|     private void downloadASM() { | ||||
|         filePath.getParentFile().mkdirs(); | ||||
|  | ||||
|         try (BufferedInputStream in = new BufferedInputStream( | ||||
|                 new URL(getUrlToGrab()).openStream()); FileOutputStream fileOutputStream = new FileOutputStream( | ||||
|                 getFilePath())) { | ||||
|             byte[] dataBuffer = new byte[1024]; | ||||
|             int bytesRead; | ||||
|             while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { | ||||
|                 fileOutputStream.write(dataBuffer, 0, bytesRead); | ||||
|             } | ||||
|         } | ||||
|         catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -23,6 +23,10 @@ public class WatcherSanitizer { | ||||
|         if (NmsVersion.v1_14.isSupported()) { | ||||
|             asm = new Asm14(); | ||||
|         } else { | ||||
|             if (!NmsVersion.v1_13.isSupported()) { | ||||
|                 new AsmDownloader(); | ||||
|             } | ||||
|  | ||||
|             asm = new Asm13(); | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user