Update MWTeam.givePlayerItem and ScriptedItem.createItemStack
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
b5b6fe26e2
Commit
59a8ef91e0
@ -19,11 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars;
|
package de.steamwar.misslewars;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
@ -81,6 +85,15 @@ public class MWTeam {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getUsesOfItem(ItemStack itemStack) {
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
if (itemMeta instanceof Damageable) {
|
||||||
|
Damageable damageable = (Damageable) itemMeta;
|
||||||
|
return itemStack.getType().getMaxDurability() - damageable.getDamage();
|
||||||
|
}
|
||||||
|
return 1_000_000;
|
||||||
|
}
|
||||||
|
|
||||||
public void givePlayerItem(ItemStack item) {
|
public void givePlayerItem(ItemStack item) {
|
||||||
if (players.isEmpty()) {
|
if (players.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -91,7 +104,16 @@ public class MWTeam {
|
|||||||
Inventory inventory = p.getInventory();
|
Inventory inventory = p.getInventory();
|
||||||
for (int i = 0; i <= 35; i++) { // 35 is the last normal inventory slot
|
for (int i = 0; i <= 35; i++) { // 35 is the last normal inventory slot
|
||||||
ItemStack itemStack = inventory.getItem(i);
|
ItemStack itemStack = inventory.getItem(i);
|
||||||
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() + item.getAmount() <= itemStack.getMaxStackSize()) {
|
if (itemStack != null && itemStack.isSimilar(item) && getUsesOfItem(itemStack) + getUsesOfItem(item) <= itemStack.getType().getMaxDurability()) {
|
||||||
|
int uses = getUsesOfItem(itemStack) + getUsesOfItem(item);
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
Damageable damageable = (Damageable) itemMeta;
|
||||||
|
damageable.setDamage(itemStack.getType().getMaxDurability() - uses);
|
||||||
|
itemStack.setItemMeta(damageable);
|
||||||
|
inventory.setItem(i, itemStack);
|
||||||
|
p.updateInventory();
|
||||||
|
return;
|
||||||
|
} else if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() + item.getAmount() <= 64) {
|
||||||
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
|
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
|
||||||
inventory.setItem(i, itemStack);
|
inventory.setItem(i, itemStack);
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
|
@ -26,6 +26,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LingeringPotion;
|
import org.bukkit.entity.LingeringPotion;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -45,6 +46,7 @@ public class ScriptedItem {
|
|||||||
// "lore": Lore array (OPTIONAL STRING.ARRAY)
|
// "lore": Lore array (OPTIONAL STRING.ARRAY)
|
||||||
// "amount": Item amount (OPTIONAL [default 1] INT)
|
// "amount": Item amount (OPTIONAL [default 1] INT)
|
||||||
// "potion": Object with key value pairs for PotionType and Object containing duration and amplifier (OPTIONAL OBJECT)
|
// "potion": Object with key value pairs for PotionType and Object containing duration and amplifier (OPTIONAL OBJECT)
|
||||||
|
// "uses": Uses of Item (OPTIONAL INT)
|
||||||
// "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
|
// "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
|
||||||
// - onClick
|
// - onClick
|
||||||
// - onHit
|
// - onHit
|
||||||
@ -99,6 +101,12 @@ public class ScriptedItem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jsonObject.has("uses") && itemMeta instanceof Damageable) {
|
||||||
|
int uses = jsonObject.getAsJsonPrimitive("uses").getAsInt();
|
||||||
|
Damageable damageable = (Damageable) itemMeta;
|
||||||
|
damageable.setDamage(itemStack.getType().getMaxDurability() - uses);
|
||||||
|
}
|
||||||
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
@ -116,5 +124,4 @@ public class ScriptedItem {
|
|||||||
public String getEntityName() {
|
public String getEntityName() {
|
||||||
return entityName;
|
return entityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren