-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Screw libs in kotlin, %frozenjoin_player-position%, indicates at what…
… position the player joined the server (persistent), sounds fix
- Loading branch information
Showing
56 changed files
with
986 additions
and
150 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 was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...hub/frcsty/frozenjoin/FrozenJoinPlugin.kt → ...lin/com/github/frcsty/FrozenJoinPlugin.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
16 changes: 8 additions & 8 deletions
16
...csty/frozenjoin/command/ConvertCommand.kt → ...m/github/frcsty/command/ConvertCommand.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
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
12 changes: 6 additions & 6 deletions
12
.../frcsty/frozenjoin/command/HelpCommand.kt → .../com/github/frcsty/command/HelpCommand.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
14 changes: 7 additions & 7 deletions
14
.../frcsty/frozenjoin/command/InfoCommand.kt → .../com/github/frcsty/command/InfoCommand.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
8 changes: 4 additions & 4 deletions
8
.../frcsty/frozenjoin/command/MotdCommand.kt → .../com/github/frcsty/command/MotdCommand.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
16 changes: 8 additions & 8 deletions
16
...rcsty/frozenjoin/command/ReloadCommand.kt → ...om/github/frcsty/command/ReloadCommand.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
6 changes: 3 additions & 3 deletions
6
...frozenjoin/configuration/MessageLoader.kt → ...hub/frcsty/configuration/MessageLoader.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
4 changes: 2 additions & 2 deletions
4
...rcsty/frozenjoin/convert/FileConverter.kt → ...om/github/frcsty/convert/FileConverter.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
112 changes: 112 additions & 0 deletions
112
src/main/kotlin/com/github/frcsty/library/ActionHandler.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,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") | ||
} | ||
} |
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,6 @@ | ||
package com.github.frcsty.library | ||
|
||
class ActionHolder( | ||
val action: String, | ||
val delay: Long | ||
) |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/github/frcsty/library/actions/Action.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,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) {} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/github/frcsty/library/actions/broadcast/ActionbarBroadcastAction.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,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)) } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/github/frcsty/library/actions/broadcast/BroadcastAction.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,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) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/github/frcsty/library/actions/broadcast/CenterBroadcastAction.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 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)) } | ||
} | ||
} |
Oops, something went wrong.