Merge branch 'master' into 1.16
# Conflicts: # src/main/java/carpet/utils/Messenger.java
This commit is contained in:
commit
5713d2bffc
4 files changed
+55
-33
No files matched your search
@@ -1295,6 +1295,26 @@ public class CarpetExpression
|
||||
|
||||
}
|
||||
|
||||
private static String getScoreboardKeyFromValue(Value keyValue)
|
||||
{
|
||||
if (keyValue instanceof EntityValue)
|
||||
{
|
||||
Entity e = ((EntityValue) keyValue).getEntity();
|
||||
if (e instanceof PlayerEntity)
|
||||
{
|
||||
return e.getName().getString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return e.getUuidAsString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return keyValue.getString();
|
||||
}
|
||||
}
|
||||
|
||||
private void API_Scoreboard()
|
||||
{
|
||||
// scoreboard(player,'objective')
|
||||
@@ -1316,24 +1336,7 @@ public class CarpetExpression
|
||||
Value ret = ListValue.wrap(scoreboard.getAllPlayerScores(objective).stream().map(s -> new StringValue(s.getPlayerName())).collect(Collectors.toList()));
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
String key;
|
||||
Value keyValue = lv.get(1).evalValue(c);
|
||||
if (keyValue instanceof EntityValue)
|
||||
{
|
||||
Entity e = ((EntityValue) keyValue).getEntity();
|
||||
if (e instanceof PlayerEntity)
|
||||
{
|
||||
key = e.getDisplayName().getString();
|
||||
}
|
||||
else
|
||||
{
|
||||
key = e.getUuidAsString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
key = keyValue.getString();
|
||||
}
|
||||
String key = getScoreboardKeyFromValue(lv.get(1).evalValue(c));
|
||||
if (!scoreboard.playerHasObjective(key, objective) && lv.size()==2)
|
||||
return LazyValue.NULL;
|
||||
ScoreboardPlayerScore scoreboardPlayerScore = scoreboard.getPlayerScore(key, objective);
|
||||
@@ -1345,15 +1348,24 @@ public class CarpetExpression
|
||||
return (_c, _t) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("scoreboard_remove", 1, (c, t, lv)-> {
|
||||
this.expr.addLazyFunction("scoreboard_remove", -1, (c, t, lv)-> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
String objectiveName = lv.get(0).evalValue(c).getString();
|
||||
ScoreboardObjective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective == null)
|
||||
return LazyValue.FALSE;
|
||||
scoreboard.removeObjective(objective);
|
||||
return LazyValue.TRUE;
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
scoreboard.removeObjective(objective);
|
||||
return LazyValue.TRUE;
|
||||
}
|
||||
String key = getScoreboardKeyFromValue(lv.get(1).evalValue(c));
|
||||
if (!scoreboard.playerHasObjective(key, objective)) return LazyValue.NULL;
|
||||
ScoreboardPlayerScore scoreboardPlayerScore = scoreboard.getPlayerScore(key, objective);
|
||||
Value previous = new NumericValue(scoreboardPlayerScore.getScore());
|
||||
scoreboard.resetPlayerScore(key, objective);
|
||||
return (c_, t_) -> previous;
|
||||
});
|
||||
|
||||
// objective_add('lvl','level')
|
||||
|
||||
@@ -3,7 +3,6 @@ package carpet.utils;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -80,7 +79,7 @@ public class Messenger
|
||||
}
|
||||
};
|
||||
|
||||
private static BaseText _applyStyleToTextComponent(BaseText comp, String style)
|
||||
public static Style parseStyle(String style)
|
||||
{
|
||||
Style myStyle= Style.EMPTY.withColor(Formatting.WHITE);
|
||||
for (CarpetFormatting cf: CarpetFormatting.values())
|
||||
@@ -154,7 +153,8 @@ public class Messenger
|
||||
return previous_message;
|
||||
}
|
||||
BaseText txt = new LiteralText(str);
|
||||
return _applyStyleToTextComponent(txt, desc);
|
||||
txt.setStyle(parseStyle(desc));
|
||||
return txt;
|
||||
}
|
||||
public static BaseText tp(String desc, Vec3d pos) { return tp(desc, pos.x, pos.y, pos.z); }
|
||||
public static BaseText tp(String desc, BlockPos pos) { return tp(desc, pos.getX(), pos.getY(), pos.getZ()); }
|
||||
@@ -274,7 +274,7 @@ public class Messenger
|
||||
public static BaseText s(String text, String style)
|
||||
{
|
||||
BaseText message = new LiteralText(text);
|
||||
_applyStyleToTextComponent(message, style);
|
||||
message.setStyle(parseStyle(style));
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user