-
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.
* feat: afk and onlinetime * feat: custom chat * feat: remove useless perms
- Loading branch information
1 parent
04722ff
commit 8c12653
Showing
13 changed files
with
242 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.blockventuremc.consts | ||
|
||
import kotlin.time.Duration.Companion.seconds | ||
|
||
val AFK_DURATION = 15.seconds |
This file was deleted.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/net/blockventuremc/modules/general/events/ActivityEvents.kt
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,58 @@ | ||
package net.blockventuremc.modules.general.events | ||
|
||
import org.bukkit.Location | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerCommandPreprocessEvent | ||
import org.bukkit.event.player.PlayerInteractEvent | ||
import org.bukkit.event.player.PlayerMoveEvent | ||
import org.bukkit.event.player.PlayerTeleportEvent | ||
import io.papermc.paper.event.player.AsyncChatEvent | ||
import net.blockventuremc.extensions.toDatabaseUser | ||
import net.blockventuremc.modules.general.events.custom.AFKChangeEvent | ||
|
||
class ActivityEvents: Listener { | ||
|
||
private fun handleMovement(from: Location, to: Location, player: Player) { | ||
if (from.blockX != to.blockX || from.blockZ != to.blockZ) { | ||
player.toDatabaseUser().addActivity(AFKChangeEvent.Cause.MOVE) | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun onMove(event: PlayerMoveEvent) { | ||
val player = event.player | ||
val from = event.from | ||
val to = event.to | ||
handleMovement(from, to, player) | ||
} | ||
|
||
|
||
@EventHandler | ||
fun onTeleportIntoArea(event: PlayerTeleportEvent) { | ||
val player = event.player | ||
val from = event.from | ||
val to = event.to | ||
handleMovement(from, to, player) | ||
} | ||
|
||
@EventHandler | ||
fun onChat(event: AsyncChatEvent) { | ||
val player = event.player | ||
player.toDatabaseUser().addActivity(AFKChangeEvent.Cause.CHAT) | ||
} | ||
|
||
@EventHandler | ||
fun onCommand(event: PlayerCommandPreprocessEvent) { | ||
val player = event.player | ||
player.toDatabaseUser().addActivity(AFKChangeEvent.Cause.CHAT) | ||
} | ||
|
||
@EventHandler | ||
fun onInteract(event: PlayerInteractEvent) { | ||
val player = event.player | ||
player.toDatabaseUser().addActivity(AFKChangeEvent.Cause.INTERACT) | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/net/blockventuremc/modules/general/events/ChatEvent.kt
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.blockventuremc.modules.general.events | ||
|
||
import dev.fruxz.stacked.extension.asPlainString | ||
import dev.fruxz.stacked.text | ||
import io.papermc.paper.event.player.AsyncChatEvent | ||
import me.clip.placeholderapi.PlaceholderAPI | ||
import net.blockventuremc.extensions.toDatabaseUser | ||
import org.bukkit.Bukkit | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
|
||
class ChatEvent: Listener { | ||
|
||
private val chatFormat = "<color:%color%>%rank% <color:#3d3d3d>»</color> <color:#c8d6e5>%playername%</color> <color:#f6e58d>" | ||
|
||
private val urlRegex = | ||
Regex("http[s]?:\\/\\/(?:[a-zA-Z]|[0-9]|[\$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") | ||
|
||
@EventHandler | ||
fun onChat(event: AsyncChatEvent): Unit = with(event) { | ||
val player = player | ||
|
||
val placeHolderText = chatFormat | ||
val messagePlain = message().asPlainString | ||
|
||
val format = | ||
text(parsePlaceholders(placeHolderText, player)).append(text(parsePlaceholders(messagePlain, player))) | ||
|
||
event.renderer { _, _, _, _ -> | ||
return@renderer format | ||
} | ||
} | ||
|
||
private fun parsePlaceholders(text: String, player: Player): String { | ||
var parsed = text | ||
parsed = parsed.replace("%playername%", player.name) | ||
parsed = parsed.replace("%displayname%", player.displayName().asPlainString) | ||
parsed = parsed.replace("%color%", player.toDatabaseUser().rank.color) | ||
parsed = parsed.replace("%rank%", player.toDatabaseUser().rank.name) | ||
|
||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { | ||
parsed = PlaceholderAPI.setPlaceholders(player, parsed) | ||
} | ||
|
||
val plainText = text(parsed).asPlainString | ||
|
||
// Test for link and replace it with a clickable link | ||
for (match in urlRegex.findAll(plainText)) { | ||
val url = match.value | ||
val urlText = "<color:#7593ff><click:open_url:'$url'>$url</click></color>" | ||
parsed = parsed.replace(url, urlText) | ||
} | ||
return parsed | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/net/blockventuremc/modules/general/events/custom/AFKChangeEvent.kt
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,27 @@ | ||
package net.blockventuremc.modules.general.events.custom | ||
|
||
import org.bukkit.event.HandlerList | ||
|
||
class AFKChangeEvent(var afk: Boolean, val cause: Cause) : BooleanStatusChangedEvent(afk) { | ||
|
||
companion object { | ||
private val handlerList = HandlerList() | ||
|
||
fun getHandlerList(): HandlerList { | ||
return handlerList | ||
} | ||
} | ||
|
||
override fun getHandlers(): HandlerList { | ||
return handlerList | ||
} | ||
|
||
|
||
enum class Cause { | ||
NO_ACTIVITY, | ||
MOVE, | ||
CHAT, | ||
INTERACT, | ||
UNKNOWN | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/net/blockventuremc/modules/general/events/custom/BooleanChangeEvent.kt
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,16 @@ | ||
package net.blockventuremc.modules.general.events.custom | ||
|
||
import org.bukkit.event.Cancellable | ||
import org.bukkit.event.Event | ||
|
||
abstract class BooleanStatusChangedEvent(var newValue: Boolean) : Event(), Cancellable { | ||
private var cancelled = false | ||
|
||
override fun isCancelled(): Boolean { | ||
return cancelled | ||
} | ||
|
||
override fun setCancelled(cancel: Boolean) { | ||
cancelled = cancel | ||
} | ||
} |