bugfix get_string, expand player vars, add TokenMessage, improvements to TokenParticle and TokenPlayer
All checks were successful
/ Auto-Build-App (push) Successful in 1m38s
All checks were successful
/ Auto-Build-App (push) Successful in 1m38s
This commit is contained in:
parent
3a9074b80e
commit
f9f538589f
5 changed files with 97 additions and 14 deletions
|
@ -27,6 +27,8 @@ public class BaseScript {
|
||||||
for (String key : TokenMath.valid_tokens)
|
for (String key : TokenMath.valid_tokens)
|
||||||
tokens.put(key, new TokenMath());
|
tokens.put(key, new TokenMath());
|
||||||
|
|
||||||
|
tokens.put("message", new TokenMessage());
|
||||||
|
|
||||||
|
|
||||||
colors.put("light_gray", Color.LIGHT_GRAY);
|
colors.put("light_gray", Color.LIGHT_GRAY);
|
||||||
colors.put("gray", Color.GRAY);
|
colors.put("gray", Color.GRAY);
|
||||||
|
@ -173,7 +175,7 @@ public class BaseScript {
|
||||||
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
text.add(tokens[step]);
|
text.add(tokens[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +189,7 @@ public class BaseScript {
|
||||||
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
text.add(tokens[step]);
|
text.add(tokens[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -35,6 +35,8 @@ public class ExecutionContext {
|
||||||
|
|
||||||
public void store_player_data(Account account){
|
public void store_player_data(Account account){
|
||||||
variable.put("event_player_id", account.getUniqueId());
|
variable.put("event_player_id", account.getUniqueId());
|
||||||
|
variable.put("event_player_username", account.getUsername());
|
||||||
|
variable.put("event_player_displayname", account.getDisplayName());
|
||||||
Player player = account.getPlayer();
|
Player player = account.getPlayer();
|
||||||
Vector3 pos = player.getPosition();
|
Vector3 pos = player.getPosition();
|
||||||
variable.put("event_player_pos_x", pos.x);
|
variable.put("event_player_pos_x", pos.x);
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
package net.pietru.cookie_utils.scripting.tokens;
|
||||||
|
|
||||||
|
import finalforeach.cosmicreach.GameSingletons;
|
||||||
|
import finalforeach.cosmicreach.entities.player.Player;
|
||||||
|
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||||
|
import finalforeach.cosmicreach.networking.packets.ParticleSystemPacket;
|
||||||
|
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
|
import net.pietru.cookie_utils.scripting.BaseScript;
|
||||||
|
import net.pietru.cookie_utils.scripting.ExecutionContext;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.pietru.cookie_utils.utils.player_utils.parseAsPlayer;
|
||||||
|
|
||||||
|
public class TokenMessage implements BaseToken {
|
||||||
|
|
||||||
|
public static final List<String> optional_args = List.of(
|
||||||
|
"player",
|
||||||
|
"zone"
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get_token_checker_id() {
|
||||||
|
return "token_message";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canHandle(String[] tokens, int step) {
|
||||||
|
String token = tokens[step];
|
||||||
|
return token.equals("message") && tokens.length>=step+next_token(tokens,step);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token_name
|
||||||
|
* message
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public int next_token(String[] tokens, int step) {
|
||||||
|
ArrayList<String> msg_arr = BaseScript.get_string(tokens, step+1);
|
||||||
|
return 1+msg_arr.size()+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
||||||
|
tokens,
|
||||||
|
step+1+msg_arr.size(),
|
||||||
|
optional_args
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(String[] tokens, int step, ExecutionContext executionContext) {
|
||||||
|
String token = tokens[step];
|
||||||
|
if (!token.equals("message"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ArrayList<String> msg_arr = BaseScript.get_string(tokens, step+1);
|
||||||
|
String msg = BaseScript.get_if_variable(String.join(" ", msg_arr),executionContext);
|
||||||
|
|
||||||
|
Map<String,String> args = BaseScript.get_optional_args(
|
||||||
|
tokens,
|
||||||
|
step+1+msg_arr.size(),
|
||||||
|
optional_args,
|
||||||
|
executionContext
|
||||||
|
);
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket(msg);
|
||||||
|
if (args.containsKey("player")) {
|
||||||
|
Player player = parseAsPlayer(BaseScript.get_if_variable(args.get("player"), executionContext));
|
||||||
|
if (player == null) {
|
||||||
|
BaseScript.log_token_error(this, "Failed to parse player.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
packet.setupAndSend(ServerSingletons.getConnection(player));
|
||||||
|
} else {
|
||||||
|
if (args.containsKey("zone")) {
|
||||||
|
String zoneId = BaseScript.get_if_variable(args.get("zone"), executionContext);
|
||||||
|
Zone zone = GameSingletons.world.getZoneIfExists(zoneId);
|
||||||
|
if (zone != null)
|
||||||
|
ServerSingletons.SERVER.broadcast(zone, packet);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (Zone wz : GameSingletons.world.getZones())
|
||||||
|
ServerSingletons.SERVER.broadcast(wz, packet);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,11 +40,7 @@ public class TokenParticle implements BaseToken {
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(String[] tokens, int step) {
|
public boolean canHandle(String[] tokens, int step) {
|
||||||
String token = tokens[step];
|
String token = tokens[step];
|
||||||
return token.equals("particle") && tokens.length>=step+5+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
return token.equals("particle") && tokens.length>=step+next_token(tokens,step);
|
||||||
tokens,
|
|
||||||
step+5,
|
|
||||||
optional_args
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,11 +52,11 @@ public class TokenParticle implements BaseToken {
|
||||||
* */
|
* */
|
||||||
@Override
|
@Override
|
||||||
public int next_token(String[] tokens, int step) {
|
public int next_token(String[] tokens, int step) {
|
||||||
return 5+BaseScript.get_optional_args(
|
return 5+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
||||||
tokens,
|
tokens,
|
||||||
step+5,
|
step+5,
|
||||||
optional_args
|
optional_args
|
||||||
).size()*2;
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,11 +30,7 @@ public class TokenPlayer implements BaseToken {
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(String[] tokens, int step) {
|
public boolean canHandle(String[] tokens, int step) {
|
||||||
String token = tokens[step];
|
String token = tokens[step];
|
||||||
return token.equals("player") && tokens.length>=step+2+BaseScript.get_optional_args(
|
return token.equals("player") && tokens.length>=step+next_token(tokens,step);
|
||||||
tokens,
|
|
||||||
step,
|
|
||||||
optional_args
|
|
||||||
).size()*2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue