Guest User

Untitled

a guest
Feb 14th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. package no.spillere.blowable;
  2.  
  3. import com.google.common.collect.Lists;
  4. import me.clip.placeholderapi.metrics.bukkit.Metrics;
  5. import no.spillere.blowable.handlers.ConfigHandler;
  6. import no.spillere.blowable.handlers.ReloadCommand;
  7. import no.spillere.blowable.listeners.Listener;
  8. import no.spillere.blowable.listeners.SomeExpansion;
  9. import no.spillere.blowable.listeners.WitherListener;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandMap;
  13. import org.bukkit.command.PluginCommand;
  14. import org.bukkit.command.TabCompleter;
  15. import org.bukkit.configuration.file.FileConfiguration;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.plugin.Plugin;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. import java.lang.reflect.Constructor;
  21. import java.lang.reflect.Field;
  22. import java.util.ArrayList;
  23.  
  24. public class BlowablePlugin extends JavaPlugin {
  25.  
  26. public FileConfiguration config;
  27. public int configVersion = 12;
  28.  
  29. public ArrayList<Player> vanished = new ArrayList<>();
  30. public static BlowablePlugin instance;
  31. public static int mc_version;
  32. public static String mc_protocol;
  33. public static Metrics metrics;
  34.  
  35. public final Listener Listener = new Listener(this);
  36. public final WitherListener WitherListener = new WitherListener(this);
  37.  
  38. public void onEnable() {
  39. String pck = getServer().getClass().getPackage().getName();
  40. mc_protocol = pck.substring(pck.lastIndexOf('.') + 1);
  41. String[] split = mc_protocol.replaceFirst("v", "").split("_");
  42. mc_version = Integer.parseInt(split[0] + split[1]);
  43. getLogger().info("Running on server with " + mc_version + " / " + mc_protocol + ".");
  44.  
  45. // Load plugin
  46. instance = this;
  47. loadListeners();
  48. getDataFolder().mkdir();
  49. loadConfig();
  50. registerCommands();
  51. if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
  52. new SomeExpansion().register();
  53. }
  54.  
  55. // Enable bStats
  56. int pluginId = 13883;
  57. metrics = new Metrics(this, pluginId);
  58. }
  59.  
  60. public static BlowablePlugin getInstance()
  61. {
  62. return instance;
  63. }
  64.  
  65. public void loadListeners() {
  66. getServer().getPluginManager().registerEvents(Listener, this);
  67. getServer().getPluginManager().registerEvents(WitherListener, this);
  68. }
  69.  
  70. private void loadConfig() {
  71. config = getConfig();
  72. config.options().copyDefaults(true);
  73. config.addDefault("Config Version", 0);
  74. ConfigHandler.exportConfig();
  75. }
  76.  
  77. private void registerCommands() {
  78. registerCommand("blowable", new ReloadCommand(), "blowableobsidian", "blowableobsidians");
  79. }
  80.  
  81. public void registerCommand(String name, CommandExecutor executor, String... aliases) {
  82. try {
  83. Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
  84. constructor.setAccessible(true);
  85.  
  86. PluginCommand command = constructor.newInstance(name, this);
  87.  
  88. command.setExecutor(executor);
  89. command.setAliases(Lists.newArrayList(aliases));
  90. if (executor instanceof TabCompleter) {
  91. command.setTabCompleter((TabCompleter) executor);
  92. }
  93. this.getCommandMap().register("blowableobsidians", command);
  94. } catch (Exception e) {
  95. e.printStackTrace();
  96. }
  97. }
  98.  
  99. private CommandMap getCommandMap() {
  100. try {
  101. org.bukkit.Server server = Bukkit.getServer();
  102. Field commandMap = server.getClass().getDeclaredField("commandMap");
  103. commandMap.setAccessible(true);
  104. return (CommandMap) commandMap.get(server);
  105. } catch (IllegalAccessException | NoSuchFieldException e) {
  106. e.printStackTrace();
  107. return null;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment