Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.ArrayList;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.CreatureSpawner;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin {
- public String prefix;
- public String error;
- private static Main plugin;
- public static String spawnerTitle;
- public static ArrayList<String> spawnerlore;
- public void Setup(Main plugin){
- Main.plugin = plugin;
- }
- @Override
- public void onEnable() {
- //getServer().getPluginManager().registerEvents(this, (Plugin)this);
- Bukkit.getPluginManager().registerEvents(new EventHandler(), this);
- getLogger().info("");
- File conf = new File(getDataFolder() + File.separator + "config.yml");
- if (!conf.exists()) {
- getLogger().info("[+] SLAVA UKRAINE! Creating new Config //config.yml//");
- getConfig().options().copyDefaults(true);
- saveDefaultConfig();
- getLogger().info("[+] GEROYAM SLAVA! Config created");
- } else {
- getLogger().info("[+] Config exists LOLOOLOLLOLLOLOLOLLOLLOLLL");
- }
- Setup(this);
- prefix = getConfig().getString("Settings.prefix");
- prefix = ChatColor.translateAlternateColorCodes('&', prefix);
- error = getConfig().getString("Settings.errormsg");
- error = ChatColor.translateAlternateColorCodes('&', error);
- spawnerTitle = getConfig().getString("Settings.spawnertitle");
- spawnerTitle = ChatColor.translateAlternateColorCodes('&', spawnerTitle);
- spawnerlore = (ArrayList<String>) getConfig().getStringList("Settings.spawnerlore");
- }
- @SuppressWarnings("null")
- public void giveSpawner(Player player , EntityType mob, int lvl, int amount) {
- int value = plugin.getConfig().getInt("Settings.value");
- if(!plugin.getConfig().getConfigurationSection("data").contains(player.getName())) {
- plugin.getConfig().createSection("data." + player.getName());
- value++;
- plugin.getConfig().createSection("data." + player.getName() + "." + plugin.getConfig().getInt("Settings.value"));
- plugin.getConfig().addDefault("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnerlvl", lvl);
- plugin.getConfig().addDefault("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnermob", mob.toString());
- plugin.getConfig().set("Settings.value", value);
- plugin.saveConfig();
- }
- else {
- value++;
- plugin.getConfig().createSection("data." + player.getName() + "." + plugin.getConfig().getInt("Settings.value"));
- plugin.getConfig().set("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnerlvl", lvl);
- plugin.getConfig().set("data." + player.getName() + "." + Integer.toString(plugin.getConfig().getInt("Settings.value")) + ".spawnermob", mob.toString());
- plugin.getConfig().set("Settings.value", value);
- plugin.saveConfig();
- }
- ///////////////////////////////// Проблемное место
- spawnerlore.replaceAll((str) -> str.replace('&', '§').replace("%value%", Integer.toString(plugin.getConfig().getInt("Settings.value"))).replace("%lvl%", Integer.toString(lvl).replace("%mob%", mob.toString())));
- Inventory inv = player.getInventory();
- ItemStack item = ItemUtil.createSpawner(spawnerTitle.replace("%player%", player.getName()), spawnerlore, amount);
- /////////////////////////////////////
- inv.addItem(item);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(cmd.getName().equalsIgnoreCase("spawners") && sender.hasPermission("gspawners.spawners") && sender instanceof Player) {
- sender.sendMessage("" + prefix + ChatColor.GRAY + "Выдача спавнера: " + ChatColor.YELLOW + "/spawners give [НИК] [Моб капсом на англ] [лвл спавнера] [количество]");
- if(args.length != 0 && args.length > 0) {
- if(args[0].equalsIgnoreCase("give") && sender.hasPermission("gspawners.give") && args.length > 2) {
- String mob = args[2];
- EntityType et = EntityType.fromName(mob);
- int lvl = Integer.valueOf(args[3]);
- int amount = Integer.valueOf(args[4]);
- Player p = Bukkit.getPlayer(args[1]);
- giveSpawner(p, et, lvl, amount);
- }
- else {
- sender.sendMessage(prefix + error);
- }
- }
- return true;
- }
- else if(cmd.getName().equalsIgnoreCase("lol") && sender.hasPermission("gspawners.spawners") && sender instanceof Player) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment