This commit is contained in:
parent
1febc27d67
commit
072521f228
5 changed files with 164 additions and 34 deletions
|
@ -18,5 +18,5 @@ see [docs](https://git.unurled.me/SacredRealms/docs) for more information
|
|||
## Running
|
||||
|
||||
- [Java 17](https://adoptium.net/temurin/releases/?version=17)
|
||||
- [PaperMC 1.20.4](https://papermc.io/downloads/paper) or any fork of it (purpur, etc)
|
||||
- [PaperMC 1.20.6](https://papermc.io/downloads/paper) or any fork of it (purpur, etc)
|
||||
- a build of the plugin
|
|
@ -10,6 +10,8 @@ import me.unurled.sacredrealms.sr.components.item.Item;
|
|||
import me.unurled.sacredrealms.sr.components.item.ItemManager;
|
||||
import me.unurled.sacredrealms.sr.components.item.ItemType;
|
||||
import me.unurled.sacredrealms.sr.components.item.Rarity;
|
||||
import me.unurled.sacredrealms.sr.components.item.abilities.Ability;
|
||||
import me.unurled.sacredrealms.sr.components.item.enchantments.Enchantment;
|
||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
@ -60,9 +62,9 @@ public class ItemCommand implements TabExecutor {
|
|||
switch (args[2].toLowerCase()) {
|
||||
case "name" -> modified = modifyName(sender, args, p, item);
|
||||
case MATERIAL -> modified = modifyMaterial(sender, args, p, item);
|
||||
case ENCHANTMENTS -> modified = modifyEnchantments(args, p);
|
||||
case ENCHANTMENTS -> modified = modifyEnchantments(args, p, item);
|
||||
case ATTRIBUTES -> modified = modifyAttributes(sender, args, p, item);
|
||||
case ABILITIES -> modified = modifyAbilities(sender, args, p);
|
||||
case ABILITIES -> modified = modifyAbilities(sender, args, p, item);
|
||||
case CUSTOMMODELDATA -> modified = modifyModelData(sender, args, p, item);
|
||||
case RARITY -> modified = modifyRarity(sender, args, p, item);
|
||||
case "type" -> modified = modifyType(sender, args, p, item);
|
||||
|
@ -88,6 +90,7 @@ public class ItemCommand implements TabExecutor {
|
|||
String description = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
|
||||
item.setDescription(description);
|
||||
sender.sendMessage(comp("<green>Description set."));
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -106,6 +109,7 @@ public class ItemCommand implements TabExecutor {
|
|||
}
|
||||
item.setType(type);
|
||||
sender.sendMessage(comp("<green>Type set."));
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -124,6 +128,7 @@ public class ItemCommand implements TabExecutor {
|
|||
}
|
||||
item.setRarity(rarity);
|
||||
sender.sendMessage(comp("<green>Rarity set."));
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -142,22 +147,24 @@ public class ItemCommand implements TabExecutor {
|
|||
}
|
||||
item.setCustomModelData(customModelData);
|
||||
sender.sendMessage(comp("<green>Custom model data set."));
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean modifyAbilities(
|
||||
@NotNull CommandSender sender, @NotNull String @NotNull [] args, Player p) {
|
||||
@NotNull CommandSender sender, @NotNull String @NotNull [] args, Player p, Item item) {
|
||||
if (args.length < 5) {
|
||||
p.sendMessage("Usage: /item modify <id> abilities add <ability>");
|
||||
return false;
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("add")) {
|
||||
p.sendMessage("Abilities not working for now.");
|
||||
// TODO: add ability
|
||||
item.addAbility(Ability.getAbility(args[4]));
|
||||
} else if (args[3].equalsIgnoreCase(REMOVE)) {
|
||||
sender.sendMessage("Abilities not working for now.");
|
||||
// TODO: remove ability
|
||||
item.removeAbility(Ability.getAbility(args[4]));
|
||||
}
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -170,7 +177,7 @@ public class ItemCommand implements TabExecutor {
|
|||
String name = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
|
||||
item.setName(name);
|
||||
sender.sendMessage(comp("<green>Item name set."));
|
||||
// TODO: update item in player inventory
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -187,31 +194,40 @@ public class ItemCommand implements TabExecutor {
|
|||
}
|
||||
item.setMaterial(material);
|
||||
sender.sendMessage(comp("<green>Item material set."));
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean modifyEnchantments(@NotNull String @NotNull [] args, Player p) {
|
||||
private static boolean modifyEnchantments(@NotNull String @NotNull [] args, Player p, Item item) {
|
||||
if (args.length < 4) {
|
||||
p.sendMessage("Usage: /item modify <id> enchantments <add|remove> [enchantment]");
|
||||
p.sendMessage("Usage: /item modify <id> enchantments <add|remove> [enchantment] <level>");
|
||||
return false;
|
||||
}
|
||||
if (args[3].equalsIgnoreCase("add")) {
|
||||
if (args.length < 5) {
|
||||
p.sendMessage("Usage: /item modify <id> enchantments add <enchantment>");
|
||||
if (args.length < 6) {
|
||||
p.sendMessage("Usage: /item modify <id> enchantments add <enchantment> <level>");
|
||||
return false;
|
||||
}
|
||||
// TODO: add enchantment
|
||||
int level = 1;
|
||||
try {
|
||||
level = Integer.parseInt(args[5]);
|
||||
} catch (NumberFormatException e) {
|
||||
p.sendMessage("Invalid level.");
|
||||
return false;
|
||||
}
|
||||
item.addEnchantment(Enchantment.getEnchantment(args[4]), level);
|
||||
p.sendMessage("Enchantments not working for now.");
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (args[3].equalsIgnoreCase(REMOVE)) {
|
||||
if (args.length < 5) {
|
||||
p.sendMessage("Usage: /item modify <id> enchantments remove <enchantment>");
|
||||
return false;
|
||||
}
|
||||
// TODO: remove enchantment
|
||||
item.removeEnchantment(Enchantment.getEnchantment(args[4]));
|
||||
p.sendMessage("Enchantments not working for now.");
|
||||
}
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -261,6 +277,7 @@ public class ItemCommand implements TabExecutor {
|
|||
item.removeAttribute(attribute);
|
||||
sender.sendMessage(comp("<green>Attribute removed."));
|
||||
}
|
||||
updateItem(p, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -347,16 +364,31 @@ public class ItemCommand implements TabExecutor {
|
|||
@Nullable
|
||||
private static List<String> modify(@NotNull String @NotNull [] args) {
|
||||
if (args.length == 5 && (args[0].equalsIgnoreCase(MODIFY))) {
|
||||
// TODO: Enchantments in completion
|
||||
/*if (args[2].equalsIgnoreCase("enchantments")) {
|
||||
return Arrays.stream(Enchantment.values()).map(Enum::name).toList();
|
||||
} else*/ if (args[2].equalsIgnoreCase(ATTRIBUTES)) {
|
||||
return Arrays.stream(Attribute.values()).map(Enum::name).toList();
|
||||
if (args[2].equalsIgnoreCase(ENCHANTMENTS)) {
|
||||
return Arrays.stream(Enchantment.values())
|
||||
.map(
|
||||
name -> {
|
||||
if (name.name().startsWith(args[3].toUpperCase())) return name.name();
|
||||
return null;
|
||||
})
|
||||
.toList();
|
||||
} else if (args[2].equalsIgnoreCase(ATTRIBUTES)) {
|
||||
return Arrays.stream(Attribute.values())
|
||||
.map(
|
||||
name -> {
|
||||
if (name.name().startsWith(args[3].toUpperCase())) return name.name();
|
||||
return null;
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void updateItem(@NotNull Player p, @NotNull Item newItem) {
|
||||
p.getInventory().setItemInMainHand(newItem.toItemStack());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<String> modifyCompletion(@NotNull String @NotNull [] args) {
|
||||
if (args.length == 4 && (args[0].equalsIgnoreCase(MODIFY))) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package me.unurled.sacredrealms.sr.components.item;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
|
||||
import static me.unurled.sacredrealms.sr.utils.Items.lore;
|
||||
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
||||
|
||||
|
@ -96,6 +96,10 @@ public class Item {
|
|||
return id;
|
||||
}
|
||||
|
||||
public void setId(@NotNull String arg) {
|
||||
this.id = arg;
|
||||
}
|
||||
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -104,18 +108,14 @@ public class Item {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void setId(@NotNull String arg) {
|
||||
this.id = arg;
|
||||
public @NotNull Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(@NotNull Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public @NotNull Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public @NotNull String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -144,6 +144,10 @@ public class Item {
|
|||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(@NotNull Map<Attribute, Double> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public Double getAttribute(Attribute attribute) {
|
||||
return attributes.get(attribute);
|
||||
}
|
||||
|
@ -156,10 +160,6 @@ public class Item {
|
|||
attributes.remove(attribute);
|
||||
}
|
||||
|
||||
public void setAttributes(@NotNull Map<Attribute, Double> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public @NotNull Map<Enchantment, Integer> getEnchantments() {
|
||||
return enchantments;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public class Item {
|
|||
PersistentDataContainer p = meta.getPersistentDataContainer();
|
||||
p.set(ItemManager.ID, PersistentDataType.STRING, id);
|
||||
|
||||
meta.displayName(comp(name).color(rarity.getColor()));
|
||||
meta.displayName(textComp(name).color(rarity.getColor()));
|
||||
|
||||
if (customModelData != 0) {
|
||||
meta.setCustomModelData(customModelData);
|
||||
|
|
|
@ -1,10 +1,67 @@
|
|||
package me.unurled.sacredrealms.sr.components.item.abilities;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Represents an ability that an item can have. TODO: Implement this class */
|
||||
@SuppressWarnings("unused")
|
||||
public record Ability(
|
||||
String name, String description, Integer cooldown, Integer manaCost, Integer damage) {
|
||||
public enum Ability {
|
||||
TEST("TEST", "Test", "Test", 1, 1, 1);
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final Integer cooldown;
|
||||
private final Integer manaCost;
|
||||
private final Integer damage;
|
||||
|
||||
Ability(
|
||||
String id,
|
||||
String name,
|
||||
String description,
|
||||
Integer cooldown,
|
||||
Integer manaCost,
|
||||
Integer damage) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.cooldown = cooldown;
|
||||
this.manaCost = manaCost;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public static @Nullable Ability getAbility(@NotNull String id) {
|
||||
for (Ability ability : Ability.values()) {
|
||||
if (ability.getId().equalsIgnoreCase(id)) {
|
||||
return ability;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Integer getCooldown() {
|
||||
return cooldown;
|
||||
}
|
||||
|
||||
public Integer getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
public Integer getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -1,3 +1,44 @@
|
|||
package me.unurled.sacredrealms.sr.components.item.enchantments;
|
||||
|
||||
public record Enchantment(String name, String ID, Integer maxLevel) {}
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum Enchantment {
|
||||
TEST("TEST", "test", "", 255);
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final Integer maxLevel;
|
||||
|
||||
Enchantment(String id, String name, String description, Integer maxLevel) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public static @Nullable Enchantment getEnchantment(String id) {
|
||||
for (Enchantment enchantment : Enchantment.values()) {
|
||||
if (enchantment.getId().equalsIgnoreCase(id)) {
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Integer getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue