-
Notifications
You must be signed in to change notification settings - Fork 0
Waypoint share #3
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| plugins { | ||
| id("java") | ||
| } | ||
|
|
||
| group = "de.nick" | ||
| version = "unspecified" | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation(platform("org.junit:junit-bom:5.10.0")) | ||
| testImplementation("org.junit.jupiter:junit-jupiter") | ||
| testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
| } | ||
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package de.nick.waypointsharesystem | ||
|
|
||
| import de.nick.waypointsharesystem.listener.ChatListener | ||
| import de.nick.waypointsharesystem.listener.InventoryClickListener | ||
| import net.derfarmer.moduleloader.modules.Module | ||
|
|
||
| object WaypointShareModule : Module() { | ||
| override fun onEnable() { | ||
| println("EV WaypointShare loading") | ||
| register(ChatListener) | ||
| register(InventoryClickListener) | ||
| println("EV WaypointShare Enabled") | ||
| } | ||
|
|
||
| override fun onDisable() { | ||
| } | ||
|
|
||
| override fun onReload() { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package de.nick.waypointsharesystem.listener | ||
|
|
||
| import de.nick.waypointsharesystem.WaypointShareModule | ||
| import de.nick.waypointsharesystem.utils.ShareInventory | ||
| import de.nick.waypointsharesystem.utils.SkullBuilder | ||
| import io.papermc.paper.event.player.AsyncChatEvent | ||
| import net.derfarmer.moduleloader.sendMSG | ||
| import net.derfarmer.playersystem.PlayerManager | ||
| import net.derfarmer.playersystem.utils.ItemBuilder | ||
| import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer | ||
| import org.bukkit.Bukkit | ||
| import org.bukkit.Material | ||
| import org.bukkit.Sound | ||
| import org.bukkit.entity.Player | ||
| import org.bukkit.event.EventHandler | ||
| import org.bukkit.event.Listener | ||
| import java.util.* | ||
|
|
||
| object ChatListener : Listener { | ||
|
|
||
| val playerWaypointMessages: HashMap<UUID, String> = HashMap() | ||
| val playerWaypointWaiting = arrayListOf<Player>() | ||
|
|
||
| @EventHandler | ||
| fun onChat(event: AsyncChatEvent) { | ||
|
|
||
| val messageComponent = event.message() | ||
| val messagesString = PlainTextComponentSerializer.plainText().serialize(messageComponent) | ||
|
|
||
| if (playerWaypointWaiting.contains(event.player)) { | ||
| playerWaypointWaiting.remove(event.player) | ||
| event.isCancelled = true | ||
|
|
||
| val targetPlayer = Bukkit.getServer().getPlayer(messagesString) | ||
|
|
||
| if (targetPlayer != null && targetPlayer.isOnline) { | ||
|
|
||
| targetPlayer.sendMSG("") | ||
| targetPlayer.sendMSG("waypointshare.send.privat.message", event.player.name) | ||
| targetPlayer.sendMSG("waypointshare.send.privat.waypointmessage", getLastWaypointMessage(event.player.uniqueId).toString()) | ||
| targetPlayer.sendMSG("") | ||
| targetPlayer.playSound(targetPlayer.location, Sound.BLOCK_NOTE_BLOCK_BASS, 10.0F, 10.0F) | ||
|
|
||
| event.player.sendMessage("§7Du hast §aerfolgreich §7den Waypoint an den Spieler §a" + targetPlayer.name + " §7geschickt") | ||
| return | ||
| } | ||
| event.player.sendMSG("waypointshare.player.notOnline", messagesString) | ||
| event.player.playSound(event.player.location, Sound.BLOCK_GLASS_BREAK, 10.0F, 10.0F) | ||
| } | ||
|
|
||
| if (!messagesString.lowercase().startsWith("xaero-waypoint:")) return | ||
|
|
||
| event.isCancelled = true | ||
|
|
||
| playerWaypointMessages[event.player.uniqueId] = messagesString | ||
|
|
||
| val sendInventory = ShareInventory().inventory | ||
|
|
||
|
|
||
| for (i in 0.. 26) { | ||
| sendInventory.setItem(i, ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).setDisplayName(" ").build()) | ||
| } | ||
|
|
||
| sendInventory.setItem(10, SkullBuilder() | ||
| .setDisplayName("§6Schicke den §e§lWaypoint §6an einen Freund") | ||
| .setSkullOwner("76cbae7246cc2c6e888587198c7959979666b4f5a4088f24e26e075f140ae6c3") | ||
| .build()) | ||
|
|
||
| sendInventory.setItem(13, SkullBuilder() | ||
| .setDisplayName("§9Schicke den §b§lWaypoint §9an alle.") | ||
| .setSkullOwner("bdde594dead88b35bc21ad1ab238dcae411253e34a585d925258ce674c642617") | ||
| .build()) | ||
|
|
||
| if (PlayerManager.getClanName(event.player).isBlank()) { | ||
| sendInventory.setItem(16, SkullBuilder() | ||
| .setDisplayName("§2Du bist leider in keinem Clan") | ||
| .setSkullOwner("4a2fe01a1f7d76f3cd6ddb53d5325a398ad748d718ae720a6bc23382867d6531") | ||
| .build()) | ||
|
|
||
|
|
||
| Bukkit.getRegionScheduler().execute(WaypointShareModule.plugin, event.player.location) { | ||
| event.player.openInventory(sendInventory) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| sendInventory.setItem(16, SkullBuilder() | ||
| .setDisplayName("§2Schicke den §a§lWaypoint §2nur an Clanmitglieder.") | ||
| .setSkullOwner("e730127542440ef0e18b4a2994fbd097e9529d59f6cedb57dbfd5fb6134a606d") | ||
| .build()) | ||
|
|
||
|
|
||
| Bukkit.getRegionScheduler().execute(WaypointShareModule.plugin, event.player.location) { | ||
| event.player.openInventory(sendInventory) | ||
| event.player.playSound(event.player.location, Sound.BLOCK_CHEST_OPEN, 10.0F, 10.0F) | ||
| } | ||
| } | ||
| fun getLastWaypointMessage(player: UUID): String? { | ||
| return playerWaypointMessages[player] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||
| package de.nick.waypointsharesystem.listener | ||||||
|
|
||||||
| import de.nick.waypointsharesystem.utils.ShareInventory | ||||||
| import net.derfarmer.moduleloader.sendMSG | ||||||
| import net.derfarmer.playersystem.PlayerManager | ||||||
| import net.derfarmer.playersystem.clan.ClanManager | ||||||
| import net.kyori.adventure.text.Component | ||||||
| import org.bukkit.Bukkit | ||||||
| import org.bukkit.Sound | ||||||
| import org.bukkit.entity.Player | ||||||
| import org.bukkit.event.EventHandler | ||||||
| import org.bukkit.event.Listener | ||||||
| import org.bukkit.event.inventory.InventoryClickEvent | ||||||
|
|
||||||
| object InventoryClickListener : Listener { | ||||||
|
|
||||||
| @EventHandler | ||||||
| fun onInventoryClick(event: InventoryClickEvent) { | ||||||
|
|
||||||
| if (event.inventory.holder !is ShareInventory) return | ||||||
|
|
||||||
| val player = event.whoClicked | ||||||
| if(player !is Player) return | ||||||
|
|
||||||
| event.isCancelled = true | ||||||
|
|
||||||
| val waypointMessage = ChatListener.getLastWaypointMessage(player.uniqueId) ?: return | ||||||
|
|
||||||
| when(event.slot) { | ||||||
| 10 -> { | ||||||
| if (ChatListener.playerWaypointWaiting.contains(player)) { | ||||||
| player.closeInventory() | ||||||
| player.sendMSG("waypointshare.type.playername.inchat") | ||||||
| player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_BASS, 10.0F, 10.0F) | ||||||
| player.closeInventory() | ||||||
| return | ||||||
| } | ||||||
| ChatListener.playerWaypointWaiting.add(player) | ||||||
| player.sendMSG("waypointshare.type.playername.inchat") | ||||||
| player.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_BASS, 10.0F, 10.0F) | ||||||
| player.closeInventory() | ||||||
| } | ||||||
| 13 -> { | ||||||
| ChatListener.playerWaypointMessages.remove(player.uniqueId) | ||||||
|
|
||||||
| Bukkit.getOnlinePlayers().forEach { onlinePlayer -> | ||||||
| onlinePlayer.sendMSG("") | ||||||
| onlinePlayer.sendMSG("waypointshare.send.global.message", player.name) | ||||||
| onlinePlayer.sendMSG("waypointshare.waypointMessage", waypointMessage) | ||||||
| onlinePlayer.sendMSG("") | ||||||
| onlinePlayer.playSound(player.location, Sound.BLOCK_NOTE_BLOCK_BASS, 10.0F, 10.0F) | ||||||
| } | ||||||
| } | ||||||
| 16 -> { | ||||||
| ChatListener.playerWaypointMessages.remove(player.uniqueId) | ||||||
| if (PlayerManager.getClanName(player).isBlank()) { | ||||||
|
|
||||||
| player.sendMSG("waypointshare.you.not.clan") | ||||||
| player.playSound(player.location, Sound.BLOCK_GLASS_BREAK, 10.0F, 10.0F) | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| val clan = PlayerManager.getClan(player) | ||||||
|
|
||||||
| if (clan != null) { | ||||||
|
|
||||||
| ClanManager.sendClanMessage(player, clan, Component.text("hat ein waypoint geteilt")) | ||||||
| ClanManager.sendClanMessage(player, clan, Component.text(waypointMessage)) | ||||||
|
|
||||||
| Bukkit.getOnlinePlayers().forEach { onlinePlayer -> | ||||||
| if (PlayerManager.getClan(onlinePlayer) == PlayerManager.getClan(player)) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't the clan of the player every time in the loop use clan var on line 64, don't use getClan from onlinePlayer use getClanName an compare that, saves time on gson parsing
Suggested change
Even better loop over clan.members get the player by uuid if not null play the sound |
||||||
| onlinePlayer.playSound(onlinePlayer.location, Sound.BLOCK_NOTE_BLOCK_BASS, 10.0F, 10.0F) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| player.closeInventory() | ||||||
|
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package de.nick.waypointsharesystem.utils | ||
|
|
||
| import net.kyori.adventure.text.Component | ||
| import org.bukkit.Bukkit | ||
| import org.bukkit.inventory.Inventory | ||
| import org.bukkit.inventory.InventoryHolder | ||
|
|
||
| class ShareInventory : InventoryHolder { | ||
| override fun getInventory(): Inventory { | ||
|
|
||
| return Bukkit.createInventory(this, 3*9, Component.text("WaypointShare")) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bitte alles außer version und group entfernen