From 0cf90ea6964cef8fabef71207d9854c04779a826 Mon Sep 17 00:00:00 2001 From: unurled Date: Tue, 24 May 2022 11:25:35 +0200 Subject: [PATCH] 0.5.2 custom model data command + disable dungeon for now --- .gitignore | 1 + bin/main/config.yml | 14 --- bin/main/plugin.yml | 49 -------- build.gradle | 13 +-- src/main/java/gq/unurled/raxen/Raxen.java | 2 +- .../admin/CustomModelDataCommand.java | 105 ++++++++++++++++++ .../raxen/listener/player/PortalEvent.java | 27 +++++ .../raxen/manager/server/CommandManager.java | 7 ++ .../raxen/manager/server/DungeonsManager.java | 16 ++- .../gq/unurled/raxen/utils/DungeonUtils.java | 51 +++++++++ .../java/gq/unurled/raxen/utils/Utils.java | 16 +++ src/main/resources/plugin.yml | 9 +- 12 files changed, 233 insertions(+), 77 deletions(-) delete mode 100644 bin/main/config.yml delete mode 100644 bin/main/plugin.yml create mode 100644 src/main/java/gq/unurled/raxen/commands/admin/CustomModelDataCommand.java create mode 100644 src/main/java/gq/unurled/raxen/listener/player/PortalEvent.java diff --git a/.gitignore b/.gitignore index 108f7ad..f9ab433 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ api/ *.iml worlds/ +bin/ .gradle/ gradle.properties diff --git a/bin/main/config.yml b/bin/main/config.yml deleted file mode 100644 index cc0b004..0000000 --- a/bin/main/config.yml +++ /dev/null @@ -1,14 +0,0 @@ - version: "${version}" - motd: "YAY, Super server!" - motd-reload: "Server reloading!" - - storage: "MONGODB" # switch between "MONGODB", "MYSQL"(not implemented), "YML"(currently making it) - # if MYSQL or MongoDB - username: "no_usr" # if mysql if you are on mongodb, add username in the url - password: "no_pass" # if mysql if you are on mongodb, add password in the url - url: "mongodb://localhost:27017" - - useResourcePack: false - resource_pack_url: "https://mc-packs.net/" # recommend to use https://mc-packs.net/ => free resource pack hoster (will eventually develop one myself but not atm) - resource_pack_sha1: "sha1hallo" # sha1 hash - debug: true \ No newline at end of file diff --git a/bin/main/plugin.yml b/bin/main/plugin.yml deleted file mode 100644 index ce65f50..0000000 --- a/bin/main/plugin.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Raxen -version: '${version}' -main: gq.unurled.raxen.Raxen -author: unurled -api-version: 1.18 -depend: [ProtocolLib, PlaceholderAPI] -softdepend: [AureliumSkills, LuckPerms] - -commands: - reloadplugin: - aliases: - - rlpl - - reloadpl - description: reload command that stops the server. - skills: - aliases: - - skill - description: skill command. - testgui: - description: test gui command - storage: - description: acces player storage - nbt: - description: nbt command - raxen: - description: raxen main command - itemlist: - aliases: itl - description: Open ItemList menu - entityspawn: - description: Spawn an custom entity - class: - description: player command that make them choose their class and then their stats - -permissions: - raxen.reload.cmd: - description: reload command permission - raxen.test.gui.cmd: - description: testgui command permission - raxen.nbt.cmd: - description: nbt command permission - raxen.raxen.cmd: - description: raxen command permssion - raxen.itemlist.cmd: - description: itemlist command permission - raxen.entityspawn.cmd: - description: entityspawn command permission - raxen.class.cmd: - description: class command premission \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0f79562..f327146 100644 --- a/build.gradle +++ b/build.gradle @@ -55,10 +55,9 @@ repositories { dependencies { // lombok stuff - implementation 'org.projectlombok:lombok:1.18.22' - annotationProcessor 'org.projectlombok:lombok:1.18.22' - testCompileOnly 'org.projectlombok:lombok:1.18.22' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' + implementation 'org.projectlombok:lombok:1.18.24' + annotationProcessor 'org.projectlombok:lombok:1.18.24' + testCompileOnly 'org.projectlombok:lombok:1.18.24' // mongo stuff implementation 'org.mongodb:mongodb-driver-sync:4.5.1' @@ -71,8 +70,8 @@ dependencies { compileOnly 'net.luckperms:api:5.4' compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1' compileOnly 'net.essentialsx:EssentialsX:2.19.4' - compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.1.0' - compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.1.0' + compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.1.2' + compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.1.2' compileOnly 'me.clip:placeholderapi:2.11.1' compileOnly 'net.citizensnpcs:citizens-main:2.0.29-SNAPSHOT' compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.3.1' @@ -81,7 +80,7 @@ dependencies { } group = 'gq.unurled' -version = '0.5.1' +version = '0.5.2' description = 'Raxen' java.sourceCompatibility = JavaVersion.VERSION_17 diff --git a/src/main/java/gq/unurled/raxen/Raxen.java b/src/main/java/gq/unurled/raxen/Raxen.java index 986b862..e6bd816 100644 --- a/src/main/java/gq/unurled/raxen/Raxen.java +++ b/src/main/java/gq/unurled/raxen/Raxen.java @@ -18,7 +18,7 @@ import static gq.unurled.raxen.utils.Utils.colorComp; public final class Raxen extends JavaPlugin { private static final String prefix = "Rx> "; - @Getter private static String version = "0.5.1"; + @Getter private static String version = "0.5.2"; private final PluginManager pm = getServer().getPluginManager(); private static Raxen plugin; diff --git a/src/main/java/gq/unurled/raxen/commands/admin/CustomModelDataCommand.java b/src/main/java/gq/unurled/raxen/commands/admin/CustomModelDataCommand.java new file mode 100644 index 0000000..7f33f54 --- /dev/null +++ b/src/main/java/gq/unurled/raxen/commands/admin/CustomModelDataCommand.java @@ -0,0 +1,105 @@ +package gq.unurled.raxen.commands.admin; + +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static gq.unurled.raxen.utils.Utils.*; + +public class CustomModelDataCommand implements TabExecutor { + + /** + * change custom model data of an item + * @param sender Source of the command + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments + * @return + */ + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player)) { + errorConsoleSender(sender); + return true; + } + Player p = (Player) sender; + if (!(p.hasPermission("raxen.custommodeldata.cmd"))) { + p.sendMessage(noPerms()); + return true; + } + ItemStack it = p.getInventory().getItemInMainHand(); + if (args.length == 0) { + p.sendMessage(colorComp("Usage: /custommodeldata ")); + return true; + } + if (!(isInt(args[0]))) { + Material material = Material.getMaterial(args[1]); + if (material != null) { + it = customModelData(new ItemStack(material), Integer.parseInt(args[0])); + p.getInventory().setItemInMainHand(it); + p.updateInventory(); + } else { + p.sendMessage(colorComp("Please specify a valid Item Name or a valid Integer.")); + } + } else { + if (it != null && it.getType() != Material.AIR) { // check if player has an item in hand + // has item in hand applying the custom model data + it = customModelData(it, Integer.parseInt(args[0])); + p.getInventory().setItemInMainHand(it); + p.updateInventory(); + } else { + p.sendMessage(colorComp("Get an item in hand please or specify an item")); + p.sendMessage(colorComp("Usage: /custommodeldata ")); + } + } + return true; + } + + /** + * @param sender Source of the command. For players tab-completing a + * command inside of a command block, this will be the player, not + * the command block. + * @param command Command which was executed + * @param label Alias of the command which was used + * @param args The arguments passed to the command, including final + * partial argument to be completed + * @return + */ + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + final List completions = new ArrayList<>(); + + List SUB_COMMANDS= new ArrayList<>(); + + if (!(isInt(args[0]))) { + return Arrays.asList( "§c" + args[0]); + } + if (args.length == 2) { + for (Material mat : Material.values()) { + SUB_COMMANDS.add(mat.name()); + } + StringUtil.copyPartialMatches(args[1], SUB_COMMANDS, completions); + Collections.sort(completions); + } + return completions; + } + + private ItemStack customModelData(ItemStack it, Integer in) { + ItemMeta itm = it.getItemMeta(); + itm.setCustomModelData(in); + it.setItemMeta(itm); + return it; + } +} diff --git a/src/main/java/gq/unurled/raxen/listener/player/PortalEvent.java b/src/main/java/gq/unurled/raxen/listener/player/PortalEvent.java new file mode 100644 index 0000000..dbd56f4 --- /dev/null +++ b/src/main/java/gq/unurled/raxen/listener/player/PortalEvent.java @@ -0,0 +1,27 @@ +package gq.unurled.raxen.listener.player; + +import gq.unurled.raxen.components.dungeons.Gate; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityPortalEnterEvent; + +import static gq.unurled.raxen.utils.DungeonUtils.isInRange; +import static gq.unurled.raxen.utils.DungeonUtils.whichIsInRange; + +public class PortalEvent implements Listener { + + @EventHandler + public void PortalE(EntityPortalEnterEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + Location loc = e.getLocation(); + // if loc is in range + if (isInRange(loc)) { + Gate g = whichIsInRange(loc); + //g.t + } + } + } +} diff --git a/src/main/java/gq/unurled/raxen/manager/server/CommandManager.java b/src/main/java/gq/unurled/raxen/manager/server/CommandManager.java index 34b8262..61e0d24 100644 --- a/src/main/java/gq/unurled/raxen/manager/server/CommandManager.java +++ b/src/main/java/gq/unurled/raxen/manager/server/CommandManager.java @@ -22,6 +22,7 @@ public class CommandManager { private RaxenCommand raxenCommand; private SpawnEntity entityspawn; private ClassCommand classCommand; + private CustomModelDataCommand customModelDataCommand; public CommandManager(Raxen main) { this.main = main; @@ -31,6 +32,7 @@ public class CommandManager { this.classCommand = new ClassCommand(this.main); this.skillsCommand = new SkillsCommand(main); this.raxenCommand = new RaxenCommand(main); + this.customModelDataCommand = new CustomModelDataCommand(); } /** @@ -64,6 +66,11 @@ public class CommandManager { main.getCommand("class").setTabCompleter(classCommand); main.getCommand("class").setExecutor(classCommand); + + main.getCommand("custommodeldata").setTabCompleter(customModelDataCommand); + main.getCommand("custommodeldata").setExecutor(customModelDataCommand); + + } } diff --git a/src/main/java/gq/unurled/raxen/manager/server/DungeonsManager.java b/src/main/java/gq/unurled/raxen/manager/server/DungeonsManager.java index afc98f5..223d496 100644 --- a/src/main/java/gq/unurled/raxen/manager/server/DungeonsManager.java +++ b/src/main/java/gq/unurled/raxen/manager/server/DungeonsManager.java @@ -4,17 +4,17 @@ import gq.unurled.raxen.Raxen; import gq.unurled.raxen.components.dungeons.Dungeon; import gq.unurled.raxen.components.dungeons.Gate; import gq.unurled.raxen.components.dungeons.types.forest.ForestDungeon; +import org.bukkit.Location; import java.util.HashMap; -import java.util.UUID; public class DungeonsManager { private Raxen main; - private HashMap gates = new HashMap<>(); + private HashMap gates = new HashMap<>(); - private HashMap dungeons = new HashMap<>(); + private HashMap dungeons = new HashMap<>(); public DungeonsManager(Raxen main) { this.main = main; @@ -26,10 +26,16 @@ public class DungeonsManager { */ public void registerDungeons() { ForestDungeon forestDungeon = new ForestDungeon(); - dungeons.put("FOREST", forestDungeon); - + dungeons.put(forestDungeon.getGate(), forestDungeon); + gates.put(forestDungeon.getGate(), forestDungeon.getGate().getLoc()); + /* for (String s : dungeons.keySet()) { main.getManager().getWorldManager().loadWorld(dungeons.get(s).getName()); } + */ + } + + public HashMap getGates() { + return gates; } } diff --git a/src/main/java/gq/unurled/raxen/utils/DungeonUtils.java b/src/main/java/gq/unurled/raxen/utils/DungeonUtils.java index 3e6a621..45ea5ef 100644 --- a/src/main/java/gq/unurled/raxen/utils/DungeonUtils.java +++ b/src/main/java/gq/unurled/raxen/utils/DungeonUtils.java @@ -1,9 +1,14 @@ package gq.unurled.raxen.utils; +import gq.unurled.raxen.Raxen; +import gq.unurled.raxen.components.dungeons.Gate; import gq.unurled.raxen.components.dungeons.Rank; import gq.unurled.raxen.components.dungeons.Types; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; import java.util.Random; public class DungeonUtils { @@ -49,4 +54,50 @@ public class DungeonUtils { Random r = new Random(); r.nextInt(); } + + /** + * if a gate is in range of the player + * @return boolean + */ + public static Boolean isInRange(Location loc) { + Raxen main = (Raxen) Bukkit.getServer().getPluginManager().getPlugin("Raxen"); + HashMap gats = main.getManager().getDungeonsManager().getGates(); + for (Gate g : gats.keySet()) { + Double x = g.getLoc().getX(); + Double y = g.getLoc().getY(); + Double z = g.getLoc().getZ(); + Double radius = Double.valueOf(g.getPortalRadius()); + if (loc.getX() < x+radius && loc.getX() > x-radius) { + if (loc.getY() < y+radius && loc.getY() > y-radius) { + if (loc.getZ() < z+radius && loc.getZ() > z-radius) { + return true; + } + } + } + } + return false; + } + + /** + * if a gate is in range of the player + * @return the gates which is in range + */ + public static Gate whichIsInRange(Location loc) { + Raxen main = (Raxen) Bukkit.getServer().getPluginManager().getPlugin("Raxen"); + HashMap gats = main.getManager().getDungeonsManager().getGates(); + for (Gate g : gats.keySet()) { + Double x = g.getLoc().getX(); + Double y = g.getLoc().getY(); + Double z = g.getLoc().getZ(); + Double radius = Double.valueOf(g.getPortalRadius()); + if (loc.getX() < x+radius && loc.getX() > x-radius) { + if (loc.getY() < y+radius && loc.getY() > y-radius) { + if (loc.getZ() < z+radius && loc.getZ() > z-radius) { + return g; + } + } + } + } + return null; + } } diff --git a/src/main/java/gq/unurled/raxen/utils/Utils.java b/src/main/java/gq/unurled/raxen/utils/Utils.java index 31573a3..fb0ee00 100644 --- a/src/main/java/gq/unurled/raxen/utils/Utils.java +++ b/src/main/java/gq/unurled/raxen/utils/Utils.java @@ -316,6 +316,10 @@ public class Utils { return colorComp("An Error has occurred. Please retry or contact an Admin."); } + public static void errorConsoleSender(CommandSender sender) { + sender.sendMessage(colorComp("Can't use this command as the console.")); + } + /** * Copy folder from sourceDirectoryLocation to destinationDirectoryLocation * @param sourceDirectoryLocation the source directory @@ -350,4 +354,16 @@ public class Utils { } Files.delete(path); } + + public static boolean isInt(String strNum) { + if (strNum == null) { + return false; + } + try { + double d = Integer.parseInt(strNum); + } catch (NumberFormatException nfe) { + return false; + } + return true; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ef94031..7f1952f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -31,6 +31,11 @@ commands: description: Spawn an custom entity class: description: player command that make them choose their class and then their stats + custommodeldata: + aliases: + - cmdata + - cmd + description: set custom model data to item permissions: raxen.reload.cmd: @@ -46,4 +51,6 @@ permissions: raxen.entityspawn.cmd: description: entityspawn command permission raxen.class.cmd: - description: class command premission \ No newline at end of file + description: class command permission + raxen.custommodeldata.cmd: + description: custom model data command permission \ No newline at end of file