forked from GeyserMC/Geyser
Merge branch 'master' of https://github.com/GeyserMC/Geyser
This commit is contained in:
commit
3574212b4b
9 changed files with 205 additions and 84 deletions
|
@ -43,10 +43,8 @@ public class AgeableEntity extends CreatureEntity {
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
if (entityMetadata.getId() == 15) {
|
if (entityMetadata.getId() == 15) {
|
||||||
boolean isBaby = (boolean) entityMetadata.getValue();
|
boolean isBaby = (boolean) entityMetadata.getValue();
|
||||||
if (isBaby) {
|
metadata.put(EntityData.SCALE, isBaby ? .55f : 1f);
|
||||||
metadata.put(EntityData.SCALE, .55f);
|
metadata.getFlags().setFlag(EntityFlag.BABY, isBaby);
|
||||||
metadata.getFlags().setFlag(EntityFlag.BABY, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
|
|
@ -44,9 +44,19 @@ public class WolfEntity extends TameableEntity {
|
||||||
if (entityMetadata.getId() == 18) {
|
if (entityMetadata.getId() == 18) {
|
||||||
metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue());
|
metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Reset wolf color
|
||||||
|
if (entityMetadata.getId() == 16) {
|
||||||
|
byte xd = (byte) entityMetadata.getValue();
|
||||||
|
boolean angry = (xd & 0x02) == 0x02;
|
||||||
|
if (angry) {
|
||||||
|
metadata.put(EntityData.COLOR, (byte) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wolf collar color
|
// Wolf collar color
|
||||||
// Relies on EntityData.OWNER_EID being set in TameableEntity.java
|
// Relies on EntityData.OWNER_EID being set in TameableEntity.java
|
||||||
if (entityMetadata.getId() == 19) {
|
if (entityMetadata.getId() == 19 && !metadata.getFlags().getFlag(EntityFlag.ANGRY)) {
|
||||||
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue());
|
||||||
}
|
}
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
|
|
@ -49,8 +49,10 @@ public class ShulkerEntity extends GolemEntity {
|
||||||
}
|
}
|
||||||
if (entityMetadata.getId() == 16) {
|
if (entityMetadata.getId() == 16) {
|
||||||
Position position = (Position) entityMetadata.getValue();
|
Position position = (Position) entityMetadata.getValue();
|
||||||
|
if (position != null) {
|
||||||
metadata.put(EntityData.SHULKER_ATTACH_POS, Vector3i.from(position.getX(), position.getY(), position.getZ()));
|
metadata.put(EntityData.SHULKER_ATTACH_POS, Vector3i.from(position.getX(), position.getY(), position.getZ()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//TODO Outdated metadata flag SHULKER_PEAK_HEIGHT
|
//TODO Outdated metadata flag SHULKER_PEAK_HEIGHT
|
||||||
// if (entityMetadata.getId() == 17) {
|
// if (entityMetadata.getId() == 17) {
|
||||||
// int height = (byte) entityMetadata.getValue();
|
// int height = (byte) entityMetadata.getValue();
|
||||||
|
|
121
connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java
vendored
Normal file
121
connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java
vendored
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.network.session.cache;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.AddEntityPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.BossEventPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BossBar {
|
||||||
|
|
||||||
|
private GeyserSession session;
|
||||||
|
|
||||||
|
private long entityId;
|
||||||
|
private Message title;
|
||||||
|
private float health;
|
||||||
|
private int color;
|
||||||
|
private int overlay;
|
||||||
|
private int darkenSky;
|
||||||
|
|
||||||
|
public void addBossBar() {
|
||||||
|
addBossEntity();
|
||||||
|
updateBossBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateBossBar() {
|
||||||
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
|
bossEventPacket.setAction(BossEventPacket.Action.SHOW);
|
||||||
|
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getClientData().getLanguageCode()));
|
||||||
|
bossEventPacket.setHealthPercentage(health);
|
||||||
|
bossEventPacket.setColor(color); //ignored by client
|
||||||
|
bossEventPacket.setOverlay(overlay);
|
||||||
|
bossEventPacket.setDarkenSky(darkenSky);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(bossEventPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTitle(Message title) {
|
||||||
|
this.title = title;
|
||||||
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
|
bossEventPacket.setAction(BossEventPacket.Action.TITLE);
|
||||||
|
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(title, session.getClientData().getLanguageCode()));
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(bossEventPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateHealth(float health) {
|
||||||
|
this.health = health;
|
||||||
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
|
bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE);
|
||||||
|
bossEventPacket.setHealthPercentage(health);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(bossEventPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBossBar() {
|
||||||
|
BossEventPacket bossEventPacket = new BossEventPacket();
|
||||||
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
|
bossEventPacket.setAction(BossEventPacket.Action.HIDE);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(bossEventPacket);
|
||||||
|
removeBossEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bedrock still needs an entity to display the BossBar.<br>
|
||||||
|
* Just like 1.8 but it doesn't care about which entity
|
||||||
|
*/
|
||||||
|
private void addBossEntity() {
|
||||||
|
AddEntityPacket addEntityPacket = new AddEntityPacket();
|
||||||
|
addEntityPacket.setUniqueEntityId(entityId);
|
||||||
|
addEntityPacket.setRuntimeEntityId(entityId);
|
||||||
|
addEntityPacket.setIdentifier("minecraft:creeper");
|
||||||
|
addEntityPacket.setEntityType(33);
|
||||||
|
addEntityPacket.setPosition(session.getPlayerEntity().getPosition());
|
||||||
|
addEntityPacket.setRotation(Vector3f.ZERO);
|
||||||
|
addEntityPacket.setMotion(Vector3f.ZERO);
|
||||||
|
addEntityPacket.getMetadata().put(EntityData.SCALE, 0.01F); // scale = 0 doesn't work?
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(addEntityPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeBossEntity() {
|
||||||
|
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
|
||||||
|
removeEntityPacket.setUniqueEntityId(entityId);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(removeEntityPacket);
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,7 +48,7 @@ public class EntityCache {
|
||||||
private Long2ObjectMap<Entity> entities = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
|
private Long2ObjectMap<Entity> entities = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
|
||||||
private Long2LongMap entityIdTranslations = Long2LongMaps.synchronize(new Long2LongOpenHashMap());
|
private Long2LongMap entityIdTranslations = Long2LongMaps.synchronize(new Long2LongOpenHashMap());
|
||||||
private Map<UUID, PlayerEntity> playerEntities = Collections.synchronizedMap(new HashMap<>());
|
private Map<UUID, PlayerEntity> playerEntities = Collections.synchronizedMap(new HashMap<>());
|
||||||
private Object2LongMap<UUID> bossbars = new Object2LongOpenHashMap<>();
|
private Map<UUID, BossBar> bossBars = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private AtomicLong nextEntityId = new AtomicLong(2L);
|
private AtomicLong nextEntityId = new AtomicLong(2L);
|
||||||
|
@ -116,24 +116,30 @@ public class EntityCache {
|
||||||
playerEntities.remove(uuid);
|
playerEntities.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long addBossBar(UUID uuid) {
|
public void addBossBar(UUID uuid, BossBar bossBar) {
|
||||||
long entityId = getNextEntityId().incrementAndGet();
|
bossBars.put(uuid, bossBar);
|
||||||
bossbars.put(uuid, entityId);
|
bossBar.addBossBar();
|
||||||
return entityId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getBossBar(UUID uuid) {
|
public BossBar getBossBar(UUID uuid) {
|
||||||
return bossbars.containsKey(uuid) ? bossbars.get(uuid) : -1;
|
return bossBars.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long removeBossBar(UUID uuid) {
|
public void removeBossBar(UUID uuid) {
|
||||||
return bossbars.remove(uuid);
|
BossBar bossBar = bossBars.remove(uuid);
|
||||||
|
if (bossBar != null) {
|
||||||
|
bossBar.removeBossBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateBossBars() {
|
||||||
|
bossBars.values().forEach(BossBar::updateBossBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
entities = null;
|
entities = null;
|
||||||
entityIdTranslations = null;
|
entityIdTranslations = null;
|
||||||
playerEntities = null;
|
playerEntities = null;
|
||||||
bossbars = null;
|
bossBars = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||||
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||||
session.getUpstream().sendPacket(spawnPacket);
|
session.getUpstream().sendPacket(spawnPacket);
|
||||||
entity.updateBedrockAttributes(session);
|
entity.updateBedrockAttributes(session);
|
||||||
|
session.getEntityCache().updateBossBars();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JUMP:
|
case JUMP:
|
||||||
|
|
|
@ -85,11 +85,23 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//https://wiki.vg/Protocol#Interact_Entity
|
||||||
|
switch (packet.getActionType()) {
|
||||||
|
case 0: //Interact
|
||||||
Vector3f vector = packet.getClickPosition();
|
Vector3f vector = packet.getClickPosition();
|
||||||
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
InteractAction.values()[packet.getActionType()], vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
|
InteractAction.INTERACT, Hand.MAIN_HAND);
|
||||||
|
ClientPlayerInteractEntityPacket interactAtPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
session.getDownstream().getSession().send(entityPacket);
|
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
|
||||||
|
session.getDownstream().getSession().send(interactPacket);
|
||||||
|
session.getDownstream().getSession().send(interactAtPacket);
|
||||||
|
break;
|
||||||
|
case 1: //Attack
|
||||||
|
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
|
InteractAction.ATTACK);
|
||||||
|
session.getDownstream().getSession().send(attackPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,80 +26,38 @@
|
||||||
package org.geysermc.connector.network.translators.java;
|
package org.geysermc.connector.network.translators.java;
|
||||||
|
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.session.cache.BossBar;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.utils.MessageUtils;
|
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerBossBarPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerBossBarPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import java.awt.*;
|
||||||
import com.nukkitx.protocol.bedrock.packet.AddEntityPacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.BossEventPacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
|
|
||||||
|
|
||||||
@Translator(packet = ServerBossBarPacket.class)
|
@Translator(packet = ServerBossBarPacket.class)
|
||||||
public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket> {
|
public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket> {
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerBossBarPacket packet, GeyserSession session) {
|
public void translate(ServerBossBarPacket packet, GeyserSession session) {
|
||||||
BossEventPacket bossEventPacket = new BossEventPacket();
|
BossBar bossBar = session.getEntityCache().getBossBar(packet.getUuid());
|
||||||
bossEventPacket.setBossUniqueEntityId(session.getEntityCache().getBossBar(packet.getUuid()));
|
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case ADD:
|
case ADD:
|
||||||
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
long entityId = session.getEntityCache().getNextEntityId().incrementAndGet();
|
||||||
addBossEntity(session, entityId);
|
bossBar = new BossBar(session, entityId, packet.getTitle(), packet.getHealth(), 0, 1, 0);
|
||||||
|
session.getEntityCache().addBossBar(packet.getUuid(), bossBar);
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.SHOW);
|
|
||||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
|
||||||
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), session.getClientData().getLanguageCode()));
|
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
|
||||||
bossEventPacket.setColor(0); //ignored by client
|
|
||||||
bossEventPacket.setOverlay(1);
|
|
||||||
bossEventPacket.setDarkenSky(0);
|
|
||||||
break;
|
break;
|
||||||
case UPDATE_TITLE:
|
case UPDATE_TITLE:
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.TITLE);
|
if (bossBar != null) bossBar.updateTitle(packet.getTitle());
|
||||||
bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), session.getClientData().getLanguageCode()));
|
|
||||||
break;
|
break;
|
||||||
case UPDATE_HEALTH:
|
case UPDATE_HEALTH:
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE);
|
if (bossBar != null) bossBar.updateHealth(packet.getHealth());
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
bossEventPacket.setAction(BossEventPacket.Action.HIDE);
|
session.getEntityCache().removeBossBar(packet.getUuid());
|
||||||
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
|
||||||
break;
|
break;
|
||||||
case UPDATE_STYLE:
|
case UPDATE_STYLE:
|
||||||
case UPDATE_FLAGS:
|
case UPDATE_FLAGS:
|
||||||
//todo
|
//todo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getUpstream().sendPacket(bossEventPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bedrock still needs an entity to display the BossBar.<br>
|
|
||||||
* Just like 1.8 but it doesn't care about which entity
|
|
||||||
*/
|
|
||||||
private void addBossEntity(GeyserSession session, long entityId) {
|
|
||||||
AddEntityPacket addEntityPacket = new AddEntityPacket();
|
|
||||||
addEntityPacket.setUniqueEntityId(entityId);
|
|
||||||
addEntityPacket.setRuntimeEntityId(entityId);
|
|
||||||
addEntityPacket.setIdentifier("minecraft:creeper");
|
|
||||||
addEntityPacket.setEntityType(33);
|
|
||||||
addEntityPacket.setPosition(session.getPlayerEntity().getPosition());
|
|
||||||
addEntityPacket.setRotation(Vector3f.ZERO);
|
|
||||||
addEntityPacket.setMotion(Vector3f.ZERO);
|
|
||||||
addEntityPacket.getMetadata().put(EntityData.SCALE, 0.01F); // scale = 0 doesn't work?
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(addEntityPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeBossEntity(GeyserSession session, long entityId) {
|
|
||||||
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
|
|
||||||
removeEntityPacket.setUniqueEntityId(entityId);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(removeEntityPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.scoreboard.Scoreboard;
|
import org.geysermc.connector.scoreboard.Scoreboard;
|
||||||
|
import org.geysermc.connector.scoreboard.Team;
|
||||||
import org.geysermc.connector.scoreboard.UpdateType;
|
import org.geysermc.connector.scoreboard.UpdateType;
|
||||||
import org.geysermc.connector.utils.MessageUtils;
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
|
@ -45,9 +46,10 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerTeamPacket packet, GeyserSession session) {
|
public void translate(ServerTeamPacket packet, GeyserSession session) {
|
||||||
GeyserConnector.getInstance().getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction()+" "+ Arrays.toString(packet.getPlayers()));
|
GeyserConnector.getInstance().getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction() + " " + Arrays.toString(packet.getPlayers()));
|
||||||
|
|
||||||
Scoreboard scoreboard = session.getScoreboardCache().getScoreboard();
|
Scoreboard scoreboard = session.getScoreboardCache().getScoreboard();
|
||||||
|
Team team = scoreboard.getTeam(packet.getTeamName());
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
||||||
|
@ -57,18 +59,29 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
||||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
|
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()));
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
scoreboard.getTeam(packet.getTeamName())
|
if (team != null) {
|
||||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
.setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix()))
|
||||||
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
|
.setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix()))
|
||||||
.setUpdateType(UpdateType.UPDATE);
|
.setUpdateType(UpdateType.UPDATE);
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ADD_PLAYER:
|
case ADD_PLAYER:
|
||||||
scoreboard.getTeam(packet.getTeamName()).addEntities(packet.getPlayers());
|
if(team != null){
|
||||||
|
team.addEntities(packet.getPlayers());
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REMOVE_PLAYER:
|
case REMOVE_PLAYER:
|
||||||
scoreboard.getTeam(packet.getTeamName()).removeEntities(packet.getPlayers());
|
if(team != null){
|
||||||
|
team.removeEntities(packet.getPlayers());
|
||||||
|
} else {
|
||||||
|
GeyserConnector.getInstance().getLogger().error("Error while translating Team Packet " + packet.getAction() + "! Scoreboard Team " + packet.getTeamName() + " is not registered.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
scoreboard.removeTeam(packet.getTeamName());
|
scoreboard.removeTeam(packet.getTeamName());
|
||||||
|
|
Loading…
Reference in a new issue