diff --git a/.gitignore b/.gitignore index f9ab433..090c47c 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,5 @@ buildNumber.properties run/ /.gradle/ /gradle/ + +resource_pack/raxen/assets/minecraft/ diff --git a/build.gradle b/build.gradle index 081ebf5..09d9bae 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java' id 'maven-publish' id "com.github.johnrengelman.shadow" version "7.1.2" - id "io.papermc.paperweight.userdev" version "1.3.5" + id "io.papermc.paperweight.userdev" version "1.3.9" } apply plugin: "java" @@ -60,27 +60,27 @@ dependencies { testCompileOnly 'org.projectlombok:lombok:1.18.24' // mongo stuff - implementation 'org.mongodb:mongodb-driver-sync:4.7.1' - implementation 'org.mongodb:bson:4.7.1' - implementation 'org.mongodb:mongodb-driver-core:4.7.1' + implementation 'org.mongodb:mongodb-driver-sync:4.7.2' + implementation 'org.mongodb:bson:4.7.2' + implementation 'org.mongodb:mongodb-driver-core:4.7.2' implementation 'de.tr7zw:item-nbt-api-plugin:2.10.0' - compileOnly 'io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT' compileOnly 'com.comphenix.protocol:ProtocolLib:4.8.0' compileOnly 'net.luckperms:api:5.4' compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1' - compileOnly 'net.essentialsx:EssentialsX:2.19.4' + compileOnly 'net.essentialsx:EssentialsX:2.19.7' //compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.3.0' //compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.3.0' - compileOnly 'me.clip:placeholderapi:2.11.1' + compileOnly 'me.clip:placeholderapi:2.11.2' //compileOnly 'net.citizensnpcs:citizens-main:2.0.30-SNAPSHOT' compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.3.1' compileOnly fileTree(dir: 'libs', include: '*.jar') - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19.2-R0.1-SNAPSHOT") } group = 'me.unurled' -version = '0.5.4' +version = '0.5.5' description = 'Raxen' java { @@ -110,9 +110,9 @@ tasks { shadowJar { dependencies { include dependency('de.tr7zw:item-nbt-api-plugin:2.10.0') - include dependency('org.mongodb:mongodb-driver-sync:4.5.1') - include dependency('org.mongodb:bson:4.5.1') - include dependency('org.mongodb:mongodb-driver-core:4.5.1') + include dependency('org.mongodb:mongodb-driver-sync:4.7.2') + include dependency('org.mongodb:bson:4.7.2') + include dependency('org.mongodb:mongodb-driver-core:4.7.2') } relocate("de.tr7zw.changeme", "me.unurled.libs.de.tr7zw") relocate("de.tr7zw", "me.unurled.libs.de.tr7zw") @@ -123,8 +123,7 @@ shadowJar { } } -gradle.projectsEvaluated { - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } -} \ No newline at end of file + +tasks.withType(JavaCompile) { + options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation"] +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fc..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/resource_pack/raxen/assets/minecraft/font/default.json b/resource_pack/raxen/assets/minecraft/font/default.json deleted file mode 100644 index 2c6f3a9..0000000 --- a/resource_pack/raxen/assets/minecraft/font/default.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "providers": [ - { - "chars": - [ - "ꀀ" - ], - "file": "minecraft:/recipe_showcase.png", - "ascent":40, - "height":164, - "type":"bitmap" - } - ] -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/models/item/compass.json b/resource_pack/raxen/assets/minecraft/models/item/compass.json deleted file mode 100644 index 59fd30e..0000000 --- a/resource_pack/raxen/assets/minecraft/models/item/compass.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "item/compass_16" - }, - "overrides": [ - { - "predicate": { - "custom_model_data": 1 - }, - "model": "raxen/item/device" - } - - ] -} diff --git a/resource_pack/raxen/assets/minecraft/models/item/diamond_axe.json b/resource_pack/raxen/assets/minecraft/models/item/diamond_axe.json deleted file mode 100644 index a5ea6a9..0000000 --- a/resource_pack/raxen/assets/minecraft/models/item/diamond_axe.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "parent":"item/handheld", - "textures": { - "layer0":"item/diamond_axe" - }, - "overrides": [ - { - "predicate": { - "custom_model_data":1 - }, - "model":"default/magical_axe" - }, - { - "predicate": { - "custom_model_data":2 - }, - "model":"default/battle_axe" - } - ] -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/models/item/diamond_shovel.json b/resource_pack/raxen/assets/minecraft/models/item/diamond_shovel.json deleted file mode 100644 index f6cbdeb..0000000 --- a/resource_pack/raxen/assets/minecraft/models/item/diamond_shovel.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "parent": "minecraft:item/handheld", - "textures": { - "layer0": "minecraft:item/diamond_shovel" - }, - "overrides": [ - { - "predicate": { - "custom_model_data": 1 - }, - "model":"raxen/item/device" - }, - { - "predicate": { - "custom_model_data": 2 - }, - "model":"raxen/gui/lower_section" - },{ - "predicate": { - "custom_model_data": 3 - }, - "model":"raxen/gui/upper_section" - } - ] -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/models/raxen/gui/lower_section.json b/resource_pack/raxen/assets/minecraft/models/raxen/gui/lower_section.json deleted file mode 100644 index b44bd7e..0000000 --- a/resource_pack/raxen/assets/minecraft/models/raxen/gui/lower_section.json +++ /dev/null @@ -1,27 +0,0 @@ -{ -"textures": { - "texture": "raxen/gui/lower_section" -}, -"elements": [ -{ - "from": [ -16, -16, 15.9375 ], - "to": [ 32, 32, 16 ], - "faces": { - "north": { "uv": [ 11, 16, 0, 5 ], "rotation": 180, "texture": "#texture" }, - "south": { "uv": [ 0, 5, 11, 16 ], "texture": "#texture" } - } -} -], -"display": { - "firstperson_lefthand": { - "rotation": [ 0, 0, 0 ], - "translation": [ 0, 0, 0 ], - "scale": [ 0, 0, 0 ] - }, - "gui": { - "rotation": [ 0, 0, 0 ], - "translation": [ 72, -74, -80 ], - "scale": [ 3.66, 3.66, 3.66 ] - } -} -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/models/raxen/gui/upper_section.json b/resource_pack/raxen/assets/minecraft/models/raxen/gui/upper_section.json deleted file mode 100644 index 3abf8d3..0000000 --- a/resource_pack/raxen/assets/minecraft/models/raxen/gui/upper_section.json +++ /dev/null @@ -1,27 +0,0 @@ -{ -"textures": { - "texture": "raxen/gui/upper_section" -}, -"elements": [ -{ - "from": [ -16, -16, 15.9375 ], - "to": [ 32, 32, 16 ], - "faces": { - "north": { "uv": [ 11, 16, 0, 5 ], "rotation": 180, "texture": "#texture" }, - "south": { "uv": [ 0, 5, 11, 16 ], "texture": "#texture" } - } -} -], -"display": { - "firstperson_lefthand": { - "rotation": [ 0, 0, 0 ], - "translation": [ 0, 0, 0 ], - "scale": [ 0, 0, 0 ] - }, - "gui": { - "rotation": [ 0, 0, 0 ], - "translation": [ 72, 29, -80 ], - "scale": [ 3.66, 3.66, 3.66 ] - } -} -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/models/raxen/item/device.json b/resource_pack/raxen/assets/minecraft/models/raxen/item/device.json deleted file mode 100644 index 61c801b..0000000 --- a/resource_pack/raxen/assets/minecraft/models/raxen/item/device.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "credit": "Made with Blockbench", - "texture_size": [32, 32], - "textures": { - "0": "raxen/item/device" - }, - "elements": [ - { - "from": [5, 4, 7], - "to": [12, 12, 9], - "faces": { - "north": {"uv": [7, 0, 14, 8], "texture": "#0"}, - "east": {"uv": [2, 8, 4, 16], "texture": "#0"}, - "south": {"uv": [0, 0, 7, 8], "texture": "#0"}, - "west": {"uv": [0, 8, 2, 16], "texture": "#0"}, - "up": {"uv": [11, 10, 4, 8], "rotation": 180, "texture": "#0"}, - "down": {"uv": [11, 10, 4, 12], "rotation": 180, "texture": "#0"} - } - } - ], - "display": { - "thirdperson_righthand": { - "translation": [0, 4, 1] - }, - "firstperson_righthand": { - "rotation": [-12, -25, 0] - }, - "gui": { - "translation": [-0.75, 0, 0], - "scale": [1.5, 1.5, 1.5] - }, - "fixed": { - "rotation": [0, -180, 0], - "scale": [1.5, 1.5, 1.5] - } - } -} \ No newline at end of file diff --git a/resource_pack/raxen/assets/minecraft/textures/block/oak_planks.png b/resource_pack/raxen/assets/minecraft/textures/block/oak_planks.png deleted file mode 100644 index 05faf77..0000000 Binary files a/resource_pack/raxen/assets/minecraft/textures/block/oak_planks.png and /dev/null differ diff --git a/resource_pack/raxen/assets/minecraft/textures/raxen/gui/lower_section.png b/resource_pack/raxen/assets/minecraft/textures/raxen/gui/lower_section.png deleted file mode 100644 index ae3ef13..0000000 Binary files a/resource_pack/raxen/assets/minecraft/textures/raxen/gui/lower_section.png and /dev/null differ diff --git a/resource_pack/raxen/assets/minecraft/textures/raxen/gui/upper_section.png b/resource_pack/raxen/assets/minecraft/textures/raxen/gui/upper_section.png deleted file mode 100644 index 5b86c80..0000000 Binary files a/resource_pack/raxen/assets/minecraft/textures/raxen/gui/upper_section.png and /dev/null differ diff --git a/resource_pack/raxen/assets/minecraft/textures/raxen/item/device.png b/resource_pack/raxen/assets/minecraft/textures/raxen/item/device.png deleted file mode 100644 index 6790fde..0000000 Binary files a/resource_pack/raxen/assets/minecraft/textures/raxen/item/device.png and /dev/null differ diff --git a/src/main/java/me/unurled/raxen/Raxen.java b/src/main/java/me/unurled/raxen/Raxen.java index 1345827..f898707 100644 --- a/src/main/java/me/unurled/raxen/Raxen.java +++ b/src/main/java/me/unurled/raxen/Raxen.java @@ -18,7 +18,7 @@ import static me.unurled.raxen.utils.Utils.colorComp; public final class Raxen extends JavaPlugin { private static final String prefix = "Rx> "; - @Getter private static String version = "0.5.4"; + @Getter private static String version = "0.5.5"; private final PluginManager pm = getServer().getPluginManager(); private static Raxen plugin; diff --git a/src/main/java/me/unurled/raxen/commands/admin/EntitiyCommand.java b/src/main/java/me/unurled/raxen/commands/admin/EntitiyCommand.java new file mode 100644 index 0000000..254d5e6 --- /dev/null +++ b/src/main/java/me/unurled/raxen/commands/admin/EntitiyCommand.java @@ -0,0 +1,2 @@ +package me.unurled.raxen.commands.admin;public class EntitiyCommand { +} diff --git a/src/main/java/me/unurled/raxen/commands/admin/ItemTo64Command.java b/src/main/java/me/unurled/raxen/commands/admin/ItemTo64Command.java new file mode 100644 index 0000000..0476e9c --- /dev/null +++ b/src/main/java/me/unurled/raxen/commands/admin/ItemTo64Command.java @@ -0,0 +1,2 @@ +package me.unurled.raxen.commands.admin;public class ItemTo64 { +} diff --git a/src/main/java/me/unurled/raxen/commands/admin/SpawnEntity.java b/src/main/java/me/unurled/raxen/commands/admin/SpawnEntity.java index ea4a05a..2e6917b 100644 --- a/src/main/java/me/unurled/raxen/commands/admin/SpawnEntity.java +++ b/src/main/java/me/unurled/raxen/commands/admin/SpawnEntity.java @@ -2,19 +2,27 @@ package me.unurled.raxen.commands.admin; import me.unurled.raxen.Raxen; import me.unurled.raxen.components.entity.other.EntityNamespacedKey; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static me.unurled.raxen.components.entity.other.EntityUtils.setNameSpacedKeys; +import static me.unurled.raxen.utils.Items.itemFrom64; import static me.unurled.raxen.utils.Utils.*; public class SpawnEntity implements TabExecutor { @@ -30,23 +38,99 @@ public class SpawnEntity implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender instanceof Player)) { - log(colorString("Console can't execute this command!")); - return false; + log(colorTextComp("Console can't execute this command!")); + try { // /entityspawn ZOMBIE "&cHello folks" x:0 y:0 z:0 level health defense speed strength itemStackBinary64: helmet, chestplate, leggings, boots, main-hand, off-hand + if (validateArgs(args, 16)) { + args = setNullInArgs(args); + } else { + log(colorTextComp("Please use null if you don't want some parameters in the command.")); + log(colorTextComp("Follow this command: /entityspawn TYPE \"name\" x y z level health defense speed strength " + + "helmet(itemStackBinary64) chestplate(itemStackBinary64) leggings(itemStackBinary64) boots(itemStackBinary64) main-hand(itemStackBinary64) off-hand(itemStackBinary64)")); + return false; + } + + EntityType types = EntityType.valueOf(args[0]); + Location loc = new Location(Bukkit.getWorld("world"), Double.parseDouble(args[2]), Double.parseDouble(args[3]), Double.parseDouble(args[4])); + Entity e = loc.getWorld().spawnEntity(loc, types, false); + setNameSpacedKeys(e, getStringFromArg(args), Integer.parseInt(args[6]), Integer.parseInt(args[7]),0, + Integer.parseInt(args[8]),0, Integer.parseInt(args[9]),0, Integer.parseInt(args[10]),0); + e.customName(colorTextComp(getStringFromArg(args))); + e.setCustomNameVisible(true); + if (e instanceof LivingEntity livingEntity) { +// livingEntity.getEquipment().set + ItemStack helmet = itemFrom64(args[11]); + ItemStack chestplate = itemFrom64(args[12]); + ItemStack leggins = itemFrom64(args[13]); + ItemStack boots = itemFrom64(args[14]); + ItemStack mainhand = itemFrom64(args[15]); + ItemStack offhand = itemFrom64(args[14]); + EntityEquipment equip = livingEntity.getEquipment(); + equip.setHelmet(helmet); + equip.setChestplate(chestplate); + equip.setLeggings(leggins); + equip.setBoots(boots); + equip.setItemInMainHand(mainhand); + equip.setItemInOffHand(offhand); + } + + System.out.println(e.getName()); + } catch (IllegalArgumentException e) { + error("Something happened near the SpawnEntity command."); + throw new RuntimeException(e); + } catch (IOException e) { + error("Could not deserialize item from the command EntitySpawn (command launched by " + sender.getName() + ")"); + throw new RuntimeException(e); + } + } + for (String arg : args) { + log(arg); } Player player = (Player) sender; if (!player.hasPermission("raxen.entityspawn.cmd")) { player.sendMessage(noPerms()); return false; } - //example command : /entityspawn ZOMBIE "&cHello folks" 50 200 - try { - EntityType types = EntityType.valueOf(args[0]); - Entity e = player.getWorld().spawnEntity(player.getLocation(), types, false); - setNameSpacedKeys(e, "Name", 100, 100,0,50,0,100,0,100,0); - e.customName(colorTextComp(args[1])); - e.setCustomNameVisible(true); - } catch (IllegalArgumentException e) { + try { // /entityspawn ZOMBIE "&cHello folks" x:0 y:0 z:0 level health defense speed strength itemStackBinary64: helmet, chestplate, leggings, boots, main-hand, off-hand + if (validateArgs(args, 16)) { + args = setNullInArgs(args); + } else { + log(colorTextComp("Please use null if you don't want some parameters in the command.")); + log(colorTextComp("Follow this command: /entityspawn TYPE \"name\" x y z level health defense speed strength " + + "helmet(itemStackBinary64) chestplate(itemStackBinary64) leggings(itemStackBinary64) boots(itemStackBinary64) main-hand(itemStackBinary64) off-hand(itemStackBinary64)")); + return false; + } + EntityType types = EntityType.valueOf(args[0]); + Location loc = new Location(Bukkit.getWorld("world"), Double.parseDouble(args[2]), Double.parseDouble(args[3]), Double.parseDouble(args[4])); + Entity e = loc.getWorld().spawnEntity(loc, types, false); + setNameSpacedKeys(e, getStringFromArg(args), Integer.parseInt(args[6]), Integer.parseInt(args[7]),0, + Integer.parseInt(args[8]),0, Integer.parseInt(args[9]),0, Integer.parseInt(args[10]),0); + e.customName(colorTextComp(getStringFromArg(args))); + e.setCustomNameVisible(true); + if (e instanceof LivingEntity livingEntity) { +// livingEntity.getEquipment().set + ItemStack helmet = itemFrom64(args[11]); + ItemStack chestplate = itemFrom64(args[12]); + ItemStack leggins = itemFrom64(args[13]); + ItemStack boots = itemFrom64(args[14]); + ItemStack mainhand = itemFrom64(args[15]); + ItemStack offhand = itemFrom64(args[14]); + EntityEquipment equip = livingEntity.getEquipment(); + equip.setHelmet(helmet); + equip.setChestplate(chestplate); + equip.setLeggings(leggins); + equip.setBoots(boots); + equip.setItemInMainHand(mainhand); + equip.setItemInOffHand(offhand); + } + + System.out.println(e.getName()); + } catch (IllegalArgumentException e) { + error("Something happened near the SpawnEntity command."); + throw new RuntimeException(e); + } catch (IOException e) { + error("Could not deserialize item from the command EntitySpawn (command launched by " + sender.getName() + ")"); + throw new RuntimeException(e); } return false; diff --git a/src/main/java/me/unurled/raxen/components/entity/player/Scoreboard.java b/src/main/java/me/unurled/raxen/components/entity/player/Scoreboard.java index 7c196d6..5aee096 100644 --- a/src/main/java/me/unurled/raxen/components/entity/player/Scoreboard.java +++ b/src/main/java/me/unurled/raxen/components/entity/player/Scoreboard.java @@ -4,10 +4,7 @@ import me.unurled.raxen.Raxen; import me.unurled.raxen.utils.libs.Vault; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.ScoreboardManager; +import org.bukkit.scoreboard.*; import static me.unurled.raxen.utils.Utils.*; @@ -24,17 +21,17 @@ public class Scoreboard { public void createScorebord(Player player) { ScoreboardManager manager = Bukkit.getScoreboardManager(); org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard(); - Objective obj = board.registerNewObjective("Raxen","dummy", colorTextComp("Elixium")); + Objective obj = board.registerNewObjective("Raxen", "dummy", colorTextComp("Elixium")); obj.setDisplaySlot(DisplaySlot.SIDEBAR); - Score score = obj.getScore(colorString("-------------")); + Score score = obj.getScore(textCompToString(colorTextComp("-------------"))); score.setScore(4); - Score score1 = obj.getScore(colorString("Name:" + player.getName())); + Score score1 = obj.getScore(textCompToString(colorTextComp("Name:" + player.getName()))); score1.setScore(3); - Score score2 = obj.getScore(colorString("Location")); + Score score2 = obj.getScore(textCompToString(colorTextComp("Location"))); score2.setScore(2); - Score score3 = obj.getScore(colorString("Coins: " + vault.getBalanceString(player))); + Score score3 = obj.getScore(textCompToString(colorTextComp("Coins: " + vault.getBalanceString(player)))); score3.setScore(1); - Score score4 = obj.getScore(colorString("unurled.me")); + Score score4 = obj.getScore(textCompToString(colorTextComp("unurled.me"))); score4.setScore(0); player.setScoreboard(board); } @@ -50,7 +47,8 @@ public class Scoreboard { } } player.getScoreboard().resetScores("Coins"); - Score score = objective.getScore(colorString("Coins: " + vault.getBalanceString(player))); + assert objective != null; + Score score = objective.getScore(textCompToString(colorTextComp("Coins: " + vault.getBalanceString(player)))); score.setScore(1); } } diff --git a/src/main/java/me/unurled/raxen/listener/entity/DamageEntity.java b/src/main/java/me/unurled/raxen/listener/entity/DamageEntity.java index 53b930f..0daf4b1 100644 --- a/src/main/java/me/unurled/raxen/listener/entity/DamageEntity.java +++ b/src/main/java/me/unurled/raxen/listener/entity/DamageEntity.java @@ -15,6 +15,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import java.util.Objects; + import static me.unurled.raxen.utils.Utils.debug; public class DamageEntity implements Listener { @@ -46,10 +48,9 @@ public class DamageEntity implements Listener { Integer health = 0; Integer itemHealth = 0; Integer initDamage = 0; - PlayerManager pm = ((Raxen) Bukkit.getPluginManager().getPlugin("Raxen")).getManager().getPlayerManager(); + PlayerManager pm = ((Raxen) Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Raxen"))).getManager().getPlayerManager(); debug(main, e.getEntity().getName(), e.getEntity().getType().toString(), e.getDamager().getType().toString(), e.getDamager().getName()); - if (e.getDamager() instanceof Player) { - Player playerDamager = (Player) e.getDamager(); + if (e.getDamager() instanceof Player playerDamager) { strength = pm.getStrength().get(playerDamager); itemStrength = pm.getItemStrength().get(playerDamager); } else { @@ -60,8 +61,7 @@ public class DamageEntity implements Listener { } itemStrength = pm.getItemStrength().getItem((LivingEntity) entityDamager); } - if (e.getEntity() instanceof Player) { - Player playerVictim = (Player) e.getEntity(); + if (e.getEntity() instanceof Player playerVictim) { me.unurled.raxen.components.entity.player.attributes.Attributes attributes = new me.unurled.raxen.components.entity.player.attributes.Attributes(main); defense = pm.getDefense().get(playerVictim); health = pm.getHealth().get(playerVictim); @@ -93,7 +93,7 @@ public class DamageEntity implements Listener { debug(main, String.valueOf(health_with_defense)); if (damage >= health_with_defense) { debug(main, "Killed entity normally."); - e.setDamage(e.getEntity().getType().getDefaultAttributes().getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()); + e.setDamage(Objects.requireNonNull(e.getEntity().getType().getDefaultAttributes().getAttribute(Attribute.GENERIC_MAX_HEALTH)).getDefaultValue()); } else { debug(main, "Applying damage to entity."); if (defense == 0) { @@ -101,8 +101,7 @@ public class DamageEntity implements Listener { } else { health = health_with_defense - health - damage; } - if (e.getEntity() instanceof Player) { - Player playerVictim = (Player) e.getEntity(); + if (e.getEntity() instanceof Player playerVictim) { me.unurled.raxen.components.entity.player.attributes.Attributes attributes = new me.unurled.raxen.components.entity.player.attributes.Attributes(main); pm.getHealth().set(playerVictim, health); playerVictim.setHealth(health.doubleValue()/5); diff --git a/src/main/java/me/unurled/raxen/listener/player/InteractEvent.java b/src/main/java/me/unurled/raxen/listener/player/InteractEvent.java new file mode 100644 index 0000000..2512f67 --- /dev/null +++ b/src/main/java/me/unurled/raxen/listener/player/InteractEvent.java @@ -0,0 +1,18 @@ +package me.unurled.raxen.listener.player; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class InteractEvent implements Listener { + @EventHandler + public void PlayerInteractEvent(PlayerInteractEvent e) { +// Player p = e.getPlayer(); +// if (e.hasItem()) { +// ItemStack i = e.getItem(); +// } + } +} diff --git a/src/main/java/me/unurled/raxen/listener/player/RespawnEvent.java b/src/main/java/me/unurled/raxen/listener/player/RespawnEvent.java new file mode 100644 index 0000000..78c807e --- /dev/null +++ b/src/main/java/me/unurled/raxen/listener/player/RespawnEvent.java @@ -0,0 +1,21 @@ +package me.unurled.raxen.listener.player; + +import me.unurled.raxen.Raxen; +import me.unurled.raxen.manager.entity.PlayerManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerRespawnEvent; + +import static me.unurled.raxen.utils.Utils.msgPlayer; + +public class RespawnEvent implements Listener { + @EventHandler + public void PlayerRespawnEvent(PlayerRespawnEvent e) { + Player p = e.getPlayer(); + PlayerManager pm = ((Raxen) Bukkit.getPluginManager().getPlugin("Raxen")).getManager().getPlayerManager(); + pm.getHealth().set(p, pm.getMaxHealth().get(p)); + msgPlayer(p, "You have been killed. You lost something deep in you..."); + } +} diff --git a/src/main/java/me/unurled/raxen/manager/entity/PlayerManager.java b/src/main/java/me/unurled/raxen/manager/entity/PlayerManager.java index d082906..d792d8a 100644 --- a/src/main/java/me/unurled/raxen/manager/entity/PlayerManager.java +++ b/src/main/java/me/unurled/raxen/manager/entity/PlayerManager.java @@ -15,6 +15,8 @@ import org.bukkit.scheduler.BukkitTask; import java.util.HashMap; import java.util.UUID; +import static me.unurled.raxen.utils.Utils.*; + public class PlayerManager { private Raxen main; @@ -61,9 +63,11 @@ public class PlayerManager { BukkitTask task = new BukkitRunnable() { @Override public void run() { - player.sendActionBar(Component.text(pm.getHealth().get(player) + "/" + pm.getMaxHealth().get(player) + "❤ " + pm.getMana().get(player) + "/" + pm.getMaxMana().get(player))); + player.sendActionBar(colorComp("" + pm.getHealth().get(player) + "/" + + pm.getMaxHealth().get(player) + "❤ " + pm.getMana().get(player) + "/" + + pm.getMaxMana().get(player) + "")); } - }.runTaskTimer(main, 0L, 20L); + }.runTaskTimerAsynchronously(main, 10, 20); if(actionBar.containsKey(player.getUniqueId())) { actionBar.replace(player.getUniqueId(), task); } else { @@ -80,6 +84,8 @@ public class PlayerManager { BukkitTask task = actionBar.get(player.getUniqueId()); task.cancel(); actionBar.remove(player.getUniqueId()); + } else { + debug(colorTextComp("Player " + player.getName() + " didn't have any Action Bar" + player.getUniqueId().toString() + "")); } } diff --git a/src/main/java/me/unurled/raxen/manager/server/CommandManager.java b/src/main/java/me/unurled/raxen/manager/server/CommandManager.java index 43cca01..d58b9c9 100644 --- a/src/main/java/me/unurled/raxen/manager/server/CommandManager.java +++ b/src/main/java/me/unurled/raxen/manager/server/CommandManager.java @@ -22,20 +22,24 @@ public class CommandManager { private SkillsCommand skillsCommand; private RaxenCommand raxenCommand; private SpawnEntity entityspawn; + private EntitiyCommand entitiyCommand; private ClassCommand classCommand; private CustomModelDataCommand customModelDataCommand; private MainGuiCommand mainGuiCommand; + private ItemTo64Command itemTo64Command; public CommandManager(Raxen main) { this.main = main; this.itemListCommand = new ItemListCommand(this.main); this.nbtCommand = new NbtCommand(this.main); this.entityspawn = new SpawnEntity(this.main); + this.entitiyCommand = new EntitiyCommand(); this.classCommand = new ClassCommand(this.main); - this.skillsCommand = new SkillsCommand(main); - this.raxenCommand = new RaxenCommand(main); + this.skillsCommand = new SkillsCommand(this.main); + this.raxenCommand = new RaxenCommand(this.main); this.customModelDataCommand = new CustomModelDataCommand(); - this.mainGuiCommand = new MainGuiCommand(main); + this.mainGuiCommand = new MainGuiCommand(this.main); + this.itemTo64Command = new ItemTo64Command(); } /** @@ -75,6 +79,8 @@ public class CommandManager { main.getCommand("main_gui").setTabCompleter(mainGuiCommand); main.getCommand("main_gui").setExecutor(mainGuiCommand); - } + main.getCommand("itemto64").setTabCompleter(itemTo64Command); + main.getCommand("itemto64").setExecutor(itemTo64Command); + } } diff --git a/src/main/java/me/unurled/raxen/manager/server/ResourcePackManager.java b/src/main/java/me/unurled/raxen/manager/server/ResourcePackManager.java index 169f190..2e9b497 100644 --- a/src/main/java/me/unurled/raxen/manager/server/ResourcePackManager.java +++ b/src/main/java/me/unurled/raxen/manager/server/ResourcePackManager.java @@ -28,7 +28,7 @@ public class ResourcePackManager { } /** - * Method to enable the ressourcpack + * Method to enable the ressourcepack */ private void enable() { if(useRP) { diff --git a/src/main/java/me/unurled/raxen/utils/Items.java b/src/main/java/me/unurled/raxen/utils/Items.java index 753bb19..5220c22 100644 --- a/src/main/java/me/unurled/raxen/utils/Items.java +++ b/src/main/java/me/unurled/raxen/utils/Items.java @@ -393,7 +393,7 @@ public class Items { * @return a string * @throws IllegalStateException stream errors */ - private static @NotNull String itemTo64(ItemStack stack) throws IllegalStateException { + public static @NotNull String itemTo64(ItemStack stack) throws IllegalStateException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); @@ -414,7 +414,10 @@ public class Items { * @return itemstack * @throws IOException stream error */ - private static ItemStack itemFrom64(String data) throws IOException { + public static ItemStack itemFrom64(String data) throws IOException { + if (data != null) { + return new ItemStack(Material.AIR); + } try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); diff --git a/src/main/java/me/unurled/raxen/utils/Utils.java b/src/main/java/me/unurled/raxen/utils/Utils.java index e2492dd..cc95da3 100644 --- a/src/main/java/me/unurled/raxen/utils/Utils.java +++ b/src/main/java/me/unurled/raxen/utils/Utils.java @@ -112,7 +112,7 @@ public class Utils { /** * Strips all color from a string. - * @param string the string that want's to be decolored. + * @param string the string that wants to be decolored. * @return a decolored string */ public static String decolor(String string) { @@ -163,6 +163,21 @@ public class Utils { } } + /** + * debug output to console if debug is set to true in config + * @param comps output to console + */ + public static void debug(TextComponent... comps) { + Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen"); + assert main != null; + FileConfiguration config = main.getConfig(); + if(config.getBoolean("debug")) { + for(TextComponent comp : comps) { + main.getLogger().info(textCompToString(comp)); + } + } + } + /** * Log the strings to the console * @param main a main instance running @@ -366,4 +381,62 @@ public class Utils { } return true; } + + /** + * get a string from args which contains "" + * @param args a string list + * @return a string + */ + public static String getStringFromArg(String[] args) { + String result = ""; + boolean getFColon = false; + boolean getLColon = false; + for (String arg : args) { + if (arg.contains("\"")) { + if (!getFColon) { + getFColon = true; + } else if (getFColon && !getLColon) { + result += arg.replace("\"", ""); + return result; + } else if (getFColon) { + result += arg.replace("\"", ""); + } + } + } + return result; + } + + /** + * search if there is an args that is null or do not exist + * @param args a list of string + * @param n a number of entries a list should have + * @return a boolean if true or not + */ + public static Boolean validateArgs(String[] args, Integer n) { + for (int i = 0; i < n ; i++) { + if (args.length < n-1) { + return false; + } else if (args[i] == null) { + return false; + } + } + return true; + } + + /** + * changes every "null" in list to the object null + * @param args a list of strings + * @return return a new list + */ + public static String[] setNullInArgs(String[] args) { + String[] newList = new String[args.length]; + for (int i = 0 ; i < args.length ; i++) { + if (args[i].equalsIgnoreCase("null")) { + newList[i] = null; + } else { + newList[i] = args[i]; + } + } + return newList; + } } diff --git a/src/main/java/me/unurled/raxen/utils/libs/MongoDB.java b/src/main/java/me/unurled/raxen/utils/libs/MongoDB.java index bd75b75..d01826a 100644 --- a/src/main/java/me/unurled/raxen/utils/libs/MongoDB.java +++ b/src/main/java/me/unurled/raxen/utils/libs/MongoDB.java @@ -1,6 +1,7 @@ package me.unurled.raxen.utils.libs; import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; @@ -12,8 +13,7 @@ import org.bukkit.configuration.file.FileConfiguration; import java.util.Objects; -import static me.unurled.raxen.utils.Utils.colorComp; -import static me.unurled.raxen.utils.Utils.log; +import static me.unurled.raxen.utils.Utils.*; public class MongoDB { @Getter @@ -29,7 +29,7 @@ public class MongoDB { FileConfiguration config = Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Raxen")).getConfig(); String uri = (String) config.get("url"); assert uri != null; - log("URI" + uri); + debug("URI " + uri); ConnectionString connectionString = new ConnectionString(uri); mongoClient = MongoClients.create(connectionString); mongoDatabase = mongoClient.getDatabase("Raxen"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 703e2f5..cecaf1c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: me.unurled.raxen.Raxen author: unurled api-version: 1.19 depend: [ProtocolLib, PlaceholderAPI, 'Multiverse-Core'] -softdepend: [AureliumSkills, LuckPerms] +softdepend: [LuckPerms, Essentials] commands: reloadplugin: @@ -29,6 +29,8 @@ commands: description: Open ItemList menu entityspawn: description: Spawn an custom entity + entity: + description: Spawn an custom entity class: description: player command that make them choose their class and then their stats custommodeldata: @@ -38,6 +40,8 @@ commands: description: set custom model data to item main_gui: description: not very much used, more with right click on device + itemto64: + description: transform an item to it's 64encoded byte permissions: raxen.reload.cmd: @@ -52,9 +56,13 @@ permissions: description: itemlist command permission raxen.entityspawn.cmd: description: entityspawn command permission + raxen.entity.cmd: + description: entity command permission raxen.class.cmd: description: class command permission raxen.custommodeldata.cmd: description: custom model data command permission raxen.maingui.cmd: - description: main gui command permission \ No newline at end of file + description: main gui command permission + raxen.itemto64.cmd: + description: item to 64 command permission