diff --git a/betterhoppers/.gradle/8.9/checksums/checksums.lock b/betterhoppers/.gradle/8.9/checksums/checksums.lock deleted file mode 100644 index a34b831..0000000 Binary files a/betterhoppers/.gradle/8.9/checksums/checksums.lock and /dev/null differ diff --git a/betterhoppers/.gradle/8.9/dependencies-accessors/gc.properties b/betterhoppers/.gradle/8.9/dependencies-accessors/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/betterhoppers/.gradle/8.9/fileChanges/last-build.bin b/betterhoppers/.gradle/8.9/fileChanges/last-build.bin deleted file mode 100644 index f76dd23..0000000 Binary files a/betterhoppers/.gradle/8.9/fileChanges/last-build.bin and /dev/null differ diff --git a/betterhoppers/.gradle/8.9/fileHashes/fileHashes.lock b/betterhoppers/.gradle/8.9/fileHashes/fileHashes.lock deleted file mode 100644 index 36208c9..0000000 Binary files a/betterhoppers/.gradle/8.9/fileHashes/fileHashes.lock and /dev/null differ diff --git a/betterhoppers/.gradle/8.9/gc.properties b/betterhoppers/.gradle/8.9/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/betterhoppers/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/betterhoppers/.gradle/buildOutputCleanup/buildOutputCleanup.lock deleted file mode 100644 index 890aaea..0000000 Binary files a/betterhoppers/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ diff --git a/betterhoppers/.gradle/buildOutputCleanup/cache.properties b/betterhoppers/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 2a70299..0000000 --- a/betterhoppers/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Sun Jul 20 15:58:26 CEST 2025 -gradle.version=8.14.2 diff --git a/betterhoppers/.gradle/vcs-1/gc.properties b/betterhoppers/.gradle/vcs-1/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/betterhoppers/build.gradle.kts b/betterhoppers/build.gradle.kts deleted file mode 100755 index c51689f..0000000 --- a/betterhoppers/build.gradle.kts +++ /dev/null @@ -1,49 +0,0 @@ -plugins { - `java-library` - id("io.papermc.paperweight.userdev") version "2.0.0-beta.14" - id("xyz.jpenilla.run-paper") version "2.3.1" // Adds runServer and runMojangMappedServer tasks for testing -} -group = "de.hessj.betterhoppers" -version = "1.0-SNAPSHOT" -description = "betterhoppers" - -tasks.withType { - destinationDirectory.set(file("../")) -} - -dependencies { - implementation(files("../craftbukkit.jar")) - implementation(files("../helper-1.0-SNAPSHOT.jar")) - paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT") -} - -tasks { - // Configure reobfJar to run when invoking the build task - assemble { - dependsOn(reobfJar) - } - - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - - // Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable. - // See https://openjdk.java.net/jeps/247 for more information. - options.release.set(21) - } - javadoc { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - } - processResources { - filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything - val props = mapOf( - "name" to project.name, - "version" to project.version, - "description" to project.description, - "apiVersion" to "1.21" - ) - inputs.properties(props) - filesMatching("plugin.yml") { - expand(props) - } - } -} \ No newline at end of file diff --git a/betterhoppers/settings.gradle.kts b/betterhoppers/settings.gradle.kts deleted file mode 100755 index 60e49ba..0000000 --- a/betterhoppers/settings.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0" -} - -rootProject.name = "betterhoppers" \ No newline at end of file diff --git a/betterhoppers/src/main/java/de/hessj/betterhoppers/App.java b/betterhoppers/src/main/java/de/hessj/betterhoppers/App.java deleted file mode 100755 index f7c660c..0000000 --- a/betterhoppers/src/main/java/de/hessj/betterhoppers/App.java +++ /dev/null @@ -1,80 +0,0 @@ -package de.hessj.betterhoppers; - -import java.util.Arrays; -import java.util.List; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ShapelessRecipe; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.components.CustomModelDataComponent; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.ChatColor; - -public class App extends JavaPlugin { - public static App main; - public de.hessj.helper.Helper helper= new de.hessj.helper.Helper(); - public PluginManager pM = Bukkit.getPluginManager(); - NamespacedKey nskHopper = new NamespacedKey(this, "R3SFILTERHOPPER"); - String name = "Trichterfilter"; - - @Override - public void onEnable() { - main = this; - getLogger().info("Plugin enabled!"); - listenerRegistration(); - - ItemStack hopper = new ItemStack(Material.HOPPER); - ItemMeta im = hopper.getItemMeta(); - im.displayName(Component.text(ChatColor.WHITE + name)); - im.lore(Arrays.asList(Component.text(ChatColor.GRAY + "STRG + Rechtsklick auf den platzierten Filter"), - Component.text(ChatColor.GRAY + "ohne Item in der Hand, um den Filter zu öffnen"))); - im.setCustomModelData(1000021); - - - CustomModelDataComponent cmdc = im.getCustomModelDataComponent(); - List list = Arrays.asList("filter_hopper"); - cmdc.setStrings(list); - im.setCustomModelDataComponent(cmdc); - - - - hopper.setItemMeta(im); - - ShapelessRecipe srHopper = new ShapelessRecipe(nskHopper, hopper); - srHopper.addIngredient(Material.HOPPER); - srHopper.addIngredient(Material.COMPARATOR); - getServer().addRecipe(srHopper); - if (getServer().getRecipe(nskHopper) == null) { - getServer().addRecipe(srHopper); - } - - } - - - - - - - @Override - public void onDisable() { - getLogger().info("Plugin disabled!"); - } - - private void listenerRegistration() { - pM.registerEvents(new BetterHopperListener(), this); - pM.registerEvents(new LoginListener(), this); - } - - public Boolean checkFilterHopper(ItemStack is) { - - if (is.displayName().toString().contains(name)) { - return true; - } - - return false; - } -} \ No newline at end of file diff --git a/betterhoppers/src/main/java/de/hessj/betterhoppers/BetterHopperListener.java b/betterhoppers/src/main/java/de/hessj/betterhoppers/BetterHopperListener.java deleted file mode 100755 index de42858..0000000 --- a/betterhoppers/src/main/java/de/hessj/betterhoppers/BetterHopperListener.java +++ /dev/null @@ -1,313 +0,0 @@ -package de.hessj.betterhoppers; - -import java.io.IOException; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; -import org.bukkit.event.inventory.InventoryPickupItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -import de.hessj.helper.Helper; -import net.kyori.adventure.text.Component; - -public class BetterHopperListener implements Listener { - Component inventoryname = Component.text("Items zum filtern:"); - @EventHandler - public void onBlockPlace(BlockPlaceEvent e) { - if (App.main.checkFilterHopper(e.getItemInHand())) { - Location loc = e.getBlockPlaced().getLocation(); - InventoryHolder invh = (InventoryHolder) e.getBlockPlaced().getState(); - Inventory newHopperinv = Bukkit.createInventory(invh, 9); - App.main.getConfig() - .set("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory", - Helper.itemStackArrayToBase64(newHopperinv.getContents())); - App.main.saveConfig(); - } - - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent e) throws IllegalArgumentException, IOException { - - if (e.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR && e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getPlayer().isSneaking() - && e.getClickedBlock().getType().equals(Material.HOPPER)) { - e.setCancelled(true); - if (App.main.getConfig().getConfigurationSection("hoppers") != null) { - - String w = e.getClickedBlock().getWorld().getName(); - Location loc = e.getClickedBlock().getLocation(); - - if (App.main.getConfig().get("hoppers." + w + "." + loc.getBlockX() + "~" + loc.getBlockY() + "~" - + loc.getBlockZ()) != null) { - InventoryHolder invh = (InventoryHolder) e.getClickedBlock().getState(); - - Inventory hopperinv = Bukkit.createInventory(invh, 9, inventoryname); - hopperinv.setContents(Helper.itemStackArrayFromBase64( - App.main.getConfig().getString("hoppers." + w + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory"))); - e.getPlayer().openInventory(hopperinv); - } - - } - } - } - - @EventHandler - public void onInvClose(InventoryCloseEvent e) { - if (e.getView().title().equals(inventoryname)) { - Inventory invtosave = e.getInventory(); - InventoryHolder invholder = e.getInventory().getHolder(); - Location loc = invholder.getInventory().getLocation(); - App.main.getConfig() - .set("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory", - Helper.itemStackArrayToBase64(invtosave.getContents())); - App.main.saveConfig(); - } - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent e) { - Inventory top = e.getView().getTopInventory(); - Inventory bottom = e.getView().getBottomInventory(); - if (e.getView().title().equals(inventoryname)) { - e.setCancelled(true); - if (e.getClickedInventory() == top) { - if (top.getItem(e.getSlot()) != null) { - top.setItem(e.getSlot(), null); - } - } else if (e.getClickedInventory() == bottom) { - if (bottom.getItem(e.getSlot()) != null) { - if (top.firstEmpty() != -1) { - ItemStack is = bottom.getItem(e.getSlot()).clone(); - is.setAmount(1); - if (!top.containsAtLeast(is, 1)) {// if top hat das item noch nicht dann nur adden - - top.addItem(is); - } - } - } - } - - } - } - - @EventHandler - public void onBlockBreak(BlockBreakEvent e) { - if (e.getPlayer() != null && e.getPlayer().getGameMode() == GameMode.SURVIVAL) { - if (e.getBlock().getType() == Material.HOPPER) { - Location loc = e.getBlock().getLocation(); - if (App.main.getConfig() - .contains("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory")) { - - App.main.getConfig().getConfigurationSection("hoppers") - .set(loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ(), null); - App.main.saveConfig(); - e.setCancelled(true); - e.getBlock().setType(Material.AIR); - e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), - new ItemStack(Material.HOPPER, 1)); - e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), - new ItemStack(Material.COMPARATOR, 1)); - } - } - } - } - - @EventHandler - public void onBlockBreak(EntityExplodeEvent e) { - for (Block b : e.blockList()) { - if (b.getType() == Material.HOPPER) { - Location loc = b.getLocation(); - if (App.main.getConfig() - .contains("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory")) { - App.main.getConfig().getConfigurationSection("hoppers") - .set(loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ(), null); - App.main.saveConfig(); - b.setType(Material.AIR); - b.getWorld().dropItemNaturally(loc, new ItemStack(Material.HOPPER, 1)); - b.getWorld().dropItemNaturally(loc, new ItemStack(Material.COMPARATOR, 1)); - } - } - } - } - - @EventHandler - public void onInventoryPickupEvent(InventoryPickupItemEvent event) throws IllegalArgumentException, IOException { - Inventory dest = event.getInventory(); - Location loc = dest.getLocation(); - if (App.main.getConfig() - .contains("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory")) { - - InventoryHolder invh = (InventoryHolder) event.getInventory().getLocation().getWorld() - .getBlockAt(event.getInventory().getLocation()).getState(); - - Inventory hopperinv = Bukkit.createInventory(invh, 9, inventoryname); - hopperinv.setContents(Helper.itemStackArrayFromBase64( - App.main.getConfig().getString("hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" - + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory"))); - - if (!checkSimilarity(event.getItem().getItemStack().getType(), hopperinv)) { - - event.setCancelled(true); - } - } - } - - - - - - - - - - - - - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true) - public void onItemMove(InventoryMoveItemEvent e) throws IllegalArgumentException, IOException { - Inventory dest = e.getDestination(); - if(dest.getLocation() != null){ - Location destLoc = dest.getLocation(); - Inventory source = e.getSource(); - - - - if (App.main.getConfig() - .contains("hoppers." + destLoc.getWorld().getName() + "." + destLoc.getBlockX() + "~" - + destLoc.getBlockY() + "~" + destLoc.getBlockZ() + ".filterinventory")) { - - - InventoryHolder invh = (InventoryHolder) destLoc.getWorld().getBlockAt(destLoc).getState(); - Inventory filterInv = Bukkit.createInventory(invh, 9, inventoryname); - - - - - - filterInv.setContents(Helper.itemStackArrayFromBase64( - App.main.getConfig().getString("hoppers." + destLoc.getWorld().getName() + "." + destLoc.getBlockX() + "~" - + destLoc.getBlockY() + "~" + destLoc.getBlockZ() + ".filterinventory"))); - - - - if(!filterInv.contains(e.getItem().getType())){ - e.setCancelled(true); - - for (int slot = 1; slot < source.getSize(); slot++) { - if(source.getItem(slot) != null){ - ItemStack temp = source.getItem(slot).clone(); - temp.setAmount(1); - if(filterInv.containsAtLeast(temp,1)){ - moveItem(source, slot, dest); - return; - } - - } - - } - - } - -}} - } - - - -public void moveItem(Inventory source, Integer slot, Inventory dest){ - Boolean freespace = false; - ItemStack i = source.getItem(slot); - - - - - - - - - for (ItemStack is : dest.getContents()) { - if (is != null) { - if (is.isSimilar(i)) { - - if (is.getAmount() == is.getMaxStackSize()) { - // nix tun - } else { - is.setAmount(is.getAmount()+1); - i.setAmount(i.getAmount()-1); - return; - } - - } - } else { - freespace = true; - } - - } - - - - - - - - - - - - - - if (freespace) { - ItemStack iClone = i.clone(); - iClone.setAmount(1); - dest.setItem(dest.firstEmpty(), iClone); - i.setAmount(i.getAmount()-1); - } -} - - - - - - - - - - - public static boolean checkSimilarity(Material material, Inventory inv) { - - for (ItemStack itemstack : inv.getContents()) { - if (itemstack == null) { - continue; - } - if (material.equals(itemstack.getType())) { - return true; - } - } - - return false; - } - -} diff --git a/betterhoppers/src/main/java/de/hessj/betterhoppers/LoginListener.java b/betterhoppers/src/main/java/de/hessj/betterhoppers/LoginListener.java deleted file mode 100755 index 3a92c24..0000000 --- a/betterhoppers/src/main/java/de/hessj/betterhoppers/LoginListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.hessj.betterhoppers; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class LoginListener implements Listener { - - @EventHandler - public void onLogin(PlayerJoinEvent e){ - e.getPlayer().discoverRecipe(App.main.nskHopper); - } -} diff --git a/betterhoppers/src/main/resources/plugin.yml b/betterhoppers/src/main/resources/plugin.yml deleted file mode 100755 index 8aebb59..0000000 --- a/betterhoppers/src/main/resources/plugin.yml +++ /dev/null @@ -1,5 +0,0 @@ -main: de.hessj.betterhoppers.App -name: BetterHoppersPlugin -depend: [HelperPlugin] -version: 0.1 -api-version: 1.21 \ No newline at end of file diff --git a/dailyquests/src/main/java/de/hessj/dailyquests/App.java b/dailyquests/src/main/java/de/hessj/dailyquests/App.java index e48a2f0..67f7a8c 100755 --- a/dailyquests/src/main/java/de/hessj/dailyquests/App.java +++ b/dailyquests/src/main/java/de/hessj/dailyquests/App.java @@ -1,84 +1,53 @@ package de.hessj.dailyquests; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.AbstractMap.SimpleEntry; -import java.util.Map.Entry; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; +import de.hessj.helper.Helper; +import de.hessj.helper.Helper.Type; +import net.kyori.adventure.text.Component; +import net.md_5.bungee.api.ChatColor; +import org.bukkit.*; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.RecipeChoice; -import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.*; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.components.CustomModelDataComponent; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.Scoreboard; -import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.ChatColor; -import de.hessj.helper.Helper.Type; +import org.bukkit.scoreboard.ScoreboardManager; + +import java.time.*; +import java.util.*; +import java.util.AbstractMap.SimpleEntry; +import java.util.Map.Entry; public class App extends JavaPlugin { + public static App main; - public de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); - public ArrayList rewardList = new ArrayList(); + public Helper helper = new Helper(); + public static final String DIAMOND_DUST_KEY = "R3SDiamondDust"; + public static final String DIAMOND_DUST_RECIPE_KEY = "R3S_SR_DIAMONDDUST"; + public static final long TICKS_PER_SECOND = 20L; + public static final long SECONDS_PER_DAY = 86400L; + + public ArrayList rewardList = new ArrayList<>(); public ItemStack diamondDust; public NamespacedKey nskdiamondDust; - public NamespacedKey nskDD = new NamespacedKey(this, "R3S_SR_DIAMONDDUST"); + public NamespacedKey nskDD; @Override public void onEnable() { getLogger().info("Plugin enabled!"); main = this; + + nskdiamondDust = new NamespacedKey(this, DIAMOND_DUST_KEY); + nskDD = new NamespacedKey(this, DIAMOND_DUST_RECIPE_KEY); + setupRewards(); DailyQuestsListeners.getTodaysQuest(); - LocalDateTime start = LocalDateTime.now(); - LocalDateTime nextMidnight = start.plusDays(1).withHour(0).withMinute(0).withSecond(0); - ZonedDateTime zdt = ZonedDateTime.of(nextMidnight, ZoneId.of("Europe/Berlin")); - Duration duration = Duration.between(start, zdt); - long secUntil = duration.toMillis() / 1000; - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - @Override - public void run() { - resetQuestScheduler(); - } - }, 20 * secUntil); // Wird beim nächsten 0Uhr ausgeführt - listenerRegistration(); - } - - public void resetQuestScheduler() { - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { - @Override - public void run() { - getConfig().set("players", null); - saveConfig(); - for (Player p : Bukkit.getServer().getOnlinePlayers()) { - DailyQuestsListeners.getDailyQuests(p); - Entry actionMapEntry = DailyQuestsCommands.boards.get(p.getName()); - Scoreboard board = actionMapEntry.getKey(); - if (!actionMapEntry.getValue()) { - p.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard()); - DailyQuestsCommands.boards.put(p.getName(), new SimpleEntry(board, false)); - } else { - p.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard()); - p.setScoreboard(board); - - DailyQuestsCommands.boards.put(p.getName(), new SimpleEntry(board, true)); - } - p.sendMessage(helper.R3SMessage(Type.INFO, "[DailyQuests] Du hast eine neue Quest erhalten!")); - } - saveConfig(); - } - }, 0L, (24 * 60 * 60) * 20L); // Alle 24std neue Quest + scheduleMidnightReset(); + registerListenersAndCommands(); } @Override @@ -86,66 +55,114 @@ public class App extends JavaPlugin { getLogger().info("Plugin disabled!"); } - private void listenerRegistration() { + private void registerListenersAndCommands() { PluginManager pM = Bukkit.getPluginManager(); pM.registerEvents(new DailyQuestsListeners(), this); getCommand("quest").setExecutor(new DailyQuestsCommands()); } + private void scheduleMidnightReset() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime nextMidnight = now.plusDays(1).withHour(0).withMinute(0).withSecond(0); + ZonedDateTime zdt = ZonedDateTime.of(nextMidnight, ZoneId.of("Europe/Berlin")); + Duration duration = Duration.between(now, zdt); + long secondsUntilMidnight = duration.getSeconds(); + + Bukkit.getScheduler().runTaskLater(this, this::startQuestResetScheduler, secondsUntilMidnight * TICKS_PER_SECOND); + } + + private void startQuestResetScheduler() { + new BukkitRunnable() { + @Override + public void run() { + resetDailyQuestsForAllPlayers(); + } + }.runTaskTimer(this, 0L, SECONDS_PER_DAY * TICKS_PER_SECOND); + } + + private void resetDailyQuestsForAllPlayers() { + getConfig().set("players", null); + saveConfig(); + + for (Player player : Bukkit.getOnlinePlayers()) { + DailyQuestsListeners.getDailyQuests(player); + updatePlayerScoreboard(player); + player.sendMessage(helper.R3SMessage(Type.INFO, "[DailyQuests] Du hast eine neue Quest erhalten!")); + } + + saveConfig(); + } + + private void updatePlayerScoreboard(Player player) { + Entry entry = DailyQuestsCommands.boards.get(player.getName()); + Scoreboard board = entry.getKey(); + boolean isActive = entry.getValue(); + + ScoreboardManager manager = Bukkit.getScoreboardManager(); + player.setScoreboard(manager.getNewScoreboard()); + + if (isActive) { + player.setScoreboard(board); + } + + DailyQuestsCommands.boards.put(player.getName(), new SimpleEntry<>(board, isActive)); + } + private void setupRewards() { - - nskdiamondDust = new NamespacedKey(App.main, "R3SDiamondDust"); + createDiamondDustItem(); + registerDiamondDustRecipe(); + initializeRewardList(); + } + + private void createDiamondDustItem() { diamondDust = new ItemStack(Material.BARRIER); - ItemMeta mdiamondDust = diamondDust.getItemMeta(); - mdiamondDust.setCustomModelData(1000010); + ItemMeta meta = diamondDust.getItemMeta(); + meta.setCustomModelData(1000010); + CustomModelDataComponent cmdc = meta.getCustomModelDataComponent(); + cmdc.setStrings(Collections.singletonList("diamond_dust")); + meta.setCustomModelDataComponent(cmdc); - + meta.displayName(Component.translatable(ChatColor.WHITE + "Diamant-Staub")); + meta.getPersistentDataContainer().set(nskdiamondDust, PersistentDataType.STRING, DIAMOND_DUST_KEY); + diamondDust.setItemMeta(meta); + } + private void registerDiamondDustRecipe() { + RecipeChoice choice = new RecipeChoice.ExactChoice(diamondDust); + ShapedRecipe recipe = new ShapedRecipe(nskDD, new ItemStack(Material.DIAMOND)); + recipe.shape("** ", "** ", " "); + recipe.setIngredient('*', choice); - CustomModelDataComponent cmdc4 = mdiamondDust.getCustomModelDataComponent(); - List list4 = Arrays.asList("diamond_dust"); - cmdc4.setStrings(list4); - mdiamondDust.setCustomModelDataComponent(cmdc4); + if (getServer().getRecipe(nskDD) == null) { + getServer().addRecipe(recipe); + } + } - - - - - - mdiamondDust.displayName(Component.translatable(ChatColor.WHITE + "Diamant-Staub")); - mdiamondDust.getPersistentDataContainer().set(nskdiamondDust, PersistentDataType.STRING, "R3SDiamondDust"); - diamondDust.setItemMeta(mdiamondDust); - RecipeChoice rc = new RecipeChoice.ExactChoice(diamondDust); - ShapedRecipe ddRecipe = new ShapedRecipe(nskDD, - new ItemStack(Material.DIAMOND)); - ddRecipe.shape("** ", "** ", " "); - ddRecipe.setIngredient('*', rc); - if (getServer().getRecipe(nskDD) == null) { - App.main.getServer().addRecipe(ddRecipe); - } - rewardList.add(new ItemStack(Material.EXPERIENCE_BOTTLE, 1)); - rewardList.add(new ItemStack(Material.APPLE, 10)); - rewardList.add(new ItemStack(Material.POTATO, 5)); - rewardList.add(new ItemStack(Material.CARROT, 5)); - rewardList.add(new ItemStack(Material.COOKED_BEEF, 10)); - rewardList.add(new ItemStack(Material.COOKED_CHICKEN, 10)); - rewardList.add(new ItemStack(Material.COOKED_CHICKEN, 10)); - rewardList.add(new ItemStack(Material.COOKED_COD, 10)); - rewardList.add(new ItemStack(Material.COOKED_MUTTON, 10)); - rewardList.add(new ItemStack(Material.COOKED_PORKCHOP, 10)); - rewardList.add(new ItemStack(Material.COOKED_RABBIT, 10)); - rewardList.add(new ItemStack(Material.COOKED_SALMON, 10)); - rewardList.add(new ItemStack(Material.IRON_INGOT, 5)); - rewardList.add(new ItemStack(Material.COPPER_INGOT, 5)); - rewardList.add(new ItemStack(Material.GOLD_NUGGET, 5)); - rewardList.add(new ItemStack(Material.FIREWORK_ROCKET, 5)); - rewardList.add(new ItemStack(Material.SADDLE, 1)); - rewardList.add(new ItemStack(Material.MELON_SEEDS, 5)); - rewardList.add(new ItemStack(Material.PUMPKIN_SEEDS, 5)); - rewardList.add(new ItemStack(Material.BEETROOT_SEEDS, 5)); - rewardList.add(new ItemStack(Material.DIAMOND, 1)); - rewardList.add(new ItemStack(Material.CAKE, 1)); - rewardList.add(new ItemStack(Material.ENDER_PEARL, 5)); + private void initializeRewardList() { + rewardList.addAll(List.of( + new ItemStack(Material.EXPERIENCE_BOTTLE, 1), + new ItemStack(Material.APPLE, 10), + new ItemStack(Material.POTATO, 5), + new ItemStack(Material.CARROT, 5), + new ItemStack(Material.COOKED_BEEF, 10), + new ItemStack(Material.COOKED_CHICKEN, 10), + new ItemStack(Material.COOKED_COD, 10), + new ItemStack(Material.COOKED_MUTTON, 10), + new ItemStack(Material.COOKED_PORKCHOP, 10), + new ItemStack(Material.COOKED_RABBIT, 10), + new ItemStack(Material.COOKED_SALMON, 10), + new ItemStack(Material.IRON_INGOT, 5), + new ItemStack(Material.COPPER_INGOT, 5), + new ItemStack(Material.GOLD_NUGGET, 5), + new ItemStack(Material.FIREWORK_ROCKET, 5), + new ItemStack(Material.SADDLE, 1), + new ItemStack(Material.MELON_SEEDS, 5), + new ItemStack(Material.PUMPKIN_SEEDS, 5), + new ItemStack(Material.BEETROOT_SEEDS, 5), + new ItemStack(Material.DIAMOND, 1), + new ItemStack(Material.CAKE, 1), + new ItemStack(Material.ENDER_PEARL, 5) + )); } } \ No newline at end of file diff --git a/dailyquests/src/main/java/de/hessj/dailyquests/DailyQuestsCommands.java b/dailyquests/src/main/java/de/hessj/dailyquests/DailyQuestsCommands.java index 7174954..936a6b3 100755 --- a/dailyquests/src/main/java/de/hessj/dailyquests/DailyQuestsCommands.java +++ b/dailyquests/src/main/java/de/hessj/dailyquests/DailyQuestsCommands.java @@ -1,195 +1,154 @@ package de.hessj.dailyquests; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; +import java.util.*; import java.util.AbstractMap.SimpleEntry; -import java.util.Map.Entry; + + import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.ProfileProperty; import de.hessj.helper.Helper.Type; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import org.bukkit.*; +import org.bukkit.command.*; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.*; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.*; + import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.ChatColor; public class DailyQuestsCommands implements CommandExecutor { - public static HashMap> boards = new HashMap>(); + public static Map> boards = new HashMap<>(); public static NamespacedKey nsksurpriseBox; public static ItemStack surpriseBox; public static de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); public static void updateSB(Player p) { - if (!(boards.containsKey(p.getName()))) { + boards.putIfAbsent(p.getName(), new SimpleEntry<>(Bukkit.getScoreboardManager().getNewScoreboard(), false)); - Scoreboard board = Bukkit.getServer().getScoreboardManager().getNewScoreboard(); - boards.put(p.getName(), new SimpleEntry(board, false)); - } Entry actionMapEntry = boards.get(p.getName()); Scoreboard board = actionMapEntry.getKey(); - if (board.getObjective(DisplaySlot.SIDEBAR) != null) { - board.getObjective(DisplaySlot.SIDEBAR).unregister(); - } - Objective o = board.registerNewObjective("test", "dummy", Component.text("Quest:")); - + Objective existing = board.getObjective(DisplaySlot.SIDEBAR); + if (existing != null) existing.unregister(); + Objective o = board.registerNewObjective("dailyquests", ObjectiveCriteria.DUMMY, Component.text("Quest:")); o.setDisplaySlot(DisplaySlot.SIDEBAR); - Score score; - for (Object obj : App.main.getConfig().getConfigurationSection("players." + p.getUniqueId() + ".currentQuests") - .getKeys(false).toArray()) { - if (!obj.toString().equals("null")) { - String desc = ""; - if (!App.main.getConfig().get("quests." + obj.toString() + ".tool").equals("none")) { - desc = (App.main.getConfig().get("quests." + obj.toString() + ".description")).toString() - .replace("[x]", - App.main.getConfig() - .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() - + ".countneeded") - .toString()/* - * App.main.getConfig().get("quests." + obj.toString() + - * ".count").toString() - */) - .replace("[b]", App.main.getConfig().get("quests." + obj.toString() + ".target").toString()) - .replace("[t]", App.main.getConfig().get("quests." + obj.toString() + ".tool").toString() - .replace("Material.", "")); + ConfigurationSection questsSection = App.main.getConfig().getConfigurationSection("players." + p.getUniqueId() + ".currentQuests"); + if (questsSection == null) return; - } else { - desc = App.main.getConfig().get("quests." + obj.toString() + ".description").toString() - .replace("[x]", - App.main.getConfig() - .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() - + ".countneeded") - .toString()) - .replace("[b]", - App.main.getConfig().get("quests." + obj.toString() + ".target").toString()); + for (String questKey : questsSection.getKeys(false)) { + if (questKey.equals("null")) continue; - } - desc = desc.replace("Material.", ""); - if (desc.length() >= 39) { - desc = desc.substring(0, 39); - } - if (App.main.getConfig() - .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + ".state") - .equals("finished")) { - board.resetScores(desc); - score = o.getScore(ChatColor.STRIKETHROUGH + "" + desc); - } else { - score = o.getScore(desc); - } - score.setScore(App.main.getConfig() - .getInt("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + ".currentcount")); - checkForCompletion(p); + String desc = formatQuestDescription(p.getUniqueId(), questKey); + if (desc.length() >= 39) desc = desc.substring(0, 39); + + int currentCount = getConfigInt("players." + p.getUniqueId() + ".currentQuests." + questKey + ".currentcount"); + + if ("finished".equals(getConfigString("players." + p.getUniqueId() + ".currentQuests." + questKey + ".state"))) { + board.resetScores(desc); + o.getScore(ChatColor.STRIKETHROUGH + desc).setScore(currentCount); + } else { + o.getScore(desc).setScore(currentCount); } + + checkForCompletion(p); } - if (actionMapEntry.getValue()) { - boards.put(p.getName(), new SimpleEntry(board, true)); - } else { - boards.put(p.getName(), new SimpleEntry(board, false)); - } + + boards.put(p.getName(), new SimpleEntry<>(board, actionMapEntry.getValue())); } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - updateSB((Player) sender); - Entry actionMapEntry = boards.get(((Player) sender).getName()); - Scoreboard board = actionMapEntry.getKey(); - if (actionMapEntry.getValue()) { - ((Player) sender).setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard()); - boards.put(((Player) sender).getName(), new SimpleEntry(board, false)); - } else { - ((Player) sender).setScoreboard(board); - boards.put(((Player) sender).getName(), new SimpleEntry(board, true)); - } + if (sender instanceof Player player) { + updateSB(player); + Entry entry = boards.get(player.getName()); + boolean showing = entry.getValue(); + + player.setScoreboard(showing ? Bukkit.getScoreboardManager().getNewScoreboard() : entry.getKey()); + boards.put(player.getName(), new SimpleEntry<>(entry.getKey(), !showing)); } return true; } - static void checkForCompletion(Player p) { + private static void checkForCompletion(Player p) { + UUID uuid = p.getUniqueId(); int completed = 0; - int all = 0; - for (Object questIDs : App.main.getConfig().getConfigurationSection("quests").getKeys(false).toArray()) { - if (App.main.getConfig() - .contains("players." + p.getUniqueId().toString() + ".currentQuests." + questIDs.toString())) { - if (App.main.getConfig().get( - "players." + p.getUniqueId().toString() + ".currentQuests." + questIDs.toString() + ".state") - .equals("finished")) { - completed++; - } - all++; + int total = 0; + + for (String questID : App.main.getConfig().getConfigurationSection("quests").getKeys(false)) { + String path = "players." + uuid + ".currentQuests." + questID; + if (App.main.getConfig().contains(path)) { + if ("finished".equals(getConfigString(path + ".state"))) completed++; + total++; } } - if (completed == all) { - if (!App.main.getConfig().get("players." + p.getUniqueId().toString() + ".rewards").equals("claimed")) { - surpriseBox = new ItemStack(Material.PLAYER_HEAD, 1); - SkullMeta im = (SkullMeta) surpriseBox.getItemMeta(); - im.displayName(Component.translatable(ChatColor.WHITE + "Überraschungsbox")); - im.setPlayerProfile(Bukkit.createProfile(UUID.randomUUID(), null)); - PlayerProfile playerProfile = im.getPlayerProfile(); - playerProfile.getProperties().add(new ProfileProperty("textures", - "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQxZmJlYTljMmQxOTA0MGU1NjdmMzg3YWI0NmIyZjhhM2ExZGE4ZWVjOWQzOTllMmU0YWRjZjA1YWRhOGEyYSJ9fX0=")); - im.setPlayerProfile(playerProfile); - nsksurpriseBox = new NamespacedKey(App.main, "R3SSurpriseBox"); - im.getPersistentDataContainer().set(nsksurpriseBox, PersistentDataType.STRING, "R3S_SurpriseBox"); - ArrayList lore = new ArrayList(); - lore.add(Component.translatable("Quest Belohnung")); - im.lore(lore); - surpriseBox.setItemMeta(im); - - Boolean freeSpace = false; - Boolean given = false; - for (ItemStack i : p.getInventory().getStorageContents()) { - if (i != null) { - - if (i.getType() == surpriseBox.getType() && i.hasItemMeta() - && i.getItemMeta().getPersistentDataContainer() != null) { - if (i.getItemMeta().getPersistentDataContainer().has(nsksurpriseBox, - PersistentDataType.STRING)) { - if (i.getAmount() < 64) { - i.setAmount(i.getAmount() + 1); - given = true; - break; - } - } - } - - } else { - if (i == null) { - freeSpace = true; - } - } - } - if (!freeSpace && !given) { - - p.sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll, schaffe Platz und logge dich ein, deine Questbelohnung zu erhalten!")); - } else { - if (!given && freeSpace) { - p.getInventory().addItem(surpriseBox); - } - p.sendMessage( - helper.R3SMessage(Type.SUCCESS,"[DailyQuests] Du hast 1x Überraschungsbox als Questbelohnung erhalten!")); - App.main.getConfig().set("players." + p.getUniqueId() + ".rewards", "claimed"); - App.main.saveConfig(); - } - } + if (completed == total && !"claimed".equals(getConfigString("players." + uuid + ".rewards"))) { + giveSurpriseBox(p); + App.main.getConfig().set("players." + uuid + ".rewards", "claimed"); + App.main.saveConfig(); } } + + private static void giveSurpriseBox(Player p) { + surpriseBox = new ItemStack(Material.PLAYER_HEAD); + SkullMeta meta = (SkullMeta) surpriseBox.getItemMeta(); + meta.displayName(Component.text(ChatColor.WHITE + "Überraschungsbox")); + + PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID(), null); + profile.getProperties().add(new ProfileProperty("textures", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQxZmJlYTljMmQxOTA0MGU1NjdmMzg3YWI0NmIyZjhhM2ExZGE4ZWVjOWQzOTllMmU0YWRjZjA1YWRhOGEyYSJ9fX0=")); + meta.setPlayerProfile(profile); + + nsksurpriseBox = new NamespacedKey(App.main, "R3SSurpriseBox"); + meta.getPersistentDataContainer().set(nsksurpriseBox, PersistentDataType.STRING, "R3S_SurpriseBox"); + meta.lore(List.of(Component.text("Quest Belohnung"))); + surpriseBox.setItemMeta(meta); + + boolean given = false, hasSpace = false; + + for (ItemStack i : p.getInventory().getStorageContents()) { + if (i == null) { + hasSpace = true; + continue; + } + + if (i.isSimilar(surpriseBox) && i.getAmount() < 64) { + i.setAmount(i.getAmount() + 1); + given = true; + break; + } + } + + if (!given && hasSpace) { + p.getInventory().addItem(surpriseBox); + p.sendMessage(helper.R3SMessage(Type.SUCCESS, "[DailyQuests] Du hast 1x Überraschungsbox als Questbelohnung erhalten!")); + } else if (!given) { + p.sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll, schaffe Platz und logge dich ein, um deine Questbelohnung zu erhalten!")); + } + } + + private static String getConfigString(String path) { + Object value = App.main.getConfig().get(path); + return value != null ? value.toString() : ""; + } + + private static int getConfigInt(String path) { + return App.main.getConfig().getInt(path); + } + + private static String formatQuestDescription(UUID playerId, String questKey) { + String base = getConfigString("quests." + questKey + ".description"); + String count = getConfigString("players." + playerId + ".currentQuests." + questKey + ".countneeded"); + String target = getConfigString("quests." + questKey + ".target"); + String tool = getConfigString("quests." + questKey + ".tool").replace("Material.", ""); + + return base.replace("[x]", count).replace("[b]", target).replace("[t]", tool); + } } diff --git a/environmentex/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/environmentex/.gradle/buildOutputCleanup/buildOutputCleanup.lock index bbd758c..53f6ebf 100644 Binary files a/environmentex/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/environmentex/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/environmentex/.gradle/buildOutputCleanup/cache.properties b/environmentex/.gradle/buildOutputCleanup/cache.properties index 2927ca3..86def24 100644 --- a/environmentex/.gradle/buildOutputCleanup/cache.properties +++ b/environmentex/.gradle/buildOutputCleanup/cache.properties @@ -1,2 +1,2 @@ -#Wed Jul 02 13:24:00 CEST 2025 +#Wed Jul 30 01:48:01 CEST 2025 gradle.version=8.14.2 diff --git a/environmentex/.gradle/caches/paperweight/taskCache/mappedServerJar.jar b/environmentex/.gradle/caches/paperweight/taskCache/mappedServerJar.jar index b26d0aa..6495c64 100644 Binary files a/environmentex/.gradle/caches/paperweight/taskCache/mappedServerJar.jar and b/environmentex/.gradle/caches/paperweight/taskCache/mappedServerJar.jar differ diff --git a/environmentex/.gradle/caches/paperweight/taskCache/reobfJar.log b/environmentex/.gradle/caches/paperweight/taskCache/reobfJar.log index 84325fa..b0b7e7a 100644 --- a/environmentex/.gradle/caches/paperweight/taskCache/reobfJar.log +++ b/environmentex/.gradle/caches/paperweight/taskCache/reobfJar.log @@ -1,2 +1,2 @@ Command: /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home/bin/java -Xmx1G -classpath /Users/janik/.gradle/caches/modules-2/files-2.1/net.fabricmc/tiny-remapper/0.11.1/6c1f29838864ba8f495855edfc8ef17706fedb5d/tiny-remapper-0.11.1-fat.jar net.fabricmc.tinyremapper.Main /Users/janik/Desktop/MCPlugins/environmentex-1.0-SNAPSHOT.jar /Users/janik/Desktop/MCPlugins/environmentex/build/libs/environmentex-1.0-SNAPSHOT-reobf.jar /Users/janik/Desktop/MCPlugins/environmentex/.gradle/caches/paperweight/taskCache/reobfMappings.tiny mojang spigot /Users/janik/Desktop/MCPlugins/environmentex/.gradle/caches/paperweight/taskCache/mappedServerJar.jar --threads=1 -[INFO] Finished after 896,39 ms. +[INFO] Finished after 1133,52 ms. diff --git a/environmentex/.gradle/file-system.probe b/environmentex/.gradle/file-system.probe index a2b73c4..4ddf24f 100644 Binary files a/environmentex/.gradle/file-system.probe and b/environmentex/.gradle/file-system.probe differ diff --git a/environmentex/build/classes/java/main/de/hessj/environmentex/App$1.class b/environmentex/build/classes/java/main/de/hessj/environmentex/App$1.class index 3620df2..506711f 100644 Binary files a/environmentex/build/classes/java/main/de/hessj/environmentex/App$1.class and b/environmentex/build/classes/java/main/de/hessj/environmentex/App$1.class differ diff --git a/environmentex/build/classes/java/main/de/hessj/environmentex/App$2.class b/environmentex/build/classes/java/main/de/hessj/environmentex/App$2.class index 5b13126..0276289 100644 Binary files a/environmentex/build/classes/java/main/de/hessj/environmentex/App$2.class and b/environmentex/build/classes/java/main/de/hessj/environmentex/App$2.class differ diff --git a/environmentex/build/classes/java/main/de/hessj/environmentex/App.class b/environmentex/build/classes/java/main/de/hessj/environmentex/App.class index 48cf7b6..5885845 100644 Binary files a/environmentex/build/classes/java/main/de/hessj/environmentex/App.class and b/environmentex/build/classes/java/main/de/hessj/environmentex/App.class differ diff --git a/environmentex/build/classes/java/main/de/hessj/environmentex/EnvironmentExCommands.class b/environmentex/build/classes/java/main/de/hessj/environmentex/EnvironmentExCommands.class index 8dfc069..65a0b5d 100644 Binary files a/environmentex/build/classes/java/main/de/hessj/environmentex/EnvironmentExCommands.class and b/environmentex/build/classes/java/main/de/hessj/environmentex/EnvironmentExCommands.class differ diff --git a/environmentex/build/classes/java/main/de/hessj/environmentex/WorkbenchToGo.class b/environmentex/build/classes/java/main/de/hessj/environmentex/WorkbenchToGo.class index 8e047ba..37a282f 100644 Binary files a/environmentex/build/classes/java/main/de/hessj/environmentex/WorkbenchToGo.class and b/environmentex/build/classes/java/main/de/hessj/environmentex/WorkbenchToGo.class differ diff --git a/environmentex/build/libs/environmentex-1.0-SNAPSHOT-reobf.jar b/environmentex/build/libs/environmentex-1.0-SNAPSHOT-reobf.jar index 94a11fc..152e60d 100644 Binary files a/environmentex/build/libs/environmentex-1.0-SNAPSHOT-reobf.jar and b/environmentex/build/libs/environmentex-1.0-SNAPSHOT-reobf.jar differ diff --git a/environmentex/build/reports/problems/problems-report.html b/environmentex/build/reports/problems/problems-report.html index 68e1170..6fab95c 100644 --- a/environmentex/build/reports/problems/problems-report.html +++ b/environmentex/build/reports/problems/problems-report.html @@ -650,7 +650,7 @@ code + .copy-button { diff --git a/environmentex/build/resources/main/plugin.yml b/environmentex/build/resources/main/plugin.yml index 8a9aef4..bdb5d82 100755 --- a/environmentex/build/resources/main/plugin.yml +++ b/environmentex/build/resources/main/plugin.yml @@ -27,4 +27,7 @@ commands: usage: / r3load: description: ---- + usage: / + quest: + description: Zeigt die heutigen Quests an usage: / \ No newline at end of file diff --git a/environmentex/build/tmp/compileJava/previous-compilation-data.bin b/environmentex/build/tmp/compileJava/previous-compilation-data.bin index 7c35da3..d9a60cc 100644 Binary files a/environmentex/build/tmp/compileJava/previous-compilation-data.bin and b/environmentex/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/environmentex/src/main/java/de/hessj/environmentex/App.java b/environmentex/src/main/java/de/hessj/environmentex/App.java index 0859a7a..a7ee7e9 100755 --- a/environmentex/src/main/java/de/hessj/environmentex/App.java +++ b/environmentex/src/main/java/de/hessj/environmentex/App.java @@ -6,6 +6,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.ScoreboardManager; +import de.hessj.helper.Helper.Type; import net.kyori.adventure.text.Component; import net.md_5.bungee.api.ChatColor; import org.bukkit.NamespacedKey; @@ -22,12 +25,20 @@ import org.bukkit.inventory.RecipeChoice.MaterialChoice; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.components.CustomModelDataComponent; import org.bukkit.persistence.PersistentDataType; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.scoreboard.Scoreboard; +import java.time.*; +import java.util.Map.Entry; public class App extends JavaPlugin { public static de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); @@ -44,11 +55,21 @@ public class App extends JavaPlugin { public NamespacedKey nsk4; public NamespacedKey nskEmptyExpBottle; public NamespacedKey nskGlow; + public static final String DIAMOND_DUST_KEY = "R3SDiamondDust"; + public static final String DIAMOND_DUST_RECIPE_KEY = "R3S_SR_DIAMONDDUST"; + public static final long TICKS_PER_SECOND = 20L; + public static final long SECONDS_PER_DAY = 86400L; + + public ArrayList rewardList = new ArrayList<>(); + public ItemStack diamondDust; + public NamespacedKey nskdiamondDust; + public NamespacedKey nskDD; public ItemMeta meta; public ItemMeta meta2; public ItemStack eBottle; public final List recipeKeys = new ArrayList<>(); - +public NamespacedKey nskHopper; + private final String name = "Trichterfilter"; public static boolean coordinateRunner = false; public PluginManager pM = Bukkit.getPluginManager(); public HashMap hmActionbar = new HashMap(); @@ -56,13 +77,61 @@ public class App extends JavaPlugin { public NamespacedKey nskLockedChest = new NamespacedKey(this, "R3SLockedChest"); public NamespacedKey nskLockedChestRecipe = new NamespacedKey(this, "R3SLockedChestRecipe"); public ItemStack lockedChest; + public boolean checkFilterHopper(ItemStack is) { + if (is == null) return false; + if (!is.hasItemMeta()) return false; + if (is.getItemMeta().displayName() == null) return false; + + return is.getItemMeta().displayName().toString().contains(name); + } + + public String getHopperConfigPath(org.bukkit.Location loc) { + return "hoppers." + loc.getWorld().getName() + "." + loc.getBlockX() + "~" + loc.getBlockY() + "~" + loc.getBlockZ() + ".filterinventory"; + } + + private void registerHopperRecipe() { + if (getServer().getRecipe(nskHopper) != null) return; + + ItemStack hopper = new ItemStack(Material.HOPPER); + ItemMeta im = hopper.getItemMeta(); + im.displayName(Component.text(ChatColor.WHITE + name)); + im.lore(Arrays.asList( + Component.text(ChatColor.GRAY + "STRG + Rechtsklick auf den platzierten Filter"), + Component.text(ChatColor.GRAY + "ohne Item in der Hand, um den Filter zu öffnen") + )); + im.setCustomModelData(1000021); + + CustomModelDataComponent cmdc = im.getCustomModelDataComponent(); + cmdc.setStrings(List.of("filter_hopper")); + im.setCustomModelDataComponent(cmdc); + + hopper.setItemMeta(im); + + ShapelessRecipe srHopper = new ShapelessRecipe(nskHopper, hopper); + srHopper.addIngredient(Material.HOPPER); + srHopper.addIngredient(Material.COMPARATOR); + + getServer().addRecipe(srHopper); + } @Override public void onEnable() { SquidPrevention.removeSquidReceipes(); SquidPrevention.addCustomSquidRecipes(); + nskHopper = new NamespacedKey(this, "R3SFILTERHOPPER"); + registerHopperRecipe(); + + nskdiamondDust = new NamespacedKey(this, DIAMOND_DUST_KEY); + nskDD = new NamespacedKey(this, DIAMOND_DUST_RECIPE_KEY); + + setupRewards(); + + + scheduleMidnightReset(); + main = this; + DailyQuests.getTodaysQuest(); lockedChest = new ItemStack(Material.CHEST); ItemMeta imlockedChest = lockedChest.getItemMeta(); imlockedChest.displayName(Component.translatable(ChatColor.AQUA + "Verschlossene Truhe")); @@ -464,6 +533,8 @@ public class App extends JavaPlugin { pM.registerEvents(new ChestEx(), this); pM.registerEvents(new Backpacks(), this); pM.registerEvents(new DeathLoc(), this); + pM.registerEvents(new BetterHoppers(), this); + pM.registerEvents(new DailyQuests(), this); getCommand("test").setExecutor(new EnvironmentExCommands()); getCommand("y").setExecutor(new EnvironmentExCommands()); getCommand("n").setExecutor(new EnvironmentExCommands()); @@ -473,12 +544,121 @@ public class App extends JavaPlugin { getCommand("pin").setTabCompleter(new PinFeature()); getCommand("ignorevote").setExecutor(new EnvironmentExCommands()); getCommand("r3load").setExecutor(new EnvironmentExCommands()); + getCommand("quest").setExecutor(new EnvironmentExCommands()); } public void log(Object msg) { App.main.getLogger().info(msg.toString()); } + + + private void scheduleMidnightReset() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime nextMidnight = now.plusDays(1).withHour(0).withMinute(0).withSecond(0); + ZonedDateTime zdt = ZonedDateTime.of(nextMidnight, ZoneId.of("Europe/Berlin")); + Duration duration = Duration.between(now, zdt); + long secondsUntilMidnight = duration.getSeconds(); + + Bukkit.getScheduler().runTaskLater(this, this::startQuestResetScheduler, secondsUntilMidnight * TICKS_PER_SECOND); + } + + private void startQuestResetScheduler() { + new BukkitRunnable() { + @Override + public void run() { + resetDailyQuestsForAllPlayers(); + } + }.runTaskTimer(this, 0L, SECONDS_PER_DAY * TICKS_PER_SECOND); + } + + private void resetDailyQuestsForAllPlayers() { + getConfig().set("players", null); + saveConfig(); + + for (Player player : Bukkit.getOnlinePlayers()) { + DailyQuests.getDailyQuests(player); + updatePlayerScoreboard(player); + player.sendMessage(helper.R3SMessage(Type.INFO, "[DailyQuests] Du hast eine neue Quest erhalten!")); + } + + saveConfig(); + } + + private void updatePlayerScoreboard(Player player) { + Entry entry = EnvironmentExCommands.boards.get(player.getName()); + Scoreboard board = entry.getKey(); + boolean isActive = entry.getValue(); + + ScoreboardManager manager = Bukkit.getScoreboardManager(); + player.setScoreboard(manager.getNewScoreboard()); + + if (isActive) { + player.setScoreboard(board); + } + + EnvironmentExCommands.boards.put(player.getName(), new SimpleEntry<>(board, isActive)); + } + + private void setupRewards() { + createDiamondDustItem(); + registerDiamondDustRecipe(); + initializeRewardList(); + } + + private void createDiamondDustItem() { + diamondDust = new ItemStack(Material.BARRIER); + ItemMeta meta = diamondDust.getItemMeta(); + meta.setCustomModelData(1000010); + + CustomModelDataComponent cmdc = meta.getCustomModelDataComponent(); + cmdc.setStrings(Collections.singletonList("diamond_dust")); + meta.setCustomModelDataComponent(cmdc); + + meta.displayName(Component.translatable(ChatColor.WHITE + "Diamant-Staub")); + meta.getPersistentDataContainer().set(nskdiamondDust, PersistentDataType.STRING, DIAMOND_DUST_KEY); + diamondDust.setItemMeta(meta); + } + + private void registerDiamondDustRecipe() { + RecipeChoice choice = new RecipeChoice.ExactChoice(diamondDust); + ShapedRecipe recipe = new ShapedRecipe(nskDD, new ItemStack(Material.DIAMOND)); + recipe.shape("** ", "** ", " "); + recipe.setIngredient('*', choice); + + if (getServer().getRecipe(nskDD) == null) { + getServer().addRecipe(recipe); + } + } + + private void initializeRewardList() { + rewardList.addAll(List.of( + new ItemStack(Material.EXPERIENCE_BOTTLE, 1), + new ItemStack(Material.APPLE, 10), + new ItemStack(Material.POTATO, 5), + new ItemStack(Material.CARROT, 5), + new ItemStack(Material.COOKED_BEEF, 10), + new ItemStack(Material.COOKED_CHICKEN, 10), + new ItemStack(Material.COOKED_COD, 10), + new ItemStack(Material.COOKED_MUTTON, 10), + new ItemStack(Material.COOKED_PORKCHOP, 10), + new ItemStack(Material.COOKED_RABBIT, 10), + new ItemStack(Material.COOKED_SALMON, 10), + new ItemStack(Material.IRON_INGOT, 5), + new ItemStack(Material.COPPER_INGOT, 5), + new ItemStack(Material.GOLD_NUGGET, 5), + new ItemStack(Material.FIREWORK_ROCKET, 5), + new ItemStack(Material.SADDLE, 1), + new ItemStack(Material.MELON_SEEDS, 5), + new ItemStack(Material.PUMPKIN_SEEDS, 5), + new ItemStack(Material.BEETROOT_SEEDS, 5), + new ItemStack(Material.DIAMOND, 1), + new ItemStack(Material.CAKE, 1), + new ItemStack(Material.ENDER_PEARL, 5) + )); + } + + public static Boolean isDay() { // wenn zeit kleiner als 24000 && zeit größer gleich 12575 diff --git a/environmentex/src/main/java/de/hessj/environmentex/BetterHoppers.java b/environmentex/src/main/java/de/hessj/environmentex/BetterHoppers.java new file mode 100644 index 0000000..c469e50 --- /dev/null +++ b/environmentex/src/main/java/de/hessj/environmentex/BetterHoppers.java @@ -0,0 +1,251 @@ +//GPT'd +package de.hessj.environmentex; + +import java.io.IOException; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import de.hessj.helper.Helper; +import net.kyori.adventure.text.Component; + +public class BetterHoppers implements Listener { + + private static final Component inventoryName = Component.text("Items zum filtern:"); + + @EventHandler + public void onLogin(final PlayerJoinEvent event) { + event.getPlayer().discoverRecipe(App.main.nskHopper); + } + + @EventHandler + public void onBlockPlace(final org.bukkit.event.block.BlockPlaceEvent e) { + if (App.main.checkFilterHopper(e.getItemInHand())) { + final Location loc = e.getBlockPlaced().getLocation(); + final InventoryHolder invHolder = (InventoryHolder) e.getBlockPlaced().getState(); + final Inventory newHopperInv = Bukkit.createInventory(invHolder, 9); + App.main.getConfig() + .set(App.main.getHopperConfigPath(loc), Helper.itemStackArrayToBase64(newHopperInv.getContents())); + App.main.saveConfig(); + } + } + + @EventHandler + public void onPlayerInteract(final PlayerInteractEvent e) { + try { + if (e.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR + && e.getAction() == Action.RIGHT_CLICK_BLOCK + && e.getPlayer().isSneaking() + && e.getClickedBlock() != null + && e.getClickedBlock().getType() == Material.HOPPER) { + + e.setCancelled(true); + + final Location loc = e.getClickedBlock().getLocation(); + final String path = App.main.getHopperConfigPath(loc); + + if (App.main.getConfig().contains(path)) { + final InventoryHolder invHolder = (InventoryHolder) e.getClickedBlock().getState(); + final Inventory hopperInv = Bukkit.createInventory(invHolder, 9, inventoryName); + + hopperInv.setContents(Helper.itemStackArrayFromBase64(App.main.getConfig().getString(path))); + e.getPlayer().openInventory(hopperInv); + } + } + } catch (IllegalArgumentException | IOException ex) { + ex.printStackTrace(); + } + } + + @EventHandler + public void onInventoryClose(final InventoryCloseEvent e) { + if (e.getView().title().equals(inventoryName)) { + final Inventory invToSave = e.getInventory(); + final InventoryHolder invHolder = invToSave.getHolder(); + if (invHolder == null) + return; + final Location loc = invHolder.getInventory().getLocation(); + + if (loc != null) { + App.main.getConfig().set(App.main.getHopperConfigPath(loc), + Helper.itemStackArrayToBase64(invToSave.getContents())); + App.main.saveConfig(); + } + } + } + + @EventHandler + public void onInventoryClick(final InventoryClickEvent e) { + final Inventory top = e.getView().getTopInventory(); + final Inventory bottom = e.getView().getBottomInventory(); + + if (e.getView().title().equals(inventoryName)) { + e.setCancelled(true); + + if (e.getClickedInventory() == top) { + if (top.getItem(e.getSlot()) != null) { + top.setItem(e.getSlot(), null); + } + } else if (e.getClickedInventory() == bottom) { + if (bottom.getItem(e.getSlot()) != null && top.firstEmpty() != -1) { + final ItemStack is = bottom.getItem(e.getSlot()).clone(); + is.setAmount(1); + + if (!top.containsAtLeast(is, 1)) { + top.addItem(is); + } + } + } + } + } + + @EventHandler + public void onBlockBreak(final BlockBreakEvent e) { + if (e.getPlayer() != null && e.getPlayer().getGameMode() == GameMode.SURVIVAL) { + final Block block = e.getBlock(); + if (block.getType() == Material.HOPPER) { + if (removeFilterHopperData(block)) { + e.setCancelled(true); + } + } + } + } + + @EventHandler + public void onEntityExplode(final EntityExplodeEvent e) { + for (final Block block : e.blockList()) { + if (block.getType() == Material.HOPPER) { + removeFilterHopperData(block); + } + } + } + + private boolean removeFilterHopperData(final Block block) { + final Location loc = block.getLocation(); + final String path = App.main.getHopperConfigPath(loc).replace(".filterinventory", ""); + if (App.main.getConfig().contains(path + ".filterinventory")) { + App.main.getConfig().set(path, null); + App.main.saveConfig(); + block.setType(Material.AIR); + block.getWorld().dropItemNaturally(loc, new ItemStack(Material.HOPPER)); + block.getWorld().dropItemNaturally(loc, new ItemStack(Material.COMPARATOR)); + return true; + } + return false; + } + + @EventHandler + public void onInventoryPickupItem(final InventoryPickupItemEvent event) { + try { + final Inventory dest = event.getInventory(); + final Location loc = dest.getLocation(); + if (loc == null) + return; + + final String path = App.main.getHopperConfigPath(loc); + if (App.main.getConfig().contains(path)) { + final InventoryHolder invHolder = (InventoryHolder) loc.getWorld().getBlockAt(loc).getState(); + final Inventory hopperInv = Bukkit.createInventory(invHolder, 9, inventoryName); + hopperInv.setContents(Helper.itemStackArrayFromBase64(App.main.getConfig().getString(path))); + + if (!checkSimilarity(event.getItem().getItemStack().getType(), hopperInv)) { + event.setCancelled(true); + } + } + } catch (IllegalArgumentException | IOException ex) { + ex.printStackTrace(); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onInventoryMoveItem(final InventoryMoveItemEvent e) { + try { + final Inventory dest = e.getDestination(); + final Location destLoc = dest.getLocation(); + if (destLoc == null) + return; + + final String path = App.main.getHopperConfigPath(destLoc); + if (App.main.getConfig().contains(path)) { + final InventoryHolder invHolder = (InventoryHolder) destLoc.getWorld().getBlockAt(destLoc).getState(); + final Inventory filterInv = Bukkit.createInventory(invHolder, 9, inventoryName); + filterInv.setContents(Helper.itemStackArrayFromBase64(App.main.getConfig().getString(path))); + + if (!filterInv.contains(e.getItem().getType())) { + e.setCancelled(true); + + final Inventory source = e.getSource(); + for (int slot = 0; slot < source.getSize(); slot++) { + final ItemStack sourceItem = source.getItem(slot); + if (sourceItem != null) { + final ItemStack temp = sourceItem.clone(); + temp.setAmount(1); + if (filterInv.containsAtLeast(temp, 1)) { + moveItem(source, slot, dest); + return; + } + } + } + } + } + } catch (IllegalArgumentException | IOException ex) { + ex.printStackTrace(); + } + } + + private void moveItem(final Inventory source, final int slot, final Inventory dest) { + final ItemStack i = source.getItem(slot); + if (i == null) + return; + + boolean freeSpace = false; + + for (final ItemStack is : dest.getContents()) { + if (is != null) { + if (is.isSimilar(i)) { + if (is.getAmount() < is.getMaxStackSize()) { + is.setAmount(is.getAmount() + 1); + i.setAmount(i.getAmount() - 1); + source.setItem(slot, i.getAmount() > 0 ? i : null); + return; + } + } + } else { + freeSpace = true; + } + } + + if (freeSpace) { + final ItemStack iClone = i.clone(); + iClone.setAmount(1); + dest.setItem(dest.firstEmpty(), iClone); + i.setAmount(i.getAmount() - 1); + source.setItem(slot, i.getAmount() > 0 ? i : null); + } + } + + private boolean checkSimilarity(final Material m, final Inventory filterInv) { + for (final ItemStack is : filterInv.getContents()) { + if (is != null && is.getType() == m) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/environmentex/src/main/java/de/hessj/environmentex/DailyQuests.java b/environmentex/src/main/java/de/hessj/environmentex/DailyQuests.java new file mode 100644 index 0000000..608a9f1 --- /dev/null +++ b/environmentex/src/main/java/de/hessj/environmentex/DailyQuests.java @@ -0,0 +1,1627 @@ +package de.hessj.environmentex; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.AbstractMap.SimpleEntry; +import java.util.Map.Entry; +import org.bukkit.Material; +import org.bukkit.block.data.type.Beehive; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityBreedEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityTameEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.inventory.FurnaceBurnEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerEditBookEvent; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerShearEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.scoreboard.Scoreboard; + +import de.hessj.helper.Helper.Type; +import net.kyori.adventure.text.Component; +import net.md_5.bungee.api.ChatColor; + +public class DailyQuests implements Listener { + public static ArrayList todaysQuest = new ArrayList(); + public static String questDesc; + public static String questAction; + public static String questTarget; + public static String questTool; + public static String questCount; + public static Integer questId; + public Boolean given = false; + public Boolean freeSpace = false; + public de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); + + @EventHandler + public void craftBlocker(PrepareItemCraftEvent e) { + if (e.getInventory().containsAtLeast(App.main.diamondDust, 1) && e.getInventory().getResult() != null + && !e.getInventory().getResult().getType().equals(Material.DIAMOND)) { + e.getInventory().setResult(null); + } + } + + @EventHandler + public void ovenBlocker(FurnaceBurnEvent e) { + + if (e.getFuel() != null && e.getFuel().equals(App.main.diamondDust)) { + e.setCancelled(true); + } + } + + public void giveSmallReward(Object obj, Player p) { + List giveList = Arrays.asList(new ItemStack(Material.EMERALD), App.main.diamondDust); + Random rand = new Random(); + ItemStack randomElement = giveList.get(rand.nextInt(giveList.size())); + String itemName = ""; + if (randomElement.equals(new ItemStack(Material.EMERALD))) { + itemName = "Smaragd"; + } else if (randomElement.equals(App.main.diamondDust)) { + itemName = "Diamant-Staub"; + } + + for (ItemStack i : p.getInventory().getStorageContents()) { + if (randomElement.equals(App.main.diamondDust)) { + if (i != null && i.getType() == randomElement.getType() && i.hasItemMeta() + && i.getItemMeta() != null + && i.getItemMeta().getPersistentDataContainer() != null + && i.getItemMeta().getPersistentDataContainer().has( + App.main.nskdiamondDust, PersistentDataType.STRING)) { + if (i.getAmount() < 64) { + i.setAmount(i.getAmount() + 1); + given = true; + break; + } + } else { + if (i == null) { + freeSpace = true; + } + } + } else { + if (i != null && i.getType() == randomElement.getType()) { + if (i.getAmount() < 64) { + i.setAmount(i.getAmount() + 1); + given = true; + break; + } + } else { + if (i == null) { + freeSpace = true; + } + } + } + } + if (!freeSpace && !given) {// ansonsten checken für free space + + p.sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll, deine Questbelohnung wurde gedropped!")); + p.getWorld().dropItem( + p.getLocation(), randomElement); + App.main.getConfig() + .set("players." + + p.getUniqueId() + + ".currentQuests." + obj.toString() + ".state", "finished"); + App.main.saveConfig(); + } else { + if (!given && freeSpace) { + p.getInventory() + .addItem(randomElement); + } + p.sendMessage(helper.R3SMessage(Type.SUCCESS, "[DailyQuests] Du hast 1x " + itemName + " als Questbelohnung erhalten!")); + App.main.getConfig() + .set("players." + + p.getUniqueId() + + ".currentQuests." + obj.toString() + ".state", "finished"); + App.main.saveConfig(); + } + + } + + public static void getTodaysQuest() { + App.main.getConfig().addDefault("quests.19.description", "Sammle [x]x Honig"); + App.main.getConfig().addDefault("quests.19.action", "honey"); + App.main.getConfig().addDefault("quests.19.target", "none"); + App.main.getConfig().addDefault("quests.19.tool", "Material.GLASS_BOTTLE"); + App.main.getConfig().addDefault("quests.19.count", "[mid]"); + App.main.getConfig().addDefault("quests.18.description", "Gehe eine Runde angeln"); + App.main.getConfig().addDefault("quests.18.action", "fish"); + App.main.getConfig().addDefault("quests.18.target", "none"); + App.main.getConfig().addDefault("quests.18.tool", "Material.FISHING_ROD"); + App.main.getConfig().addDefault("quests.18.count", "[once]"); + App.main.getConfig().addDefault("quests.17.description", "Melke eine Kuh"); + App.main.getConfig().addDefault("quests.17.action", "milk"); + App.main.getConfig().addDefault("quests.17.target", "EntityType.COW"); + App.main.getConfig().addDefault("quests.17.tool", "Material.BUCKET"); + App.main.getConfig().addDefault("quests.17.count", "[once]"); + App.main.getConfig().addDefault("quests.16.description", "Heile einen Eisengolem"); + App.main.getConfig().addDefault("quests.16.action", "heal"); + App.main.getConfig().addDefault("quests.16.target", "EntityType.IRON_GOLEM"); + App.main.getConfig().addDefault("quests.16.tool", "Material.IRON_INGOT"); + App.main.getConfig().addDefault("quests.16.count", "[once]"); + App.main.getConfig().addDefault("quests.15.description", "Backe einen Kuchen"); + App.main.getConfig().addDefault("quests.15.action", "bake"); + App.main.getConfig().addDefault("quests.15.target", "Material.CAKE"); + App.main.getConfig().addDefault("quests.15.tool", "none"); + App.main.getConfig().addDefault("quests.15.count", "[once]"); + App.main.getConfig().addDefault("quests.14.description", "Schreibe ein Buch"); + App.main.getConfig().addDefault("quests.14.action", "write"); + App.main.getConfig().addDefault("quests.14.target", "Material.WRITABLE_BOOK"); + App.main.getConfig().addDefault("quests.14.tool", "none"); + App.main.getConfig().addDefault("quests.14.count", "[once]"); + App.main.getConfig().addDefault("quests.13.description", "Schere ein Schaf"); + App.main.getConfig().addDefault("quests.13.action", "shear"); + App.main.getConfig().addDefault("quests.13.target", "EntityType.SHEEP"); + App.main.getConfig().addDefault("quests.13.tool", "none"); + App.main.getConfig().addDefault("quests.13.count", "[once]"); + App.main.getConfig().addDefault("quests.12.description", "Begehe Bedrock mit Lederstiefel"); + App.main.getConfig().addDefault("quests.12.action", "touch"); + App.main.getConfig().addDefault("quests.12.target", "Material.BEDROCK"); + App.main.getConfig().addDefault("quests.12.tool", "Material.LEATHER_BOOTS"); + App.main.getConfig().addDefault("quests.12.count", "[once]"); + App.main.getConfig().addDefault("quests.11.description", "Züchte [x]x Kuh"); + App.main.getConfig().addDefault("quests.11.action", "breed"); + App.main.getConfig().addDefault("quests.11.target", "CraftCow"); + App.main.getConfig().addDefault("quests.11.tool", "none"); + App.main.getConfig().addDefault("quests.11.count", "[low]"); + App.main.getConfig().addDefault("quests.10.description", "Schneeballschlacht mit Schneemann"); + App.main.getConfig().addDefault("quests.10.action", "snowfight"); + App.main.getConfig().addDefault("quests.10.target", "EntityType.SNOWMAN"); + App.main.getConfig().addDefault("quests.10.tool", "Material.SNOWBALL"); + App.main.getConfig().addDefault("quests.10.count", "[once]"); + App.main.getConfig().addDefault("quests.9.description", "Reise zum End"); + App.main.getConfig().addDefault("quests.9.action", "travel"); + App.main.getConfig().addDefault("quests.9.target", + App.main.getServer().getWorlds().get(0).getName() + "_end"); + App.main.getConfig().addDefault("quests.9.tool", "none"); + App.main.getConfig().addDefault("quests.9.count", "[once]"); + App.main.getConfig().addDefault("quests.8.description", "Reise zum Nether"); + App.main.getConfig().addDefault("quests.8.action", "travel"); + App.main.getConfig().addDefault("quests.8.target", + App.main.getServer().getWorlds().get(0).getName() + "_nether"); + App.main.getConfig().addDefault("quests.8.tool", "none"); + App.main.getConfig().addDefault("quests.8.count", "[once]"); + App.main.getConfig().addDefault("quests.7.description", "Töte [x]x Skelett mit Bogen"); + App.main.getConfig().addDefault("quests.7.action", "kill"); + App.main.getConfig().addDefault("quests.7.target", "EntityType.SKELETON"); + App.main.getConfig().addDefault("quests.7.tool", "Material.BOW"); + App.main.getConfig().addDefault("quests.7.count", "[high]"); + App.main.getConfig().addDefault("quests.5.description", "Zähme einen Wolf"); + App.main.getConfig().addDefault("quests.5.action", "tame"); + App.main.getConfig().addDefault("quests.5.target", "EntityType.WOLF"); + App.main.getConfig().addDefault("quests.5.tool", "none"); + App.main.getConfig().addDefault("quests.5.count", "[once]"); + App.main.getConfig().addDefault("quests.4.description", "Töte [x]x Spinne"); + App.main.getConfig().addDefault("quests.4.action", "kill"); + App.main.getConfig().addDefault("quests.4.target", "EntityType.SPIDER"); + App.main.getConfig().addDefault("quests.4.tool", "none"); + App.main.getConfig().addDefault("quests.4.count", "[mid]"); + App.main.getConfig().addDefault("quests.3.description", "Baue [x]x Kohle mit Holzaxt ab"); + App.main.getConfig().addDefault("quests.3.action", "break"); + App.main.getConfig().addDefault("quests.3.target", "Material.COAL_ORE"); + App.main.getConfig().addDefault("quests.3.tool", "Material.WOODEN_AXE"); + App.main.getConfig().addDefault("quests.3.count", "[high]"); + App.main.getConfig().addDefault("quests.2.description", "Baue [x]x Kohle ab"); + App.main.getConfig().addDefault("quests.2.action", "break"); + App.main.getConfig().addDefault("quests.2.target", "Material.COAL_ORE"); + App.main.getConfig().addDefault("quests.2.tool", "none"); + App.main.getConfig().addDefault("quests.2.count", "[high]"); + App.main.getConfig().addDefault("quests.1.description", "Töte [x]x Zombie mit Holzschwert"); + App.main.getConfig().addDefault("quests.1.action", "kill"); + App.main.getConfig().addDefault("quests.1.target", "EntityType.ZOMBIE"); + App.main.getConfig().addDefault("quests.1.tool", "Material.WOODEN_SWORD"); + App.main.getConfig().addDefault("quests.1.count", "[high]"); + App.main.getConfig().options().copyDefaults(true); + App.main.saveConfig(); + + } + + public static ArrayList questList = new ArrayList(); + + public static void getDailyQuests(Player p) { + if (!App.main.getConfig().contains(("players." + p.getUniqueId()).toString())) { + int questsAvailable = 0; + for (Object obj : App.main.getConfig().getConfigurationSection("quests").getKeys(false) + .toArray()) { + questsAvailable++; + obj.toString();// damit Warning weg ist + } + int randoQuestOne = 9999; + int randoQuestTwo = 9999; + int randoQuestThree = 9999; + for (int i = 1; i <= 3; i++) { + int randomQuestID = new Random().nextInt(questsAvailable) + 1; + while (randomQuestID == randoQuestOne || randomQuestID == randoQuestTwo + || randomQuestID == randoQuestThree) { + randomQuestID = new Random().nextInt(questsAvailable) + 1; + } + questDesc = App.main.getConfig().getString("quests." + randomQuestID + ".description"); + questAction = App.main.getConfig().getString("quests." + randomQuestID + ".action"); + questTarget = App.main.getConfig().getString("quests." + randomQuestID + ".target"); + questTool = App.main.getConfig().getString("quests." + randomQuestID + ".tool"); + questCount = App.main.getConfig().getString("quests." + randomQuestID + ".count"); + questId = randomQuestID; + if (i == 1) { + randoQuestOne = randomQuestID; + } else if (i == 2) { + randoQuestTwo = randomQuestID; + } else if (i == 3) { + randoQuestThree = randomQuestID; + } + App.main.getConfig().set( + "players." + p.getUniqueId() + ".currentQuests." + questId + ".state", + "ongoing"); + App.main.getConfig() + .set("players." + p.getUniqueId() + ".currentQuests." + questId + + ".currentcount", + 0); + int qCount = 9999; + if (questCount.equals("[once]")) { + qCount = 1; + } else if (questCount.equals("[low]")) { + qCount = random_int(1, 3); + + } else if (questCount.equals("[mid]")) { + qCount = random_int(2, 4); + } else if (questCount.equals("[high]")) { + qCount = random_int(3, 5); + } + App.main.getConfig().set("players." + p.getUniqueId() + ".currentQuests." + questId + + ".countneeded", qCount); + App.main.getConfig().set("players." + p.getUniqueId() + ".rewards", "pending"); + } + App.main.saveConfig(); + } + } + + public static int random_int(int Min, int Max) { + return (int) (Math.random() * (Max - Min)) + Min; + } + + @EventHandler + public void onLogoff(PlayerQuitEvent e) { + Entry actionMapEntry = EnvironmentExCommands.boards.get(e.getPlayer().getName()); + if (actionMapEntry != null) { + Scoreboard board = actionMapEntry.getKey(); + EnvironmentExCommands.boards.put(e.getPlayer().getName(), + new SimpleEntry(board, false)); + } + } + + @EventHandler + public void onLogin(PlayerJoinEvent e) { + + + + e.getPlayer().discoverRecipe(App.main.nskDD); + + + + + + + + + + e.getPlayer().sendMessage(helper.R3SMessage(Type.INFO, "[DailyQuests] Hallo, " + e.getPlayer().getName() + + ". Du kannst die Questanzeige mit \"/quest\" ein- oder ausblenden.")); + getDailyQuests(e.getPlayer()); + } + + @EventHandler + public void onItemUse(PlayerInteractEvent e) { + if ((e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) + && e.getPlayer().getInventory().getItemInMainHand().getType() == Material.PLAYER_HEAD + && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().displayName() != null && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().displayName() + .equals(Component.translatable(ChatColor.WHITE + "Überraschungsbox"))) { + e.setCancelled(true); + freeSpace = false; + ItemStack randoItem = App.main.rewardList + .get(((new Random())).nextInt(App.main.rewardList.size())); + for (ItemStack i : e.getPlayer().getInventory().getStorageContents()) { + if (i == null || i == randoItem) { + freeSpace = true; + } + } + if (freeSpace) { + e.getPlayer().getInventory().addItem(randoItem); + e.getPlayer().getInventory().getItemInMainHand() + .setAmount(e.getPlayer().getInventory().getItemInMainHand().getAmount() + - 1); + } else { + e.getPlayer().sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll!")); + } + } + } + + @EventHandler + public void onEntityHurt(EntityDamageByEntityEvent e) { + if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof Player + && e.getEntity().getType().equals(EntityType.SNOW_GOLEM)) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + + ((Player) ((Projectile) e.getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests") + .getKeys(false).toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")) + .toString() + .equals("snowfight")) { + + if (("EntityType." + e.getEntityType().toString()) + .equals((App.main.getConfig().get( + "quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig() + .get("players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".state") + .equals("ongoing")) { + if (!App.main.getConfig() + .get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getInventory() + .getItemInMainHand() + .getType().toString()) + .equals( + App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig().set( + "players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig().set( + "players." + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + + ((Player) ((Projectile) e + .getDamager()).getShooter()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + + giveSmallReward(obj, ((Player) ((Projectile) e.getDamager()) + .getShooter())); + + } + EnvironmentExCommands.updateSB( + ((Player) ((Projectile) e.getDamager()).getShooter())); + } + } + } + } + } + + @EventHandler + public void onEntityKill(EntityDeathEvent e) { + if (e.getEntity().getKiller() instanceof Player) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getEntity().getKiller().getUniqueId() + + ".currentQuests") + .getKeys(false).toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")) + .toString().equals("kill")) { + + if (("EntityType." + e.getEntityType().toString()) + .equals((App.main.getConfig().get( + "quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig().get("players." + + e.getEntity().getKiller() + .getUniqueId() + + ".currentQuests." + obj.toString() + + ".state").equals("ongoing")) { + if (!App.main.getConfig() + .get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getEntity().getKiller() + .getInventory().getItemInMainHand() + .getType().toString()).equals( + App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig().set( + "players." + e.getEntity() + .getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getEntity().getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getEntity() + .getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getEntity().getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + + e.getEntity().getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getEntity() + .getKiller() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig().get("players." + + e.getEntity().getKiller() + .getUniqueId() + + ".currentQuests." + obj.toString() + + ".state").equals("ongoing")) { + freeSpace = false; + given = false; + giveSmallReward(obj, e.getEntity().getKiller()); + + } + EnvironmentExCommands.updateSB(e.getEntity().getKiller()); + } + } + } + } + } + + @EventHandler + public void onCraft(CraftItemEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + ((Player) e.getWhoClicked()).getUniqueId() + + ".currentQuests") + .getKeys(false).toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("bake")) { + if (("Material." + e.getRecipe().getResult().getType().toString()) + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig().get("players." + + ((Player) e.getWhoClicked()).getUniqueId() + + ".currentQuests." + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + ((Player) e.getWhoClicked()).getInventory() + .getItemInMainHand().getType() + .toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + ((Player) e + .getWhoClicked()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + ((Player) e.getWhoClicked()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + ((Player) e.getWhoClicked()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + ((Player) e.getWhoClicked()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + ((Player) e.getWhoClicked()).getUniqueId() + + ".currentQuests." + + obj.toString() + ".currentcount") == App.main + .getConfig() + .getInt("players." + ((Player) e + .getWhoClicked()) + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig().get("players." + + ((Player) e.getWhoClicked()).getUniqueId() + + ".currentQuests." + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, ((Player) e.getWhoClicked())); + + } + EnvironmentExCommands.updateSB(((Player) e.getWhoClicked())); + } + } + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("break")) { + + if (("Material." + e.getBlock().getType().toString()) + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getPlayer().getInventory() + .getItemInMainHand().getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + } + + @EventHandler + public void onGolemHeal(PlayerInteractEntityEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("heal")) { + + if (("EntityType." + e.getRightClicked().getType().toString())//////////// + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && ((LivingEntity) e.getRightClicked()).getHealth() < 100 + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getPlayer().getInventory() + .getItemInMainHand().getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + } + + @EventHandler + public void onCowMilking(PlayerInteractEntityEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("milk")) { + + if (("EntityType." + e.getRightClicked().getType().toString())//////////// + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getPlayer().getInventory() + .getItemInMainHand().getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + } + + @EventHandler + public void onFish(PlayerFishEvent e) { + + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("fish")) { + + if (App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getPlayer().getInventory() + .getItemInMainHand().getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool")) + && e.getCaught() != null) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + } + + @EventHandler + public void onTame(EntityTameEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getOwner().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("tame")) { + + if (("EntityType." + e.getEntityType()) + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig() + .get("players." + e.getOwner().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + + ((Player) e.getOwner()).getInventory() + .getItemInMainHand().getType() + .toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getOwner() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getOwner().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getOwner().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getOwner() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getOwner().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getOwner() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getOwner().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, (Player) e.getOwner()); + + } + EnvironmentExCommands.updateSB(((Player) e.getOwner())); + } + } + } + } + + @EventHandler + public void onNetherEnter(PlayerChangedWorldEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("travel")) { + + if (e.getPlayer().getWorld().getName() + .equals((App.main.getConfig() + .get("quests." + obj.toString() + ".target")) + .toString()) + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + + ((Player) e.getPlayer()).getInventory() + .getItemInMainHand().getType() + .toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + + } + EnvironmentExCommands.updateSB(((Player) e.getPlayer())); + } + } + } + } + + @EventHandler + public void onBreed(EntityBreedEvent e) { + if (e.getBreeder() != null) { + for (Object obj : App.main.getConfig() + .getConfigurationSection( + "players." + e.getBreeder().getUniqueId() + ".currentQuests") + .getKeys(false).toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")) + .toString().equals("breed")) { + + if (e.getEntity().toString() + .equals((App.main.getConfig().get( + "quests." + obj.toString() + ".target")) + .toString()) + + && App.main.getConfig().get("players." + + e.getBreeder().getUniqueId() + + ".currentQuests." + obj.toString() + + ".state").equals("ongoing")) { + if (!App.main.getConfig() + .get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + ((Player) e.getBreeder()) + .getInventory().getItemInMainHand() + .getType().toString()).equals( + App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig().set( + "players." + e.getBreeder() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getBreeder().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getBreeder() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getBreeder().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getBreeder().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getBreeder() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig().get("players." + + e.getBreeder().getUniqueId() + + ".currentQuests." + obj.toString() + + ".state").equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, (Player) e.getBreeder()); + + } + EnvironmentExCommands.updateSB(((Player) e.getBreeder())); + } + } + } + } + } + + @EventHandler + public void onBlockTouch(PlayerMoveEvent e) { + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("touch")) { + + if (("Material." + e.getPlayer().getLocation().subtract(0, 1, 0).getBlock() + .getType().toString()) + .equals((App.main.getConfig().get("quests." + + obj.toString() + ".target")) + .toString()) + + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + // WENN SPIELER LEDER BOOTS AN HAT + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (e.getPlayer().getInventory().getBoots() != null + && ("Material." + e.getPlayer().getInventory() + .getBoots().getType() + .toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + + } + + @EventHandler + public void onSheepShear(PlayerShearEntityEvent e) { + if (("EntityType." + e.getEntity().getType().toString()).equals("EntityType.SHEEP")) { + for (Object obj : App.main.getConfig() + .getConfigurationSection( + "players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")) + .toString().equals("shear")) { + + if (("EntityType." + e.getEntity().getType().toString()) + .equals((App.main.getConfig().get( + "quests." + obj.toString() + ".target")) + .toString()) + + && App.main.getConfig().get("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + // WENN SPIELER LEDER BOOTS AN HAT + if (!App.main.getConfig() + .get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (e.getPlayer().getInventory().getItemInMainHand() + .getType().toString() + .equals(App.main.getConfig().get( + "quests." + obj.toString() + + ".tool"))) { + App.main.getConfig().set( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig().get("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + + } + + } + + @EventHandler + public void onHoneyCollect(PlayerInteractEvent e) { + + if (e.getClickedBlock() != null + && (e.getClickedBlock().getType() == Material.BEEHIVE + || e.getClickedBlock().getType() == Material.BEE_NEST) + && e.getAction() == Action.RIGHT_CLICK_BLOCK) { + + Beehive b = (Beehive) e.getClickedBlock().getState().getBlockData(); + + for (Object obj : App.main.getConfig() + .getConfigurationSection( + "players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")) + .toString().equals("honey")) { + + if (App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing") && b.getHoneyLevel() == 5) { + // WENN SPIELER LEDER BOOTS AN HAT + if (!App.main.getConfig() + .get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + + e.getPlayer().getInventory() + .getItemInMainHand() + .getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig().set( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig().get("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + + } + + } + + @EventHandler + public void onBookWrite(PlayerEditBookEvent e) { + + for (Object obj : App.main.getConfig() + .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests") + .getKeys(false) + .toArray()) { + // obj = questnr + if (!obj.toString().equals("null")) { + if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString() + .equals("write")) { + + if (e.isSigning() && App.main.getConfig().get( + "players." + e.getPlayer().getUniqueId() + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool") + .equals("none")) { + if (("Material." + e.getPlayer().getInventory() + .getItemInMainHand().getType().toString()) + .equals(App.main.getConfig() + .get("quests." + obj + .toString() + + ".tool"))) { + App.main.getConfig() + .set("players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig() + .getInt("players." + + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + } else { + App.main.getConfig() + .set("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount", + App.main.getConfig().getInt( + "players." + e.getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".currentcount") + + 1); + } + App.main.saveConfig(); + } + if (App.main.getConfig() + .getInt("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + obj.toString() + + ".currentcount") == App.main + .getConfig() + .getInt("players." + e + .getPlayer() + .getUniqueId() + + ".currentQuests." + + obj.toString() + + ".countneeded") + && App.main.getConfig() + .get("players." + e.getPlayer().getUniqueId() + + ".currentQuests." + + obj.toString() + ".state") + .equals("ongoing")) { + + freeSpace = false; + given = false; + giveSmallReward(obj, e.getPlayer()); + } + EnvironmentExCommands.updateSB(e.getPlayer()); + } + } + } + } +} \ No newline at end of file diff --git a/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java b/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java index cdc1b87..8444ef1 100755 --- a/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java +++ b/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; @@ -25,12 +26,29 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import de.hessj.helper.Helper.Type; import org.bukkit.scheduler.BukkitTask; +import java.util.ArrayList; +import java.util.AbstractMap.SimpleEntry; +import java.util.Map.Entry; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; +import net.kyori.adventure.text.Component; +import net.md_5.bungee.api.ChatColor; + public class EnvironmentExCommands implements CommandExecutor, Listener { - public de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); private final Map> playerPins = new HashMap<>(); public static final Map playerTasks = new HashMap<>(); public static HashMap bossBars = new HashMap<>(); + public static HashMap> boards = new HashMap>(); + public static NamespacedKey nsksurpriseBox; + public static ItemStack surpriseBox; + public static de.hessj.helper.Helper helper = new de.hessj.helper.Helper(); int taskId; public boolean isPlayerOnlineByName(String name) { @@ -38,6 +56,150 @@ public class EnvironmentExCommands implements CommandExecutor, Listener { return player != null && player.isOnline(); } + + public static void updateSB(Player p) { + if (!(boards.containsKey(p.getName()))) { + + Scoreboard board = Bukkit.getServer().getScoreboardManager().getNewScoreboard(); + boards.put(p.getName(), new SimpleEntry(board, false)); + } + Entry actionMapEntry = boards.get(p.getName()); + Scoreboard board = actionMapEntry.getKey(); + + if (board.getObjective(DisplaySlot.SIDEBAR) != null) { + board.getObjective(DisplaySlot.SIDEBAR).unregister(); + } + Objective o = board.registerNewObjective("test", "dummy", Component.text("Quest:")); + + + o.setDisplaySlot(DisplaySlot.SIDEBAR); + Score score; + for (Object obj : App.main.getConfig().getConfigurationSection("players." + p.getUniqueId() + ".currentQuests") + .getKeys(false).toArray()) { + + if (!obj.toString().equals("null")) { + String desc = ""; + if (!App.main.getConfig().get("quests." + obj.toString() + ".tool").equals("none")) { + desc = (App.main.getConfig().get("quests." + obj.toString() + ".description")).toString() + .replace("[x]", + App.main.getConfig() + .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + + ".countneeded") + .toString()/* + * App.main.getConfig().get("quests." + obj.toString() + + * ".count").toString() + */) + .replace("[b]", App.main.getConfig().get("quests." + obj.toString() + ".target").toString()) + .replace("[t]", App.main.getConfig().get("quests." + obj.toString() + ".tool").toString() + .replace("Material.", "")); + + } else { + desc = App.main.getConfig().get("quests." + obj.toString() + ".description").toString() + .replace("[x]", + App.main.getConfig() + .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + + ".countneeded") + .toString()) + .replace("[b]", + App.main.getConfig().get("quests." + obj.toString() + ".target").toString()); + + } + desc = desc.replace("Material.", ""); + if (desc.length() >= 39) { + desc = desc.substring(0, 39); + } + if (App.main.getConfig() + .get("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + ".state") + .equals("finished")) { + board.resetScores(desc); + score = o.getScore(ChatColor.STRIKETHROUGH + "" + desc); + } else { + score = o.getScore(desc); + } + score.setScore(App.main.getConfig() + .getInt("players." + p.getUniqueId() + ".currentQuests." + obj.toString() + ".currentcount")); + checkForCompletion(p); + } + } + if (actionMapEntry.getValue()) { + boards.put(p.getName(), new SimpleEntry(board, true)); + } else { + boards.put(p.getName(), new SimpleEntry(board, false)); + } + } + + static void checkForCompletion(Player p) { + int completed = 0; + int all = 0; + for (Object questIDs : App.main.getConfig().getConfigurationSection("quests").getKeys(false).toArray()) { + if (App.main.getConfig() + .contains("players." + p.getUniqueId().toString() + ".currentQuests." + questIDs.toString())) { + if (App.main.getConfig().get( + "players." + p.getUniqueId().toString() + ".currentQuests." + questIDs.toString() + ".state") + .equals("finished")) { + completed++; + } + all++; + } + } + if (completed == all) { + if (!App.main.getConfig().get("players." + p.getUniqueId().toString() + ".rewards").equals("claimed")) { + + surpriseBox = new ItemStack(Material.PLAYER_HEAD, 1); + SkullMeta im = (SkullMeta) surpriseBox.getItemMeta(); + im.displayName(Component.translatable(ChatColor.WHITE + "Überraschungsbox")); + im.setPlayerProfile(Bukkit.createProfile(UUID.randomUUID(), null)); + PlayerProfile playerProfile = im.getPlayerProfile(); + playerProfile.getProperties().add(new ProfileProperty("textures", + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQxZmJlYTljMmQxOTA0MGU1NjdmMzg3YWI0NmIyZjhhM2ExZGE4ZWVjOWQzOTllMmU0YWRjZjA1YWRhOGEyYSJ9fX0=")); + im.setPlayerProfile(playerProfile); + nsksurpriseBox = new NamespacedKey(App.main, "R3SSurpriseBox"); + im.getPersistentDataContainer().set(nsksurpriseBox, PersistentDataType.STRING, "R3S_SurpriseBox"); + ArrayList lore = new ArrayList(); + lore.add(Component.translatable("Quest Belohnung")); + im.lore(lore); + surpriseBox.setItemMeta(im); + + Boolean freeSpace = false; + Boolean given = false; + for (ItemStack i : p.getInventory().getStorageContents()) { + if (i != null) { + + if (i.getType() == surpriseBox.getType() && i.hasItemMeta() + && i.getItemMeta().getPersistentDataContainer() != null) { + if (i.getItemMeta().getPersistentDataContainer().has(nsksurpriseBox, + PersistentDataType.STRING)) { + if (i.getAmount() < 64) { + i.setAmount(i.getAmount() + 1); + given = true; + break; + } + } + } + + } else { + if (i == null) { + freeSpace = true; + } + } + } + if (!freeSpace && !given) { + + p.sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll, schaffe Platz und logge dich ein, deine Questbelohnung zu erhalten!")); + } else { + if (!given && freeSpace) { + p.getInventory().addItem(surpriseBox); + } + p.sendMessage( + helper.R3SMessage(Type.SUCCESS,"[DailyQuests] Du hast 1x Überraschungsbox als Questbelohnung erhalten!")); + App.main.getConfig().set("players." + p.getUniqueId() + ".rewards", "claimed"); + App.main.saveConfig(); + } + } + } + } + + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { @@ -57,6 +219,19 @@ public class EnvironmentExCommands implements CommandExecutor, Listener { } } + if (label.equalsIgnoreCase("quest")) { + updateSB((Player) sender); + Entry actionMapEntry = boards.get(((Player) sender).getName()); + Scoreboard board = actionMapEntry.getKey(); + if (actionMapEntry.getValue()) { + ((Player) sender).setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard()); + boards.put(((Player) sender).getName(), new SimpleEntry(board, false)); + } else { + ((Player) sender).setScoreboard(board); + boards.put(((Player) sender).getName(), new SimpleEntry(board, true)); + } + } + if (label.equalsIgnoreCase("afk")) { Player p = (Player) sender; p.playerListName(App.helper.R3SMessage(Type.ERROR, "[AFK] " + p.getName())); diff --git a/environmentex/src/main/resources/plugin.yml b/environmentex/src/main/resources/plugin.yml index 667a476..baf39f7 100755 --- a/environmentex/src/main/resources/plugin.yml +++ b/environmentex/src/main/resources/plugin.yml @@ -27,4 +27,7 @@ commands: usage: / r3load: description: ---- + usage: / + quest: + description: Zeigt die heutigen Quests an usage: / \ No newline at end of file