Skip to content

Commit

Permalink
Add /enchant max level
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan committed Mar 25, 2017
1 parent 91d3bed commit 93b14f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import bammerbom.ultimatecore.sponge.api.permission.Permission;
import bammerbom.ultimatecore.sponge.api.permission.PermissionLevel;
import bammerbom.ultimatecore.sponge.api.permission.PermissionOption;
import org.spongepowered.api.text.Text;

public class ItemPermissions {
Expand Down Expand Up @@ -54,4 +55,6 @@ public class ItemPermissions {
// public static Permission UC_ITEM_BOOKEDIT_BASE = Permission.create("uc.item.bookedit.base", "item", PermissionLevel.ADMIN, "bookedit", Text.of("Allows you to use the bookedit command."));
// public static Permission UC_ITEM_FIREWORK_BASE = Permission.create("uc.item.firework.base", "item", PermissionLevel.ADMIN, "firework", Text.of("Allows you to use the firework command."));
// public static Permission UC_ITEM_LEATHERARMORCOLOR_BASE = Permission.create("uc.item.leatherarmorcolor.base", "item", PermissionLevel.ADMIN, "leatherarmorcolor", Text.of("Allows you to use the leatherarmorcolor command."));

public static PermissionOption UC_ITEM_ITEMENCHANT_MAXLEVEL = PermissionOption.create("uc.item.itemenchant.maxlevel", "item", "itemenchant", "10", Text.of("The maximum level an item can be enchanted by this player using /enchant."));
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public CommandResult execute(CommandSource sender, CommandContext args) throws C
Enchantment ench = args.<Enchantment>getOne("enchantment").get();
int level = args.hasAny("level") ? args.<Integer>getOne("level").get() : 1;

if(level > ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p)){
throw Messages.error(p, "item.command.itemenchant.maxlevel", "%max%", ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p));
}

List<ItemEnchantment> enchs = stack.get(Keys.ITEM_ENCHANTMENTS).orElse(new ArrayList<>());
if (level > 0) {
enchs.add(new ItemEnchantment(ench, level));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ item.command.itemdurability.notsupported=&cThe item in your hand does not have a
item.command.itemdurability.success=&3You set the durability of the item in your hand to &b%arg%&3.
item.command.itemenchant.description=Add an enchantment to the item in your hand.
item.command.itemenchant.notfound=&cThe enchantment '%enchantment%' could not be found.
item.command.itemenchant.maxlevel=&cThe specified level is too high! (Max %max%)
item.command.itemenchant.success2=&3You removed the enchantment &b%enchant% &3from the item.
item.command.itemenchant.success=&3You added the enchantment &b%enchant% &3level &b%level% &3to the item.
item.command.itemhidetags.description=Change whether a certain tag is hidden.
Expand Down

0 comments on commit 93b14f4

Please sign in to comment.