Skip to content

Commit

Permalink
Allow location flag to be parsed for getSenderLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Oct 23, 2023
1 parent 7da3dcd commit b063a68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Expand Up @@ -35,7 +35,6 @@ public static StatusMapper mapping(Behavior wrapping, Supplier<BehaviorStatus> t

public static Behavior singleUse(Behavior base) {
return new Behavior() {

@Override
public void reset() {
base.reset();
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/net/citizensnpcs/api/command/CommandContext.java
Expand Up @@ -252,32 +252,37 @@ public String getRawCommand() {
}

public Location getSenderLocation() throws CommandException {
if (location != null || sender == null)
if (location != null)
return location;

if (hasValueFlag("location"))
return parseLocation(location, getFlag("location"));

Location base = null;
if (sender instanceof Player) {
location = ((Player) sender).getLocation();
base = ((Player) sender).getLocation();
} else if (sender instanceof BlockCommandSender) {
location = ((BlockCommandSender) sender).getBlock().getLocation();
base = ((BlockCommandSender) sender).getBlock().getLocation();
}
return location;

if (hasValueFlag("location"))
return location = parseLocation(base, getFlag("location"));

return location = base;
}

public Location getSenderTargetBlockLocation() throws CommandException {
if (sender == null)
if (location != null)
return location;
if (hasValueFlag("location")) {
return parseLocation(location, getFlag("location"));
}

Location base = null;
if (sender instanceof Player) {
location = ((Player) sender).getTargetBlock((java.util.Set<org.bukkit.Material>) null, 50).getLocation();
base = ((Player) sender).getTargetBlock((java.util.Set<org.bukkit.Material>) null, 50).getLocation();
} else if (sender instanceof BlockCommandSender) {
location = ((BlockCommandSender) sender).getBlock().getLocation();
base = ((BlockCommandSender) sender).getBlock().getLocation();
}
return location;

if (hasValueFlag("location"))
return location = parseLocation(base, getFlag("location"));

return location = base;
}

public String[] getSlice(int index) {
Expand Down Expand Up @@ -377,18 +382,21 @@ public static Location parseLocation(Location currentLocation, String flag) thro
case 6:
if (denizen) {
worldName = parts[5].replaceFirst("w@", "");
} else
} else {
pitch = Float.parseFloat(parts[5]);
}
case 5:
if (denizen) {
pitch = Float.parseFloat(parts[4]);
} else
} else {
yaw = Float.parseFloat(parts[4]);
}
case 4:
if (denizen && parts.length > 4) {
yaw = Float.parseFloat(parts[3]);
} else
} else {
worldName = parts[3].replaceFirst("w@", "");
}
case 3:
x = Double.parseDouble(parts[0]);
y = Double.parseDouble(parts[1]);
Expand Down

0 comments on commit b063a68

Please sign in to comment.