Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.52 KB | None | 0 0
  1. package me.flo.hub;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Location;
  11. import org.bukkit.Material;
  12. import org.bukkit.Sound;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.configuration.InvalidConfigurationException;
  16. import org.bukkit.configuration.file.YamlConfiguration;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.event.EventHandler;
  19. import org.bukkit.event.EventPriority;
  20. import org.bukkit.event.Listener;
  21. import org.bukkit.event.block.Action;
  22. import org.bukkit.event.block.BlockBreakEvent;
  23. import org.bukkit.event.block.BlockPlaceEvent;
  24. import org.bukkit.event.entity.EntityDamageEvent;
  25. import org.bukkit.event.inventory.InventoryClickEvent;
  26. import org.bukkit.event.player.PlayerDropItemEvent;
  27. import org.bukkit.event.player.PlayerInteractEvent;
  28. import org.bukkit.event.player.PlayerJoinEvent;
  29. import org.bukkit.event.player.PlayerKickEvent;
  30. import org.bukkit.event.player.PlayerQuitEvent;
  31. import org.bukkit.inventory.ItemStack;
  32. import org.bukkit.inventory.meta.ItemMeta;
  33. import org.bukkit.plugin.java.JavaPlugin;
  34.  
  35. public class Hub extends JavaPlugin implements Listener {
  36.     /*
  37.      * Plugin by Flo
  38.      *
  39.      */
  40.     //Config
  41.     YamlConfiguration db = new YamlConfiguration();
  42.    
  43.     //Database
  44.     File dbfile = new File(getDataFolder(), "db.yml");
  45.    
  46.     //Prefix
  47.     String prefix = "§c[§3mHub§c] ";  
  48.    
  49.     //Timeoutlist
  50.     ArrayList<Player> timeout = new ArrayList<Player>();
  51.    
  52.     //Teleporter Inventory
  53.     HashMap<Player, ItemStack[]> save = new HashMap<Player, ItemStack[]>();
  54.    
  55.     //Teleporter Edit Mode
  56.     ArrayList<Player> teledit = new ArrayList<Player>();
  57.     HashMap<Player, ItemStack[]> tsave = new HashMap<Player, ItemStack[]>();
  58.    
  59.    
  60.    
  61.    
  62.     public void onEnable() {
  63.         this.getServer().getPluginManager().registerEvents(this, this);
  64.         config();
  65.         dbconf();
  66.     }
  67.    
  68.     public void onDisable() {
  69.  
  70.     }
  71.    
  72.     public void config() {
  73.         String conspref = "[mHub] ";
  74.         int fu = 0;
  75.         if (!(this.getConfig().getString("Update") == null)) {
  76.             if (!(this.getConfig().getString("Update") == "2")) {
  77.                 fu = 1;
  78.             }
  79.         }
  80.         File configfile = new File(getDataFolder(), "config.yml");
  81.         if(!configfile.exists() || fu == 1){
  82.             System.out.println(conspref + "No config.yml found.");
  83.             System.out.println(conspref + "New config.yml created.");
  84.             this.reloadConfig();
  85.             this.getConfig().addDefault("Update", "1");
  86.             this.getConfig().addDefault("General.autospawntp", true);
  87.             this.getConfig().addDefault("General.nopermission", "&c[§3mHub§c] &4You don't have permissions to execute this command.");
  88.             this.getConfig().addDefault("Items.teleportername", "&6Teleporter");
  89.             this.getConfig().addDefault("Items.playerson", "&2Players: On");
  90.             this.getConfig().addDefault("Items.playersoff", "&cPlayers: Off");
  91.             this.getConfig().addDefault("Items.visibilitydelay", 5);
  92.             this.getConfig().addDefault("Items.delaymessage", "&c[§3mHub§c] &4Please wait $time seconds before you use this item again.");
  93.             this.getConfig().addDefault("Items.backitem", "&4Back");
  94.             this.getConfig().options().copyDefaults(true);
  95.            
  96.        
  97.             this.saveConfig();
  98.         } else {
  99.             System.out.println(conspref + "config.yml sucessful loaded.");
  100.         }
  101.     }
  102.    
  103.     @SuppressWarnings("static-access")
  104.     public void dbconf() {
  105.  
  106.         db = db.loadConfiguration(dbfile);
  107.         int fu = 0;
  108.         if (!(db.getString("Update") == null)) {
  109.             if (!(db.getString("Update") == "2")) { // FIX BEFORE RELEASE! SET CORRECT NUMBER!
  110.                 fu = 1;
  111.             }
  112.         }
  113.        
  114.        
  115.        
  116.         if(!dbfile.exists() || fu == 1){
  117.             try {
  118.                 dbfile.createNewFile();
  119.             } catch (IOException e) {
  120.                 e.printStackTrace();
  121.             }
  122.             try {
  123.                 db.load(dbfile);
  124.             } catch (IOException | InvalidConfigurationException e1) {
  125.                 e1.printStackTrace();
  126.             }
  127.             db.options().header("This is a DB file for saving informations from the plugin. DONT EDIT!");
  128.             db.addDefault("Update", 1);
  129.             db.addDefault("General.spawnworld", "unset");
  130.             db.addDefault("General.spawncorx", 0);
  131.             db.addDefault("General.spawncory", 0);
  132.             db.addDefault("General.spawncorz", 0);
  133.             db.addDefault("General.spawnyaw", 0);
  134.             db.addDefault("General.spawnpitch", 0);
  135.            
  136.             db.addDefault("s0.x", 0);
  137.             db.addDefault("s0.y", 0);
  138.             db.addDefault("s0.z", 0);
  139.             db.addDefault("s0.ya", 0);
  140.             db.addDefault("s0.p", 0);
  141.             db.addDefault("s0.name", "noname");
  142.             db.addDefault("s0.id", 1);
  143.            
  144.            
  145.             db.addDefault("s1.x", 0);
  146.             db.addDefault("s1.y", 0);
  147.             db.addDefault("s1.z", 0);
  148.             db.addDefault("s1.ya", 0);
  149.             db.addDefault("s1.p", 0);
  150.             db.addDefault("s1.name", "noname");
  151.             db.addDefault("s1.id", 1);
  152.            
  153.            
  154.             db.addDefault("s2.x", 0);
  155.             db.addDefault("s2.y", 0);
  156.             db.addDefault("s2.z", 0);
  157.             db.addDefault("s2.ya", 0);
  158.             db.addDefault("s2.p", 0);
  159.             db.addDefault("s2.name", "noname");
  160.             db.addDefault("s2.id", 1);
  161.            
  162.            
  163.             db.addDefault("s3.x", 0);
  164.             db.addDefault("s3.y", 0);
  165.             db.addDefault("s3.z", 0);
  166.             db.addDefault("s3.ya", 0);
  167.             db.addDefault("s3.p", 0);
  168.             db.addDefault("s3.name", "noname");
  169.             db.addDefault("s3.id", 1);
  170.            
  171.            
  172.             db.addDefault("s4.x", 0);
  173.             db.addDefault("s4.y", 0);
  174.             db.addDefault("s4.z", 0);
  175.             db.addDefault("s4.ya", 0);
  176.             db.addDefault("s4.p", 0);
  177.             db.addDefault("s4.name", "noname");
  178.             db.addDefault("s4.id", 1);
  179.            
  180.            
  181.             db.addDefault("s5.x", 0);
  182.             db.addDefault("s5.y", 0);
  183.             db.addDefault("s5.z", 0);
  184.             db.addDefault("s5.ya", 0);
  185.             db.addDefault("s5.p", 0);
  186.             db.addDefault("s5.name", "noname");
  187.             db.addDefault("s5.id", 1);
  188.            
  189.            
  190.             db.addDefault("s6.x", 0);
  191.             db.addDefault("s6.y", 0);
  192.             db.addDefault("s6.z", 0);
  193.             db.addDefault("s6.ya", 0);
  194.             db.addDefault("s6.p", 0);
  195.             db.addDefault("s6.name", "noname");
  196.             db.addDefault("s6.id", 1);
  197.            
  198.            
  199.             db.addDefault("s7.x", 0);
  200.             db.addDefault("s7.y", 0);
  201.             db.addDefault("s7.z", 0);
  202.             db.addDefault("s7.ya", 0);
  203.             db.addDefault("s7.p", 0);
  204.             db.addDefault("s7.name", "noname");
  205.             db.addDefault("s7.id", 1);
  206.            
  207.    
  208.            
  209.            
  210.             db.options().copyDefaults(true);
  211.             try {
  212.                 db.save(dbfile);
  213.             } catch (IOException e) {
  214.                 e.printStackTrace();
  215.             }
  216.         } else {
  217.         }
  218.     }
  219.    
  220.     @EventHandler(priority = EventPriority.HIGHEST)
  221.     public void onBlockPlace(BlockPlaceEvent e) {
  222.         Player p = e.getPlayer();
  223.         if (!(p.hasPermission("mhub.bypass"))) {
  224.             e.setCancelled(true);
  225.         }
  226.     }
  227.    
  228.     @EventHandler(priority = EventPriority.HIGHEST)
  229.     public void onBlockDestroy(BlockBreakEvent e) {
  230.         Player p = e.getPlayer();
  231.         if (!(p.hasPermission("mhub.bypass"))) {
  232.             e.setCancelled(true);
  233.         }
  234.     }
  235.    
  236.     @EventHandler(priority = EventPriority.HIGHEST)
  237.     public void onPlayerQuit(PlayerQuitEvent e) {
  238.         Player p = e.getPlayer();
  239.         if (tsave.containsKey(p)) {
  240.             p.getInventory().setContents(tsave.get(p));
  241.             p.updateInventory();
  242.             tsave.remove(p);
  243.             teledit.remove(p);
  244.         }
  245.     }
  246.    
  247.     @EventHandler(priority = EventPriority.HIGHEST)
  248.     public void onPlayerKick(PlayerKickEvent e) {
  249.         Player p = e.getPlayer();
  250.         if (tsave.containsKey(p)) {
  251.             p.getInventory().setContents(tsave.get(p));
  252.             p.updateInventory();
  253.             tsave.remove(p);
  254.             teledit.remove(p);
  255.         }
  256.     }
  257.    
  258.    
  259.     public boolean onCommand(CommandSender sender, Command cmd, String laben, String[] args) {
  260.        
  261.         Player p = (Player) sender;
  262.         String noperm = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("General.nopermission"));
  263.        
  264.         if (cmd.getName().equalsIgnoreCase("mhub-setspawn")) {
  265.             if (p.hasPermission("mhub.setspawn")) {
  266.                 db.set("General.spawnworld", p.getLocation().getWorld().getName());
  267.                 db.set("General.spawncorx", p.getLocation().getX());
  268.                 db.set("General.spawncory", p.getLocation().getY());
  269.                 db.set("General.spawncorz", p.getLocation().getZ());
  270.                 db.set("General.spawnyaw", p.getLocation().getYaw());
  271.                 db.set("General.spawnpitch", p.getLocation().getPitch());
  272.                 sc();
  273.                 p.sendMessage(prefix + "§aHub spawn successful set!");
  274.                
  275.             } else {
  276.                 p.sendMessage(noperm);
  277.             }
  278.            
  279.         }
  280.         if (cmd.getName().equalsIgnoreCase("mhub-edit-teleporter")) {
  281.             if (p.hasPermission("mhub.editteleporter")) {
  282.                 if (teledit.contains(p)) {
  283.                     teledit.remove(p);
  284.                     p.getInventory().setContents(tsave.get(p));
  285.                     tsave.remove(p);
  286.                     p.sendMessage(prefix + "§2You are no longer in the teleporter edit mode.");
  287.                     saveInvItem(p, "s0", 0);
  288.                     saveInvItem(p, "s1", 1);
  289.                     saveInvItem(p, "s2", 2);
  290.                     saveInvItem(p, "s3", 3);
  291.                     saveInvItem(p, "s4", 4);
  292.                     saveInvItem(p, "s5", 5);
  293.                     saveInvItem(p, "s6", 6);
  294.                     saveInvItem(p, "s7", 7);
  295.                    
  296.                 } else {
  297.                     teledit.add(p);
  298.                     tsave.put(p, p.getInventory().getContents());
  299.                     p.sendMessage(prefix + "§2You are now in the teleporter edit mode.");
  300.                     p.sendMessage("");
  301.                     p.sendMessage(prefix + "§aAdd a Item into one hotbar slot from slot §c1 §ato §c8§a.");
  302.                     p.sendMessage(prefix + "§aRightclick on the item on a position to set the warp point.");
  303.                     p.sendMessage(prefix + "§aIf you are finished, type '/mhub-edit-teleporter' again");
  304.                     setInvItem(p, "s0", 0, "§0§r§r");
  305.                     setInvItem(p, "s1", 1, "§1§r§r");
  306.                     setInvItem(p, "s2", 2, "§2§r§r");
  307.                     setInvItem(p, "s3", 3, "§3§r§r");
  308.                     setInvItem(p, "s4", 4, "§4§r§r");
  309.                     setInvItem(p, "s5", 5, "§5§r§r");
  310.                     setInvItem(p, "s6", 6, "§6§r§r");
  311.                     setInvItem(p, "s7", 7, "§7§r§r");
  312.                 }
  313.             } else {
  314.                 p.sendMessage(noperm);
  315.             }
  316.         }
  317.            
  318.        
  319.        
  320.         return true;
  321.  
  322.        
  323.     }
  324.    
  325.    
  326.     @EventHandler(priority = EventPriority.HIGHEST)
  327.     public void onItemDrop(PlayerDropItemEvent e) {
  328.         Player p = e.getPlayer();
  329.         if (!(p.hasPermission("mhub.items.bypass"))) {
  330.             e.setCancelled(true);
  331.         }
  332.     }  
  333.     @EventHandler(priority = EventPriority.HIGHEST)
  334.     public void onInvClick(InventoryClickEvent e) {
  335.        
  336.         Player p = (Player) e.getWhoClicked();
  337.         if (!teledit.contains(p)) {
  338.             if (!(p.hasPermission("mhub.items.bypass"))) {
  339.                 e.setCancelled(true);
  340.             }
  341.         }
  342.     }
  343.    
  344.     @EventHandler(priority = EventPriority.HIGHEST)
  345.     public void onDamage(EntityDamageEvent e) {
  346.         if (e.getEntity() instanceof Player) {
  347.             Player p = (Player) e.getEntity();
  348.             if (!(p.hasPermission("mhub.items.bypass"))) {
  349.                 e.setCancelled(true);
  350.             }
  351.         }
  352.     }
  353.    
  354.    
  355.  
  356.    
  357.     @EventHandler(priority = EventPriority.HIGHEST)
  358.     public void onInteract(PlayerInteractEvent e) {
  359.         Player p = e.getPlayer();
  360.         if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
  361.         if (e.getItem() != null) {
  362.         if (e.getItem().getItemMeta().getDisplayName() != null) {
  363.             //Visibility Switcher
  364.             if (e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&',
  365.                 this.getConfig().getString("Items.playerson"))) ||
  366.                 e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&'
  367.                         , this.getConfig().getString("Items.playersoff")))) {
  368.             switchv(p);
  369.            
  370.             }
  371.            
  372.            
  373.        
  374.             if (e.getItem().getItemMeta().getDisplayName()
  375.                     .equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.teleportername")))) {
  376.                
  377.                 teleporter(p);
  378.                
  379.             }
  380.            
  381.            
  382.             if (e.getItem().getItemMeta().getDisplayName().contains("§8§r§r")) {
  383.                     p.getInventory().setContents(save.get(p));
  384.                     save.remove(p);
  385.                     p.updateInventory();
  386.             }
  387.        
  388.        
  389.        
  390.         }}}
  391.        
  392.     }
  393.    
  394.    
  395.    
  396.     @SuppressWarnings("deprecation")
  397.     @EventHandler(priority = EventPriority.HIGHEST)
  398.     public void onPlayerJoin(PlayerJoinEvent e) {
  399.         Player p = e.getPlayer();
  400.         db.addDefault(p.getUniqueId().toString() + ".vis", "on");
  401.        
  402.         if (this.getConfig().getBoolean("General.autospawntp") == true) {
  403.             if (db.getString("General.spawnworld").equalsIgnoreCase("unset")) {
  404.                 for (Player allp : Bukkit.getOnlinePlayers()) {
  405.                     if (allp.isOp()) {
  406.                         allp.sendMessage(prefix + "A player is joined, but the spawn isn't set.");
  407.                         allp.sendMessage(prefix + "Please set the spawn with '/mhub-setspawn' or disable autospawntp in the config.yml");
  408.                     }
  409.                 }
  410.             } else {
  411.                
  412.                 Location spawnloc = new Location(Bukkit.getWorld(db.getString("General.spawnworld")),
  413.                         db.getDouble("General.spawncorx"), db.getDouble("General.spawncory"),
  414.                         db.getDouble("General.spawncorz"), (float) db.getDouble("General.spawnyaw"), (float) db.getDouble("General.spawnpitch"));    
  415.                 p.teleport(spawnloc);
  416.             }
  417.         }
  418.    
  419.         if (!(p.hasPermission("mhub.items.bypass"))) {
  420.             p.getInventory().clear();
  421.             p.getInventory().setHeldItemSlot(4);
  422.             ItemStack teleporter = new ItemStack(Material.COMPASS, 1);
  423.             ItemMeta teleportermeta = teleporter.getItemMeta();
  424.             teleportermeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.teleportername")));
  425.             teleporter.setItemMeta(teleportermeta);
  426.             p.getInventory().setItem(4, teleporter);
  427.            
  428.             if (db.getString(p.getUniqueId().toString() + ".vis") != null) {
  429.                 if (db.getString(p.getUniqueId().toString() + ".vis").equalsIgnoreCase("on")) {
  430.                     ItemStack playerson = new ItemStack(Material.getMaterial(351), 1, (byte) 10);
  431.                     ItemMeta playersonmeta = playerson.getItemMeta();
  432.                     playersonmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playerson")));
  433.                     playerson.setItemMeta(playersonmeta);
  434.                     p.getInventory().setItem(3, playerson);
  435.                 }
  436.             } else {
  437.                 ItemStack playerson = new ItemStack(Material.getMaterial(351), 1, (byte) 10);
  438.                 ItemMeta playersonmeta = playerson.getItemMeta();
  439.                 playersonmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playerson")));
  440.                 playerson.setItemMeta(playersonmeta);
  441.                 p.getInventory().setItem(3, playerson);
  442.             }
  443.            
  444.             if (db.getString(p.getUniqueId().toString() + ".vis") != null) {
  445.                 if (db.getString(p.getUniqueId().toString() + ".vis").equalsIgnoreCase("off")) {
  446.                 ItemStack playersoff = new ItemStack(Material.getMaterial(351), 1, (byte) 1);
  447.                 ItemMeta playersoffmeta = playersoff.getItemMeta();
  448.                 playersoffmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playersoff")));
  449.                 playersoff.setItemMeta(playersoffmeta);
  450.                 p.getInventory().setItem(3, playersoff);
  451.                 }
  452.                 for (Player allp : Bukkit.getOnlinePlayers()) {
  453.                     p.hidePlayer(allp);
  454.                 }
  455.             }
  456.            
  457.         }
  458.     }
  459.    
  460.    
  461.     @SuppressWarnings("deprecation")
  462.     public void switchv(Player p) {
  463.         if (timeout.contains(p)) {
  464.             p.playSound(p.getLocation(), Sound.FIZZ, 1, 1);
  465.             p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.delaymessage")).replace("$time", "" + this.getConfig().getInt("Items.visibilitydelay")));
  466.         } else {
  467.         if (db.getString(p.getUniqueId().toString() + ".vis") == null) {
  468.             db.set(p.getUniqueId().toString() + ".vis", "off"); sc();
  469.             ItemStack playersoff = new ItemStack(Material.getMaterial(351), 1, (byte) 1);
  470.             ItemMeta playersoffmeta = playersoff.getItemMeta();
  471.             playersoffmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playersoff")));
  472.             playersoff.setItemMeta(playersoffmeta);
  473.             p.getInventory().setItem(3, playersoff);
  474.             for (Player allp : Bukkit.getOnlinePlayers()) {
  475.                 p.hidePlayer(allp);
  476.             }
  477.             p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
  478.         } else {
  479.             if (db.getString(p.getUniqueId().toString() + ".vis").equalsIgnoreCase("on")) {
  480.                 db.set(p.getUniqueId().toString() + ".vis", "off"); sc();
  481.                 for (Player allp : Bukkit.getOnlinePlayers()) {
  482.                     p.hidePlayer(allp);
  483.                 }
  484.                 db.set(p.getUniqueId().toString() + ".vis", "off"); sc();
  485.                 ItemStack playersoff = new ItemStack(Material.getMaterial(351), 1, (byte) 1);
  486.                 ItemMeta playersoffmeta = playersoff.getItemMeta();
  487.                 playersoffmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playersoff")));
  488.                 playersoff.setItemMeta(playersoffmeta);
  489.                 p.getInventory().setItem(3, playersoff);
  490.                 p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
  491.             } else {
  492.                 db.set(p.getUniqueId().toString() + ".vis", "on"); sc();
  493.                 for (Player allp : Bukkit.getOnlinePlayers()) {
  494.                     p.showPlayer(allp);
  495.                 }
  496.                 ItemStack playerson = new ItemStack(Material.getMaterial(351), 1, (byte) 10);
  497.                 ItemMeta playersonmeta = playerson.getItemMeta();
  498.                 playersonmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.playerson")));
  499.                 playerson.setItemMeta(playersonmeta);
  500.                 p.getInventory().setItem(3, playerson);
  501.                 p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
  502.             }
  503.         }
  504.         timeout.add(p);
  505.         this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  506.  
  507.             @Override
  508.             public void run() {
  509.                 timeout.remove(p);
  510.                
  511.             }
  512.            
  513.         }, 20*this.getConfig().getInt("Items.visibilitydelay"));
  514.         }
  515.        
  516.        
  517.        
  518.     }
  519.    
  520.    
  521.     public void sc() {
  522.         try {
  523.             db.save(dbfile);
  524.         } catch (IOException e) {
  525.             e.printStackTrace();
  526.         }
  527.     }
  528.    
  529.    
  530.     public void teleporter(Player pl) {
  531.         save.put(pl, pl.getInventory().getContents());     
  532.        
  533.         setInvItem(pl, "s0", 0, "§0§r§r");
  534.         setInvItem(pl, "s1", 1, "§1§r§r");
  535.         setInvItem(pl, "s2", 2, "§2§r§r");
  536.         setInvItem(pl, "s3", 3, "§3§r§r");
  537.         setInvItem(pl, "s4", 4, "§4§r§r");
  538.         setInvItem(pl, "s5", 5, "§5§r§r");
  539.         setInvItem(pl, "s6", 6, "§6§r§r");
  540.         setInvItem(pl, "s7", 7, "§7§r§r");
  541.         ItemStack Back = new ItemStack(Material.BARRIER);
  542.         ItemMeta Meta = Back.getItemMeta();
  543.         Meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Items.backitem")) + " " + "§8§r§r");
  544.         Back.setItemMeta(Meta);
  545.        
  546.         pl.getInventory().setItem(8, Back);
  547.    
  548.         pl.updateInventory();
  549.     }
  550.    
  551.    
  552.     public void setInvItem(Player p, String slot, int SlotNum, String identity) {
  553.         @SuppressWarnings("deprecation")
  554.         ItemStack Item = new ItemStack(Material.getMaterial(db.getInt(slot + ".id")));
  555.         ItemMeta Meta = Item.getItemMeta();
  556.             Meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', db.getString(slot + ".name")) + " " + identity);
  557.         Item.setItemMeta(Meta);
  558.         p.getInventory().setItem(SlotNum, Item);
  559.         p.updateInventory();
  560.     }
  561.    
  562.    
  563.     @SuppressWarnings("deprecation")
  564.     public void saveInvItem(Player p, String slot, int SlotNum) {
  565.         p.sendMessage("" + SlotNum);
  566.         db.set(slot + ".id", p.getInventory().getItem(SlotNum).getTypeId());
  567.         if (p.getInventory().getItem(SlotNum).getItemMeta().hasDisplayName()) {
  568.             db.set(slot + ".name", p.getInventory().getItem(SlotNum).getItemMeta().getDisplayName().toString());
  569.         }
  570.         p.updateInventory();
  571.     }
  572.  
  573.  
  574. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement