Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 7ead9fc

Browse files
author
Erich Gubler
committed
Made effect.set Calculations dynamic (uses dynamic integer matches now), added color support for Messages. Fixed an infinite loop that an invalid reference would give.
1 parent 346ff83 commit 7ead9fc

32 files changed

Lines changed: 535 additions & 631 deletions

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<project name="ModDamage" default="jar">
33
<property file="build/build.properties"/>
44
<target name="jar">
5-
<delete file="../Minecraft/plugins/ModDamage.jar" />
5+
<!-- <delete file="../Minecraft/plugins/ModDamage.jar" /> -->
66

7-
<jar destfile="../Minecraft/plugins/ModDamage.jar" update="true">
7+
<jar destfile="../Minecraft/plugins/ModDamage.jar" update="no">
88
<fileset dir="bin" includes="**/*.class" />
99
<fileset dir="." includes="plugin.yml" />
1010
<manifest>

src/com/KoryuObihiro/bukkit/ModDamage/Backend/Aliasing/MessageAliaser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.KoryuObihiro.bukkit.ModDamage.Backend.Aliasing;
22

3-
import com.KoryuObihiro.bukkit.ModDamage.RoutineObjects.Base.Message.DynamicMessage;
3+
import com.KoryuObihiro.bukkit.ModDamage.RoutineObjects.Message.DynamicMessage;
44

