tried to patch some bugs
This commit is contained in:
parent
92fd2242b3
commit
ce0ffdbdfc
9 changed files with 128 additions and 89 deletions
|
@ -13,9 +13,9 @@ group = "me.unurled.sacredrealms"
|
|||
version = "0.1.0"
|
||||
description = "The main SR plugin."
|
||||
|
||||
val mcVersion = "1.20.6-R0.1-SNAPSHOT"
|
||||
val mcVersion = "1.21-R0.1-SNAPSHOT"
|
||||
val redisVersion = "5.2.0-beta2"
|
||||
val invuiVersion = "1.30"
|
||||
val invuiVersion = "1.32"
|
||||
|
||||
val javaVersion = 21
|
||||
|
||||
|
@ -29,7 +29,8 @@ dependencies {
|
|||
|
||||
implementation("redis.clients:jedis:${redisVersion}")
|
||||
|
||||
implementation("xyz.xenondevs.invui:invui:${invuiVersion}")
|
||||
implementation("xyz.xenondevs.invui:invui-core:${invuiVersion}")
|
||||
implementation("xyz.xenondevs.invui:inventory-access-r20:${invuiVersion}:remapped-mojang")
|
||||
}
|
||||
|
||||
java {
|
||||
|
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,7 @@
|
|||
#Mon Apr 29 21:41:32 CEST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -6,6 +6,8 @@ import static me.unurled.sacredrealms.sr.utils.Component.textComp;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
|
||||
import me.unurled.sacredrealms.sr.components.entity.SREntityType;
|
||||
import me.unurled.sacredrealms.sr.gui.entitytype.EntityTypeGUI;
|
||||
|
@ -21,37 +23,37 @@ import xyz.xenondevs.invui.window.Window;
|
|||
|
||||
public class EntityTypeCommand implements TabExecutor {
|
||||
|
||||
private static boolean list(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
private static void list(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
if (!(sender instanceof Player p)) {
|
||||
sender.sendMessage(comp(NOT_PLAYER));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (em.getTypes().isEmpty()) {
|
||||
sender.sendMessage(textComp("There are no entity types to display."));
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
Window window =
|
||||
Window.single().setViewer(p).setTitle(args[1]).setGui(EntityTypeGUI.listGui()).build();
|
||||
window.open();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
private static boolean edit(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
private static void edit(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype edit <ID>");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (!(sender instanceof Player p)) {
|
||||
sender.sendMessage(comp(NOT_PLAYER));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (!em.getTypes().stream().map(SREntityType::getId).toList().contains(args[1])) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
SREntityType type = em.getType(args[1]);
|
||||
Window window =
|
||||
|
@ -61,47 +63,64 @@ public class EntityTypeCommand implements TabExecutor {
|
|||
.setGui(EntityTypeGUI.createGui(type))
|
||||
.build();
|
||||
window.open();
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage("Usage: /entitytype edit <ID> <type|behavior|loot|item|stats|name|level>");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("type")) {
|
||||
if (args.length < 5) {
|
||||
sender.sendMessage("Usage: /entitytype edit <ID> type <type>");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
EntityType type = EntityType.valueOf(args[4]);
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (setType(sender, args, em, type)) return true;
|
||||
if (setType(sender, args, em, type)) return;
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean delete(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
private static void delete(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype delete <ID>");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (!em.getTypes().stream().map(SREntityType::getId).toList().contains(args[1])) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return;
|
||||
}
|
||||
// em.removeEntityType(em.getType(args[1]));
|
||||
}
|
||||
|
||||
private static boolean create(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
private static void create(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype create <ID>");
|
||||
return true;
|
||||
sender.sendMessage("Usage: /entitytype create <Name>");
|
||||
return;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(comp(NOT_PLAYER));
|
||||
return true;
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (em.getTypes().stream().map(SREntityType::getId).toList().contains(args[1])) {
|
||||
sender.sendMessage("An entity type with that ID already exists.");
|
||||
return;
|
||||
}
|
||||
SREntityType type = new SREntityType(args[1], args[1].toUpperCase());
|
||||
em.addEntityType(type);
|
||||
sender.sendMessage(textComp("<green>Entity type created successfully."));
|
||||
if (sender instanceof Player p) {
|
||||
// opens gui
|
||||
Window window =
|
||||
Window.single()
|
||||
.setViewer(p)
|
||||
.setTitle(args[1])
|
||||
.setGui(EntityTypeGUI.createGui(type))
|
||||
.build();
|
||||
window.open();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean setType(
|
||||
|
@ -147,17 +166,21 @@ public class EntityTypeCommand implements TabExecutor {
|
|||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create" -> {
|
||||
if (create(sender, args)) return true;
|
||||
create(sender, args);
|
||||
return true;
|
||||
}
|
||||
case "delete" -> {
|
||||
if (delete(sender, args)) return true;
|
||||
delete(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
case "edit" -> {
|
||||
if (edit(sender, args)) return true;
|
||||
edit(sender, args);
|
||||
return true;
|
||||
}
|
||||
case "list" -> {
|
||||
if (list(sender, args)) return true;
|
||||
list(sender, args);
|
||||
return true;
|
||||
}
|
||||
default -> sender.sendMessage("Usage: /entitytype <create|delete|edit|list>");
|
||||
}
|
||||
|
|
|
@ -35,7 +35,9 @@ public class ItemCommand implements TabExecutor {
|
|||
public static final String RARITY = "rarity";
|
||||
public static final String REMOVE = "remove";
|
||||
public static final String USAGE =
|
||||
"Usage: /item modify <id> <name|material|enchantments|attributes|abilities|custommodeldata|rarity|type|description> [value]";
|
||||
"Usage: /item modify <id>"
|
||||
+ " <name|material|enchantments|attributes|abilities|custommodeldata|rarity|type|description>"
|
||||
+ " [value]";
|
||||
|
||||
private static void modify(
|
||||
@NotNull CommandSender sender, @NotNull String @NotNull [] args, Player p) {
|
||||
|
@ -391,31 +393,29 @@ public class ItemCommand implements TabExecutor {
|
|||
|
||||
@Nullable
|
||||
private static List<String> modifyCompletion(@NotNull String @NotNull [] args) {
|
||||
if (args.length == 4 && (args[0].equalsIgnoreCase(MODIFY))) {
|
||||
if (args[2].equalsIgnoreCase(RARITY)) {
|
||||
return Arrays.stream(Rarity.values()).map(Enum::name).toList();
|
||||
} else if (args[2].equalsIgnoreCase("type")) {
|
||||
return Arrays.stream(ItemType.values()).map(Enum::name).toList();
|
||||
} else if (args[2].equalsIgnoreCase(MATERIAL)) {
|
||||
return Arrays.stream(Material.values())
|
||||
.map(
|
||||
name -> {
|
||||
if (name.name().startsWith(args[3].toUpperCase())) return name.name();
|
||||
return null;
|
||||
})
|
||||
.toList();
|
||||
} else if (args[2].equalsIgnoreCase(ENCHANTMENTS)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(ATTRIBUTES)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(ABILITIES)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(CUSTOMMODELDATA)) {
|
||||
try {
|
||||
Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
return List.of("1");
|
||||
}
|
||||
if (args[2].equalsIgnoreCase(RARITY)) {
|
||||
return Arrays.stream(Rarity.values()).map(Enum::name).toList();
|
||||
} else if (args[2].equalsIgnoreCase("type")) {
|
||||
return Arrays.stream(ItemType.values()).map(Enum::name).toList();
|
||||
} else if (args[2].equalsIgnoreCase(MATERIAL)) {
|
||||
return Arrays.stream(Material.values())
|
||||
.map(
|
||||
name -> {
|
||||
if (name.name().startsWith(args[3].toUpperCase())) return name.name();
|
||||
return null;
|
||||
})
|
||||
.toList();
|
||||
} else if (args[2].equalsIgnoreCase(ENCHANTMENTS)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(ATTRIBUTES)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(ABILITIES)) {
|
||||
return List.of("add", REMOVE);
|
||||
} else if (args[2].equalsIgnoreCase(CUSTOMMODELDATA)) {
|
||||
try {
|
||||
Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
return List.of("1");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -539,7 +539,8 @@ public class ItemCommand implements TabExecutor {
|
|||
List<String> completions = argsLengthThree(args);
|
||||
if (completions != null) return completions;
|
||||
|
||||
completions = modifyCompletion(args);
|
||||
if (args.length == 4 && (args[0].equalsIgnoreCase(MODIFY)))
|
||||
completions = modifyCompletion(args);
|
||||
if (completions != null) return completions;
|
||||
|
||||
completions = modify(args);
|
||||
|
|
|
@ -20,6 +20,32 @@ public class SpawnEntityCommand implements TabExecutor {
|
|||
private static final String USAGE =
|
||||
"Usage: /spawnentity <entityType> [amount] [x] [y] [z] " + "[world]";
|
||||
|
||||
private void spawnEntity(
|
||||
CommandSender sender, String type, int amount, double x, double y, double z, World world) {
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (em == null) {
|
||||
sender.sendMessage("EntityManager is null.");
|
||||
return;
|
||||
}
|
||||
SREntityType eType = em.getType(type);
|
||||
if (type == null) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return;
|
||||
}
|
||||
em.spawnEntity(eType, amount, x, y, z, world);
|
||||
}
|
||||
|
||||
private int getAmount(CommandSender sender, String[] args) {
|
||||
if (args.length > 1 && (args.length < 5 || args.length > 6)) {
|
||||
try {
|
||||
return Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid amount.");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given command, returning its success. <br>
|
||||
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
|
||||
|
@ -105,15 +131,7 @@ public class SpawnEntityCommand implements TabExecutor {
|
|||
world = player.getWorld();
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
if (args.length > 1 && (args.length < 5 || args.length > 6)) {
|
||||
try {
|
||||
amount = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid amount.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
int amount = getAmount(sender, args);
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("Invalid world.");
|
||||
|
@ -121,17 +139,6 @@ public class SpawnEntityCommand implements TabExecutor {
|
|||
}
|
||||
|
||||
// spawn entity
|
||||
EntityManager em = Manager.getInstance(EntityManager.class);
|
||||
if (em == null) {
|
||||
sender.sendMessage("EntityManager is null.");
|
||||
return true;
|
||||
}
|
||||
SREntityType type = em.getType(args[0]);
|
||||
if (type == null) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return true;
|
||||
}
|
||||
em.spawnEntity(type, amount, x, y, z, world);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -110,6 +110,8 @@ public class EntityManager extends Manager {
|
|||
|
||||
public void addEntityType(@NotNull SREntityType type) {
|
||||
types.add(type);
|
||||
// save to db type
|
||||
saveType(type);
|
||||
}
|
||||
|
||||
public List<SREntityType> getTypes() {
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package me.unurled.sacredrealms.sr.components.entity;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
@ -147,7 +144,7 @@ public class SREntityType {
|
|||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
return item == null ? new ItemStack(Material.BONE) : item;
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
|
@ -155,6 +152,12 @@ public class SREntityType {
|
|||
}
|
||||
|
||||
public List<ItemStack> getArmor() {
|
||||
if (armor.isEmpty()) {
|
||||
armor.add(new ItemStack(Material.AIR));
|
||||
armor.add(new ItemStack(Material.AIR));
|
||||
armor.add(new ItemStack(Material.AIR));
|
||||
armor.add(new ItemStack(Material.AIR));
|
||||
}
|
||||
return armor;
|
||||
}
|
||||
|
||||
|
@ -164,7 +167,7 @@ public class SREntityType {
|
|||
}
|
||||
|
||||
public ItemStack getHandItem() {
|
||||
return handItem;
|
||||
return handItem == null ? new ItemStack(Material.AIR) : handItem;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -173,7 +176,7 @@ public class SREntityType {
|
|||
}
|
||||
|
||||
public ItemStack getSecondHandItem() {
|
||||
return secondHandItem;
|
||||
return secondHandItem == null ? new ItemStack(Material.AIR) : secondHandItem;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
@ -26,6 +26,8 @@ public enum Rarity {
|
|||
private final Double weight;
|
||||
private final TextColor color;
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
Rarity(String name, String id, Double weight, TextColor color) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
|
@ -46,7 +48,6 @@ public enum Rarity {
|
|||
@NotNull
|
||||
public static Rarity getRandomRarity(double luck) {
|
||||
// more weight equals less chance to get it
|
||||
Random random = new Random();
|
||||
double randomValue = random.nextDouble() * (1.0 / (luck == 0 ? 1 : luck));
|
||||
|
||||
double cumulativeProbability = 0.0;
|
||||
|
|
|
@ -17,7 +17,7 @@ public class EntityItemDisplay extends AbstractItem {
|
|||
|
||||
private final String name;
|
||||
|
||||
public EntityItemDisplay(SREntityType type) {
|
||||
public EntityItemDisplay(@NotNull SREntityType type) {
|
||||
name = type.getItem().getType().name();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue