SHARE
TWEET

Untitled

a guest Oct 12th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Made by gush on Oct 12, 2017
  3.  */
  4. package hs.gush.bukkit;
  5.  
  6. import java.util.List;
  7. import java.util.concurrent.Callable;
  8. import java.util.function.BiFunction;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.OfflinePlayer;
  12. import org.bukkit.plugin.Plugin;
  13. import org.bukkit.plugin.PluginManager;
  14.  
  15. import net.milkbowl.vault.economy.Economy;
  16. import net.milkbowl.vault.economy.EconomyResponse;
  17. import net.milkbowl.vault.permission.Permission;
  18.  
  19. //Made by gush on Oct 12, 2017
  20. /**
  21.  * @author gush
  22.  *
  23.  */
  24. public class UncoupledPlugin<T extends Plugin> implements Callable<T>{
  25.    
  26.     final String name;
  27.     final Class<T> clazz;
  28.     final PluginManager pManager;
  29.     @SuppressWarnings("unchecked")
  30.     public UncoupledPlugin(T plugin, PluginManager pManager){
  31.         name = plugin.getName();
  32.         clazz = (Class<T>) plugin.getClass();
  33.         this.pManager = pManager;
  34.     }
  35.     public UncoupledPlugin(T plugin){
  36.         this(plugin,Bukkit.getPluginManager());
  37.     }
  38.     public UncoupledPlugin(Class<? extends Plugin> type, String name){
  39.         this(type,name,Bukkit.getPluginManager());
  40.     }
  41.     @SuppressWarnings("unchecked")
  42.     public UncoupledPlugin(Class<? extends Plugin> type, String name,PluginManager pManager){
  43.         this.clazz = (Class<T>) type;
  44.         this.pManager = pManager;
  45.         this.name = name;
  46.     }
  47.     @Override
  48.     public T call(){
  49.         return getPluginFunc().apply(pManager, name);
  50.     }
  51.     @SuppressWarnings("unchecked")
  52.     private BiFunction<PluginManager, String, T> getPluginFunc(){
  53.        
  54.         return (manager,name)->{
  55.             Plugin plugin = manager.getPlugin(name);
  56.             if(plugin == null)return null;
  57.             else if(plugin.getClass() == clazz)return (T) plugin;
  58.             else return null;
  59.         };
  60.     }
  61. }
RAW Paste Data
Top