From 119f35b690d6e198f68775b917d8382b8293df20 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 6 Mar 2020 15:44:49 -0600 Subject: [PATCH 01/26] Fix chat getting cut off (Closes #188) --- .../java/org/geysermc/connector/utils/MessageUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 00dc98369..a47d013d4 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -164,7 +164,7 @@ public class MessageUtils { } private static String getFormat(List formats) { - String str = ""; + StringBuilder str = new StringBuilder(); for (ChatFormat cf : formats) { String base = "\u00a7"; switch (cf) { @@ -184,13 +184,13 @@ public class MessageUtils { base += "o"; break; default: - break; + return ""; } - str += base; + str.append(base); } - return str; + return str.toString(); } public static boolean isMessage(String text) { From e4c2f79bc51fdfca307ee29306faf4a752f17b08 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 6 Mar 2020 15:56:48 -0600 Subject: [PATCH 02/26] Fix a couple minor entity bugs --- .../main/java/org/geysermc/connector/entity/LivingEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index bbe72f996..c1e00798c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -64,7 +64,7 @@ public class LivingEntity extends Entity { metadata.put(EntityData.POTION_COLOR, (int) entityMetadata.getValue()); break; case 10: - // metadata.put(EntityData.POTION_AMBIENT, (boolean) entityMetadata.getValue()); + metadata.put(EntityData.POTION_AMBIENT, (boolean) entityMetadata.getValue()); break; } From 7bd53c95c3e92ed4a60faaa5693762616a0af65d Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 6 Mar 2020 17:29:11 -0600 Subject: [PATCH 03/26] Work on a lot more entity flags --- .../connector/entity/LivingEntity.java | 2 +- .../entity/living/animal/BeeEntity.java | 48 +++++++++++++++++ .../entity/living/animal/FoxEntity.java | 54 +++++++++++++++++++ .../entity/living/animal/OcelotEntity.java | 47 ++++++++++++++++ .../entity/living/animal/PandaEntity.java | 49 +++++++++++++++++ .../entity/living/animal/PigEntity.java | 47 ++++++++++++++++ .../entity/living/animal/PolarBearEntity.java | 47 ++++++++++++++++ .../animal/horse/AbstractHorseEntity.java | 7 +++ .../animal/horse/ChestedHorseEntity.java | 6 +-- .../living/animal/tameable/CatEntity.java | 51 ++++++++++++++++++ .../animal/{ => tameable}/TameableEntity.java | 16 +++++- .../living/animal/tameable/WolfEntity.java | 48 +++++++++++++++++ .../entity/living/monster/BlazeEntity.java | 49 +++++++++++++++++ .../entity/living/monster/CreeperEntity.java | 51 ++++++++++++++++++ .../entity/living/monster/SpiderEntity.java | 49 +++++++++++++++++ .../connector/entity/type/EntityType.java | 32 +++++------ .../connector/utils/MessageUtils.java | 2 +- 17 files changed, 583 insertions(+), 22 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java rename connector/src/main/java/org/geysermc/connector/entity/living/animal/{ => tameable}/TameableEntity.java (67%) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index c1e00798c..40b30f704 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -64,7 +64,7 @@ public class LivingEntity extends Entity { metadata.put(EntityData.POTION_COLOR, (int) entityMetadata.getValue()); break; case 10: - metadata.put(EntityData.POTION_AMBIENT, (boolean) entityMetadata.getValue()); + metadata.put(EntityData.POTION_AMBIENT, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0)); break; } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java new file mode 100644 index 000000000..db4858573 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java @@ -0,0 +1,48 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class BeeEntity extends AnimalEntity { + + public BeeEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java new file mode 100644 index 000000000..a277f8ee1 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java @@ -0,0 +1,54 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class FoxEntity extends AnimalEntity { + + public FoxEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + if (entityMetadata.getId() == 17) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); + metadata.getFlags().setFlag(EntityFlag.SNEAKING, (xd & 0x04) == 0x04); + metadata.getFlags().setFlag(EntityFlag.SLEEPING, (xd & 0x20) == 0x20); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java new file mode 100644 index 000000000..1c5dc9752 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java @@ -0,0 +1,47 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class OcelotEntity extends AnimalEntity { + + public OcelotEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + metadata.getFlags().setFlag(EntityFlag.TRUSTING, (boolean) entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java new file mode 100644 index 000000000..f22815c68 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java @@ -0,0 +1,49 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class PandaEntity extends AnimalEntity { + + public PandaEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 21) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.SNEEZING, (xd & 0x02) == 0x02); + metadata.getFlags().setFlag(EntityFlag.EATING, (xd & 0x04) == 0x04); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java new file mode 100644 index 000000000..b28ad99f5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java @@ -0,0 +1,47 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class PigEntity extends AnimalEntity { + + public PigEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java new file mode 100644 index 000000000..6011d5130 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java @@ -0,0 +1,47 @@ +/* + * 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.entity.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class PolarBearEntity extends AnimalEntity { + + public PolarBearEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + metadata.getFlags().setFlag(EntityFlag.STANDING, (boolean) entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java index 4598d1851..396ad6849 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java @@ -27,6 +27,7 @@ package org.geysermc.connector.entity.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -39,6 +40,12 @@ public class AbstractHorseEntity extends AnimalEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x02) == 0x02); + metadata.getFlags().setFlag(EntityFlag.SADDLED, (xd & 0x04) == 0x04); + metadata.getFlags().setFlag(EntityFlag.EATING, (xd & 0x10) == 0x10); + } super.updateBedrockMetadata(entityMetadata, session); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/ChestedHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/ChestedHorseEntity.java index 3023aa21a..df3543575 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/ChestedHorseEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/ChestedHorseEntity.java @@ -39,9 +39,9 @@ public class ChestedHorseEntity extends AbstractHorseEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { - // https://wiki.vg/Entity_metadata#Horse - metadata.getFlags().setFlag(EntityFlag.CHESTED, chestplate != null && chestplate.getId() != 0); - + if (entityMetadata.getId() == 18) { + metadata.getFlags().setFlag(EntityFlag.CHESTED, (boolean) entityMetadata.getValue()); + } super.updateBedrockMetadata(entityMetadata, session); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java new file mode 100644 index 000000000..5a8a1dcf2 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -0,0 +1,51 @@ +/* + * 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.entity.living.animal.tameable; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class CatEntity extends TameableEntity { + + public CatEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 18) { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + if (entityMetadata.getId() == 21) { + // FIXME: Colors the whole animal instead of just collar + metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java similarity index 67% rename from connector/src/main/java/org/geysermc/connector/entity/living/animal/TameableEntity.java rename to connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index 1fc6ea7e6..2f212595b 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -23,15 +23,29 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.entity.living.animal; +package org.geysermc.connector.entity.living.animal.tameable; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; public class TameableEntity extends AnimalEntity { public TameableEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); + metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); + metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); + } + super.updateBedrockMetadata(entityMetadata, session); + } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java new file mode 100644 index 000000000..6f6ab15f8 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -0,0 +1,48 @@ +/* + * 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.entity.living.animal.tameable; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class WolfEntity extends TameableEntity { + + public WolfEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 19) { + // FIXME: Colors the whole animal instead of just collar + // metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java new file mode 100644 index 000000000..168369767 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/BlazeEntity.java @@ -0,0 +1,49 @@ +/* + * 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.entity.living.monster; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class BlazeEntity extends MonsterEntity { + + public BlazeEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 15) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.ON_FIRE, (xd & 0x01) == 0x01); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java new file mode 100644 index 000000000..49a81d8e1 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java @@ -0,0 +1,51 @@ +/* + * 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.entity.living.monster; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class CreeperEntity extends MonsterEntity { + + public CreeperEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 16) { + metadata.getFlags().setFlag(EntityFlag.POWERED, (boolean) entityMetadata.getValue()); + } + if (entityMetadata.getId() == 17) { + metadata.getFlags().setFlag(EntityFlag.IGNITED, (boolean) entityMetadata.getValue()); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java new file mode 100644 index 000000000..301145e65 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/SpiderEntity.java @@ -0,0 +1,49 @@ +/* + * 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.entity.living.monster; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class SpiderEntity extends MonsterEntity { + + public SpiderEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 15) { + byte xd = (byte) entityMetadata.getValue(); + metadata.getFlags().setFlag(EntityFlag.WALL_CLIMBING, (xd & 0x01) == 0x01); + } + + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 1ad131e60..873c85345 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -28,14 +28,14 @@ package org.geysermc.connector.entity.type; import lombok.Getter; import org.geysermc.connector.entity.*; import org.geysermc.connector.entity.living.*; -import org.geysermc.connector.entity.living.animal.AnimalEntity; -import org.geysermc.connector.entity.living.animal.TameableEntity; +import org.geysermc.connector.entity.living.animal.*; +import org.geysermc.connector.entity.living.animal.tameable.CatEntity; +import org.geysermc.connector.entity.living.animal.tameable.TameableEntity; import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity; -import org.geysermc.connector.entity.living.animal.RabbitEntity; -import org.geysermc.connector.entity.living.animal.SheepEntity; import org.geysermc.connector.entity.living.animal.horse.ChestedHorseEntity; import org.geysermc.connector.entity.living.animal.horse.HorseEntity; import org.geysermc.connector.entity.living.animal.horse.LlamaEntity; +import org.geysermc.connector.entity.living.animal.tameable.WolfEntity; import org.geysermc.connector.entity.living.monster.*; import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity; import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity; @@ -46,9 +46,9 @@ public enum EntityType { CHICKEN(AnimalEntity.class, 10, 0.7f, 0.4f), COW(AnimalEntity.class, 11, 1.4f, 0.9f), - PIG(AnimalEntity.class, 12, 0.9f), + PIG(PigEntity.class, 12, 0.9f), SHEEP(SheepEntity.class, 13, 1.3f, 0.9f), - WOLF(AnimalEntity.class, 14, 0.85f, 0.6f), + WOLF(WolfEntity.class, 14, 0.85f, 0.6f), VILLAGER(AbstractMerchantEntity.class, 15, 1.8f, 0.6f, 0.6f, 1.62f), MOOSHROOM(AnimalEntity.class, 16, 1.4f, 0.9f), SQUID(WaterEntity.class, 17, 0.8f), @@ -56,21 +56,21 @@ public enum EntityType { BAT(AmbientEntity.class, 19, 0.9f, 0.5f), IRON_GOLEM(GolemEntity.class, 20, 2.7f, 1.4f), SNOW_GOLEM(GolemEntity.class, 21, 1.9f, 0.7f), - OCELOT(AgeableEntity.class, 22, 0.35f, 0.3f), + OCELOT(OcelotEntity.class, 22, 0.35f, 0.3f), HORSE(HorseEntity.class, 23, 1.6f, 1.3965f), DONKEY(ChestedHorseEntity.class, 24, 1.6f, 1.3965f), MULE(ChestedHorseEntity.class, 25, 1.6f, 1.3965f), SKELETON_HORSE(AbstractHorseEntity.class, 26, 1.6f, 1.3965f), ZOMBIE_HORSE(AbstractHorseEntity.class, 27, 1.6f, 1.3965f), - POLAR_BEAR(AnimalEntity.class, 28, 1.4f, 1.3f), + POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f), LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f), TRADER_LLAMA(LlamaEntity.class, 29, 1.187f, 0.9f), PARROT(TameableEntity.class, 30, 0.9f, 0.5f), DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f), ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f), - CREEPER(MonsterEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), + CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), SKELETON(AbstractSkeletonEntity.class, 34, 1.8f, 0.6f, 0.6f, 1.62f), - SPIDER(MonsterEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f), + SPIDER(SpiderEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f), ZOMBIE_PIGMAN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f), SLIME(InsentientEntity.class, 37, 0.51f), ENDERMAN(MonsterEntity.class, 38, 2.9f, 0.6f), @@ -78,13 +78,13 @@ public enum EntityType { CAVE_SPIDER(MonsterEntity.class, 40, 0.5f, 0.7f), GHAST(FlyingEntity.class, 41, 4.0f), MAGMA_CUBE(InsentientEntity.class, 42, 0.51f), - BLAZE(MonsterEntity.class, 43, 1.8f, 0.6f), + BLAZE(BlazeEntity.class, 43, 1.8f, 0.6f), ZOMBIE_VILLAGER(ZombieEntity.class, 44, 1.8f, 0.6f, 0.6f, 1.62f), WITCH(RaidParticipantEntity.class, 45, 1.8f, 0.6f, 0.6f, 1.62f), STRAY(AbstractSkeletonEntity.class, 46, 1.8f, 0.6f, 0.6f, 1.62f), HUSK(ZombieEntity.class, 47, 1.8f, 0.6f, 0.6f, 1.62f), WITHER_SKELETON(AbstractSkeletonEntity.class, 48, 2.4f, 0.7f), - GUARDIAN(MonsterEntity.class, 49, 0.85f), + GUARDIAN(GuardianEntity.class, 49, 0.85f), ELDER_GUARDIAN(GuardianEntity.class, 50, 1.9975f), NPC(PlayerEntity.class, 51, 1.8f, 0.6f, 0.6f, 1.62f), WITHER(MonsterEntity.class, 52, 3.5f, 0.9f), @@ -112,7 +112,7 @@ public enum EntityType { FIREWORK_ROCKET(Entity.class, 72, 0f), TRIDENT(ArrowEntity.class, 73, 0f), TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f), - CAT(TameableEntity.class, 75, 0.35f, 0.3f), + CAT(CatEntity.class, 75, 0.35f, 0.3f), SHULKER_BULLET(Entity.class, 76, 0f), FISHING_BOBBER(Entity.class, 77, 0f), CHALKBOARD(Entity.class, 78, 0f), @@ -149,9 +149,9 @@ public enum EntityType { DROWNED(ZombieEntity.class, 110, 1.95f, 0.6f), TROPICAL_FISH(AbstractFishEntity.class, 111, 0.6f, 0.6f), COD(AbstractFishEntity.class, 112, 0.25f, 0.5f), - PANDA(AnimalEntity.class, 113, 1.25f, 1.125f, 1.825f), - FOX(AnimalEntity.class, 121, 0.5f, 1.25f), - BEE(InsentientEntity.class, 122, 0.6f, 0.6f); + PANDA(PandaEntity.class, 113, 1.25f, 1.125f, 1.825f), + FOX(FoxEntity.class, 121, 0.5f, 1.25f), + BEE(BeeEntity.class, 122, 0.6f, 0.6f); private Class entityClass; private final int type; diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index a47d013d4..db172a045 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -157,7 +157,7 @@ public class MessageUtils { base += "r"; break; default: - break; + return ""; } return base; From 0e355c1a956307195b2a8e46579156ea1040ec16 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 6 Mar 2020 19:27:12 -0600 Subject: [PATCH 04/26] Fix natural creeper explosion animation not showing up --- .../connector/entity/living/monster/CreeperEntity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java index 49a81d8e1..e99e1a63f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/CreeperEntity.java @@ -39,6 +39,9 @@ public class CreeperEntity extends MonsterEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 15 && (int) entityMetadata.getValue() > 0) { + metadata.getFlags().setFlag(EntityFlag.IGNITED, true); + } if (entityMetadata.getId() == 16) { metadata.getFlags().setFlag(EntityFlag.POWERED, (boolean) entityMetadata.getValue()); } From 9e203d48aa7c0848a50a8041282a19b48a4fe793 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 6 Mar 2020 19:37:35 -0600 Subject: [PATCH 05/26] Fix running Geyser commands ingame --- .../bedrock/BedrockCommandRequestTranslator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index 19d1a55f6..8091781aa 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -37,8 +38,9 @@ public class BedrockCommandRequestTranslator extends PacketTranslator Date: Sun, 8 Mar 2020 11:45:00 -0500 Subject: [PATCH 06/26] Move DeviceOS to common module --- common/pom.xml | 6 +++ .../org/geysermc/floodgate/util/DeviceOS.java | 52 +++++++++++++++++++ .../session/auth/BedrockClientData.java | 18 +------ 3 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java diff --git a/common/pom.xml b/common/pom.xml index 1f6c20b7e..0a47fbcaa 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -18,5 +18,11 @@ 2.8.2 compile + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.9.8 + compile + \ No newline at end of file diff --git a/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java b/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java new file mode 100644 index 000000000..ee14fc90b --- /dev/null +++ b/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java @@ -0,0 +1,52 @@ +/* + * 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.floodgate.util; + +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + +public enum DeviceOS { + + @JsonEnumDefaultValue + UNKNOWN, + ANDROID, + IOS, + OSX, + FIREOS, + GEARVR, + HOLOLENS, + WIN10, + WIN32, + DEDICATED, + ORBIS, + NX, + SWITCH; + + private static final DeviceOS[] VALUES = values(); + + public static DeviceOS getById(int id) { + return id < VALUES.length ? VALUES[id] : VALUES[0]; + } +} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java index 3793e5227..66536e069 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; +import org.geysermc.floodgate.util.DeviceOS; import java.util.UUID; @@ -65,23 +66,6 @@ public class BedrockClientData { POCKET } - public enum DeviceOS { - @JsonEnumDefaultValue - UNKOWN, - ANDROID, - IOS, - OSX, - FIREOS, - GEARVR, - HOLOLENS, - WIN10, - WIN32, - DEDICATED, - ORBIS, - NX, - SWITCH - } - public enum InputMode { @JsonEnumDefaultValue UNKNOWN, From 37d377b483aa63fc9c73b4259f7837c4de1896d0 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Mon, 9 Mar 2020 21:32:19 +0100 Subject: [PATCH 07/26] Floodgate now uses identity instead of xuid --- .../org/geysermc/floodgate/util/BedrockData.java | 12 +++++++----- .../connector/network/session/GeyserSession.java | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index 8beeb9987..a94a20727 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -3,6 +3,8 @@ package org.geysermc.floodgate.util; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.UUID; + @AllArgsConstructor @Getter public class BedrockData { @@ -11,15 +13,15 @@ public class BedrockData { private String version; private String username; - private String xuid; + private UUID bedrockId; private int deviceId; private String languageCode; private int inputMode; private String ip; private int dataLength; - public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) { - this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH); + public BedrockData(String version, String username, UUID bedrockId, int deviceId, String languageCode, int inputMode, String ip) { + this(version, username, bedrockId, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH); } public static BedrockData fromString(String data) { @@ -27,7 +29,7 @@ public class BedrockData { if (split.length != EXPECTED_LENGTH) return null; return new BedrockData( - split[0], split[1], split[2], Integer.parseInt(split[3]), + split[0], split[1], UUID.fromString(split[2]), Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), split[6], split.length ); } @@ -38,7 +40,7 @@ public class BedrockData { @Override public String toString() { - return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ + return version +'\0'+ username +'\0'+ bedrockId +'\0'+ deviceId +'\0'+ languageCode +'\0'+ inputMode +'\0'+ ip; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index a2d8a7263..b443f9638 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -221,7 +221,7 @@ public class GeyserSession implements CommandSender { encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData( clientData.getGameVersion(), authData.getName(), - authData.getXboxUUID(), + authData.getUUID(), clientData.getDeviceOS().ordinal(), clientData.getLanguageCode(), clientData.getCurrentInputMode().ordinal(), From c7f1f0b71f968335a6d40a9ff3f980152f7588d6 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 10 Mar 2020 18:40:22 -0500 Subject: [PATCH 08/26] Shade in fastutil for Sponge and relocate to shaded package (Fixes #198) --- bootstrap/bukkit/pom.xml | 4 ++++ bootstrap/sponge/pom.xml | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 0f4d32885..0e5dd3df7 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -49,6 +49,10 @@ io.netty org.geysermc.platform.bukkit.shaded.netty + + it.unimi.dsi.fastutil + org.geysermc.platform.bukkit.shaded.fastutil + true diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml index 1b1dd8e94..83c070aed 100644 --- a/bootstrap/sponge/pom.xml +++ b/bootstrap/sponge/pom.xml @@ -53,6 +53,10 @@ io.netty org.geysermc.platform.sponge.shaded.netty + + it.unimi.dsi.fastutil + org.geysermc.platform.sponge.shaded.fastutil + true @@ -71,7 +75,6 @@ com.google.code.gson:* org.yaml:* - com.nukkitx:fastutil-lite:* org.slf4j:* org.ow2.asm:* From 105ce2b3b59a40c8438a88207c33d00dccd393a6 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 10 Mar 2020 19:40:51 -0500 Subject: [PATCH 09/26] Add effect translations --- .../network/translators/TranslatorsInit.java | 2 + .../entity/JavaEntityEffectTranslator.java | 55 +++++++++++++++++++ .../JavaEntityRemoveEffectTranslator.java | 52 ++++++++++++++++++ .../geysermc/connector/utils/EntityUtils.java | 24 ++++++-- 4 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 3cba0151f..a1ca1faf0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -114,6 +114,8 @@ public class TranslatorsInit { Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator()); Registry.registerJava(ServerEntityStatusPacket.class, new JavaEntityStatusTranslator()); Registry.registerJava(ServerEntityEquipmentPacket.class, new JavaEntityEquipmentTranslator()); + Registry.registerJava(ServerEntityEffectPacket.class, new JavaEntityEffectTranslator()); + Registry.registerJava(ServerEntityRemoveEffectPacket.class, new JavaEntityRemoveEffectTranslator()); Registry.registerJava(ServerBossBarPacket.class, new JavaBossBarTranslator()); Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java new file mode 100644 index 000000000..9716d9597 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java @@ -0,0 +1,55 @@ +/* + * 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.translators.java.entity; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; +import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.EntityUtils; + +public class JavaEntityEffectTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityEffectPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + MobEffectPacket mobEffectPacket = new MobEffectPacket(); + mobEffectPacket.setAmplifier(packet.getAmplifier()); + mobEffectPacket.setDuration(packet.getDuration()); + mobEffectPacket.setEvent(MobEffectPacket.Event.ADD); + mobEffectPacket.setRuntimeEntityId(entity.getGeyserId()); + mobEffectPacket.setParticles(packet.isShowParticles()); + mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect())); + session.getUpstream().sendPacket(mobEffectPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java new file mode 100644 index 000000000..97837bb81 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java @@ -0,0 +1,52 @@ +/* + * 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.translators.java.entity; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket; +import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.EntityUtils; + +public class JavaEntityRemoveEffectTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityRemoveEffectPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + MobEffectPacket mobEffectPacket = new MobEffectPacket(); + mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE); + mobEffectPacket.setRuntimeEntityId(entity.getGeyserId()); + mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect())); + session.getUpstream().sendPacket(mobEffectPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java index 79f85ac67..ec1ff4512 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java @@ -25,20 +25,32 @@ package org.geysermc.connector.utils; +import com.github.steveice10.mc.protocol.data.game.entity.Effect; import com.github.steveice10.mc.protocol.data.game.entity.type.MobType; import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; import org.geysermc.connector.entity.type.EntityType; public class EntityUtils { - public static MobType toJavaEntity(EntityType type) { - try { - return MobType.valueOf(type.name()); - } catch (IllegalArgumentException ex) { - return null; + public static int toBedrockEffectId(Effect effect) { + switch (effect) { + case GLOWING: + case LUCK: + case UNLUCK: + case DOLPHINS_GRACE: + case BAD_OMEN: + case HERO_OF_THE_VILLAGE: + return 0; + case LEVITATION: + return 24; + case CONDUIT_POWER: + return 26; + case SLOW_FALLING: + return 27; + default: + return effect.ordinal() + 1; } } - public static EntityType toBedrockEntity(MobType type) { try { return EntityType.valueOf(type.name()); From 9f36ba14cd32c7e1f9f0dac21602dfb2f711a658 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Wed, 11 Mar 2020 23:03:12 +0100 Subject: [PATCH 10/26] Added the Xbox One as DeviceOS --- common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java b/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java index ee14fc90b..0705d1694 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java +++ b/common/src/main/java/org/geysermc/floodgate/util/DeviceOS.java @@ -42,7 +42,8 @@ public enum DeviceOS { DEDICATED, ORBIS, NX, - SWITCH; + SWITCH, + XBOX_ONE; private static final DeviceOS[] VALUES = values(); From 79164927803748bb6f30e1fc74afcbd160b1f80f Mon Sep 17 00:00:00 2001 From: Redned Date: Sat, 14 Mar 2020 13:41:54 -0500 Subject: [PATCH 11/26] Update links to a few of what's left/needs adding to it's new location --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1cd56040d..8a0197972 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,12 @@ Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set - Donate: https://patreon.com/GeyserMC ## What's Left to be Added/Fixed -- Inventories ([#67](https://github.com/GeyserMC/Geyser/pull/67)) -- Crafting ([#67](https://github.com/GeyserMC/Geyser/pull/67)) -- Creative Mode ([#67](https://github.com/GeyserMC/Geyser/pull/67)) +- Inventories ([`inventory`](https://github.com/GeyserMC/Geyser/tree/inventory)) +- Crafting ([`inventory`](https://github.com/GeyserMC/Geyser/tree/inventory)) +- Creative Mode ([`inventory`](https://github.com/GeyserMC/Geyser/tree/inventory)) - Sounds - Block Particles -- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities)) +- Block Entities ([`inventory`](https://github.com/GeyserMC/Geyser/tree/inventory)) - Some Entity Flags ## Compiling From e203cfd4a7509f459e8910120d8b039ed425125e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 14 Mar 2020 14:02:58 -0500 Subject: [PATCH 12/26] Move back to XUID for Floodgate The normal identity UUID caused problems and caused the bedrock client to crash when using Floodgate. This was likely because on bedrock edition, it's a version 3 UUID opposed to java edition which uses version 4. --- .../java/org/geysermc/floodgate/util/BedrockData.java | 10 +++++----- .../connector/network/session/GeyserSession.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index a94a20727..dc895a79d 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -13,15 +13,15 @@ public class BedrockData { private String version; private String username; - private UUID bedrockId; + private String xuid; private int deviceId; private String languageCode; private int inputMode; private String ip; private int dataLength; - public BedrockData(String version, String username, UUID bedrockId, int deviceId, String languageCode, int inputMode, String ip) { - this(version, username, bedrockId, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH); + public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) { + this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH); } public static BedrockData fromString(String data) { @@ -29,7 +29,7 @@ public class BedrockData { if (split.length != EXPECTED_LENGTH) return null; return new BedrockData( - split[0], split[1], UUID.fromString(split[2]), Integer.parseInt(split[3]), + split[0], split[1], split[2], Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), split[6], split.length ); } @@ -40,7 +40,7 @@ public class BedrockData { @Override public String toString() { - return version +'\0'+ username +'\0'+ bedrockId +'\0'+ deviceId +'\0'+ languageCode +'\0'+ + return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ inputMode +'\0'+ ip; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index b443f9638..a2d8a7263 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -221,7 +221,7 @@ public class GeyserSession implements CommandSender { encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData( clientData.getGameVersion(), authData.getName(), - authData.getUUID(), + authData.getXboxUUID(), clientData.getDeviceOS().ordinal(), clientData.getLanguageCode(), clientData.getCurrentInputMode().ordinal(), From 16c9317a36592de148b5aadd6b62a4804e480d57 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 15 Mar 2020 13:20:55 -0500 Subject: [PATCH 13/26] Fix flickering sky if time is too high (Closes #200) This was caused because the max int size is 2,147,483,647, which is what Minecraft: Bedrock Edition uses in the time packet. In Minecraft: Java Edition, a long is used which has a max length of 9,223,372,036,854,775,807, thus causing the sky to bug out. This commit uses the modulus operator with the max time value per-day of 24,000 to retrieve the remainder. --- .../translators/java/world/JavaUpdateTimeTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java index e2173e2ca..e820e278e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java @@ -34,9 +34,9 @@ public class JavaUpdateTimeTranslator extends PacketTranslator Date: Tue, 17 Mar 2020 11:43:09 -0500 Subject: [PATCH 14/26] Add Geyser reload command and commands for platforms (Closes #141) --- .../platform/bukkit/GeyserBukkitPlugin.java | 13 ++- .../bukkit/command/BukkitCommandSender.java | 52 +++++++++ .../command/GeyserBukkitCommandExecutor.java | 75 +++++++++++++ .../bukkit/src/main/resources/plugin.yml | 6 +- .../bungeecord/GeyserBungeePlugin.java | 12 ++- .../command/BungeeCommandSender.java | 54 ++++++++++ .../command/GeyserBungeeCommandExecutor.java | 76 +++++++++++++ .../platform/sponge/GeyserSpongePlugin.java | 9 +- .../command/GeyserSpongeCommandExecutor.java | 100 ++++++++++++++++++ .../sponge/command/SpongeCommandSender.java | 54 ++++++++++ .../platform/standalone/GeyserBootstrap.java | 6 +- .../velocity/GeyserVelocityPlugin.java | 14 ++- .../GeyserVelocityCommandExecutor.java | 62 +++++++++++ .../command/VelocityCommandSender.java | 62 +++++++++++ .../geysermc/connector/GeyserConnector.java | 35 ++++-- .../connector/command/GeyserCommand.java | 24 ++--- .../connector/command/GeyserCommandMap.java | 28 +++-- .../command/defaults/HelpCommand.java | 18 ++-- .../command/defaults/ReloadCommand.java | 55 ++++++++++ .../command/defaults/StopCommand.java | 11 +- .../BedrockCommandRequestTranslator.java | 3 +- 21 files changed, 693 insertions(+), 76 deletions(-) create mode 100644 bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/BukkitCommandSender.java create mode 100644 bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/GeyserBukkitCommandExecutor.java create mode 100644 bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java create mode 100644 bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/GeyserBungeeCommandExecutor.java create mode 100644 bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java create mode 100644 bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/SpongeCommandSender.java create mode 100644 bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/GeyserVelocityCommandExecutor.java create mode 100644 bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/VelocityCommandSender.java create mode 100644 connector/src/main/java/org/geysermc/connector/command/defaults/ReloadCommand.java diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index 21f130da3..3c7ae8391 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -29,6 +29,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.common.bootstrap.IGeyserBootstrap; +import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor; import java.util.UUID; @@ -37,25 +38,27 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { private GeyserBukkitConfiguration geyserConfig; private GeyserBukkitLogger geyserLogger; + private GeyserConnector connector; + @Override public void onEnable() { saveDefaultConfig(); - geyserConfig = new GeyserBukkitConfiguration(getDataFolder(), getConfig()); - + this.geyserConfig = new GeyserBukkitConfiguration(getDataFolder(), getConfig()); if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { getConfig().set("metrics.uuid", UUID.randomUUID().toString()); saveConfig(); } - geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); + this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); + this.connector = GeyserConnector.start(PlatformType.BUKKIT, this); - GeyserConnector.start(PlatformType.BUKKIT, this); + this.getCommand("geyser").setExecutor(new GeyserBukkitCommandExecutor(connector)); } @Override public void onDisable() { - GeyserConnector.stop(); + connector.shutdown(); } @Override diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/BukkitCommandSender.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/BukkitCommandSender.java new file mode 100644 index 000000000..05e371e5a --- /dev/null +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/BukkitCommandSender.java @@ -0,0 +1,52 @@ +/* + * 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.platform.bukkit.command; + +import lombok.AllArgsConstructor; + +import org.bukkit.command.ConsoleCommandSender; +import org.geysermc.connector.command.CommandSender; + +@AllArgsConstructor +public class BukkitCommandSender implements CommandSender { + + private org.bukkit.command.CommandSender handle; + + @Override + public String getName() { + return handle.getName(); + } + + @Override + public void sendMessage(String message) { + handle.sendMessage(message); + } + + @Override + public boolean isConsole() { + return handle instanceof ConsoleCommandSender; + } +} diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/GeyserBukkitCommandExecutor.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/GeyserBukkitCommandExecutor.java new file mode 100644 index 000000000..84920db72 --- /dev/null +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/command/GeyserBukkitCommandExecutor.java @@ -0,0 +1,75 @@ +/* + * 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.platform.bukkit.command; + +import lombok.AllArgsConstructor; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserCommand; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@AllArgsConstructor +public class GeyserBukkitCommandExecutor implements TabExecutor { + + private GeyserConnector connector; + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length > 0) { + if (getCommand(args[0]) != null) { + if (!sender.hasPermission(getCommand(args[0]).getPermission())) { + sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command!"); + return true; + } + getCommand(args[0]).execute(new BukkitCommandSender(sender), args); + return true; + } + } else { + getCommand("help").execute(new BukkitCommandSender(sender), args); + return true; + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 1) { + return Arrays.asList("?", "help", "reload", "shutdown", "stop"); + } + return new ArrayList<>(); + } + + private GeyserCommand getCommand(String label) { + return connector.getCommandMap().getCommands().get(label); + } +} diff --git a/bootstrap/bukkit/src/main/resources/plugin.yml b/bootstrap/bukkit/src/main/resources/plugin.yml index b67547f25..8e002eb22 100644 --- a/bootstrap/bukkit/src/main/resources/plugin.yml +++ b/bootstrap/bukkit/src/main/resources/plugin.yml @@ -2,4 +2,8 @@ main: org.geysermc.platform.bukkit.GeyserBukkitPlugin name: ${outputName}-Bukkit author: ${project.organization.name} website: ${project.organization.url} -version: ${project.version} \ No newline at end of file +version: ${project.version} +commands: + geyser: + description: The main command for Geyser. + usage: /geyser help \ No newline at end of file diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index b396ede5d..d6974dafa 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -33,6 +33,7 @@ import net.md_5.bungee.config.YamlConfiguration; import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.common.bootstrap.IGeyserBootstrap; +import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor; import java.io.File; import java.io.IOException; @@ -46,6 +47,8 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { private GeyserBungeeConfiguration geyserConfig; private GeyserBungeeLogger geyserLogger; + private GeyserConnector connector; + @Override public void onEnable() { if (!getDataFolder().exists()) @@ -73,7 +76,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { return; } - geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration); + this.geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration); if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { configuration.set("metrics.uuid", UUID.randomUUID().toString()); @@ -85,14 +88,15 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { } } - geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); + this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); + this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this); - GeyserConnector.start(PlatformType.BUNGEECORD, this); + this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(connector)); } @Override public void onDisable() { - GeyserConnector.stop(); + connector.shutdown(); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java new file mode 100644 index 000000000..d40dc902b --- /dev/null +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java @@ -0,0 +1,54 @@ +/* + * 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.platform.bungeecord.command; + +import lombok.AllArgsConstructor; + +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import org.geysermc.connector.command.CommandSender; + +@AllArgsConstructor +public class BungeeCommandSender implements CommandSender { + + private net.md_5.bungee.api.CommandSender handle; + + @Override + public String getName() { + return handle.getName(); + } + + @Override + public void sendMessage(String message) { + handle.sendMessage(TextComponent.fromLegacyText(message)); + } + + @Override + public boolean isConsole() { + return !(handle instanceof ProxiedPlayer); + } +} diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/GeyserBungeeCommandExecutor.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/GeyserBungeeCommandExecutor.java new file mode 100644 index 000000000..8149d2917 --- /dev/null +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/GeyserBungeeCommandExecutor.java @@ -0,0 +1,76 @@ +/* + * 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.platform.bungeecord.command; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.api.plugin.TabExecutor; + +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserCommand; + +import java.util.ArrayList; +import java.util.Arrays; + +public class GeyserBungeeCommandExecutor extends Command implements TabExecutor { + + private GeyserConnector connector; + + public GeyserBungeeCommandExecutor(GeyserConnector connector) { + super("geyser"); + + this.connector = connector; + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (args.length > 0) { + if (getCommand(args[0]) != null) { + if (!sender.hasPermission(getCommand(args[0]).getPermission())) { + sender.sendMessage(TextComponent.fromLegacyText(ChatColor.RED + "You do not have permission to execute this command!")); + return; + } + getCommand(args[0]).execute(new BungeeCommandSender(sender), args); + } + } else { + getCommand("help").execute(new BungeeCommandSender(sender), args); + } + } + + @Override + public Iterable onTabComplete(CommandSender sender, String[] args) { + if (args.length == 1) { + return Arrays.asList("?", "help", "reload", "shutdown", "stop"); + } + return new ArrayList<>(); + } + + private GeyserCommand getCommand(String label) { + return connector.getCommandMap().getCommands().get(label); + } +} diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java index 15ab0d1fe..a2074b158 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java @@ -34,7 +34,9 @@ import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; +import org.geysermc.platform.sponge.command.GeyserSpongeCommandExecutor; import org.slf4j.Logger; +import org.spongepowered.api.Sponge; import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.game.state.GameStartedServerEvent; @@ -58,6 +60,8 @@ public class GeyserSpongePlugin implements IGeyserBootstrap { private GeyserSpongeConfiguration geyserConfig; private GeyserSpongeLogger geyserLogger; + private GeyserConnector connector; + @Override public void onEnable() { if (!configDir.exists()) @@ -81,13 +85,14 @@ public class GeyserSpongePlugin implements IGeyserBootstrap { } this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode()); + this.connector = GeyserConnector.start(PlatformType.SPONGE, this); - GeyserConnector.start(PlatformType.SPONGE, this); + Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(connector), "geyser"); } @Override public void onDisable() { - GeyserConnector.stop(); + connector.shutdown(); } @Override diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java new file mode 100644 index 000000000..c68ff4e47 --- /dev/null +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java @@ -0,0 +1,100 @@ +/* + * 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.platform.sponge.command; + +import lombok.AllArgsConstructor; + +import org.geysermc.common.ChatColor; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserCommand; +import org.spongepowered.api.command.CommandCallable; +import org.spongepowered.api.command.CommandException; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +@AllArgsConstructor +public class GeyserSpongeCommandExecutor implements CommandCallable { + + private GeyserConnector connector; + + @Override + public CommandResult process(CommandSource source, String arguments) throws CommandException { + String[] args = arguments.split(" "); + if (args.length > 0) { + if (getCommand(args[0]) != null) { + if (!source.hasPermission(getCommand(args[0]).getPermission())) { + source.sendMessage(Text.of(ChatColor.RED + "You do not have permission to execute this command!")); + return CommandResult.success(); + } + getCommand(args[0]).execute(new SpongeCommandSender(source), args); + } + } else { + getCommand("help").execute(new SpongeCommandSender(source), args); + } + return CommandResult.success(); + } + + @Override + public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) throws CommandException { + if (arguments.split(" ").length == 1) { + return Arrays.asList("?", "help", "reload", "shutdown", "stop"); + } + return new ArrayList<>(); + } + + @Override + public boolean testPermission(CommandSource source) { + return true; + } + + @Override + public Optional getShortDescription(CommandSource source) { + return Optional.of(Text.of("The main command for Geyser.")); + } + + @Override + public Optional getHelp(CommandSource source) { + return Optional.of(Text.of("/geyser help")); + } + + @Override + public Text getUsage(CommandSource source) { + return Text.of("/geyser help"); + } + + private GeyserCommand getCommand(String label) { + return connector.getCommandMap().getCommands().get(label); + } +} diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/SpongeCommandSender.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/SpongeCommandSender.java new file mode 100644 index 000000000..a309a26f3 --- /dev/null +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/SpongeCommandSender.java @@ -0,0 +1,54 @@ +/* + * 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.platform.sponge.command; + +import lombok.AllArgsConstructor; + +import org.geysermc.connector.command.CommandSender; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.command.source.ConsoleSource; +import org.spongepowered.api.text.Text; + +@AllArgsConstructor +public class SpongeCommandSender implements CommandSender { + + private CommandSource handle; + + @Override + public String getName() { + return handle.getName(); + } + + @Override + public void sendMessage(String message) { + handle.sendMessage(Text.of(message)); + } + + @Override + public boolean isConsole() { + return handle instanceof ConsoleSource; + } +} diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 199745388..1ba111e7d 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -40,6 +40,8 @@ public class GeyserBootstrap implements IGeyserBootstrap { private GeyserConfiguration geyserConfig; private GeyserLogger geyserLogger; + private GeyserConnector connector; + public static void main(String[] args) { new GeyserBootstrap().onEnable(); } @@ -56,13 +58,13 @@ public class GeyserBootstrap implements IGeyserBootstrap { System.exit(0); } - GeyserConnector.start(PlatformType.STANDALONE, this); + connector = GeyserConnector.start(PlatformType.STANDALONE, this); geyserLogger.start(); } @Override public void onDisable() { - GeyserConnector.stop(); + connector.shutdown(); System.exit(0); } diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java index 4020b81e4..5ab411f3e 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java @@ -27,6 +27,7 @@ package org.geysermc.platform.velocity; import com.google.inject.Inject; +import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; @@ -36,6 +37,7 @@ import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; +import org.geysermc.platform.velocity.command.GeyserVelocityCommandExecutor; import org.slf4j.Logger; import java.io.File; @@ -48,9 +50,13 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { @Inject private Logger logger; + @Inject + private CommandManager commandManager; + private GeyserVelocityConfiguration geyserConfig; private GeyserVelocityLogger geyserLogger; + private GeyserConnector connector; @Override public void onEnable() { @@ -59,19 +65,21 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { if (!configDir.exists()) configDir.mkdir(); File configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); - geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class); + this.geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class); } catch (IOException ex) { logger.warn("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); ex.printStackTrace(); } this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode()); - GeyserConnector.start(PlatformType.VELOCITY, this); + this.connector = GeyserConnector.start(PlatformType.VELOCITY, this); + + this.commandManager.register(new GeyserVelocityCommandExecutor(connector), "geyser"); } @Override public void onDisable() { - GeyserConnector.stop(); + connector.shutdown(); } @Override diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/GeyserVelocityCommandExecutor.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/GeyserVelocityCommandExecutor.java new file mode 100644 index 000000000..39a0af97c --- /dev/null +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/GeyserVelocityCommandExecutor.java @@ -0,0 +1,62 @@ +/* + * 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.platform.velocity.command; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; + +import lombok.AllArgsConstructor; + +import net.kyori.text.TextComponent; + +import org.geysermc.common.ChatColor; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserCommand; + +@AllArgsConstructor +public class GeyserVelocityCommandExecutor implements Command { + + private GeyserConnector connector; + + @Override + public void execute(CommandSource source, String[] args) { + if (args.length > 0) { + if (getCommand(args[0]) != null) { + if (!source.hasPermission(getCommand(args[0]).getPermission())) { + source.sendMessage(TextComponent.of(ChatColor.RED + "You do not have permission to execute this command!")); + return; + } + getCommand(args[0]).execute(new VelocityCommandSender(source), args); + } + } else { + getCommand("help").execute(new VelocityCommandSender(source), args); + } + } + + private GeyserCommand getCommand(String label) { + return connector.getCommandMap().getCommands().get(label); + } +} diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/VelocityCommandSender.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/VelocityCommandSender.java new file mode 100644 index 000000000..1b0d6f3e6 --- /dev/null +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/command/VelocityCommandSender.java @@ -0,0 +1,62 @@ +/* + * 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.platform.velocity.command; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; + +import lombok.AllArgsConstructor; + +import net.kyori.text.TextComponent; + +import org.geysermc.connector.command.CommandSender; + +@AllArgsConstructor +public class VelocityCommandSender implements CommandSender { + + private CommandSource handle; + + @Override + public String getName() { + if (handle instanceof Player) { + return ((Player) handle).getUsername(); + } else if (handle instanceof ConsoleCommandSource) { + return "CONSOLE"; + } + return ""; + } + + @Override + public void sendMessage(String message) { + handle.sendMessage(TextComponent.of(message)); + } + + @Override + public boolean isConsole() { + return handle instanceof ConsoleCommandSource; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 12c09e162..401e3eb93 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -68,9 +68,6 @@ public class GeyserConnector { private RemoteServer remoteServer; private AuthType authType; - private IGeyserLogger logger; - private IGeyserConfiguration config; - private GeyserCommandMap commandMap; private boolean shuttingDown = false; @@ -80,15 +77,20 @@ public class GeyserConnector { private BedrockServer bedrockServer; private PlatformType platformType; + private IGeyserBootstrap bootstrap; private Metrics metrics; - private GeyserConnector(PlatformType platformType, IGeyserConfiguration config, IGeyserLogger logger) { + private GeyserConnector(PlatformType platformType, IGeyserBootstrap bootstrap) { long startupTime = System.currentTimeMillis(); instance = this; - this.logger = logger; + this.bootstrap = bootstrap; + + IGeyserLogger logger = bootstrap.getGeyserLogger(); + IGeyserConfiguration config = bootstrap.getGeyserConfig(); + this.platformType = platformType; logger.info("******************************************"); @@ -97,7 +99,6 @@ public class GeyserConnector { logger.info(""); logger.info("******************************************"); - this.config = config; this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool()); logger.setDebug(config.isDebugMode()); @@ -137,11 +138,16 @@ public class GeyserConnector { } public void shutdown() { - logger.info("Shutting down Geyser."); + bootstrap.getGeyserLogger().info("Shutting down Geyser."); shuttingDown = true; generalThreadPool.shutdown(); bedrockServer.close(); + players.clear(); + remoteServer = null; + authType = null; + commandMap.getCommands().clear(); + commandMap = null; } public void addPlayer(GeyserSession player) { @@ -157,11 +163,20 @@ public class GeyserConnector { } public static GeyserConnector start(PlatformType platformType, IGeyserBootstrap bootstrap) { - return new GeyserConnector(platformType, bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger()); + return new GeyserConnector(platformType, bootstrap); } - public static void stop() { - instance.shutdown(); + public void reload() { + shutdown(); + bootstrap.onEnable(); + } + + public IGeyserLogger getLogger() { + return bootstrap.getGeyserLogger(); + } + + public IGeyserConfiguration getConfig() { + return bootstrap.getGeyserConfig(); } public static GeyserConnector getInstance() { diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java index ea8ed874a..62bc6c73f 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java @@ -25,33 +25,23 @@ package org.geysermc.connector.command; -import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import java.util.ArrayList; import java.util.List; @Getter -@Setter +@RequiredArgsConstructor public abstract class GeyserCommand { - private String name; - private String description; - - @Setter(AccessLevel.NONE) - private GeyserCommandMap commandMap; + protected final String name; + protected final String description; + protected final String permission; + @Setter private List aliases = new ArrayList<>(); - public GeyserCommand(String name) { - this(name, "A geyser command."); - } - - public GeyserCommand(String name, String description) { - this.name = name; - this.description = description; - } - public abstract void execute(CommandSender sender, String[] args); -} +} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java index 7172622c3..c4bf488ee 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java @@ -25,8 +25,10 @@ package org.geysermc.connector.command; +import lombok.Getter; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.defaults.HelpCommand; +import org.geysermc.connector.command.defaults.ReloadCommand; import org.geysermc.connector.command.defaults.StopCommand; import java.util.Collections; @@ -35,37 +37,35 @@ import java.util.Map; public class GeyserCommandMap { - private final Map commandMap = Collections.synchronizedMap(new HashMap<>()); + @Getter + private final Map commands = Collections.synchronizedMap(new HashMap<>()); + private GeyserConnector connector; public GeyserCommandMap(GeyserConnector connector) { this.connector = connector; - registerDefaults(); - } - - public void registerDefaults() { - registerCommand(new HelpCommand(connector, "help", "Shows help for all registered commands.")); - registerCommand(new StopCommand(connector, "stop", "Shut down Geyser.")); + registerCommand(new HelpCommand(connector, "help", "Shows help for all registered commands.", "geyser.command.help")); + registerCommand(new ReloadCommand(connector, "reload", "Reloads the Geyser configurations. Kicks all players when used!", "geyser.command.reload")); + registerCommand(new StopCommand(connector, "stop", "Shuts down Geyser.", "geyser.command.stop")); } public void registerCommand(GeyserCommand command) { - commandMap.put(command.getName(), command); + commands.put(command.getName(), command); connector.getLogger().debug("Registered command " + command.getName()); if (command.getAliases().isEmpty()) return; for (String alias : command.getAliases()) - commandMap.put(alias, command); + commands.put(alias, command); } public void runCommand(CommandSender sender, String command) { if (!command.startsWith("geyser ")) return; - command = command.trim(); - command = command.replace("geyser ", ""); + command = command.trim().replace("geyser ", ""); String label; String[] args; @@ -78,7 +78,7 @@ public class GeyserCommandMap { args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine }; } - GeyserCommand cmd = commandMap.get(label); + GeyserCommand cmd = commands.get(label); if (cmd == null) { connector.getLogger().error("Invalid Command! Try /geyser help for a list of commands."); return; @@ -86,8 +86,4 @@ public class GeyserCommandMap { cmd.execute(sender, args); } - - public Map getCommands() { - return commandMap; - } } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java index 4fa0068ae..cdfb612a6 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java @@ -30,14 +30,17 @@ import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class HelpCommand extends GeyserCommand { public GeyserConnector connector; - public HelpCommand(GeyserConnector connector, String name, String description) { - super(name, description); + public HelpCommand(GeyserConnector connector, String name, String description, String permission) { + super(name, description, permission); this.connector = connector; this.setAliases(Collections.singletonList("?")); @@ -47,12 +50,7 @@ public class HelpCommand extends GeyserCommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----"); Map cmds = connector.getCommandMap().getCommands(); - - List commands = new ArrayList<>(cmds.keySet()); - Collections.sort(commands); - - for (String cmd : commands) { - sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()); - } + List commands = connector.getCommandMap().getCommands().keySet().stream().sorted().collect(Collectors.toList()); + commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription())); } } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/ReloadCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/ReloadCommand.java new file mode 100644 index 000000000..bd8444c79 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/ReloadCommand.java @@ -0,0 +1,55 @@ +/* + * 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.command.defaults; + +import org.geysermc.common.ChatColor; +import org.geysermc.common.PlatformType; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.CommandSender; +import org.geysermc.connector.command.GeyserCommand; +import org.geysermc.connector.network.session.GeyserSession; + +public class ReloadCommand extends GeyserCommand { + + private GeyserConnector connector; + + public ReloadCommand(GeyserConnector connector, String name, String description, String permission) { + super(name, description, permission); + this.connector = connector; + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) { + return; + } + sender.sendMessage(ChatColor.YELLOW + "Reloading Geyser configurations... all connected bedrock clients will be kicked."); + for (GeyserSession session : connector.getPlayers().values()) { + session.getUpstream().disconnect("Geyser has been reloaded... sorry for the inconvenience!"); + } + connector.reload(); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java index 25034f1ad..4694d0fd0 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java @@ -25,6 +25,7 @@ package org.geysermc.connector.command.defaults; +import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; @@ -33,10 +34,10 @@ import java.util.Collections; public class StopCommand extends GeyserCommand { - public GeyserConnector connector; + private GeyserConnector connector; - public StopCommand(GeyserConnector connector, String name, String description) { - super(name, description); + public StopCommand(GeyserConnector connector, String name, String description, String permission) { + super(name, description, permission); this.connector = connector; this.setAliases(Collections.singletonList("shutdown")); @@ -44,9 +45,9 @@ public class StopCommand extends GeyserCommand { @Override public void execute(CommandSender sender, String[] args) { - if (!sender.isConsole()) + if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) { return; - + } connector.shutdown(); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index 8091781aa..93b6b3ec4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.bedrock; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; +import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.network.session.GeyserSession; @@ -39,7 +40,7 @@ public class BedrockCommandRequestTranslator extends PacketTranslator Date: Tue, 17 Mar 2020 17:55:11 -0500 Subject: [PATCH 15/26] Make the passthrough motd display correctly on clients Before: https://i.e3ndr.xyz/?i=W63C After: https://i.e3ndr.xyz/?i=SGKS --- .../connector/network/ConnectorServerEventHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index a7b28a23d..f0ae14a5c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -66,8 +66,12 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { pong.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); pong.setIpv4Port(config.getBedrock().getPort()); if (connector.getConfig().isPingPassthrough() && serverInfo != null) { - pong.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription())); - pong.setSubMotd(config.getBedrock().getMotd2()); + String[] motd = MessageUtils.getBedrockMessage(serverInfo.getDescription()).split("\n"); + String mainMotd = motd[0]; // First line of the motd. + String subMotd = (motd.length != 1) ? motd[1] : ""; // Second line of the motd if present, otherwise blank. + + pong.setMotd(mainMotd.trim()); + pong.setSubMotd(subMotd.trim()); // Trimmed to shift it to the left, prevents the universe from collapsing on us just because we went 2 characters over the text box's limit. pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers()); pong.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers()); } else { From 62b183a387c329b504f588d24ae72d04bb405bfd Mon Sep 17 00:00:00 2001 From: Redned Date: Wed, 18 Mar 2020 16:10:28 -0500 Subject: [PATCH 16/26] Update bedrock protocol lib and remove trove --- connector/pom.xml | 32 ++++++++++++++++--- .../network/session/cache/EntityCache.java | 7 ++-- .../translators/block/BlockTranslator.java | 14 +++++--- .../player/JavaPlayerAbilitiesTranslator.java | 4 +-- .../java/scoreboard/JavaTeamTranslator.java | 3 +- .../world/JavaNotifyClientTranslator.java | 4 +-- .../connector/scoreboard/Scoreboard.java | 5 +-- .../geysermc/connector/scoreboard/Team.java | 4 +-- .../org/geysermc/connector/utils/Toolbox.java | 2 +- 9 files changed, 55 insertions(+), 20 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index e9de81e64..a523d2633 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -39,13 +39,37 @@ com.nukkitx.protocol bedrock-v389 - 2.5.1 + 2.5.4 + compile + + + net.sf.trove4j + trove + + + + + com.nukkitx.fastutil + fastutil-int-int-maps + 8.3.1 compile - com.nukkitx - fastutil-lite - 8.1.1 + com.nukkitx.fastutil + fastutil-int-float-maps + 8.3.1 + compile + + + com.nukkitx.fastutil + fastutil-long-long-maps + 8.3.1 + compile + + + com.nukkitx.fastutil + fastutil-object-long-maps + 8.3.1 compile diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java index bbd714e2f..f32ee2a5c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -26,6 +26,9 @@ package org.geysermc.connector.network.session.cache; import it.unimi.dsi.fastutil.longs.*; +import it.unimi.dsi.fastutil.objects.Object2LongMap; +import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.PlayerEntity; @@ -45,7 +48,7 @@ public class EntityCache { private Long2ObjectMap entities = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>()); private Long2LongMap entityIdTranslations = Long2LongMaps.synchronize(new Long2LongOpenHashMap()); private Map playerEntities = Collections.synchronizedMap(new HashMap<>()); - private Map bossbars = new HashMap<>(); + private Object2LongMap bossbars = new Object2LongOpenHashMap<>(); @Getter private AtomicLong nextEntityId = new AtomicLong(2L); @@ -92,7 +95,7 @@ public class EntityCache { } public Set getEntitiesByType(Class entityType) { - Set entitiesOfType = new HashSet<>(); + Set entitiesOfType = new ObjectOpenHashSet<>(); for (Entity entity : (entityType == PlayerEntity.class ? playerEntities : entities).values()) { if (entity.is(entityType)) { entitiesOfType.add(entity.as(entityType)); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 8308db2ed..c782e099a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -32,9 +32,14 @@ import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.stream.NBTInputStream; import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.ListTag; -import gnu.trove.map.TObjectIntMap; -import gnu.trove.map.hash.TObjectIntHashMap; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.Toolbox; @@ -78,7 +83,8 @@ public class BlockTranslator { } catch (Exception e) { throw new AssertionError("Unable to load Java block mappings", e); } - TObjectIntMap addedStatesMap = new TObjectIntHashMap<>(512, 0.5f, -1); + Object2IntMap addedStatesMap = new Object2IntOpenHashMap<>(); + addedStatesMap.defaultReturnValue(-1); List paletteList = new ArrayList<>(); int waterRuntimeId = -1; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java index f27be49bf..8e9224ed3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java @@ -31,11 +31,11 @@ import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; -import java.util.HashSet; import java.util.Set; public class JavaPlayerAbilitiesTranslator extends PacketTranslator { @@ -54,7 +54,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator playerFlags = new HashSet<>(); + Set playerFlags = new ObjectOpenHashSet<>(); playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP); if (packet.isCanFly()) playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java index 48a553048..9ef7c7056 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.java.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -73,6 +74,6 @@ public class JavaTeamTranslator extends PacketTranslator { } private Set toPlayerSet(String[] players) { - return new HashSet<>(Arrays.asList(players)); + return new ObjectOpenHashSet<>(Arrays.asList(players)); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index 490a66437..29ad5c3ed 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -36,11 +36,11 @@ import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.*; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; -import java.util.HashSet; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; @@ -68,7 +68,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator playerFlags = new HashSet<>(); + Set playerFlags = new ObjectOpenHashSet<>(); GameMode gameMode = (GameMode) packet.getValue(); if (gameMode == GameMode.ADVENTURE) playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD); diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java index 48fe492f4..03ccb2fd3 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java @@ -30,6 +30,7 @@ import com.nukkitx.protocol.bedrock.data.ScoreInfo; import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket; import com.nukkitx.protocol.bedrock.packet.SetScorePacket; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import org.geysermc.connector.network.session.GeyserSession; @@ -113,7 +114,7 @@ public class Scoreboard { } public void onUpdate() { - Set changedObjectives = new HashSet<>(); + Set changedObjectives = new ObjectOpenHashSet<>(); List addScores = new ArrayList<>(); List removeScores = new ArrayList<>(); @@ -133,7 +134,7 @@ public class Scoreboard { boolean hasUpdate = globalUpdate; List handledScores = new ArrayList<>(); - for (String identifier : new HashSet<>(objective.getScores().keySet())) { + for (String identifier : new ObjectOpenHashSet<>(objective.getScores().keySet())) { Score score = objective.getScores().get(identifier); Team team = score.getTeam(); diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java index d72fb60fd..bf4b78532 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java @@ -25,12 +25,12 @@ package org.geysermc.connector.scoreboard; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,7 +45,7 @@ public class Team { private String name; private String prefix; private String suffix; - private Set entities = new HashSet<>(); + private Set entities = new ObjectOpenHashSet<>(); public Team(Scoreboard scoreboard, String id) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 27c0fd617..45802196b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -48,7 +48,7 @@ public class Toolbox { public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); public static final CompoundTag BIOMES; - public static final Collection ITEMS = new ArrayList<>(); + public static final List ITEMS = new ArrayList<>(); public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); From 8b824cccf7135edfb6dfb40842cb30f6c8f98a41 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Thu, 19 Mar 2020 12:51:14 +0100 Subject: [PATCH 17/26] Added VR as InputMode (fixes #219) --- .../connector/network/session/auth/BedrockClientData.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java index 66536e069..8fc56acd3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java @@ -71,6 +71,7 @@ public class BedrockClientData { UNKNOWN, KEYBOARD_MOUSE, TOUCH, // I guess Touch? - CONTROLLER + CONTROLLER, + VR } } From a821312f7e1c1da31b8b947476e744af9d42c6bc Mon Sep 17 00:00:00 2001 From: DoctorMacc <20743703+DoctorMacc@users.noreply.github.com> Date: Mon, 23 Mar 2020 15:13:45 -0400 Subject: [PATCH 18/26] Add switch for dealing with ChatColor.NONE In-game chat uses ChatColor.NONE for handling reset of text. --- .../src/main/java/org/geysermc/connector/utils/MessageUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index db172a045..b5260ab75 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -154,6 +154,7 @@ public class MessageUtils { base += "f"; break; case RESET: + case NONE: base += "r"; break; default: From 13a58dc8252d2124c71be8eb87a3b0134b540705 Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Mon, 23 Mar 2020 23:03:33 -0500 Subject: [PATCH 19/26] Begin making translators annotation based Also, rename TranslatorsInit to Translators; makes alot more sense. --- connector/pom.xml | 5 ++ .../geysermc/connector/GeyserConnector.java | 4 +- .../geysermc/connector/entity/ItemEntity.java | 4 +- .../network/session/cache/ChunkCache.java | 4 +- .../network/translators/Registry.java | 9 +- .../network/translators/Translator.java | 34 ++++++++ ...{TranslatorsInit.java => Translators.java} | 85 ++++++++++--------- .../inventory/GenericInventoryTranslator.java | 6 +- .../entity/JavaEntityEquipmentTranslator.java | 4 +- .../inventory/OpenWindowPacketTranslator.java | 4 +- .../geysermc/connector/utils/ChunkUtils.java | 4 +- .../connector/utils/InventoryUtils.java | 14 +-- 12 files changed, 112 insertions(+), 65 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/Translator.java rename connector/src/main/java/org/geysermc/connector/network/translators/{TranslatorsInit.java => Translators.java} (79%) diff --git a/connector/pom.xml b/connector/pom.xml index a523d2633..25ef50730 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -116,5 +116,10 @@ + + org.reflections + reflections + 0.9.12 + diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 401e3eb93..fb93a27de 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -40,7 +40,7 @@ import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.network.ConnectorServerEventHandler; import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.thread.PingPassthroughThread; import org.geysermc.connector.utils.Toolbox; import org.geysermc.common.IGeyserConfiguration; @@ -104,7 +104,7 @@ public class GeyserConnector { logger.setDebug(config.isDebugMode()); Toolbox.init(); - TranslatorsInit.start(); + Translators.start(); commandMap = new GeyserCommandMap(this); remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort()); diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java index 4c227cadd..a80323076 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java @@ -31,7 +31,7 @@ import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.AddItemEntityPacket; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; public class ItemEntity extends Entity { @@ -49,7 +49,7 @@ public class ItemEntity extends Entity { itemPacket.setUniqueEntityId(geyserId); itemPacket.setFromFishing(false); itemPacket.getMetadata().putAll(metadata); - itemPacket.setItemInHand(TranslatorsInit.getItemTranslator().translateToBedrock((ItemStack) entityMetadata.getValue())); + itemPacket.setItemInHand(Translators.getItemTranslator().translateToBedrock((ItemStack) entityMetadata.getValue())); session.getUpstream().sendPacket(itemPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java index 5e94f3d9c..bc88694d8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java @@ -32,7 +32,7 @@ import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import lombok.Getter; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.world.chunk.ChunkPosition; @@ -102,7 +102,7 @@ public class ChunkCache { levelChunkPacket.setChunkZ(position.getZ()); levelChunkPacket.setCachingEnabled(false); levelChunkPacket.setSubChunksLength(0); - levelChunkPacket.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA); + levelChunkPacket.setData(Translators.EMPTY_LEVEL_CHUNK_DATA); session.getUpstream().sendPacket(levelChunkPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java index f32fe4b6d..ecdd35812 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java @@ -39,14 +39,15 @@ public class Registry { public static final Registry JAVA = new Registry<>(); public static final Registry BEDROCK = new Registry<>(); - public static void registerJava(Class clazz, PacketTranslator translator) { - JAVA.MAP.put(clazz, translator); + public static void registerJava(Class targetPacket, PacketTranslator translator) { + JAVA.MAP.put(targetPacket, translator); } - public static void registerBedrock(Class clazz, PacketTranslator translator) { - BEDROCK.MAP.put(clazz, translator); + public static void registerBedrock(Class targetPacket, PacketTranslator translator) { + BEDROCK.MAP.put(targetPacket, translator); } + @SuppressWarnings("unchecked") public

boolean translate(Class clazz, P packet, GeyserSession session) { if (!session.getUpstream().isClosed() && !session.isClosed()) { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java b/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java new file mode 100644 index 000000000..8e097ba4d --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Translator.java @@ -0,0 +1,34 @@ +/* + * 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.translators; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(value = RetentionPolicy.RUNTIME) +public @interface Translator { + Class packet(); + +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java similarity index 79% rename from connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java rename to connector/src/main/java/org/geysermc/connector/network/translators/Translators.java index a1ca1faf0..c87cab3ce 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java @@ -25,48 +25,26 @@ package org.geysermc.connector.network.translators; -import com.github.steveice10.mc.protocol.packet.ingame.server.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.*; -import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket; -import com.nukkitx.nbt.CompoundTagBuilder; -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.protocol.bedrock.packet.*; -import lombok.Getter; -import org.geysermc.connector.network.translators.bedrock.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator; -import org.geysermc.connector.network.translators.java.*; -import org.geysermc.connector.network.translators.java.entity.*; -import org.geysermc.connector.network.translators.java.entity.player.*; -import org.geysermc.connector.network.translators.java.entity.spawn.*; -import org.geysermc.connector.network.translators.java.inventory.OpenWindowPacketTranslator; -import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator; -import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator; -import org.geysermc.connector.network.translators.java.scoreboard.JavaTeamTranslator; -import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator; -import org.geysermc.connector.network.translators.java.window.JavaOpenWindowTranslator; -import org.geysermc.connector.network.translators.java.window.JavaSetSlotTranslator; -import org.geysermc.connector.network.translators.java.window.JavaWindowItemsTranslator; -import org.geysermc.connector.network.translators.java.world.*; +import org.reflections.Reflections; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import com.github.steveice10.packetlib.packet.Packet; +import com.nukkitx.nbt.CompoundTagBuilder; +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.protocol.bedrock.BedrockPacket; -public class TranslatorsInit { +import lombok.Getter; + +public class Translators { @Getter private static ItemTranslator itemTranslator; @@ -91,8 +69,9 @@ public class TranslatorsInit { } } + @SuppressWarnings("unchecked") public static void start() { - Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator()); + /*Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator()); Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator()); Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator()); @@ -162,8 +141,36 @@ public class TranslatorsInit { Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator()); Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator()); Registry.registerBedrock(RespawnPacket.class, new BedrockRespawnTranslator()); - Registry.registerBedrock(ShowCreditsPacket.class, new BedrockShowCreditsTranslator()); - + Registry.registerBedrock(ShowCreditsPacket.class, new BedrockShowCreditsTranslator());*/ + + Reflections ref = new Reflections("org.geysermc.connector.network.translators"); + + for (Class clazz : ref.getTypesAnnotatedWith(Translator.class)) { + Class packet = clazz.getAnnotation(Translator.class).packet(); + + GeyserConnector.getInstance().getLogger().debug("Found annotated translator: " + clazz.getCanonicalName() + " : " + packet.getSimpleName()); + + try { + if (Packet.class.isAssignableFrom(packet)) { + Class targetPacket = (Class) packet; + PacketTranslator translator = (PacketTranslator) clazz.newInstance(); + + Registry.registerJava(targetPacket, translator); + + } else if (BedrockPacket.class.isAssignableFrom(packet)) { + Class targetPacket = (Class) packet; + PacketTranslator translator = (PacketTranslator) clazz.newInstance(); + + Registry.registerBedrock(targetPacket, translator); + + } else { + GeyserConnector.getInstance().getLogger().error("Class " + clazz.getCanonicalName() + " is annotated as a translator but has an invalid target packet."); + } + } catch (InstantiationException | IllegalAccessException e) { + GeyserConnector.getInstance().getLogger().error("Could not instantiate annotated translator " + clazz.getCanonicalName() + "."); + } + } + itemTranslator = new ItemTranslator(); BlockTranslator.init(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java index 754d05c67..f7be13c39 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java @@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; public class GenericInventoryTranslator extends InventoryTranslator { @@ -54,7 +54,7 @@ public class GenericInventoryTranslator extends InventoryTranslator { public void updateInventory(GeyserSession session, Inventory inventory) { ItemData[] bedrockItems = new ItemData[inventory.getItems().length]; for (int i = 0; i < bedrockItems.length; i++) { - bedrockItems[i] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]); + bedrockItems[i] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]); } InventoryContentPacket contentPacket = new InventoryContentPacket(); @@ -67,7 +67,7 @@ public class GenericInventoryTranslator extends InventoryTranslator { public void updateSlot(GeyserSession session, Inventory inventory, int slot) { InventorySlotPacket slotPacket = new InventorySlotPacket(); slotPacket.setContainerId(inventory.getId()); - slotPacket.setItem(TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[slot])); + slotPacket.setItem(Translators.getItemTranslator().translateToBedrock(inventory.getItems()[slot])); slotPacket.setSlot(slot); session.getUpstream().sendPacket(slotPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java index 5efe8e4e3..c5f5ad3f6 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java @@ -31,7 +31,7 @@ import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; public class JavaEntityEquipmentTranslator extends PacketTranslator { @@ -52,7 +52,7 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator { @Override public void translate(ServerOpenWindowPacket packet, GeyserSession session) { System.out.println("debug: " + packet.getType()); - InventoryTranslator translator = TranslatorsInit.getInventoryTranslator(); + InventoryTranslator translator = Translators.getInventoryTranslator(); translator.openInventory(session, new Inventory(packet.getName(), packet.getWindowId(), packet.getType(), 54)); diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 1a6296c02..2acda2c2b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -33,7 +33,7 @@ import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.world.chunk.ChunkSection; @@ -109,7 +109,7 @@ public class ChunkUtils { data.setChunkX(chunkX + x); data.setChunkZ(chunkZ + z); data.setSubChunksLength(0); - data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA); + data.setData(Translators.EMPTY_LEVEL_CHUNK_DATA); data.setCachingEnabled(false); session.getUpstream().sendPacket(data); diff --git a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java index 56b59584d..045b81d16 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java @@ -37,7 +37,7 @@ import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.TranslatorsInit; +import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import java.util.List; @@ -52,17 +52,17 @@ public class InventoryUtils { ItemData[] contents = new ItemData[40]; // Inventory for (int i = 9; i < 36; i++) { - contents[i] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]); + contents[i] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]); } // Hotbar for (int i = 36; i < 45; i++) { - contents[i - 36] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]); + contents[i - 36] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]); } // Armor for (int i = 5; i < 9; i++) { - contents[i + 31] = TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[i]); + contents[i + 31] = Translators.getItemTranslator().translateToBedrock(inventory.getItems()[i]); } inventoryContentPacket.setContents(contents); @@ -74,7 +74,7 @@ public class InventoryUtils { session.getInventoryCache().getInventories().put(packet.getWindowId(), inventory); session.getInventoryCache().setOpenInventory(inventory); - InventoryTranslator translator = TranslatorsInit.getInventoryTranslator(); + InventoryTranslator translator = Translators.getInventoryTranslator(); translator.prepareInventory(session, inventory); GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> { List packets = session.getInventoryCache().getCachedPackets().get(inventory.getId()); @@ -99,7 +99,7 @@ public class InventoryUtils { if (packet.getWindowId() != openInventory.getId()) return; - InventoryTranslator translator = TranslatorsInit.getInventoryTranslator(); + InventoryTranslator translator = Translators.getInventoryTranslator(); if (translator == null) { session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId())); return; @@ -120,7 +120,7 @@ public class InventoryUtils { if (packet.getWindowId() != openInventory.getId()) return; - InventoryTranslator translator = TranslatorsInit.getInventoryTranslator(); + InventoryTranslator translator = Translators.getInventoryTranslator(); if (translator == null) { session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId())); return; From bbf6683bd86c7c792e78a74b397969cdb7ad8e8c Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Mon, 23 Mar 2020 23:24:17 -0500 Subject: [PATCH 20/26] Make all translators annotation based --- .../network/translators/Registry.java | 9 ++++---- .../bedrock/BedrockActionTranslator.java | 13 ++++++----- .../bedrock/BedrockAnimateTranslator.java | 7 ++++-- .../BedrockCommandRequestTranslator.java | 8 ++++--- .../bedrock/BedrockInteractTranslator.java | 11 +++++----- ...BedrockInventoryTransactionTranslator.java | 9 +++++--- .../BedrockMobEquipmentTranslator.java | 7 ++++-- .../bedrock/BedrockMovePlayerTranslator.java | 16 ++++++++------ .../BedrockPlayerInitializedTranslator.java | 7 +++--- .../bedrock/BedrockRespawnTranslator.java | 7 ++++-- .../bedrock/BedrockShowCreditsTranslator.java | 7 ++++-- .../bedrock/BedrockTextTranslator.java | 7 ++++-- .../java/JavaBossBarTranslator.java | 9 +++++--- .../translators/java/JavaChatTranslator.java | 10 +++++---- .../java/JavaDifficultyTranslator.java | 7 ++++-- .../java/JavaJoinGameTranslator.java | 13 +++++++---- .../JavaLoginPluginMessageTranslator.java | 7 ++++-- .../java/JavaPluginMessageTranslator.java | 7 ++++-- .../java/JavaRespawnTranslator.java | 7 ++++-- .../translators/java/JavaTitleTranslator.java | 7 ++++-- .../entity/JavaEntityAnimationTranslator.java | 7 ++++-- .../entity/JavaEntityDestroyTranslator.java | 5 ++++- .../entity/JavaEntityEffectTranslator.java | 7 ++++-- .../entity/JavaEntityEquipmentTranslator.java | 7 ++++-- .../entity/JavaEntityHeadLookTranslator.java | 11 ++++++---- .../entity/JavaEntityMetadataTranslator.java | 7 ++++-- .../JavaEntityPositionRotationTranslator.java | 5 ++++- .../entity/JavaEntityPositionTranslator.java | 6 +++-- .../JavaEntityPropertiesTranslator.java | 7 ++++-- .../JavaEntityRemoveEffectTranslator.java | 7 ++++-- .../entity/JavaEntityRotationTranslator.java | 11 ++++++---- .../entity/JavaEntityStatusTranslator.java | 9 +++++--- .../entity/JavaEntityTeleportTranslator.java | 8 ++++--- .../entity/JavaEntityVelocityTranslator.java | 9 +++++--- .../player/JavaPlayerAbilitiesTranslator.java | 14 +++++++----- .../player/JavaPlayerActionAckTranslator.java | 5 ++++- .../player/JavaPlayerHealthTranslator.java | 7 ++++-- .../player/JavaPlayerListEntryTranslator.java | 11 ++++++---- .../JavaPlayerPositionRotationTranslator.java | 20 +++++++++-------- .../JavaPlayerSetExperienceTranslator.java | 5 ++++- .../spawn/JavaSpawnExpOrbTranslator.java | 7 ++++-- .../JavaSpawnGlobalEntityTranslator.java | 7 ++++-- .../entity/spawn/JavaSpawnMobTranslator.java | 10 +++++---- .../spawn/JavaSpawnObjectTranslator.java | 12 +++++----- .../spawn/JavaSpawnPaintingTranslator.java | 8 ++++--- .../spawn/JavaSpawnPlayerTranslator.java | 8 ++++--- .../inventory/OpenWindowPacketTranslator.java | 8 +++---- .../JavaDisplayScoreboardTranslator.java | 5 ++++- .../JavaScoreboardObjectiveTranslator.java | 7 ++++-- .../java/scoreboard/JavaTeamTranslator.java | 12 +++++----- .../scoreboard/JavaUpdateScoreTranslator.java | 8 ++++--- .../java/window/JavaOpenWindowTranslator.java | 5 ++++- .../java/window/JavaSetSlotTranslator.java | 7 ++++-- .../window/JavaWindowItemsTranslator.java | 5 ++++- .../java/world/JavaBlockChangeTranslator.java | 5 ++++- .../java/world/JavaChunkDataTranslator.java | 16 ++++++++------ .../world/JavaMultiBlockChangeTranslator.java | 7 ++++-- .../world/JavaNotifyClientTranslator.java | 22 +++++++++++++------ .../world/JavaSpawnPositionTranslator.java | 7 ++++-- .../java/world/JavaUnloadChunkTranslator.java | 5 ++++- .../java/world/JavaUpdateTimeTranslator.java | 7 ++++-- .../JavaUpdateViewDistanceTranslator.java | 5 ++++- .../JavaUpdateViewPositionTranslator.java | 7 ++++-- 63 files changed, 354 insertions(+), 179 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java index ecdd35812..cf80cdbfe 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java @@ -25,13 +25,14 @@ package org.geysermc.connector.network.translators; -import com.github.steveice10.packetlib.packet.Packet; -import com.nukkitx.protocol.bedrock.BedrockPacket; +import java.util.HashMap; +import java.util.Map; + import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; -import java.util.HashMap; -import java.util.Map; +import com.github.steveice10.packetlib.packet.Packet; +import com.nukkitx.protocol.bedrock.BedrockPacket; public class Registry { private final Map, PacketTranslator> MAP = new HashMap<>(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java index 98a580ee3..ebc45ff08 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java @@ -25,6 +25,13 @@ package org.geysermc.connector.network.translators.bedrock; +import java.util.concurrent.TimeUnit; + +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; @@ -36,12 +43,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; - -import java.util.concurrent.TimeUnit; +@Translator(packet = PlayerActionPacket.class) public class BedrockActionTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java index a3b500806..33eea7651 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + 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 org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = AnimatePacket.class) public class BedrockAnimateTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index 93b6b3ec4..28cbf4c41 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -25,15 +25,17 @@ package org.geysermc.connector.network.translators.bedrock; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; -import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; - import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; + +@Translator(packet = CommandRequestPacket.class) public class BedrockCommandRequestTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index ab73e9bb1..012ef90ea 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -25,16 +25,17 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; -import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InteractPacket; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.entity.PlayerEntity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = InteractPacket.class) public class BedrockInteractTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 8b4364a7e..cc399f107 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -25,6 +25,11 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; @@ -36,10 +41,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = InventoryTransactionPacket.class) public class BedrockInventoryTransactionTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java index 881e14948..3427a99f4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket; import com.nukkitx.protocol.bedrock.data.ContainerId; import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = MobEquipmentPacket.class) public class BedrockMobEquipmentTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index 0f13eff8b..0b5ab02bb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -25,6 +25,14 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.common.ChatColor; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.PlayerEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket; import com.nukkitx.math.GenericMath; import com.nukkitx.math.vector.Vector3f; @@ -32,13 +40,7 @@ import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.common.ChatColor; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.entity.PlayerEntity; -import org.geysermc.connector.entity.type.EntityType; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; - +@Translator(packet = MovePlayerPacket.class) public class BedrockMovePlayerTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index a2422d342..fda2cade2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -25,14 +25,15 @@ package org.geysermc.connector.network.translators.bedrock; -import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; - -import org.geysermc.common.AuthType; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.SkinUtils; +import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; + +@Translator(packet = SetLocalPlayerAsInitializedPacket.class) public class BedrockPlayerInitializedTranslator extends PacketTranslator { @Override public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java index 298914ad4..3c7e85ecf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.ClientRequest; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.RespawnPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = RespawnPacket.class) public class BedrockRespawnTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java index 9bd104b21..161397b66 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockShowCreditsTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.bedrock; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.ClientRequest; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket; import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = ShowCreditsPacket.class) public class BedrockShowCreditsTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java index f33f3fbd9..1c8416310 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.bedrock; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; -import com.nukkitx.protocol.bedrock.packet.TextPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.nukkitx.protocol.bedrock.packet.TextPacket; + +@Translator(packet = TextPacket.class) public class BedrockTextTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java index bfde6f74c..3c1452a53 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java @@ -25,16 +25,19 @@ package org.geysermc.connector.network.translators.java; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +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.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 org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.utils.MessageUtils; +@Translator(packet = ServerBossBarPacket.class) public class JavaBossBarTranslator extends PacketTranslator { @Override public void translate(ServerBossBarPacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index 58c17b712..226bd9714 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -25,14 +25,16 @@ package org.geysermc.connector.network.translators.java; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.utils.MessageUtils; + import com.github.steveice10.mc.protocol.data.message.TranslationMessage; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import com.nukkitx.protocol.bedrock.packet.TextPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.utils.MessageUtils; - +@Translator(packet = ServerChatPacket.class) public class JavaChatTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java index 6741cd7ec..1abf8e461 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket; -import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket; +import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket; + +@Translator(packet = ServerDifficultyPacket.class) public class JavaDifficultyTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 51758011e..1abe1940c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -25,16 +25,21 @@ package org.geysermc.connector.network.translators.java; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; - -import com.nukkitx.protocol.bedrock.data.PlayerPermission; -import com.nukkitx.protocol.bedrock.packet.*; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.DimensionUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; +import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; + +@Translator(packet = ServerJoinGamePacket.class) public class JavaJoinGameTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java index f92fca9f9..1ce17fe91 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java @@ -1,10 +1,13 @@ package org.geysermc.connector.network.translators.java; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.login.client.LoginPluginResponsePacket; import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = LoginPluginRequestPacket.class) public class JavaLoginPluginMessageTranslator extends PacketTranslator { @Override public void translate(LoginPluginRequestPacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java index f60d405ef..60227aa4a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaPluginMessageTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket; + +@Translator(packet = ServerPluginMessagePacket.class) public class JavaPluginMessageTranslator extends PacketTranslator { @Override public void translate(ServerPluginMessagePacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java index 285f9d855..185aab540 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java @@ -25,14 +25,17 @@ package org.geysermc.connector.network.translators.java; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; -import com.nukkitx.protocol.bedrock.packet.*; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.DimensionUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; + +@Translator(packet = ServerRespawnPacket.class) public class JavaRespawnTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java index 852c1af81..7334f8f8b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaTitleTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket; -import com.nukkitx.protocol.bedrock.packet.SetTitlePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.MessageUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket; +import com.nukkitx.protocol.bedrock.packet.SetTitlePacket; + +@Translator(packet = ServerTitlePacket.class) public class JavaTitleTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java index 28c3e1f6d..9d8853e75 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityAnimationTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket; -import com.nukkitx.protocol.bedrock.packet.AnimatePacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket; +import com.nukkitx.protocol.bedrock.packet.AnimatePacket; + +@Translator(packet = ServerEntityAnimationPacket.class) public class JavaEntityAnimationTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java index 848b823de..98da3892c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket; + +@Translator(packet = ServerEntityDestroyPacket.class) public class JavaEntityDestroyTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java index 9716d9597..be54e967f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEffectTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; -import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.EntityUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; +import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; + +@Translator(packet = ServerEntityEffectPacket.class) public class JavaEntityEffectTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java index c5f5ad3f6..70c171425 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java @@ -25,14 +25,17 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket; -import com.nukkitx.protocol.bedrock.data.ItemData; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translators; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket; +import com.nukkitx.protocol.bedrock.data.ItemData; + +@Translator(packet = ServerEntityEquipmentPacket.class) public class JavaEntityEquipmentTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityHeadLookTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityHeadLookTranslator.java index c03c75837..d21d8cd6b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityHeadLookTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityHeadLookTranslator.java @@ -25,15 +25,18 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; -import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; + +@Translator(packet = ServerEntityHeadLookPacket.class) public class JavaEntityHeadLookTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java index d8d28fb71..dd097b7da 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; + +@Translator(packet = ServerEntityMetadataPacket.class) public class JavaEntityMetadataTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java index 7319c5612..581f16e36 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; + +@Translator(packet = ServerEntityPositionRotationPacket.class) public class JavaEntityPositionRotationTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java index ae404d80d..b0ae3595e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionTranslator.java @@ -25,12 +25,14 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; - import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; + +@Translator(packet = ServerEntityPositionPacket.class) public class JavaEntityPositionTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java index c5c71f753..aedbf1a18 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPropertiesTranslator.java @@ -25,14 +25,17 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.AttributeUtils; +import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; + +@Translator(packet = ServerEntityPropertiesPacket.class) public class JavaEntityPropertiesTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java index 97837bb81..fd8be52cb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRemoveEffectTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket; -import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.EntityUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket; +import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; + +@Translator(packet = ServerEntityRemoveEffectPacket.class) public class JavaEntityRemoveEffectTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java index c0cde6d3e..24ca5bb4a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java @@ -25,15 +25,18 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; -import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; + +@Translator(packet = ServerEntityRotationPacket.class) public class JavaEntityRotationTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java index 2865b14c7..d3e3973ce 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; -import com.nukkitx.protocol.bedrock.data.EntityEventType; -import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; +import com.nukkitx.protocol.bedrock.data.EntityEventType; +import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; + +@Translator(packet = ServerEntityStatusPacket.class) public class JavaEntityStatusTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java index a08e4866f..febfc9ce3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java @@ -25,13 +25,15 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; -import com.nukkitx.math.vector.Vector3f; - import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; +import com.nukkitx.math.vector.Vector3f; + +@Translator(packet = ServerEntityTeleportPacket.class) public class JavaEntityTeleportTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java index 8c3c26d8a..2bb8f6157 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityVelocityTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; + +@Translator(packet = ServerEntityVelocityPacket.class) public class JavaEntityVelocityTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java index 8e9224ed3..87e693ff8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerAbilitiesTranslator.java @@ -25,19 +25,23 @@ package org.geysermc.connector.network.translators.java.entity.player; +import java.util.Set; + +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket; import com.nukkitx.protocol.bedrock.data.EntityDataMap; import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; + import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; - -import java.util.Set; +@Translator(packet = ServerPlayerAbilitiesPacket.class) public class JavaPlayerAbilitiesTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java index 451081a1a..09eb5d55b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerActionAckTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.entity.player; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.ChunkUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket; + +@Translator(packet = ServerPlayerActionAckPacket.class) public class JavaPlayerActionAckTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java index bfae527b9..8dc432565 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerHealthTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity.player; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket; -import com.nukkitx.protocol.bedrock.packet.SetHealthPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket; +import com.nukkitx.protocol.bedrock.packet.SetHealthPacket; + +@Translator(packet = ServerPlayerHealthPacket.class) public class JavaPlayerHealthTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java index 48f20dbdd..5ac759b48 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java @@ -25,16 +25,19 @@ package org.geysermc.connector.network.translators.java.entity.player; +import org.geysermc.connector.entity.PlayerEntity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.utils.SkinUtils; + import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; -import org.geysermc.connector.entity.PlayerEntity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.utils.SkinUtils; +@Translator(packet = ServerPlayerListEntryPacket.class) public class JavaPlayerListEntryTranslator extends PacketTranslator { @Override public void translate(ServerPlayerListEntryPacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 0c6b9258a..0f56bc935 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -25,20 +25,22 @@ package org.geysermc.connector.network.translators.java.entity.player; -import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.protocol.bedrock.data.EntityEventType; -import com.nukkitx.protocol.bedrock.packet.*; - -import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; -import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; - import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityEventType; +import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; +import com.nukkitx.protocol.bedrock.packet.RespawnPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; + +@Translator(packet = ServerPlayerPositionRotationPacket.class) public class JavaPlayerPositionRotationTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java index 05eccbaa3..ace7a2b8e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerSetExperienceTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.entity.player; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket; + +@Translator(packet = ServerPlayerSetExperiencePacket.class) public class JavaPlayerSetExperienceTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java index b1a10f7b6..79ba3e0f5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java @@ -25,14 +25,17 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; -import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.ExpOrbEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; +import com.nukkitx.math.vector.Vector3f; + +@Translator(packet = ServerSpawnExpOrbPacket.class) public class JavaSpawnExpOrbTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java index b9c3d65bd..da2e59afe 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket; -import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket; +import com.nukkitx.math.vector.Vector3f; + +@Translator(packet = ServerSpawnGlobalEntityPacket.class) public class JavaSpawnGlobalEntityTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java index ee01323b0..d955ecfdb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java @@ -25,18 +25,20 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; -import com.nukkitx.math.vector.Vector3f; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.EntityUtils; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; +import com.nukkitx.math.vector.Vector3f; +@Translator(packet = ServerSpawnMobPacket.class) public class JavaSpawnMobTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java index 88a64b500..15741c98e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java @@ -25,19 +25,21 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; -import com.nukkitx.math.vector.Vector3f; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.EntityUtils; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; +import com.nukkitx.math.vector.Vector3f; +@Translator(packet = ServerSpawnObjectPacket.class) public class JavaSpawnObjectTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java index 3da528531..5fe3847f1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java @@ -25,15 +25,17 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket; -import com.nukkitx.math.vector.Vector3f; - import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PaintingEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.PaintingType; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket; +import com.nukkitx.math.vector.Vector3f; + +@Translator(packet = ServerSpawnPaintingPacket.class) public class JavaSpawnPaintingTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java index f737a13c3..331eb0945 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java @@ -25,16 +25,18 @@ package org.geysermc.connector.network.translators.java.entity.spawn; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; -import com.nukkitx.math.vector.Vector3f; - import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.SkinUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import com.nukkitx.math.vector.Vector3f; + +@Translator(packet = ServerSpawnPlayerPacket.class) public class JavaSpawnPlayerTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java index cd563a80f..2719a72a0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/inventory/OpenWindowPacketTranslator.java @@ -1,15 +1,15 @@ package org.geysermc.connector.network.translators.java.inventory; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; -import com.nukkitx.protocol.bedrock.data.ContainerId; -import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; -import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.inventory.InventoryTranslator; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; + +@Translator(packet = ServerOpenWindowPacket.class) public class OpenWindowPacketTranslator extends PacketTranslator { @Override public void translate(ServerOpenWindowPacket packet, GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java index 49bfc4ba9..5a722953a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java @@ -25,10 +25,13 @@ package org.geysermc.connector.network.translators.java.scoreboard; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; + +@Translator(packet = ServerDisplayScoreboardPacket.class) public class JavaDisplayScoreboardTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java index eac126866..d852e652a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java @@ -25,15 +25,18 @@ package org.geysermc.connector.network.translators.java.scoreboard; -import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.ScoreboardCache; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.scoreboard.Objective; import org.geysermc.connector.scoreboard.Scoreboard; import org.geysermc.connector.utils.MessageUtils; +import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; + +@Translator(packet = ServerScoreboardObjectivePacket.class) public class JavaScoreboardObjectiveTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java index 9ef7c7056..a832f3d71 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -25,20 +25,22 @@ package org.geysermc.connector.network.translators.java.scoreboard; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import java.util.Arrays; +import java.util.Set; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.scoreboard.Scoreboard; import org.geysermc.connector.scoreboard.UpdateType; import org.geysermc.connector.utils.MessageUtils; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; + +@Translator(packet = ServerTeamPacket.class) public class JavaTeamTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java index 5232823d0..eac2ed049 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java @@ -25,15 +25,17 @@ package org.geysermc.connector.network.translators.java.scoreboard; -import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction; -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; - import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.scoreboard.Objective; import org.geysermc.connector.scoreboard.Scoreboard; +import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; + +@Translator(packet = ServerUpdateScorePacket.class) public class JavaUpdateScoreTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java index a22998d53..9495bed48 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.window; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.InventoryUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; + +@Translator(packet = ServerOpenWindowPacket.class) public class JavaOpenWindowTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java index 18e309d80..93df65e82 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java @@ -25,14 +25,17 @@ package org.geysermc.connector.network.translators.java.window; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.InventoryCache; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.InventoryUtils; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; + +@Translator(packet = ServerSetSlotPacket.class) public class JavaSetSlotTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java index b5cd605e6..f2287f6dc 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java @@ -25,13 +25,16 @@ package org.geysermc.connector.network.translators.java.window; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.InventoryCache; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.InventoryUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; + +@Translator(packet = ServerWindowItemsPacket.class) public class JavaWindowItemsTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java index 913552fa4..b79525a9d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.ChunkUtils; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket; + +@Translator(packet = ServerBlockChangePacket.class) public class JavaBlockChangeTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index f570bb0b0..4687dfbbf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -25,6 +25,14 @@ package org.geysermc.connector.network.translators.java.world; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.BiomeTranslator; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.utils.ChunkUtils; +import org.geysermc.connector.world.chunk.ChunkSection; + import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; @@ -35,13 +43,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.BiomeTranslator; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.utils.ChunkUtils; -import org.geysermc.connector.world.chunk.ChunkSection; - +@Translator(packet = ServerChunkDataPacket.class) public class JavaChunkDataTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java index e36019317..64733a027 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMultiBlockChangeTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.ChunkUtils; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket; + +@Translator(packet = ServerMultiBlockChangePacket.class) public class JavaMultiBlockChangeTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index 29ad5c3ed..3e1904d48 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -25,6 +25,14 @@ package org.geysermc.connector.network.translators.java.world; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.data.game.ClientRequest; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.world.notify.EnterCreditsValue; @@ -35,15 +43,15 @@ import com.nukkitx.protocol.bedrock.data.EntityDataMap; import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.PlayerPermission; -import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; +import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; +import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket; + import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; -import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; - -import java.util.Set; -import java.util.concurrent.ThreadLocalRandom; +@Translator(packet = ServerNotifyClientPacket.class) public class JavaNotifyClientTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnPositionTranslator.java index 3e2029add..d518a7aea 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnPositionTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.world; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.SetSpawnPositionPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = ServerSpawnPositionPacket.class) public class JavaSpawnPositionTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java index 330a4d61b..02c693d87 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.world.chunk.ChunkPosition; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket; + +@Translator(packet = ServerUnloadChunkPacket.class) public class JavaUnloadChunkTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java index e820e278e..ccb69856c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTimeTranslator.java @@ -25,11 +25,14 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; -import com.nukkitx.protocol.bedrock.packet.SetTimePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; +import com.nukkitx.protocol.bedrock.packet.SetTimePacket; + +@Translator(packet = ServerUpdateTimePacket.class) public class JavaUpdateTimeTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java index 1b339b1cf..823ce1998 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java @@ -25,10 +25,13 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket; + +@Translator(packet = ServerUpdateViewDistancePacket.class) public class JavaUpdateViewDistanceTranslator extends PacketTranslator { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java index ebe9062fa..452e86e4f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java @@ -25,12 +25,15 @@ package org.geysermc.connector.network.translators.java.world; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; +@Translator(packet = ServerUpdateViewPositionPacket.class) public class JavaUpdateViewPositionTranslator extends PacketTranslator { @Override From ac8d1bf295c875fc17ea418734ca37bbb277b8c4 Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Tue, 24 Mar 2020 02:56:04 -0500 Subject: [PATCH 21/26] Automatically add loopback exemption to Windows --- .../platform/standalone/GeyserBootstrap.java | 14 +++--- .../geysermc/platform/standalone/Util.java | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 1ba111e7d..0b70df580 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -25,18 +25,18 @@ package org.geysermc.platform.standalone; +import java.io.File; +import java.io.IOException; +import java.util.UUID; + import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; import org.geysermc.platform.standalone.console.GeyserLogger; -import java.io.File; -import java.io.IOException; -import java.util.UUID; - public class GeyserBootstrap implements IGeyserBootstrap { - + private GeyserConfiguration geyserConfig; private GeyserLogger geyserLogger; @@ -49,7 +49,9 @@ public class GeyserBootstrap implements IGeyserBootstrap { @Override public void onEnable() { geyserLogger = new GeyserLogger(); - + + Util.checkLoopback(geyserLogger); + try { File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java new file mode 100644 index 000000000..753b3b245 --- /dev/null +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java @@ -0,0 +1,44 @@ +package org.geysermc.platform.standalone; + +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.OpenOption; +import java.nio.file.Paths; + +import org.geysermc.platform.standalone.console.GeyserLogger; + +public class Util { + private static final String checkExemption = "powershell -Command \"CheckNetIsolation LoopbackExempt -s\""; // Java's Exec feature runs as CMD, NetIsolation is only accessible from PowerShell. + private static final String loopbackCommand = "powershell -Command \"CheckNetIsolation LoopbackExempt -a -n='Microsoft.MinecraftUWP_8wekyb3d8bbwe'\""; + private static final String startScript = "powershell -Command \"Start-Process 'cmd' -ArgumentList /c,%temp%/loopback_minecraft.bat -Verb runAs\""; + + public static void checkLoopback(GeyserLogger geyserLogger) { + if (System.getProperty("os.name").equalsIgnoreCase("Windows 10")) { + try { + Process process = Runtime.getRuntime().exec(checkExemption); + InputStream is = process.getInputStream(); + StringBuilder sb = new StringBuilder(); + + while (process.isAlive()) { + if (is.available() != 0) { + sb.append((char) is.read()); + } + } + + String result = sb.toString(); + + if (!result.contains("minecraftuwp")) { + Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes(), new OpenOption[0]); + process = Runtime.getRuntime().exec(startScript); + + geyserLogger.warning("Added loopback exemption to Windows!"); + } + } catch (Exception e) { + e.printStackTrace(); + + geyserLogger.error("Couldn't auto add loopback exemption to Windows!"); + } + } + } + +} From f8407eeb5a3fde0cffdd52f0d50372ff3c6c8264 Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Wed, 25 Mar 2020 00:55:09 -0500 Subject: [PATCH 22/26] Add requested changes to PR --- .../platform/standalone/GeyserBootstrap.java | 2 +- .../{Util.java => LoopbackUtil.java} | 5 +- .../network/translators/Translators.java | 72 ------------------- 3 files changed, 4 insertions(+), 75 deletions(-) rename bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/{Util.java => LoopbackUtil.java} (91%) diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 0b70df580..284d94072 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -50,7 +50,7 @@ public class GeyserBootstrap implements IGeyserBootstrap { public void onEnable() { geyserLogger = new GeyserLogger(); - Util.checkLoopback(geyserLogger); + LoopbackUtil.checkLoopback(geyserLogger); try { File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java similarity index 91% rename from bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java rename to bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java index 753b3b245..20a810726 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/Util.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java @@ -5,9 +5,10 @@ import java.nio.file.Files; import java.nio.file.OpenOption; import java.nio.file.Paths; +import org.geysermc.common.ChatColor; import org.geysermc.platform.standalone.console.GeyserLogger; -public class Util { +public class LoopbackUtil { private static final String checkExemption = "powershell -Command \"CheckNetIsolation LoopbackExempt -s\""; // Java's Exec feature runs as CMD, NetIsolation is only accessible from PowerShell. private static final String loopbackCommand = "powershell -Command \"CheckNetIsolation LoopbackExempt -a -n='Microsoft.MinecraftUWP_8wekyb3d8bbwe'\""; private static final String startScript = "powershell -Command \"Start-Process 'cmd' -ArgumentList /c,%temp%/loopback_minecraft.bat -Verb runAs\""; @@ -31,7 +32,7 @@ public class Util { Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes(), new OpenOption[0]); process = Runtime.getRuntime().exec(startScript); - geyserLogger.warning("Added loopback exemption to Windows!"); + geyserLogger.info(ChatColor.AQUA + "Added loopback exemption to Windows!"); } } catch (Exception e) { e.printStackTrace(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java index c87cab3ce..d4e5dae8b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Translators.java @@ -71,78 +71,6 @@ public class Translators { @SuppressWarnings("unchecked") public static void start() { - /*Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator()); - - Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator()); - Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator()); - Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator()); - Registry.registerJava(ServerTitlePacket.class, new JavaTitleTranslator()); - Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator()); - Registry.registerJava(ServerRespawnPacket.class, new JavaRespawnTranslator()); - Registry.registerJava(ServerSpawnPositionPacket.class, new JavaSpawnPositionTranslator()); - Registry.registerJava(ServerDifficultyPacket.class, new JavaDifficultyTranslator()); - - Registry.registerJava(ServerEntityAnimationPacket.class, new JavaEntityAnimationTranslator()); - Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator()); - Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator()); - Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator()); - Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator()); - Registry.registerJava(ServerEntityPropertiesPacket.class, new JavaEntityPropertiesTranslator()); - Registry.registerJava(ServerEntityRotationPacket.class, new JavaEntityRotationTranslator()); - Registry.registerJava(ServerEntityHeadLookPacket.class, new JavaEntityHeadLookTranslator()); - Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator()); - Registry.registerJava(ServerEntityStatusPacket.class, new JavaEntityStatusTranslator()); - Registry.registerJava(ServerEntityEquipmentPacket.class, new JavaEntityEquipmentTranslator()); - Registry.registerJava(ServerEntityEffectPacket.class, new JavaEntityEffectTranslator()); - Registry.registerJava(ServerEntityRemoveEffectPacket.class, new JavaEntityRemoveEffectTranslator()); - Registry.registerJava(ServerBossBarPacket.class, new JavaBossBarTranslator()); - - Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); - Registry.registerJava(ServerSpawnGlobalEntityPacket.class, new JavaSpawnGlobalEntityTranslator()); - Registry.registerJava(ServerSpawnMobPacket.class, new JavaSpawnMobTranslator()); - Registry.registerJava(ServerSpawnObjectPacket.class, new JavaSpawnObjectTranslator()); - Registry.registerJava(ServerSpawnPaintingPacket.class, new JavaSpawnPaintingTranslator()); - Registry.registerJava(ServerSpawnPlayerPacket.class, new JavaSpawnPlayerTranslator()); - Registry.registerJava(ServerPlayerListEntryPacket.class, new JavaPlayerListEntryTranslator()); - - Registry.registerJava(ServerPlayerPositionRotationPacket.class, new JavaPlayerPositionRotationTranslator()); - Registry.registerJava(ServerPlayerSetExperiencePacket.class, new JavaPlayerSetExperienceTranslator()); - Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator()); - Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator()); - - Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator()); - - Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator()); - Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator()); - Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator()); - Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator()); - Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator()); - Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator()); - Registry.registerJava(ServerScoreboardObjectivePacket.class, new JavaScoreboardObjectiveTranslator()); - Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaDisplayScoreboardTranslator()); - Registry.registerJava(ServerUpdateScorePacket.class, new JavaUpdateScoreTranslator()); - Registry.registerJava(ServerTeamPacket.class, new JavaTeamTranslator()); - Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator()); - Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator()); - Registry.registerJava(ServerUnloadChunkPacket.class, new JavaUnloadChunkTranslator()); - - Registry.registerJava(ServerUpdateViewPositionPacket.class, new JavaUpdateViewPositionTranslator()); - Registry.registerJava(ServerUpdateViewDistancePacket.class, new JavaUpdateViewDistanceTranslator()); - - Registry.registerJava(ServerOpenWindowPacket.class, new OpenWindowPacketTranslator()); - - Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); - Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator()); - Registry.registerBedrock(InventoryTransactionPacket.class, new BedrockInventoryTransactionTranslator()); - Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator()); - Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator()); - Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator()); - Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator()); - Registry.registerBedrock(InteractPacket.class, new BedrockInteractTranslator()); - Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator()); - Registry.registerBedrock(RespawnPacket.class, new BedrockRespawnTranslator()); - Registry.registerBedrock(ShowCreditsPacket.class, new BedrockShowCreditsTranslator());*/ - Reflections ref = new Reflections("org.geysermc.connector.network.translators"); for (Class clazz : ref.getTypesAnnotatedWith(Translator.class)) { From 5222232e720cc590ad20640949e94d0355b52ba1 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Thu, 26 Mar 2020 23:00:52 -0500 Subject: [PATCH 23/26] Add rest of fixes for operator bug --- .../org/geysermc/connector/network/session/GeyserSession.java | 2 +- .../network/translators/java/JavaJoinGameTranslator.java | 2 +- .../java/entity/player/JavaPlayerAbilitiesTranslator.java | 2 +- .../translators/java/world/JavaNotifyClientTranslator.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index a2d8a7263..4a6f43826 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -381,7 +381,7 @@ public class GeyserSession implements CommandSender { startGamePacket.setBonusChestEnabled(false); startGamePacket.setStartingWithMap(false); startGamePacket.setTrustingPlayers(true); - startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR); + startGamePacket.setDefaultPlayerPermission(PlayerPermission.MEMBER); startGamePacket.setServerChunkTickRange(4); startGamePacket.setBehaviorPackLocked(false); startGamePacket.setResourcePackLocked(false); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 1abe1940c..0d6caaed0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -49,7 +49,7 @@ public class JavaJoinGameTranslator extends PacketTranslator Date: Thu, 26 Mar 2020 23:29:16 -0500 Subject: [PATCH 24/26] Fix null potion type message in console (Addresses #227) --- .../java/org/geysermc/connector/entity/type/EntityType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 873c85345..f6af511cd 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -123,7 +123,7 @@ public enum EntityType { PAINTING(PaintingEntity.class, 83, 0f), MINECART(MinecartEntity.class, 84, 0f), FIREBALL(ItemedFireballEntity.class, 85, 0f), - SPLASH_POTION(ThrowableEntity.class, 86, 0f), + POTION(ThrowableEntity.class, 86, 0f), ENDER_PEARL(ThrowableEntity.class, 87, 0f), LEASH_KNOT(Entity.class, 88, 0f), WITHER_SKULL(Entity.class, 89, 0f), From 9b487d7d034fc97acf80ca020fc9dfcd7b93414e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 3 Apr 2020 17:20:14 -0500 Subject: [PATCH 25/26] Fix combat by sending the animate packet after damage (Closes #260) --- .../translators/bedrock/BedrockAnimateTranslator.java | 10 ++++++++-- .../bedrock/BedrockInventoryTransactionTranslator.java | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java index 33eea7651..7ccb24262 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java @@ -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 { @@ -40,8 +42,12 @@ public class BedrockAnimateTranslator extends PacketTranslator { 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; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index cc399f107..de23b8a05 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -61,7 +61,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator Date: Sat, 4 Apr 2020 01:27:34 -0500 Subject: [PATCH 26/26] Add support for team prefixes, suffixes, and colors (Fixes #150) --- .../connector/entity/PlayerEntity.java | 28 ++++++++++ .../java/scoreboard/JavaTeamTranslator.java | 2 + .../geysermc/connector/scoreboard/Team.java | 3 +- .../connector/utils/MessageUtils.java | 54 ++++++++++--------- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 56d59ec3d..fb48871b3 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -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.utils.SkinUtils; import java.util.UUID; @@ -152,4 +157,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()); + } + } + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java index a832f3d71..c9d1ccfe2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -52,12 +52,14 @@ public class JavaTeamTranslator extends PacketTranslator { 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); diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java index bf4b78532..c2fcc02c8 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java @@ -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 entities = new ObjectOpenHashSet<>(); - public Team(Scoreboard scoreboard, String id) { this.scoreboard = scoreboard; this.id = id; diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index b5260ab75..7b4c84a7e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -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 getTranslationParams(Message[] messages) { - List strings = new ArrayList(); - for (int i = 0; i < messages.length; i++) { - if (messages[i] instanceof TranslationMessage) { - TranslationMessage translation = (TranslationMessage) messages[i]; + List 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 ""; + } }