0.4.2: rewrite of the Skill system of player, refactored to be Attributes
started some work on Entity => need some time on it. that's all :)
This commit is contained in:
parent
d943dfadaa
commit
22000e12ca
28 changed files with 780 additions and 264 deletions
5
pom.xml
5
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>gq.unurled</groupId>
|
||||
<artifactId>raxen</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<version>0.4.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Raxen</name>
|
||||
|
@ -32,6 +32,7 @@
|
|||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -126,13 +127,13 @@
|
|||
<version>2.9.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>nbt-injector</artifactId>
|
||||
<version>2.9.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.github.simplix-softworks</groupId>
|
||||
<artifactId>SimplixStorage</artifactId>
|
||||
|
|
|
@ -20,7 +20,7 @@ public final class Raxen extends JavaPlugin {
|
|||
|
||||
private static final String prefix = ChatColor.AQUA + "Rx" + ChatColor.LIGHT_PURPLE + "> ";
|
||||
@Getter
|
||||
private static final String version = "0.0.4";
|
||||
private static final String version = "0.4.2";
|
||||
private final PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
@Getter
|
||||
|
@ -99,6 +99,8 @@ public final class Raxen extends JavaPlugin {
|
|||
public void onDisable() {
|
||||
Reload.kickAll();
|
||||
|
||||
playerConfig.close();
|
||||
|
||||
getServer().getConsoleSender().sendMessage(Component.text(prefix +"§cServer Stopped Successfully!"));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package gq.unurled.raxen.commands;
|
|||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.manager.StorageManager;
|
||||
import gq.unurled.raxen.utils.Utils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
@ -14,8 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static gq.unurled.raxen.utils.Utils.color;
|
||||
import static gq.unurled.raxen.utils.Utils.msgPlayer;
|
||||
import static gq.unurled.raxen.utils.Utils.*;
|
||||
|
||||
public class RaxenCommand implements TabExecutor {
|
||||
|
||||
|
@ -33,33 +33,33 @@ public class RaxenCommand implements TabExecutor {
|
|||
msgPlayer(player, Raxen.getPrefix() + color("&cYou can't execute this command. Insufficient permission."));
|
||||
}
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
msgPl(player, 0);
|
||||
case 1:
|
||||
case 0 -> msgPl(player, 0);
|
||||
case 1 -> {
|
||||
switch (args[0]) {
|
||||
case "mongodb":
|
||||
case "mongo":
|
||||
case "MONGODB":
|
||||
case "MONGO":
|
||||
case "mongodb", "mongo", "MONGODB", "MONGO" -> {
|
||||
//print info about connection
|
||||
msgPlayer(player, Raxen.getPrefix() + color("&6--------------------------------"),color("&cMONGO DB"));
|
||||
sender.sendMessage(Raxen.getPrefix() + color("&6Printing About Raxen's MongoDB connection..."));
|
||||
msgPlayer(player, Raxen.getPrefix() + color("&6---------------------------------------------"),
|
||||
color("&cMONGO DB"));
|
||||
msgPlayer(player, StorageManager.getMongo().getMongoClient().getClusterDescription().toString());
|
||||
msgPlayer(player, StorageManager.getMongo().getMongoDatabase().getName());
|
||||
msgPlayer(player, StorageManager.getMongo().getMongoCollection().getNamespace().toString());
|
||||
case "v":
|
||||
case "version":
|
||||
case "ver":
|
||||
msgPlayer(player, color("&6---------------------------------------------"));
|
||||
}
|
||||
case "v", "version", "ver" -> {
|
||||
msgPl(player, 0);
|
||||
case "hemlp":
|
||||
case "?":
|
||||
case "h":
|
||||
}
|
||||
case "hemlp", "?", "h" -> {
|
||||
//print help
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(String.valueOf(args.length));
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
case 0 -> {
|
||||
sender.sendMessage(Raxen.getPrefix() + color("&6Printing About Raxen..."),
|
||||
color("&6---------------------------------------------"),
|
||||
color("&3 Raxen "),
|
||||
|
@ -67,32 +67,37 @@ public class RaxenCommand implements TabExecutor {
|
|||
color("&3 - Author: &l&cU&6n&eu&2r&al&be&3d&r"));
|
||||
TextComponent txt = Component.text(color("&3 - Website: https://unurled.gq"));
|
||||
sender.sendMessage(txt);
|
||||
case 1:
|
||||
sender.sendMessage(color("&6---------------------------------------------"));
|
||||
return true;
|
||||
}
|
||||
case 1 -> {
|
||||
log("hello");
|
||||
switch (args[0]) {
|
||||
case "mongodb":
|
||||
case "mongo":
|
||||
case "MONGODB":
|
||||
case "MONGO":
|
||||
case "mongodb", "mongo", "MONGODB", "MONGO" -> {
|
||||
//print info about connection
|
||||
sender.sendMessage( Raxen.getPrefix() + color("&6--------------------------------"),color("&cMONGO DB"));
|
||||
sender.sendMessage(Raxen.getPrefix() + color("&6Printing About Raxen's MongoDB connection..."));
|
||||
sender.sendMessage(color("&6---------------------------------------------"), color("&cMONGO DB"));
|
||||
sender.sendMessage(StorageManager.getMongo().getMongoClient().getClusterDescription().toString());
|
||||
sender.sendMessage(StorageManager.getMongo().getMongoDatabase().getName());
|
||||
sender.sendMessage(StorageManager.getMongo().getMongoCollection().getNamespace().toString());
|
||||
case "v":
|
||||
case "version":
|
||||
case "ver":
|
||||
sender.sendMessage(color("&6---------------------------------------------"));
|
||||
return true;
|
||||
}
|
||||
case "v", "version", "ver" -> {
|
||||
sender.sendMessage(Raxen.getPrefix() + color("&6Printing About Raxen..."),
|
||||
color("&6---------------------------------------------"),
|
||||
color("&3 Raxen "),
|
||||
color("&3 - Version: " + Raxen.getVersion()),
|
||||
color("&3 - Author: &l&cU&6n&eu&2r&al&be&3d&r"));
|
||||
txt = Component.text(color("&3 - Website: https://unurled.gq"));
|
||||
TextComponent txt= Component.text(color("&3 - Website: https://unurled.gq"));
|
||||
sender.sendMessage(txt);
|
||||
sender.sendMessage(color("&6---------------------------------------------"));
|
||||
case "hemlp":
|
||||
case "?":
|
||||
case "h":
|
||||
return true;
|
||||
}
|
||||
case "hemlp", "?", "h" ->
|
||||
//print help
|
||||
log("why tf?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,8 +111,7 @@ public class RaxenCommand implements TabExecutor {
|
|||
color("&6---------------------------------------------"),
|
||||
color("&3 Raxen "),
|
||||
color("&3 - Version: " + Raxen.getVersion()),
|
||||
color("&3 - Author: &l&cU&6n&eu&2r&al&be&3d&r"),
|
||||
color("&3 - Website: https://unurled.gq"));
|
||||
color("&3 - Author: &l&cU&6n&eu&2r&al&be&3d&r"));
|
||||
TextComponent txt = Component.text(color("&3 - Website: https://unurled.gq"))
|
||||
.clickEvent(ClickEvent.openUrl("https://unurled.gq"));
|
||||
player.sendMessage(txt);
|
||||
|
|
|
@ -2,7 +2,7 @@ package gq.unurled.raxen.commands.admin;
|
|||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.command.TabExecutor;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -24,9 +25,11 @@ import static gq.unurled.raxen.utils.Utils.*;
|
|||
|
||||
public class NbtCommand implements TabExecutor {
|
||||
|
||||
private Raxen main;
|
||||
private ProfileManager profileManager;
|
||||
|
||||
public NbtCommand(Raxen main) {
|
||||
this.main = main;
|
||||
this.profileManager = main.getProfileManager();
|
||||
}
|
||||
|
||||
|
@ -78,23 +81,23 @@ public class NbtCommand implements TabExecutor {
|
|||
}
|
||||
itm.lore(lore);
|
||||
it.setItemMeta(itm);
|
||||
Skills skills = profileManager.getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
Attributes attributes = new Attributes(main);
|
||||
nbti.setInteger(args[0], Integer.parseInt(args[1]) + a);
|
||||
if(nbti.hasKey("SPEED")) {
|
||||
skills.addSpeed(nbti.getInteger("SPEED"));
|
||||
attributes.addSpeed(player, nbti.getInteger("SPEED"));
|
||||
}
|
||||
if(nbti.hasKey("HEALTH")) {
|
||||
skills.addHealth(nbti.getInteger("HEALTH"));
|
||||
attributes.addHealth(player, nbti.getInteger("HEALTH"));
|
||||
}
|
||||
if(nbti.hasKey("DEFENSE")) {
|
||||
skills.addDefense(nbti.getInteger("DEFENSE"));
|
||||
attributes.addDefense(player, nbti.getInteger("DEFENSE"));
|
||||
}
|
||||
if(nbti.hasKey("STRENGTH")) {
|
||||
skills.addStrength(nbti.getInteger("STRENGTH"));
|
||||
attributes.addStrength(player, nbti.getInteger("STRENGTH"));
|
||||
}
|
||||
it = nbti.getItem();
|
||||
msgPlayer(player, Raxen.getPrefix() + color("&fYou successfully added the nbt " +attributes(args[0]) + "&fwith " + args[1] + "&f."));
|
||||
updateSkills(player);
|
||||
updateSkills(main, player);
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), it);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package gq.unurled.raxen.commands.admin;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.entity.EntityNamespacedKey;
|
||||
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.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static gq.unurled.raxen.components.entity.Entity.setNameSpacedKeys;
|
||||
import static gq.unurled.raxen.utils.Utils.*;
|
||||
|
||||
public class SpawnEntity implements TabExecutor {
|
||||
|
||||
private Raxen main;
|
||||
private EntityNamespacedKey namespacedKey;
|
||||
|
||||
public SpawnEntity(Raxen main) {
|
||||
this.main = main;
|
||||
this.namespacedKey = new EntityNamespacedKey(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
log("&cConsole can't execute this command!");
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (player.hasPermission("raxen.entityspawn.cmd")) {
|
||||
player.sendMessage(noPerms());
|
||||
return false;
|
||||
}
|
||||
//example command : /entityspawn ZOMBIE "&cHello folks" 50 200
|
||||
EntityType type = EntityType.valueOf(args[0]);
|
||||
Entity e = player.getWorld().spawnEntity(player.getLocation(), type, false);
|
||||
setNameSpacedKeys(e, "&cName", 100, 100,0,50,0,100,0,100,0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package gq.unurled.raxen.commands.player;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -18,8 +18,10 @@ import static gq.unurled.raxen.utils.Utils.*;
|
|||
public class SkillsCommand implements TabExecutor {
|
||||
|
||||
private ProfileManager profileManager;
|
||||
private Raxen main;
|
||||
|
||||
public SkillsCommand(Raxen main) {
|
||||
this.main = main;
|
||||
this.profileManager = main.getProfileManager();
|
||||
}
|
||||
|
||||
|
@ -30,7 +32,7 @@ public class SkillsCommand implements TabExecutor {
|
|||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Skills skills = profileManager.getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
Attributes attributes = new Attributes(main);
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
//open gui
|
||||
|
@ -45,64 +47,64 @@ public class SkillsCommand implements TabExecutor {
|
|||
switch (args[0]) {
|
||||
case "health":
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
skills.setHealth(skills.getHealth() + Integer.parseInt(args[2]));
|
||||
attributes.setHealth(player, attributes.getHealth(player) + Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were added " + args[2] + " health more!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("set")) {
|
||||
skills.setHealth(Integer.parseInt(args[2]));
|
||||
attributes.setHealth(player, Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You are set " + args[2] + " health!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("remove")) {
|
||||
skills.setHealth(skills.getHealth() - Integer.parseInt(args[2]));
|
||||
attributes.setHealth(player ,attributes.getHealth(player) - Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were removeded " + args[2] + " health less!");
|
||||
|
||||
}
|
||||
break;
|
||||
case "defense":
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
skills.setDefense(skills.getDefense() + Integer.parseInt(args[2]));
|
||||
attributes.setDefense(player, attributes.getDefense(player) + Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were added " + args[2] + " defense more!");
|
||||
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("set")) {
|
||||
skills.setDefense(Integer.parseInt(args[2]));
|
||||
attributes.setDefense(player, Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You are set " + args[2] + " defense!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("remove")) {
|
||||
skills.setDefense(skills.getDefense() - Integer.parseInt(args[2]));
|
||||
attributes.setDefense(player, attributes.getDefense(player) - Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were removed " + args[2] + " defense less!");
|
||||
}
|
||||
break;
|
||||
case "speed":
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
skills.setSpeed(skills.getSpeed() + Integer.parseInt(args[2]));
|
||||
attributes.setSpeed(player, attributes.getSpeed(player) + Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were added " + args[2] + " speed more!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("set")) {
|
||||
skills.setSpeed(Integer.parseInt(args[2]));
|
||||
attributes.setSpeed(player, Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You are set " + args[2] + " speed!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("remove")) {
|
||||
skills.setSpeed(skills.getSpeed() - Integer.parseInt(args[2]));
|
||||
attributes.setSpeed(player, attributes.getSpeed(player) - Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were removed " + args[2] + " speed less!");
|
||||
}
|
||||
break;
|
||||
case "stregnth":
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
skills.setStrength(skills.getStrength() + Integer.parseInt(args[2]));
|
||||
attributes.setStrength(player, attributes.getStrength(player) + Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were added " + args[2] + " strength more!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("set")) {
|
||||
skills.setStrength(Integer.parseInt(args[2]));
|
||||
attributes.setStrength(player, Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You are set " + args[2] + " strength!");
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("remove")) {
|
||||
skills.setStrength(skills.getStrength() - Integer.parseInt(args[2]));
|
||||
attributes.setStrength(player, attributes.getStrength(player) - Integer.parseInt(args[2]));
|
||||
msgPlayer(player,"You were removed " + args[2] + " strength less!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(player);
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(main, player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
178
src/main/java/gq/unurled/raxen/components/entity/Attributes.java
Normal file
178
src/main/java/gq/unurled/raxen/components/entity/Attributes.java
Normal file
|
@ -0,0 +1,178 @@
|
|||
package gq.unurled.raxen.components.entity;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attribute;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class Attributes {
|
||||
|
||||
private static EntityNamespacedKey namespacedKey;
|
||||
|
||||
public Attributes(Raxen main) {
|
||||
namespacedKey = new EntityNamespacedKey(main);
|
||||
}
|
||||
|
||||
public static Attribute getAttribute(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
health = data.get(namespacedKey.healthKey, PersistentDataType.INTEGER);
|
||||
itemHealth = data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER);
|
||||
defense = data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER);
|
||||
itemDefense = data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER);
|
||||
speed = data.get(namespacedKey.speedKey, PersistentDataType.INTEGER);
|
||||
itemSpeed = data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER);
|
||||
strength = data.get(namespacedKey.strengthKey , PersistentDataType.INTEGER);
|
||||
itemDmg = data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER);
|
||||
return new Attribute(health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg);
|
||||
}
|
||||
|
||||
public static void setAttributes(Entity e, int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemDmg) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, health);
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, itemHealth);
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, defense);
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, itemDefense);
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, speed);
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, itemSpeed);
|
||||
data.set(namespacedKey.strengthKey , PersistentDataType.INTEGER, strength);
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, itemDmg);
|
||||
}
|
||||
|
||||
public void removeSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, data.get(namespacedKey.speedKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, data.get(namespacedKey.healthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
|
||||
public void removeItemSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
|
||||
public void addSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, data.get(namespacedKey.speedKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, data.get(namespacedKey.healthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
|
||||
public void addItemSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
|
||||
public Integer getSpeed(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.speedKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getStrength(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getHealth(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.healthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getDefense(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public Integer getItemSpeed(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemStrength(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemHealth(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemDefense(Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public void setHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
|
||||
public void setItemHealth(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemDefense(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemSpeed(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemStrength(Entity e, int i) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
}
|
68
src/main/java/gq/unurled/raxen/components/entity/Entity.java
Normal file
68
src/main/java/gq/unurled/raxen/components/entity/Entity.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package gq.unurled.raxen.components.entity;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attribute;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import static gq.unurled.raxen.utils.Utils.log;
|
||||
import static gq.unurled.raxen.utils.Utils.msgPlayer;
|
||||
|
||||
public class Entity {
|
||||
|
||||
private static Raxen main;
|
||||
private static EntityNamespacedKey namespacedKey;
|
||||
|
||||
public Entity(Raxen main) {
|
||||
main = main;
|
||||
namespacedKey = new EntityNamespacedKey(main);
|
||||
}
|
||||
|
||||
public static void setNameSpacedKeys(org.bukkit.entity.Entity e, String name, Integer level, int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemDmg) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, health);
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, itemHealth);
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, speed);
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, itemSpeed);
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, defense);
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, defense);
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, strength);
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, itemDmg);
|
||||
data.set(namespacedKey.nameKey, PersistentDataType.STRING, name);
|
||||
data.set(namespacedKey.levelKey, PersistentDataType.INTEGER, level);
|
||||
}
|
||||
|
||||
public static Attribute getattributesEntity(org.bukkit.entity.Entity e) {
|
||||
PersistentDataContainer data = e.getPersistentDataContainer();
|
||||
int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
health = data.get(namespacedKey.healthKey, PersistentDataType.INTEGER);
|
||||
itemHealth = data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER);
|
||||
defense = data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER);
|
||||
itemDefense = data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER);
|
||||
speed = data.get(namespacedKey.speedKey, PersistentDataType.INTEGER);
|
||||
itemSpeed = data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER);
|
||||
strength = data.get(namespacedKey.strengthKey , PersistentDataType.INTEGER);
|
||||
itemDmg = data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER);
|
||||
return new Attribute(health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg);
|
||||
}
|
||||
|
||||
public static void updateSkills(LivingEntity livingEntity) {
|
||||
Attributes attributes = new Attributes(main);
|
||||
int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
org.bukkit.entity.Entity e = livingEntity;
|
||||
health = attributes.getHealth(e);
|
||||
itemHealth = attributes.getItemHealth(e);
|
||||
defense = attributes.getDefense(e);
|
||||
itemDefense = attributes.getItemDefense(e);
|
||||
speed = attributes.getSpeed(e);
|
||||
itemSpeed = attributes.getItemSpeed(e);
|
||||
strength = attributes.getStrength(e);
|
||||
itemDmg = attributes.getItemStrength(e);
|
||||
livingEntity.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH).setBaseValue(20D + (health + itemHealth) / 100);
|
||||
livingEntity.getAttribute(org.bukkit.attribute.Attribute.GENERIC_FLYING_SPEED).setBaseValue((float) (0.0 + ((speed + itemSpeed) / 100) * 0.2));
|
||||
livingEntity.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue((float) (0.0 + ((speed + itemSpeed) / 100) * 0.2));
|
||||
log("Speed " + (speed + itemSpeed), "Health " + (health + itemHealth), "Defense " + (defense+itemDefense), "Strength " + (strength+itemDmg));
|
||||
}
|
||||
|
||||
}
|
|
@ -5,16 +5,27 @@ import org.bukkit.NamespacedKey;
|
|||
|
||||
public class EntityNamespacedKey {
|
||||
public EntityNamespacedKey(Raxen main) {
|
||||
nameKey = new NamespacedKey(main, "name");
|
||||
levelKey = new NamespacedKey(main, "level");
|
||||
strengthKey = new NamespacedKey(main, "strength");
|
||||
healthKey = new NamespacedKey(main, "health");
|
||||
itemHealthKey = new NamespacedKey(main, "itemHealth");
|
||||
speedKey = new NamespacedKey(main, "speed");
|
||||
itemSpeedKey = new NamespacedKey(main, "itemSpeedKey");
|
||||
defenseKey = new NamespacedKey(main, "defense");
|
||||
itemDefenseKey = new NamespacedKey(main, "itemDefense");
|
||||
strengthKey = new NamespacedKey(main, "strength");
|
||||
itemStrengthKey = new NamespacedKey(main, "itemDmg");
|
||||
}
|
||||
|
||||
public final NamespacedKey nameKey;
|
||||
public final NamespacedKey levelKey;
|
||||
public final NamespacedKey healthKey;
|
||||
public final NamespacedKey itemHealthKey;
|
||||
public final NamespacedKey speedKey;
|
||||
public final NamespacedKey itemSpeedKey;
|
||||
public final NamespacedKey defenseKey;
|
||||
public final NamespacedKey itemDefenseKey;
|
||||
public final NamespacedKey strengthKey;
|
||||
public final NamespacedKey itemStrengthKey;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package gq.unurled.raxen.components.entity.spawn;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class Eggs {
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package gq.unurled.raxen.components.player.Attributes;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class Attribute {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
|
||||
public Attribute(int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemDmg) {
|
||||
this.health = health;
|
||||
this.itemHealth = itemHealth;
|
||||
this.defense = defense;
|
||||
this.itemDefense = itemDefense;
|
||||
this.speed = speed;
|
||||
this.itemSpeed = itemSpeed;
|
||||
this.strength = strength;
|
||||
this.itemDmg = itemDmg;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package gq.unurled.raxen.components.player.Attributes;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.entity.EntityNamespacedKey;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class Attributes {
|
||||
|
||||
private static EntityNamespacedKey namespacedKey;
|
||||
|
||||
public Attributes(Raxen main) {
|
||||
namespacedKey = new EntityNamespacedKey(main);
|
||||
}
|
||||
|
||||
public static Attribute getAttribute(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
health = data.get(namespacedKey.healthKey, PersistentDataType.INTEGER);
|
||||
itemHealth = data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER);
|
||||
defense = data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER);
|
||||
itemDefense = data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER);
|
||||
speed = data.get(namespacedKey.speedKey, PersistentDataType.INTEGER);
|
||||
itemSpeed = data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER);
|
||||
strength = data.get(namespacedKey.strengthKey , PersistentDataType.INTEGER);
|
||||
itemDmg = data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER);
|
||||
return new Attribute(health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg);
|
||||
}
|
||||
|
||||
public static void setAttributes(Player player, int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemDmg) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, health);
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, itemHealth);
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, defense);
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, itemDefense);
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, speed);
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, itemSpeed);
|
||||
data.set(namespacedKey.strengthKey , PersistentDataType.INTEGER, strength);
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, itemDmg);
|
||||
}
|
||||
|
||||
public void removeSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, data.get(namespacedKey.speedKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, data.get(namespacedKey.healthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
|
||||
public void removeItemSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
public void removeItemStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER) -i);
|
||||
}
|
||||
|
||||
public void addSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, data.get(namespacedKey.speedKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, data.get(namespacedKey.healthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
|
||||
public void addItemSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
public void addItemStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER) +i);
|
||||
}
|
||||
|
||||
public Integer getSpeed(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.speedKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getStrength(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.strengthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getHealth(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.healthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getDefense(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.defenseKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public Integer getItemSpeed(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemStrength(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemHealth(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemHealthKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
public Integer getItemDefense(Player player) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
return data.get(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public void setHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.healthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.defenseKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.speedKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.strengthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
|
||||
public void setItemHealth(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemHealthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemDefense(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemDefenseKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemSpeed(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemSpeedKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
public void setItemStrength(Player player, int i) {
|
||||
PersistentDataContainer data = player.getPersistentDataContainer();
|
||||
data.set(namespacedKey.itemStrengthKey, PersistentDataType.INTEGER, i);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,20 @@
|
|||
package gq.unurled.raxen.components.player;
|
||||
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
|
||||
public class Profile {
|
||||
|
||||
private Skills skils;
|
||||
private Attributes skils;
|
||||
|
||||
public Profile(Skills skils) {
|
||||
public Profile(Attributes skils) {
|
||||
this.skils = skils;
|
||||
}
|
||||
|
||||
public Skills getSkils() {
|
||||
public Attributes getSkils() {
|
||||
return skils;
|
||||
}
|
||||
|
||||
public void setSkils(Skills skils) {
|
||||
public void setSkils(Attributes skils) {
|
||||
this.skils = skils;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
package gq.unurled.raxen.components.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class Skills {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
|
||||
public Skills(int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemDmg) {
|
||||
this.health = health;
|
||||
this.itemHealth = health;
|
||||
this.defense = defense;
|
||||
this.itemDefense = itemDefense;
|
||||
this.speed = speed;
|
||||
this.itemSpeed = speed;
|
||||
this.strength = strength;
|
||||
this.itemDmg = itemDmg;
|
||||
}
|
||||
|
||||
public void removeSpeed(int i) {
|
||||
this.speed =this.getSpeed() - i;
|
||||
}
|
||||
public void removeHealth(int i) {
|
||||
this.health =this.getHealth() - i;
|
||||
}
|
||||
public void removeDefense(int i) {
|
||||
this.defense =this.getDefense() - i;
|
||||
}
|
||||
public void removeStrength(int i) {
|
||||
this.strength =this.getStrength() - i;
|
||||
}
|
||||
|
||||
public void removeItemSpeed(int i) {
|
||||
this.itemSpeed =this.getItemSpeed() - i;
|
||||
}
|
||||
public void removeItemHealth(int i) {
|
||||
this.itemHealth =this.getItemHealth() - i;
|
||||
}
|
||||
public void removeItemDefense(int i) {
|
||||
this.itemDefense =this.getItemDefense() - i;
|
||||
}
|
||||
public void removeItemStrength(int i) {
|
||||
this.itemDmg =this.getItemDmg() - i;
|
||||
}
|
||||
|
||||
public void addSpeed(int i) {
|
||||
this.speed = this.getSpeed() + i;
|
||||
}
|
||||
public void addHealth(int i) {
|
||||
this.health = this.getHealth() + i;
|
||||
}
|
||||
public void addDefense(int i) {
|
||||
this.defense = this.getDefense() + i;
|
||||
}
|
||||
public void addStrength(int i) {
|
||||
this.strength = this.getStrength() + i;
|
||||
}
|
||||
|
||||
public void addItemSpeed(int i) {
|
||||
this.itemSpeed = this.getItemSpeed() + i;
|
||||
}
|
||||
public void addItemHealth(int i) {
|
||||
this.itemHealth = this.getItemHealth() + i;
|
||||
}
|
||||
public void addItemDefense(int i) {
|
||||
this.itemDefense = this.getItemDefense() + i;
|
||||
}
|
||||
public void addItemStrength(int i) {
|
||||
this.itemDmg = this.getItemDmg() + i;
|
||||
}
|
||||
}
|
|
@ -12,10 +12,10 @@ public class ResourcePack {
|
|||
private FileConfiguration config;
|
||||
private ResourcePackManager resourcePackManager;
|
||||
|
||||
public ResourcePack(Raxen main) {
|
||||
public ResourcePack(Raxen main, ResourcePackManager manager) {
|
||||
this.main = main;
|
||||
this.config = main.getConfig();
|
||||
this.resourcePackManager = main.getResourcePackManager();
|
||||
this.resourcePackManager = manager;
|
||||
}
|
||||
|
||||
public void join(Player player) {
|
||||
|
|
|
@ -2,9 +2,15 @@ package gq.unurled.raxen.config;
|
|||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static gq.unurled.raxen.utils.Utils.log;
|
||||
|
||||
public class Config {
|
||||
private Raxen main;
|
||||
|
@ -27,8 +33,16 @@ public class Config {
|
|||
if (!(configFile.exists())) {
|
||||
main.saveDefaultConfig();
|
||||
}
|
||||
if(!main.getVersion().equalsIgnoreCase((String) config.get("version"))){
|
||||
main.saveDefaultConfig();
|
||||
FileConfiguration conf = new YamlConfiguration();
|
||||
log(config.getString("version"));
|
||||
try {
|
||||
conf.load(configFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log(conf.getString("version"));
|
||||
if(!Raxen.getVersion().equals(config.getString("version"))){
|
||||
main.saveResource("config.yml", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ package gq.unurled.raxen.config;
|
|||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attribute;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.components.player.Inventories;
|
||||
import gq.unurled.raxen.components.player.Profile;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Storage;
|
||||
import gq.unurled.raxen.components.player.Storages.EnderChest;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
|
@ -38,25 +38,28 @@ public class PlayerConfig {
|
|||
private static StorageManager sto;
|
||||
|
||||
public PlayerConfig(Raxen main) {
|
||||
this.main = main;
|
||||
this.sto = main.getStorageManager();
|
||||
this.mongoDB = sto.getMongo();
|
||||
this.mongoDB.connect();
|
||||
PlayerConfig.main = main;
|
||||
sto = Raxen.getStorageManager();
|
||||
this.mongoDB = StorageManager.getMongo();
|
||||
this.mongoCollection = mongoDB.getMongoCollection();
|
||||
this.profileManager = main.getProfileManager();
|
||||
profileManager = Raxen.getProfileManager();
|
||||
}
|
||||
|
||||
public void saveUsingMongoDB(Player player, Skills skills, String invstr, Integer reverse) {
|
||||
public void close() {
|
||||
mongoDB.close();
|
||||
}
|
||||
|
||||
public void saveUsingMongoDB(Player player, Attributes attributes, String invstr, Integer reverse) {
|
||||
Document doc = new Document("uuid", player.getUniqueId().toString())
|
||||
.append("name", player.getName())
|
||||
.append("health", skills.getHealth())
|
||||
.append("itemHealth", skills.getItemHealth())
|
||||
.append("defense", skills.getDefense())
|
||||
.append("itemDefense", skills.getItemDefense())
|
||||
.append("speed", skills.getSpeed())
|
||||
.append("itemSpeed", skills.getItemSpeed())
|
||||
.append("strength", skills.getStrength())
|
||||
.append("itemDmg", skills.getItemDmg())
|
||||
.append("health", attributes.getHealth(player))
|
||||
.append("itemHealth", attributes.getItemHealth(player))
|
||||
.append("defense", attributes.getDefense(player))
|
||||
.append("itemDefense", attributes.getItemDefense(player))
|
||||
.append("speed", attributes.getSpeed(player))
|
||||
.append("itemSpeed", attributes.getItemSpeed(player))
|
||||
.append("strength", attributes.getStrength(player))
|
||||
.append("itemDmg", attributes.getItemStrength(player))
|
||||
.append("inv", invstr);
|
||||
if (profileManager.getPlayerStorage(player.getUniqueId()) != null) {
|
||||
if(profileManager.getPlayerStorage(player.getUniqueId()).getEc() != null) {
|
||||
|
@ -77,23 +80,25 @@ public class PlayerConfig {
|
|||
Document playerDoc = mongoCollection.find(Filters.eq("uuid", player.getUniqueId().toString())).first();
|
||||
if(playerDoc == null) {
|
||||
mongoCollection.insertOne(doc);
|
||||
log("insert one");
|
||||
}
|
||||
else {
|
||||
mongoCollection.replaceOne(Filters.eq("uuid", player.getUniqueId().toString()), doc);
|
||||
log("replace one");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveUsingYml(Player player, Skills skills, String invstr, Integer reverse) {
|
||||
public void saveUsingYml(Player player, Attributes attributes, String invstr, Integer reverse) {
|
||||
FileConfiguration config = sto.createYml(player);
|
||||
config.set("name", player.getName());
|
||||
config.set("health", skills.getHealth());
|
||||
config.set("itemHealth", skills.getItemHealth());
|
||||
config.set("strength", skills.getStrength());
|
||||
config.set("itemDmg", skills.getItemDmg());
|
||||
config.set("speed", skills.getSpeed());
|
||||
config.set("itemSpeed", skills.getItemSpeed());
|
||||
config.set("defense", skills.getDefense());
|
||||
config.set("itemDefense", skills.getItemDefense());
|
||||
config.set("health", attributes.getHealth(player));
|
||||
config.set("itemHealth", attributes.getItemHealth(player));
|
||||
config.set("strength", attributes.getStrength(player));
|
||||
config.set("itemDmg", attributes.getItemStrength(player));
|
||||
config.set("speed", attributes.getSpeed(player));
|
||||
config.set("itemSpeed", attributes.getItemSpeed(player));
|
||||
config.set("defense", attributes.getDefense(player));
|
||||
config.set("itemDefense", attributes.getItemDefense(player));
|
||||
config.set("inv", invstr);
|
||||
if (profileManager.getPlayerStorage(player.getUniqueId()) != null) {
|
||||
if(profileManager.getPlayerStorage(player.getUniqueId()).getEc() != null) {
|
||||
|
@ -121,15 +126,16 @@ public class PlayerConfig {
|
|||
public void loadUsingMongoDB(Player player) {
|
||||
Document playerDoc = mongoCollection.find(Filters.eq("uuid", player.getUniqueId().toString())).first();
|
||||
if(playerDoc == null) {
|
||||
log("something went wrong");
|
||||
profileManager.createNewProfile(player);
|
||||
profileManager.createNewStorage(player);
|
||||
profileManager.createNewInventory(player);
|
||||
return;
|
||||
}
|
||||
Skills skills = new Skills(playerDoc.getInteger("health"), playerDoc.getInteger("itemHealth"), playerDoc.getInteger("defense"), playerDoc.getInteger("itemDefense"), playerDoc.getInteger("speed"), playerDoc.getInteger("itemSpeed"), playerDoc.getInteger("strength"), playerDoc.getInteger("itemDmg"));
|
||||
Profile profile = new Profile(skills);
|
||||
Attributes.setAttributes(player, playerDoc.getInteger("health"), playerDoc.getInteger("itemHealth"), playerDoc.getInteger("defense"),
|
||||
playerDoc.getInteger("itemDefense"), playerDoc.getInteger("speed"), playerDoc.getInteger("itemSpeed"),
|
||||
playerDoc.getInteger("strength"), playerDoc.getInteger("itemDmg"));
|
||||
|
||||
profileManager.setPlayerProfile(player.getUniqueId(), profile);
|
||||
Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
|
||||
if(playerDoc.getString("ec") != null) {
|
||||
ItemStack[] itList = Items.listItemStackDeserilize(playerDoc.getString("ec"));
|
||||
|
@ -149,12 +155,10 @@ public class PlayerConfig {
|
|||
|
||||
public void loadUsingYml(Player player) throws IOException {
|
||||
FileConfiguration config = sto.createYml(player);
|
||||
Skills skills = new Skills(config.getInt("health"), config.getInt("itemHealth"),
|
||||
Attributes.setAttributes(player, config.getInt("health"), config.getInt("itemHealth"),
|
||||
config.getInt("defense"), config.getInt("itemDefense"),
|
||||
config.getInt("speed"), config.getInt("itemSpeed"),
|
||||
config.getInt("strength"), config.getInt("itemDmg"));
|
||||
Profile profile = new Profile(skills);
|
||||
profileManager.setPlayerProfile(player.getUniqueId(), profile);
|
||||
|
||||
Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
|
||||
if((String) config.get("ec") != null) {
|
||||
|
@ -174,7 +178,7 @@ public class PlayerConfig {
|
|||
}
|
||||
|
||||
public void savePlayerConfig(Player player) {
|
||||
Skills skills = profileManager.getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
Attributes attributes = new Attributes(main);
|
||||
Inventory inv = player.getInventory();
|
||||
List<String> listInv = new ArrayList<String>();
|
||||
Integer reverse = 0;
|
||||
|
@ -186,34 +190,36 @@ public class PlayerConfig {
|
|||
}
|
||||
}
|
||||
String invstr = Items.listItemStackSerelize(listInv);
|
||||
|
||||
|
||||
Object storage = sto.getConfig().get("storage");
|
||||
if (storage == "MONGODB") {
|
||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||
saveUsingMongoDB(player, skills, invstr, reverse);
|
||||
} else if (storage == "MYSQL" || storage == "YML") {
|
||||
saveUsingYml(player, skills, invstr, reverse);
|
||||
log("saving...");
|
||||
String storage = sto.getConfig().getString("storage");
|
||||
saveUsingMongoDB(player, attributes, invstr, reverse);
|
||||
log("using mongo");
|
||||
if (storage == "MYSQL" || storage == "YML") {
|
||||
saveUsingYml(player, attributes, invstr, reverse);
|
||||
log("using yml");
|
||||
}
|
||||
|
||||
log("Player: " + player.getName() + " data successfully saved!");
|
||||
}
|
||||
|
||||
public void loadPlayerConfig(Player player) {
|
||||
String st = (String) StorageManager.getConfig().get("storage");
|
||||
String st = StorageManager.getConfig().getString("storage");
|
||||
String value = "";
|
||||
if (st.equals("MONGODB")) {
|
||||
loadUsingMongoDB(player);
|
||||
value = "mongodb";
|
||||
warn("'" + st + "'");
|
||||
}
|
||||
else {
|
||||
warn("'" + st + "'");
|
||||
value = "yml";
|
||||
try {
|
||||
loadUsingYml(player);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
log("Player: " + player.getName() + " data successfully loaded!");
|
||||
log("Player: " + player.getName() + " data successfully loaded using " + value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package gq.unurled.raxen.listener.entity;
|
|||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.entity.EntityNamespacedKey;
|
||||
import gq.unurled.raxen.components.items.Attributes;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
import gq.unurled.raxen.utils.Items;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
@ -16,6 +15,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import static gq.unurled.raxen.utils.Utils.log;
|
||||
|
||||
public class DamageEntity implements Listener {
|
||||
private Raxen main;
|
||||
private ProfileManager profileManager;
|
||||
|
@ -38,11 +39,12 @@ public class DamageEntity implements Listener {
|
|||
Integer health = 0;
|
||||
Integer itemHealth = 0;
|
||||
Integer initDamage = 0;
|
||||
log(e.getEntity().getName(), e.getEntity().getType().toString(), e.getDamager().getType().toString(), e.getDamager().getName());
|
||||
if (e.getDamager() instanceof Player) {
|
||||
Player playerDamager = (Player) e.getDamager();
|
||||
Skills skills = profileManager.getPlayerProfile(playerDamager.getUniqueId()).getSkils();
|
||||
strength = skills.getStrength();
|
||||
itemDmg = skills.getItemDmg();
|
||||
gq.unurled.raxen.components.player.Attributes.Attributes attributes = new gq.unurled.raxen.components.player.Attributes.Attributes(main);
|
||||
strength = attributes.getStrength(playerDamager);
|
||||
itemDmg = attributes.getItemStrength(playerDamager);
|
||||
} else {
|
||||
Entity entityDamager = e.getDamager();
|
||||
PersistentDataContainer data = entityDamager.getPersistentDataContainer();
|
||||
|
@ -54,11 +56,11 @@ public class DamageEntity implements Listener {
|
|||
}
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player playerVictim = (Player) e.getEntity();
|
||||
Skills skills = profileManager.getPlayerProfile(playerVictim.getUniqueId()).getSkils();
|
||||
defense = skills.getDefense();
|
||||
health = skills.getHealth();
|
||||
itemDefense = skills.getItemDefense();
|
||||
itemHealth = skills.getItemHealth();
|
||||
gq.unurled.raxen.components.player.Attributes.Attributes attributes = new gq.unurled.raxen.components.player.Attributes.Attributes(main);
|
||||
defense = attributes.getDefense(playerVictim);
|
||||
health = attributes.getHealth(playerVictim);
|
||||
itemDefense = attributes.getItemDefense(playerVictim);
|
||||
itemHealth = attributes.getItemHealth(playerVictim);
|
||||
} else {
|
||||
Entity entityVictim = e.getEntity();
|
||||
PersistentDataContainer data = entityVictim.getPersistentDataContainer();
|
||||
|
@ -75,16 +77,22 @@ public class DamageEntity implements Listener {
|
|||
initDamage = (5+ itemDmg) * (1+ (strength/100));
|
||||
damage = initDamage;
|
||||
defense = defense + itemDefense;
|
||||
log(String.valueOf(damage));
|
||||
defense = defense/(defense+100);
|
||||
damage = damage*defense;
|
||||
if (damage >= health) {
|
||||
log(String.valueOf(damage));
|
||||
log(String.valueOf(defense));
|
||||
Integer health_with_defense = health * (1+ (defense/100));
|
||||
log(String.valueOf(damage));
|
||||
log(String.valueOf(health));
|
||||
log(String.valueOf(health_with_defense));
|
||||
if (damage >= health_with_defense) {
|
||||
e.setDamage(e.getEntity().getType().getDefaultAttributes().getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
|
||||
} else {
|
||||
health = health - damage;
|
||||
health = health_with_defense - health - damage;
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player playerVictim = (Player) e.getEntity();
|
||||
Skills skills = profileManager.getPlayerProfile(playerVictim.getUniqueId()).getSkils();
|
||||
skills.setHealth(health);
|
||||
gq.unurled.raxen.components.player.Attributes.Attributes attributes = new gq.unurled.raxen.components.player.Attributes.Attributes(main);
|
||||
attributes.setHealth(playerVictim, health);
|
||||
} else {
|
||||
Entity entityVictim = e.getEntity();
|
||||
PersistentDataContainer data = entityVictim.getPersistentDataContainer();
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package gq.unurled.raxen.listener.entity;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
import static gq.unurled.raxen.components.entity.Entity.updateSkills;
|
||||
import static gq.unurled.raxen.utils.Utils.log;
|
||||
|
||||
public class SpawnEvent implements Listener {
|
||||
@EventHandler
|
||||
public void Spawn(EntitySpawnEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
//player stuff dont want to talk about it;
|
||||
log("Player: " + ((Player) e.getEntity()).getName());
|
||||
} else {
|
||||
log(e.getEntity().getName());
|
||||
updateSkills((LivingEntity) e.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package gq.unurled.raxen.listener.player;
|
|||
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -14,47 +14,49 @@ import org.bukkit.inventory.ItemStack;
|
|||
public class ArmorEvent implements Listener {
|
||||
|
||||
private ProfileManager profileManager;
|
||||
private Raxen main;
|
||||
|
||||
public ArmorEvent(Raxen main) {
|
||||
this.main = main;
|
||||
this.profileManager = main.getProfileManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ArmorChangeEvent(PlayerArmorChangeEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Skills skills = profileManager.getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
Attributes attributes = new Attributes(main);
|
||||
if(e.getOldItem() != null && e.getOldItem().getType() != Material.AIR) {
|
||||
ItemStack oldItem = e.getOldItem();
|
||||
NBTItem nbti = new NBTItem(oldItem);
|
||||
if(nbti.hasKey("SPEED")) {
|
||||
skills.removeSpeed(nbti.getInteger("SPEED"));
|
||||
attributes.removeSpeed(player, nbti.getInteger("SPEED"));
|
||||
}
|
||||
if(nbti.hasKey("HEALTH")) {
|
||||
skills.removeHealth(nbti.getInteger("HEALTH"));
|
||||
attributes.removeHealth(player, nbti.getInteger("HEALTH"));
|
||||
}
|
||||
if(nbti.hasKey("DEFENSE")) {
|
||||
skills.removeDefense(nbti.getInteger("DEFENSE"));
|
||||
attributes.removeDefense(player, nbti.getInteger("DEFENSE"));
|
||||
}
|
||||
if(nbti.hasKey("STRENGTH")) {
|
||||
skills.removeStrength(nbti.getInteger("STRENGTH"));
|
||||
attributes.removeStrength(player, nbti.getInteger("STRENGTH"));
|
||||
}
|
||||
}
|
||||
if(e.getNewItem() != null && e.getNewItem().getType() != Material.AIR) {
|
||||
ItemStack newItem = e.getNewItem();
|
||||
NBTItem nbti = new NBTItem(newItem);
|
||||
if(nbti.hasKey("SPEED")) {
|
||||
skills.addSpeed(nbti.getInteger("SPEED"));
|
||||
attributes.addSpeed(player, nbti.getInteger("SPEED"));
|
||||
}
|
||||
if(nbti.hasKey("HEALTH")) {
|
||||
skills.addHealth(nbti.getInteger("HEALTH"));
|
||||
attributes.addHealth(player, nbti.getInteger("HEALTH"));
|
||||
}
|
||||
if(nbti.hasKey("DEFENSE")) {
|
||||
skills.addDefense(nbti.getInteger("DEFENSE"));
|
||||
attributes.addDefense(player, nbti.getInteger("DEFENSE"));
|
||||
}
|
||||
if(nbti.hasKey("STRENGTH")) {
|
||||
skills.addStrength(nbti.getInteger("STRENGTH"));
|
||||
attributes.addStrength(player, nbti.getInteger("STRENGTH"));
|
||||
}
|
||||
}
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(player);
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(main, player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package gq.unurled.raxen.listener.player;
|
|||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.manager.ProfileManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -14,47 +14,49 @@ import org.bukkit.inventory.ItemStack;
|
|||
public class ItemHandEvent implements Listener {
|
||||
|
||||
private ProfileManager profileManager;
|
||||
private Raxen main;
|
||||
|
||||
public ItemHandEvent(Raxen main) {
|
||||
this.main = main;
|
||||
this.profileManager = main.getProfileManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ItemHeldEvent(PlayerItemHeldEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Skills skills = profileManager.getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
Attributes attributes = new Attributes(main);
|
||||
ItemStack oldItem = player.getInventory().getItem(e.getPreviousSlot());
|
||||
ItemStack newItem = player.getInventory().getItem(e.getNewSlot());
|
||||
if(oldItem != null && oldItem.getType() != Material.AIR) {
|
||||
NBTItem nbti = new NBTItem(oldItem);
|
||||
if(nbti.hasKey("SPEED")) {
|
||||
skills.removeItemSpeed(nbti.getInteger("SPEED"));
|
||||
attributes.removeItemSpeed(player, nbti.getInteger("SPEED"));
|
||||
}
|
||||
if(nbti.hasKey("HEALTH")) {
|
||||
skills.removeItemHealth(nbti.getInteger("HEALTH"));
|
||||
attributes.removeItemHealth(player, nbti.getInteger("HEALTH"));
|
||||
}
|
||||
if(nbti.hasKey("DEFENSE")) {
|
||||
skills.removeItemDefense(nbti.getInteger("DEFENSE"));
|
||||
attributes.removeItemDefense(player, nbti.getInteger("DEFENSE"));
|
||||
}
|
||||
if(nbti.hasKey("STRENGTH")) {
|
||||
skills.removeItemStrength(nbti.getInteger("STRENGTH"));
|
||||
attributes.removeItemStrength(player, nbti.getInteger("STRENGTH"));
|
||||
}
|
||||
}
|
||||
if(newItem != null && newItem.getType() != Material.AIR) {
|
||||
NBTItem nbti = new NBTItem(newItem);
|
||||
if(nbti.hasKey("SPEED")) {
|
||||
skills.addItemSpeed(nbti.getInteger("SPEED"));
|
||||
attributes.addItemSpeed(player, nbti.getInteger("SPEED"));
|
||||
}
|
||||
if(nbti.hasKey("HEALTH")) {
|
||||
skills.addItemHealth(nbti.getInteger("HEALTH"));
|
||||
attributes.addItemHealth(player, nbti.getInteger("HEALTH"));
|
||||
}
|
||||
if(nbti.hasKey("DEFENSE")) {
|
||||
skills.addItemDefense(nbti.getInteger("DEFENSE"));
|
||||
attributes.addItemDefense(player, nbti.getInteger("DEFENSE"));
|
||||
}
|
||||
if(nbti.hasKey("STRENGTH")) {
|
||||
skills.addItemStrength(nbti.getInteger("STRENGTH"));
|
||||
attributes.addItemStrength(player, nbti.getInteger("STRENGTH"));
|
||||
}
|
||||
}
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(player);
|
||||
gq.unurled.raxen.utils.Skills.updateSkills(main, player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package gq.unurled.raxen.manager;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.entity.EntityNamespacedKey;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import gq.unurled.raxen.components.player.Inventories;
|
||||
import gq.unurled.raxen.components.player.Profile;
|
||||
import gq.unurled.raxen.components.player.Skills;
|
||||
import gq.unurled.raxen.components.player.Storage;
|
||||
import gq.unurled.raxen.components.player.Storages.EnderChest;
|
||||
import gq.unurled.raxen.components.player.Storages.Inventory;
|
||||
|
@ -21,33 +21,17 @@ import static gq.unurled.raxen.utils.Utils.log;
|
|||
public class ProfileManager {
|
||||
|
||||
private Raxen main;
|
||||
private Map<UUID, Profile> profiles = new HashMap<>();
|
||||
private EntityNamespacedKey namespacedKey;
|
||||
private Map<UUID, Storage> storages = new HashMap<>();
|
||||
private Map<UUID, Inventories> inventory = new HashMap<>();
|
||||
|
||||
public ProfileManager(Raxen main) {
|
||||
this.main = main;
|
||||
this.namespacedKey = new EntityNamespacedKey(main);
|
||||
}
|
||||
|
||||
public Profile createNewProfile(Player player) {
|
||||
Skills skills = new Skills( 100, 0, 50, 0, 100, 0, 100, 0);
|
||||
Profile profile = new Profile(skills);
|
||||
profiles.put(player.getUniqueId(), profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
public Profile getPlayerProfile(UUID uuid) {
|
||||
return profiles.get(uuid);
|
||||
}
|
||||
|
||||
public void setPlayerProfile(UUID uuid, Profile profile) {
|
||||
if(profiles.get(uuid) == null) {
|
||||
profiles.put(uuid, profile);
|
||||
}
|
||||
else {
|
||||
profiles.replace(uuid, profile);
|
||||
}
|
||||
log("Profile Updated!");
|
||||
public void createNewProfile(Player player) {
|
||||
Attributes.setAttributes(player, 100,0,50,0,100,0,100,0);
|
||||
}
|
||||
|
||||
public Storage createNewStorage(Player player) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ResourcePackManager {
|
|||
|
||||
public ResourcePackManager(Raxen main) {
|
||||
this.main = main;
|
||||
this.resourcePack = new ResourcePack(main);
|
||||
this.resourcePack = new ResourcePack(main, this);
|
||||
this.config = main.getConfig();
|
||||
this.useRP = this.config.getBoolean("useResourcePack");
|
||||
enable();
|
||||
|
|
|
@ -79,9 +79,13 @@ public class StorageManager {
|
|||
customConfig.set("uuid", player.getUniqueId().toString());
|
||||
customConfig.set("name", player.getName());
|
||||
customConfig.set("health", 100);
|
||||
customConfig.set("itemHealth", 0);
|
||||
customConfig.set("defense", 50);
|
||||
customConfig.set("itemDefense", 0);
|
||||
customConfig.set("speed", 100);
|
||||
customConfig.set("itemSpeed", 0);
|
||||
customConfig.set("strength", 100);
|
||||
customConfig.set("itemDmg", 0);
|
||||
customConfig.set("inv","");
|
||||
customConfig.set("ec","");
|
||||
try {
|
||||
|
|
|
@ -274,42 +274,42 @@ public class Items {
|
|||
Integer speed = 0;
|
||||
Integer strength = 0;
|
||||
if (equi != null) {
|
||||
if (equi.getItemInMainHand().getType() != Material.AIR || equi.getItemInMainHand() != null) {
|
||||
if (equi.getItemInMainHand().getType() != Material.AIR && equi.getHelmet() != null) {
|
||||
ItemStack item = equi.getItemInMainHand();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
speed = speed + getSpeed(item);
|
||||
strength = strength + getStrength(item);
|
||||
}
|
||||
if (equi.getHelmet().getType() != Material.AIR || equi.getHelmet() != null) {
|
||||
if (equi.getHelmet().getType() != Material.AIR && equi.getHelmet() != null) {
|
||||
ItemStack item = equi.getHelmet();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
speed = speed + getSpeed(item);
|
||||
strength = strength + getStrength(item);
|
||||
}
|
||||
if (equi.getChestplate().getType() != Material.AIR || equi.getChestplate() != null) {
|
||||
if (equi.getChestplate().getType() != Material.AIR && equi.getChestplate() != null) {
|
||||
ItemStack item = equi.getChestplate();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
speed = speed + getSpeed(item);
|
||||
strength = strength + getStrength(item);
|
||||
}
|
||||
if (equi.getChestplate().getType() != Material.AIR || equi.getChestplate() != null) {
|
||||
if (equi.getChestplate().getType() != Material.AIR && equi.getChestplate() != null) {
|
||||
ItemStack item = equi.getChestplate();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
speed = speed + getSpeed(item);
|
||||
strength = strength + getStrength(item);
|
||||
}
|
||||
if (equi.getLeggings().getType() != Material.AIR || equi.getLeggings() != null) {
|
||||
if (equi.getLeggings().getType() != Material.AIR && equi.getLeggings() != null) {
|
||||
ItemStack item = equi.getLeggings();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
speed = speed + getSpeed(item);
|
||||
strength = strength + getStrength(item);
|
||||
}
|
||||
if (equi.getBoots().getType() != Material.AIR || equi.getBoots() != null) {
|
||||
if (equi.getBoots().getType() != Material.AIR && equi.getBoots() != null) {
|
||||
ItemStack item = equi.getBoots();
|
||||
health = health + getHealth(item);
|
||||
defense = defense + getDefense(item);
|
||||
|
|
|
@ -26,4 +26,10 @@ public class MongoDB {
|
|||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MongoDB connected!");
|
||||
}
|
||||
|
||||
public void close() {
|
||||
mongoClient.close();
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "MongoDB disconnected!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gq.unurled.raxen.utils;
|
||||
|
||||
import gq.unurled.raxen.Raxen;
|
||||
import gq.unurled.raxen.components.player.Attributes.Attributes;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -8,17 +9,17 @@ import static gq.unurled.raxen.utils.Utils.msgPlayer;
|
|||
|
||||
public class Skills {
|
||||
|
||||
public static void updateSkills(Player player) {
|
||||
gq.unurled.raxen.components.player.Skills skills = Raxen.getProfileManager().getPlayerProfile(player.getUniqueId()).getSkils();
|
||||
public static void updateSkills(Raxen main, Player player) {
|
||||
Attributes attributes = new Attributes(main);
|
||||
int health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemDmg;
|
||||
health = skills.getHealth();
|
||||
itemHealth = skills.getItemHealth();
|
||||
defense = skills.getDefense();
|
||||
itemDefense = skills.getItemDefense();
|
||||
speed = skills.getSpeed();
|
||||
itemSpeed = skills.getItemSpeed();
|
||||
strength = skills.getStrength();
|
||||
itemDmg = skills.getItemDmg();
|
||||
health = attributes.getHealth(player);
|
||||
itemHealth = attributes.getItemHealth(player);
|
||||
defense = attributes.getDefense(player);
|
||||
itemDefense = attributes.getItemDefense(player);
|
||||
speed = attributes.getSpeed(player);
|
||||
itemSpeed = attributes.getItemSpeed(player);
|
||||
strength = attributes.getStrength(player);
|
||||
itemDmg = attributes.getItemStrength(player);
|
||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20D + (health + itemHealth) / 100);
|
||||
player.setWalkSpeed((float) (0.0 + ((speed + itemSpeed) / 100) * 0.2));
|
||||
player.setFlySpeed((float) (0.0 + ((speed + itemSpeed) / 100) * 0.2));
|
||||
|
|
|
@ -26,7 +26,8 @@ commands:
|
|||
itemlist:
|
||||
aliases: itl
|
||||
description: Open ItemList menu
|
||||
usage: /itemlist
|
||||
entityspawn:
|
||||
description: Spawn an custom entity
|
||||
|
||||
permissions:
|
||||
raxen.reload.cmd:
|
||||
|
@ -39,3 +40,5 @@ permissions:
|
|||
description: raxen command permssion
|
||||
raxen.itemlist.cmd:
|
||||
description: itemlist command permission
|
||||
raxen.entityspawn.cmd:
|
||||
description: entityspawn command permission
|
Loading…
Reference in a new issue