Filled EnchantAll

Discussion in 'Archived: Plugin Requests' started by MinecraftPlayer8, Apr 2, 2014.

  1. Plugin category: Admin-Tools, General

    Suggested name: EnchantAll

    What I want: When you use /enchant all you will get all enchants (highest enchants) on example a diamond sword. The plugin muss not overwrite the Essentials plugin so you can still use /enchant efficiency 3 (example) or /enchant sharpness 2.

    Ideas for commands: /enchant all

    Ideas for permissions: EnchantAll.use (use for the /enchant all command)

    When I'd like it by: Whenever you finish it
    Additional Info: Can the creator of this plugin release the source code so i can learn from it
     
  2. Offline

    kungfuko

    timtheenchanter
     
  3. The plugin overwrites Essentials.
     
  4. Offline

    kungfuko

    No

    And tag me next time

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    au2001

    MinecraftPlayer8
    Here is the source code for it (to get the plugin, compile it with eclipse) :
    EnchantAll.class :
    Code:java
    1. package me.au2001.EnchantAll;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.enchantments.Enchantment;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class EnchantAll extends JavaPlugin {
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. public static EnchantAll plugin;
    16.  
    17. public void onEnable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info("[" + pdfFile.getName() + "] v" + pdfFile.getVersion() + " is enabled!");
    20. }
    21.  
    22. public void onDisable() {
    23. PluginDescriptionFile pdfFile = this.getDescription();
    24. this.logger.info("[" + pdfFile.getName() + "] is disabled!");
    25. }
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    28. if (commandLabel.equalsIgnoreCase("enchantme")) {
    29. if (sender instanceof Player) {
    30. if (sender.hasPermission("echantme.use")) {
    31. if (args.length == 2) {
    32. if (Enchantment.getByName(args[0]) != null) {
    33. Player player = (Player)sender;
    34. int level = Integer.parseInt(args[1].replaceAll("[\\D]", ""));
    35. player.getItemInHand().addUnsafeEnchantment(Enchantment.getByName(args[0]), level);
    36. sender.sendMessage(ChatColor.GREEN + "This item has successfully been enchanted.");
    37. } else {
    38. sender.sendMessage(ChatColor.RED + "This enchantment doesn't exists.");
    39. }
    40. } else {
    41. sender.sendMessage(ChatColor.RED + "Wrong number of command parameters.");
    42. }
    43. } else {
    44. sender.sendMessage(ChatColor.RED + "You don't have permissions to execute this command.");
    45. }
    46. } else {
    47. sender.sendMessage("You must be a player to execute this command.");
    48. }
    49. return true;
    50. }
    51. return false;
    52. }
    53. }


    plugin.yml :
    Code:text
    1. name: EnchantAll
    2. main: me.au2001. EnchantAll. EnchantAll
    3. version: 1.0
    4. descirption: >
    5. Plugin description!
    6. commands:
    7. enchantme:
    8. description: Enchants an item.
    9. permissions:
    10. enchantme.use:
    11. description: Give access to the /enchantme command.
     
  6. Online

    timtower Administrator Administrator Moderator

    au2001 That will probaby override, or be overridden by essentials as far as I know.
     
  7. Offline

    au2001

    timtower
    No, that's why the command is /enchantME and not /enchant.
     
  8. Online

    timtower Administrator Administrator Moderator

    Whoops, missed that, my bad.
     
  9. I think the plugin.yml is not correct.
     
  10. Offline

    au2001

    Do you want me to compile it for you?
    Or what's your error?
     
  11. If you can compile (how do i copy a code from a console?)
     
  12. Offline

    au2001

    MinecraftPlayer8
    Do you mean the minecraft console of your server?
    If so, just select and do ctrl+c (or cmd+c on a mac) then paste it here (ctrl+v or cmd+v).
     
  13. Offline

    Maurdekye

    au2001 Here, don't get all complicated; he doesn't know how to compile code. Besides, I can write him a plugin that uses the /enchant command without overwriting Essentials.
     
  14. Offline

    au2001

  15. Offline

    Maurdekye

  16. Offline

    au2001

    Maurdekye
    I tested that, it's overridden by minecraft vanilla command
     
  17. Offline

    Maurdekye

    Last edited by a moderator: Jun 7, 2016
  18. Offline

    Maurdekye

    MinecraftPlayer8 au2001 By the way, here's the source;
    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.enchantments.Enchantment;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.EventPriority;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class EnchantAll extends JavaPlugin implements Listener {
    13. public void onEnable() {
    14. Bukkit.getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. @EventHandler(priority = EventPriority.HIGHEST)
    18. public void PreCommand(PlayerCommandPreprocessEvent event) {
    19. Player sender = event.getPlayer();
    20. if (!event.getPlayer().hasPermission("enchantall.use")) return;
    21. String[] commargs = event.getMessage().split(" +");
    22. if (commargs.length < 2) return;
    23. if (commargs[0].equalsIgnoreCase("/enchant") && commargs[1].equalsIgnoreCase("all")) {
    24. event.setCancelled(true);
    25. ItemStack held = sender.getItemInHand();
    26. boolean enchanted = false;
    27. for (Enchantment ench : Enchantment.values()) {
    28. try {
    29. held.addEnchantment(ench, ench.getMaxLevel());
    30. enchanted = true;
    31. } catch (Exception ignored) {}
    32. }
    33. String goodname = held.getType().name().replaceAll("_", " ").toLowerCase();
    34. if (enchanted)
    35. sender.sendMessage(ChatColor.AQUA + "Fully enchanted your " + goodname);
    36. else
    37. sender.sendMessage(ChatColor.GRAY + "You can't enchant " + goodname + "!");
    38. }
    39. }
    40. }
     
  19. Offline

    au2001

    Maurdekye
    So, would that work?
    Code:java
    1. package me.au2001.EnchantAll;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.enchantments.Enchantment;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.EventPriority;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class EnchantAll extends JavaPlugin implements Listener {
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public static EnchantAll plugin;
    19.  
    20. public void onEnable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. Bukkit.getPluginManager().registerEvents(this, this);
    23. this.logger.info("[" + pdfFile.getName() + "] v" + pdfFile.getVersion() + " is enabled!");
    24. }
    25.  
    26. public void onDisable() {
    27. PluginDescriptionFile pdfFile = this.getDescription();
    28. this.logger.info("[" + pdfFile.getName() + "] is disabled!");
    29. }
    30.  
    31. @EventHandler(priority=EventPriority.HIGHEST)
    32. public void beforeCommand (PlayerCommandPreprocessEvent event) {
    33. Player sender = event.getPlayer();
    34. String[] args = event.getMessage().split(" +");
    35. String commandLabel = args[0];
    36. if (commandLabel.equalsIgnoreCase("/enchant")) {
    37. if (sender.hasPermission("echantall.use")) {
    38. if (args.length == 2) {
    39. if (Enchantment.getByName(args[1]) != null) {
    40. Player player = (Player)sender;
    41. int level = Integer.parseInt(args[2].replaceAll("[\\D]", ""));
    42. player.getItemInHand().addUnsafeEnchantment(Enchantment.getByName(args[0]), level);
    43. sender.sendMessage(ChatColor.GREEN + "This item has successfully been enchanted.");
    44. } else {
    45. sender.sendMessage(ChatColor.RED + "This enchantment doesn't exists.");
    46. }
    47. } else {
    48. sender.sendMessage(ChatColor.RED + "Wrong number of command parameters.");
    49. }
    50. } else {
    51. sender.sendMessage(ChatColor.RED + "You don't have permissions to execute this command.");
    52. }
    53. event.setCancelled(true);
    54. }
    55. }
    56. }
     
  20. Offline

    Maurdekye

    au2001 The code you posted? I'm fairly sure it would overwrite the default /enchant command on most occasions, which is what you don't want.
     
  21. Offline

    au2001

    MinecraftPlayer8
    Why do you want to keep the essentials command?
    If our plugin does the same thing, it wouldn't change anything.

    @Murdekye
    But when I try it, it doesn't do anything!
    The default command is called and nothing else...
     
  22. Offline

    killerbigmacs

    Just use TimTheEnchanter, it isn't over ridden by essentials and you can do any levels up to 1000
     
  23. killerbigmacs I am not requesting a plugin that can enchant higher than the normal enchants.
     
  24. Offline

    Onlineids

    What exactly are you asking for then? A command that gets the item in your hand and enchants it to the highest legit level?
     
  25. Yes Onlineids but Maurdeky made it.
     
  26. Offline

    au2001

    MinecraftPlayer8
    If the command is /enchantall, is it ok? Would be really simple to do.
     
  27. au2001 He already made it.
     
  28. Offline

    au2001

    Ya sorry, thought the link was broken
     

Share This Page