Guest User

ProtocolUtils

a guest
Feb 17th, 2018
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package dashnetwork.protocolsupportpotions.utils;
  2.  
  3. import org.bukkit.entity.Player;
  4.  
  5. import dashnetwork.protocolsupportpotions.main.Main;
  6. import protocolsupport.api.ProtocolSupportAPI;
  7. import us.myles.ViaVersion.api.Via;
  8.  
  9. public class ProtocolUtils {
  10.    
  11.     private static Main plugin = Main.getInstance();
  12.    
  13.     public static boolean getAPI() {
  14.         if (plugin.getServer().getPluginManager().getPlugin("ProtocolSupport") != null) {
  15.             return true;
  16.         }
  17.         else if (plugin.getServer().getPluginManager().getPlugin("ViaVersion") != null) {
  18.             return false;
  19.         }
  20.         else {
  21.             plugin.getLogger().severe("ProtocolSupport or ViaVersion not detected!");
  22.             plugin.getServer().getPluginManager().disablePlugin(plugin);
  23.            
  24.             return false;
  25.         }
  26.     }
  27.    
  28.     private static int getProtocolSupport(Player player) {
  29.         if (ProtocolSupportAPI.getProtocolVersion(player).getName() == null) {
  30.             return -1;
  31.         }
  32.         else {
  33.             return ProtocolSupportAPI.getProtocolVersion(player).getId();
  34.         }
  35.     }
  36.    
  37.     private static int getViaVersion(Player player) {
  38.         return Via.getAPI().getPlayerVersion(player.getUniqueId());
  39.     }
  40.    
  41.     public static boolean isOlder(Player player, boolean value) {
  42.         if (getAPI()) {
  43.             return getProtocolSupport(player) <= (value ? 210 : 47);
  44.         }
  45.         else {
  46.             return getViaVersion(player) <= (value ? 210 : 47);
  47.         }
  48.     }
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment