GPT'd (refactored) some classes
Some checks failed
Gitea Actions Demo / Build-Gradle (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Build-Gradle (push) Has been cancelled
This commit is contained in:
@@ -16,4 +16,5 @@ TO RELEASE: jukeboxes können mit Redstone gesteuert werden + crafted music
|
|||||||
TO RELEASE: Squids won't spawn + GLOWSTONE DUST für Rahmen
|
TO RELEASE: Squids won't spawn + GLOWSTONE DUST für Rahmen
|
||||||
TO RELEASE: MUTE FUNCTION FOR TAGGED MOBS
|
TO RELEASE: MUTE FUNCTION FOR TAGGED MOBS
|
||||||
r3load command?
|
r3load command?
|
||||||
TO RELEASE: SHIFT RIGHT CLICK INV SORT
|
TO RELEASE: SHIFT RIGHT CLICK INV SORT
|
||||||
|
TO RELEASE: right click with bell on villager folow
|
||||||
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
|
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 1014,68 ms.
|
[INFO] Finished after 896,39 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.
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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -650,7 +650,7 @@ code + .copy-button {
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function configurationCacheProblems() { return (
|
function configurationCacheProblems() { return (
|
||||||
// begin-report-data
|
// begin-report-data
|
||||||
{"diagnostics":[{"locations":[{}],"problem":[{"text":"The org.gradle.api.plugins.Convention type has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"The org.gradle.api.plugins.Convention type has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.2/userguide/upgrading_version_8.html#deprecated_access_to_conventions","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"the-org-gradle-api-plugins-convention-type-has-been-deprecated","displayName":"The org.gradle.api.plugins.Convention type has been deprecated."}]},{"locations":[{}],"problem":[{"text":"The org.gradle.api.plugins.Convention type has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"The org.gradle.api.plugins.Convention type has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.2/userguide/upgrading_version_8.html#deprecated_access_to_conventions","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"the-org-gradle-api-plugins-convention-type-has-been-deprecated","displayName":"The org.gradle.api.plugins.Convention type has been deprecated."}]},{"locations":[{}],"problem":[{"text":"The org.gradle.api.plugins.Convention type has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"The org.gradle.api.plugins.Convention type has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.2/userguide/upgrading_version_8.html#deprecated_access_to_conventions","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"the-org-gradle-api-plugins-convention-type-has-been-deprecated","displayName":"The org.gradle.api.plugins.Convention type has been deprecated."}]}],"problemsReport":{"totalProblemCount":3,"buildName":"environmentex","requestedTasks":"","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/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":[]}}
|
||||||
// end-report-data
|
// end-report-data
|
||||||
);}
|
);}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Binary file not shown.
@@ -1,37 +1,59 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import net.kyori.adventure.text.Component;
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import de.hessj.helper.Helper.Type;
|
import de.hessj.helper.Helper.Type;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
public class AFKListener implements Listener {
|
public class AFKListener implements Listener {
|
||||||
public static HashMap<UUID, BukkitTask> timers = new HashMap<UUID, BukkitTask>();
|
|
||||||
|
private final static Map<UUID, BukkitTask> afkTimers = new HashMap<>();
|
||||||
|
|
||||||
|
private static final long AFK_DELAY_TICKS = 5 * 60 * 20; // 5 minutes
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMove(PlayerMoveEvent e) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
resetTimer(e.getPlayer());
|
Player player = event.getPlayer();
|
||||||
|
resetAfkTimer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTimer(Player p) {
|
@EventHandler
|
||||||
timers.get(p.getUniqueId()).cancel();
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
p.playerListName(Component.text(p.getName()));
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
createAFKTimer(p);
|
BukkitTask task = afkTimers.remove(uuid);
|
||||||
|
if (task != null) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createAFKTimer(Player p) {
|
public static void resetAfkTimer(Player player) {
|
||||||
BukkitTask i = Bukkit.getServer().getScheduler().runTaskLater(App.main, new Runnable() {
|
UUID uuid = player.getUniqueId();
|
||||||
@Override
|
|
||||||
public void run() {
|
// Cancel old task if it exists
|
||||||
p.playerListName(App.helper.R3SMessage(Type.ERROR, "[AFK] " + p.getName()));
|
BukkitTask oldTask = afkTimers.remove(uuid);
|
||||||
|
if (oldTask != null) {
|
||||||
|
oldTask.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset player list name in case they were AFK
|
||||||
|
player.playerListName(Component.text(player.getName()));
|
||||||
|
|
||||||
|
// Create and store new task
|
||||||
|
BukkitTask newTask = Bukkit.getScheduler().runTaskLater(App.main, () -> {
|
||||||
|
if (player.isOnline()) {
|
||||||
|
player.playerListName(App.helper.R3SMessage(Type.ERROR, "[AFK] " + player.getName()));
|
||||||
}
|
}
|
||||||
}, (5 * 60 * 20));
|
}, AFK_DELAY_TICKS);
|
||||||
timers.put(p.getUniqueId(), i);
|
|
||||||
|
afkTimers.put(uuid, newTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,6 @@ public class App extends JavaPlugin {
|
|||||||
public NamespacedKey nskLockedChestRecipe = new NamespacedKey(this, "R3SLockedChestRecipe");
|
public NamespacedKey nskLockedChestRecipe = new NamespacedKey(this, "R3SLockedChestRecipe");
|
||||||
public ItemStack lockedChest;
|
public ItemStack lockedChest;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
SquidPrevention.removeSquidReceipes();
|
SquidPrevention.removeSquidReceipes();
|
||||||
@@ -76,11 +75,9 @@ public class App extends JavaPlugin {
|
|||||||
safechestRecipe.setIngredient('L', rc);
|
safechestRecipe.setIngredient('L', rc);
|
||||||
safechestRecipe.setIngredient('K', Material.TRIPWIRE_HOOK);
|
safechestRecipe.setIngredient('K', Material.TRIPWIRE_HOOK);
|
||||||
safechestRecipe.setIngredient('I', Material.IRON_INGOT);
|
safechestRecipe.setIngredient('I', Material.IRON_INGOT);
|
||||||
if (getServer().getRecipe(nskLockedChestRecipe) == null) {
|
if (getServer().getRecipe(nskLockedChestRecipe) == null) {
|
||||||
App.main.getServer().addRecipe(safechestRecipe);
|
App.main.getServer().addRecipe(safechestRecipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getServer().recipeIterator().forEachRemaining(recipe -> {
|
getServer().recipeIterator().forEachRemaining(recipe -> {
|
||||||
if (recipe instanceof ShapelessRecipe) {
|
if (recipe instanceof ShapelessRecipe) {
|
||||||
@@ -100,13 +97,11 @@ public class App extends JavaPlugin {
|
|||||||
}, 1000 * 20 / 1000, 1000 * 20 / 1000);
|
}, 1000 * 20 / 1000, 1000 * 20 / 1000);
|
||||||
|
|
||||||
getLogger().info("Plugin enabled!");
|
getLogger().info("Plugin enabled!");
|
||||||
|
|
||||||
|
|
||||||
|
// if(App.main.getServer().getPort() == 25588){
|
||||||
// if(App.main.getServer().getPort() == 25588){
|
|
||||||
CustomMusicDiscs cmd = new CustomMusicDiscs();
|
CustomMusicDiscs cmd = new CustomMusicDiscs();
|
||||||
cmd.createDiscs(App.main);
|
cmd.createDiscs(App.main);
|
||||||
//}
|
// }
|
||||||
|
|
||||||
backPack = new ItemStack(Material.BARRIER, 1);
|
backPack = new ItemStack(Material.BARRIER, 1);
|
||||||
ItemMeta im = backPack.getItemMeta();
|
ItemMeta im = backPack.getItemMeta();
|
||||||
@@ -329,7 +324,7 @@ public class App extends JavaPlugin {
|
|||||||
Collection<? extends Player> onlinePlayer = Bukkit.getServer().getOnlinePlayers();
|
Collection<? extends Player> onlinePlayer = Bukkit.getServer().getOnlinePlayers();
|
||||||
for (Player p : onlinePlayer) {
|
for (Player p : onlinePlayer) {
|
||||||
hmActionbar.put(p, true);
|
hmActionbar.put(p, true);
|
||||||
AFKListener.createAFKTimer(p);
|
AFKListener.resetAfkTimer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -468,6 +463,7 @@ public class App extends JavaPlugin {
|
|||||||
pM.registerEvents(new BetterHoes(), this);
|
pM.registerEvents(new BetterHoes(), this);
|
||||||
pM.registerEvents(new ChestEx(), this);
|
pM.registerEvents(new ChestEx(), this);
|
||||||
pM.registerEvents(new Backpacks(), this);
|
pM.registerEvents(new Backpacks(), this);
|
||||||
|
pM.registerEvents(new DeathLoc(), this);
|
||||||
getCommand("test").setExecutor(new EnvironmentExCommands());
|
getCommand("test").setExecutor(new EnvironmentExCommands());
|
||||||
getCommand("y").setExecutor(new EnvironmentExCommands());
|
getCommand("y").setExecutor(new EnvironmentExCommands());
|
||||||
getCommand("n").setExecutor(new EnvironmentExCommands());
|
getCommand("n").setExecutor(new EnvironmentExCommands());
|
||||||
@@ -493,4 +489,9 @@ public class App extends JavaPlugin {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isRaining() {
|
||||||
|
World world = Bukkit.getServer().getWorlds().get(0);
|
||||||
|
return world.hasStorm() || world.isThundering();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
//GPT failed a little
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
@@ -14,7 +14,6 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlotGroup;
|
import org.bukkit.inventory.EquipmentSlotGroup;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -28,20 +27,6 @@ import net.kyori.adventure.text.format.TextDecoration;
|
|||||||
|
|
||||||
public class ArmoredElytra implements Listener {
|
public class ArmoredElytra implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void tes(PlayerDeathEvent e) {
|
|
||||||
Location deathLoc = e.getPlayer().getLocation();
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
e.getPlayer().spigot().respawn();
|
|
||||||
e.getPlayer().sendMessage("Todes koordinaten: " + deathLoc.getBlockX() + " " + deathLoc.getBlockY()
|
|
||||||
+ " " + deathLoc.getBlockZ());
|
|
||||||
}
|
|
||||||
}.runTaskLater(App.main, 1L); // Run next tick to prevent death screen
|
|
||||||
}
|
|
||||||
|
|
||||||
private final List<String> CHESTPLATES = Arrays.asList("LEATHER_CHESTPLATE", "IRON_CHESTPLATE",
|
private final List<String> CHESTPLATES = Arrays.asList("LEATHER_CHESTPLATE", "IRON_CHESTPLATE",
|
||||||
"DIAMOND_CHESTPLATE", "NETHERITE_CHESTPLATE", "GOLDEN_CHESTPLATE", "CHAINMAIL_CHESTPLATE");
|
"DIAMOND_CHESTPLATE", "NETHERITE_CHESTPLATE", "GOLDEN_CHESTPLATE", "CHAINMAIL_CHESTPLATE");
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Collection;
|
import org.bukkit.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.Dispenser;
|
||||||
@@ -15,16 +11,48 @@ import org.bukkit.entity.ItemFrame;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockDispenseEvent;
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.Recipe;
|
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class AutoCrafter implements Listener {
|
public class AutoCrafter implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onThrow(BlockDispenseEvent event) {
|
||||||
|
if (event.getBlock().getType() != Material.DISPENSER) return;
|
||||||
|
|
||||||
|
Dispenser dispenser = (Dispenser) event.getBlock().getState();
|
||||||
|
BlockFace facing = ((Directional) dispenser.getBlockData()).getFacing();
|
||||||
|
Inventory tempInventory = dispenser.getInventory();
|
||||||
|
|
||||||
|
Collection<ItemFrame> frames = event.getBlock().getLocation().getNearbyEntitiesByType(ItemFrame.class, 1.5);
|
||||||
|
if (frames.isEmpty()) return;
|
||||||
|
|
||||||
|
for (ItemFrame frame : frames) {
|
||||||
|
ItemStack frameItem = frame.getItem();
|
||||||
|
if (frameItem.getType() == Material.AIR) return;
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
Material outputMaterial = frameItem.getType();
|
||||||
|
Recipe recipe = findRecipe(outputMaterial);
|
||||||
|
if (recipe == null) return;
|
||||||
|
|
||||||
|
Map<Material, Integer> required = extractIngredients(recipe);
|
||||||
|
if (required.isEmpty()) return;
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!hasRequiredMaterials(tempInventory, required)) return;
|
||||||
|
|
||||||
|
removeMaterials(tempInventory, required);
|
||||||
|
dispenseThroughFace(event.getBlock(), new ItemStack(outputMaterial), facing);
|
||||||
|
}
|
||||||
|
}.runTaskLater(App.main, 0L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Recipe findRecipe(Material output) {
|
private Recipe findRecipe(Material output) {
|
||||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(output))) {
|
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(output))) {
|
||||||
if (recipe.getResult().getType() == output) {
|
if (recipe.getResult().getType() == output) {
|
||||||
@@ -34,110 +62,78 @@ public class AutoCrafter implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private Map<Material, Integer> extractIngredients(Recipe recipe) {
|
||||||
private void onThrow(BlockDispenseEvent event) {
|
Map<Material, Integer> required = new HashMap<>();
|
||||||
if (event.getBlock().getType() != Material.DISPENSER) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dispenser dispenser = (Dispenser) event.getBlock().getState();
|
if (recipe instanceof ShapedRecipe shaped) {
|
||||||
BlockFace facing = ((Directional) dispenser.getBlockData()).getFacing();
|
String[] shape = shaped.getShape();
|
||||||
Inventory tempInventory = dispenser.getInventory();
|
Map<Character, RecipeChoice> choiceMap = shaped.getChoiceMap();
|
||||||
|
|
||||||
Collection<ItemFrame> frames = event.getBlock().getLocation().getNearbyEntitiesByType(ItemFrame.class, 1.5);
|
for (String row : shape) {
|
||||||
if (frames.toArray().length == 0)
|
for (char key : row.toCharArray()) {
|
||||||
return;
|
RecipeChoice choice = choiceMap.get(key);
|
||||||
|
if (choice instanceof RecipeChoice.MaterialChoice matChoice && !matChoice.getChoices().isEmpty()) {
|
||||||
for (ItemFrame frame : frames) {
|
Material mat = matChoice.getChoices().get(0); // Take first acceptable material
|
||||||
if (frame.getItem().getType() == Material.AIR)
|
required.put(mat, required.getOrDefault(mat, 0) + 1);
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
String outputItemName = frame.getItem().getType().name();
|
|
||||||
Recipe recipe = findRecipe(Material.matchMaterial(outputItemName));
|
|
||||||
|
|
||||||
if (recipe == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Material, Integer> required = new HashMap<>();
|
|
||||||
|
|
||||||
if (recipe instanceof ShapedRecipe) {
|
|
||||||
ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
|
|
||||||
shapedRecipe.getIngredientMap().values().forEach(item -> {
|
|
||||||
if (item != null) {
|
|
||||||
required.put(item.getType(), required.getOrDefault(item.getType(), 0) + 1);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else if (recipe instanceof ShapelessRecipe) {
|
|
||||||
ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe;
|
|
||||||
shapelessRecipe.getIngredientList().forEach(item -> {
|
|
||||||
required.put(item.getType(), required.getOrDefault(item.getType(), 0) + 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!hasRequiredMaterials(tempInventory, required)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Map.Entry<Material, Integer> entry : required.entrySet()) {
|
|
||||||
|
|
||||||
removeMaterialFromInventory(dispenser.getInventory(), entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
dispenseThroughFace(event.getBlock(), new ItemStack(Material.matchMaterial(outputItemName)),
|
|
||||||
facing);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}.runTaskLater(App.main, 0L);
|
} else if (recipe instanceof ShapelessRecipe shapeless) {
|
||||||
|
for (RecipeChoice choice : shapeless.getChoiceList()) {
|
||||||
|
if (choice instanceof RecipeChoice.MaterialChoice matChoice && !matChoice.getChoices().isEmpty()) {
|
||||||
|
Material mat = matChoice.getChoices().get(0);
|
||||||
|
required.put(mat, required.getOrDefault(mat, 0) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void dispenseThroughFace(Block dispenser, ItemStack item, BlockFace facing) {
|
return required;
|
||||||
Location dispenseLocation = dispenser.getRelative(facing).getLocation().add(0.5, 0.5, 0.5);
|
|
||||||
Item droppedItem = dispenser.getWorld().dropItem(dispenseLocation, item);
|
|
||||||
Vector velocity = new Vector(facing.getModX(), facing.getModY(), facing.getModZ()).multiply(0.3);
|
|
||||||
droppedItem.setVelocity(velocity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRequiredMaterials(Inventory inventory, Map<Material, Integer> required) {
|
private boolean hasRequiredMaterials(Inventory inventory, Map<Material, Integer> required) {
|
||||||
|
|
||||||
for (Map.Entry<Material, Integer> entry : required.entrySet()) {
|
for (Map.Entry<Material, Integer> entry : required.entrySet()) {
|
||||||
int materialCount = countMaterialInInventory(inventory, entry.getKey());
|
if (countMaterial(inventory, entry.getKey()) < entry.getValue()) {
|
||||||
if (materialCount < entry.getValue()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countMaterialInInventory(Inventory inventory, Material material) {
|
private int countMaterial(Inventory inventory, Material material) {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
for (ItemStack item : inventory.getContents()) {
|
||||||
if (inventory.getItem(i) != null && inventory.getItem(i).getType() == material) {
|
if (item != null && item.getType() == material) {
|
||||||
count += inventory.getItem(i).getAmount();
|
count += item.getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeMaterialFromInventory(Inventory inventory, Material material, int amount) {
|
private void removeMaterials(Inventory inventory, Map<Material, Integer> required) {
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
for (Map.Entry<Material, Integer> entry : required.entrySet()) {
|
||||||
if (inventory.getItem(i) != null && inventory.getItem(i).getType() == material) {
|
Material mat = entry.getKey();
|
||||||
int currentAmount = inventory.getItem(i).getAmount();
|
int amount = entry.getValue();
|
||||||
if (currentAmount <= amount) {
|
|
||||||
amount -= currentAmount;
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
inventory.clear(i);
|
ItemStack item = inventory.getItem(i);
|
||||||
} else {
|
if (item != null && item.getType() == mat) {
|
||||||
inventory.getItem(i).setAmount(currentAmount - amount);
|
int stackAmount = item.getAmount();
|
||||||
break;
|
if (stackAmount <= amount) {
|
||||||
}
|
amount -= stackAmount;
|
||||||
if (amount <= 0) {
|
inventory.clear(i);
|
||||||
break;
|
} else {
|
||||||
|
item.setAmount(stackAmount - amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void dispenseThroughFace(Block dispenserBlock, ItemStack item, BlockFace facing) {
|
||||||
|
Location loc = dispenserBlock.getRelative(facing).getLocation().add(0.5, 0.5, 0.5);
|
||||||
|
Item dropped = dispenserBlock.getWorld().dropItem(loc, item);
|
||||||
|
Vector velocity = new Vector(facing.getModX(), facing.getModY(), facing.getModZ()).multiply(0.3);
|
||||||
|
dropped.setVelocity(velocity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
//GPT failed
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@@ -28,7 +28,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import de.hessj.helper.Helper;
|
import de.hessj.helper.Helper;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
@@ -19,7 +20,6 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.view.AnvilView;
|
import org.bukkit.inventory.view.AnvilView;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import io.netty.util.internal.ThreadLocalRandom;
|
import io.netty.util.internal.ThreadLocalRandom;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -41,12 +41,10 @@ public class BetterHoes implements Listener {
|
|||||||
if (!(right.getItemMeta() instanceof EnchantmentStorageMeta bookMeta)) return;
|
if (!(right.getItemMeta() instanceof EnchantmentStorageMeta bookMeta)) return;
|
||||||
if (!bookMeta.hasStoredEnchant(Enchantment.INFINITY)) return;
|
if (!bookMeta.hasStoredEnchant(Enchantment.INFINITY)) return;
|
||||||
|
|
||||||
// Create the new hoe with Infinity
|
|
||||||
ItemStack result = left.clone();
|
ItemStack result = left.clone();
|
||||||
result.addUnsafeEnchantment(Enchantment.INFINITY, 1);
|
result.addUnsafeEnchantment(Enchantment.INFINITY, 1);
|
||||||
event.setResult(result);
|
event.setResult(result);
|
||||||
|
|
||||||
// Set repair cost using the view (modern API)
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -130,7 +128,6 @@ public class BetterHoes implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also process the center block last to guarantee it runs even with radius 0
|
|
||||||
tryHarvestCrop(event, center, helper);
|
tryHarvestCrop(event, center, helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +149,9 @@ public class BetterHoes implements Listener {
|
|||||||
|
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
helper.damageTool(toolDamageChance(helper.getTool().getType()));
|
helper.damageTool(toolDamageChance(helper.getTool().getType()));
|
||||||
// block.getWorld().dropItemNaturally(block.getLocation(), getCropDrop(cropType));
|
|
||||||
dropCrop(cropType, block.getLocation(), helper.getTool());
|
dropCrop(cropType, block.getLocation(), helper.getTool());
|
||||||
if (hasInfinity(helper.getTool())) {
|
if (hasInfinity(helper.getTool())) {
|
||||||
block.setType(cropType); // reset crop
|
block.setType(cropType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,13 +167,13 @@ public class BetterHoes implements Listener {
|
|||||||
switch (cropType) {
|
switch (cropType) {
|
||||||
case WHEAT -> {
|
case WHEAT -> {
|
||||||
world.dropItemNaturally(location, new ItemStack(Material.WHEAT));
|
world.dropItemNaturally(location, new ItemStack(Material.WHEAT));
|
||||||
int seedCount = 1 + random.nextInt(3); // vanilla: 0–3 seeds (simplified)
|
int seedCount = 1 + random.nextInt(3);
|
||||||
world.dropItemNaturally(location, new ItemStack(Material.WHEAT_SEEDS, seedCount));
|
world.dropItemNaturally(location, new ItemStack(Material.WHEAT_SEEDS, seedCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
case CARROTS -> {
|
case CARROTS -> {
|
||||||
int base = 1;
|
int base = 1;
|
||||||
int extra = random.nextInt(fortuneLevel + 2); // fortune increases upper bound
|
int extra = random.nextInt(fortuneLevel + 2);
|
||||||
int total = base + extra;
|
int total = base + extra;
|
||||||
world.dropItemNaturally(location, new ItemStack(Material.CARROT, total));
|
world.dropItemNaturally(location, new ItemStack(Material.CARROT, total));
|
||||||
}
|
}
|
||||||
@@ -188,7 +184,6 @@ public class BetterHoes implements Listener {
|
|||||||
int total = base + extra;
|
int total = base + extra;
|
||||||
world.dropItemNaturally(location, new ItemStack(Material.POTATO, total));
|
world.dropItemNaturally(location, new ItemStack(Material.POTATO, total));
|
||||||
|
|
||||||
// Slightly increase chance of poisonous potato with Fortune
|
|
||||||
double poisonChance = 0.02 + (0.005 * fortuneLevel);
|
double poisonChance = 0.02 + (0.005 * fortuneLevel);
|
||||||
if (random.nextDouble() < poisonChance) {
|
if (random.nextDouble() < poisonChance) {
|
||||||
world.dropItemNaturally(location, new ItemStack(Material.POISONOUS_POTATO));
|
world.dropItemNaturally(location, new ItemStack(Material.POISONOUS_POTATO));
|
||||||
@@ -220,7 +215,6 @@ public class BetterHoes implements Listener {
|
|||||||
return new Random().nextDouble() < chance ? 0 : 1;
|
return new Random().nextDouble() < chance ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper class for handling tool durability and inventory safely
|
|
||||||
static class PlayerInventoryHelper {
|
static class PlayerInventoryHelper {
|
||||||
private final org.bukkit.entity.Player player;
|
private final org.bukkit.entity.Player player;
|
||||||
private final ItemStack tool;
|
private final ItemStack tool;
|
||||||
|
|||||||
@@ -1,181 +1,111 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.EntityEffect;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.ShulkerBox;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
import de.hessj.helper.Helper;
|
import de.hessj.helper.Helper;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.block.ShulkerBox;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.*;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
import org.bukkit.inventory.*;
|
||||||
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.potion.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class BetterTotems implements Listener {
|
public class BetterTotems implements Listener {
|
||||||
ItemStack totem = new ItemStack(Material.TOTEM_OF_UNDYING, 1);
|
|
||||||
Inventory temp_inv = Bukkit.createInventory(null, 9, Component.translatable("tempBackpack"));
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
private static final ItemStack TOTEM = new ItemStack(Material.TOTEM_OF_UNDYING, 1);
|
||||||
public void onPlayerDamage(EntityDamageEvent event) throws IOException {
|
|
||||||
if (event.getEntity() instanceof Player) {
|
private record BackpackConfig(String key, String configPath, int size) {}
|
||||||
Player player = (Player) event.getEntity();
|
|
||||||
double pHealth = player.getHealth();
|
private static final List<BackpackConfig> backpacks = List.of(
|
||||||
double pDamage = event.getFinalDamage();
|
new BackpackConfig("R3S_kleiner_Rucksack", "backpack.contents.leatherbackpack", 9),
|
||||||
if (event.getCause().equals(DamageCause.VOID)) {
|
new BackpackConfig("R3S_Rucksack", "backpack.contents.ironbackpack", 18),
|
||||||
|
new BackpackConfig("R3S_großer_Rucksack", "backpack.contents.goldbackpack", 27),
|
||||||
|
new BackpackConfig("R3S_riesiger_Rucksack", "backpack.contents.diamondbackpack", 36)
|
||||||
|
);
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerDamage(EntityDamageEvent event) throws IOException {
|
||||||
|
if (!(event.getEntity() instanceof Player player)) return;
|
||||||
|
if (event.getCause() == DamageCause.VOID) return;
|
||||||
|
|
||||||
|
double remainingHealth = player.getHealth() - event.getFinalDamage();
|
||||||
|
if (remainingHealth > 0) return;
|
||||||
|
|
||||||
|
PlayerInventory pInv = player.getInventory();
|
||||||
|
|
||||||
|
if (pInv.containsAtLeast(TOTEM, 1)) {
|
||||||
|
pInv.removeItem(TOTEM);
|
||||||
|
resurrect(event, player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pHealth - pDamage <= 0) {
|
|
||||||
PlayerInventory pInv = player.getInventory();
|
|
||||||
boolean hasTotem = pInv.containsAtLeast(totem, 1);
|
|
||||||
Iterator<ItemStack> var17;
|
|
||||||
if (hasTotem) {
|
|
||||||
pInv.removeItem(totem);
|
|
||||||
resurrect(event, player);
|
|
||||||
} else {
|
|
||||||
var17 = pInv.iterator();
|
|
||||||
|
|
||||||
while (var17.hasNext()) {
|
for (ItemStack item : pInv) {
|
||||||
ItemStack item = (ItemStack) var17.next();
|
if (item == null || !item.hasItemMeta()) continue;
|
||||||
|
|
||||||
if (item != null && item.hasItemMeta()
|
for (int i = 0; i < backpacks.size(); i++) {
|
||||||
&& item.getItemMeta().getPersistentDataContainer().has(App.main.nsk, PersistentDataType.STRING)
|
BackpackConfig config = backpacks.get(i);
|
||||||
&& (item.getItemMeta().getPersistentDataContainer().get(App.main.nsk, PersistentDataType.STRING)
|
NamespacedKey key = switch (i) {
|
||||||
.equals("R3S_kleiner_Rucksack"))) {
|
case 0 -> App.main.nsk;
|
||||||
|
case 1 -> App.main.nsk2;
|
||||||
|
case 2 -> App.main.nsk3;
|
||||||
|
case 3 -> App.main.nsk4;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (key == null) continue;
|
||||||
|
|
||||||
App.main.log("bin drin + k");
|
var pdc = item.getItemMeta().getPersistentDataContainer();
|
||||||
temp_inv = Bukkit.createInventory(null, 9, Component.translatable("tempBackpack"));
|
if (!pdc.has(key, PersistentDataType.STRING)) continue;
|
||||||
ItemStack[] is;
|
if (!Objects.equals(pdc.get(key, PersistentDataType.STRING), config.key())) continue;
|
||||||
|
|
||||||
is = Helper.itemStackArrayFromBase64(
|
String encoded = App.main.getConfig().getString(player.getUniqueId() + "." + config.configPath());
|
||||||
App.main.getConfig().getString(player.getUniqueId() + ".backpack.contents.leatherbackpack"));
|
if (encoded == null) continue;
|
||||||
temp_inv.setContents(is);
|
|
||||||
if (temp_inv.containsAtLeast(totem, 1)) {
|
|
||||||
temp_inv.removeItem(totem);
|
|
||||||
resurrect(event, player);
|
|
||||||
App.main.getConfig().set(player.getUniqueId() + ".backpack.contents.leatherbackpack",
|
|
||||||
Helper.itemStackArrayToBase64(temp_inv.getContents()));
|
|
||||||
App.main.saveConfig();
|
|
||||||
App.main.reloadConfig();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item != null && item.hasItemMeta()
|
Inventory inv = Bukkit.createInventory(null, config.size(), Component.translatable("tempBackpack"));
|
||||||
&& item.getItemMeta().getPersistentDataContainer().has(App.main.nsk2, PersistentDataType.STRING)
|
inv.setContents(Helper.itemStackArrayFromBase64(encoded));
|
||||||
&& (item.getItemMeta().getPersistentDataContainer()
|
|
||||||
.get(App.main.nsk2, PersistentDataType.STRING)
|
|
||||||
.equals("R3S_Rucksack"))) {
|
|
||||||
|
|
||||||
App.main.log("bin drin + r");
|
if (inv.containsAtLeast(TOTEM, 1)) {
|
||||||
temp_inv = Bukkit.createInventory(null, 18, Component.translatable("tempBackpack"));
|
inv.removeItem(TOTEM);
|
||||||
ItemStack[] is;
|
resurrect(event, player);
|
||||||
|
App.main.getConfig().set(player.getUniqueId() + "." + config.configPath(),
|
||||||
is = Helper.itemStackArrayFromBase64(
|
Helper.itemStackArrayToBase64(inv.getContents()));
|
||||||
App.main.getConfig().getString(player.getUniqueId() + ".backpack.contents.ironbackpack"));
|
App.main.saveConfig();
|
||||||
temp_inv.setContents(is);
|
App.main.reloadConfig();
|
||||||
if (temp_inv.containsAtLeast(totem, 1)) {
|
return;
|
||||||
temp_inv.removeItem(totem);
|
}
|
||||||
resurrect(event, player);
|
|
||||||
App.main.getConfig().set(player.getUniqueId() + ".backpack.contents.ironbackpack",
|
|
||||||
Helper.itemStackArrayToBase64(temp_inv.getContents()));
|
|
||||||
App.main.saveConfig();
|
|
||||||
App.main.reloadConfig();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item != null && item.hasItemMeta()
|
|
||||||
&& item.getItemMeta().getPersistentDataContainer().has(App.main.nsk3, PersistentDataType.STRING)
|
|
||||||
&& (item.getItemMeta().getPersistentDataContainer()
|
|
||||||
.get(App.main.nsk3, PersistentDataType.STRING)
|
|
||||||
.equals("R3S_großer_Rucksack"))) {
|
|
||||||
|
|
||||||
App.main.log("bin drin + g");
|
|
||||||
temp_inv = Bukkit.createInventory(null, 27, Component.translatable("tempBackpack"));
|
|
||||||
ItemStack[] is;
|
|
||||||
|
|
||||||
is = Helper.itemStackArrayFromBase64(
|
|
||||||
App.main.getConfig().getString(player.getUniqueId() + ".backpack.contents.goldbackpack"));
|
|
||||||
temp_inv.setContents(is);
|
|
||||||
if (temp_inv.containsAtLeast(totem, 1)) {
|
|
||||||
temp_inv.removeItem(totem);
|
|
||||||
resurrect(event, player);
|
|
||||||
App.main.getConfig().set(player.getUniqueId() + ".backpack.contents.goldbackpack",
|
|
||||||
Helper.itemStackArrayToBase64(temp_inv.getContents()));
|
|
||||||
App.main.saveConfig();
|
|
||||||
App.main.reloadConfig();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item != null && item.hasItemMeta()
|
|
||||||
&& item.getItemMeta().getPersistentDataContainer().has(App.main.nsk4, PersistentDataType.STRING)
|
|
||||||
&& (item.getItemMeta().getPersistentDataContainer()
|
|
||||||
.get(App.main.nsk4, PersistentDataType.STRING)
|
|
||||||
.equals("R3S_riesiger_Rucksack"))) {
|
|
||||||
|
|
||||||
App.main.log("bin drin + riesig");
|
|
||||||
temp_inv = Bukkit.createInventory(null, 36, Component.translatable("tempBackpack"));
|
|
||||||
ItemStack[] is;
|
|
||||||
|
|
||||||
is = Helper.itemStackArrayFromBase64(
|
|
||||||
App.main.getConfig().getString(player.getUniqueId() + ".backpack.contents.diamondbackpack"));
|
|
||||||
temp_inv.setContents(is);
|
|
||||||
if (temp_inv.containsAtLeast(totem, 1)) {
|
|
||||||
temp_inv.removeItem(totem);
|
|
||||||
resurrect(event, player);
|
|
||||||
App.main.getConfig().set(player.getUniqueId() + ".backpack.contents.diamondbackpack",
|
|
||||||
Helper.itemStackArrayToBase64(temp_inv.getContents()));
|
|
||||||
App.main.saveConfig();
|
|
||||||
App.main.reloadConfig();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item != null && (item.getType().toString().endsWith("SHULKER_BOX"))) {
|
|
||||||
|
|
||||||
BlockStateMeta blockMeta = (BlockStateMeta) item.getItemMeta();
|
|
||||||
if (blockMeta.getBlockState() instanceof ShulkerBox) {
|
|
||||||
ShulkerBox box = (ShulkerBox) blockMeta.getBlockState();
|
|
||||||
Inventory inv = box.getSnapshotInventory();
|
|
||||||
|
|
||||||
if (inv.containsAtLeast(totem, 1)) {
|
|
||||||
inv.removeItem(new ItemStack[] { totem });
|
|
||||||
box.update(true, false);
|
|
||||||
blockMeta.setBlockState(box);
|
|
||||||
item.setItemMeta(blockMeta);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (item.getType().toString().endsWith("SHULKER_BOX")) {
|
||||||
|
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
||||||
|
if (!(meta.getBlockState() instanceof ShulkerBox box)) continue;
|
||||||
|
|
||||||
}
|
Inventory shulkerInv = box.getSnapshotInventory();
|
||||||
}
|
if (shulkerInv.containsAtLeast(TOTEM, 1)) {
|
||||||
|
shulkerInv.removeItem(TOTEM);
|
||||||
|
box.update(true, false);
|
||||||
|
meta.setBlockState(box);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
resurrect(event, player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void resurrect(EntityDamageEvent event, Player player) {
|
private void resurrect(EntityDamageEvent event, Player player) {
|
||||||
event.setDamage(0.0D);
|
event.setDamage(0.0D);
|
||||||
player.setHealth(5);
|
player.setHealth(5);
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 5 * 20, 2));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 100, 2));
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 45 * 20, 2));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 900, 2));
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 40 * 20, 1));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 800, 1));
|
||||||
if (event.getCause().equals(DamageCause.DROWNING)) {
|
if (event.getCause() == DamageCause.DROWNING) {
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 5 * 20, 1));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 100, 1));
|
||||||
}
|
}
|
||||||
player.playEffect(EntityEffect.PROTECTED_FROM_DEATH);
|
player.playEffect(EntityEffect.PROTECTED_FROM_DEATH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -10,18 +11,24 @@ import com.google.common.base.Enums;
|
|||||||
import io.papermc.paper.event.entity.EntityInsideBlockEvent;
|
import io.papermc.paper.event.entity.EntityInsideBlockEvent;
|
||||||
|
|
||||||
public class CauldronConcrete implements Listener {
|
public class CauldronConcrete implements Listener {
|
||||||
@EventHandler
|
|
||||||
public void onPowderDrop(EntityInsideBlockEvent e){
|
@EventHandler
|
||||||
Block block = e.getBlock();
|
public void onPowderDrop(EntityInsideBlockEvent event) {
|
||||||
if(block.getType()==Material.WATER_CAULDRON && e.getEntity() instanceof Item){
|
if (!(event.getEntity() instanceof Item item)) return;
|
||||||
Item item = (Item) e.getEntity();
|
|
||||||
ItemStack concrete = item.getItemStack();
|
Block block = event.getBlock();
|
||||||
if(!concrete.getType().toString().endsWith("_CONCRETE_POWDER")) return;
|
if (block.getType() != Material.WATER_CAULDRON) return;
|
||||||
Material mat = Enums.getIfPresent(Material.class, concrete.getType().toString().replace("_POWDER", "")).orNull();
|
|
||||||
if(mat != null){
|
ItemStack stack = item.getItemStack();
|
||||||
item.getWorld().dropItem(item.getLocation(), new ItemStack(mat,concrete.getAmount()));
|
Material type = stack.getType();
|
||||||
item.remove();
|
|
||||||
}
|
if (!type.name().endsWith("_CONCRETE_POWDER")) return;
|
||||||
}
|
|
||||||
|
String hardenedName = type.name().replace("_POWDER", "");
|
||||||
|
Material hardened = Enums.getIfPresent(Material.class, hardenedName).orNull();
|
||||||
|
if (hardened == null) return;
|
||||||
|
|
||||||
|
item.getWorld().dropItem(item.getLocation(), new ItemStack(hardened, stack.getAmount()));
|
||||||
|
item.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -9,22 +10,44 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
import org.bukkit.inventory.StonecuttingRecipe;
|
import org.bukkit.inventory.StonecuttingRecipe;
|
||||||
|
|
||||||
public class CustomRecipes implements Listener {
|
public class CustomRecipes implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEnable(ServerLoadEvent e) {
|
public void onEnable(ServerLoadEvent e) {
|
||||||
StonecuttingRecipe scrStoneToCobble = new StonecuttingRecipe(new NamespacedKey(App.main, "R3S_SCR_STONE"), new ItemStack(Material.COBBLESTONE), Material.STONE);
|
StonecuttingRecipe scrStoneToCobble = new StonecuttingRecipe(
|
||||||
App.main.getServer().addRecipe(scrStoneToCobble);
|
new NamespacedKey(App.main, "R3S_SCR_STONE"),
|
||||||
App.main.recipeKeys.add(scrStoneToCobble.getKey());
|
new ItemStack(Material.COBBLESTONE),
|
||||||
ShapelessRecipe srGlowberryToGlowpowder = new ShapelessRecipe(new NamespacedKey(App.main, "R3S_SLR_GLOWBERRY"), new ItemStack(Material.GLOWSTONE_DUST));
|
Material.STONE);
|
||||||
srGlowberryToGlowpowder.addIngredient(new ItemStack(Material.GLOW_BERRIES));
|
registerRecipe(scrStoneToCobble);
|
||||||
App.main.getServer().addRecipe(srGlowberryToGlowpowder);
|
|
||||||
App.main.recipeKeys.add(srGlowberryToGlowpowder.getKey());
|
ShapelessRecipe srGlowberryToGlowpowder = new ShapelessRecipe(
|
||||||
ShapedRecipe srSoulsoil = new ShapedRecipe(new NamespacedKey(App.main, "R3S_SR_SOULSOIL"), new ItemStack(Material.SOUL_SOIL));
|
new NamespacedKey(App.main, "R3S_SLR_GLOWBERRY"),
|
||||||
srSoulsoil.shape("DS ","SD "," ");
|
new ItemStack(Material.GLOWSTONE_DUST));
|
||||||
|
srGlowberryToGlowpowder.addIngredient(Material.GLOW_BERRIES);
|
||||||
|
registerRecipe(srGlowberryToGlowpowder);
|
||||||
|
|
||||||
|
ShapedRecipe srSoulsoil = new ShapedRecipe(
|
||||||
|
new NamespacedKey(App.main, "R3S_SR_SOULSOIL"),
|
||||||
|
new ItemStack(Material.SOUL_SOIL));
|
||||||
|
srSoulsoil.shape("DS ", "SD ", " ");
|
||||||
srSoulsoil.setIngredient('S', Material.SOUL_SAND);
|
srSoulsoil.setIngredient('S', Material.SOUL_SAND);
|
||||||
srSoulsoil.setIngredient('D', Material.DIRT);
|
srSoulsoil.setIngredient('D', Material.DIRT);
|
||||||
App.main.getServer().addRecipe(srSoulsoil);
|
registerRecipe(srSoulsoil);
|
||||||
App.main.recipeKeys.add(srSoulsoil.getKey());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void registerRecipe(ShapedRecipe recipe) {
|
||||||
|
App.main.getServer().addRecipe(recipe);
|
||||||
|
App.main.recipeKeys.add(recipe.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerRecipe(ShapelessRecipe recipe) {
|
||||||
|
App.main.getServer().addRecipe(recipe);
|
||||||
|
App.main.recipeKeys.add(recipe.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerRecipe(StonecuttingRecipe recipe) {
|
||||||
|
App.main.getServer().addRecipe(recipe);
|
||||||
|
App.main.recipeKeys.add(recipe.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT failed
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//GPT not needed
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@@ -8,7 +9,8 @@ import org.bukkit.event.entity.EntityTargetEvent;
|
|||||||
public class EntityMuter implements Listener {
|
public class EntityMuter implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntitySound(EntityTargetEvent event) {
|
public void onEntitySound(EntityTargetEvent event) {
|
||||||
if (event.getEntity().getType() != EntityType.ZOMBIE && event.getTarget() != null && event.getTarget().getType() != EntityType.VILLAGER) {
|
if (event.getEntity().getType() != EntityType.ZOMBIE && event.getTarget() != null
|
||||||
|
&& event.getTarget().getType() != EntityType.VILLAGER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.getEntity().customName() != null) {
|
if (event.getEntity().customName() != null) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//TODO: needs fix!
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
//GPT failed
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -34,7 +34,7 @@ public class HealthBarListener implements Listener {
|
|||||||
public void setBarString(Double remainingHearts, Double fullHearts, Double finaldmg, LivingEntity lentity) {
|
public void setBarString(Double remainingHearts, Double fullHearts, Double finaldmg, LivingEntity lentity) {
|
||||||
lentity.setCustomNameVisible(true);
|
lentity.setCustomNameVisible(true);
|
||||||
if (remainingHearts > 0 && remainingHearts < 1) {
|
if (remainingHearts > 0 && remainingHearts < 1) {
|
||||||
lentity.customName(Component.text("Stehend K.O"));
|
lentity.customName(Component.text("One hit wonder"));
|
||||||
|
|
||||||
} else if (remainingHearts > 0) {
|
} else if (remainingHearts > 0) {
|
||||||
lentity.customName(
|
lentity.customName(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@@ -31,103 +31,106 @@ import net.kyori.adventure.text.format.TextDecoration;
|
|||||||
|
|
||||||
public class InfinityWaterBucket implements Listener {
|
public class InfinityWaterBucket implements Listener {
|
||||||
|
|
||||||
|
private final Helper helper = new Helper(); // Avoid repeated instantiations
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onAnvilUse(PrepareAnvilEvent e) {
|
public void onAnvilUse(PrepareAnvilEvent event) {
|
||||||
if (e.getView().getBottomInventory().getHolder() instanceof Player) {
|
if (!(event.getView().getBottomInventory().getHolder() instanceof Player))
|
||||||
AnvilView av = e.getView();
|
return;
|
||||||
ItemStack slot1 = av.getItem(0);
|
|
||||||
ItemStack slot2 = av.getItem(1);
|
AnvilView anvil = event.getView();
|
||||||
if (slot1 == null || slot2 == null)
|
ItemStack slot1 = anvil.getItem(0);
|
||||||
|
ItemStack slot2 = anvil.getItem(1);
|
||||||
|
|
||||||
|
if (slot1 == null || slot2 == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (slot1.getType() == Material.WATER_BUCKET && slot2.getType() == Material.ENCHANTED_BOOK) {
|
||||||
|
if (!(slot2.getItemMeta() instanceof EnchantmentStorageMeta meta))
|
||||||
return;
|
return;
|
||||||
if (slot1.getType() == Material.WATER_BUCKET && slot2.getType() == Material.ENCHANTED_BOOK) {
|
|
||||||
EnchantmentStorageMeta enchMeta = (EnchantmentStorageMeta) slot2.getItemMeta();
|
|
||||||
|
|
||||||
Map<Enchantment, Integer> enchs = enchMeta.getStoredEnchants();
|
if (meta.hasStoredEnchant(Enchantment.INFINITY)) {
|
||||||
if (enchs.containsKey(Enchantment.INFINITY) && enchs.get(Enchantment.INFINITY) > 0) {
|
ItemStack result = slot1.clone();
|
||||||
ItemStack result = slot1.clone();
|
ItemMeta resultMeta = result.getItemMeta();
|
||||||
ItemMeta meta = result.getItemMeta();
|
|
||||||
meta.displayName(Component.text(av.getRenameText()));
|
|
||||||
Style st = Style.style().decoration(TextDecoration.ITALIC, false).build();
|
|
||||||
if (av.getRenameText().length() == 0) {
|
|
||||||
meta.displayName(Component.translatable(slot1.getType().getItemTranslationKey()).style(st));
|
|
||||||
} else {
|
|
||||||
meta.displayName(Component.text(av.getRenameText()).style(st));
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.addEnchant(Enchantment.INFINITY, 1, true);
|
Style style = Style.style().decoration(TextDecoration.ITALIC, false).build();
|
||||||
|
String renameText = anvil.getRenameText();
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
result.setItemMeta(meta);
|
|
||||||
av.setRepairCost(2);
|
|
||||||
av.setItem(2, result);
|
|
||||||
}
|
|
||||||
}.runTaskLater(App.main, 1);
|
|
||||||
|
|
||||||
|
if (renameText == null || renameText.isEmpty()) {
|
||||||
|
resultMeta
|
||||||
|
.displayName(Component.translatable(slot1.getType().getItemTranslationKey()).style(style));
|
||||||
|
} else {
|
||||||
|
resultMeta.displayName(Component.text(renameText).style(style));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultMeta.addEnchant(Enchantment.INFINITY, 1, true);
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
result.setItemMeta(resultMeta);
|
||||||
|
anvil.setRepairCost(2);
|
||||||
|
anvil.setItem(2, result);
|
||||||
|
}
|
||||||
|
}.runTaskLater(App.main, 1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFishPickUp(PlayerBucketEntityEvent e) {
|
public void onFishPickUp(PlayerBucketEntityEvent event) {
|
||||||
var helper = new Helper();
|
ItemStack item = event.getOriginalBucket();
|
||||||
Player player = e.getPlayer();
|
if (item == null || item.getEnchantments().isEmpty())
|
||||||
ItemStack item = e.getOriginalBucket();
|
|
||||||
if (item == null)
|
|
||||||
return;
|
return;
|
||||||
if (item.getEnchantments().size() <= 0)
|
|
||||||
return;
|
if (event.getEntity() instanceof Fish || event.getEntity() instanceof Axolotl) {
|
||||||
if (e.getEntity() instanceof Fish || e.getEntity() instanceof Axolotl) {
|
event.setCancelled(true);
|
||||||
e.setCancelled(true);
|
event.getPlayer().sendMessage(helper.R3SMessage(Type.ERROR, "Du kannst mit diesem Eimer nichts fangen!"));
|
||||||
player.sendMessage(helper.R3SMessage(Type.ERROR, "Du kannst mit diesem Eimer nichts fangen!"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBucketUse(PlayerInteractEvent e) {
|
public void onBucketUse(PlayerInteractEvent event) {
|
||||||
if (e.getItem() == null)
|
if (event.getItem() == null)
|
||||||
return;
|
return;
|
||||||
ItemStack itm = e.getItem().clone();
|
|
||||||
if (itm.getType() == Material.WATER_BUCKET && itm.getEnchantments().size() > 0
|
|
||||||
&& e.getAction() == Action.RIGHT_CLICK_BLOCK && e.useItemInHand() != Result.DENY) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
Player player = e.getPlayer();
|
|
||||||
if (player.getWorld().getEnvironment() == Environment.NETHER
|
|
||||||
|| (App.helper.isInteractable(e.getClickedBlock()) && !e.getPlayer().isSneaking()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Block block = e.getClickedBlock().getRelative(e.getBlockFace());
|
ItemStack bucket = event.getItem();
|
||||||
|
if (bucket.getType() != Material.WATER_BUCKET || bucket.getEnchantments().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
if (!e.getClickedBlock().isEmpty() && e.getClickedBlock().getBlockData() instanceof Waterlogged) {
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.useItemInHand() == Result.DENY)
|
||||||
|
return;
|
||||||
|
|
||||||
Waterlogged waterlogged = (Waterlogged) e.getClickedBlock().getBlockData();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!waterlogged.isWaterlogged()) {
|
if (player.getWorld().getEnvironment() == Environment.NETHER ||
|
||||||
waterlogged.setWaterlogged(true);
|
(App.helper.isInteractable(event.getClickedBlock()) && !player.isSneaking())) {
|
||||||
e.getClickedBlock().setBlockData(waterlogged);
|
return;
|
||||||
} else {
|
}
|
||||||
waterlogged.setWaterlogged(false);
|
|
||||||
e.getClickedBlock().setBlockData(waterlogged);
|
event.setCancelled(true);
|
||||||
}
|
Block clickedBlock = event.getClickedBlock();
|
||||||
|
if (clickedBlock == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Block targetBlock = clickedBlock.getRelative(event.getBlockFace());
|
||||||
|
|
||||||
|
// Waterlog toggle
|
||||||
|
if (!clickedBlock.isEmpty() && clickedBlock.getBlockData() instanceof Waterlogged waterlogged) {
|
||||||
|
waterlogged.setWaterlogged(!waterlogged.isWaterlogged());
|
||||||
|
clickedBlock.setBlockData(waterlogged);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove full water source or place new water
|
||||||
|
if (targetBlock.getType() == Material.WATER && targetBlock.getBlockData() instanceof Levelled levelled) {
|
||||||
|
if (levelled.getLevel() == 0) {
|
||||||
|
targetBlock.setType(Material.AIR);
|
||||||
} else {
|
} else {
|
||||||
if (block.getType().equals(Material.WATER)) { // aber nicht bei flowing water!!
|
targetBlock.setType(Material.WATER); // refresh water
|
||||||
|
|
||||||
Levelled lv = (Levelled) block.getBlockData();
|
|
||||||
|
|
||||||
if (lv.getLevel() == 0) {
|
|
||||||
block.setType(Material.AIR, true);
|
|
||||||
} else {
|
|
||||||
block.setType(Material.WATER, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
block.setType(Material.WATER, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
targetBlock.setType(Material.WATER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ public class LoginListener implements Listener {
|
|||||||
App.main.hmActionbar.put(e.getPlayer(), true);
|
App.main.hmActionbar.put(e.getPlayer(), true);
|
||||||
|
|
||||||
e.getPlayer().discoverRecipes(App.main.recipeKeys);
|
e.getPlayer().discoverRecipes(App.main.recipeKeys);
|
||||||
AFKListener.createAFKTimer(e.getPlayer());
|
AFKListener.resetAfkTimer(e.getPlayer());
|
||||||
|
|
||||||
e.joinMessage(null);
|
e.joinMessage(null);
|
||||||
if (!customConfig.contains("players." + e.getPlayer().getUniqueId())) {
|
if (!customConfig.contains("players." + e.getPlayer().getUniqueId())) {
|
||||||
|
|||||||
@@ -1,39 +1,35 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
public class MobBurner implements Listener {
|
public class MobBurner implements Listener {
|
||||||
|
|
||||||
public static Boolean isRaining(){
|
private static final int FIRE_DURATION_TICKS = 20;
|
||||||
World w = Bukkit.getServer().getWorlds().get(0);
|
|
||||||
if(w.hasStorm() || w.isThundering()){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void tryBurning() {
|
public static void tryBurning() {
|
||||||
if(App.isDay() && !isRaining()){
|
if (!App.isDay() || App.isRaining()) {
|
||||||
World w = Bukkit.getServer().getWorlds().get(0);
|
return;
|
||||||
List<Entity> entities = new ArrayList<Entity>(w.getLivingEntities());
|
}
|
||||||
for(Entity e: entities){
|
|
||||||
if(e.getType().equals(EntityType.CREEPER)){
|
World world = Bukkit.getServer().getWorlds().get(0);
|
||||||
Location loc = e.getLocation();
|
List<Creeper> creepers = world.getLivingEntities().stream()
|
||||||
if (loc.getBlockY() >= w.getHighestBlockYAt(loc))
|
.filter(e -> e.getType() == EntityType.CREEPER)
|
||||||
{
|
.map(e -> (Creeper) e)
|
||||||
e.setFireTicks(1000 * 20 / 1000);
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
|
for (Creeper creeper : creepers) {
|
||||||
|
Location loc = creeper.getLocation();
|
||||||
|
if (loc.getBlockY() >= world.getHighestBlockYAt(loc)) {
|
||||||
|
creeper.setFireTicks(FIRE_DURATION_TICKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@@ -15,62 +15,53 @@ import org.bukkit.inventory.RecipeChoice;
|
|||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
public class SquidPrevention implements Listener {
|
public class SquidPrevention implements Listener {
|
||||||
|
|
||||||
|
private static final String NAMESPACE = "environmentex";
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSquidSpawn(EntitySpawnEvent event) {
|
public void onSquidSpawn(EntitySpawnEvent event) {
|
||||||
if (event.getEntityType() == EntityType.SQUID || event.getEntityType() == EntityType.GLOW_SQUID) {
|
EntityType type = event.getEntityType();
|
||||||
|
if (type == EntityType.SQUID || type == EntityType.GLOW_SQUID) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSquidReceipes() {
|
public static void removeSquidReceipes() {
|
||||||
Iterator<Recipe> it = Bukkit.recipeIterator();
|
Iterator<Recipe> it = Bukkit.recipeIterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Recipe recipe = it.next();
|
Recipe recipe = it.next();
|
||||||
if (recipe instanceof ShapelessRecipe sr &&
|
|
||||||
sr.getResult().getType() == Material.WRITABLE_BOOK) {
|
if (!(recipe instanceof ShapelessRecipe sr)) {
|
||||||
it.remove(); // remove the default Book and Quill recipe
|
continue;
|
||||||
}
|
}
|
||||||
if (recipe instanceof ShapelessRecipe sr &&
|
|
||||||
sr.getResult().getType() == Material.GLOW_ITEM_FRAME) {
|
Material resultType = sr.getResult().getType();
|
||||||
it.remove(); // remove the default Book and Quill recipe
|
|
||||||
|
if (resultType == Material.WRITABLE_BOOK || resultType == Material.GLOW_ITEM_FRAME) {
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addCustomSquidRecipes() {
|
public static void addCustomSquidRecipes() {
|
||||||
ItemStack bookAndQuill = new ItemStack(Material.WRITABLE_BOOK);
|
ItemStack bookAndQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||||
|
ShapelessRecipe bookRecipe = new ShapelessRecipe(new NamespacedKey(NAMESPACE, "custom_book_and_quill"), bookAndQuill);
|
||||||
|
bookRecipe.addIngredient(Material.BOOK);
|
||||||
|
bookRecipe.addIngredient(Material.FEATHER);
|
||||||
|
bookRecipe.addIngredient(Material.BLACK_DYE);
|
||||||
|
Bukkit.addRecipe(bookRecipe);
|
||||||
|
|
||||||
ShapelessRecipe customRecipe = new ShapelessRecipe(
|
ItemStack blackDye = new ItemStack(Material.BLACK_DYE);
|
||||||
new NamespacedKey("environmentex", "custom_book_and_quill"),
|
ShapelessRecipe blackDyeRecipe = new ShapelessRecipe(new NamespacedKey(NAMESPACE, "custom_black_dye"), blackDye);
|
||||||
bookAndQuill);
|
RecipeChoice.MaterialChoice coalChoice = new RecipeChoice.MaterialChoice(Material.COAL, Material.CHARCOAL);
|
||||||
|
blackDyeRecipe.addIngredient(coalChoice);
|
||||||
customRecipe.addIngredient(Material.BOOK);
|
Bukkit.addRecipe(blackDyeRecipe);
|
||||||
customRecipe.addIngredient(Material.FEATHER);
|
|
||||||
customRecipe.addIngredient(Material.BLACK_DYE);
|
|
||||||
Bukkit.addRecipe(customRecipe);
|
|
||||||
|
|
||||||
ItemStack blackdye = new ItemStack(Material.BLACK_DYE);
|
|
||||||
|
|
||||||
ShapelessRecipe blackcustomRecipe = new ShapelessRecipe(
|
|
||||||
new NamespacedKey("environmentex", "custom_black_dye"),
|
|
||||||
blackdye);
|
|
||||||
|
|
||||||
// Use RecipeChoice.MaterialChoice for multiple options
|
|
||||||
RecipeChoice choice = new RecipeChoice.MaterialChoice(Material.COAL, Material.CHARCOAL);
|
|
||||||
blackcustomRecipe.addIngredient(choice);
|
|
||||||
|
|
||||||
Bukkit.addRecipe(blackcustomRecipe);
|
|
||||||
|
|
||||||
ItemStack glow_frame = new ItemStack(Material.GLOW_ITEM_FRAME);
|
|
||||||
|
|
||||||
ShapelessRecipe glow_framecustomRecipe = new ShapelessRecipe(
|
|
||||||
new NamespacedKey("environmentex", "custom_glow_frame"),
|
|
||||||
glow_frame);
|
|
||||||
|
|
||||||
glow_framecustomRecipe.addIngredient(Material.GLOWSTONE_DUST);
|
|
||||||
glow_framecustomRecipe.addIngredient(Material.ITEM_FRAME);
|
|
||||||
|
|
||||||
Bukkit.addRecipe(glow_framecustomRecipe);
|
|
||||||
|
|
||||||
|
ItemStack glowFrame = new ItemStack(Material.GLOW_ITEM_FRAME);
|
||||||
|
ShapelessRecipe glowFrameRecipe = new ShapelessRecipe(new NamespacedKey(NAMESPACE, "custom_glow_frame"), glowFrame);
|
||||||
|
glowFrameRecipe.addIngredient(Material.GLOWSTONE_DUST);
|
||||||
|
glowFrameRecipe.addIngredient(Material.ITEM_FRAME);
|
||||||
|
Bukkit.addRecipe(glowFrameRecipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,84 +1,144 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
import org.bukkit.entity.Villager.Profession;
|
import org.bukkit.entity.Villager.Profession;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import com.destroystokyo.paper.entity.Pathfinder;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
|
|
||||||
public class VillagerListener implements Listener {
|
public class VillagerListener implements Listener {
|
||||||
|
|
||||||
|
private final Map<UUID, BukkitTask> activeVillagerTasks = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClickNPC(PlayerInteractAtEntityEvent e) {
|
public void onClickNPC(PlayerInteractAtEntityEvent e) {
|
||||||
if (e.getPlayer().displayName().toString().contains("R3STEAS")) {
|
Player player = e.getPlayer();
|
||||||
if (e.getRightClicked() instanceof Villager
|
String playerName = player.displayName().toString();
|
||||||
&& e.getPlayer().getInventory().getItemInMainHand().getType() == Material.BELL) {
|
|
||||||
|
|
||||||
Villager vil = (Villager) e.getRightClicked();
|
if (!playerName.contains("R3STEAS"))
|
||||||
if (vil.getProfession() == Profession.LIBRARIAN && vil.getVillagerExperience() == 0) {
|
return;
|
||||||
vil.setProfession(Profession.NONE);
|
|
||||||
|
|
||||||
vil.setProfession(Profession.LIBRARIAN);
|
if (!(e.getRightClicked() instanceof Villager vil))
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(App.main, new Runnable() {
|
return;
|
||||||
public void run() {
|
if (player.getInventory().getItemInMainHand().getType() != Material.BELL)
|
||||||
e.getPlayer().getOpenInventory().close();
|
return;
|
||||||
|
|
||||||
for (MerchantRecipe mr : vil.getRecipes()) {
|
if (vil.getProfession() == Profession.LIBRARIAN && vil.getVillagerExperience() == 0) {
|
||||||
|
// Reset profession, probably to refresh trades
|
||||||
|
vil.setProfession(Profession.NONE);
|
||||||
|
vil.setProfession(Profession.LIBRARIAN);
|
||||||
|
|
||||||
Collection<Player> en = Bukkit.getServer().getWorlds().get(0)
|
Bukkit.getScheduler().runTaskLater(App.main, () -> {
|
||||||
.getNearbyPlayers(vil.getLocation(), 5);
|
player.getOpenInventory().close();
|
||||||
|
showEnchantmentInfoToNearbyPlayers(vil);
|
||||||
|
}, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Entity ent : en) {
|
private void showEnchantmentInfoToNearbyPlayers(Villager vil) {
|
||||||
if (ent instanceof Player) {
|
Collection<Player> nearbyPlayers = Bukkit.getWorlds().get(0).getNearbyPlayers(vil.getLocation(), 5);
|
||||||
Player enti = (Player) ent;
|
|
||||||
if(!enti.getPlayer().displayName().toString().contains("R3STEAS")){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mr.getResult().getItemMeta() instanceof EnchantmentStorageMeta) {
|
|
||||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) mr.getResult()
|
|
||||||
.getItemMeta();
|
|
||||||
Map<Enchantment, Integer> storedEn = meta.getStoredEnchants();
|
|
||||||
for (Map.Entry<Enchantment, Integer> entry : storedEn.entrySet()) {
|
|
||||||
Enchantment entc = entry.getKey();
|
|
||||||
Integer val = entry.getValue();
|
|
||||||
|
|
||||||
String enchantmentName = "enchantment.minecraft."
|
for (MerchantRecipe mr : vil.getRecipes()) {
|
||||||
+ entc.getKey().getKey();
|
nearbyPlayers.stream()
|
||||||
|
.filter(p -> p.displayName().toString().contains("R3STEAS"))
|
||||||
|
.forEach(p -> showEnchantmentInfo(p, mr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (val == entc.getMaxLevel()) {
|
private void showEnchantmentInfo(Player player, MerchantRecipe recipe) {
|
||||||
ent.showTitle(Title.title(Component.text("MAX LEVEL!"),
|
if (!(recipe.getResult().getItemMeta() instanceof EnchantmentStorageMeta meta))
|
||||||
Component.translatable(enchantmentName)));
|
return;
|
||||||
} else {
|
|
||||||
ent.sendMessage("----");
|
|
||||||
ent.sendMessage("");
|
|
||||||
ent.sendMessage(Component.translatable(enchantmentName));
|
|
||||||
ent.sendMessage(Component.text("LVL " + val));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
Map<Enchantment, Integer> storedEnchants = meta.getStoredEnchants();
|
||||||
|
for (Map.Entry<Enchantment, Integer> entry : storedEnchants.entrySet()) {
|
||||||
|
Enchantment enchant = entry.getKey();
|
||||||
|
int level = entry.getValue();
|
||||||
|
|
||||||
}
|
String enchantmentName = "enchantment.minecraft." + enchant.getKey().getKey();
|
||||||
|
|
||||||
}
|
if (level == enchant.getMaxLevel()) {
|
||||||
}
|
player.showTitle(Title.title(Component.text("MAX LEVEL!"), Component.translatable(enchantmentName)));
|
||||||
|
} else {
|
||||||
}
|
player.sendMessage("----");
|
||||||
|
player.sendMessage("");
|
||||||
}, 1L);
|
player.sendMessage(Component.translatable(enchantmentName));
|
||||||
}
|
player.sendMessage(Component.text("LVL " + level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler
|
||||||
|
public void onVillagerClick(PlayerInteractEntityEvent event) {
|
||||||
|
if (!(event.getRightClicked() instanceof Villager villager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
if (heldItem.getType() != Material.BELL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UUID villagerId = villager.getUniqueId();
|
||||||
|
|
||||||
|
cancelAndRemoveTask(villagerId);
|
||||||
|
|
||||||
|
BukkitTask task = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!villager.isValid() || !player.isOnline()) {
|
||||||
|
cancelAndRemoveTask(villagerId);
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack currentItem = player.getInventory().getItemInMainHand();
|
||||||
|
if (currentItem.getType() != Material.BELL) {
|
||||||
|
cancelAndRemoveTask(villagerId);
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double maxDistance = 16.0;
|
||||||
|
double distanceSquared = villager.getLocation().distanceSquared(player.getLocation());
|
||||||
|
|
||||||
|
if (distanceSquared > maxDistance * maxDistance) {
|
||||||
|
cancelAndRemoveTask(villagerId);
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distanceSquared > 2.0) { // avoid jitter when close
|
||||||
|
Pathfinder pathfinder = villager.getPathfinder();
|
||||||
|
pathfinder.moveTo(player.getLocation(), 0.45);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(App.main, 0L, 10L); // every 10 ticks (0.5s)
|
||||||
|
|
||||||
|
activeVillagerTasks.put(villagerId, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelAndRemoveTask(UUID villagerId) {
|
||||||
|
BukkitTask existing = activeVillagerTasks.remove(villagerId);
|
||||||
|
if (existing != null) {
|
||||||
|
existing.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
|
//GPT'd
|
||||||
package de.hessj.environmentex;
|
package de.hessj.environmentex;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -17,56 +16,78 @@ import org.bukkit.inventory.ShapedRecipe;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
|
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public class WorkbenchToGo implements Listener {
|
public class WorkbenchToGo implements Listener {
|
||||||
private Component nameWorkbench = Component.text(ChatColor.WHITE + "Portable Werkbank");
|
private static final int CUSTOM_MODEL_DATA = 1000020;
|
||||||
private NamespacedKey nskWorkbench = new NamespacedKey(App.main, "R3S_WORKBENCH");
|
private static final String WORKBENCH_KEY_VALUE = "R3S_WORKBENCH";
|
||||||
|
private static final Component NAME_WORKBENCH = Component.text(ChatColor.WHITE + "Portable Werkbank");
|
||||||
|
private final NamespacedKey nskWorkbench = new NamespacedKey(App.main, WORKBENCH_KEY_VALUE);
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLoad(ServerLoadEvent e) {
|
public void onLoad(ServerLoadEvent e) {
|
||||||
ItemStack isWorkbench = new ItemStack(Material.BARRIER);
|
var portableWorkbench = new ItemStack(Material.BARRIER);
|
||||||
ItemMeta mWorkbench = isWorkbench.getItemMeta();
|
ItemMeta meta = portableWorkbench.getItemMeta();
|
||||||
mWorkbench.getPersistentDataContainer().set(nskWorkbench, PersistentDataType.STRING, "R3S_WORKBENCH");
|
|
||||||
mWorkbench.displayName(nameWorkbench);
|
meta.getPersistentDataContainer().set(nskWorkbench, PersistentDataType.STRING, WORKBENCH_KEY_VALUE);
|
||||||
mWorkbench.setCustomModelData(1000020);
|
meta.displayName(NAME_WORKBENCH);
|
||||||
CustomModelDataComponent cmdc = mWorkbench.getCustomModelDataComponent();
|
meta.setCustomModelData(CUSTOM_MODEL_DATA);
|
||||||
List<String> list = Arrays.asList("crafting_table_to_go");
|
|
||||||
cmdc.setStrings(list);
|
CustomModelDataComponent cmdc = meta.getCustomModelDataComponent();
|
||||||
mWorkbench.setCustomModelDataComponent(cmdc);
|
cmdc.setStrings(Collections.singletonList("crafting_table_to_go"));
|
||||||
isWorkbench.setItemMeta(mWorkbench);
|
meta.setCustomModelDataComponent(cmdc);
|
||||||
ShapedRecipe srWorkbench = new ShapedRecipe(new NamespacedKey(App.main, "R3S_SR_Workbench"), isWorkbench);
|
|
||||||
srWorkbench.shape("DDD", "DWD", "DDD");
|
portableWorkbench.setItemMeta(meta);
|
||||||
srWorkbench.setIngredient('D', Material.DIAMOND);
|
|
||||||
srWorkbench.setIngredient('W', Material.CRAFTING_TABLE);
|
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(App.main, "R3S_SR_Workbench"), portableWorkbench);
|
||||||
App.main.getServer().addRecipe(srWorkbench);
|
recipe.shape("DDD", "DWD", "DDD");
|
||||||
App.main.recipeKeys.add(srWorkbench.getKey());
|
recipe.setIngredient('D', Material.DIAMOND);
|
||||||
|
recipe.setIngredient('W', Material.CRAFTING_TABLE);
|
||||||
|
|
||||||
|
App.main.getServer().addRecipe(recipe);
|
||||||
|
App.main.recipeKeys.add(recipe.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
if (e.getPlayer().getInventory().getItemInMainHand() != null
|
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
|
||||||
&& e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.BARRIER)) {
|
|
||||||
if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta()
|
|
||||||
&& e.getPlayer().getInventory().getItemInMainHand().getItemMeta()
|
|
||||||
.getPersistentDataContainer() != null
|
|
||||||
&& e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer()
|
|
||||||
.has(nskWorkbench, PersistentDataType.STRING)) {
|
|
||||||
|
|
||||||
if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK
|
if (!isPortableWorkbench(item)) {
|
||||||
|| e.getAction() == Action.PHYSICAL
|
return;
|
||||||
|| (e.getClickedBlock() != null && App.helper.isInteractable(e.getClickedBlock()))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.setCancelled(true);
|
|
||||||
MenuType.Typed<InventoryView, ?> craftingMenuType = MenuType.CRAFTING;
|
|
||||||
InventoryView craftingView = craftingMenuType.builder()
|
|
||||||
.title(Component.text("Custom Crafting"))
|
|
||||||
.build(e.getPlayer());
|
|
||||||
e.getPlayer().openInventory(craftingView);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldIgnoreAction(e)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
InventoryView craftingView = MenuType.CRAFTING.builder()
|
||||||
|
.title(Component.translatable("container.crafting"))
|
||||||
|
.build(e.getPlayer());
|
||||||
|
|
||||||
|
e.getPlayer().openInventory(craftingView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPortableWorkbench(ItemStack item) {
|
||||||
|
if (item == null || item.getType() != Material.BARRIER)
|
||||||
|
return false;
|
||||||
|
if (!item.hasItemMeta())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var container = item.getItemMeta().getPersistentDataContainer();
|
||||||
|
return container.has(nskWorkbench, PersistentDataType.STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldIgnoreAction(PlayerInteractEvent e) {
|
||||||
|
Action action = e.getAction();
|
||||||
|
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK || action == Action.PHYSICAL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (e.getClickedBlock() != null && App.helper.isInteractable(e.getClickedBlock())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user