-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification messages for different events
* Server start and stop * Discord integration start and stop * Player join, leave, death * Advancement messages
- Loading branch information
Showing
8 changed files
with
240 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package sciwhiz12.concord.msg; | ||
|
||
import net.minecraft.advancements.DisplayInfo; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.util.text.TranslationTextComponent; | ||
import net.minecraftforge.event.entity.living.LivingDeathEvent; | ||
import net.minecraftforge.event.entity.player.AdvancementEvent; | ||
import net.minecraftforge.event.entity.player.PlayerEvent; | ||
import net.minecraftforge.eventbus.api.EventPriority; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import sciwhiz12.concord.ChatBot; | ||
import sciwhiz12.concord.ConcordConfig; | ||
|
||
public class PlayerListener { | ||
private final ChatBot bot; | ||
|
||
public PlayerListener(ChatBot bot) { | ||
this.bot = bot; | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { | ||
if (event.getEntity().getEntityWorld().isRemote()) return; | ||
if (!ConcordConfig.PLAYER_JOIN) return; | ||
|
||
TranslationTextComponent text = new TranslationTextComponent("message.concord.player.join", | ||
event.getPlayer().getDisplayName()); | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), text.getString()); | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) { | ||
if (event.getEntity().getEntityWorld().isRemote()) return; | ||
if (!ConcordConfig.PLAYER_LEAVE) return; | ||
|
||
TranslationTextComponent text = new TranslationTextComponent("message.concord.player.leave", | ||
event.getPlayer().getDisplayName()); | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), text.getString()); | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
void onLivingDeath(LivingDeathEvent event) { | ||
if (event.getEntity().getEntityWorld().isRemote()) return; | ||
if (!ConcordConfig.PLAYER_DEATH) return; | ||
|
||
if (event.getEntity() instanceof ServerPlayerEntity) { | ||
ServerPlayerEntity player = (ServerPlayerEntity) event.getEntity(); | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), player.getCombatTracker().getDeathMessage().getString()); | ||
} | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
void onAdvancement(AdvancementEvent event) { | ||
if (event.getEntity().getEntityWorld().isRemote()) return; | ||
|
||
final DisplayInfo info = event.getAdvancement().getDisplay(); | ||
if (info != null && info.shouldAnnounceToChat()) { | ||
switch (info.getFrame()) { | ||
case TASK: { | ||
if (!ConcordConfig.PLAYER_ADV_TASK) return; | ||
break; | ||
} | ||
case CHALLENGE: { | ||
if (!ConcordConfig.PLAYER_ADV_CHALLENGE) return; | ||
break; | ||
} | ||
case GOAL: { | ||
if (!ConcordConfig.PLAYER_ADV_GOAL) return; | ||
break; | ||
} | ||
} | ||
TranslationTextComponent text = new TranslationTextComponent( | ||
"message.concord.player.advancement." + info.getFrame().getName(), | ||
event.getPlayer().getDisplayName(), | ||
info.getTitle(), | ||
info.getDescription()); | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), text.getString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sciwhiz12.concord.msg; | ||
|
||
import net.minecraft.util.text.TranslationTextComponent; | ||
import net.minecraftforge.eventbus.api.EventPriority; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.event.server.FMLServerStartedEvent; | ||
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; | ||
import sciwhiz12.concord.ChatBot; | ||
import sciwhiz12.concord.ConcordConfig; | ||
|
||
public class StatusListener { | ||
private final ChatBot bot; | ||
|
||
public StatusListener(ChatBot bot) { | ||
this.bot = bot; | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
void onServerStarted(FMLServerStartedEvent event) { | ||
if (!ConcordConfig.SERVER_START) return; | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), | ||
new TranslationTextComponent("message.concord.server.start").getString()); | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOW) | ||
void onServerStopping(FMLServerStoppingEvent event) { | ||
if (!ConcordConfig.SERVER_STOP) return; | ||
|
||
Messaging.sendToChannel(bot.getDiscord(), | ||
new TranslationTextComponent("message.concord.server.stop").getString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters