Skip to content

Commit 81a0c3c

Browse files
committed
Improve handling of ~console in user functions
1 parent 5635d79 commit 81a0c3c

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,11 @@ public static MCOfflinePlayer GetUser(Mixed search, Target t) {
845845
public static MCOfflinePlayer GetUser(String search, Target t) {
846846
MCOfflinePlayer ofp;
847847
if(search.length() > 0 && search.length() <= 16) {
848-
ofp = getServer().getOfflinePlayer(search);
848+
if(CONSOLE_NAME.equals(search)) {
849+
ofp = null;
850+
} else {
851+
ofp = getServer().getOfflinePlayer(search);
852+
}
849853
} else {
850854
try {
851855
ofp = getServer().getOfflinePlayer(GetUUID(search, t));

src/main/java/com/laytonsmith/core/functions/Environment.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,15 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro
986986
if(!(blockState instanceof MCSkull skull)) {
987987
throw new CRERangeException("The block at the specified location is not a skull", t);
988988
}
989-
MCOfflinePlayer owner = (args[1] instanceof CNull ? null : Static.GetUser(args[1], t));
989+
MCOfflinePlayer owner;
990+
if(args[1] instanceof CNull) {
991+
owner = null;
992+
} else {
993+
owner = Static.GetUser(args[1], t);
994+
if(owner == null) {
995+
throw new CRENotFoundException(this.getName() + " could not get offline player: " + args[1].val(), t);
996+
}
997+
}
990998
if(owner != null && args.length == 3) {
991999
MCPlayerProfile profile = Static.getServer().getPlayerProfile(owner.getUniqueID(), owner.getName());
9921000
if(profile != null) {

src/main/java/com/laytonsmith/core/functions/PlayerManagement.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,12 +5096,15 @@ public Boolean runAsync() {
50965096

50975097
@Override
50985098
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
5099-
MCCommandSender cs = environment.getEnv(CommandHelperEnvironment.class).GetCommandSender();
5100-
MCOfflinePlayer op = null;
5099+
MCOfflinePlayer op;
51015100
if(args.length == 1) {
51025101
op = Static.GetUser(args[0].val(), t);
5103-
} else if(cs != null) {
5104-
op = Static.GetUser(cs.getName(), t);
5102+
} else {
5103+
op = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
5104+
if(op == null) {
5105+
throw new CREInsufficientArgumentsException(this.getName()
5106+
+ " requires a player argument when ran from a non-player", t);
5107+
}
51055108
}
51065109
return new CInt((op == null ? 0 : op.getFirstPlayed()), t); // Return 0 for fake/null command senders.
51075110
}
@@ -5160,12 +5163,15 @@ public Boolean runAsync() {
51605163

51615164
@Override
51625165
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
5163-
MCCommandSender cs = environment.getEnv(CommandHelperEnvironment.class).GetCommandSender();
5164-
MCOfflinePlayer op = null;
5166+
MCOfflinePlayer op;
51655167
if(args.length == 1) {
51665168
op = Static.GetUser(args[0].val(), t);
5167-
} else if(cs != null) {
5168-
op = Static.GetUser(cs.getName(), t);
5169+
} else {
5170+
op = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
5171+
if(op == null) {
5172+
throw new CREInsufficientArgumentsException(this.getName()
5173+
+ " requires a player argument when ran from a non-player", t);
5174+
}
51695175
}
51705176
return new CInt((op == null ? 0 : op.getLastPlayed()), t); // Return 0 for fake/null command senders.
51715177
}

0 commit comments

Comments
 (0)