Need help on a Code!

Discussion in 'Spigot Plugin Help' started by Timuh, Oct 5, 2013.

  1. ok i need help on setting a item on slot inventory #2 i dont want it to be on slot inventory #1

    Code:

    public class MagicClock extends JavaPlugin {

    private Logger logger = Logger.getLogger("Minecraft.MagicClock");
    private PluginDescriptionFile pdfFile;

    public PlayerListener pl;
    public HistoryHandler hl;

    public void onEnable() {
    pl = new PlayerListener(this);
    hl = new HistoryHandler(this);
    loadConfig();
    pdfFile = this.getDescription();
    logger.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " enabled!");
    }

    public void onDisable() {
    logger.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " disabled!");
    }

    private void loadConfig() {
    this.getConfig().addDefault("cooldown", 5);
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    }

    public ItemStack getClock() {
    ItemStack is = new ItemStack(Material.WATCH);
    List<String> lores = new ArrayList<String>();
    lores.add(ChatColor.GREEN + "Toggle visibility of all players in the lobby!");
    ItemMeta im = is.getItemMeta();
    im.setLore(lores);
    im.setDisplayName(ChatColor.YELLOW + "Magic Clock");
    is.setItemMeta(im);
    return is;
    }

    public String timeUntil(Long sec) {
    Integer buf;
    if (sec < 60*2) {
    buf = Math.round(sec);
    return buf + " second" + (buf==1?"":"s");
    }
    if (sec < 3600*2) {
    buf = Math.round(sec/60);
    return buf + " minute" + (buf==1?"":"s");
    }
    if (sec < 86400*2) {
    buf = Math.round(sec/3600);
    return buf + " hour" + (buf==1?"":"s");
    }
    buf = Math.round(sec/86400);
    return buf + " day" + (buf==1?"":"s");
    }
    }
    public class PlayerListener implements Listener {

    private static MagicClock plugin;

    public PlayerListener(MagicClock instance) {
    plugin = instance;
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    if (HistoryHandler.getState(player.getName())) {
    for (Player players : Bukkit.getOnlinePlayers()) {
    player.hidePlayer(players);
    }
    }
    for (Player players : Bukkit.getOnlinePlayers()) {
    if (HistoryHandler.getState(players.getName())) {
    players.hidePlayer(player);
    }
    }
    ItemStack[] contents = player.getInventory().getContents();
    List<String> lore = plugin.getClock().getItemMeta().getLore();
    boolean hasitem = false;
    for (ItemStack is : contents) {
    if (contents == null || is == null) {
    hasitem = false;
    break;
    }
    else if (is.getItemMeta().getLore().equals(lore)) {
    return;
    }
    }
    if (!hasitem) {
    HistoryHandler.setState(player.getName(), true, new Date().getTime() / 1000);
    player.getInventory().addItem(plugin.getClock());
    }
    }


    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerDropItem(final PlayerDropItemEvent event) {
    List<String> lore = plugin.getClock().getItemMeta().getLore();

    if (event.getItemDrop().getItemStack().getItemMeta().getLore() != null) {
    if (event.getItemDrop().getItemStack().getItemMeta().getLore().equals(lore)) {
    event.setCancelled(true);
    }
    }
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    @Override
    public void run() {
    event.getPlayer().updateInventory();}
    });
    }

    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
    event.getPlayer().getInventory().addItem(plugin.getClock());
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
    event.getDrops().remove(plugin.getClock());
    }

    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (player.getInventory().getItemInHand().equals(plugin.getClock())) {
    if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    Long now = new Date().getTime() / 1000;
    Long seconds = HistoryHandler.getTimestamp(player.getName()) + plugin.getConfig().getInt("cooldown") - now;
    if (seconds <= 0) {
    if (HistoryHandler.getState(player.getName())) {
    for (Player players : Bukkit.getOnlinePlayers()) {
    player.showPlayer(players);
    }
    player.sendMessage(ChatColor.DARK_GREEN + ".");
    HistoryHandler.setState(player.getName(), false, now);
    } else {
    for (Player players : Bukkit.getOnlinePlayers()) {
    player.hidePlayer(players);
    }
    player.sendMessage(ChatColor.DARK_GREEN + "");
    HistoryHandler.setState(player.getName(), true, now);
    }
    } else {
    player.sendMessage(ChatColor.RED + " ");
    }
    }
    }
    }
    }

    PLEASE HELP!
     
  2. I have a present for you.
    It's called PasteBin:pastebin.com
    Use it wisely