diff --git a/src/com/massivecraft/massivecore/command/MassiveCommand.java b/src/com/massivecraft/massivecore/command/MassiveCommand.java index d6afbb47..fb1f221a 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCommand.java +++ b/src/com/massivecraft/massivecore/command/MassiveCommand.java @@ -715,7 +715,8 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand public List getRequirements() { return this.requirements; } public void setRequirements(List requirements) { this.requirements = requirements; } - public void addRequirements(Requirement... requirements) { this.requirements.addAll(Arrays.asList(requirements)); } + public void addRequirements(Collection requirements) { this.requirements.addAll(requirements); } + public void addRequirements(Requirement... requirements) { this.addRequirements(Arrays.asList(requirements)); } public boolean isRequirementsMet(CommandSender sender, boolean verboose) { diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java index c1403f4e..d4898ff4 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditAbstract.java @@ -5,17 +5,14 @@ import java.util.Map.Entry; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.requirement.RequirementEditorUse; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.event.EventMassiveCoreEditorEdit; import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.Txt; public class CommandEditAbstract extends MassiveCommand @@ -54,12 +51,6 @@ public class CommandEditAbstract extends MassiveCommand // Requirements this.addRequirements(RequirementEditorUse.get()); - - if (this.isWrite() != null && this.isWrite()) - { - Permission permission = this.getPropertyPermission(); - if (permission != null) this.addRequirements(RequirementHasPerm.get(permission.getName())); - } } // -------------------------------------------- // @@ -106,9 +97,6 @@ public class CommandEditAbstract extends MassiveCommand return; } - // Permission - if ( ! PermUtil.has(sender, this.getPropertyPermission(), true)) return; - // Inherited / Source / Before Entry inherited = this.getInheritedEntry(); O source = inherited.getKey(); @@ -202,16 +190,6 @@ public class CommandEditAbstract extends MassiveCommand return this.getSettings().getUsed(sender); } - public Permission getPropertyPermission() - { - return this.getSettings().getPropertyPermission(this.getProperty()); - } - - public Permission getUsedPermission() - { - return this.getSettings().getUsedPermission(); - } - public Mson getObjectVisual() { return this.getObjectType().getVisualMson(this.getObject(), sender); diff --git a/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java b/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java index c0b07742..f0e71ee5 100644 --- a/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java +++ b/src/com/massivecraft/massivecore/command/editor/CommandEditSimple.java @@ -2,7 +2,6 @@ package com.massivecraft.massivecore.command.editor; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.TypeNullable; -import com.massivecraft.massivecore.util.PermUtil; public class CommandEditSimple extends CommandEditAbstract { @@ -36,9 +35,6 @@ public class CommandEditSimple extends CommandEditAbstract return; } - // Permission - if ( ! PermUtil.has(sender, this.getPropertyPermission(), true)) return; - // Arguments V after = this.readArg(); diff --git a/src/com/massivecraft/massivecore/command/editor/EditSettings.java b/src/com/massivecraft/massivecore/command/editor/EditSettings.java index 07611523..fc694d07 100644 --- a/src/com/massivecraft/massivecore/command/editor/EditSettings.java +++ b/src/com/massivecraft/massivecore/command/editor/EditSettings.java @@ -1,11 +1,13 @@ package com.massivecraft.massivecore.command.editor; +import java.util.Collections; +import java.util.List; import java.util.Set; import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.Requirement; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.sender.TypeSender; import com.massivecraft.massivecore.util.MUtil; @@ -38,14 +40,7 @@ public class EditSettings } protected EditSettings createUsedSettings() { - final EditSettings main = this; - return new EditSettings(TypeSender.get(), new PropertyThis(TypeSender.get())) { - @Override - public Permission getPropertyPermission(Property property) - { - return main.getUsedPermission(); - } - }; + return new EditSettings(TypeSender.get(), new PropertyThis(TypeSender.get())); } // -------------------------------------------- // @@ -90,14 +85,9 @@ public class EditSettings // PERMISSONS // -------------------------------------------- // - public Permission getPropertyPermission(Property property) + public List getUsedRequirements() { - return null; - } - - public Permission getUsedPermission() - { - return null; + return Collections.emptyList(); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/editor/Property.java b/src/com/massivecraft/massivecore/command/editor/Property.java index 98b0e7f0..48edb076 100644 --- a/src/com/massivecraft/massivecore/command/editor/Property.java +++ b/src/com/massivecraft/massivecore/command/editor/Property.java @@ -1,6 +1,7 @@ package com.massivecraft.massivecore.command.editor; import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -11,6 +12,8 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.requirement.Requirement; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.store.Entity; @@ -57,6 +60,17 @@ public abstract class Property implements Named public void setName(String name) { this.names = new MassiveList(name); } public void setNames(String... names) { this.names = new MassiveList(names); } + // -------------------------------------------- // + // REQUIREMENTS + // -------------------------------------------- // + + protected List requirements = new ArrayList(); + + public List getRequirements() { return this.requirements; } + public void setRequirements(List requirements) { this.requirements = requirements; } + public void addRequirements(Collection requirements) { this.requirements.addAll(requirements); } + public void addRequirements(Requirement... requirements) { this.addRequirements(Arrays.asList(requirements)); } + // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // @@ -147,7 +161,9 @@ public abstract class Property implements Named public CommandEditAbstract createEditCommand(EditSettings settings) { - return this.getValueType().createEditCommand(settings, this); + CommandEditAbstract ret = this.getValueType().createEditCommand(settings, this); + ret.addRequirements(this.getRequirements()); + return ret; } public Mson getInheritedVisual(O object, O source, V value, CommandSender sender) diff --git a/src/com/massivecraft/massivecore/command/editor/PropertyUsed.java b/src/com/massivecraft/massivecore/command/editor/PropertyUsed.java index b6c70518..8fbe6d9b 100644 --- a/src/com/massivecraft/massivecore/command/editor/PropertyUsed.java +++ b/src/com/massivecraft/massivecore/command/editor/PropertyUsed.java @@ -13,6 +13,7 @@ public abstract class PropertyUsed extends Property public PropertyUsed(EditSettings settings) { super(TypeSender.get(), settings.getObjectType(), "used " + settings.getObjectType().getName()); + this.addRequirements(settings.getUsedRequirements()); } } diff --git a/src/com/massivecraft/massivecore/command/requirement/RequirementHasItemInHand.java b/src/com/massivecraft/massivecore/command/requirement/RequirementHasItemInHand.java new file mode 100644 index 00000000..35f44e3e --- /dev/null +++ b/src/com/massivecraft/massivecore/command/requirement/RequirementHasItemInHand.java @@ -0,0 +1,57 @@ +package com.massivecraft.massivecore.command.requirement; + +import org.bukkit.Material; +import org.bukkit.command.CommandSender; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.type.TypeItemStack; + +public class RequirementHasItemInHand extends RequirementAbstract +{ + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static RequirementHasItemInHand i = new RequirementHasItemInHand(TypeItemStack.get()); + public static RequirementHasItemInHand get() { return i; } + + public static RequirementHasItemInHand get(TypeItemStack innerType) { return new RequirementHasItemInHand(innerType); } + public static RequirementHasItemInHand get(Material... materialWhitelist) { return get(TypeItemStack.get(materialWhitelist)); } + + public RequirementHasItemInHand(TypeItemStack innerType) { this.innerType = innerType; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final TypeItemStack innerType; + public TypeItemStack getInnerType() { return this.innerType; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) + { + return this.getInnerType().isValid(null, sender); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) + { + try + { + this.getInnerType().read(sender); + } + catch (MassiveException e) + { + return e.getMessages().toPlain(true); + } + return null; + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java b/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java new file mode 100644 index 00000000..b040b6a8 --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/TypeEnchantment.java @@ -0,0 +1,76 @@ +package com.massivecraft.massivecore.command.type; + +import java.util.Collections; +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.enchantments.Enchantment; + +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.util.Txt; + +public class TypeEnchantment extends TypeAbstractChoice +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeEnchantment i = new TypeEnchantment(); + public static TypeEnchantment get() { return i; } + public TypeEnchantment() + { + this.setVisualColor(ChatColor.AQUA); + this.setAll(Enchantment.values()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getNameInner(Enchantment enchantment) + { + return Txt.getNicedEnumString(enchantment.getName()); + } + + @Override + public Set getNamesInner(Enchantment enchantment) + { + Set ret = new MassiveSet<>(); + ret.add(this.getName(enchantment)); + + if (Enchantment.DAMAGE_ALL.equals(enchantment)) Collections.addAll(ret, "Sharpness"); + if (Enchantment.DAMAGE_ARTHROPODS.equals(enchantment)) Collections.addAll(ret, "BaneOfArthropdos"); + if (Enchantment.DAMAGE_UNDEAD.equals(enchantment)) Collections.addAll(ret, "Smite"); + if (Enchantment.DIG_SPEED.equals(enchantment)) Collections.addAll(ret, "Efficiency"); + if (Enchantment.DURABILITY.equals(enchantment)) Collections.addAll(ret, "Unbreaking"); + if (Enchantment.THORNS.equals(enchantment)) Collections.addAll(ret); + if (Enchantment.FIRE_ASPECT.equals(enchantment)) Collections.addAll(ret); + if (Enchantment.KNOCKBACK.equals(enchantment)) Collections.addAll(ret); + if (Enchantment.LOOT_BONUS_BLOCKS.equals(enchantment)) Collections.addAll(ret, "Fortune"); + if (Enchantment.LOOT_BONUS_MOBS.equals(enchantment)) Collections.addAll(ret, "Looting"); + if (Enchantment.OXYGEN.equals(enchantment)) Collections.addAll(ret, "Respiration", "Breathing"); + if (Enchantment.PROTECTION_ENVIRONMENTAL.equals(enchantment)) Collections.addAll(ret, "Protection"); + if (Enchantment.PROTECTION_EXPLOSIONS.equals(enchantment)) Collections.addAll(ret, "BlastProtection", "ExplosionProtection"); + if (Enchantment.PROTECTION_FALL.equals(enchantment)) Collections.addAll(ret, "FeatherFalling", "FallProtection"); + if (Enchantment.PROTECTION_FIRE.equals(enchantment)) Collections.addAll(ret, "FireProtection"); + if (Enchantment.PROTECTION_PROJECTILE.equals(enchantment)) Collections.addAll(ret, "ProectileProtection"); + if (Enchantment.SILK_TOUCH.equals(enchantment)) Collections.addAll(ret); + if (Enchantment.WATER_WORKER.equals(enchantment)) Collections.addAll(ret, "AquaAffinity"); + if (Enchantment.ARROW_FIRE.equals(enchantment)) Collections.addAll(ret, "Flame"); + if (Enchantment.ARROW_DAMAGE.equals(enchantment)) Collections.addAll(ret, "Power"); + if (Enchantment.ARROW_KNOCKBACK.equals(enchantment)) Collections.addAll(ret, "Punch"); + if (Enchantment.ARROW_INFINITE.equals(enchantment)) Collections.addAll(ret, "Infinity"); + if (Enchantment.LUCK.equals(enchantment)) Collections.addAll(ret, "LuckOfSea", "LuckOfTheSea"); + if (Enchantment.LURE.equals(enchantment)) Collections.addAll(ret); + + return ret; + } + + @Override + public String getIdInner(Enchantment enchantment) + { + return enchantment.getName(); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypePattern.java b/src/com/massivecraft/massivecore/command/type/combined/TypePattern.java new file mode 100644 index 00000000..b9eb8b6d --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/combined/TypePattern.java @@ -0,0 +1,66 @@ +package com.massivecraft.massivecore.command.type.combined; + +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; + +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor; +import com.massivecraft.massivecore.command.type.enumeration.TypePatternType; + +public class TypePattern extends TypeCombined +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypePattern i = new TypePattern(); + public static TypePattern get() { return i; } + + public TypePattern() + { + super( + TypeDyeColor.get(), + TypePatternType.get() + ); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public List split(Pattern value) + { + return new MassiveList( + value.getColor(), + value.getPattern() + ); + } + + @Override + public Pattern combine(List parts) + { + DyeColor color = null; + PatternType pattern = null; + + for (int i = 0 ; i < parts.size() ; i++) + { + Object part = parts.get(i); + + if (i == 0) + { + color = (DyeColor)part; + } + else if (i == 1) + { + pattern = (PatternType) part; + } + } + + return new Pattern(color, pattern); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/container/TypeMap.java b/src/com/massivecraft/massivecore/command/type/container/TypeMap.java index 7a1e5f28..53e46145 100644 --- a/src/com/massivecraft/massivecore/command/type/container/TypeMap.java +++ b/src/com/massivecraft/massivecore/command/type/container/TypeMap.java @@ -13,6 +13,11 @@ public class TypeMap extends TypeContainer, Entry> // INSTANCE & CONSTRUCT // -------------------------------------------- // + public static TypeMap get(Type keyType, Type valueType) + { + return get(TypeEntry.get(keyType, valueType)); + } + public static TypeMap get(TypeEntry entryType) { return new TypeMap(entryType); diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypeItemFlag.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypeItemFlag.java new file mode 100644 index 00000000..7e3efff1 --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/enumeration/TypeItemFlag.java @@ -0,0 +1,18 @@ +package com.massivecraft.massivecore.command.type.enumeration; + +import org.bukkit.inventory.ItemFlag; + +public class TypeItemFlag extends TypeEnum +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeItemFlag i = new TypeItemFlag(); + public static TypeItemFlag get() { return i; } + public TypeItemFlag() + { + super(ItemFlag.class); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypePatternType.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypePatternType.java new file mode 100644 index 00000000..13f506c7 --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/enumeration/TypePatternType.java @@ -0,0 +1,18 @@ +package com.massivecraft.massivecore.command.type.enumeration; + +import org.bukkit.block.banner.PatternType; + +public class TypePatternType extends TypeEnum +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypePatternType i = new TypePatternType(); + public static TypePatternType get() { return i; } + public TypePatternType() + { + super(PatternType.class); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/primitive/TypeShort.java b/src/com/massivecraft/massivecore/command/type/primitive/TypeShort.java new file mode 100644 index 00000000..f36e335e --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/primitive/TypeShort.java @@ -0,0 +1,30 @@ +package com.massivecraft.massivecore.command.type.primitive; + +import org.bukkit.command.CommandSender; + +public class TypeShort extends TypeAbstractNumber +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeShort i = new TypeShort(); + public static TypeShort get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "number"; + } + + @Override + public Short valueOf(String arg, CommandSender sender) throws Exception + { + return Short.parseShort(arg); + } + +} diff --git a/src/com/massivecraft/massivecore/command/type/sender/TypeSenderName.java b/src/com/massivecraft/massivecore/command/type/sender/TypeSenderName.java new file mode 100644 index 00000000..0de9c7ce --- /dev/null +++ b/src/com/massivecraft/massivecore/command/type/sender/TypeSenderName.java @@ -0,0 +1,63 @@ +package com.massivecraft.massivecore.command.type.sender; + +import com.massivecraft.massivecore.SenderPresence; +import com.massivecraft.massivecore.SenderType; +import com.massivecraft.massivecore.store.SenderIdSource; +import com.massivecraft.massivecore.store.SenderIdSourceMixinAllSenderIds; +import com.massivecraft.massivecore.util.IdUtil; + +public class TypeSenderName extends TypeSenderIdAbstract +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + private TypeSenderName(SenderIdSource source, SenderPresence presence, SenderType type) + { + super(source, presence, type); + } + + private TypeSenderName(SenderIdSource source, SenderPresence presence) + { + super(source, presence); + } + + + private TypeSenderName(SenderIdSource source, SenderType type) + { + super(source, type); + } + + + private TypeSenderName(SenderIdSource source) + { + super(source); + } + + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static final TypeSenderName i = new TypeSenderName(SenderIdSourceMixinAllSenderIds.get()); + public static TypeSenderName get() { return i; } + + // -------------------------------------------- // + // GET + // -------------------------------------------- // + + public static TypeSenderName get(SenderIdSource source, SenderPresence presence, SenderType type) { return new TypeSenderName(source, presence, type); } + public static TypeSenderName get(SenderIdSource source, SenderPresence presence) { return new TypeSenderName(source, presence); } + public static TypeSenderName get(SenderIdSource source, SenderType type) { return new TypeSenderName(source, type); } + public static TypeSenderName get(SenderIdSource source) { return new TypeSenderName(source); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getResultForSenderId(String senderId) + { + return IdUtil.getName(senderId); + } + +}