WayderTMDEV

Main class

Jul 28th, 2020 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.ArrayList;
  3.  
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.CreatureSpawner;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.inventory.Inventory;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.plugin.Plugin;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. public class Main extends JavaPlugin {
  21. public String prefix;
  22. public String error;
  23. private static Main plugin;
  24. public static String spawnerTitle;
  25. public static ArrayList<String> spawnerlore;
  26.  
  27. public void Setup(Main plugin){
  28. Main.plugin = plugin;
  29. }
  30.  
  31. @Override
  32. public void onEnable() {
  33. //getServer().getPluginManager().registerEvents(this, (Plugin)this);
  34. Bukkit.getPluginManager().registerEvents(new EventHandler(), this);
  35.  
  36. getLogger().info("");
  37. File conf = new File(getDataFolder() + File.separator + "config.yml");
  38. if (!conf.exists()) {
  39. getLogger().info("[+] SLAVA UKRAINE! Creating new Config //config.yml//");
  40. getConfig().options().copyDefaults(true);
  41. saveDefaultConfig();
  42. getLogger().info("[+] GEROYAM SLAVA! Config created");
  43. } else {
  44. getLogger().info("[+] Config exists LOLOOLOLLOLLOLOLOLLOLLOLLL");
  45. }
  46.  
  47. Setup(this);
  48.  
  49. prefix = getConfig().getString("Settings.prefix");
  50. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
  51. error = getConfig().getString("Settings.errormsg");
  52. error = ChatColor.translateAlternateColorCodes('&', error);
  53. spawnerTitle = getConfig().getString("Settings.spawnertitle");
  54. spawnerTitle = ChatColor.translateAlternateColorCodes('&', spawnerTitle);
  55. spawnerlore = (ArrayList<String>) getConfig().getStringList("Settings.spawnerlore");
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62. @SuppressWarnings("null")
  63. public void giveSpawner(Player player , EntityType mob, int lvl, int amount) {
  64. int value = plugin.getConfig().getInt("Settings.value");
  65.  
  66. if(!plugin.getConfig().getConfigurationSection("data").contains(player.getName())) {
  67. plugin.getConfig().createSection("data." + player.getName());
  68. value++;
  69. plugin.getConfig().createSection("data." + player.getName() + "." + plugin.getConfig().getInt("Settings.value"));
  70. plugin.getConfig().addDefault("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnerlvl", lvl);
  71. plugin.getConfig().addDefault("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnermob", mob.toString());
  72. plugin.getConfig().set("Settings.value", value);
  73. plugin.saveConfig();
  74. }
  75. else {
  76. value++;
  77. plugin.getConfig().createSection("data." + player.getName() + "." + plugin.getConfig().getInt("Settings.value"));
  78. plugin.getConfig().set("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnerlvl", lvl);
  79. plugin.getConfig().set("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnermob", mob.toString());
  80. plugin.getConfig().set("Settings.value", value);
  81. plugin.saveConfig();
  82. }
  83. ///////////////////////////////// Проблемное место
  84. spawnerlore.replaceAll((str) -> str.replace('&', '§').replace("%value%", Integer.toString(plugin.getConfig().getInt("Settings.value"))).replace("%lvl%", Integer.toString(lvl).replace("%mob%", mob.toString())));
  85. Inventory inv = player.getInventory();
  86. ItemStack item = ItemUtil.createSpawner(spawnerTitle.replace("%player%", player.getName()), spawnerlore, amount);
  87. /////////////////////////////////////
  88. inv.addItem(item);
  89.  
  90. }
  91.  
  92. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  93.  
  94. if(cmd.getName().equalsIgnoreCase("spawners") && sender.hasPermission("gspawners.spawners") && sender instanceof Player) {
  95. sender.sendMessage("" + prefix + ChatColor.GRAY + "Выдача спавнера: " + ChatColor.YELLOW + "/spawners give [НИК] [Моб капсом на англ] [лвл спавнера] [количество]");
  96.  
  97. if(args.length != 0 && args.length > 0) {
  98. if(args[0].equalsIgnoreCase("give") && sender.hasPermission("gspawners.give") && args.length > 2) {
  99. String mob = args[2];
  100. EntityType et = EntityType.fromName(mob);
  101. int lvl = Integer.valueOf(args[3]);
  102. int amount = Integer.valueOf(args[4]);
  103. Player p = Bukkit.getPlayer(args[1]);
  104. giveSpawner(p, et, lvl, amount);
  105. }
  106.  
  107. else {
  108. sender.sendMessage(prefix + error);
  109. }
  110. }
  111.  
  112. return true;
  113. }
  114. else if(cmd.getName().equalsIgnoreCase("lol") && sender.hasPermission("gspawners.spawners") && sender instanceof Player) {
  115.  
  116. return true;
  117. }
  118. return false;
  119. }
  120.  
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment