Skip to content

Commit

Permalink
Screw libs in kotlin, %frozenjoin_player-position%, indicates at what…
Browse files Browse the repository at this point in the history
… position the player joined the server (persistent), sounds fix
  • Loading branch information
Frcsty committed Sep 2, 2020
1 parent 0e5a232 commit cc10024
Show file tree
Hide file tree
Showing 56 changed files with 986 additions and 150 deletions.
20 changes: 8 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ plugins {
}

group = "com.github.frcsty"
version = "2.1.2"
version = "2.1.3"

def path = "com.github.frcsty.frozenjoin"
def version = JavaVersion.VERSION_1_8
def javaVersion = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
Expand All @@ -19,15 +19,9 @@ repositories {
}

dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:5.6.2"
testImplementation "io.kotest:kotest-runner-junit5-jvm:4.0.6"
testImplementation "io.kotest:kotest-assertions-core-jvm:4.0.6"
implementation "me.mattstudios.utils:matt-framework:1.4"
implementation "org.bstats:bstats-bukkit:1.7"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
implementation("com.github.frcsty:FrozenActions:1.0.0") {
exclude group: "com.github.frcsty.libs.kotlin"
}
compileOnly "net.luckperms:api:5.1"
compileOnly "com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT"
compileOnly "me.clip:placeholderapi:2.10.6"
Expand All @@ -41,13 +35,15 @@ processResources {

shadowJar {
relocate "org.bstats", "${path}.bstats"
relocate "me.mattstudios.utils", "${path}.utils"
relocate "me.mattstudios.mf", "${path}.mf-utils"
relocate "kotlin", "${path}.kotlin"

archiveFileName.set("${project.name}-${version}.jar")
}

sourceCompatibility = version
targetCompatibility = version
sourceCompatibility = javaVersion
targetCompatibility = javaVersion

compileKotlin {
kotlinOptions.jvmTarget = version
kotlinOptions.jvmTarget = javaVersion
}
21 changes: 0 additions & 21 deletions src/main/java/com/github/frcsty/Handler.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.frcsty.frozenjoin
package com.github.frcsty

import com.github.frcsty.frozenjoin.load.Loader
import com.github.frcsty.load.Loader
import org.bukkit.plugin.java.JavaPlugin

class FrozenJoinPlugin : JavaPlugin() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.frcsty.frozenjoin.command

import com.github.frcsty.frozenjoin.FrozenJoinPlugin
import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.convert.FileConverter
import com.github.frcsty.frozenjoin.load.Settings
import com.github.frcsty.frozenjoin.load.logInfo
import com.github.frcsty.frozenjoin.util.replacePlaceholder
package com.github.frcsty.command

import com.github.frcsty.FrozenJoinPlugin
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.convert.FileConverter
import com.github.frcsty.load.Settings
import com.github.frcsty.load.logInfo
import com.github.frcsty.util.replacePlaceholder
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Permission
import me.mattstudios.mf.annotations.SubCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.frcsty.frozenjoin.command
package com.github.frcsty.command

import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.util.*
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.util.*
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Permission
import me.mattstudios.mf.annotations.SubCommand
Expand Down Expand Up @@ -34,8 +34,7 @@ class FormatCommand(private val messageLoader: MessageLoader) : CommandBase() {
when (argument) {
JOIN_COMMAND,
QUIT_COMMAND -> {
player.setCustomMessage(JOIN_COMMAND, message = msg)
player.setCustomMessage(QUIT_COMMAND, message = msg)
player.setCustomMessage(argument, message = msg)
}
else -> {
sender.sendMessage(messageLoader.getMessage("customMessageInvalidArgumentMessage"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.frcsty.frozenjoin.command
package com.github.frcsty.command

import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.util.color
import com.github.frcsty.frozenjoin.util.replacePlaceholder
import com.github.frcsty.frozenjoin.load.Settings
import com.github.frcsty.frozenjoin.load.logInfo
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.load.Settings
import com.github.frcsty.load.logInfo
import com.github.frcsty.util.color
import com.github.frcsty.util.replacePlaceholder
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Permission
import me.mattstudios.mf.annotations.SubCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.frcsty.frozenjoin.command
package com.github.frcsty.command

import com.github.frcsty.frozenjoin.FrozenJoinPlugin
import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.load.Settings
import com.github.frcsty.frozenjoin.load.logInfo
import com.github.frcsty.frozenjoin.util.color
import com.github.frcsty.frozenjoin.util.replacePlaceholder
import com.github.frcsty.FrozenJoinPlugin
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.load.Settings
import com.github.frcsty.load.logInfo
import com.github.frcsty.util.color
import com.github.frcsty.util.replacePlaceholder
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Default
import me.mattstudios.mf.annotations.Permission
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.frcsty.frozenjoin.command
package com.github.frcsty.command

import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.load.Loader
import com.github.frcsty.frozenjoin.message.MessageFormatter
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.load.Loader
import com.github.frcsty.message.MessageFormatter
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Default
import me.mattstudios.mf.annotations.Permission
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.frcsty.frozenjoin.command

import com.github.frcsty.frozenjoin.FrozenJoinPlugin
import com.github.frcsty.frozenjoin.configuration.MessageLoader
import com.github.frcsty.frozenjoin.util.color
import com.github.frcsty.frozenjoin.load.Loader
import com.github.frcsty.frozenjoin.load.Settings
import com.github.frcsty.frozenjoin.load.logInfo
package com.github.frcsty.command

import com.github.frcsty.FrozenJoinPlugin
import com.github.frcsty.configuration.MessageLoader
import com.github.frcsty.load.Loader
import com.github.frcsty.load.Settings
import com.github.frcsty.load.logInfo
import com.github.frcsty.util.color
import me.mattstudios.mf.annotations.Command
import me.mattstudios.mf.annotations.Permission
import me.mattstudios.mf.annotations.SubCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.frcsty.frozenjoin.configuration
package com.github.frcsty.configuration

import com.github.frcsty.frozenjoin.FrozenJoinPlugin
import com.github.frcsty.frozenjoin.util.color
import com.github.frcsty.FrozenJoinPlugin
import com.github.frcsty.util.color
import org.bukkit.configuration.ConfigurationSection

class MessageLoader(private val plugin: FrozenJoinPlugin) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.frcsty.frozenjoin.convert
package com.github.frcsty.convert

import com.github.frcsty.frozenjoin.load.Settings
import com.github.frcsty.load.Settings
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
import java.util.logging.Level
Expand Down
112 changes: 112 additions & 0 deletions src/main/kotlin/com/github/frcsty/library/ActionHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.github.frcsty.library

import com.github.frcsty.library.actions.Action
import com.github.frcsty.library.actions.broadcast.*
import com.github.frcsty.library.actions.player.*
import com.github.frcsty.library.time.parseTime
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin
import java.util.*
import java.util.concurrent.TimeUnit

private val ACTION_PATTERN = Regex("(.*) ?\\[(?<action>[A-Z]+?)] ?(?<arguments>.+)", RegexOption.IGNORE_CASE)
private val DELAY_PATTERN = Regex("\\[DELAY=(?<delay>\\d+[a-z])]", RegexOption.IGNORE_CASE)
private val CHANCE_PATTERN = Regex("\\[CHANCE=(?<chance>\\d+)]", RegexOption.IGNORE_CASE)
private val RANDOM = SplittableRandom()

class ActionHandler(private val plugin: Plugin) {

val actions = mutableMapOf<String, Action>()

fun loadDefault() {
setOf(
ActionbarBroadcastAction,
ActionbarMessageAction,
BroadcastAction,
BungeeAction,
CenterBroadcastAction,
CenterMessageAction,
ConsoleCommandAction,
EquipItemAction,
JsonBroadcastAction,
JsonMessageAction,
MessageAction,
PlayerCommandAction,
SoundAction,
SoundBroadcastAction,
TeleportAction,
TitleBroadcastAction,
TitleMessageAction
).forEach { this.actions[it.id] = it }
}

fun setAction(identifier: String, action: Action) {
this.actions[identifier] = action
}

fun execute(player: Player, input: List<String>) {
input.forEach { execute(player, it) }
}

private fun execute(player: Player, input: String) {
val actionHolder = getDelayAction(hasChanceAction(input) ?: return)
val inputAction = actionHolder.action
val match = ACTION_PATTERN.matchEntire(inputAction)

if (match == null) {
println("Action does not match regex $inputAction")
return
}

val arguments = match.groups["arguments"]?.value ?: return
val delay = actionHolder.delay

val actionName = match.groups["action"]?.value?.toUpperCase()

val action = actions[actionName] ?: return

Bukkit.getScheduler().runTaskLater(
plugin,
Runnable {
action.run(player, arguments)
action.run(plugin, player, arguments)
},
delay
)
}

private fun hasChanceAction(input: String): String? {
val match = CHANCE_PATTERN.matchEntire(input) ?: return input
val chanceGroup = match.groups["chance"] ?: return null
val chance = chanceGroup.value.toInt()

val randomValue = RANDOM.nextInt(100) + 1

return if (randomValue <= chance) {
input.replace(chanceGroup.value, "")
} else null
}

private fun getDelayAction(input: String): ActionHolder {
val match = DELAY_PATTERN.matchEntire(input) ?: return ActionHolder(input, 0L)

val delayGroup = match.groups["delay"] ?: return ActionHolder(input, 0L)
val delay = delayGroup.value

return try {
val time = delay.parseTime()
ActionHolder(
action = input.replace(delayGroup.value, ""),
delay = time.to(TimeUnit.SECONDS) * 20L
)
} catch (ex: IllegalArgumentException) {
ex.printStackTrace()
ActionHolder(input, 0L)
}
}

init {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord")
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/com/github/frcsty/library/ActionHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.frcsty.library

class ActionHolder(
val action: String,
val delay: Long
)
10 changes: 10 additions & 0 deletions src/main/kotlin/com/github/frcsty/library/actions/Action.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.frcsty.library.actions

import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin

interface Action {
val id: String
fun run(player: Player, data: String) {}
fun run(plugin: Plugin, player: Player, data: String) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.frcsty.library.actions.broadcast

import com.github.frcsty.library.actions.Action
import com.github.frcsty.library.util.getTranslatedMessage
import com.github.frcsty.library.util.sendActionBarMessage
import org.bukkit.Bukkit
import org.bukkit.entity.Player

object ActionbarBroadcastAction : Action {
override val id = "ACTIONBARBROADCAST"

override fun run(player: Player, data: String) {
Bukkit.getServer().onlinePlayers.forEach { it.sendActionBarMessage(data.getTranslatedMessage(player)) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.frcsty.library.actions.broadcast

import com.github.frcsty.library.actions.Action
import com.github.frcsty.library.util.sendTranslatedMessage
import org.bukkit.Bukkit
import org.bukkit.entity.Player

object BroadcastAction : Action {
override val id = "BROADCAST"

override fun run(player: Player, data: String) = Bukkit.getServer().onlinePlayers.forEach {
it.sendTranslatedMessage(data, player)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.frcsty.library.actions.broadcast

import com.github.frcsty.library.actions.Action
import com.github.frcsty.library.actions.player.CenterMessageAction
import com.github.frcsty.library.util.getTranslatedMessage
import org.bukkit.Bukkit
import org.bukkit.entity.Player

object CenterBroadcastAction : Action {

override val id = "CENTERBROADCAST"

override fun run(player: Player, data: String) {
Bukkit.getServer().onlinePlayers.forEach { CenterMessageAction.run(it, data.getTranslatedMessage(player)) }
}
}
Loading

0 comments on commit cc10024

Please sign in to comment.