fix: Elytra name + test wise added PlayerDeath Instantrespawn

This commit is contained in:
Janik Heß
2025-03-05 21:21:00 +01:00
parent 64dc607449
commit a8fed0a79c
6 changed files with 213 additions and 87 deletions

View File

@@ -7,6 +7,9 @@ group = "de.hessj.environmentex"
version = "1.0-SNAPSHOT"
description = "environmentex"
tasks.withType<Jar> {
destinationDirectory.set(file("../"))
}
dependencies {
implementation(files("../craftbukkit.jar"))

View File

@@ -1,21 +1,15 @@
package de.hessj.environmentex;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.world.item.component.CustomModelData;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
@@ -482,6 +476,8 @@ public class App extends JavaPlugin {
getCommand("n").setExecutor(new EnvironmentExCommands());
getCommand("add").setExecutor(new EnvironmentExCommands());
getCommand("afk").setExecutor(new EnvironmentExCommands());
getCommand("pin").setExecutor(new EnvironmentExCommands());
getCommand("pin").setTabCompleter(new PinFeature());
}
public void log(Object msg) {

View File

@@ -13,11 +13,12 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.view.AnvilView;
import org.bukkit.scheduler.BukkitRunnable;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -25,30 +26,44 @@ import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
public class ArmoredElytra implements Listener {
private final List <String> CHESTPLATES = Arrays.asList("LEATHER_CHESTPLATE","IRON_CHESTPLATE","DIAMOND_CHESTPLATE","NETHERITE_CHESTPLATE","GOLDEN_CHESTPLATE","CHAINMAIL_CHESTPLATE");
//TODO: test if elytra armor works
@EventHandler
public void onElytraCombine(PrepareAnvilEvent e){
if(e.getView().getBottomInventory().getHolder() instanceof Player){
new BukkitRunnable(){
@EventHandler
public void tes(PlayerDeathEvent e) {
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().spigot().respawn();
e.getPlayer().sendMessage("Todes koordinaten: " + e.getPlayer().getLocation().getX() + " "
+ e.getPlayer().getLocation().getY() + " " + e.getPlayer().getLocation().getZ());
}
}.runTaskLater(App.main, 1L); // Run next tick to prevent death screen
}
private final List<String> CHESTPLATES = Arrays.asList("LEATHER_CHESTPLATE", "IRON_CHESTPLATE",
"DIAMOND_CHESTPLATE", "NETHERITE_CHESTPLATE", "GOLDEN_CHESTPLATE", "CHAINMAIL_CHESTPLATE");
@EventHandler
public void onElytraCombine(PrepareAnvilEvent e) {
if (e.getView().getBottomInventory().getHolder() instanceof Player) {
new BukkitRunnable() {
@Override
public void run() {
AnvilInventory inv = e.getInventory();
ItemStack item1 = inv.getItem(0); // chestplate
ItemStack item2 = inv.getItem(1); // elytra
if(item1 != null && item2 != null){
if(CHESTPLATES.contains(item2.getType().toString()) && item1.getType() == Material.ELYTRA){
AnvilView av = e.getView();
ItemStack item1 = av.getItem(0); // chestplate
ItemStack item2 = av.getItem(1); // elytra
if (item1 != null && item2 != null) {
if (CHESTPLATES.contains(item2.getType().toString()) && item1.getType() == Material.ELYTRA) {
ItemStack combinedElytra = item1.clone();
ItemMeta meta = combinedElytra.getItemMeta();
ItemMeta chestPlateMeta = item2.getItemMeta();
Map<Enchantment,Integer> enchants = new HashMap<>();
Map<Enchantment, Integer> enchants = new HashMap<>();
int armor = 0;
int toughness = 0;
double knockbackres = 0.0;
switch(item2.getType()){
switch (item2.getType()) {
case LEATHER_CHESTPLATE:
armor = 3;
@@ -73,80 +88,84 @@ public class ArmoredElytra implements Listener {
break;
}
if(chestPlateMeta.hasAttributeModifiers()){
if(chestPlateMeta.getAttributeModifiers(Attribute.ARMOR) != null){
armor=0;
for(AttributeModifier modifier : chestPlateMeta.getAttributeModifiers(Attribute.ARMOR)){
if (chestPlateMeta.hasAttributeModifiers()) {
if (chestPlateMeta.getAttributeModifiers(Attribute.ARMOR) != null) {
armor = 0;
for (AttributeModifier modifier : chestPlateMeta
.getAttributeModifiers(Attribute.ARMOR)) {
armor = (int) modifier.getAmount();
}
}
if(chestPlateMeta.getAttributeModifiers(Attribute.ARMOR_TOUGHNESS) != null){
toughness=0;
for(AttributeModifier modifier : chestPlateMeta.getAttributeModifiers(Attribute.ARMOR_TOUGHNESS)){
if (chestPlateMeta.getAttributeModifiers(Attribute.ARMOR_TOUGHNESS) != null) {
toughness = 0;
for (AttributeModifier modifier : chestPlateMeta
.getAttributeModifiers(Attribute.ARMOR_TOUGHNESS)) {
toughness = (int) modifier.getAmount();
}
}
if(chestPlateMeta.getAttributeModifiers(Attribute.KNOCKBACK_RESISTANCE) != null){
knockbackres=0;
for(AttributeModifier modifier : chestPlateMeta.getAttributeModifiers(Attribute.KNOCKBACK_RESISTANCE)){
if (chestPlateMeta.getAttributeModifiers(Attribute.KNOCKBACK_RESISTANCE) != null) {
knockbackres = 0;
for (AttributeModifier modifier : chestPlateMeta
.getAttributeModifiers(Attribute.KNOCKBACK_RESISTANCE)) {
knockbackres = (int) modifier.getAmount();
}
}
}
if(armor != 0){
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor", armor, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
if (armor != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor", armor,
Operation.ADD_NUMBER, EquipmentSlot.CHEST);
meta.addAttributeModifier(Attribute.ARMOR, mod);
}
if(toughness != 0){
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor_toughness", toughness, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
if (toughness != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor_toughness",
toughness, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, mod);
}
if(knockbackres != 0){
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "knockback_resistance", knockbackres, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
if (knockbackres != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "knockback_resistance",
knockbackres, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, mod);
}
for(Enchantment ench : item2.getEnchantments().keySet()){
for (Enchantment ench : item2.getEnchantments().keySet()) {
enchants.put(ench, item2.getEnchantments().get(ench));
}
for(Enchantment ench : item1.getEnchantments().keySet()){
if(enchants.containsKey(ench)){
if(enchants.get(ench) < item1.getEnchantments().get(ench)){
for (Enchantment ench : item1.getEnchantments().keySet()) {
if (enchants.containsKey(ench)) {
if (enchants.get(ench) < item1.getEnchantments().get(ench)) {
enchants.put(ench, item1.getEnchantments().get(ench));
}
}
else{
} else {
enchants.put(ench, item1.getEnchantments().get(ench));
}
}
combinedElytra.setItemMeta(meta);
for(Enchantment ench : enchants.keySet()){
combinedElytra.addUnsafeEnchantment(Enchantment.getByKey(ench.getKey()), enchants.get(ench));
for (Enchantment ench : enchants.keySet()) {
combinedElytra.addUnsafeEnchantment(Enchantment.getByKey(ench.getKey()),
enchants.get(ench));
}
ItemMeta elytraMeta = combinedElytra.getItemMeta();
Style st = Style.style().color(NamedTextColor.DARK_PURPLE).decoration(TextDecoration.ITALIC,false).build();
Style st2 = Style.style().color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC,false).build();
List<Component> lore = Arrays.asList(Component.translatable("Kombiniert mit: ").style(st), Component.translatable(item2.getType().getItemTranslationKey()).style(st));
Style st = Style.style().color(NamedTextColor.DARK_PURPLE)
.decoration(TextDecoration.ITALIC, false).build();
Style st2 = Style.style().color(NamedTextColor.YELLOW)
.decoration(TextDecoration.ITALIC, false).build();
List<Component> lore = Arrays.asList(Component.translatable("Kombiniert mit: ").style(st),
Component.translatable(item2.getType().getItemTranslationKey()).style(st));
elytraMeta.lore(lore);
if(inv.getRenameText() == ""){
elytraMeta.displayName(Component.translatable(item1.getType().getItemTranslationKey()).style(st2));
if (av.getRenameText().length() == 0) {
elytraMeta.displayName(Component.text("Elytren").style(st2));
} else {
elytraMeta.displayName(Component.text(av.getRenameText()).style(st2));
}
else {
elytraMeta.displayName(Component.text(inv.getRenameText()).style(st2));
}
combinedElytra.setItemMeta(elytraMeta);
inv.setRepairCost(10);
inv.setItem(2, combinedElytra);
combinedElytra.setItemMeta(elytraMeta);
av.setRepairCost(10);
av.setItem(2, combinedElytra);
}
}
}
}.runTaskLater(App.main, 2);
}

View File

@@ -1,13 +1,13 @@
package de.hessj.environmentex;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -16,14 +16,12 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import de.hessj.helper.Helper.Type;
import net.minecraft.world.level.material.LavaFluid;
import net.md_5.bungee.api.ChatColor;
public class EnvironmentExCommands implements CommandExecutor, Listener {
public de.hessj.helper.Helper helper= new de.hessj.helper.Helper();
public de.hessj.helper.Helper helper = new de.hessj.helper.Helper();
private final Map<UUID, Map<String, Location>> playerPins = new HashMap<>();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -32,7 +30,7 @@ public class EnvironmentExCommands implements CommandExecutor, Listener {
if (label.equalsIgnoreCase("y")) {
if (!EnvironmentExListeners.hasVoted.contains(((Player) sender).getUniqueId())) {
EnvironmentExListeners.voteForYes++;
((Player) sender).sendMessage(helper.R3SMessage(Type.INFO,"Du hast für Ja gevotet."));
((Player) sender).sendMessage(helper.R3SMessage(Type.INFO, "Du hast für Ja gevotet."));
EnvironmentExListeners.hasVoted.add(((Player) sender).getUniqueId());
}
} else if (label.equalsIgnoreCase("n")) {
@@ -49,12 +47,83 @@ public class EnvironmentExCommands implements CommandExecutor, Listener {
p.playerListName(App.main.helper.R3SMessage(Type.ERROR, "[AFK] " + p.getName()));
}
if (label.equalsIgnoreCase("pin")) {
Player p = (Player) sender;
UUID playerId = p.getUniqueId();
playerPins.putIfAbsent(playerId, new HashMap<>());
if (args.length < 1) {
p.sendMessage(ChatColor.RED + "Benutzung: /pin <set|show|list|remove> [name]");
return true;
}
String subCommand = args[0].toLowerCase();
Map<String, Location> pins = playerPins.get(playerId);
switch (subCommand) {
case "set":
if (args.length < 2) {
p.sendMessage(ChatColor.RED + "Benutzung: /pin set <name>");
return true;
}
String pinName = args[1];
Location playerLocation = p.getLocation();
pins.put(pinName, playerLocation);
// Save to YAML file
PinFeature.pinConfig.set(playerId + "." + pinName + ".loc",
playerLocation.getWorld().getName() + ", " + playerLocation.getBlockX() + ", "
+ playerLocation.getBlockY() + ", " + playerLocation.getBlockZ());
savePins();
p.sendMessage(ChatColor.GREEN + "Pin '" + pinName + "' wurde hinzugefügt.");
break;
case "list":
loadPinsFromConfig(playerId);
if (pins.isEmpty()) {
p.sendMessage(ChatColor.RED + "Du hast keine Pins.");
return true;
}
p.sendMessage(ChatColor.BLUE + "Deine Pins:");
for (String name : pins.keySet()) {
Location location = pins.get(name);
String w = "Overworld: ";
if(location.getWorld().getName().endsWith("_nether")){
w = "Nether: ";
}
else if(location.getWorld().getName().endsWith("_end")){
w = "End: ";
}
p.sendMessage("- " + w + name + " (" + location.getBlockX() + ", " + location.getBlockY() + ", "
+ location.getBlockZ() + ")");
}
break;
case "remove":
if (args.length < 2) {
p.sendMessage(ChatColor.RED + "Benutzung: /pin remove <name>");
return true;
}
pinName = args[1];
if (pins.remove(pinName) != null) {
PinFeature.pinConfig.set(playerId + "." + pinName, null);
savePins();
p.sendMessage(ChatColor.GREEN + "Pin '" + pinName + "' wurde entfernt.");
} else {
p.sendMessage(ChatColor.RED + "Kein Pin mit diesem Namen gefunden.");
}
break;
default:
p.sendMessage(ChatColor.RED + "Benutzung: /pin <set|show|list|remove> [name]");
}
}
} else {
if (label.equalsIgnoreCase("add") && args.length == 1) {
UUID uuid;
try {
@@ -74,16 +143,50 @@ public class EnvironmentExCommands implements CommandExecutor, Listener {
if (label.equalsIgnoreCase("infbucket")) {
try {
Player p = (Player) sender;
ItemStack testEnchant = new ItemStack (Material.BOW, 1);
ItemMeta testEnchantMeta = testEnchant.getItemMeta();
testEnchantMeta.addEnchant(Enchantment.INFINITY,1,false);
testEnchant.setItemMeta(testEnchantMeta);
ItemStack testEnchant = new ItemStack(Material.BOW, 1);
ItemMeta testEnchantMeta = testEnchant.getItemMeta();
testEnchantMeta.addEnchant(Enchantment.INFINITY, 1, false);
testEnchant.setItemMeta(testEnchantMeta);
p.getWorld().dropItemNaturally(p.getLocation(), testEnchant);
} catch (Exception ex) {
App.main.getLogger().info("Die angegebene UUID ist inkorrekt!");
}
}
}
return true;
}
private void savePins() {
try {
PinFeature.pinConfig.save(PinFeature.pinYml);
} catch (IOException e) {
Bukkit.getLogger().severe("Could not save pins.yml!");
}
}
private void loadPinsFromConfig(UUID playerId) {
// Clear the current player's pins map before loading new data
playerPins.putIfAbsent(playerId, new HashMap<>());
Map<String, Location> pins = playerPins.get(playerId);
// Get the pin configuration for this player
if (PinFeature.pinConfig.contains(playerId.toString())) {
for (String pinName : PinFeature.pinConfig.getConfigurationSection(playerId.toString()).getKeys(false)) {
String locationString = PinFeature.pinConfig.getString(playerId + "." + pinName + ".loc");
if (locationString != null) {
String[] locParts = locationString.split(", ");
if (locParts.length == 4) {
String worldName = locParts[0];
int x = Integer.parseInt(locParts[1]);
int y = Integer.parseInt(locParts[2]);
int z = Integer.parseInt(locParts[3]);
Location location = new Location(Bukkit.getWorld(worldName), x, y, z);
pins.put(pinName, location);
}
}
}
}
}
}

View File

@@ -22,10 +22,10 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.view.AnvilView;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionType;
import de.hessj.helper.Helper.Type;
@@ -42,10 +42,11 @@ public class ExpBottleListener implements Listener {
@EventHandler
public void on_prepare_anvil(PrepareAnvilEvent event) {
AnvilInventory inventory = event.getInventory();
inventory.setMaximumRepairCost(999999);
if (inventory.getRepairCost() > 40) {
inventory.setRepairCost(40);
//TODO: check if replacement method worked
AnvilView av = event.getView();
av.setMaximumRepairCost(999999);
if (av.getRepairCost() > 40) {
av.setRepairCost(40);
}
}
@@ -173,7 +174,8 @@ public class ExpBottleListener implements Listener {
public void onDispense(BlockDispenseEvent e) {
if (e.getItem().getType() == Material.POTION && e.getBlock().getType() == Material.DISPENSER) {
PotionMeta pm = (PotionMeta) e.getItem().getItemMeta();
if (pm.getBasePotionData().getType() == PotionType.WATER) {
//TODO: check if working after method replacement
if (pm.getBasePotionType() == PotionType.WATER) {
Location loc = e.getBlock().getLocation();
Dispenser dis = (Dispenser) e.getBlock().getState();

View File

@@ -18,4 +18,7 @@ commands:
usage: /<command> <UUID>
afk:
description: Setzt den AFK Status
usage: /<command>
pin:
description: ----
usage: /<command>