This commit is contained in:
parent
7cc9395cbc
commit
1380e7479a
11 changed files with 45 additions and 77 deletions
|
@ -4,6 +4,7 @@ import me.unurled.sacredrealms.sr.SR;
|
||||||
import me.unurled.sacredrealms.sr.commands.admin.AttributeCommand;
|
import me.unurled.sacredrealms.sr.commands.admin.AttributeCommand;
|
||||||
import me.unurled.sacredrealms.sr.commands.player.ResetAdventureCommand;
|
import me.unurled.sacredrealms.sr.commands.player.ResetAdventureCommand;
|
||||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
|
||||||
public class CommandManager extends Manager {
|
public class CommandManager extends Manager {
|
||||||
|
|
||||||
|
@ -11,10 +12,17 @@ public class CommandManager extends Manager {
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
super.load();
|
super.load();
|
||||||
SR.getInstance().getCommand("attributes").setExecutor(new AttributeCommand());
|
SR instance = SR.getInstance();
|
||||||
SR.getInstance().getCommand("attributes").setTabCompleter(new AttributeCommand());
|
PluginCommand attributes = instance.getCommand("attributes");
|
||||||
|
if (attributes != null) {
|
||||||
|
attributes.setExecutor(new AttributeCommand());
|
||||||
|
attributes.setTabCompleter(new AttributeCommand());
|
||||||
|
}
|
||||||
|
|
||||||
SR.getInstance().getCommand("resetadventure").setExecutor(new ResetAdventureCommand());
|
PluginCommand resetadventure = instance.getCommand("resetadventure");
|
||||||
SR.getInstance().getCommand("resetadventure").setTabCompleter(new ResetAdventureCommand());
|
if (resetadventure != null) {
|
||||||
|
resetadventure.setExecutor(new ResetAdventureCommand());
|
||||||
|
resetadventure.setTabCompleter(new ResetAdventureCommand());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,12 +133,19 @@ public class ResetAdventureCommand implements TabExecutor {
|
||||||
if (args[0].isBlank()) {
|
if (args[0].isBlank()) {
|
||||||
return Arrays.stream(Bukkit.getOfflinePlayers())
|
return Arrays.stream(Bukkit.getOfflinePlayers())
|
||||||
.map(OfflinePlayer::getName)
|
.map(OfflinePlayer::getName)
|
||||||
.toList().stream().limit(10).toList();
|
.toList()
|
||||||
|
.stream()
|
||||||
|
.limit(10)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
return Arrays.stream(Bukkit.getOfflinePlayers())
|
return Arrays.stream(Bukkit.getOfflinePlayers())
|
||||||
.map(OfflinePlayer::getName).filter(Objects::nonNull)
|
.map(OfflinePlayer::getName)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
.filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
|
.filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||||
.toList().stream().limit(10).toList();
|
.toList()
|
||||||
|
.stream()
|
||||||
|
.limit(10)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public enum Attribute {
|
||||||
return minValue;
|
return minValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("SameReturnValue")
|
||||||
public PersistentDataType<Double, Double> getType() {
|
public PersistentDataType<Double, Double> getType() {
|
||||||
return PersistentDataType.DOUBLE;
|
return PersistentDataType.DOUBLE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,13 @@ import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("EmptyMethod")
|
||||||
public class CombatManager extends Manager {
|
public class CombatManager extends Manager {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDamage(EntityDamageByBlockEvent e) {
|
public void onDamage(@NotNull EntityDamageByBlockEvent e) {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
// blast enchant :shrug:
|
// blast enchant :shrug:
|
||||||
// fall damage, fire damage, etc
|
// fall damage, fire damage, etc
|
||||||
|
@ -31,7 +33,7 @@ public class CombatManager extends Manager {
|
||||||
|
|
||||||
// TODO: Finish this
|
// TODO: Finish this
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDamage(EntityDamageByEntityEvent e) {
|
public void onDamage(@NotNull EntityDamageByEntityEvent e) {
|
||||||
e.setDamage(0.0);
|
e.setDamage(0.0);
|
||||||
|
|
||||||
if (!(e.getDamager() instanceof LivingEntity damager)
|
if (!(e.getDamager() instanceof LivingEntity damager)
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class EntityManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntitySpawn(EntitySpawnEvent e) {
|
public void onEntitySpawn(@NotNull EntitySpawnEvent e) {
|
||||||
if (e.getEntity() instanceof Player) return;
|
if (e.getEntity() instanceof Player) return;
|
||||||
|
|
||||||
if (isSREntity(e.getEntity().getUniqueId())) return;
|
if (isSREntity(e.getEntity().getUniqueId())) return;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
|
||||||
|
@SuppressWarnings("EmptyMethod")
|
||||||
public class ItemManager extends Manager {
|
public class ItemManager extends Manager {
|
||||||
public static final NamespacedKey ID = new NamespacedKey("sr", "id");
|
public static final NamespacedKey ID = new NamespacedKey("sr", "id");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.unurled.sacredrealms.sr.components.item.abilities;
|
package me.unurled.sacredrealms.sr.components.item.abilities;
|
||||||
|
|
||||||
/** Represents an ability that an item can have. TODO: Implement this class */
|
/** Represents an ability that an item can have. TODO: Implement this class */
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Ability {
|
public class Ability {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
|
@ -40,11 +40,19 @@ public class PlayerManager extends Manager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DataHandler dh = dm.getDataHandler();
|
DataHandler dh = dm.getDataHandler();
|
||||||
}
|
// save all players
|
||||||
|
Gson gson =
|
||||||
|
new GsonBuilder()
|
||||||
|
.excludeFieldsWithoutExposeAnnotation()
|
||||||
|
.registerTypeAdapter(Inventory.class, new InventorySerializer())
|
||||||
|
.registerTypeAdapter(PotionEffect.class, new PotionEffectSerializer())
|
||||||
|
.create();
|
||||||
|
for (SRPlayer player : players.values()) {
|
||||||
|
dh.set(PLAYER_KEY + player.getUuid(), gson.toJson(player));
|
||||||
|
}
|
||||||
|
|
||||||
/** Load the data */
|
players.clear();
|
||||||
/*@Override
|
}
|
||||||
public void loadData() {}*/
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public SRPlayer getPlayer(UUID uuid) {
|
public SRPlayer getPlayer(UUID uuid) {
|
||||||
|
@ -89,7 +97,7 @@ public class PlayerManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(@NotNull PlayerQuitEvent e) {
|
||||||
SRPlayer player = getPlayer(e.getPlayer().getUniqueId());
|
SRPlayer player = getPlayer(e.getPlayer().getUniqueId());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package me.unurled.sacredrealms.sr.data;
|
package me.unurled.sacredrealms.sr.data;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -14,14 +13,6 @@ public interface DataHandler {
|
||||||
*/
|
*/
|
||||||
String get(@NotNull String key);
|
String get(@NotNull String key);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a value from the data source
|
|
||||||
*
|
|
||||||
* @param key The key to get the value from
|
|
||||||
* @return The value of the key
|
|
||||||
*/
|
|
||||||
Object getGson(@NotNull String key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value in the data source
|
* Set a value in the data source
|
||||||
*
|
*
|
||||||
|
@ -30,23 +21,6 @@ public interface DataHandler {
|
||||||
*/
|
*/
|
||||||
void set(@NotNull String key, @Nullable String value);
|
void set(@NotNull String key, @Nullable String value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a value in the data source
|
|
||||||
*
|
|
||||||
* @param key The key to set the value to
|
|
||||||
* @param value The value to set
|
|
||||||
*/
|
|
||||||
void set(@NotNull String key, Gson value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a value to the data source
|
|
||||||
*
|
|
||||||
* @param key The key to append the value to
|
|
||||||
* @param path The path to append the value to
|
|
||||||
* @param json The json to append
|
|
||||||
*/
|
|
||||||
void jsonAppend(@NotNull String key, @NotNull String path, @NotNull Object... json);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a value from the data source
|
* Remove a value from the data source
|
||||||
*
|
*
|
||||||
|
@ -56,6 +30,7 @@ public interface DataHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a key exists in the data source
|
* Check if a key exists in the data source
|
||||||
|
*
|
||||||
* @param key The key to check
|
* @param key The key to check
|
||||||
* @return If the key exists
|
* @return If the key exists
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,11 +2,9 @@ package me.unurled.sacredrealms.sr.data;
|
||||||
|
|
||||||
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
import static me.unurled.sacredrealms.sr.utils.Logger.error;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import me.unurled.sacredrealms.sr.SR;
|
import me.unurled.sacredrealms.sr.SR;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import redis.clients.jedis.JedisPooled;
|
import redis.clients.jedis.JedisPooled;
|
||||||
import redis.clients.jedis.json.Path2;
|
|
||||||
|
|
||||||
public class Redis implements DataHandler {
|
public class Redis implements DataHandler {
|
||||||
|
|
||||||
|
@ -41,17 +39,6 @@ public class Redis implements DataHandler {
|
||||||
return client.get(key);
|
return client.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a value from the data source
|
|
||||||
*
|
|
||||||
* @param key The key to get the value from
|
|
||||||
* @return The value of the key
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getGson(@NotNull String key) {
|
|
||||||
return client.jsonGet(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value in the data source
|
* Set a value in the data source
|
||||||
*
|
*
|
||||||
|
@ -63,28 +50,6 @@ public class Redis implements DataHandler {
|
||||||
client.set(key, value);
|
client.set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a value in the data source
|
|
||||||
*
|
|
||||||
* @param key The key to set the value to
|
|
||||||
* @param value The value to set
|
|
||||||
*/
|
|
||||||
public void set(@NotNull String key, Gson value) {
|
|
||||||
client.jsonSet(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a value to the data source
|
|
||||||
*
|
|
||||||
* @param key The key to append the value to
|
|
||||||
* @param path The path to append the value to
|
|
||||||
* @param json The json to append
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void jsonAppend(@NotNull String key, @NotNull String path, @NotNull Object... json) {
|
|
||||||
client.jsonArrAppend(key, Path2.of(path), json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a value from the data source
|
* Remove a value from the data source
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public class Items {
|
public class Items {
|
||||||
public static @NotNull Double getTotalAttribute(Player player, Attribute attribute) {
|
public static @NotNull Double getTotalAttribute(Player player, Attribute attribute) {
|
||||||
return getTotalAttribute(player.getEquipment(), attribute);
|
return getTotalAttribute(player.getEquipment(), attribute);
|
||||||
|
@ -63,7 +64,6 @@ public class Items {
|
||||||
* <dark_purple>Enchantments: <blue>➤ Enchantment <if max level gold>1 <blue>➤ Enchantment <if max
|
* <dark_purple>Enchantments: <blue>➤ Enchantment <if max level gold>1 <blue>➤ Enchantment <if max
|
||||||
* level gold>2
|
* level gold>2
|
||||||
*
|
*
|
||||||
* @param item the item
|
|
||||||
* @param stack the itemstack
|
* @param stack the itemstack
|
||||||
* @return the itemstack with lore
|
* @return the itemstack with lore
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue