Skip to content

Commit

Permalink
Client emote stop events
Browse files Browse the repository at this point in the history
  • Loading branch information
KosmX committed Oct 8, 2022
1 parent 19c9491 commit 0dd732d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,46 @@ public interface EmotePlayEvent {
void onEmotePlay(KeyframeAnimation emoteData, UUID userID);
}

/**
* A player is stopping the played emote by command
* <p>
* NOTE: Emote ending won't trigger any events
*/
public static final Event<EmoteStopEvent> EMOTE_STOP = new Event<>(EmoteStopEvent.class, listeners -> (emote, userID) -> {
for (EmoteStopEvent listener : listeners) {
listener.onEmoteStop(emote, userID);
}
});


@FunctionalInterface
public interface EmoteStopEvent {

/**
* Used to create emote stop side effects
* @param userID User ID
*/
void onEmoteStop(UUID emoteID, UUID userID);
}


/**
* The client player is stopping its own emote
* It will trigger only if the command is from the client
*/
public static final Event<LocalEmoteStopEvent> LOCAL_EMOTE_STOP = new Event<>(LocalEmoteStopEvent.class, listeners -> () -> {
for (LocalEmoteStopEvent listener : listeners) {
listener.onEmoteStop();
}
});


@FunctionalInterface
public interface LocalEmoteStopEvent {

/**
* Used to create emote stop side effects
*/
void onEmoteStop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static boolean clientStopLocalEmote(KeyframeAnimation emoteData) {
packetBuilder.configureToSendStop(emoteData.getUuid(), EmoteInstance.instance.getClientMethods().getMainPlayer().emotes_getUUID());
ClientPacketManager.send(packetBuilder, null);
EmoteInstance.instance.getClientMethods().getMainPlayer().stopEmote();

ClientEmoteEvents.LOCAL_EMOTE_STOP.invoker().onEmoteStop();
return true;
}
return false;
Expand All @@ -96,6 +98,7 @@ static void executeMessage(NetData data, INetworkInstance networkInstance) throw
IEmotePlayerEntity player = EmoteInstance.instance.getGetters().getPlayerFromUUID(data.player);
assert data.stopEmoteID != null;
if(player != null) {
ClientEmoteEvents.EMOTE_STOP.invoker().onEmoteStop(data.stopEmoteID, player.emotes_getUUID());
player.stopEmote(data.stopEmoteID);
if(player.isMainPlayer() && !data.isForced){
EmoteInstance.instance.getClientMethods().sendChatMessage(EmoteInstance.instance.getDefaults().newTranslationText("emotecraft.blockedEmote"));
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs = -Xmx4G
#See copy-paste
mod_description = Play emotes in Minecraft\\nOpen the menu to setup your fast-choose wheel\\n\\nYou can add custom emotes, and you can play these even if nobody else has them\\n\\nSpecial thanks:\\nKale Ko for creating emotes and help in the UI design\\nOrsond for inspiring me and providing CollarMC\\nArchitectury for the Forge build tools
#Mod properties
version_base = 2.2.5
version_base = 2.2.6
maven_group = io.github.kosmx.emotes
archives_base_name = emotecraft
#Most of this project is compiled against Java8. but it can be overwritten
Expand Down

0 comments on commit 0dd732d

Please sign in to comment.