merged BetterHoppers and DailyQuests
All checks were successful
Gitea Actions Demo / Build-Gradle (push) Successful in 4m32s
All checks were successful
Gitea Actions Demo / Build-Gradle (push) Successful in 4m32s
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +0,0 @@
|
||||
#Sun Jul 20 15:58:26 CEST 2025
|
||||
gradle.version=8.14.2
|
||||
@@ -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<Jar> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
|
||||
}
|
||||
|
||||
rootProject.name = "betterhoppers"
|
||||
@@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
main: de.hessj.betterhoppers.App
|
||||
name: BetterHoppersPlugin
|
||||
depend: [HelperPlugin]
|
||||
version: 0.1
|
||||
api-version: 1.21
|
||||
@@ -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<ItemStack> rewardList = new ArrayList<ItemStack>();
|
||||
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<ItemStack> 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<Scoreboard, Boolean> 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<Scoreboard, Boolean>(board, false));
|
||||
} else {
|
||||
p.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard());
|
||||
p.setScoreboard(board);
|
||||
|
||||
DailyQuestsCommands.boards.put(p.getName(), new SimpleEntry<Scoreboard, Boolean>(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<Scoreboard, Boolean> 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() {
|
||||
createDiamondDustItem();
|
||||
registerDiamondDustRecipe();
|
||||
initializeRewardList();
|
||||
}
|
||||
|
||||
nskdiamondDust = new NamespacedKey(App.main, "R3SDiamondDust");
|
||||
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);
|
||||
|
||||
if (getServer().getRecipe(nskDD) == null) {
|
||||
getServer().addRecipe(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
CustomModelDataComponent cmdc4 = mdiamondDust.getCustomModelDataComponent();
|
||||
List<String> list4 = Arrays.asList("diamond_dust");
|
||||
cmdc4.setStrings(list4);
|
||||
mdiamondDust.setCustomModelDataComponent(cmdc4);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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<String, Entry<Scoreboard, Boolean>> boards = new HashMap<String, Entry<Scoreboard, Boolean>>();
|
||||
public static Map<String, Entry<Scoreboard, Boolean>> 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<Scoreboard, Boolean>(board, false));
|
||||
}
|
||||
Entry<Scoreboard, Boolean> 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<Scoreboard, Boolean>(board, true));
|
||||
} else {
|
||||
boards.put(p.getName(), new SimpleEntry<Scoreboard, Boolean>(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<Scoreboard, Boolean> 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<Scoreboard, Boolean>(board, false));
|
||||
} else {
|
||||
((Player) sender).setScoreboard(board);
|
||||
boards.put(((Player) sender).getName(), new SimpleEntry<Scoreboard, Boolean>(board, true));
|
||||
}
|
||||
if (sender instanceof Player player) {
|
||||
updateSB(player);
|
||||
Entry<Scoreboard, Boolean> 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<Component> lore = new ArrayList<Component>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
@@ -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.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -650,7 +650,7 @@ code + .copy-button {
|
||||
<script type="text/javascript">
|
||||
function configurationCacheProblems() { return (
|
||||
// begin-report-data
|
||||
{"diagnostics":[{"locations":[{"path":"/Users/janik/Desktop/MCPlugins/environmentex/src/main/java/de/hessj/environmentex/App.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}],"severity":"ADVICE","problemDetails":[{"text":"Hinweis: Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}],"contextualLabel":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.plural","displayName":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}]},{"locations":[{"path":"/Users/janik/Desktop/MCPlugins/environmentex/src/main/java/de/hessj/environmentex/App.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}],"severity":"ADVICE","problemDetails":[{"text":"Hinweis: Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}],"contextualLabel":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.recompile","displayName":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}]}],"problemsReport":{"totalProblemCount":2,"buildName":"environmentex","requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.2/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
||||
{"diagnostics":[{"locations":[{"path":"/Users/janik/Desktop/MCPlugins/environmentex/src/main/java/de/hessj/environmentex/MobHeads.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}],"severity":"ADVICE","problemDetails":[{"text":"Hinweis: Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}],"contextualLabel":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.plural","displayName":"Einige Eingabedateien verwenden oder überschreiben eine veraltete API."}]},{"locations":[{"path":"/Users/janik/Desktop/MCPlugins/environmentex/src/main/java/de/hessj/environmentex/MobHeads.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}],"severity":"ADVICE","problemDetails":[{"text":"Hinweis: Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}],"contextualLabel":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.deprecated.recompile","displayName":"Wiederholen Sie die Kompilierung mit -Xlint:deprecation, um Details zu erhalten."}]}],"problemsReport":{"totalProblemCount":2,"buildName":"environmentex","requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.2/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
||||
// end-report-data
|
||||
);}
|
||||
</script>
|
||||
|
||||
@@ -28,3 +28,6 @@ commands:
|
||||
r3load:
|
||||
description: ----
|
||||
usage: /<command>
|
||||
quest:
|
||||
description: Zeigt die heutigen Quests an
|
||||
usage: /<command>
|
||||
Binary file not shown.
@@ -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<ItemStack> rewardList = new ArrayList<>();
|
||||
public ItemStack diamondDust;
|
||||
public NamespacedKey nskdiamondDust;
|
||||
public NamespacedKey nskDD;
|
||||
public ItemMeta meta;
|
||||
public ItemMeta meta2;
|
||||
public ItemStack eBottle;
|
||||
public final List<NamespacedKey> recipeKeys = new ArrayList<>();
|
||||
|
||||
public NamespacedKey nskHopper;
|
||||
private final String name = "Trichterfilter";
|
||||
public static boolean coordinateRunner = false;
|
||||
public PluginManager pM = Bukkit.getPluginManager();
|
||||
public HashMap<Player, Boolean> hmActionbar = new HashMap<Player, Boolean>();
|
||||
@@ -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<Scoreboard, Boolean> 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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
1627
environmentex/src/main/java/de/hessj/environmentex/DailyQuests.java
Normal file
1627
environmentex/src/main/java/de/hessj/environmentex/DailyQuests.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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<UUID, Map<String, Location>> playerPins = new HashMap<>();
|
||||
public static final Map<UUID, BukkitTask> playerTasks = new HashMap<>();
|
||||
public static HashMap<UUID, BossBar> bossBars = new HashMap<>();
|
||||
public static HashMap<String, Entry<Scoreboard, Boolean>> boards = new HashMap<String, Entry<Scoreboard, Boolean>>();
|
||||
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<Scoreboard, Boolean>(board, false));
|
||||
}
|
||||
Entry<Scoreboard, Boolean> 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<Scoreboard, Boolean>(board, true));
|
||||
} else {
|
||||
boards.put(p.getName(), new SimpleEntry<Scoreboard, Boolean>(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<Component> lore = new ArrayList<Component>();
|
||||
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<Scoreboard, Boolean> 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<Scoreboard, Boolean>(board, false));
|
||||
} else {
|
||||
((Player) sender).setScoreboard(board);
|
||||
boards.put(((Player) sender).getName(), new SimpleEntry<Scoreboard, Boolean>(board, true));
|
||||
}
|
||||
}
|
||||
|
||||
if (label.equalsIgnoreCase("afk")) {
|
||||
Player p = (Player) sender;
|
||||
p.playerListName(App.helper.R3SMessage(Type.ERROR, "[AFK] " + p.getName()));
|
||||
|
||||
@@ -28,3 +28,6 @@ commands:
|
||||
r3load:
|
||||
description: ----
|
||||
usage: /<command>
|
||||
quest:
|
||||
description: Zeigt die heutigen Quests an
|
||||
usage: /<command>
|
||||
Reference in New Issue
Block a user