Guest User

MultiExploitFix

a guest
Aug 13th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.43 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------
  2. MultiExploitFix
  3. By CaptainShockwave
  4.  
  5. Current Features:
  6. -Reverts over-enchanted items upon use.
  7. --------------------------------------------------------------------------------------------------
  8. package me.captainshockwave.exploitfix;
  9.  
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.net.URL;
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. import java.util.Map.Entry;
  16.  
  17. import org.apache.commons.io.FileUtils;
  18. import org.bukkit.Bukkit;
  19. import org.bukkit.command.Command;
  20. import org.bukkit.command.CommandExecutor;
  21. import org.bukkit.command.CommandSender;
  22. import org.bukkit.enchantments.Enchantment;
  23. import org.bukkit.entity.Player;
  24. import org.bukkit.event.EventHandler;
  25. import org.bukkit.event.Listener;
  26. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  27. import org.bukkit.inventory.ItemStack;
  28. import org.bukkit.plugin.java.JavaPlugin;
  29.  
  30. import net.md_5.bungee.api.ChatColor;
  31.  
  32. public class Main extends JavaPlugin implements CommandExecutor, Listener {
  33.    
  34.     public void onEnable() {
  35.         getCommand("update").setExecutor(this);
  36.         Bukkit.getPluginManager().registerEvents(this, this);
  37.     }
  38.  
  39.     // couldnt figure out how to get the latest version's download
  40.     public static String getLatestVersionUrl() {
  41.         return "spigotmc.org/plugin";
  42.     }
  43.    
  44.     @SuppressWarnings("deprecation")
  45.     @Override
  46.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  47.         if (label.equalsIgnoreCase("update")) {
  48.             if (sender.isOp() || !sender.hasPermission("exploitfix.update"))
  49.             {
  50.                 if (args.length == 0) {
  51.                     sender.sendMessage(ChatColor.YELLOW + "Latest version: " + getLatestVersionUrl() + "\nCopy the url and use /update download <url> to download the update faster");
  52.                 } else if (args[0].equalsIgnoreCase("download")) {
  53.                     if (args.length < 2) {
  54.                         sender.sendMessage(ChatColor.RED + "Please paste the URL to download the update from");
  55.                         return false;
  56.                     }
  57.                        
  58.                     Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(this , new Runnable() {
  59.                         public void run() {
  60.                             try {
  61.                                 sender.sendMessage(ChatColor.YELLOW + "Downloading...");
  62.                                 FileUtils.copyURLToFile(new URL(args[1]), new File("plugins/ExploitFix.jar"));
  63.                                 sender.sendMessage(ChatColor.YELLOW + "Download complete");
  64.                             } catch (IOException e) {
  65.                                 e.printStackTrace();
  66.                             }
  67.                         }
  68.                     });
  69.                 }
  70.             }
  71.         }
  72.         return false;
  73.     }
  74.    
  75.     @EventHandler
  76.     public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
  77.         Player damager = (Player) event.getDamager();
  78.         // prevents item from dealing damage if it was reverted
  79.         event.setCancelled(revert(damager.getInventory().getItemInMainHand()));
  80.     }
  81.    
  82.     // reverts the item
  83.     public boolean revert(ItemStack itemStack) {
  84.         boolean is32k = false;
  85.         if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasEnchants()) {
  86.             Map<Enchantment, Integer> newEnchants = new HashMap<>();
  87.             for (Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet()) {
  88.                 if (entry.getValue() > entry.getKey().getMaxLevel()) {
  89.                     newEnchants.put(entry.getKey(), entry.getKey().getMaxLevel());
  90.                     is32k = true;
  91.                 } else {
  92.                     newEnchants.put(entry.getKey(), entry.getValue());
  93.                 }
  94.                 itemStack.removeEnchantment(entry.getKey());
  95.             }
  96.                 itemStack.addEnchantments(newEnchants);
  97.         }
  98.         return is32k;
  99.     }
  100.    
  101. }
Add Comment
Please, Sign In to add comment