diff --git a/me/Drison64/Lobby/ASclick.java b/me/Drison64/Lobby/ASclick.java index f471e06..78cbea3 100644 --- a/me/Drison64/Lobby/ASclick.java +++ b/me/Drison64/Lobby/ASclick.java @@ -27,24 +27,6 @@ public void clicked(Entity entity, Player player) { if (entity.getType().equals(EntityType.ARMOR_STAND)) { if (entity.getCustomName().equals(ChatColor.BLUE + "Daily Reward")) { customConfig.reload(); - /* - if (customConfig.get().isSet("dailyreward." + player.getName() + ".timestamp")) { - long now = Instant.now().getEpochSecond(); - long finish = customConfig.get().getLong("dailyreward." + player.getName() + ".timestamp") + 86400; - player.openInventory(dailyReward.inv); - long seconds = (finish - now) % 60; - long hours = (finish - now) / 60; - long minutes = hours % 60; - hours = hours / 60; - if (!((finish - now) == 0)) { - dailyReward.inv.setItem(1, new ItemStack(mkitem.mkitem(1, Material.COAL, "Daily Reward", Arrays.asList("", "Next in " + hours + ":" + minutes + ":" + seconds)))); - } else { - customConfig.get().set("dailyreward." + player.getName() + ".timestamp", null); - } - } else { - dailyReward.inv.setItem(1, new ItemStack(mkitem.mkitem(1, Material.DIAMOND, "Daily Reward", Arrays.asList("", "Click to get!")))); - } - */ player.openInventory(dailyReward.inv); } else if (entity.getCustomName().equals(ChatColor.BLUE + "Tic Tac Toe")) { player.openInventory(Bukkit.createInventory(null, 27, "Tic tac toe menu")); diff --git a/me/Drison64/Lobby/Main.java b/me/Drison64/Lobby/Main.java index 2a1a84c..184590f 100644 --- a/me/Drison64/Lobby/Main.java +++ b/me/Drison64/Lobby/Main.java @@ -267,6 +267,15 @@ public void run() { customConfig.get().set(player.getUniqueId() + ".dr_timestamp", null); customConfig.save(); } + } else { + if (!((finish - now) < 0)) { + player.getOpenInventory().getTopInventory().setItem(1, mkitem.mkitem(1, Material.COAL, "", Arrays.asList("", "Next in " + shours + ":" + sminutes + ":" + sseconds))); + player.updateInventory(); + } else { + player.getOpenInventory().setItem(1, new ItemStack(mkitem.mkitem(1, Material.DIAMOND, "Daily Reward", Arrays.asList("", "Click to get!")))); + customConfig.get().set(player.getUniqueId() + ".dr_timestamp", null); + customConfig.save(); + } } } else { player.getOpenInventory().setItem(1, new ItemStack(mkitem.mkitem(1, Material.DIAMOND, "Daily Reward", Arrays.asList("", "Click to get!")))); @@ -295,7 +304,25 @@ public void run() { } } } - }, 0L, 2L); + }, 0L, 1L); + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + @Override + public void run() { + for (Player player : Bukkit.getOnlinePlayers()) { + player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + customConfig.reload(); + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + objective.setDisplayName("Name"); + Score score1 = objective.getScore("Coins: " + customConfig.get().get(player.getUniqueId() + ".coins")); + score1.setScore(9); + Score score = objective.getScore(""); + score.setScore(10); + Score score2 = objective.getScore(""); + score2.setScore(8); + player.setScoreboard(board); + } + } + }, 0L, 5L); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { @Override public void run() { @@ -350,8 +377,6 @@ public void onJoin(PlayerJoinEvent e) { customConfig.get().set(player.getUniqueId() + ".coins", 1000); customConfig.save(); } - Score score1 = objective.getScore("Coins: " + customConfig.get().get(player.getUniqueId() + ".coins")); - score1.setScore(9); player.setScoreboard(board); player.setGameMode(GameMode.ADVENTURE); Location spawn = new Location(Bukkit.getWorld("world"), 678.5, 127.5, -61.5, 180, 0); @@ -425,4 +450,20 @@ public static Entity getAS(String type) { return null; } + public void updateScoreboard(Player player) { + Scoreboard sb = Bukkit.getScoreboardManager().getNewScoreboard(); + Objective obj = sb.registerNewObjective("scoreboard", "dummy"); + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + + customConfig.reload(); + obj.setDisplayName("§6Server name"); + obj.getScore("§6").setScore(5); + obj.getScore("§bHello " + player.getName()).setScore(4); + obj.getScore("§6").setScore(3); + obj.getScore("Coins: " + customConfig.get().getInt(player.getUniqueId() + ".coins")).setScore(2); + obj.getScore("§6").setScore(1); + + player.setScoreboard(sb); + } + } diff --git a/me/Drison64/Lobby/dailyReward.java b/me/Drison64/Lobby/dailyReward.java index 2678f9d..7bf6ea7 100644 --- a/me/Drison64/Lobby/dailyReward.java +++ b/me/Drison64/Lobby/dailyReward.java @@ -24,27 +24,32 @@ public void onInvClick(InventoryClickEvent e) { e.setCancelled(true); Player player = (Player) e.getWhoClicked(); if (e.getRawSlot() == 1) { - customConfig.get().set(player.getUniqueId() + ".dr_timestamp", Instant.now().getEpochSecond()); - customConfig.save(); - long now = Instant.now().getEpochSecond(); - long finish = customConfig.get().getLong(player.getUniqueId() + ".dr_timestamp") + 10; - long seconds = (finish - now) % 60; - long hours = (finish - now) / 60; - long minutes = hours % 60; - hours = hours / 60; - String sseconds = String.valueOf(seconds); - String sminutes = String.valueOf(minutes); - String shours = String.valueOf(hours); - if (sseconds.length() == 1) { - sseconds = "0" + sseconds; + if (e.getView().getTopInventory().getItem(1).getType().equals(Material.DIAMOND)) { + customConfig.get().set(player.getUniqueId() + ".dr_timestamp", Instant.now().getEpochSecond()); + customConfig.save(); + long now = Instant.now().getEpochSecond(); + long finish = customConfig.get().getLong(player.getUniqueId() + ".dr_timestamp") + 10; + long seconds = (finish - now) % 60; + long hours = (finish - now) / 60; + long minutes = hours % 60; + hours = hours / 60; + String sseconds = String.valueOf(seconds); + String sminutes = String.valueOf(minutes); + String shours = String.valueOf(hours); + if (sseconds.length() == 1) { + sseconds = "0" + sseconds; + } + if (sminutes.length() == 1) { + sminutes = "0" + sminutes; + } + if (shours.length() == 1) { + shours = "0" + shours; + } + player.getOpenInventory().getTopInventory().setItem(1, mkitem.mkitem(1, Material.COAL, "Daily Reward", Arrays.asList("", "Next in " + shours + ":" + sminutes + ":" + sseconds))); + customConfig.reload(); + customConfig.get().set(player.getUniqueId() + ".coins", customConfig.get().getInt(player.getUniqueId() + ".coins") + 10); + customConfig.save(); } - if (sminutes.length() == 1) { - sminutes = "0" + sminutes; - } - if (shours.length() == 1) { - shours = "0" + shours; - } - player.getOpenInventory().getTopInventory().setItem(1, mkitem.mkitem(1, Material.COAL, "Daily Reward", Arrays.asList("", "Next in " + shours + ":" + sminutes + ":" + sseconds))); } } }