Skip to content

Commit

Permalink
Merge branch 'release/1.0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxlego08 committed Aug 2, 2024
2 parents 6534604 + 00d5040 commit 652cd84
Show file tree
Hide file tree
Showing 19 changed files with 1,149 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.maxlego08.essentials.api.chat.InteractiveChat;
import fr.maxlego08.essentials.api.commands.CommandManager;
import fr.maxlego08.essentials.api.economy.EconomyManager;
import fr.maxlego08.essentials.api.enchantment.Enchantments;
import fr.maxlego08.essentials.api.hologram.HologramManager;
import fr.maxlego08.essentials.api.kit.Kit;
import fr.maxlego08.essentials.api.modules.ModuleManager;
Expand Down Expand Up @@ -244,4 +245,6 @@ public interface EssentialsPlugin extends Plugin {
VaultManager getVaultManager();

InteractiveChat startInteractiveChat(Player player, Consumer<String> consumer, long expiredAt);

Enchantments getEnchantments();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public enum Permission {
ESSENTIALS_VOTEPARTY_USE, ESSENTIALS_VOTEPARTY_SET,
ESSENTIALS_VOTEPARTY_REMOVE, ESSENTIALS_VOTEPARTY_ADD,
ESSENTIALS_VOTE_USE, ESSENTIALS_VOTE_SET,
ESSENTIALS_VOTE_REMOVE, ESSENTIALS_VOTE_ADD, VAULT_USE, VAULT_SET_SLOT, VAULT_ADD_SLOT;
ESSENTIALS_VOTE_REMOVE, ESSENTIALS_VOTE_ADD, VAULT_USE, VAULT_SET_SLOT, VAULT_ADD_SLOT, ESSENTIALS_ENCHANT;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.maxlego08.essentials.api.enchantment;

import java.util.List;
import java.util.Optional;

public interface Enchantments {

Optional<EssentialsEnchantment> getEnchantments(String enchantment);

void register();

List<String> getEnchantments();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fr.maxlego08.essentials.api.enchantment;

import org.bukkit.enchantments.Enchantment;

import java.util.List;

public interface EssentialsEnchantment {

Enchantment enchantment();

List<String> aliases();

}
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public enum Message {
DESCRIPTION_VOTE_SET("Set the number of votes for a player"),
DESCRIPTION_VOTE_ADD("Add votes to a player"),
DESCRIPTION_VOTE_REMOVE("Remove votes from a player"),
DESCRIPTION_ENCHANT("Add enchant to an item"),


YOU("you"),
Expand Down Expand Up @@ -667,6 +668,15 @@ public enum Message {
COMMAND_VAULT_RENAME_ERROR("<error>You cannot use this name for your vault."),
COMMAND_VAULT_RENAME_RESET("<success>You just reset the name of your vault."),

COMMAND_ENCHANT_INVALID("<error>You need to specify a valid player."),
COMMAND_ENCHANT_ERROR_ENCHANT("<error>Impossible to find the enchantment &f%name%<error>."),
COMMAND_ENCHANT_ERROR_ITEM_SELF("<error>You must have an item in your hand."),
COMMAND_ENCHANT_ERROR_ITEM_PLAYER("<error>%player% has no item in his hand."),
COMMAND_ENCHANT_REMOVE_SELF("<success>The enchantment &f%enchant% <success>has been removed from your item in hand."),
COMMAND_ENCHANT_REMOVE_PLAYER("<success>The enchantment &f%enchant% <success>has been removed from the item from &f%player%’s<succes> hand."),
COMMAND_ENCHANT_SUCCESS_SELF("<success>The enchantment &f%enchant% <success>has been applied to your item in hand."),
COMMAND_ENCHANT_SUCCESS_PLAYER("<success>The enchantment &f%enchant% <success>has been applied to the item from &f%player%’s<succes> hand."),

;

private EssentialsPlugin plugin;
Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Unreleased

# 1.0.0.2

- Added the command `/ess convert EssentialsX`, allows converting the database from EssentialsX to zEssentials.
Documentation: https://zessentials.groupez.dev/getting-started/convert#essentialsx
- Fixed the scoreboard title not appearing
- Added `/homes` alias for `/home` command for default configurations
- Added `/enchant` command
- Added enchantments list with aliases
- Added dutch translation [#19](https://github.com/Maxlego08/zEssentials/pull/19)

# 1.0.0.1

- Added the command `/ess convert CMI`, allows converting the database from CMI to zEssentials.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.0.0.1
version=1.0.0.2
systemProp.file.encoding=utf-8
9 changes: 9 additions & 0 deletions src/main/java/fr/maxlego08/essentials/ZEssentialsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fr.maxlego08.essentials.api.chat.InteractiveChat;
import fr.maxlego08.essentials.api.commands.CommandManager;
import fr.maxlego08.essentials.api.economy.EconomyManager;
import fr.maxlego08.essentials.api.enchantment.Enchantments;
import fr.maxlego08.essentials.api.hologram.HologramManager;
import fr.maxlego08.essentials.api.kit.Kit;
import fr.maxlego08.essentials.api.modules.ModuleManager;
Expand Down Expand Up @@ -47,6 +48,7 @@
import fr.maxlego08.essentials.commands.ZCommandManager;
import fr.maxlego08.essentials.commands.commands.essentials.CommandEssentials;
import fr.maxlego08.essentials.economy.EconomyModule;
import fr.maxlego08.essentials.enchantments.ZEnchantments;
import fr.maxlego08.essentials.hologram.HologramModule;
import fr.maxlego08.essentials.kit.KitModule;
import fr.maxlego08.essentials.listener.PlayerListener;
Expand Down Expand Up @@ -142,6 +144,7 @@ public final class ZEssentialsPlugin extends ZPlugin implements EssentialsPlugin

private final UUID consoleUniqueId = UUID.fromString("00000000-0000-0000-0000-000000000000");
private final List<Material> materials = Arrays.stream(Material.values()).filter(e -> !e.name().startsWith("LEGACY_")).toList();
private final Enchantments enchantments = new ZEnchantments();
private EssentialsUtils essentialsUtils;
private ServerStorage serverStorage = new ZServerStorage(this);
private InventoryManager inventoryManager;
Expand All @@ -157,6 +160,7 @@ public void onEnable() {

this.saveDefaultConfig();
this.saveOrUpdateConfiguration("config.yml", true);
this.enchantments.register();

FoliaLib foliaLib = new FoliaLib(this);
this.serverImplementation = foliaLib.getImpl();
Expand Down Expand Up @@ -639,4 +643,9 @@ public InteractiveChat startInteractiveChat(Player player, Consumer<String> cons
this.interactiveChatHelper.register(player, interactiveChat);
return interactiveChat;
}

@Override
public Enchantments getEnchantments() {
return this.enchantments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import fr.maxlego08.essentials.commands.commands.utils.CommandRules;
import fr.maxlego08.essentials.commands.commands.utils.CommandTrash;
import fr.maxlego08.essentials.commands.commands.utils.CommandVersion;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandEnchant;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandFly;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandGod;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandInvsee;
Expand Down Expand Up @@ -191,7 +192,7 @@ public void loadCommands(CommandManager commandManager) {

register("sethome", CommandSetHome.class, "hcreate", "hc");
register("delhome", CommandDelHome.class, "hdelete", "hd");
register("home", CommandHome.class, "h");
register("home", CommandHome.class, "h", "homes");

register("ban", CommandBan.class);
register("mute", CommandMute.class);
Expand Down Expand Up @@ -223,6 +224,7 @@ public void loadCommands(CommandManager commandManager) {
register("killall", CommandKillAll.class);
register("seen", CommandSeen.class, "whois");
register("seenip", CommandSeenIp.class, "whoisip");
register("enchant", CommandEnchant.class, "enchantment");

register("kit", CommandKit.class, "kits");
register("showkit", CommandShowKit.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.convert.cmi.CMIConvert;
import fr.maxlego08.essentials.convert.essentialsx.EssentialsXConvert;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;

import java.util.Arrays;
Expand All @@ -29,6 +30,14 @@ protected CommandResultType perform(EssentialsPlugin plugin) {
return CommandResultType.SUCCESS;
}

if (pluginName.equalsIgnoreCase("EssentialsX")) {

EssentialsXConvert essentialsXConvert = new EssentialsXConvert(plugin);
essentialsXConvert.convert(sender);

return CommandResultType.SUCCESS;
}

return CommandResultType.SYNTAX_ERROR;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package fr.maxlego08.essentials.commands.commands.utils.admins;

import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;

import java.util.Arrays;

public class CommandEnchant extends VCommand {
public CommandEnchant(EssentialsPlugin plugin) {
super(plugin);
this.setPermission(Permission.ESSENTIALS_ENCHANT);
this.setDescription(Message.DESCRIPTION_ENCHANT);
this.addRequireArg("enchantment", (a, b) -> plugin.getEnchantments().getEnchantments());
this.addRequireArg("level", (a, b) -> Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"));
this.addOptionalArg("player");
}

@Override
protected CommandResultType perform(EssentialsPlugin plugin) {

String enchantAsString = this.argAsString(0);
int level = this.argAsInteger(1);
Player player = this.argAsPlayer(2, this.player);

if (level < 0) return CommandResultType.SYNTAX_ERROR;

if (player == null) {
message(sender, Message.COMMAND_SPEED_INVALID);
return CommandResultType.DEFAULT;
}

var optional = plugin.getEnchantments().getEnchantments(enchantAsString);
if (optional.isEmpty()) {
message(sender, Message.COMMAND_ENCHANT_ERROR_ENCHANT, "%enchant%", enchantAsString);
return CommandResultType.DEFAULT;
}

Enchantment enchantment = optional.get().enchantment();
ItemStack itemStack = player.getInventory().getItemInMainHand();
if (itemStack.getType().isAir()) {
message(sender, player, Message.COMMAND_ENCHANT_ERROR_ITEM_SELF, Message.COMMAND_ENCHANT_ERROR_ITEM_PLAYER);
return CommandResultType.DEFAULT;
}

enchant(itemStack, enchantment, level);
String translatedEnchantments = "<lang:" + enchantment.translationKey() + ">";

if (level == 0) {
message(sender, player, Message.COMMAND_ENCHANT_REMOVE_SELF, Message.COMMAND_ENCHANT_REMOVE_PLAYER, "%enchant%", translatedEnchantments);
} else {
message(sender, player, Message.COMMAND_ENCHANT_SUCCESS_SELF, Message.COMMAND_ENCHANT_SUCCESS_PLAYER, "%enchant%", translatedEnchantments);
}

return CommandResultType.SUCCESS;
}

private void message(CommandSender sender, Player player, Message messageSelf, Message messagePlayer, Object... objects) {

int newSize = objects.length + 2;
Object[] newObjects = new Object[newSize];
System.arraycopy(objects, 0, newObjects, 0, objects.length);
newObjects[objects.length] = "%player%";
newObjects[objects.length + 1] = player.getName();

message(sender, sender == player ? messageSelf : messagePlayer, newObjects);
}

private void enchant(ItemStack itemStack, Enchantment enchantment, int level) {
if (itemStack.getType() == Material.ENCHANTED_BOOK) {
var enchantmentStorageMeta = (EnchantmentStorageMeta) itemStack.getItemMeta();
if (level == 0) enchantmentStorageMeta.removeStoredEnchant(enchantment);
else enchantmentStorageMeta.addStoredEnchant(enchantment, level, true);
itemStack.setItemMeta(enchantmentStorageMeta);
} else {
if (level == 0) itemStack.removeEnchantment(enchantment);
else itemStack.addUnsafeEnchantment(enchantment, level);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void startConvertDatabase(CommandSender sender, SqlStorage sqlStorage) {
List<CMIUser> cmiUsers = requestHelper.select("users", CMIUser.class, table -> {
});

message(sender, "&aRecovery &f" + cmiUsers.size() + " &ausers.");
message(sender, "&aFound &f" + cmiUsers.size() + " &ausers.");

var userRepository = sqlStorage.with(UserRepository.class);
var userEconomyRepository = sqlStorage.with(UserEconomyRepository.class);
Expand Down
Loading

0 comments on commit 652cd84

Please sign in to comment.