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

Add events #36

Open
wants to merge 11 commits into
base: 1.19/dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.ftb.mods.ftbteams.FTBTeamsAPI;
import dev.ftb.mods.ftbteams.event.PlayerTransferredTeamOwnershipEvent;
import dev.ftb.mods.ftbteams.event.TeamAllyEvent;
import dev.ftb.mods.ftbteams.event.TeamEvent;
import dev.ftb.mods.ftbteams.event.*;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
Expand Down Expand Up @@ -94,6 +92,7 @@ public int invite(ServerPlayer from, Collection<GameProfile> players) throws Com
}

ranks.put(player.getId(), TeamRank.INVITED);
TeamEvent.INVITED.invoker().accept(new TeamInvitedEvent(this, players, from));
save();


Expand Down Expand Up @@ -162,6 +161,7 @@ public int promote(ServerPlayer from, Collection<GameProfile> players) throws Co
UUID id = player.getId();
if (getHighestRank(id) == TeamRank.MEMBER) {
ranks.put(id, TeamRank.OFFICER);
TeamEvent.RANK_CHANGED.invoker().accept(new TeamRankChangedEvent(this, player, TeamRank.MEMBER, TeamRank.OFFICER));
sendMessage(from.getUUID(), Component.translatable("ftbteams.message.promoted", manager.getName(id).copy().withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN));
changesMade = true;
} else {
Expand All @@ -181,6 +181,7 @@ public int demote(ServerPlayer from, Collection<GameProfile> players) throws Com
UUID id = player.getId();
if (getHighestRank(id) == TeamRank.OFFICER) {
ranks.put(id, TeamRank.MEMBER);
TeamEvent.RANK_CHANGED.invoker().accept(new TeamRankChangedEvent(this, player, TeamRank.OFFICER, TeamRank.MEMBER));
sendMessage(from.getUUID(), Component.translatable("ftbteams.message.demoted", manager.getName(id).copy().withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GOLD));
changesMade = true;
} else {
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftbteams/data/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public int denyInvite(CommandSourceStack source) throws CommandSyntaxException {

if (isInvited(player.getUUID()) && !isMember(player.getUUID())) {
ranks.put(player.getUUID(), TeamRank.ALLY);
TeamEvent.INVITE_DENIED.invoker().accept(new TeamInviteDeniedEvent(this, player));
source.sendSuccess(Component.translatable("ftbteams.message.declined"), true);
save();
manager.syncTeamsToAll(this);
Expand Down Expand Up @@ -254,6 +255,7 @@ public void sendMessage(UUID from, Component text) {
new SendMessageResponseMessage(from, text).sendTo(p);
}

TeamEvent.MESSAGE_SENT.invoker().accept(new TeamMessageSentEvent(this, text, from));
save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class TeamEvent {
public static final Event<Consumer<TeamInfoEvent>> INFO = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamAllyEvent>> ADD_ALLY = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamAllyEvent>> REMOVE_ALLY = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamMessageSentEvent>> MESSAGE_SENT = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamRankChangedEvent>> RANK_CHANGED = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamInvitedEvent>> INVITED = EventFactory.createConsumerLoop();
public static final Event<Consumer<TeamInviteDeniedEvent>> INVITE_DENIED = EventFactory.createConsumerLoop();

public static final Event<Consumer<ClientTeamPropertiesChangedEvent>> CLIENT_PROPERTIES_CHANGED = EventFactory.createConsumerLoop(ClientTeamPropertiesChangedEvent.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.ftb.mods.ftbteams.event;

import dev.ftb.mods.ftbteams.data.Team;
import net.minecraft.server.level.ServerPlayer;

public class TeamInviteDeniedEvent extends TeamEvent {
private final ServerPlayer player;

public TeamInviteDeniedEvent(Team team, ServerPlayer player) {
super(team);
this.player = player;
}

public ServerPlayer getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.ftb.mods.ftbteams.event;

import com.mojang.authlib.GameProfile;
import dev.ftb.mods.ftbteams.data.Team;
import net.minecraft.server.level.ServerPlayer;

import java.util.Collection;

public class TeamInvitedEvent extends TeamEvent {
private final Collection<GameProfile> invited;
private final ServerPlayer inviter;

public TeamInvitedEvent(Team team, Collection<GameProfile> invited, ServerPlayer inviter) {
super(team);
this.invited = invited;
this.inviter = inviter;
}

public Collection<GameProfile> getInvited() {
return invited;
}

public ServerPlayer getInviter() {
return inviter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.ftb.mods.ftbteams.event;

import dev.ftb.mods.ftbteams.data.Team;
import net.minecraft.network.chat.Component;

import java.util.UUID;

public class TeamMessageSentEvent extends TeamEvent {
private final Component message;
private final UUID from;

public TeamMessageSentEvent(Team team, Component message, UUID from) {
super(team);
this.message = message;
this.from = from;
}

public Component getMessage() {
return message;
}

public UUID getFrom() {
return from;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.ftb.mods.ftbteams.event;

import com.mojang.authlib.GameProfile;
import dev.ftb.mods.ftbteams.data.Team;
import dev.ftb.mods.ftbteams.data.TeamRank;

public class TeamRankChangedEvent extends TeamEvent {
private final GameProfile player;
private final TeamRank oldRank;
private final TeamRank newRank;

public TeamRankChangedEvent(Team team, GameProfile player, TeamRank oldRank, TeamRank newRank) {
super(team);
this.player = player;
this.oldRank = oldRank;
this.newRank = newRank;
}

public GameProfile getPlayer() {
return player;
}

public TeamRank getOldRank() {
return oldRank;
}

public TeamRank getNewRank() {
return newRank;
}
}