Advertisement
lLuffy

Untitled

Aug 13th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. package com.sk89q.worldguard.protection.flags;
  2.  
  3. import com.google.common.base.Preconditions;
  4. import com.google.common.collect.Iterators;
  5. import java.util.Collection;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8. import javax.annotation.Nullable;
  9.  
  10. public abstract class Flag<T>
  11. {
  12. private static final Pattern VALID_NAME = Pattern.compile("^[:A-Za-z0-9\\-]{1,40}$");
  13. private final String name;
  14. private final RegionGroupFlag regionGroup;
  15.  
  16. protected Flag(String name, @Nullable RegionGroup defaultGroup)
  17. {
  18. if ((name != null) && (!isValidName(name))) {
  19. throw new IllegalArgumentException("������������ �������� ��� �����");
  20. }
  21. this.name = name;
  22. this.regionGroup = (defaultGroup != null ? new RegionGroupFlag(name + "-group", defaultGroup) : null);
  23. }
  24.  
  25. protected Flag(String name)
  26. {
  27. this(name, RegionGroup.ALL);
  28. }
  29.  
  30. public final String getName()
  31. {
  32. return this.name;
  33. }
  34.  
  35. @Nullable
  36. public T getDefault()
  37. {
  38. return null;
  39. }
  40.  
  41. @Nullable
  42. public T chooseValue(Collection<T> values)
  43. {
  44. return (T)Iterators.getNext(values.iterator(), null);
  45. }
  46.  
  47. public boolean hasConflictStrategy()
  48. {
  49. return false;
  50. }
  51.  
  52. public boolean implicitlySetWithMembership()
  53. {
  54. return false;
  55. }
  56.  
  57. public boolean usesMembershipAsDefault()
  58. {
  59. return false;
  60. }
  61.  
  62. public boolean requiresSubject()
  63. {
  64. return false;
  65. }
  66.  
  67. public final RegionGroupFlag getRegionGroupFlag()
  68. {
  69. return this.regionGroup;
  70. }
  71.  
  72. public abstract T parseInput(FlagContext paramFlagContext)
  73. throws InvalidFlagFormat;
  74.  
  75. public abstract T unmarshal(@Nullable Object paramObject);
  76.  
  77. public abstract Object marshal(T paramT);
  78.  
  79. public String toString()
  80. {
  81. return getClass().getSimpleName() + "{���='" + this.name + '\'' + '}';
  82. }
  83.  
  84. public static boolean isValidName(String name)
  85. {
  86. Preconditions.checkNotNull(name, "name");
  87. return VALID_NAME.matcher(name).matches();
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement