Guest User

Untitled

a guest
Jul 22nd, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.09 KB | None | 0 0
  1. package de.hannezhd.citybuildsystem;
  2.  
  3. import de.hannezhd.citybuildsystem.Backpack.BackpackCommand;
  4. import de.hannezhd.citybuildsystem.Backpack.BackpackManager;
  5. import de.hannezhd.citybuildsystem.Economy.PayCommand;
  6. import de.hannezhd.citybuildsystem.Economy.RiseCoins;
  7. import de.hannezhd.citybuildsystem.Economy.Risecoins2;
  8. import de.hannezhd.citybuildsystem.Scoreboard.ScoreboardBuilder;
  9. import de.hannezhd.citybuildsystem.TPA.*;
  10. import de.hannezhd.citybuildsystem.commands.*;
  11. import de.hannezhd.citybuildsystem.commands.AdminShop.AdminShopClickListener;
  12. import de.hannezhd.citybuildsystem.commands.AdminShop.AdminShopCommand;
  13. import de.hannezhd.citybuildsystem.commands.homes.DelHomeCommand;
  14. import de.hannezhd.citybuildsystem.commands.homes.HomeCommand;
  15. import de.hannezhd.citybuildsystem.commands.homes.SetHomeCommand;
  16. import de.hannezhd.citybuildsystem.commands.vote.CoinseeCommand;
  17. import de.hannezhd.citybuildsystem.commands.vote.VCShopListener;
  18. import de.hannezhd.citybuildsystem.commands.vote.coins;
  19. import de.hannezhd.citybuildsystem.commands.vote.vcshop;
  20. import de.hannezhd.citybuildsystem.commands.warps.DelWarpsCommand;
  21. import de.hannezhd.citybuildsystem.commands.warps.SetWarpsCommand;
  22. import de.hannezhd.citybuildsystem.commands.warps.WarpCommand;
  23. import de.hannezhd.citybuildsystem.commands.warps.WarpsCommand;
  24. import de.hannezhd.citybuildsystem.listener.InventoryListener;
  25. import de.hannezhd.citybuildsystem.listener.InvseeListener;
  26. import de.hannezhd.citybuildsystem.listener.Joinlistener;
  27. import de.hannezhd.citybuildsystem.listener.RangInfoListener;
  28. import java.io.File;
  29. import java.io.IOException;
  30. import java.sql.SQLException;
  31. import java.util.ArrayList;
  32. import java.util.Arrays;
  33. import java.util.List;
  34.  
  35. import de.hannezhd.citybuildsystem.ränge.RangInfoCommand;
  36. import de.hannezhd.citybuildsystem.util.MYSQLManager;
  37. import de.hannezhd.citybuildsystem.util.RandGUISystem;
  38. import de.hannezhd.citybuildsystem.util.WallGUISystem;
  39. import org.bukkit.Bukkit;
  40. import org.bukkit.command.Command;
  41. import org.bukkit.command.CommandSender;
  42. import org.bukkit.configuration.ConfigurationSection;
  43. import org.bukkit.configuration.file.YamlConfiguration;
  44. import org.bukkit.entity.Player;
  45. import org.bukkit.plugin.PluginManager;
  46. import org.bukkit.plugin.java.JavaPlugin;
  47.  
  48. public final class Citybuild_system extends JavaPlugin {
  49.  
  50. public static String prefix = "§x§b§a§6§c§f§f§lR§x§a§6§6§7§f§f§li§x§9§2§6§2§f§f§ls§x§7§d§5§d§f§f§le§x§6§9§5§8§f§f§l-§x§5§5§5§3§f§f§lC§x§4§1§4§e§f§f§li§x§2§c§4§9§f§f§lt§x§1§8§4§4§f§f§ly§f ● ";
  51. public static String nopermission = prefix + "§cDazu hast du keine Rechte";
  52. private MYSQLManager mysqlManager;
  53. public static Citybuild_system plugin;
  54. private File file;
  55. private YamlConfiguration configuration;
  56. private File votecoinfile;
  57. private File risecoinfile;
  58. private File homefile;
  59. private File backpackfile;
  60. public YamlConfiguration votecoinconfiguration;
  61. public YamlConfiguration risecoinconfiguration;
  62. public YamlConfiguration homeconfiguration;
  63. public YamlConfiguration backpackconfiguration;
  64. private BackpackManager backpackManager;
  65. private static Citybuild_system instance;
  66.  
  67.  
  68. public void onEnable() {
  69. instance = this;
  70.  
  71. this.file = new File("plugins/Citybuild-system", "warps.yml");
  72. this.configuration = YamlConfiguration.loadConfiguration(this.file);
  73. this.registerBukkit();
  74.  
  75. this.votecoinfile = new File("plugins/Citybuild-system", "Votecoin.yml");
  76. this.votecoinconfiguration = YamlConfiguration.loadConfiguration(this.votecoinfile);
  77.  
  78. this.risecoinfile = new File("plugins/Citybuild-system", "money.yml");
  79. this.risecoinconfiguration = YamlConfiguration.loadConfiguration(this.risecoinfile);
  80.  
  81. this.homefile = new File("plugins/Citybuild-system", "homes.yml");
  82. this.homeconfiguration= YamlConfiguration.loadConfiguration(this.homefile);
  83.  
  84. this.backpackfile = new File("plugins/Citybuild-system", "backpack.yml");
  85. this.backpackconfiguration = YamlConfiguration.loadConfiguration(this.backpackfile);
  86. this.registerBukkit();
  87.  
  88. mysqlManager = new MYSQLManager(getDataFolder());
  89. mysqlManager.createTables();
  90. // Überprüfe den Verbindungsstatus
  91. try {
  92. if (mysqlManager.getConnection() != null && !mysqlManager.getConnection().isClosed()) {
  93. getLogger().info("Verbindung zur MySQL-Datenbank hergestellt.");
  94. } else {
  95. getLogger().severe("Verbindung zur MySQL-Datenbank fehlgeschlagen.");
  96. getServer().getPluginManager().disablePlugin(this);
  97. return;
  98. }
  99. } catch (SQLException e) {
  100. throw new RuntimeException(e);
  101. }
  102.  
  103. this.registerBukkit();
  104. this.getCommand("gm").setExecutor(new GmCommand());
  105. this.getCommand("website").setExecutor(new WebsiteCommand());
  106. this.getCommand("warp").setExecutor(new WarpCommand());
  107. this.getCommand("trash").setExecutor(new TrashCanCommand());
  108. this.getCommand("ranginfo").setExecutor(new RangInfoCommand());
  109. this.getCommand("wand").setExecutor(new WallCommand());
  110. this.getCommand("rand").setExecutor(new RandCommand());
  111. this.getCommand("adminshop").setExecutor(new AdminShopCommand(this));
  112. this.getCommand("enderchest").setExecutor(new EnderchestCommand());
  113. this.getCommand("heal").setExecutor(new HealCommand());
  114. this.getCommand("tpa").setExecutor(new TpaCommand());
  115. this.getCommand("tpaccept").setExecutor(new TpacceptCommand());
  116. this.getCommand("tpacancel").setExecutor(new TpaCancelCommand());
  117. this.getCommand("sethome").setExecutor(new SetHomeCommand(this));
  118. this.getCommand("delhome").setExecutor(new DelHomeCommand(this));
  119. this.getCommand("home").setExecutor(new HomeCommand(this));
  120. this.getCommand("tpahere").setExecutor(new TpahereCommand());
  121. this.getCommand("anvil").setExecutor(new AnvilCommand(this));
  122. this.getCommand("workbench").setExecutor(new WorkbenchCommand());
  123. this.getCommand("ptime").setExecutor(new PtimeCommand());
  124. this.getCommand("backpack").setExecutor(new BackpackCommand());
  125. this.getCommand("invsee").setExecutor(new InvseeCommand());
  126. this.getCommand("hat").setExecutor(new HatCommand());
  127.  
  128. //TabCompleter
  129. this.getCommand("gm").setTabCompleter(this);
  130. this.getCommand("votecoins").setTabCompleter(this);
  131. this.getCommand("money").setTabCompleter(this);
  132. this.getCommand("pay").setTabCompleter(this);
  133. this.getCommand("home").setTabCompleter(this);
  134. this.getCommand("delhome").setTabCompleter(this);
  135. this.getCommand("ptime").setTabCompleter(this);
  136. this.getCommand("hat").setTabCompleter(this);
  137.  
  138.  
  139. PluginManager pluginManager = Bukkit.getPluginManager();
  140. pluginManager.registerEvents(new Joinlistener(this), this);
  141. pluginManager.registerEvents(new InventoryListener(), this);
  142. pluginManager.registerEvents(new RangInfoListener(), this);
  143. pluginManager.registerEvents(new WallGUISystem(), this);
  144. pluginManager.registerEvents(new RandGUISystem(), this);
  145. pluginManager.registerEvents(new AdminShopClickListener(this), this);
  146. pluginManager.registerEvents(new ScoreboardBuilder(this), this);
  147. pluginManager.registerEvents(new InvseeListener(), this);
  148.  
  149. VCShopListener listener = new VCShopListener(this);
  150. pluginManager.registerEvents(listener, this);
  151.  
  152. //Backpack
  153. backpackManager = new BackpackManager();
  154.  
  155. System.out.println(" _____ _ _ ______ _ _ _ _____ _ ");
  156. System.out.println("/ __ \\(_)| | | ___ \\ (_)| | | | / ___| | | ");
  157. System.out.println("| / \\/ _ | |_ _ _ | |_/ / _ _ _ | | __| | ______ \\ `--. _ _ ___ | |_ ___ _ __ ___ ");
  158. System.out.println("| | | || __|| | | || ___ \\| | | || || | / _` ||______| `--. \\| | | |/ __|| __| / _ \\| '_ ` _ \\ \n");
  159. System.out.println("| \\__/\\| || |_ | |_| || |_/ /| |_| || || || (_| | /\\__/ /| |_| |\\__ \\| |_ | __/| | | | | |\n");
  160. System.out.println(" \\____/|_| \\__| \\__, |\\____/ \\__,_||_||_| \\__,_| \\____/ \\__, ||___/ \\__| \\___||_| |_| |_|\n");
  161. System.out.println(" __/ | __/ | \n");
  162. System.out.println(" |___/ |___/ \n");
  163. }
  164. private void registerBukkit() {
  165. this.getCommand("setwarps").setExecutor(new SetWarpsCommand(this));
  166. this.getCommand("warps").setExecutor(new WarpsCommand(this));
  167. this.getCommand("delwarps").setExecutor(new DelWarpsCommand(this));
  168. this.getCommand("votecoins").setExecutor(new coins(this));
  169. this.getCommand("votecoinssee").setExecutor(new CoinseeCommand(this));
  170. this.getCommand("vcshop").setExecutor(new vcshop(this));
  171. this.getCommand("money").setExecutor(new RiseCoins(this));
  172. this.getCommand("pay").setExecutor(new PayCommand(this));
  173. this.getCommand("money2").setExecutor(new Risecoins2());
  174. }
  175.  
  176. //Tab Completer
  177. @Override
  178. public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
  179. if (cmd.getName().equalsIgnoreCase("gm")) {
  180. if (args.length == 1) {
  181. return Arrays.asList("0", "1", "2", "3");
  182. } else if (args.length == 2) {
  183. List<String> playerNames = new ArrayList<>();
  184. for (Player player : Bukkit.getOnlinePlayers()) {
  185. playerNames.add(player.getName());
  186. }
  187. return playerNames;
  188. }
  189. } else if (cmd.getName().equalsIgnoreCase("votecoins")) {
  190. if (args.length == 1) {
  191. return Arrays.asList("add", "set", "remove");
  192. } else if (args.length == 2) {
  193. List<String> playerNames = new ArrayList<>();
  194. for (Player player : Bukkit.getOnlinePlayers()) {
  195. playerNames.add(player.getName());
  196. }
  197. return playerNames;
  198. } else if (args.length == 3) {
  199. return Arrays.asList("1", "10", "100", "1000");
  200. }
  201. } else if (cmd.getName().equalsIgnoreCase("money")) {
  202. if (args.length == 1) {
  203. return Arrays.asList("add", "set", "remove", "see");
  204. } else if (args.length == 2) {
  205. List<String> playerNames = new ArrayList<>();
  206. for (Player player : Bukkit.getOnlinePlayers()) {
  207. playerNames.add(player.getName());
  208. playerNames.add("*");
  209. }
  210. return playerNames;
  211. } else if (args.length == 3) {
  212. return Arrays.asList("1", "10", "100", "1000");
  213. }
  214. } else if (cmd.getName().equalsIgnoreCase("pay")) {
  215. if (args.length == 2) {
  216. return Arrays.asList("1", "10", "100", "1000");
  217. }
  218. } else if (cmd.getName().equalsIgnoreCase("home")) {
  219. Player player = (Player) sender;
  220. if (args.length == 1) {
  221. YamlConfiguration cfg = this.getHomeconfiguration();
  222. ConfigurationSection section = cfg.getConfigurationSection(player.getUniqueId().toString());
  223. if (section != null) {
  224. List<String> homes = new ArrayList<>(section.getKeys(false));
  225. // Filtere Homes basierend auf den bisherigen Argumenten
  226. String partialHomeName = args[0];
  227. homes.removeIf(homeName -> !homeName.startsWith(partialHomeName));
  228. return homes;
  229. }
  230. }
  231. } else if (cmd.getName().equalsIgnoreCase("delhome")) {
  232. Player player = (Player) sender;
  233. if (args.length == 1) {
  234. YamlConfiguration cfg = this.getHomeconfiguration();
  235. ConfigurationSection section = cfg.getConfigurationSection(player.getUniqueId().toString());
  236. if (section != null) {
  237. List<String> homes = new ArrayList<>(section.getKeys(false));
  238. // Filtere Homes basierend auf den bisherigen Argumenten
  239. String partialHomeName = args[0];
  240. homes.removeIf(homeName -> !homeName.startsWith(partialHomeName));
  241. return homes;
  242. }
  243. }
  244. } else if (cmd.getName().equalsIgnoreCase("ptime")) {
  245. Player player = (Player) sender;
  246. if (args.length == 1) {
  247. return Arrays.asList("day","night","reset","get");
  248. }
  249.  
  250. } else if (cmd.getName().equalsIgnoreCase("hat")) {
  251. Player player = (Player) sender;
  252. if (args.length == 1) {
  253. return Arrays.asList("remove", "off", "0");
  254. }
  255.  
  256. }
  257. return null;
  258. }
  259.  
  260. public static Citybuild_system getPlugin() {
  261. return instance;
  262. }
  263.  
  264. public void onDisable() {
  265. // Trenne die Verbindung zur MySQL-Datenbank
  266. mysqlManager.disconnect();
  267. getLogger().info("Verbindung zur MySQL-Datenbank getrennt.");
  268.  
  269. try {
  270. this.configuration.save(this.file);
  271. } catch (IOException var2) {
  272. throw new RuntimeException(var2);
  273. }
  274. backpackManager.save();
  275.  
  276. try {
  277. this.configuration.save(this.file);
  278. this.votecoinconfiguration.save(this.votecoinfile);
  279. this.risecoinconfiguration.save(this.risecoinfile);
  280. this.homeconfiguration.save(this.homefile);
  281. this.backpackconfiguration.save(this.backpackfile);
  282. } catch (IOException var2) {
  283. throw new RuntimeException(var2);
  284. }
  285.  
  286. }
  287.  
  288. public YamlConfiguration getConfiguration() {
  289. return this.configuration;
  290. }
  291.  
  292. public YamlConfiguration getVotecoinconfiguration() {
  293. return this.votecoinconfiguration;
  294. }
  295.  
  296. public YamlConfiguration getRisecoinconfiguration() {
  297. return this.risecoinconfiguration;
  298. }
  299. public YamlConfiguration getHomeconfiguration() {
  300. return this.homeconfiguration;
  301. }
  302. public YamlConfiguration getBackpackconfiguration() {
  303. return this.backpackconfiguration;
  304. }
  305. public BackpackManager getBackpackManager() {
  306. return backpackManager;
  307. }
  308. public static Citybuild_system getInstance() {
  309. return instance;
  310. }
  311. public void saveConfiguration() {
  312. try {
  313. configuration.save(file);
  314. } catch (IOException e) {
  315. getLogger().severe("Fehler beim Speichern der Konfigurationsdatei: " + e.getMessage());
  316. }
  317. }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment