Added /giverandombook

This commit is contained in:
Auxilor 2021-04-12 22:15:01 +01:00
parent 0cf23543ea
commit 3b24f68415
4 changed files with 77 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import com.willfp.eco.util.TelekinesisUtils;
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
import com.willfp.ecoenchants.command.commands.CommandEcoreload;
import com.willfp.ecoenchants.command.commands.CommandEnchantinfo;
import com.willfp.ecoenchants.command.commands.CommandGiverandombook;
import com.willfp.ecoenchants.command.commands.CommandRandomenchant;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
import com.willfp.ecoenchants.config.RarityYml;
@ -182,7 +183,8 @@ public class EcoEnchantsPlugin extends EcoPlugin {
new CommandEcodebug(this),
new CommandEcoreload(this),
new CommandEnchantinfo(this),
new CommandRandomenchant(this)
new CommandRandomenchant(this),
new CommandGiverandombook(this)
);
}

View File

@ -0,0 +1,64 @@
package com.willfp.ecoenchants.command.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterRandomEnchant;
import com.willfp.ecoenchants.display.EnchantmentCache;
import org.bukkit.Bukkit;
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 org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandGiverandombook extends AbstractCommand {
/**
* Instantiate a new /ecoreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandGiverandombook(@NotNull final EcoPlugin plugin) {
super(plugin, "giverandombook", "ecoenchants.randombook", false);
}
@Override
public AbstractTabCompleter getTab() {
return new TabCompleterRandomEnchant(this);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("requires-player"));
return;
}
Player player = Bukkit.getServer().getPlayer(args.get(0));
if (player == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
ItemStack itemStack = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemStack.getItemMeta();
Enchantment enchantment = Enchantment.values()[NumberUtils.randInt(0, Enchantment.values().length - 1)];
int level = NumberUtils.randInt(1, enchantment.getMaxLevel());
meta.addStoredEnchant(enchantment, level, true);
itemStack.setItemMeta(meta);
String message = this.getPlugin().getLangYml().getMessage("gave-random-book");
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
sender.sendMessage(message);
String message2 = this.getPlugin().getLangYml().getMessage("received-random-book");
message2 = message2.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
player.sendMessage(message2);
}
}

View File

@ -20,7 +20,10 @@ messages:
must-hold-item: "&cYou must be holding an enchantable item!"
no-enchants-available: "&fNo available enchantments found for this item!"
applied-random-enchant: "&fAdded %enchantment% to your item!"
gave-random-book: "&fGave %enchantment% book!"
received-random-book: "&fYou have received a %enchantment% book!"
invalid-player: "&cInvalid Player!"
requires-player: "&cRequires a Player!"
must-hold-item-other: "&cPlayer is not holding an enchantable item!"
no-targets: "&cCannot be applied"

View File

@ -36,6 +36,9 @@ commands:
randomenchant:
description: Adds a random enchantment to an item
permission: ecoenchants.randomenchant
giverandombook:
description: Gives a book containing a random enchantment
permission: ecoenchants.randombook
permissions:
ecoenchants.*:
@ -49,6 +52,7 @@ permissions:
ecoenchants.ecodebug: true
ecoenchants.randomenchant: true
ecoenchants.randomenchant.bypasshardcap: true
ecoenchants.randombook: true
ecoenchants.anvil.*: true
ecoenchants.anvil.*:
description: Allows all anvil permissions
@ -72,6 +76,9 @@ permissions:
ecoenchants.enchantinfo:
description: Allows the use of /enchantinfo to show enchant info
default: true
ecoenchants.randombook:
description: Allows the use of /giverandombook to give a book with a random enchantment
default: op
ecoenchants.randomenchant:
description: Allows the use of /randomenchant to apply a random enchantment to an item
default: op