55
public class MessageAliaser extends Aliaser<DynamicMessage>
66
{

src/com/KoryuObihiro/bukkit/ModDamage/Backend/IntegerMatching/EntityMatch.java

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,88 @@
22

33
import org.bukkit.entity.Entity;
44
import org.bukkit.entity.LivingEntity;
5-
import org.bukkit.entity.Player;
65
import org.bukkit.entity.Slime;
76

87
import com.KoryuObihiro.bukkit.ModDamage.Backend.EntityReference;
98
import com.KoryuObihiro.bukkit.ModDamage.Backend.TargetEventInfo;
109

1110
public class EntityMatch extends IntegerMatch
1211
{
13-
protected final EntityReference reference;
14-
protected final EntityPropertyMatch propertyMatch;
15-
enum EntityPropertyMatch implements MatcherEnum
12+
protected final EntityReference entityReference;
13+
private final EntityPropertyMatch propertyMatch;
14+
public enum EntityPropertyMatch
1615
{
17-
AirTicks(true),
18-
FallDistance(true),
19-
FireTicks(true),
20-
Health(true),
16+
AirTicks(true, true),
17+
FallDistance(false, true),
18+
FireTicks(true, true),
19+
Health(true, true),
2120
Light,
22-
Size,
23-
WieldQuantity,
21+
Size(true),
2422
X,
2523
Y,
2624
Z;
27-
//TODO Add player stuff
2825

29-
private boolean castsToLiving;
30-
private EntityPropertyMatch()
26+
public boolean settable = false;
27+
private boolean castsToLiving = false;
28+
private EntityPropertyMatch(){}
29+
private EntityPropertyMatch(boolean settable)
3130
{
32-
this.castsToLiving = false;
31+
this.settable = settable;
3332
}
34-
private EntityPropertyMatch(boolean castsToLiving)
33+
private EntityPropertyMatch(boolean settable, boolean castsToLiving)
3534
{
35+
this.settable = settable;
3636
this.castsToLiving = castsToLiving;
3737
}
38-
39-
protected int getProperty(TargetEventInfo eventInfo, EntityReference reference)
40-
{
41-
Entity entity = reference.getEntity(eventInfo);
42-
if(!castsToLiving || (entity instanceof LivingEntity))
43-
switch(this)
44-
{
45-
case AirTicks: return ((LivingEntity)entity).getRemainingAir();
46-
case FallDistance: return (int) ((LivingEntity)entity).getFallDistance();
47-
case FireTicks: return ((LivingEntity)entity).getFireTicks();
48-
case Health: return ((LivingEntity)entity).getHealth();
49-
case Light: return entity.getLocation().getBlock().getLightLevel();
50-
case Size: if(entity instanceof Slime) return ((Slime)entity).getSize();
51-
case WieldQuantity: if(entity instanceof Player) return ((Player)entity).getItemInHand().getAmount();
52-
case X: return entity.getLocation().getBlockX();
53-
case Y: return entity.getLocation().getBlockY();
54-
case Z: return entity.getLocation().getBlockZ();
55-
}
56-
return 0;//Shouldn't happen.
57-
}
5838
}
5939

6040
EntityMatch(EntityReference reference, EntityPropertyMatch propertyMatch)
6141
{
62-
this.reference = reference;
42+
super(propertyMatch.settable);
43+
this.entityReference = reference;
6344
this.propertyMatch = propertyMatch;
6445
}
6546

6647
@Override
67-
public int getValue(TargetEventInfo eventInfo){ return propertyMatch.getProperty(eventInfo, reference);}
48+
public int getValue(TargetEventInfo eventInfo)
49+
{
50+
Entity entity = entityReference.getEntity(eventInfo);
51+
if((!propertyMatch.castsToLiving || (entity instanceof LivingEntity)))
52+
switch(propertyMatch)
53+
{
54+
case AirTicks: return ((LivingEntity)entity).getRemainingAir();
55+
case FallDistance: return (int) ((LivingEntity)entity).getFallDistance();
56+
case FireTicks: return ((LivingEntity)entity).getFireTicks();
57+
case Health: return ((LivingEntity)entity).getHealth();
58+
case Light: return entity.getLocation().getBlock().getLightLevel();
59+
case Size: if(entity instanceof Slime) return ((Slime)entity).getSize();
60+
case X: return entity.getLocation().getBlockX();
61+
case Y: return entity.getLocation().getBlockY();
62+
case Z: return entity.getLocation().getBlockZ();
63+
}
64+
return 0;//Shouldn't happen.
65+
}
66+
67+
@Override
68+
public void setValue(TargetEventInfo eventInfo, int value, boolean additive)
69+
{
70+
Entity entity = entityReference.getEntity(eventInfo);
71+
if((!propertyMatch.castsToLiving || (entity instanceof LivingEntity)))
72+
{
73+
value += (additive?getValue(eventInfo):0);
74+
switch(propertyMatch)
75+
{
76+
case AirTicks: ((LivingEntity)entity).setRemainingAir(value);
77+
case FireTicks: ((LivingEntity)entity).setFireTicks(value);
78+
case Health: ((LivingEntity)entity).setHealth(value);
79+
case Size: if(entity instanceof Slime) ((Slime)entity).setSize(value);
80+
}
81+
}
82+
}
83+
84+
@Override
85+
public String toString()
86+
{
87+
return entityReference.name().toLowerCase() + "." + propertyMatch.name().toLowerCase();
88+
}
6889
}

src/com/KoryuObihiro/bukkit/ModDamage/Backend/IntegerMatching/IntegerMatch.java

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import java.util.regex.Matcher;
55
import java.util.regex.Pattern;
66

7+
import com.KoryuObihiro.bukkit.ModDamage.ExternalPluginManager;
78
import com.KoryuObihiro.bukkit.ModDamage.ModDamage;
89
import com.KoryuObihiro.bukkit.ModDamage.ModDamage.DebugSetting;
910
import com.KoryuObihiro.bukkit.ModDamage.ModDamage.LoadState;
1011
import com.KoryuObihiro.bukkit.ModDamage.Backend.EntityReference;
1112
import com.KoryuObihiro.bukkit.ModDamage.Backend.TargetEventInfo;
1213
import com.KoryuObihiro.bukkit.ModDamage.Backend.IntegerMatching.EntityMatch.EntityPropertyMatch;
14+
import com.KoryuObihiro.bukkit.ModDamage.Backend.IntegerMatching.PlayerMatch.PlayerPropertyMatch;
1315
import com.KoryuObihiro.bukkit.ModDamage.Backend.IntegerMatching.ServerMatch.ServerPropertyMatch;
1416
import com.KoryuObihiro.bukkit.ModDamage.Backend.IntegerMatching.WorldMatch.WorldPropertyMatch;
1517
import 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

Comments
 (0)