Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon if player hasn't Emotecraft mod #467

Open
wants to merge 2 commits into
base: 1.20.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void onDisable() {
}

public void registerProtocolListener() {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.NAMED_ENTITY_SPAWN) {
protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.SPAWN_ENTITY) {//TODO HAS MOD replace deprecate packet? (because not work for me on test HAS MOD 1.20.4)
@Override
public void onPacketSending(PacketEvent packetEvent) {
if (packetEvent.getPacketType().equals(PacketType.Play.Server.NAMED_ENTITY_SPAWN)) {
if (packetEvent.getPacketType().equals(PacketType.Play.Server.SPAWN_ENTITY)) {
//Field trackedField = packetEvent.getPacket().getStructures().getField(2);
UUID tracked = packetEvent.getPacket().getUUIDs().readSafely(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.bukkit.event.entity.EntityPoseChangeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRegisterChannelEvent;
import org.bukkit.event.player.PlayerUnregisterChannelEvent;

import java.util.HashMap;
import java.util.UUID;
Expand All @@ -25,7 +27,6 @@ public class ServerSideEmotePlay extends AbstractServerEmotePlay<Player> impleme

final HashMap<UUID, BukkitNetworkInstance> player_database = new HashMap<>();


public ServerSideEmotePlay(BukkitWrapper plugin){
this.plugin = plugin;
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, BukkitWrapper.EmotePacket);
Expand Down Expand Up @@ -149,7 +150,8 @@ public void onPlayerLeave(PlayerQuitEvent event){
Player player = event.getPlayer();

BukkitNetworkInstance instance = this.player_database.remove(player.getUniqueId());
if(instance != null)instance.closeConnection();
EmotePacket.player_has_mod.remove(player.getUniqueId());//TODO HAS MOD
if(instance != null) instance.closeConnection();
}

@EventHandler
Expand All @@ -161,4 +163,28 @@ public void playerDies(EntityPoseChangeEvent event) {
}
}
}

@EventHandler//TODO HAS MOD
public void playerRegisterChannel(PlayerRegisterChannelEvent event) {
if(event.getChannel().equals(BukkitWrapper.EmotePacket)) {
EmotePacket.player_has_mod.add(event.getPlayer().getUniqueId());
for(Player player1 : plugin.getServer().getOnlinePlayers()) {
if(event.getPlayer() != player1 && event.getPlayer().canSee(player1)) {
sendHasMode(event.getPlayer(),player1);
}
}
}
}

@EventHandler//TODO HAS MOD need this or not? reinsure
public void playerUnregisterChannel(PlayerUnregisterChannelEvent event) {
if(event.getChannel().equals(BukkitWrapper.EmotePacket)) {
EmotePacket.player_has_mod.remove(event.getPlayer().getUniqueId());
for(Player player1 : plugin.getServer().getOnlinePlayers()) {
if(event.getPlayer() != player1 && event.getPlayer().canSee(player1)) {
sendHasMode(event.getPlayer(),player1);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ default void receiveMessage(ByteBuffer byteBuffer, UUID player) {
* You are asked to send your config.
* From 2.2 in the MC configuration phase, the server will initialize config, the client will reply.
* <p>
* @deprecated ambiguous name, use {@link #sendC2SConfig()}
* @deprecated ambiguous name, use {@link #sendC2SConfig(Consumer)}
*/
@Deprecated
default void sendConfigCallback() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SerializableConfig {

public final BooleanConfigEntry autoFixEmoteStop = new BooleanConfigEntry("autoFixEmoteStop", true, true, expert, false);

public final BooleanConfigEntry sendHasModToPlayer = new BooleanConfigEntry("sendHasModToPlayer", true, true, expert);//TODO HAS MOD

public void iterate(Consumer<ConfigEntry<?>> consumer){
basics.forEach(consumer);
expert.forEach(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -21,11 +22,15 @@
public class EmotePacket {
public static final HashMap<Byte, Byte> defaultVersions = new HashMap<>();

public static final HashSet<UUID> player_has_mod = new HashSet<>();//TODO HAS MOD

static {
AbstractNetworkPacket tmp = new EmoteDataPacket();
defaultVersions.put(tmp.getID(), tmp.getVer());
tmp = new PlayerDataPacket();
defaultVersions.put(tmp.getID(), tmp.getVer());
tmp = new PlayerHasModPacket();//TODO HAS MOD
defaultVersions.put(tmp.getID(), tmp.getVer());
tmp = new DiscoveryPacket();
defaultVersions.put(tmp.getID(), tmp.getVer());
tmp = new StopPacket();
Expand Down Expand Up @@ -56,6 +61,7 @@ protected EmotePacket(@Nonnull NetData data) {
this.data = data;
subPackets.put(new EmoteDataPacket());
subPackets.put(new PlayerDataPacket());
subPackets.put(new PlayerHasModPacket());//TODO HAS MOD
subPackets.put(new StopPacket());
subPackets.put(new DiscoveryPacket());
subPackets.put(new SongPacket());
Expand Down Expand Up @@ -260,6 +266,14 @@ public Builder configureToConfigExchange(boolean songEnabled){
return this;
}

public Builder configureToSendHasMod(UUID player){//TODO HAS MOD
//if(data.purpose != PacketTask.UNKNOWN)throw new IllegalArgumentException("Can's send and stop emote at the same time");//TODO WHAT IS DO IT? 8)
data.purpose = PacketTask.HAS_MOD;
data.player = player;
data.hasMod = player_has_mod.contains(player);
return this;
}

public void removePlayerID(){
this.data.player = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public enum PacketTask {
UNKNOWN(0, false, false, false),
STREAM(1, true, false, true),
HAS_MOD(2,false,false,true),//TODO HAS MOD
CONFIG(8, false, false, false),
STOP(10, true, false, true),
FILE(0x10, true, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class NetData {
//left it null when using Collar
@Nullable
public UUID player = null;
public boolean hasMod = false;//TODO HAS MOD
//Forced flag
//On play, it can not be stopped by the player
//On stop, the server stops it not because invalid but because event stopped it
Expand Down Expand Up @@ -79,6 +80,7 @@ public NetData copy() {
data.versionsUpdated = versionsUpdated;
data.versions = versions;
data.player = player;
data.hasMod = hasMod;//TODO HAS MOD
data.sizeLimit = sizeLimit;
data.isForced = isForced;
return data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.github.kosmx.emotes.common.network.objects;

import io.github.kosmx.emotes.common.network.CommonNetwork;
import io.github.kosmx.emotes.common.network.PacketTask;

import java.io.IOException;
import java.nio.ByteBuffer;

public class PlayerHasModPacket extends AbstractNetworkPacket{//TODO HAS MOD
@Override
public byte getID() {
return 2;
}

@Override
public byte getVer() {
return 1;
}

@Override
public boolean read(ByteBuffer byteBuffer, NetData config, int version) throws IOException {
config.player = CommonNetwork.readUUID(byteBuffer);
config.hasMod = byteBuffer.get() != 0x00;
return true;
}

@Override
public void write(ByteBuffer byteBuffer, NetData config) throws IOException {
CommonNetwork.writeUUID(byteBuffer, config.player);
byteBuffer.put(config.hasMod ? (byte) 0x01 : (byte) 0x00);
}

@Override
public boolean doWrite(NetData config) {
return config.purpose == PacketTask.HAS_MOD && config.player != null;
}

@Override
public int calculateSize(NetData config) {
return 17;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"emotecraft.otherconfig.validationThreshold.tooltip": "How much offset is too much.",
"emotecraft.otherconfig.dark": "Use Dark Emote Wheel",
"emotecraft.otherconfig.showicon": "Show Icons Only (If Available)",
"emotecraft.otherconfig.inWorldIcons": "Show Icons In World",
"emotecraft.otherconfig.inWorldIcons.tooltip": "For example, if a player does not have Emotecraft installed",
"emotecraft.otherconfig.sendHasModToPlayer": "Allow server to send mod info",
"emotecraft.otherconfig.sendHasModToPlayer.tooltip": "Allow the server to send players information about whether players have Emotecraft (for admin only)",
"emotecraft.otherconfig.stopthreshold": "Emote Stop Speed",
"emotecraft.otherconfig.stopthreshold.tooltip": " (0.22 is walking speed)\n\nWith a large enough value, the emote won't stop. In that case make sure a key is bound to 'Stop playing emote.'",
"emotecraft.otherconfig.yratio": "Y-Axis Stop Threshold",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"emotecraft.otherconfig.validationThreshold.tooltip": "Предел возможного смещения персонажа",
"emotecraft.otherconfig.dark": "Тёмная тема колеса выбора эмоций",
"emotecraft.otherconfig.showicon": "Показывать иконки вместо названий эмоций (если имеются)",
"emotecraft.otherconfig.inWorldIcons": "Показывать иконки в мире",
"emotecraft.otherconfig.inWorldIcons.tooltip": "Например, если игрок не имеет установленного Emotecraft",
"emotecraft.otherconfig.sendHasModToPlayer": "Разрешить серверу отправить инфо о моде",
"emotecraft.otherconfig.sendHasModToPlayer.tooltip": "Разрешить серверу отправлять игрокам информацию о том, есть ли у них Emotecraft (только для админов)",
"emotecraft.otherconfig.stopthreshold": "Скорость остановки эмоции",
"emotecraft.otherconfig.stopthreshold.tooltip": " (0.22 - скорость ходьбы)\nс большим значением вы не перестанете проигрывать эмоцию. Убедитесь, что у вас назначена клавиша \"Остановить воспроизведение эмоции\"",
"emotecraft.otherconfig.yratio": "Влияние перемещения по оси Y на порог остановки",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public abstract class AbstractServerEmotePlay<P> extends ServerEmoteAPI {

//private AbstractServerEmotePlay instance;


public AbstractServerEmotePlay(){
try {
initMappings(EmoteInstance.instance.getConfigPath());
Expand Down Expand Up @@ -215,6 +214,21 @@ public void playerStartTracking(P tracked, P tracker) {
if (playedEmote != null) {
sendForPlayer(new EmotePacket.Builder().configureToStreamEmote(playedEmote.getLeft()).configureEmoteTick(playedEmote.getRight()).configureTarget(getUUIDFromPlayer(tracked)).build().data, tracked, getUUIDFromPlayer(tracker));
}

sendHasMode(tracked,tracker);//TODO HAS MOD
}

public void sendHasMode(P tracked, P tracker) {//TODO HAS MOD
//check server config
if(!EmoteInstance.config.sendHasModToPlayer.get()) return;

if(EmotePacket.player_has_mod.contains(getUUIDFromPlayer(tracker))) {
sendForPlayer(
new EmotePacket.Builder().configureToSendHasMod(getUUIDFromPlayer(tracked)).build().data,
tracked,
getUUIDFromPlayer(tracker)
);
}
}

@Override
Expand Down
Loading