Skip to content

Commit f9a90b7

Browse files
committed
Merge branch 'master' into genericsTake2
2 parents 14471ee + 6d8759f commit f9a90b7

7 files changed

Lines changed: 55 additions & 49 deletions

File tree

checkstyle.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<property name="message" value="Javadoc comment at column [\d]+ has parse error\. Details: no viable alternative at input '[\\t]+ \*' while parsing JAVADOC_TAG"/>
3232
</module>
3333

34+
<!-- Allow braceless else when it directly contains a switch expression -->
35+
<module name="SuppressionXpathSingleFilter">
36+
<property name="checks" value="NeedBraces"/>
37+
<property name="query" value="//LITERAL_ELSE[./EXPR/ASSIGN/LITERAL_SWITCH]"/>
38+
</module>
39+
3440
<!-- Indent must use tab characters -->
3541
<module name="RegexpSinglelineJava">
3642
<property name="format" value="^\t* ([^\*]|$)"/> <!-- Javadoc and multiline comments have a single leading whitespace, so allow " *" -->

src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitBlockEvents.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.laytonsmith.core.constructs.CString;
4646
import com.laytonsmith.core.constructs.Target;
4747
import com.laytonsmith.core.constructs.generics.GenericParameters;
48-
import com.laytonsmith.core.environments.Environment;
4948
import org.bukkit.block.Block;
5049
import org.bukkit.event.block.BlockBreakEvent;
5150
import org.bukkit.event.block.BlockBurnEvent;
@@ -392,12 +391,12 @@ public CString getLine(int index) {
392391
}
393392

