Skip to content

Commit 25610bd

Browse files
committed
Merge branch 'master' into genericsTake2
2 parents 4f9014f + 6d45acd commit 25610bd

30 files changed

Lines changed: 290 additions & 102 deletions

deprecation.txt

Whitespace-only changes.

src/main/java/com/laytonsmith/abstraction/MCCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.laytonsmith.abstraction;
22

3+
import com.laytonsmith.core.environments.Environment;
34
import java.util.List;
45

56
public interface MCCommand extends AbstractionObject {
@@ -52,7 +53,7 @@ public interface MCCommand extends AbstractionObject {
5253

5354
List<String> tabComplete(MCCommandSender sender, String alias, String[] args);
5455

55-
List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args);
56+
List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args, Environment env);
5657

5758
boolean handleCustomCommand(MCCommandSender sender, String label, String[] args);
5859
}

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ public String toString() {
211211
}
212212

213213
@Override
214-
public List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args) {
214+
public List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args, Environment env) {
215215
if(Commands.onTabComplete.containsKey(cmd.getName().toLowerCase())) {
216216
Target t = Target.UNKNOWN;
217217
Callable closure = Commands.onTabComplete.get(cmd.getName().toLowerCase());
218-
Environment env = closure.getEnv();
218+
env = closure.getEnv();
219219
CArray cargs = new CArray(t, GenericParameters.emptyBuilder(CArray.TYPE)
220220
.addNativeParameter(CString.TYPE, null).buildNative(), env);
221221
for(String arg : args) {
@@ -270,7 +270,7 @@ public boolean handleCustomCommand(MCCommandSender sender, String label, String[
270270
Mixed fret = closure.executeCallable(null, t, new CString(label, t), new CString(sender.getName(), t), cargs,
271271
new CArray(t, null, env) // reserved for an obgen style command array
272272
);
273-
if(fret.isInstanceOf(CBoolean.TYPE, null, env)) {
273+
if(fret instanceof CBoolean) {
274274
return ((CBoolean) fret).getBoolean();
275275
}
276276
} catch (ConfigRuntimeException cre) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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.environments.Environment;
1213
import com.laytonsmith.core.exceptions.CRE.CRECastException;
1314
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
1415
import com.laytonsmith.core.environments.Environment;
@@ -124,11 +125,18 @@ <T extends Mixed, Z> MCTagType(BiFunction<T, Environment, Z> conversion, BiFunct
124125
this.construction = construction;
125126
}
126127

128+
/** @deprecated Use {@link #convert(MCTagContainer, Mixed, Environment)} instead. */
129+
@Deprecated
130+
public Object convert(MCTagContainer container, Mixed value) {
131+
return convert(container, value, null);
132+
}
133+
127134
/**
128135
* Returns a Java object from a MethodScript construct.
129136
* Throws a ConfigRuntimeException if the value is not valid for this tag type.
130137
* @param container the tag container context
131138
* @param value MethodScript construct
139+
* @param env
132140
* @return a Java object
133141
*/
134142
public Object convert(MCTagContainer container, Mixed value, Environment env) {

src/main/java/com/laytonsmith/commandhelper/CommandHelperPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ public void registerEventsDynamic(Listener listener) {
536536
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
537537
MCCommandSender mcsender = BukkitConvertor.BukkitGetCorrectSender(sender);
538538
MCCommand cmd = new BukkitMCCommand(command);
539-
return cmd.handleTabComplete(mcsender, alias, args);
539+
// TODO: Figure out how to get an env here
540+
return cmd.handleTabComplete(mcsender, alias, args, null);
540541
}
541542

542543
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static long getInt(Mixed c, Target t, Environment env) {
315315
}
316316
if(c instanceof CInt || c.isInstanceOf(CInt.TYPE, null, env)) {
317317
i = getObject(c, t, CInt.class).getInt();
318-
} else if(c.isInstanceOf(CBoolean.TYPE, null, env)) {
318+
} else if(c instanceof CBoolean) {
319319
if(getObject(c, t, CBoolean.class).getBoolean()) {
320320
i = 1;
321321
} else {

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ public MCItemStack item(Mixed i, Target t, Environment env) {
333333
return item(i, t, false, env);
334334
}
335335

336+
/**
337+
* @deprecated Use {@link #item(Mixed, Target, boolean, Environment)} instead.
338+
*/
336339
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
337340
@Deprecated
338341
public MCItemStack item(Mixed i, Target t, boolean legacy) {
@@ -2170,7 +2173,7 @@ public Vector3D vector(Vector3D v, Mixed c, Target t) {
21702173
*/
21712174
public Vector3D vector(Vector3D v, Mixed c, Target t, Environment env) {
21722175
if(c.isInstanceOf(CArray.TYPE, null, env)) {
2173-
CArray va = (CArray) c;
2176+
CArray va = (CArray) c;
21742177
double x = v.X();
21752178
double y = v.Y();
21762179
double z = v.Z();
@@ -2427,6 +2430,9 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t, Enviro
24272430
return ea;
24282431
}
24292432

2433+
/**
2434+
* @deprecated Use {@link #potions(CArray, Target, Environment)} instead.
2435+
*/
24302436
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
24312437
@Deprecated
24322438
public List<MCLivingEntity.MCEffect> potions(CArray ea, Target t) {
@@ -2497,6 +2503,9 @@ public CArray potionData(MCPotionData mcpd, Target t, Environment env) {
24972503
return base;
24982504
}
24992505

2506+
/**
2507+
* @deprecated Use {@link #potionData(CArray, Target, Environment)} instead.
2508+
*/
25002509
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
25012510
@Deprecated
25022511
public MCPotionData potionData(CArray pd, Target t) {
@@ -2523,7 +2532,7 @@ public MCPotionData potionData(CArray pd, Target t, Environment env) {
25232532
}
25242533
if(pd.containsKey("upgraded")) {
25252534
Mixed cupg = pd.get("upgraded", t, env);
2526-
if(cupg.isInstanceOf(CBoolean.TYPE, null, env)) {
2535+
if(cupg instanceof CBoolean) {
25272536
upgraded = ((CBoolean) cupg).getBoolean();
25282537
} else {
25292538
throw new CREFormatException(
@@ -2537,6 +2546,9 @@ public MCPotionData potionData(CArray pd, Target t, Environment env) {
25372546
}
25382547
}
25392548

2549+
/**
2550+
* @deprecated Use {@link #legacyPotionData(CArray, Target, Environment)} instead.
2551+
*/
25402552
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
25412553
@Deprecated
25422554
public MCPotionType legacyPotionData(CArray potionArray, Target t) {
@@ -2558,13 +2570,13 @@ public MCPotionType legacyPotionData(CArray potionArray, Target t, Environment e
25582570
boolean upgraded = false;
25592571
if(potionArray.containsKey("extended")) {
25602572
Mixed cext = potionArray.get("extended", t, env);
2561-
if(cext.isInstanceOf(CBoolean.TYPE, null, env)) {
2573+
if(cext instanceof CBoolean) {
25622574
extended = ((CBoolean) cext).getBoolean();
25632575
}
25642576
}
25652577
if(potionArray.containsKey("upgraded")) {
25662578
Mixed cupg = potionArray.get("upgraded", t, env);
2567-
if(cupg.isInstanceOf(CBoolean.TYPE, null, env)) {
2579+
if(cupg instanceof CBoolean) {
25682580
upgraded = ((CBoolean) cupg).getBoolean();
25692581
}
25702582
}
@@ -3117,6 +3129,9 @@ private Construct blockState(String value) {
31173129
return new CString(value, Target.UNKNOWN);
31183130
}
31193131

3132+
/**
3133+
* @deprecated Use {@link #particleData(MCParticle, MCLocation, CArray, Target, Environment)} instead.
3134+
*/
31203135
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
31213136
@Deprecated
31223137
public Object particleData(MCParticle particleType, MCLocation l, CArray pa, Target t) {
@@ -3348,4 +3363,4 @@ public CArray regMatchValue(MatchResult matchResult, Target t) {
33483363

33493364
return ret;
33503365
}
3351-
}
3366+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public Mixed eval(ParseTree c, final Environment env) throws CancelCommandExcept
425425
if(f.shouldProfile()) {
426426
Profiler profiler = env.getEnv(StaticRuntimeEnv.class).GetProfiler();
427427
if(profiler.isLoggable(f.profileAt())) {
428-
p = profiler.start(f.profileMessage(env, args), f.profileAt());
428+
p = profiler.start(Function.ExecuteProfileMessage(f, env, args), f.profileAt());
429429
}
430430
}
431431
Mixed ret;

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.laytonsmith.core.constructs.CString;
4545
import com.laytonsmith.core.constructs.CVoid;
4646
import com.laytonsmith.core.constructs.Construct;
47+
import com.laytonsmith.core.constructs.InstanceofUtil;
4748
import com.laytonsmith.core.constructs.NativeTypeList;
4849
import com.laytonsmith.core.constructs.Target;
4950
import com.laytonsmith.core.constructs.Variable;
@@ -844,6 +845,9 @@ public static UUID GetUUID(Mixed subject, Target t) {
844845
return GetUUID(subject.val(), t);
845846
}
846847

848+
/**
849+
* @deprecated Use {@link #GetUser(Mixed, Target, Environment)} instead.
850+
*/
847851
@Deprecated
848852
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
849853
public static MCOfflinePlayer GetUser(Mixed search, Target t) {
@@ -854,6 +858,9 @@ public static MCOfflinePlayer GetUser(Mixed search, Target t, Environment env) {
854858
return GetUser(search.val(), t, env);
855859
}
856860

861+
/**
862+
* @deprecated Use {@link #GetUser(String, Target, Environment)} instead.
863+
*/
857864
@Deprecated
858865
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
859866
public static MCOfflinePlayer GetUser(String search, Target t) {
@@ -867,6 +874,7 @@ public static MCOfflinePlayer GetUser(String search, Target t) {
867874
*
868875
* @param search The text to be searched, can be between 1 and 16 characters, or 32 or 36 characters
869876
* @param t
877+
* @param env
870878
* @return
871879
*/
872880
public static MCOfflinePlayer GetUser(String search, Target t, Environment env) {
@@ -904,6 +912,9 @@ public static MCOfflinePlayer GetUser(String search, Target t, Environment env)
904912
* @deprecated This method doesn't work with user classes, and will cause errors once those are introduced. This
905913
* will be removed once those are added, instead, use the version with the environment.
906914
*/
915+
/**
916+
* @deprecated Use {@link #GetPlayer(String, Target, Environment)} instead.
917+
*/
907918
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
908919
@Deprecated
909920
public static MCPlayer GetPlayer(String player, Target t) throws ConfigRuntimeException {
@@ -945,9 +956,9 @@ public static MCPlayer GetPlayer(Mixed player, Target t, Environment env) throws
945956
}
946957

947958
/**
948-
* Returns the player specified by name.Injected players also are returned in this list. If provided a string
959+
* Returns the player specified by name or UUID. Injected players are also returned in this list. If provided a string
949960
* between 1 and 16 characters, the lookup will be name-based. If provided a string that is 32 or 36 characters, the
950-
* lookup will be uuid-based.
961+
* lookup will be UUID-based. Throws CREPlayerOfflineException if the player is not online.
951962
*
952963
* @param player
953964
* @param t
@@ -956,8 +967,6 @@ public static MCPlayer GetPlayer(Mixed player, Target t, Environment env) throws
956967
* @throws ConfigRuntimeException
957968
*/
958969
public static MCPlayer GetPlayer(String player, Target t, Environment env) throws ConfigRuntimeException {
959-
MCCommandSender m;
960-
961970
if(player == null) {
962971
throw new CREPlayerOfflineException("No player was specified!", t);
963972
}
@@ -990,6 +999,8 @@ public static MCPlayer GetPlayer(String player, Target t, Environment env) throw
990999
return p;
9911000
}
9921001

1002+
1003+
9931004
/**
9941005
* Returns the specified command sender by name. Players are supported, as is the special ~console user. The special
9951006
* ~console user will always return a user. Throws CREPlayerOfflineException if the player is not online or injected.
@@ -1727,6 +1738,14 @@ public String getString(CResource res) {
17271738
}
17281739
}
17291740

1741+
/**
1742+
* @deprecated Use {@link #getJavaObject(Mixed, Environment)} instead.
1743+
*/
1744+
@Deprecated
1745+
public static Object getJavaObject(Mixed construct) {
1746+
return getJavaObject(construct, null);
1747+
}
1748+
17301749
/**
17311750
* Given a MethodScript object, returns a java object.
17321751
*
@@ -1745,7 +1764,7 @@ public static Object getJavaObject(Mixed construct, Environment env) {
17451764
return ((CInt) construct).getInt();
17461765
} else if(construct instanceof CDouble) {
17471766
return ((CDouble) construct).getDouble();
1748-
} else if(construct instanceof CString) {
1767+
} else if(InstanceofUtil.isInstanceof(construct, CString.class, env)) {
17491768
return construct.val();
17501769
} else if(construct instanceof CByteArray) {
17511770
return ((CByteArray) construct).asByteArrayCopy();
@@ -1815,7 +1834,7 @@ public static Object getJavaObject(Mixed construct, Environment env) {
18151834
}
18161835
}
18171836
} else {
1818-
return construct;
1837+
throw new ClassCastException(construct.getClass().getName() + " cannot be cast to a POJO");
18191838
}
18201839
}
18211840

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public static String optimize(String script, Environment env,
8282
StringBuilder b = new StringBuilder();
8383
//The root always contains null.
8484
for(ParseTree child : tree.getChildren()) {
85-
b.append(optimize0(child));
85+
b.append(optimize0(child, env));
8686
}
8787
return b.toString();
8888
}
8989

90-
private static String optimize0(ParseTree node) {
90+
private static String optimize0(ParseTree node, Environment env) {
9191
if(node.getData() instanceof CFunction cFunction) {
9292
StringBuilder b = new StringBuilder();
9393
boolean first = true;
@@ -101,7 +101,7 @@ private static String optimize0(ParseTree node) {
101101
b.append(",");
102102
}
103103
first = false;
104-
b.append(optimize0(child));
104+
b.append(optimize0(child, env));
105105
}
106106
b.append(")");
107107
return b.toString();
@@ -129,7 +129,7 @@ private static String optimize0(ParseTree node) {
129129
b.append(",");
130130
}
131131
first = false;
132-
b.append(optimize0(new ParseTree(n.get(key, Target.UNKNOWN), node.getFileOptions(), true)));
132+
b.append(optimize0(new ParseTree(n.get(key, Target.UNKNOWN), node.getFileOptions(), true), env));
133133
}
134134
b.append(")");
135135
return b.toString();

0 commit comments

Comments
 (0)