-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
254 additions
and
2 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
63 changes: 63 additions & 0 deletions
63
src/main/java/net/arvandor/whisperingthreshold/discord/EmbedBuilders.java
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,63 @@ | ||
package net.arvandor.whisperingthreshold.discord; | ||
|
||
import net.dv8tion.jda.api.EmbedBuilder; | ||
|
||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public final class EmbedBuilders { | ||
|
||
private EmbedBuilders() {} | ||
|
||
public static void addItemAttributes(EmbedBuilder embedBuilder, String slot, ItemStack item) { | ||
embedBuilder.addField("Item details", slot, false); | ||
if (item != null) { | ||
embedBuilder.addField("Item", item.getType().toString(), false); | ||
embedBuilder.addField("Amount", Integer.toString(item.getAmount()), false); | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
if (meta.hasDisplayName()) { | ||
embedBuilder.addField("Display name", meta.getDisplayName(), false); | ||
} | ||
if (meta.hasLore()) { | ||
embedBuilder.addField("Lore", String.join("\n", meta.getLore()), false); | ||
} | ||
Map<String, Object> serializedMeta = meta.serialize(); | ||
if (serializedMeta.containsKey("PublicBukkitValues")) { | ||
Map<String, Object> serializedPersistentDataContainer = | ||
(Map<String, Object>) serializedMeta.get("PublicBukkitValues"); | ||
serializedPersistentDataContainer.forEach( | ||
(key, value) -> { | ||
embedBuilder.addField( | ||
"Persistent data container: " + key, | ||
toString(value), | ||
false); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static String toString(Object value) { | ||
if (value instanceof Map) { | ||
return ((Map<String, Object>) value) | ||
.entrySet().stream() | ||
.map(entry -> entry.getKey() + ": " + toString(entry.getValue())) | ||
.collect(Collectors.joining(", ")); | ||
} else if (value instanceof List) { | ||
return ((List<Object>) value) | ||
.stream().map(EmbedBuilders::toString).collect(Collectors.joining(", ")); | ||
} else if (value instanceof Object[]) { | ||
return Arrays.stream((Object[]) value) | ||
.map(EmbedBuilders::toString) | ||
.collect(Collectors.joining(", ")); | ||
} else { | ||
return value.toString(); | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/net/arvandor/whisperingthreshold/listener/GameModeChangeListener.java
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 net.arvandor.whisperingthreshold.listener; | ||
|
||
import net.arvandor.whisperingthreshold.discord.WtDiscordService; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerGameModeChangeEvent; | ||
|
||
import java.awt.Color; | ||
|
||
public class GameModeChangeListener implements Listener { | ||
|
||
private final WtDiscordService discordService; | ||
|
||
public GameModeChangeListener(WtDiscordService discordService) { | ||
this.discordService = discordService; | ||
} | ||
|
||
@EventHandler | ||
public void onGameModeChange(PlayerGameModeChangeEvent event) { | ||
EmbedBuilder embedBuilder = new EmbedBuilder(); | ||
embedBuilder.setTitle("Game mode change"); | ||
embedBuilder.setColor(Color.MAGENTA); | ||
embedBuilder.addField("Player", event.getPlayer().getName(), false); | ||
embedBuilder.addField("Old game mode", event.getPlayer().getGameMode().toString(), false); | ||
embedBuilder.addField("New game mode", event.getNewGameMode().toString(), false); | ||
MessageEmbed embed = embedBuilder.build(); | ||
|
||
discordService.sendActionLogMessage(embed); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/net/arvandor/whisperingthreshold/listener/InventoryCreativeListener.java
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,56 @@ | ||
package net.arvandor.whisperingthreshold.listener; | ||
|
||
import net.arvandor.whisperingthreshold.discord.EmbedBuilders; | ||
import net.arvandor.whisperingthreshold.discord.WtDiscordService; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryCreativeEvent; | ||
|
||
import java.awt.Color; | ||
import java.util.stream.Collectors; | ||
|
||
public class InventoryCreativeListener implements Listener { | ||
|
||
private final WtDiscordService discordService; | ||
|
||
public InventoryCreativeListener(WtDiscordService discordService) { | ||
this.discordService = discordService; | ||
} | ||
|
||
@EventHandler | ||
public void onInventoryCreative(InventoryCreativeEvent event) { | ||
EmbedBuilder embedBuilder = new EmbedBuilder(); | ||
embedBuilder.setTitle("Creative inventory action"); | ||
embedBuilder.setColor(Color.YELLOW); | ||
embedBuilder.addField("Player", event.getWhoClicked().getName(), false); | ||
embedBuilder.addField( | ||
"Clicked slot", event.getSlot() + " (" + event.getSlotType() + ")", false); | ||
embedBuilder.addBlankField(false); | ||
EmbedBuilders.addItemAttributes(embedBuilder, "Cursor item", event.getCursor()); | ||
embedBuilder.addBlankField(false); | ||
EmbedBuilders.addItemAttributes(embedBuilder, "Clicked item", event.getCurrentItem()); | ||
embedBuilder.addBlankField(false); | ||
embedBuilder.addField("World", event.getWhoClicked().getWorld().getName(), false); | ||
embedBuilder.addField( | ||
"X", String.valueOf(event.getWhoClicked().getLocation().getBlockX()), true); | ||
embedBuilder.addField( | ||
"Y", String.valueOf(event.getWhoClicked().getLocation().getBlockY()), true); | ||
embedBuilder.addField( | ||
"Z", String.valueOf(event.getWhoClicked().getLocation().getBlockZ()), true); | ||
embedBuilder.addField( | ||
"Nearby players (within 32 blocks)", | ||
event.getWhoClicked().getNearbyEntities(32, 32, 32).stream() | ||
.filter(entity -> entity instanceof Player) | ||
.map(Entity::getName) | ||
.collect(Collectors.joining(", ")), | ||
false); | ||
MessageEmbed embed = embedBuilder.build(); | ||
|
||
discordService.sendActionLogMessage(embed); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/arvandor/whisperingthreshold/listener/PlayerDropItemListener.java
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,34 @@ | ||
package net.arvandor.whisperingthreshold.listener; | ||
|
||
import static net.arvandor.whisperingthreshold.discord.EmbedBuilders.addItemAttributes; | ||
|
||
import net.arvandor.whisperingthreshold.discord.WtDiscordService; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerDropItemEvent; | ||
|
||
import java.awt.Color; | ||
|
||
public class PlayerDropItemListener implements Listener { | ||
|
||
private final WtDiscordService discordService; | ||
|
||
public PlayerDropItemListener(WtDiscordService discordService) { | ||
this.discordService = discordService; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerDropItem(PlayerDropItemEvent event) { | ||
EmbedBuilder embedBuilder = new EmbedBuilder(); | ||
embedBuilder.setTitle("Item dropped"); | ||
embedBuilder.setColor(Color.BLUE); | ||
embedBuilder.addField("Player", event.getPlayer().getName(), false); | ||
addItemAttributes(embedBuilder, "Dropped item", event.getItemDrop().getItemStack()); | ||
MessageEmbed embed = embedBuilder.build(); | ||
|
||
discordService.sendActionLogMessage(embed); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/arvandor/whisperingthreshold/listener/PlayerPickupItemListener.java
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,34 @@ | ||
package net.arvandor.whisperingthreshold.listener; | ||
|
||
import static net.arvandor.whisperingthreshold.discord.EmbedBuilders.addItemAttributes; | ||
|
||
import net.arvandor.whisperingthreshold.discord.WtDiscordService; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityPickupItemEvent; | ||
|
||
import java.awt.Color; | ||
|
||
public class PlayerPickupItemListener implements Listener { | ||
|
||
private final WtDiscordService discordService; | ||
|
||
public PlayerPickupItemListener(WtDiscordService discordService) { | ||
this.discordService = discordService; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerDropItem(EntityPickupItemEvent event) { | ||
EmbedBuilder embedBuilder = new EmbedBuilder(); | ||
embedBuilder.setTitle("Item picked up"); | ||
embedBuilder.setColor(Color.CYAN); | ||
embedBuilder.addField("Player", event.getEntity().getName(), false); | ||
addItemAttributes(embedBuilder, "Acquired item", event.getItem().getItemStack()); | ||
MessageEmbed embed = embedBuilder.build(); | ||
|
||
discordService.sendActionLogMessage(embed); | ||
} | ||
} |
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