394393
@Override
395-
public CArray getLines(Environment env) {
394+
public CArray getLines() {
396395
CArray retn = new CArray(Target.UNKNOWN, GenericParameters.emptyBuilder(CArray.TYPE)
397-
.addNativeParameter(CString.TYPE, null).buildNative(), env);
396+
.addNativeParameter(CString.TYPE, null).buildNative(), null);
398397

399398
for(int i = 0; i < 4; i++) {
400-
retn.push(new CString(pie.getLine(i), Target.UNKNOWN), Target.UNKNOWN, env);
399+
retn.push(new CString(pie.getLine(i), Target.UNKNOWN), Target.UNKNOWN, null);
401400
}
402401

403402
return retn;

src/main/java/com/laytonsmith/abstraction/enums/MCTagType.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99
import com.laytonsmith.core.constructs.CInt;
1010
import com.laytonsmith.core.constructs.CString;
1111
import com.laytonsmith.core.constructs.Target;
12+
import com.laytonsmith.core.constructs.generics.GenericParameters;
1213
import com.laytonsmith.core.environments.Environment;
1314
import com.laytonsmith.core.exceptions.CRE.CRECastException;
1415
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
1516
import com.laytonsmith.core.natives.interfaces.Mixed;
1617

1718
import java.util.function.BiFunction;
19+
import java.util.function.Function;
1820

1921
/**
2022
* Minecraft NBT types, with functions to convert to and from MethodScript constructs.
2123
*/
2224
public enum MCTagType {
2325
BYTE(
2426
(Mixed v, Environment env) -> ArgumentValidation.getInt8(v, v.getTarget(), env),
25-
(Byte v, Environment env) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
27+
(Byte v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
2628
BYTE_ARRAY(
2729
(Mixed v, Environment env) -> {
2830
CArray array = ArgumentValidation.getArray(v, v.getTarget(), env);
@@ -36,22 +38,22 @@ public enum MCTagType {
3638
}
3739
return bytes;
3840
},
39-
(byte[] array, Environment env) -> {
40-
CArray r = new CArray(Target.UNKNOWN, null, env);
41+
(byte[] array) -> {
42+
CArray r = new CArray(Target.UNKNOWN, null, null);
4143
for(int i : array) {
42-
r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, env);
44+
r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, null);
4345
}
4446
return r;
4547
}),
4648
DOUBLE(
4749
(Mixed v, Environment env) -> ArgumentValidation.getDouble(v, v.getTarget(), env),
48-
(Double v, Environment env) -> new CDouble(v, Target.UNKNOWN)),
50+
(Double v) -> new CDouble(v, Target.UNKNOWN)),
4951
FLOAT(
5052
(Mixed v, Environment env) -> ArgumentValidation.getDouble32(v, v.getTarget(), env),
51-
(Float v, Environment env) -> new CDouble(v.doubleValue(), Target.UNKNOWN)),
53+
(Float v) -> new CDouble(v.doubleValue(), Target.UNKNOWN)),
5254
INTEGER(
5355
(Mixed v, Environment env) -> ArgumentValidation.getInt32(v, v.getTarget(), env),
54-
(Integer v, Environment env) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
56+
(Integer v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
5557
INTEGER_ARRAY(
5658
(Mixed v, Environment env) -> {
5759
CArray array = ArgumentValidation.getArray(v, v.getTarget(), env);
@@ -65,16 +67,16 @@ public enum MCTagType {
6567
}
6668
return ints;
6769
},
68-
(int[] array, Environment env) -> {
69-
CArray r = new CArray(Target.UNKNOWN, null, env);
70+
(int[] array) -> {
71+
CArray r = new CArray(Target.UNKNOWN, null, null);
7072
for(int i : array) {
71-
r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, env);
73+
r.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, null);
7274
}
7375
return r;
7476
}),
7577
LONG(
7678
(Mixed v, Environment env) -> ArgumentValidation.getInt(v, v.getTarget(), env),
77-
(Long v, Environment env) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
79+
(Long v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
7880
LONG_ARRAY(
7981
(Mixed v, Environment env) -> {
8082
CArray array = ArgumentValidation.getArray(v, v.getTarget(), env);
@@ -88,38 +90,38 @@ public enum MCTagType {
8890
}
8991
return longs;
9092
},
91-
(long[] array, Environment env) -> {
92-
CArray ret = new CArray(Target.UNKNOWN, null, env);
93+
(long[] array) -> {
94+
CArray ret = new CArray(Target.UNKNOWN, null, null);
9395
for(long i : array) {
94-
ret.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, env);
96+
ret.push(new CInt(i, Target.UNKNOWN), Target.UNKNOWN, null);
9597
}
9698
return ret;
9799
}),
98100
SHORT(
99101
(Mixed v, Environment env) -> ArgumentValidation.getInt16(v, v.getTarget(), env),
100-
(Short v, Environment env) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
102+
(Short v) -> new CInt(((Number) v).longValue(), Target.UNKNOWN)),
101103
STRING(
102104
(Mixed v, Environment env) -> v.val(),
103-
(String v, Environment env) -> new CString(v, Target.UNKNOWN)),
105+
(String v) -> new CString(v, Target.UNKNOWN)),
104106
TAG_CONTAINER(
105107
(Mixed v, Environment env) -> {
106108
throw new UnsupportedOperationException();
107109
},
108-
(MCTagContainer v, Environment env) -> {
110+
(MCTagContainer v) -> {
109111
throw new UnsupportedOperationException();
110112
}),
111113
TAG_CONTAINER_ARRAY(
112114
(Mixed v, Environment env) -> {
113115
throw new UnsupportedOperationException();
114116
},
115-
(MCTagContainer[] v, Environment env) -> {
117+
(MCTagContainer[] v) -> {
116118
throw new UnsupportedOperationException();
117119
});
118120

119121
private final BiFunction conversion;
120-
private final BiFunction construction;
122+
private final Function construction;
121123

122-
<T extends Mixed, Z> MCTagType(BiFunction<T, Environment, Z> conversion, BiFunction<Z, Environment, T> construction) {
124+
<T extends Mixed, Z> MCTagType(BiFunction<T, Environment, Z> conversion, Function<Z, T> construction) {
123125
this.conversion = conversion;
124126
this.construction = construction;
125127
}
@@ -148,30 +150,30 @@ public Object convert(MCTagContainer container, Mixed value, Environment env) {
148150
throw new CREFormatException("Expected tag container array to be associative.", value.getTarget());
149151
}
150152
for(String key : containerArray.stringKeySet()) {
151-
Mixed possibleArray = containerArray.get(key, value.getTarget());
153+
Mixed possibleArray = containerArray.get(key, value.getTarget(), env);
152154
if(!possibleArray.isInstanceOf(CArray.TYPE, null, env)) {
153155
throw new CREFormatException("Expected tag entry to be an array.", possibleArray.getTarget());
154156
}
155157
CArray entryArray = (CArray) possibleArray;
156158
if(!entryArray.isAssociative()) {
157159
throw new CREFormatException("Expected tag array to be associative.", entryArray.getTarget());
158160
}
159-
Mixed entryType = entryArray.get("type", entryArray.getTarget());
160-
Mixed entryValue = entryArray.get("value", entryArray.getTarget());
161+
Mixed entryType = entryArray.get("type", entryArray.getTarget(), env);
162+
Mixed entryValue = entryArray.get("value", entryArray.getTarget(), env);
161163
MCTagType tagType;
162164
try {
163165
tagType = MCTagType.valueOf(entryType.val());
164166
} catch (IllegalArgumentException ex) {
165167
throw new CREFormatException("Tag type is not valid: " + entryType.val(), entryType.getTarget());
166168
}
167169
Object tagValue;
168-
if(tagType == MCTagType.TAG_CONTAINER) {
169-
tagValue = tagType.convert(container.newContainer(), entryValue, env);
170-
} else if(tagType == TAG_CONTAINER_ARRAY) {
170+
if(null == tagType) {
171171
tagValue = tagType.convert(container, entryValue, env);
172-
} else {
173-
tagValue = tagType.convert(container, entryValue, env);
174-
}
172+
} else tagValue = switch(tagType) {
173+
case TAG_CONTAINER -> tagType.convert(container.newContainer(), entryValue, env);
174+
case TAG_CONTAINER_ARRAY -> tagType.convert(container, entryValue, env);
175+
default -> tagType.convert(container, entryValue, env);
176+
};
175177
try {
176178
container.set(StaticLayer.GetConvertor().GetNamespacedKey(key), tagType, tagValue);
177179
} catch (ClassCastException ex) {
@@ -205,26 +207,26 @@ public Object convert(MCTagContainer container, Mixed value, Environment env) {
205207
* @param value a valid Java object
206208
* @return a MethodScript construct
207209
*/
208-
public Mixed construct(Object value, Environment env) throws ClassCastException {
210+
public Mixed construct(Object value) throws ClassCastException {
209211
if(this == TAG_CONTAINER) {
210212
MCTagContainer container = (MCTagContainer) value;
211-
CArray containerArray = CArray.GetAssociativeArray(Target.UNKNOWN, null, env);
213+
CArray containerArray = CArray.GetAssociativeArray(Target.UNKNOWN, null, null);
212214
for(MCNamespacedKey key : container.getKeys()) {
213-
CArray entry = CArray.GetAssociativeArray(Target.UNKNOWN, null, env);
215+
CArray entry = CArray.GetAssociativeArray(Target.UNKNOWN, null, null);
214216
MCTagType type = container.getType(key);
215-
entry.set("type", type.name(), Target.UNKNOWN, env);
216-
entry.set("value", type.construct(container.get(key, type), env), Target.UNKNOWN, env);
217-
containerArray.set(key.toString(), entry, Target.UNKNOWN, env);
217+
entry.set("type", type.name(), Target.UNKNOWN, null);
218+
entry.set("value", type.construct(container.get(key, type)), Target.UNKNOWN, null);
219+
containerArray.set(key.toString(), entry, Target.UNKNOWN, null);
218220
}
219221
return containerArray;
220222
} else if(this == TAG_CONTAINER_ARRAY) {
221223
MCTagContainer[] containers = (MCTagContainer[]) value;
222-
CArray array = new CArray(Target.UNKNOWN, containers.length, null, env);
224+
CArray array = new CArray(Target.UNKNOWN, containers.length, (GenericParameters) null, (Environment) null);
223225
for(MCTagContainer container : containers) {
224-
array.push(TAG_CONTAINER.construct(container, env), Target.UNKNOWN, env);
226+
array.push(TAG_CONTAINER.construct(container), Target.UNKNOWN, null);
225227
}
226228
return array;
227229
}
228-
return (Mixed) construction.apply(value, env);
230+
return (Mixed) construction.apply(value);
229231
}
230232
}

src/main/java/com/laytonsmith/abstraction/events/MCSignChangeEvent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.laytonsmith.abstraction.blocks.MCSign;
66
import com.laytonsmith.core.constructs.CArray;
77
import com.laytonsmith.core.constructs.CString;
8-
import com.laytonsmith.core.environments.Environment;
98
import com.laytonsmith.core.events.BindableEvent;
109

1110
public interface MCSignChangeEvent extends BindableEvent {
@@ -20,7 +19,7 @@ public interface MCSignChangeEvent extends BindableEvent {
2019

2120
void setLines(String[] lines);
2221

23-
CArray getLines(Environment env);
22+
CArray getLines();
2423

2524
MCSign.Side getSide();
2625
}

src/main/java/com/laytonsmith/core/ObjectGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
538538
}
539539

540540
if(meta.hasCustomTags()) {
541-
ma.set("tags", MCTagType.TAG_CONTAINER.construct(meta.getCustomTags(), null), t, null);
541+
ma.set("tags", MCTagType.TAG_CONTAINER.construct(meta.getCustomTags()), t, null);
542542
} else {
543543
ma.set("tags", CNull.NULL, t, null);
544544
}
@@ -673,7 +673,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
673673
// we can ensure we don't populate this meta array with the default banner data.
674674
if(mCBlockStateMeta.hasBlockState()) {
675675
ma.set("basecolor", banner.getBaseColor().name(), t, null);
676-
CArray patterns = new CArray(t, banner.numberOfPatterns(), null, null);
676+
CArray patterns = new CArray(t, banner.numberOfPatterns(), (GenericParameters) null, (Environment) null);
677677
for(MCPattern p : banner.getPatterns()) {
678678
CArray pattern = CArray.GetAssociativeArray(t, null, null);
679679
pattern.set("shape", new CString(p.getShape().toString(), t), t, null);
@@ -923,7 +923,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
923923
CArray effects = potions(susstew.getCustomEffects(), t);
924924
ma.set("potions", effects, t, null);
925925
} else if(meta instanceof MCBannerMeta bannermeta) {
926-
CArray patterns = new CArray(t, bannermeta.numberOfPatterns(), null, null);
926+
CArray patterns = new CArray(t, bannermeta.numberOfPatterns(), (GenericParameters) null, (Environment) null);
927927
for(MCPattern p : bannermeta.getPatterns()) {
928928
CArray pattern = CArray.GetAssociativeArray(t, null, null);
929929
pattern.set("shape", new CString(p.getShape().toString(), t), t, null);
@@ -1017,6 +1017,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
10171017
* @param t
10181018
* @return abstract item meta
10191019
* @throws ConfigRuntimeException
1020+
* @deprecated Use {@link #itemMeta(Mixed, MCMaterial, Target, Environment)} instead.
10201021
*/
10211022
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
10221023
@Deprecated

src/main/java/com/laytonsmith/core/compiler/ProcedureDefinition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.laytonsmith.PureUtilities.Version;
44
import com.laytonsmith.core.ParseTree;
55
import com.laytonsmith.core.constructs.CClassType;
6-
import com.laytonsmith.core.constructs.generics.GenericParameters;
76
import com.laytonsmith.core.constructs.Construct;
87
import com.laytonsmith.core.constructs.DocComment;
98
import com.laytonsmith.core.constructs.Target;

src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ public Map<String, Mixed> evaluate(BindableEvent e, Environment env) throws Even
957957
Map<String, Mixed> map = evaluate_helper(e);
958958

959959
map.put("player", new CString(event.getPlayer().getName(), Target.UNKNOWN));
960-
map.put("text", event.getLines(env));
960+
map.put("text", event.getLines());
961961
map.put("location", ObjectGenerator.GetGenerator().location(event.getBlock().getLocation(), false));
962962
map.put("side", new CString(event.getSide().name(), Target.UNKNOWN));
963963

0 commit comments

Comments
 (0)