44import java .util .regex .Matcher ;
55import java .util .regex .Pattern ;
66
7+ import com .KoryuObihiro .bukkit .ModDamage .ExternalPluginManager ;
78import com .KoryuObihiro .bukkit .ModDamage .ModDamage ;
89import com .KoryuObihiro .bukkit .ModDamage .ModDamage .DebugSetting ;
910import com .KoryuObihiro .bukkit .ModDamage .ModDamage .LoadState ;
1011import com .KoryuObihiro .bukkit .ModDamage .Backend .EntityReference ;
1112import com .KoryuObihiro .bukkit .ModDamage .Backend .TargetEventInfo ;
1213import com .KoryuObihiro .bukkit .ModDamage .Backend .IntegerMatching .EntityMatch .EntityPropertyMatch ;
14+ import com .KoryuObihiro .bukkit .ModDamage .Backend .IntegerMatching .PlayerMatch .PlayerPropertyMatch ;
1315import com .KoryuObihiro .bukkit .ModDamage .Backend .IntegerMatching .ServerMatch .ServerPropertyMatch ;
1416import com .KoryuObihiro .bukkit .ModDamage .Backend .IntegerMatching .WorldMatch .WorldPropertyMatch ;
1517import com .KoryuObihiro .bukkit .ModDamage .RoutineObjects .Routine ;
@@ -19,7 +21,20 @@ public class IntegerMatch
1921 protected final int value ;
2022 private final List <Routine > routines ;
2123 private final BasicIntegerMatch propertyMatch ;
22- private enum BasicIntegerMatch { StaticValue , DynamicValue , RoutineValue ;}
24+ public enum BasicIntegerMatch
25+ {
26+ StaticValue ,
27+ DynamicValue ,
28+ RoutineValue (true );
29+
30+ public boolean settable = false ;
31+ private BasicIntegerMatch (){}
32+ private BasicIntegerMatch (boolean settable )
33+ {
34+ this .settable = settable ;
35+ }
36+ }
37+ protected final boolean settable ;
2338
2439 private static final Pattern dynamicPattern ;
2540
@@ -34,41 +49,60 @@ private enum BasicIntegerMatch{ StaticValue, DynamicValue, RoutineValue;}
3449 dynamicPattern = Pattern .compile (dynamicIntegerPart , Pattern .CASE_INSENSITIVE );
3550 }
3651
37- protected interface MatcherEnum {}
52+ private IntegerMatch ()
53+ {
54+ this .value = 0 ;
55+ this .routines = null ;
56+ this .propertyMatch = BasicIntegerMatch .DynamicValue ;
57+ this .settable = true ;
58+ }
3859
39- protected IntegerMatch (int value )
60+ protected IntegerMatch (boolean settable )
4061 {
41- this .value = value ;
62+ this .value = 0 ;
4263 this .routines = null ;
4364 this .propertyMatch = BasicIntegerMatch .StaticValue ;
65+ this .settable = true ;
4466 }
4567
46- protected IntegerMatch ()
68+ private IntegerMatch (int value )
4769 {
48- this .value = 0 ;
70+ this .value = value ;
4971 this .routines = null ;
50- this .propertyMatch = BasicIntegerMatch .DynamicValue ;
72+ this .propertyMatch = BasicIntegerMatch .StaticValue ;
73+ this .settable = false ;
5174 }
5275
53- protected IntegerMatch (List <Routine > routines )
76+ private IntegerMatch (List <Routine > routines )
5477 {
5578 this .value = 0 ;
5679 this .routines = routines ;
5780 this .propertyMatch = BasicIntegerMatch .RoutineValue ;
81+ this .settable = false ;
5882 }
5983
84+ public boolean isSettable (){ return settable ;}
85+
6086 public int getValue (TargetEventInfo eventInfo )
6187 {
6288 switch (propertyMatch )
6389 {
6490 case StaticValue : return value ;
6591 case RoutineValue :
66- for (Routine routine : routines )
92+ for (Routine routine : routines )//FIXME Unify routines. Because we need default behavior.
6793 routine .run (eventInfo );
6894 case DynamicValue : return eventInfo .eventValue ;
6995 default : return 0 ;
7096 }
7197 }
98+
99+ public void setValue (TargetEventInfo eventInfo , int value , boolean additive )
100+ {
101+ switch (propertyMatch )
102+ {
103+ case DynamicValue : eventInfo .eventValue = value + (additive ?eventInfo .eventValue :0 );
104+ }
105+ }
72106
73107 public static IntegerMatch getNew (List <Routine > routines )
74108 {
@@ -91,7 +125,7 @@ public static IntegerMatch getNew(String string)
91125 if (string .startsWith ("_" ))
92126 {
93127 List <Routine > potentialAlias = ModDamage .matchRoutineAlias (string );
94- if (!potentialAlias .isEmpty ()) return new RoutineMatch (potentialAlias );
128+ if (!potentialAlias .isEmpty ()) return new IntegerMatch (potentialAlias );
95129 }
96130 else if (matcher .matches ())
97131 {
@@ -100,33 +134,51 @@ else if(matcher.matches())
100134 {
101135 if (matches [1 ].equalsIgnoreCase ("value" ))//XXX Can't think of any more properties, so no need to be dynamic here.
102136 return new IntegerMatch ();
103- ModDamage .addToLogRecord (DebugSetting .QUIET , "Error - couldn't match event property \" " + matches [1 ] + "\" " , LoadState .FAILURE );
104137 }
105138 else if (matches [0 ].equalsIgnoreCase ("world" ))
106139 {
107140 for (WorldPropertyMatch match : WorldPropertyMatch .values ())
108141 if (matches [1 ].equalsIgnoreCase (match .name ()))
109142 return new WorldMatch (match );
110- ModDamage .addToLogRecord (DebugSetting .QUIET , "Error - couldn't match world property \" " + matches [1 ] + "\" " , LoadState .FAILURE );
111143 }
112144 else if (matches [0 ].equalsIgnoreCase ("server" ))
113145 {
114146 for (ServerPropertyMatch match : ServerPropertyMatch .values ())
115147 if (matches [1 ].equalsIgnoreCase (match .name ()))
116148 return new ServerMatch (match );
117- ModDamage .addToLogRecord (DebugSetting .QUIET , "Error - couldn't match server property \" " + matches [1 ] + "\" " , LoadState .FAILURE );
118149 }
119150 else if (EntityReference .isValid (matches [0 ]))
120151 {
121152 for (EntityPropertyMatch match : EntityPropertyMatch .values ())
122153 if (matches [1 ].equalsIgnoreCase (match .name ()))
123- return new EntityMatch (EntityReference .match (matches [1 ]), match );
124- ModDamage .addToLogRecord (DebugSetting .QUIET , "Error - couldn't match entity property \" " + matches [1 ] + "\" " , LoadState .FAILURE );
154+ return new EntityMatch (EntityReference .match (matches [0 ]), match );
155+ for (PlayerPropertyMatch match : PlayerPropertyMatch .values ())
156+ if (matches [1 ].equalsIgnoreCase (match .name ()))
157+ {
158+ PlayerMatch yayMatch = new PlayerMatch (EntityReference .match (matches [0 ]), match );
159+ if (ExternalPluginManager .getMcMMOPlugin () != null == yayMatch .propertyMatch .usesMcMMO )
160+ return yayMatch ;
161+ else if (yayMatch .propertyMatch .usesMcMMO )
162+ ModDamage .addToLogRecord (DebugSetting .QUIET , "Error: attempted to use McMMO-dependent player property without McMMO." , LoadState .FAILURE );
163+ }
125164 }
165+ ModDamage .addToLogRecord (DebugSetting .QUIET , "Error - couldn't match \" " + matches [0 ] + "\" property \" " + matches [1 ] + "\" " , LoadState .FAILURE );
126166 }
127167 //These shouldn't ever happen.
128168 else ModDamage .addToLogRecord (DebugSetting .QUIET , "Critical error - unrecognized number reference \" " + string + "\" . Bug Koryu about this one." , LoadState .FAILURE );
129169 return null ;
130170 }
131171 }
172+
173+ @ Override
174+ public String toString ()
175+ {
176+ switch (propertyMatch )
177+ {
178+ case StaticValue : return "" + value ;
179+ case DynamicValue : return "event.value" ;
180+ case RoutineValue : return "<SOME-ROUTINES>" ;//shouldn't happen
181+ default : return "null" ;
182+ }
183+ }
132184}
0 commit comments