little of javadocs, need to add them when writing code from now on
This commit is contained in:
unurled 2022-04-14 22:35:27 +02:00
parent 0d910d3baf
commit bf5aa6cff0
26 changed files with 513 additions and 208 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@
.project .project
api/ api/
*.iml *.iml
worlds/
.gradle/ .gradle/
gradle.properties gradle.properties

View file

@ -81,7 +81,7 @@ dependencies {
} }
group = 'gq.unurled' group = 'gq.unurled'
version = '0.4.9' version = '0.5.1'
description = 'Raxen' description = 'Raxen'
java.sourceCompatibility = JavaVersion.VERSION_17 java.sourceCompatibility = JavaVersion.VERSION_17
@ -117,4 +117,10 @@ shadowJar {
processResources { processResources {
expand version: project.version expand version: project.version
} }
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
} }

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -18,8 +18,7 @@ import static gq.unurled.raxen.utils.Utils.colorComp;
public final class Raxen extends JavaPlugin { public final class Raxen extends JavaPlugin {
private static final String prefix = "<aqua>Rx</aqua><light_purple>></light_purple> "; private static final String prefix = "<aqua>Rx</aqua><light_purple>></light_purple> ";
@Getter @Getter private static String version = "0.5.1";
private static String version = "0.4.9";
private final PluginManager pm = getServer().getPluginManager(); private final PluginManager pm = getServer().getPluginManager();
private static Raxen plugin; private static Raxen plugin;
@ -30,12 +29,13 @@ public final class Raxen extends JavaPlugin {
private static PlayerConfig playerConfig; private static PlayerConfig playerConfig;
@Getter @Getter private ProtocolManager protocolManager;
private ProtocolManager protocolManager;
@Getter @Getter private Manager manager;
private Manager manager;
/**
* Method when the server launch the plugin.
*/
@Override @Override
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
@ -60,18 +60,27 @@ public final class Raxen extends JavaPlugin {
manager.getListenerManager().getServerPingEvent().setLoading(false); manager.getListenerManager().getServerPingEvent().setLoading(false);
} }
/**
* register the command in the command manager class.
*/
private void registerCommands() { private void registerCommands() {
manager.getCommandManager().register(); manager.getCommandManager().register();
Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<green>Commands Registered!</green>")); Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<green>Commands Registered!</green>"));
} }
/**
* register the events in the event manager class.
*/
private void registerEvents() { private void registerEvents() {
manager.getListenerManager().register(); manager.getListenerManager().register();
Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<green>Events Registered!</green>")); Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<green>Events Registered!</green>"));
} }
/**
* Method when the server stops the plugin.
*/
@Override @Override
public void onDisable() { public void onDisable() {
manager.getListenerManager().getServerPingEvent().setLoading(true); manager.getListenerManager().getServerPingEvent().setLoading(true);
@ -82,26 +91,50 @@ public final class Raxen extends JavaPlugin {
Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<red>Server Stopped Successfully!</red>")); Bukkit.getConsoleSender().sendMessage(colorComp(prefix +"<red>Server Stopped Successfully!</red>"));
} }
/**
* getter for the logger
* @return the plugin logger
*/
public static Logger getPluginLogger() { public static Logger getPluginLogger() {
return logger; return logger;
} }
/**
* getter for the bukkit's plugin manager
* @return plugin manager
*/
public PluginManager getPm() { public PluginManager getPm() {
return pm; return pm;
} }
/**
* return the instance which is launched.
* @return main instance
*/
public static Raxen getPlugin() { public static Raxen getPlugin() {
return plugin; return plugin;
} }
/**
* getter for the raxen prefix
* @return string prefix
*/
public static String getPrefix() { public static String getPrefix() {
return prefix; return prefix;
} }
/**
* getter for the yml's player configs.
* @return player config instance
*/
public static PlayerConfig getPlayerConfig() { public static PlayerConfig getPlayerConfig() {
return playerConfig; return playerConfig;
} }
/**
* getter for an instance of the config utility class
* @return raxen's config
*/
public static Config getConf() { public static Config getConf() {
return config; return config;
} }

View file

@ -2,7 +2,6 @@ package gq.unurled.raxen.commands.admin;
import de.tr7zw.nbtapi.NBTItem; import de.tr7zw.nbtapi.NBTItem;
import gq.unurled.raxen.Raxen; import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.player.attributes.Attributes;
import gq.unurled.raxen.manager.entity.PlayerManager; import gq.unurled.raxen.manager.entity.PlayerManager;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -10,7 +9,6 @@ import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -19,9 +17,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import static gq.unurled.raxen.components.entity.player.PlayerUtils.updateSkills; import static gq.unurled.raxen.components.entity.player.PlayerUtils.updateSkills;
import static gq.unurled.raxen.utils.Items.attributes;
import static gq.unurled.raxen.utils.Utils.*; import static gq.unurled.raxen.utils.Utils.*;
public class NbtCommand implements TabExecutor { public class NbtCommand implements TabExecutor {
@ -34,14 +32,15 @@ public class NbtCommand implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String msg, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String msg, @NotNull String[] args) {
if(!(sender instanceof Player)) { if(!(sender instanceof Player player)) {
error((Raxen) Bukkit.getPluginManager().getPlugin("Raxen"),colorString("<red>You can't execute this command as the Console!")); error((Raxen) Bukkit.getPluginManager().getPlugin("Raxen"),colorString("<red>You can't execute this command as the Console!"));
return true; return true;
} }
Player player = (Player) sender; if(player.getInventory().getItemInMainHand().getType() == Material.AIR) {
if(player.getInventory().getItemInMainHand().getType() == Material.AIR || player.getInventory().getItemInMainHand() == null) {
msgPlayer(player,colorTextComp("<red>You must hold an Item in hand.")); msgPlayer(player,colorTextComp("<red>You must hold an Item in hand."));
return true; return true;
} else {
player.getInventory().getItemInMainHand();
} }
switch (args.length) { switch (args.length) {
case 0, 1 -> msgPlayer(player, colorTextComp("<red>You must specify an nbt and an int.")); case 0, 1 -> msgPlayer(player, colorTextComp("<red>You must specify an nbt and an int."));
@ -56,8 +55,8 @@ public class NbtCommand implements TabExecutor {
List<Component> lore = new ArrayList<>(); List<Component> lore = new ArrayList<>();
ItemMeta itm = it.getItemMeta(); ItemMeta itm = it.getItemMeta();
lore.add((Component) itm.lore()); lore.add((Component) itm.lore());
Boolean yes = false; boolean yes = false;
Boolean ever = false; boolean ever = false;
for (Component ct : lore) { for (Component ct : lore) {
if (ct != null) { if (ct != null) {
if (ct.contains(Component.text("Attributes:"))) { if (ct.contains(Component.text("Attributes:"))) {
@ -65,7 +64,7 @@ public class NbtCommand implements TabExecutor {
ever = true; ever = true;
} else { } else {
if (yes) { if (yes) {
ct.append(Component.text(colorString(attributes(args[0]) + ": " + (Integer.parseInt(args[1]) + a)))); //ct.append(Component.text(colorString(attributes(args[0]) + ": " + (Integer.parseInt(args[1]) + a)))); deprecated
yes = false; yes = false;
} }
} }
@ -73,29 +72,27 @@ public class NbtCommand implements TabExecutor {
} }
if (!ever) { if (!ever) {
lore.add(colorTextComp("<red>Attributes:")); lore.add(colorTextComp("<red>Attributes:"));
lore.add(colorTextComp(attributes(args[0]) + ": " + (Integer.parseInt(args[1]) + a))); //lore.add(colorTextComp(attributes(args[0]) + ": " + (Integer.parseInt(args[1]) + a))); deprecated
} }
itm.lore(lore); itm.lore(lore);
it.setItemMeta(itm); it.setItemMeta(itm);
PlayerManager pm = ((Raxen) Bukkit.getPluginManager().getPlugin("Raxen")).getManager().getPlayerManager(); PlayerManager pm = ((Raxen) Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Raxen"))).getManager().getPlayerManager();
Entity e = player;
Attributes attributes = new Attributes(main);
nbti.setInteger(args[0], Integer.parseInt(args[1]) + a); nbti.setInteger(args[0], Integer.parseInt(args[1]) + a);
if (nbti.hasKey("SPEED")) { if (nbti.hasKey("SPEED")) {
pm.getSpeed().add(e, nbti.getInteger("SPEED")); pm.getSpeed().add(player, nbti.getInteger("SPEED"));
} }
if (nbti.hasKey("HEALTH")) { if (nbti.hasKey("HEALTH")) {
pm.getHealth().add(e, nbti.getInteger("HEALTH")); pm.getHealth().add(player, nbti.getInteger("HEALTH"));
} }
if (nbti.hasKey("DEFENSE")) { if (nbti.hasKey("DEFENSE")) {
pm.getDefense().add(e, nbti.getInteger("DEFENSE")); pm.getDefense().add(player, nbti.getInteger("DEFENSE"));
} }
if (nbti.hasKey("STRENGTH")) { if (nbti.hasKey("STRENGTH")) {
pm.getStrength().add(e, nbti.getInteger("STRENGTH")); pm.getStrength().add(player, nbti.getInteger("STRENGTH"));
} }
it = nbti.getItem(); it = nbti.getItem();
msgPlayer(player, colorTextComp(Raxen.getPrefix() + "<white>You successfully added the nbt " + attributes(args[0]) + "<white>with " + args[1] + "<white>.")); msgPlayer(player, colorTextComp(Raxen.getPrefix() + "<white>You successfully added the nbt " + /*attributes(args[0])*/ args[0] + "<white>with " + args[1] + "<white>."));
updateSkills(main, player); updateSkills(main, player);
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), it); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), it);
} }

View file

@ -2,48 +2,45 @@ package gq.unurled.raxen.components.dungeons;
import gq.unurled.raxen.Raxen; import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.dungeons.types.MonsterType; import gq.unurled.raxen.components.dungeons.types.MonsterType;
import gq.unurled.raxen.components.dungeons.types.forest.ForestMonster;
import gq.unurled.raxen.components.entity.other.RaxenEntity; import gq.unurled.raxen.components.entity.other.RaxenEntity;
import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static gq.unurled.raxen.utils.DungeonUtils.getRadiusFromRank; import static gq.unurled.raxen.utils.DungeonUtils.getRadiusFromRank;
import static gq.unurled.raxen.utils.Utils.log;
public class Dungeon { public class Dungeon {
private String name; @Getter private String name;
private Rank rank; @Getter private Rank rank;
private Gate gate; @Getter private Gate gate;
private Map<String, RaxenEntity> monster = new HashMap(); //String, RaxenEntity
@Getter private HashMap<String, RaxenEntity> monster = new HashMap<>();
/** /**
* The Type of the Dungeon * The Type of the Dungeon
*/ */
private Types types; @Getter private Types types;
/** /**
* Monster Types * Monster Types
*/ */
private MonsterType monsterType; @Getter private MonsterType monsterType;
private Location location; @Getter private Location location;
private Integer radius; @Getter private Integer radius;
public Dungeon(String name, Rank rank, Types types, MonsterType mType) { public Dungeon(String name, Rank rank, Types types, MonsterType mType) {
this.name = name; this.name = name;
this.rank = rank; this.rank = rank;
this.types = types; this.types = types;
this.monsterType = mType; this.monsterType = mType;
generateGate();
} }
/** /**

View file

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.Random; import java.util.Random;
import java.util.UUID;
public class Gate { public class Gate {

View file

@ -1,21 +1,34 @@
package gq.unurled.raxen.components.dungeons.types; package gq.unurled.raxen.components.dungeons.types;
import gq.unurled.raxen.components.dungeons.Rank; import gq.unurled.raxen.components.dungeons.Rank;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
public interface MonsterType { import java.util.Random;
import static gq.unurled.raxen.utils.Utils.debug;
public class MonsterType {
public enum type {; public enum type {;
private Double rate; private Double rate;
public String ID; public String ID;
public Class clazz; public Class clazz;
type(Double rate, String ID, Class clazz) { type(Double rate, String ID, Class clazz) {
this.rate = rate; this.rate = rate;
this.ID = ID; this.ID = ID;
this.clazz = clazz; this.clazz = clazz;
} }
public static type getTypeById(String ID) { public static @Nullable type getTypeById(String ID) {
for (type type : type.values()) { for (type type : type.values()) {
if(type.ID.equals(ID)) { if(type.ID.equals(ID)) {
return type; return type;
@ -31,6 +44,7 @@ public interface MonsterType {
public void setRate(Double rate) { public void setRate(Double rate) {
this.rate = rate; this.rate = rate;
} }
public String getID() { public String getID() {
return ID; return ID;
} }
@ -38,7 +52,43 @@ public interface MonsterType {
public void setID(String ID) { public void setID(String ID) {
this.ID = ID; this.ID = ID;
} }
public Class getClazz() {
return clazz;
}
public void getClazz(Class clazz) {
this.clazz = clazz;
}
} }
void genMonster(World world, Rank rank); public void genMonster(World world, Rank rank) {
Double x = 0.0;
Double y = 100.0;
Double z = 0.0;
for (type type : type.values()) {
type.name();
Random r = new Random();
int per = r.nextInt(100);
if (per >= type.rate) {
// spawn entity
debug("Spawning Entity " + type.ID);
Entity e = world.spawnEntity(new Location(world, x, y, z), EntityType.ARROW);
// e = ((RaxenEntity) type.getClazz()).createEntity();
e.setInvulnerable(true);
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
Location loc = new Location(e.getWorld(), e.getLocation().getX(), e.getLocation().getY()-1, e.getLocation().getZ());
if (loc.getBlock().getType() != Material.AIR) {
e.setInvulnerable(false);
this.cancel();
}
}
}.runTaskTimerAsynchronously(Bukkit.getPluginManager().getPlugin("Raxen"), 0L, 20L);
}
x = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
z = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
}
}
} }

View file

@ -0,0 +1,16 @@
package gq.unurled.raxen.components.dungeons.types.forest;
import gq.unurled.raxen.components.dungeons.Dungeon;
import gq.unurled.raxen.components.dungeons.Rank;
import gq.unurled.raxen.components.dungeons.Types;
import gq.unurled.raxen.components.dungeons.types.MonsterType;
public class ForestDungeon extends Dungeon {
public ForestDungeon(String name, Rank rank, Types types, MonsterType mType) {
super(name, rank, types, mType);
}
public ForestDungeon() {
super("Forest", Rank.E, Types.FOREST, new ForestMonster());
}
}

View file

@ -1,60 +1,13 @@
package gq.unurled.raxen.components.dungeons.types.forest; package gq.unurled.raxen.components.dungeons.types.forest;
import gq.unurled.raxen.components.dungeons.Rank;
import gq.unurled.raxen.components.dungeons.types.MonsterType; import gq.unurled.raxen.components.dungeons.types.MonsterType;
import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Elf; import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Elf;
import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Wolf; import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Wolf;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Zombie;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.Random; public class ForestMonster extends MonsterType {
import static gq.unurled.raxen.utils.Utils.debug; @Getter enum type {
import static org.apache.commons.lang.math.RandomUtils.nextInt;
public class ForestMonster implements MonsterType {
@Override
public void genMonster(World world, Rank rank) {
Double x = 0.0;
Double y = 100.0;
Double z = 0.0;
for (type type : type.values()) {
type.name();
Random r = new Random();
int per = r.nextInt(100);
if (per >= type.rate) {
// spawn entity
debug("Spawning Entity " + type.ID);
Entity e = world.spawnEntity(new Location(world, x, y, z), EntityType.ARROW);
e.setInvulnerable(true);
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
Location loc = new Location(e.getWorld(), e.getLocation().getX(), e.getLocation().getY()-1, e.getLocation().getZ());
if (loc.getBlock().getType() != Material.AIR) {
e.setInvulnerable(false);
this.cancel();
}
}
}.runTaskTimerAsynchronously(Bukkit.getPluginManager().getPlugin("Raxen"), 0L, 20L);
}
x = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
z = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
}
}
@Getter
enum type {
ELF(50.0 ,"ELF", Elf.class), ELF(50.0 ,"ELF", Elf.class),
WOLF(50.0, "WOLF", Wolf.class); WOLF(50.0, "WOLF", Wolf.class);

View file

@ -1,6 +1,7 @@
package gq.unurled.raxen.components.enchantments; package gq.unurled.raxen.components.enchantments;
import io.papermc.paper.enchantments.EnchantmentRarity; import io.papermc.paper.enchantments.EnchantmentRarity;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -13,19 +14,16 @@ import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
public class EnchantmentWarpper extends Enchantment { public class EnchantmentWarpper extends Enchantment {
private final String name;
private final int maxLevel; private final int maxLevel;
public EnchantmentWarpper(String nameSpace, String name, int lvl) { public EnchantmentWarpper(String nameSpace, String name, int lvl) {
super(NamespacedKey.minecraft(nameSpace)); super(NamespacedKey.minecraft(nameSpace));
this.name = name;
this.maxLevel = lvl; this.maxLevel = lvl;
} }
@Override @Override @Deprecated
public @NotNull String getName() { public @NotNull String getName() {
return name; return null;
} }
@Override @Override
@ -97,4 +95,9 @@ public class EnchantmentWarpper extends Enchantment {
public @NotNull String translationKey() { public @NotNull String translationKey() {
return null; return null;
} }
@Override
public @NotNull Key key() {
return super.key();
}
} }

View file

@ -9,8 +9,7 @@ import org.bukkit.entity.EntityType;
public class Elf extends RaxenEntity { public class Elf extends RaxenEntity {
@Getter @Getter private final String name;
private final String name;
public Elf(Raxen main, String name, Integer level, Double health, Double strength) { public Elf(Raxen main, String name, Integer level, Double health, Double strength) {
super(main, name, level, health, strength); super(main, name, level, health, strength);

View file

@ -9,8 +9,7 @@ import org.bukkit.entity.EntityType;
public class Wolf extends RaxenEntity { public class Wolf extends RaxenEntity {
@Getter @Getter private final String name;
private final String name;
public Wolf(Raxen main, String name, Integer level, Double health, Double strength) { public Wolf(Raxen main, String name, Integer level, Double health, Double strength) {

View file

@ -57,7 +57,7 @@ public class RaxenPlayer {
PersistentDataContainer data = player.getPersistentDataContainer(); PersistentDataContainer data = player.getPersistentDataContainer();
String store = data.get(namespacedKey.storage, PersistentDataType.STRING); String store = data.get(namespacedKey.storage, PersistentDataType.STRING);
org.bukkit.inventory.Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest")); org.bukkit.inventory.Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
ec = setItemsToInventory(Items.listItemStackDeserilize(store), ec); ec = setItemsToInventory(Items.listItemStackDeserialize(store), ec);
EnderChest ecc = new EnderChest(ec); EnderChest ecc = new EnderChest(ec);
Storage storage = new Storage(ecc); Storage storage = new Storage(ecc);
return storage; return storage;
@ -67,7 +67,7 @@ public class RaxenPlayer {
PersistentDataContainer data = player.getPersistentDataContainer(); PersistentDataContainer data = player.getPersistentDataContainer();
String inv = data.get(namespacedKey.inventory, PersistentDataType.STRING); String inv = data.get(namespacedKey.inventory, PersistentDataType.STRING);
org.bukkit.inventory.Inventory invv = Bukkit.createInventory(player, InventoryType.PLAYER); org.bukkit.inventory.Inventory invv = Bukkit.createInventory(player, InventoryType.PLAYER);
invv = setItemsToInventory(Items.listItemStackDeserilize(inv), invv); invv = setItemsToInventory(Items.listItemStackDeserialize(inv), invv);
Inventory invvv = new Inventory(invv); Inventory invvv = new Inventory(invv);
Inventories invvvv = new Inventories(invvv); Inventories invvvv = new Inventories(invvv);
return invvvv; return invvvv;
@ -80,11 +80,11 @@ public class RaxenPlayer {
for(ItemStack it : inv) { for(ItemStack it : inv) {
reverse = reverse + 1; reverse = reverse + 1;
if(it != null && it.getType() != Material.AIR) { if(it != null && it.getType() != Material.AIR) {
String s = Items.itemStackSerilize(it, reverse); String s = Items.itemStackSerialize(it, reverse);
listInv.add(s); listInv.add(s);
} }
} }
String invv = Items.listItemStackSerelize(listInv); String invv = Items.listItemStackSerialize(listInv);
this.inventory = new Inventories(new Inventory(inv)); this.inventory = new Inventories(new Inventory(inv));
data.set(namespacedKey.inventory, PersistentDataType.STRING, invv); data.set(namespacedKey.inventory, PersistentDataType.STRING, invv);
} }
@ -95,12 +95,12 @@ public class RaxenPlayer {
int reverse = 0; int reverse = 0;
for(ItemStack it : ec) { for(ItemStack it : ec) {
if(it != null) { if(it != null) {
String s = Items.itemStackSerilize(it, reverse); String s = Items.itemStackSerialize(it, reverse);
list.add(s); list.add(s);
} }
reverse += 1; reverse += 1;
} }
String store = Items.listItemStackSerelize(list); String store = Items.listItemStackSerialize(list);
this.storages = new Storage(new EnderChest(ec)); this.storages = new Storage(new EnderChest(ec));
data.set(namespacedKey.storage, PersistentDataType.STRING, store); data.set(namespacedKey.storage, PersistentDataType.STRING, store);
} }

View file

@ -31,7 +31,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import static gq.unurled.raxen.utils.Items.listItemStackDeserilize; import static gq.unurled.raxen.utils.Items.listItemStackDeserialize;
import static gq.unurled.raxen.utils.Items.setItemsToInventory; import static gq.unurled.raxen.utils.Items.setItemsToInventory;
import static gq.unurled.raxen.utils.Utils.debug; import static gq.unurled.raxen.utils.Utils.debug;
@ -75,12 +75,12 @@ public class PlayerConfig {
reverse = 0; reverse = 0;
for(ItemStack it : ec.getEc()) { for(ItemStack it : ec.getEc()) {
if(it != null && it.getType() != Material.AIR) { if(it != null && it.getType() != Material.AIR) {
String s = Items.itemStackSerilize(it, reverse); String s = Items.itemStackSerialize(it, reverse);
list.add(s); list.add(s);
} }
reverse += 1; reverse += 1;
} }
String ecstr = Items.listItemStackSerelize(list); String ecstr = Items.listItemStackSerialize(list);
doc.append("ec", ecstr); doc.append("ec", ecstr);
} }
} }
@ -111,11 +111,11 @@ public class PlayerConfig {
for(ItemStack it : ec.getEc()) { for(ItemStack it : ec.getEc()) {
reverse += 1; reverse += 1;
if(it != null) { if(it != null) {
String s = Items.itemStackSerilize(it, reverse); String s = Items.itemStackSerialize(it, reverse);
list.add(s); list.add(s);
} }
} }
String ecstr = Items.listItemStackSerelize(list); String ecstr = Items.listItemStackSerialize(list);
config.set("ec", ecstr); config.set("ec", ecstr);
} }
} }
@ -146,11 +146,11 @@ public class PlayerConfig {
Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest")); Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
if(playerDoc.getString("ec") != null) { if(playerDoc.getString("ec") != null) {
debug(main, "Loading " + player.getName() + "'s storage."); debug(main, "Loading " + player.getName() + "'s storage.");
ec = setItemsToInventory(listItemStackDeserilize(playerDoc.getString("ec")), ec); ec = setItemsToInventory(listItemStackDeserialize(playerDoc.getString("ec")), ec);
} }
playerManager.getRaxenPlayer(player).setStorage(ec); playerManager.getRaxenPlayer(player).setStorage(ec);
PlayerInventory inv = player.getInventory(); PlayerInventory inv = player.getInventory();
inv = setItemsToInventory(listItemStackDeserilize(playerDoc.getString("inv")), inv); inv = setItemsToInventory(listItemStackDeserialize(playerDoc.getString("inv")), inv);
player.getInventory().setContents(inv.getContents()); player.getInventory().setContents(inv.getContents());
player.updateInventory(); player.updateInventory();
gq.unurled.raxen.components.entity.player.storages.Inventory invv = new gq.unurled.raxen.components.entity.player.storages.Inventory(inv); gq.unurled.raxen.components.entity.player.storages.Inventory invv = new gq.unurled.raxen.components.entity.player.storages.Inventory(inv);
@ -169,13 +169,13 @@ public class PlayerConfig {
config.getInt("luck"), config.getInt("itemLuck")); config.getInt("luck"), config.getInt("itemLuck"));
Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest")); Inventory ec = Bukkit.createInventory(null, 54, Component.text("Ender Chest"));
if((String) config.get("ec") != null) { if((String) config.get("ec") != null) {
ec = setItemsToInventory(listItemStackDeserilize((String) config.get("ec")), ec); ec = setItemsToInventory(listItemStackDeserialize((String) config.get("ec")), ec);
} }
EnderChest ecc = new EnderChest(ec); EnderChest ecc = new EnderChest(ec);
Storage storage = new Storage(ecc); Storage storage = new Storage(ecc);
playerManager.getRaxenPlayer(player).setStorage(ec); playerManager.getRaxenPlayer(player).setStorage(ec);
Inventory inv = Bukkit.createInventory(player, InventoryType.PLAYER); Inventory inv = Bukkit.createInventory(player, InventoryType.PLAYER);
inv = setItemsToInventory(listItemStackDeserilize((String) config.getString("inv")), inv); inv = setItemsToInventory(listItemStackDeserialize((String) config.getString("inv")), inv);
player.getInventory().setContents(inv.getContents()); player.getInventory().setContents(inv.getContents());
player.updateInventory(); player.updateInventory();
gq.unurled.raxen.components.entity.player.storages.Inventory invv = new gq.unurled.raxen.components.entity.player.storages.Inventory(inv); gq.unurled.raxen.components.entity.player.storages.Inventory invv = new gq.unurled.raxen.components.entity.player.storages.Inventory(inv);
@ -191,13 +191,13 @@ public class PlayerConfig {
for(ItemStack it : inv) { for(ItemStack it : inv) {
reverse = reverse + 1; reverse = reverse + 1;
if(it != null && it.getType() != Material.AIR) { if(it != null && it.getType() != Material.AIR) {
String s = Items.itemStackSerilize(it, reverse); String s = Items.itemStackSerialize(it, reverse);
listInv.add(s); listInv.add(s);
} }
} }
String invstr= ""; String invstr= "";
if (listInv.size() > 0) { if (listInv.size() > 0) {
invstr = Items.listItemStackSerelize(listInv); invstr = Items.listItemStackSerialize(listInv);
} }
debug(main, "saving..."); debug(main, "saving...");
String storage = sto.getConfig().getString("storage"); String storage = sto.getConfig().getString("storage");

View file

@ -6,6 +6,10 @@ import gq.unurled.raxen.manager.server.*;
import gq.unurled.raxen.utils.libs.Multiverse; import gq.unurled.raxen.utils.libs.Multiverse;
import lombok.Getter; import lombok.Getter;
/**
* Manager class, it enables all features of the plugin.
* From commands, to Item and worlds, it links all of them together.
*/
public class Manager { public class Manager {
@Getter @Getter
@ -28,16 +32,21 @@ public class Manager {
private LootManager lootManager; private LootManager lootManager;
@Getter @Getter
private LibsManager libsManager; private LibsManager libsManager;
@Getter private DungeonsManager dungeonsManager;
@Getter private Multiverse multiverse; @Getter private Multiverse multiverse;
/**
* Create an instance of all managers.
* @param main Raxen
*/
public void set(Raxen main) { public void set(Raxen main) {
libsManager = new LibsManager(main); libsManager = new LibsManager(main);
multiverse = new Multiverse();
worldManager = new WorldManager(main); worldManager = new WorldManager(main);
storageManager = new StorageManager(main); storageManager = new StorageManager(main);
//Managers
itemManager = new ItemManager(main); itemManager = new ItemManager(main);
playerManager = new PlayerManager(main); playerManager = new PlayerManager(main);
listenerManager = new ListenerManager(main); listenerManager = new ListenerManager(main);
@ -45,6 +54,6 @@ public class Manager {
resourcePackManager = new ResourcePackManager(main); resourcePackManager = new ResourcePackManager(main);
entityManager = new EntityManager(main); entityManager = new EntityManager(main);
lootManager = new LootManager(main); lootManager = new LootManager(main);
multiverse = new Multiverse(); dungeonsManager = new DungeonsManager(main);
} }
} }

View file

@ -3,6 +3,7 @@ package gq.unurled.raxen.manager.entity;
import de.tr7zw.nbtapi.NBTItem; import de.tr7zw.nbtapi.NBTItem;
import gq.unurled.raxen.Raxen; import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.items.NBT; import gq.unurled.raxen.components.items.NBT;
import gq.unurled.raxen.utils.Utils;
import lombok.Getter; import lombok.Getter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -12,15 +13,15 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
import static gq.unurled.raxen.utils.Items.setLoreFromNBT;
import static gq.unurled.raxen.utils.Utils.*; import static gq.unurled.raxen.utils.Utils.*;
public class ItemManager { public class ItemManager {
@ -32,49 +33,7 @@ public class ItemManager {
public ItemManager(Raxen main) { public ItemManager(Raxen main) {
this.main = main; this.main = main;
register(); // register();
}
private void example() {
File customFile;
FileConfiguration customConfig;
customFile = new File(main.getDataFolder() + "/Items/", "/example.yml");
if (!customFile.exists()) {
customFile.getParentFile().mkdirs();
try {
customFile.createNewFile();
}
catch (IOException e) {
error((Raxen) Bukkit.getPluginManager().getPlugin("Raxen"),"Error in Item Manager saving new File.");
e.printStackTrace();
}
}
customConfig = new YamlConfiguration();
try {
customConfig.load(customFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
List<String> lore = new ArrayList<>();
lore.add("<red>super lore wahou");
if (customConfig.get("name") == null) {
customConfig.set("id", "minecraft_id_of_item");
customConfig.set("customId", "id_of_item_used_to_identify_it");
customConfig.set("name", "<red>Name of the Item");
customConfig.set("health", 100);
customConfig.set("defense", 50);
customConfig.set("speed", 100);
customConfig.set("strength", 100);
customConfig.set("custom_ability","fireball");
customConfig.set("custom_model_data", 123);
customConfig.set("lore",lore);
try {
customConfig.save(customFile);
} catch (IOException e) {
e.printStackTrace();
}
}
} }
private void register() { private void register() {
@ -109,16 +68,13 @@ public class ItemManager {
} }
} }
private void registerItem(FileConfiguration file) { private void registerItem(@NotNull FileConfiguration file) {
debug(main, file.getString("id")); debug(main, file.getString("id"));
ItemStack it = new ItemStack(Material.getMaterial((String) file.get("id"))); ItemStack it = new ItemStack(Objects.requireNonNull(Material.getMaterial((String) Objects.requireNonNull(file.get("id")))));
ItemMeta itm = it.getItemMeta(); ItemMeta itm = it.getItemMeta();
itm.displayName(colorTextComp((String) file.get("name"))); itm.displayName(colorTextComp((String) file.get("name")));
List<Component> lore = new ArrayList<>(); List<Component> lore = ((List<String>) Objects.requireNonNull(file.get("lore"))).stream().map(Utils::colorTextComp).collect(Collectors.toList());
for (String str : (List<String>) Objects.requireNonNull(file.get("lore"))) { itm.setCustomModelData(Objects.requireNonNull(file.getConfigurationSection("Pack")).getInt("custom_model_data"));
lore.add(colorTextComp(str));
}
itm.setCustomModelData(file.getConfigurationSection("Pack").getInt("custom_model_data"));
itm.lore(lore); itm.lore(lore);
it.setItemMeta(itm); it.setItemMeta(itm);
NBTItem nbti = new NBTItem(it); NBTItem nbti = new NBTItem(it);
@ -130,7 +86,7 @@ public class ItemManager {
nbti.setString(NBT.CUSTOM_ABILITY, file.getString("custom_ability")); nbti.setString(NBT.CUSTOM_ABILITY, file.getString("custom_ability"));
nbti.setDouble(NBT.DROP_RATE, file.getDouble("drop_rate")); nbti.setDouble(NBT.DROP_RATE, file.getDouble("drop_rate"));
it = nbti.getItem(); it = nbti.getItem();
it = setLoreFromNBT(it); //it = setLoreFromNBT(it); deprecated
list.put(file.getString("customId"), it); list.put(file.getString("customId"), it);
} }

View file

@ -1,11 +1,32 @@
package gq.unurled.raxen.manager.server; package gq.unurled.raxen.manager.server;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.dungeons.Dungeon;
import gq.unurled.raxen.components.dungeons.Gate; import gq.unurled.raxen.components.dungeons.Gate;
import gq.unurled.raxen.components.dungeons.types.forest.ForestDungeon;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class DungeonsManager { public class DungeonsManager {
private Raxen main;
private HashMap<UUID, Gate> gates = new HashMap<>(); private HashMap<UUID, Gate> gates = new HashMap<>();
private HashMap<String, Dungeon> dungeons = new HashMap<>();
public DungeonsManager(Raxen main) {
this.main = main;
registerDungeons();
}
public void registerDungeons() {
ForestDungeon forestDungeon = new ForestDungeon();
dungeons.put("FOREST", forestDungeon);
for (String s : dungeons.keySet()) {
main.getManager().getWorldManager().loadWorld(dungeons.get(s).getName());
}
}
} }

View file

@ -3,13 +3,16 @@ package gq.unurled.raxen.manager.server;
import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import gq.unurled.raxen.Raxen; import gq.unurled.raxen.Raxen;
import org.bukkit.World;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static gq.unurled.raxen.utils.Utils.*; import static gq.unurled.raxen.utils.Utils.*;
import static gq.unurled.raxen.utils.Utils.error;
public class WorldManager { public class WorldManager {
@ -34,10 +37,12 @@ public class WorldManager {
this.worldFolder = new File("worlds/"); this.worldFolder = new File("worlds/");
this.worldManager = main.getManager().getMultiverse().getWorldManager(); this.worldManager = main.getManager().getMultiverse().getWorldManager();
worlds.add("Forest"); worlds.add("Forest");
log(pluginFolder.getAbsolutePath(), "" + pluginFolder.isDirectory());
log(worldFolder.getAbsolutePath(), "" + worldFolder.isDirectory());
} }
/**
* remove a world
* @param name
*/
public void removeWorld(String name) { public void removeWorld(String name) {
File world = new File(worldFolder + name + "/"); File world = new File(worldFolder + name + "/");
if (!world.exists() || !world.isDirectory()) { if (!world.exists() || !world.isDirectory()) {
@ -82,19 +87,20 @@ public class WorldManager {
} }
public void loadWorld(String name) { public void loadWorld(String name) {
File world = new File(pluginFolder + name + "/"); File world = new File(pluginFolder + "/" + name + "/");
if (!world.exists() || !world.isDirectory()) { if (!world.exists() || !world.isDirectory()) {
error("Loading world " + name + ". Folder don't exists."); error("Loading world " + name + ". Folder " + world.getAbsolutePath() + " don't exists.");
return; return;
} }
File newWorld = new File(worldFolder + name); File newWorld = new File(worldFolder + "/" + name);
try { try {
log(colorTextComp("<aqua>Copping world " + world.getName() + ".</aqua>"), colorTextComp("<blue>From " + world.getAbsolutePath() + " to " + newWorld.getAbsolutePath() +".</blue>"));
copyDirectory(world.getAbsolutePath(), newWorld.getAbsolutePath()); copyDirectory(world.getAbsolutePath(), newWorld.getAbsolutePath());
} catch (IOException e) { } catch (IOException e) {
error("Error while Loading world " + name + " at coping data."); error("Error while Loading world " + name + " at coping data.");
e.printStackTrace(); e.printStackTrace();
} }
worldManager.loadWorld(name); worldManager.loadWorld(name);
worldManager.addWorld(world.getName(), World.Environment.NORMAL, null, null, false, null);
} }
} }

View file

@ -8,6 +8,9 @@ import java.util.Random;
public class DungeonUtils { public class DungeonUtils {
/**
* get the radius from the rank of a dungeon
*/
public static Integer getRadiusFromRank(@NotNull Rank rank) { public static Integer getRadiusFromRank(@NotNull Rank rank) {
Integer radius = 1; Integer radius = 1;
switch (rank) { switch (rank) {
@ -39,6 +42,9 @@ public class DungeonUtils {
return radius; return radius;
} }
/**
* used to spawn monster based on random
*/
public static void fromTypeToMonster(Types types, Rank rank) { public static void fromTypeToMonster(Types types, Rank rank) {
Random r = new Random(); Random r = new Random();
r.nextInt(); r.nextInt();

View file

@ -6,14 +6,21 @@ import gq.unurled.raxen.manager.entity.PlayerManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.util.Objects;
import static gq.unurled.raxen.utils.Utils.debug; import static gq.unurled.raxen.utils.Utils.debug;
public class EntityAttributes { public class EntityAttributes {
/**
* get every attribute of an entity
* @param e an entity
* @return an instance of attribute
*/
public static Attribute getAttribute(Entity e) { public static Attribute getAttribute(Entity e) {
int maxHealth, health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemStrength, maxMana, mana, itemMana, luck, itemLuck; int maxHealth, health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemStrength, maxMana, mana, itemMana, luck, itemLuck;
PlayerManager pm = ((Raxen) Bukkit.getPluginManager().getPlugin("Raxen")).getManager().getPlayerManager(); PlayerManager pm = ((Raxen) Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Raxen"))).getManager().getPlayerManager();
defense= pm.getDefense().get(e); defense= pm.getDefense().get(e);
maxMana = pm.getMaxMana().get(e); maxMana = pm.getMaxMana().get(e);
itemDefense= pm.getItemDefense().get(e); itemDefense= pm.getItemDefense().get(e);
@ -31,8 +38,11 @@ public class EntityAttributes {
return new Attribute(maxHealth, health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemStrength, maxMana, mana, itemMana, luck, itemLuck); return new Attribute(maxHealth, health, itemHealth, defense, itemDefense, speed, itemSpeed, strength, itemStrength, maxMana, mana, itemMana, luck, itemLuck);
} }
/**
* set each attribute
*/
public static void setAttributes(Entity e, int maxHealth, int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemStrength, int maxMana, int mana, int itemMana, int luck, int itemLuck) { public static void setAttributes(Entity e, int maxHealth, int health, int itemHealth, int defense, int itemDefense, int speed, int itemSpeed, int strength, int itemStrength, int maxMana, int mana, int itemMana, int luck, int itemLuck) {
PlayerManager pm = ((Raxen) Bukkit.getPluginManager().getPlugin("Raxen")).getManager().getPlayerManager(); PlayerManager pm = ((Raxen) Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Raxen"))).getManager().getPlayerManager();
pm.getDefense().set(e, defense); pm.getDefense().set(e, defense);
pm.getMaxMana().set(e, maxMana); pm.getMaxMana().set(e, maxMana);
pm.getItemDefense().set(e, itemDefense); pm.getItemDefense().set(e, itemDefense);
@ -47,7 +57,7 @@ public class EntityAttributes {
pm.getItemStrength().set(e, itemStrength); pm.getItemStrength().set(e, itemStrength);
pm.getItemSpeed().set(e, itemSpeed); pm.getItemSpeed().set(e, itemSpeed);
pm.getItemMana().set(e, itemMana); pm.getItemMana().set(e, itemMana);
debug("Speeeeeeeeeed " + speed); debug("Speedometer " + speed);
for (String s : pm.getAttribute().keySet()) { for (String s : pm.getAttribute().keySet()) {
debug(s + " " + pm.getAttribute().get(s).get(e).toString()); debug(s + " " + pm.getAttribute().get(s).get(e).toString());
} }

View file

@ -27,6 +27,16 @@ import static gq.unurled.raxen.utils.Utils.*;
public class Items { public class Items {
/**
* create an item with @param
* @param material the item material
* @param amount the amount of the itemstack
* @param glow if the item glows or not
* @param unb if the item is unbreakable
* @param name the name of the item
* @param lore the lore of the item
* @return the created itemstack
*/
public static @NotNull ItemStack createItem(Material material, int amount, boolean glow, boolean unb, String name, String... lore) { public static @NotNull ItemStack createItem(Material material, int amount, boolean glow, boolean unb, String name, String... lore) {
ItemStack item = new ItemStack(material, amount); ItemStack item = new ItemStack(material, amount);
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
@ -51,6 +61,14 @@ public class Items {
return item; return item;
} }
/**
* edit an item with provided @param
* @param item the item to modify
* @param name the new name of the item
* @param amount the new amount
* @param lore the new lore
* @return the modified itemstack
*/
public static @NotNull ItemStack editItem(ItemStack item, String name, int amount, List<Component> lore) { public static @NotNull ItemStack editItem(ItemStack item, String name, int amount, List<Component> lore) {
if(amount == 0) { if(amount == 0) {
amount = 1; amount = 1;
@ -64,40 +82,75 @@ public class Items {
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
return item; return item;
} }
/**
* the basic close gui button
* @return a barrier block itemstack named close
*/
public static @NotNull ItemStack closeItem () { public static @NotNull ItemStack closeItem () {
return createItem(Material.BARRIER, 1, false, false, colorString("<red>CLOSE")); return createItem(Material.BARRIER, 1, false, false, colorString("<red>CLOSE"));
} }
/**
* fill item in chest and guis
* @return a grey glass pane named nothing
*/
public static @NotNull ItemStack greyPane() { public static @NotNull ItemStack greyPane() {
return createItem(Material.GRAY_STAINED_GLASS_PANE, 1, false, true, ""); return createItem(Material.GRAY_STAINED_GLASS_PANE, 1, false, true, "");
} }
public static @NotNull String itemStackSerilize(ItemStack it, @NotNull Integer slot) { /**
* serialize item
* @param it an itemstack
* @param slot the slot it was in the inventory
* @return the serialized string
*/
public static @NotNull String itemStackSerialize(ItemStack it, @NotNull Integer slot) {
String str = ""; String str = "";
str = itemTo64(it); str = itemTo64(it);
str = str + "@#SLOT#" + slot.toString(); str = str + "@#SLOT#" + slot.toString();
return str; return str;
} }
public static class itemStackDeserilizeResult { /**
* a class that represent the itemstack deserialized.
*/
public static class itemStackDeserializeResult {
int slot; int slot;
ItemStack it; ItemStack it;
public itemStackDeserilizeResult(Integer slot, ItemStack it) { /**
* custructor
* @param slot an int of the slot of the item
* @param it the item which is deserialized.
*/
public itemStackDeserializeResult(Integer slot, ItemStack it) {
this.slot = slot; this.slot = slot;
this.it = it; this.it = it;
} }
} }
/**
* a class that represent a list of itemstack deserialized.
*/
public static class itemStackListDeserilize { public static class itemStackListDeserilize {
HashMap<Integer, ItemStack> inv; HashMap<Integer, ItemStack> inv;
/**
* constructor
* @param inv a list of itemstack with their slot.
*/
public itemStackListDeserilize(HashMap<Integer, ItemStack> inv) { public itemStackListDeserilize(HashMap<Integer, ItemStack> inv) {
this.inv = inv; this.inv = inv;
} }
} }
public static @NotNull itemStackDeserilizeResult itemStackDeserilize(@NotNull String str) { /**
* deserilize items
* @param str the serilized item
* @return a deserialized item instance
*/
public static @NotNull Items.itemStackDeserializeResult itemStackDeserilize(@NotNull String str) {
List<String> mapp = Arrays.asList(str.split("@#SLOT#")); List<String> mapp = Arrays.asList(str.split("@#SLOT#"));
Gson gson = new Gson(); Gson gson = new Gson();
ItemStack it = new ItemStack(Material.AIR); ItemStack it = new ItemStack(Material.AIR);
@ -116,11 +169,16 @@ public class Items {
} }
} }
itemStackDeserilizeResult itt = new itemStackDeserilizeResult(slot, it); itemStackDeserializeResult itt = new itemStackDeserializeResult(slot, it);
return itt; return itt;
} }
public static String listItemStackSerelize(@NotNull List<String> list) { /**
* a list of serialized item in one string
* @param list the list of all serialized item
* @return a string
*/
public static String listItemStackSerialize(@NotNull List<String> list) {
Gson gson = new Gson(); Gson gson = new Gson();
String str = ""; String str = "";
for(String a : list) { for(String a : list) {
@ -129,7 +187,12 @@ public class Items {
return str; return str;
} }
public static @NotNull HashMap<Integer, ItemStack> listItemStackDeserilize(@NotNull String str) { /**
* deserialize item
* @param str a list of all serialized item
* @return a list of itemstack with their slot
*/
public static @NotNull HashMap<Integer, ItemStack> listItemStackDeserialize(@NotNull String str) {
Gson gson = new Gson(); Gson gson = new Gson();
List<String> map = Arrays.asList(str.split("@#NEW_ITEM#")); List<String> map = Arrays.asList(str.split("@#NEW_ITEM#"));
HashMap<Integer, ItemStack> inv = new HashMap<>(); HashMap<Integer, ItemStack> inv = new HashMap<>();
@ -138,7 +201,7 @@ public class Items {
ItemStack itt; ItemStack itt;
Integer slot; Integer slot;
if(s != null) { if(s != null) {
itemStackDeserilizeResult itm = itemStackDeserilize(s); itemStackDeserializeResult itm = itemStackDeserilize(s);
itt = itm.it; itt = itm.it;
if (itt != null && itt.getType() != Material.AIR) { if (itt != null && itt.getType() != Material.AIR) {
items.add(itt); items.add(itt);
@ -151,6 +214,12 @@ public class Items {
return inv; return inv;
} }
/**
* set all item in the list to their slot in inv
* @param list a list of item with their slot
* @param inv the destined inventory
* @return the inv
*/
public static Inventory setItemsToInventory(@NotNull HashMap<Integer, ItemStack> list, Inventory inv) { public static Inventory setItemsToInventory(@NotNull HashMap<Integer, ItemStack> list, Inventory inv) {
for (Map.Entry<Integer, ItemStack> entry : list.entrySet()) { for (Map.Entry<Integer, ItemStack> entry : list.entrySet()) {
inv.setItem(entry.getKey(), entry.getValue()); inv.setItem(entry.getKey(), entry.getValue());
@ -158,6 +227,12 @@ public class Items {
return inv; return inv;
} }
/**
* set all item in the list to their slot in inv
* @param list a list of item with their slot
* @param inv the player inventory
* @return the inv
*/
public static PlayerInventory setItemsToInventory(@NotNull HashMap<Integer, ItemStack> list, PlayerInventory inv) { public static PlayerInventory setItemsToInventory(@NotNull HashMap<Integer, ItemStack> list, PlayerInventory inv) {
for (Map.Entry<Integer, ItemStack> entry : list.entrySet()) { for (Map.Entry<Integer, ItemStack> entry : list.entrySet()) {
if (entry.getKey() == 40) { if (entry.getKey() == 40) {
@ -178,6 +253,12 @@ public class Items {
return inv; return inv;
} }
/**
* serialize an item
* @param stack the item
* @return a string
* @throws IllegalStateException stream errors
*/
private static @NotNull String itemTo64(ItemStack stack) throws IllegalStateException { private static @NotNull String itemTo64(ItemStack stack) throws IllegalStateException {
try { try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@ -193,6 +274,12 @@ public class Items {
} }
} }
/**
* deserialize item for string to itemstack
* @param data string
* @return itemstack
* @throws IOException stream error
*/
private static ItemStack itemFrom64(String data) throws IOException { private static ItemStack itemFrom64(String data) throws IOException {
try { try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
@ -208,6 +295,12 @@ public class Items {
} }
} }
/**
* return in correct naming each attributes,
* @param str the nbt attribute
* @return the good name
*/
@Deprecated
public static @NotNull String attributes(@NotNull String str) { public static @NotNull String attributes(@NotNull String str) {
String stt = ""; String stt = "";
if(str.contains("SPEED")) { if(str.contains("SPEED")) {
@ -232,6 +325,15 @@ public class Items {
} }
} }
/**
* set the attribute of an item
* @param main a main instance
* @param str the attribute
* @param nb how many of the attribute
* @param nbti the item
* @return an item
*/
@Deprecated
public static NBTItem setAttributes(Raxen main, @NotNull String str, Integer nb, NBTItem nbti) { public static NBTItem setAttributes(Raxen main, @NotNull String str, Integer nb, NBTItem nbti) {
switch (str) { switch (str) {
case "SPEED": case "SPEED":
@ -252,6 +354,12 @@ public class Items {
return nbti; return nbti;
} }
/**
* set the lore from the nbt
* @param it an itemstack
* @return the modified item
*/
@Deprecated
public static @NotNull ItemStack setLoreFromNBT(@NotNull ItemStack it) { public static @NotNull ItemStack setLoreFromNBT(@NotNull ItemStack it) {
ItemMeta itm = it.getItemMeta(); ItemMeta itm = it.getItemMeta();
List<Component> lore = new ArrayList<>(); List<Component> lore = new ArrayList<>();
@ -305,5 +413,4 @@ public class Items {
it.setItemMeta(itm); it.setItemMeta(itm);
return it; return it;
} }
} }

View file

@ -23,17 +23,34 @@ public class Reload implements Listener {
private static FileConfiguration config = Raxen.getPlugin().getConfig(); private static FileConfiguration config = Raxen.getPlugin().getConfig();
private static boolean serverReloading = true; private static boolean serverReloading = true;
/**
* kick all online players
*/
public static void kickAll() { public static void kickAll() {
for(Player player : Bukkit.getOnlinePlayers()) { for(Player player : Bukkit.getOnlinePlayers()) {
player.kick(colorTextComp(Raxen.getPrefix() + "\n<red>Server is Restarting</red>\n <red>Please Wait a few Minutes to reconnect.</red>")); player.kick(colorTextComp(Raxen.getPrefix() + "\n<red>Server is Restarting</red>\n <red>Please Wait a few Minutes to reconnect.</red>"));
} }
} }
/**
* change the server ping list
* @param e the server ping list event
*/
@EventHandler @EventHandler
public static void pingList(ServerListPingEvent e) throws IOException { public static void pingList(ServerListPingEvent e) {
setPingList(e); try {
setPingList(e);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} }
/**
* update ping list
* @param e the ping event
* @throws IOException file writing
*/
public static void setPingList(ServerListPingEvent e) throws IOException { public static void setPingList(ServerListPingEvent e) throws IOException {
if(serverReloading) { if(serverReloading) {
List<String> newLines = new ArrayList<>(); List<String> newLines = new ArrayList<>();

View file

@ -11,11 +11,18 @@ public class TabApi {
private ProtocolManager protocolManager; private ProtocolManager protocolManager;
private Raxen main; private Raxen main;
/**
* instance of tabapi
* @param main running instance of main
*/
public TabApi(Raxen main) { public TabApi(Raxen main) {
this.main = main; this.main = main;
this.protocolManager = main.getProtocolManager(); this.protocolManager = main.getProtocolManager();
} }
/**
* stuff for protocolmanager, used to add player and infos to the ping list
*/
public void packetListener() { public void packetListener() {
protocolManager.addPacketListener( protocolManager.addPacketListener(
new PacketAdapter(main, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) { new PacketAdapter(main, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {

View file

@ -18,15 +18,13 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
import java.util.Comparator;
public class Utils { public class Utils {
/** /**
* * convert a string with mini-message formatting to a colored Component
* @param stringToComponent a string * @param stringToComponent a string
* @return a component * @return a component
*/ */
@ -42,6 +40,11 @@ public class Utils {
return minimessage.deserialize(stringToComponent); return minimessage.deserialize(stringToComponent);
} }
/**
* convert a string with mini-message formatting to a colored TextComponent
* @param stringToComponent a string
* @return a component
*/
public static @NotNull TextComponent colorTextComp(String stringToComponent) { public static @NotNull TextComponent colorTextComp(String stringToComponent) {
MiniMessage minimessage = MiniMessage.builder() MiniMessage minimessage = MiniMessage.builder()
.tags(TagResolver.builder() .tags(TagResolver.builder()
@ -55,7 +58,7 @@ public class Utils {
} }
/** /**
* * change the mini-message colorized format to the legacy format, with §
* @param string a string * @param string a string
* @return a colored string * @return a colored string
*/ */
@ -71,6 +74,11 @@ public class Utils {
return LegacyComponentSerializer.legacyAmpersand().serialize(minimessage.deserialize(string)); return LegacyComponentSerializer.legacyAmpersand().serialize(minimessage.deserialize(string));
} }
/**
* change the mini-message colorized format to the legacy format, with §
* @param string a string
* @return a String
*/
public static String coloredString(String string) { public static String coloredString(String string) {
MiniMessage minimessage = MiniMessage.builder() MiniMessage minimessage = MiniMessage.builder()
.tags(TagResolver.builder() .tags(TagResolver.builder()
@ -84,6 +92,29 @@ public class Utils {
.serialize(minimessage.deserialize(string))); .serialize(minimessage.deserialize(string)));
} }
/**
* transform a text-component to a string
* @param comp a string
* @return a String
*/
public static String textCompToString(TextComponent comp) {
MiniMessage minimessage = MiniMessage.builder()
.tags(TagResolver.builder()
.resolver(StandardTags.color())
.resolver(StandardTags.decorations())
.resolver(StandardTags.reset())
.build()
)
.build();
return ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacyAmpersand()
.serialize(comp));
}
/**
* Strips all color from a string.
* @param string the string that want's to be decolored.
* @return a decolored string
*/
public static String decolor(String string) { public static String decolor(String string) {
return MiniMessage.miniMessage().stripTags(string); return MiniMessage.miniMessage().stripTags(string);
} }
@ -91,7 +122,7 @@ public class Utils {
/** /**
* debug output to console if debug is set to true in config * debug output to console if debug is set to true in config
* @param main Raxen instance * @param main Raxen instance
* @param strings ouptut to console * @param strings output to console
*/ */
public static void debug(Raxen main, String... strings) { public static void debug(Raxen main, String... strings) {
FileConfiguration config = main.getConfig(); FileConfiguration config = main.getConfig();
@ -132,12 +163,21 @@ public class Utils {
} }
} }
/**
* Log the strings to the console
* @param main a main instance running
* @param strings string that want to be outputted.
*/
public static void log(Raxen main, String... strings) { public static void log(Raxen main, String... strings) {
for(String string : strings) { for(String string : strings) {
main.getLogger().info(string); main.getLogger().info(string);
} }
} }
/**
* Log the strings to the console
* @param strings string that want to be outputted.
*/
public static void log(String... strings) { public static void log(String... strings) {
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen"); Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
assert main != null; assert main != null;
@ -146,6 +186,22 @@ public class Utils {
} }
} }
/**
* Log the TextComponent to the console
* @param comp TextComponent that want to be outputted.
*/
public static void log(TextComponent... comp) {
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
assert main != null;
for(TextComponent string : comp) {
main.getServer().sendMessage(string);
}
}
/**
* Warns strings to the console using the logger
* @param strings to warn message
*/
public static void warn(String... strings) { public static void warn(String... strings) {
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen"); Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
assert main != null; assert main != null;
@ -154,12 +210,21 @@ public class Utils {
} }
} }
/**
* Warns strings to the console using the logger
* @param strings to warn message
* @param main a running instance
*/
public static void warn(Raxen main, String... strings) { public static void warn(Raxen main, String... strings) {
for(String string : strings) { for(String string : strings) {
main.getLogger().warning(string); main.getLogger().warning(string);
} }
} }
/**
* Error strings to the console using the logger
* @param strings to error message
*/
public static void error(String... strings) { public static void error(String... strings) {
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen"); Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
assert main != null; assert main != null;
@ -168,34 +233,64 @@ public class Utils {
} }
} }
/**
* Error strings to the console using the logger
* @param strings to error message
* @param main a main instance running
*/
public static void error(Raxen main, String... strings) { public static void error(Raxen main, String... strings) {
for(String string : strings) { for(String string : strings) {
main.getLogger().severe(string); main.getLogger().severe(string);
} }
} }
/**
* message strings to player.
* @param player an online player
* @param strings strings that will be sent.
*/
public static void msgPlayer(Player player, String... strings) { public static void msgPlayer(Player player, String... strings) {
for(String string : strings) { for(String string : strings) {
player.sendMessage(colorComp(string)); player.sendMessage(colorComp(string));
} }
} }
public static void msgPlayer(Player player, TextComponent strings) { /**
player.sendMessage(colorComp(PlainTextComponentSerializer.plainText().serialize(strings))); * message textComponent to player.
* @param player an online player
* @param comp textComponent that will be sent.
*/
public static void msgPlayer(Player player, TextComponent comp) {
player.sendMessage(colorComp(PlainTextComponentSerializer.plainText().serialize(comp)));
} }
public static void msgSender(CommandSender player, TextComponent strings) { /**
player.sendMessage(colorComp(PlainTextComponentSerializer.plainText().serialize(strings))); * message the command sender with textComponent.
* @param player the command sender
* @param textComponent message
*/
public static void msgSender(CommandSender player, TextComponent textComponent) {
player.sendMessage(colorComp(PlainTextComponentSerializer.plainText().serialize(textComponent)));
} }
/**
* message the command sender with strings.
* @param player the command sender
* @param strings message
*/
public static void msgSender(CommandSender player, String... strings) { public static void msgSender(CommandSender player, String... strings) {
for(String string : strings) { for(String string : strings) {
player.sendMessage(colorComp(string)); player.sendMessage(colorComp(string));
} }
} }
/**
* fill an inventory with grey glass pane.
* @param inv an inventory
* @return the inventory filled
*/
public static Inventory fillGreyPane(Inventory inv) { public static Inventory fillGreyPane(Inventory inv) {
Integer in = -1; int in = -1;
for (ItemStack it : inv) { for (ItemStack it : inv) {
in++; in++;
if (it == null || it.getType() == Material.AIR) { if (it == null || it.getType() == Material.AIR) {
@ -205,14 +300,28 @@ public class Utils {
return inv; return inv;
} }
/**
* output message when player have no perms
* @return a component
*/
public static Component noPerms() { public static Component noPerms() {
return colorComp("<red>You don't have the permission to use this feature."); return colorComp("<red>You don't have the permission to use this feature.");
} }
/**
* error message output to player
* @return a component
*/
public static Component error() { public static Component error() {
return colorComp("<red>An Error has occurred. Please retry or contact an Admin."); return colorComp("<red>An Error has occurred. Please retry or contact an Admin.");
} }
/**
* Copy folder from sourceDirectoryLocation to destinationDirectoryLocation
* @param sourceDirectoryLocation the source directory
* @param destinationDirectoryLocation the copy location
* @throws IOException exception with coping data
*/
public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException {
Files.walk(Paths.get(sourceDirectoryLocation)) Files.walk(Paths.get(sourceDirectoryLocation))
.forEach(source -> { .forEach(source -> {
@ -226,6 +335,11 @@ public class Utils {
}); });
} }
/**
* remove path directory
* @param path removed folder
* @throws IOException error with handling data
*/
public static void removeDirectory(Path path) throws IOException { public static void removeDirectory(Path path) throws IOException {
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) { try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) {
@ -236,5 +350,4 @@ public class Utils {
} }
Files.delete(path); Files.delete(path);
} }
} }

View file

@ -10,8 +10,8 @@ public class Multiverse {
private MVWorldManager worldManager; private MVWorldManager worldManager;
public Multiverse() { public Multiverse() {
this.worldManager = core.getMVWorldManager();
this.core = (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core"); this.core = (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core");
this.worldManager = core.getMVWorldManager();
} }
public MVWorldManager getWorldManager() { public MVWorldManager getWorldManager() {