Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Merge branch 'master' into inventory
Dieser Commit ist enthalten in:
Commit
7e54170473
@ -26,8 +26,11 @@
|
||||
package org.geysermc.connector.entity;
|
||||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.CommandPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
@ -39,6 +42,8 @@ import lombok.Setter;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.scoreboard.Team;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
import org.geysermc.connector.network.session.cache.EntityEffectCache;
|
||||
import org.geysermc.connector.utils.SkinUtils;
|
||||
|
||||
@ -155,4 +160,27 @@ public class PlayerEntity extends LivingEntity {
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position.add(0, entityType.getOffset(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||
super.updateBedrockMetadata(entityMetadata, session);
|
||||
|
||||
if (entityMetadata.getId() == 2) {
|
||||
// System.out.println(session.getScoreboardCache().getScoreboard().getObjectives().keySet());
|
||||
for (Team team : session.getScoreboardCache().getScoreboard().getTeams().values()) {
|
||||
// session.getConnector().getLogger().info("team name " + team.getName());
|
||||
// session.getConnector().getLogger().info("team entities " + team.getEntities());
|
||||
}
|
||||
String username = this.username;
|
||||
TextMessage name = (TextMessage) entityMetadata.getValue();
|
||||
if (name != null) {
|
||||
username = MessageUtils.getBedrockMessage(name);
|
||||
}
|
||||
Team team = session.getScoreboardCache().getScoreboard().getTeamFor(username);
|
||||
if (team != null) {
|
||||
// session.getConnector().getLogger().info("team name es " + team.getName() + " with prefix " + team.getPrefix() + " and suffix " + team.getSuffix());
|
||||
metadata.put(EntityData.NAMETAG, team.getPrefix() + MessageUtils.toChatColor(team.getColor()) + username + team.getSuffix());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Translator(packet = AnimatePacket.class)
|
||||
public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
|
||||
|
||||
@ -40,8 +42,12 @@ public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
|
||||
public void translate(AnimatePacket packet, GeyserSession session) {
|
||||
switch (packet.getAction()) {
|
||||
case SWING_ARM:
|
||||
ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND);
|
||||
session.getDownstream().getSession().send(swingArmPacket);
|
||||
// Delay so entity damage can be processed first
|
||||
session.getConnector().getGeneralThreadPool().schedule(() ->
|
||||
session.getDownstream().getSession().send(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)),
|
||||
25,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
break;
|
||||
case ITEM_RELEASE:
|
||||
if (packet.getActionType() == 0) {
|
||||
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(0, 0, 0), BlockFace.DOWN);
|
||||
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(
|
||||
packet.getBlockPosition().getX(),
|
||||
packet.getBlockPosition().getY(),
|
||||
packet.getBlockPosition().getZ()
|
||||
), BlockFace.values()[packet.getFace()]);
|
||||
session.getDownstream().getSession().send(releaseItemPacket);
|
||||
}
|
||||
break;
|
||||
|
@ -52,12 +52,14 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||
case CREATE:
|
||||
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||
.setColor(packet.getColor())
|
||||
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
|
||||
break;
|
||||
case UPDATE:
|
||||
scoreboard.getTeam(packet.getTeamName())
|
||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||
.setColor(packet.getColor())
|
||||
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
|
||||
.setUpdateType(UpdateType.UPDATE);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.connector.scoreboard;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -44,10 +45,10 @@ public class Team {
|
||||
private UpdateType updateType = UpdateType.ADD;
|
||||
private String name;
|
||||
private String prefix;
|
||||
private TeamColor color;
|
||||
private String suffix;
|
||||
private Set<String> entities = new ObjectOpenHashSet<>();
|
||||
|
||||
|
||||
public Team(Scoreboard scoreboard, String id) {
|
||||
this.scoreboard = scoreboard;
|
||||
this.id = id;
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.connector.utils;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||
import com.github.steveice10.mc.protocol.data.message.ChatColor;
|
||||
import com.github.steveice10.mc.protocol.data.message.ChatFormat;
|
||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||
@ -36,20 +37,19 @@ import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageUtils {
|
||||
|
||||
public static List<String> getTranslationParams(Message[] messages) {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
if (messages[i] instanceof TranslationMessage) {
|
||||
TranslationMessage translation = (TranslationMessage) messages[i];
|
||||
List<String> strings = new ArrayList<>();
|
||||
for (Message message : messages) {
|
||||
if (message instanceof TranslationMessage) {
|
||||
TranslationMessage translation = (TranslationMessage) message;
|
||||
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
builder.append("%");
|
||||
builder.append(translation.getTranslationKey());
|
||||
strings.add(builder.toString());
|
||||
String builder = "%" + translation.getTranslationKey();
|
||||
strings.add(builder);
|
||||
|
||||
if (translation.getTranslationKey().equals("commands.gamemode.success.other")) {
|
||||
strings.add("");
|
||||
@ -59,15 +59,12 @@ public class MessageUtils {
|
||||
strings.add(" - no permission or invalid command!");
|
||||
}
|
||||
|
||||
for (int j = 0; j < getTranslationParams(translation.getTranslationParams()).size(); j++) {
|
||||
strings.add(getTranslationParams(translation.getTranslationParams()).get(j));
|
||||
}
|
||||
strings.addAll(getTranslationParams(translation.getTranslationParams()));
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
builder.append(getFormat(messages[i].getStyle().getFormats()));
|
||||
builder.append(getColor(messages[i].getStyle().getColor()));
|
||||
builder.append(getBedrockMessage(messages[i]));
|
||||
strings.add(builder.toString());
|
||||
String builder = getFormat(message.getStyle().getFormats()) +
|
||||
getColor(message.getStyle().getColor()) +
|
||||
getBedrockMessage(message);
|
||||
strings.add(builder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,12 +72,8 @@ public class MessageUtils {
|
||||
}
|
||||
|
||||
public static String getTranslationText(TranslationMessage message) {
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
builder.append(getFormat(message.getStyle().getFormats()));
|
||||
builder.append(getColor(message.getStyle().getColor()));
|
||||
builder.append("%");
|
||||
builder.append(message.getTranslationKey());
|
||||
return builder.toString();
|
||||
return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor())
|
||||
+ "%" + message.getTranslationKey();
|
||||
}
|
||||
|
||||
public static String getBedrockMessage(Message message) {
|
||||
@ -98,7 +91,6 @@ public class MessageUtils {
|
||||
builder.append(getBedrockMessage(msg));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@ -206,7 +198,6 @@ public class MessageUtils {
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -231,7 +222,20 @@ public class MessageUtils {
|
||||
formatJson((JsonObject) a.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
public static String toChatColor(TeamColor teamColor) {
|
||||
for (ChatColor color : ChatColor.values()) {
|
||||
if (color.name().equals(teamColor.name())) {
|
||||
return getColor(color);
|
||||
}
|
||||
}
|
||||
for (ChatFormat format : ChatFormat.values()) {
|
||||
if (format.name().equals(teamColor.name())) {
|
||||
return getFormat(Collections.singletonList(format));
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren