Skip to content
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

Merge changes to master --release #32

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MCTennis is a spigot plugin to play Tennis games in Minecraft.

* Playable Tennis Minigame
* A moving TennisBall without any resource packs
* Version support 1.8.R3 - 1.20.R4
* Version support 1.8.R3 - 1.21.R1
* Check out the [MCTennis-Spigot-Page](https://www.spigotmc.org/resources/12056/) to get more information.

## Installation
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.github.shynixn"
version = "1.5.0"
version = "1.6.0"

repositories {
mavenCentral()
Expand All @@ -29,18 +29,18 @@ dependencies {
compileOnly("org.geysermc.geyser:api:2.2.0-SNAPSHOT")

// Plugin.yml Shade dependencies
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.15.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.15.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.17.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.17.0")
implementation("com.google.inject:guice:5.0.1")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.3.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.2.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
implementation("com.google.code.gson:gson:2.8.6")

// Custom dependencies
implementation("com.github.shynixn.mcutils:common:2024.1")
implementation("com.github.shynixn.mcutils:common:2024.19")
implementation("com.github.shynixn.mcutils:guice:2024.2")
implementation("com.github.shynixn.mcutils:packet:2024.5")
implementation("com.github.shynixn.mcutils:packet:2024.30")
implementation("com.github.shynixn.mcutils:sign:2024.2")

// Test
Expand Down
12 changes: 6 additions & 6 deletions docs/wiki/docs/permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ The following permissions are available in MCTennis.
* User: A permission all players can have.
* Admin: A permission only admins should have.

| Permission | Level | Description |
|------------------------|-------|------------------------------------------|
| mctennis.command | User | Allows to use the /mctennis command. |
| mctennis.join.* | User | Allows to join all games |
| mctennis.join.\<name\> | User | Allows to join a specific game |
| mctennis.edit | Admin | Allows to create, edit and delete games. |
| Permission | Level | Description |
|----------------------|-------|------------------------------------------|
| mctennis.command | User | Allows to use the /mctennis command. |
| mctennis.join.* | User | Allows to join all games |
| mctennis.join.[name] | User | Allows to join a specific game |
| mctennis.edit | Admin | Allows to create, edit and delete games. |
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.shynixn.mctennis

import com.fasterxml.jackson.core.type.TypeReference
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mctennis.contract.BedrockService
import com.github.shynixn.mctennis.contract.GameService
import com.github.shynixn.mctennis.contract.PlaceHolderService
Expand All @@ -10,6 +11,7 @@ import com.github.shynixn.mctennis.enumeration.PluginDependency
import com.github.shynixn.mctennis.impl.service.*
import com.github.shynixn.mcutils.common.ConfigurationService
import com.github.shynixn.mcutils.common.ConfigurationServiceImpl
import com.github.shynixn.mcutils.common.CoroutineExecutor
import com.github.shynixn.mcutils.common.chat.ChatMessageService
import com.github.shynixn.mcutils.common.command.CommandService
import com.github.shynixn.mcutils.common.command.CommandServiceImpl
Expand All @@ -25,15 +27,13 @@ import com.github.shynixn.mcutils.common.repository.YamlFileRepositoryImpl
import com.github.shynixn.mcutils.common.sound.SoundService
import com.github.shynixn.mcutils.common.sound.SoundServiceImpl
import com.github.shynixn.mcutils.guice.DependencyInjectionModule
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.github.shynixn.mcutils.packet.impl.service.*
import com.github.shynixn.mcutils.sign.SignService
import com.github.shynixn.mcutils.sign.SignServiceImpl
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.util.concurrent.Executor
import java.util.logging.Level

class MCTennisDependencyInjectionModule(private val plugin: Plugin) : DependencyInjectionModule() {
Expand Down Expand Up @@ -72,15 +72,19 @@ class MCTennisDependencyInjectionModule(private val plugin: Plugin) : Dependency
addService<PhysicObjectService> {
PhysicObjectServiceImpl(plugin, getService())
}
addService<CommandService>(CommandServiceImpl(plugin))
addService<CommandService>(CommandServiceImpl(object : CoroutineExecutor {
override fun execute(f: suspend () -> Unit) {
plugin.launch {
f.invoke()
}
}
}))
addService<ChatMessageService>(ChatMessageServiceImpl(plugin))
addService<PhysicObjectDispatcher>(PhysicObjectDispatcherImpl(plugin))
addService<ConfigurationService>(ConfigurationServiceImpl(plugin))
addService<SoundService>(SoundServiceImpl(plugin))
addService<PacketService>(PacketServiceImpl(plugin
) { command -> plugin.server.scheduler.runTask(plugin, command) })
addService<PacketService>(PacketServiceImpl(plugin))
addService<ItemService>(ItemServiceImpl())
addService<EntityService, EntityServiceImpl>()
addService<ChatMessageService, ChatMessageServiceImpl>()
addService<RayTracingService, RayTracingServiceImpl>()
addService<BedrockService, BedrockServiceImpl>()
addService<GameService, GameServiceImpl>()
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ class MCTennisPlugin : JavaPlugin() {
Version.VERSION_1_20_R1,
Version.VERSION_1_20_R2,
Version.VERSION_1_20_R3,
Version.VERSION_1_20_R4
Version.VERSION_1_20_R4,
Version.VERSION_1_21_R1
)
} else {
listOf(Version.VERSION_1_20_R4)
listOf(Version.VERSION_1_21_R1)
}

if (!Version.serverVersion.isCompatible(*versions.toTypedArray())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TennisBallSettings {
*/
var item: Item = Item().also {
it.typeName = "PLAYER_HEAD,397"
it.durability = 3
it.durability = "3"
it.skinBase64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0="
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,29 @@ class MCTennisCommandExecutor @Inject constructor(
) {
private val fallBackPrefix: String =
org.bukkit.ChatColor.BLUE.toString() + "[MCTennis] " + org.bukkit.ChatColor.WHITE
private val arenaTabs: suspend () -> List<String> = {
private val arenaTabs: suspend (s : CommandSender) -> List<String> = {
arenaRepository.getAll().map { e -> e.name }
}
private val coroutineExecutor = object : CoroutineExecutor {
override fun execute(f: suspend () -> Unit) {
plugin.launch {
f.invoke()
}
}
}

private val remainingStringValidator = object : Validator<String> {
override suspend fun transform(sender: CommandSender, prevArgs: List<Any>, openArgs: List<String>): String {
return openArgs.joinToString(" ")
}
}
private val maxLengthValidator = object : Validator<String> {
override suspend fun validate(sender: CommandSender, prevArgs: List<Any>, argument: String): Boolean {
override suspend fun validate(
sender: CommandSender,
prevArgs: List<Any>,
argument: String,
openArgs: List<String>
): Boolean {
return argument.length < 20
}

Expand All @@ -56,7 +68,12 @@ class MCTennisCommandExecutor @Inject constructor(
}
}
private val gameMustNotExistValidator = object : Validator<String> {
override suspend fun validate(sender: CommandSender, prevArgs: List<Any>, argument: String): Boolean {
override suspend fun validate(
sender: CommandSender,
prevArgs: List<Any>,
argument: String,
openArgs: List<String>
): Boolean {
val existingArenas = arenaRepository.getAll()
return existingArenas.firstOrNull { e -> e.name.equals(argument, true) } == null
}
Expand Down Expand Up @@ -132,91 +149,96 @@ class MCTennisCommandExecutor @Inject constructor(
return MCTennisLanguage.signTypeDoesNotExist
}

override suspend fun validate(sender: CommandSender, prevArgs: List<Any>, argument: String): Boolean {
override suspend fun validate(
sender: CommandSender,
prevArgs: List<Any>,
argument: String,
openArgs: List<String>
): Boolean {
return argument.equals("join", true) || argument.equals("leave", true)
}
}

init {
val mcCart = CommandBuilder(plugin, "mctennis", chatMessageService) {
val mcCart = CommandBuilder(plugin, coroutineExecutor, "mctennis", chatMessageService) {
usage(MCTennisLanguage.commandUsage.translateChatColors())
description(MCTennisLanguage.commandDescription)
aliases(plugin.config.getStringList("commands.mctennis.aliases"))
permission(Permission.COMMAND)
permissionMessage(MCTennisLanguage.noPermissionMessage.translateChatColors())
subCommand("create") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(maxLengthValidator).validator(maxLengthValidator)
builder().argument("name").validator(maxLengthValidator).validator(maxLengthValidator)
.validator(gameMustNotExistValidator).tabs { listOf("<name>") }.argument("displayName")
.validator(remainingStringValidator).tabs { listOf("<displayName>") }
.execute { sender, name, displayName -> createArena(sender, name, displayName) }
}
subCommand("delete") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.execute { sender, arena -> deleteArena(sender, arena) }
}
subCommand("list") {
permission(Permission.EDIT_GAME)
execution().execute { sender -> listArena(sender) }
builder().execute { sender -> listArena(sender) }
}
subCommand("toggle") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.execute { sender, arena -> toggleGame(sender, arena) }
}
subCommand("join") {
noPermission()
execution().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { sender, arena ->
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { sender, arena ->
joinGame(
sender, arena.name
)
}.argument("team").validator(teamValidator).tabs { listOf("red", "blue") }
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { sender, arena, team ->
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { sender, arena, team ->
joinGame(sender, arena.name, team)
}
}
subCommand("leave") {
noPermission()
execution().executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { sender -> leaveGame(sender) }
builder().executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { sender -> leaveGame(sender) }
}
helpCommand()
subCommand("location") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs { arenaTabs.invoke() }
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.argument("type").validator(locationTypeValidator).tabs { LocationType.values().map { e -> e.id } }
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { player, arena, locationType ->
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { player, arena, locationType ->
setLocation(player, arena, locationType)
}
}
subCommand("inventory") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs { arenaTabs.invoke() }
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.argument("team").validator(teamMetaValidator).tabs { listOf("red", "blue") }
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { player, arena, meta ->
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { player, arena, meta ->
setInventory(player, arena, meta)
}
}
subCommand("armor") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs { arenaTabs.invoke() }
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.argument("team").validator(teamMetaValidator).tabs { listOf("red", "blue") }
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { player, arena, meta ->
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { player, arena, meta ->
setArmor(player, arena, meta)
}
}
subCommand("sign") {
permission(Permission.EDIT_GAME)
execution().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
builder().argument("name").validator(gameMustExistValidator).tabs(arenaTabs)
.argument("type").validator(signTypeValidator).tabs { listOf("join", "leave") }
.executePlayer(MCTennisLanguage.commandSenderHasToBePlayer) { player, arena, signType ->
.executePlayer({MCTennisLanguage.commandSenderHasToBePlayer}) { player, arena, signType ->
setSign(player, arena, signType)
}
}
subCommand("reload") {
permission(Permission.EDIT_GAME)
execution()
builder()
.execute { sender ->
reloadArena(sender, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
package com.github.shynixn.mctennis.impl.listener

import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mctennis.contract.GameService
import com.github.shynixn.mctennis.contract.TennisBall
import com.github.shynixn.mcutils.common.physic.PhysicObjectService
import com.github.shynixn.mcutils.packet.api.event.PacketEvent
import com.github.shynixn.mcutils.packet.api.event.PacketAsyncEvent
import com.github.shynixn.mcutils.packet.api.meta.enumeration.InteractionType
import com.github.shynixn.mcutils.packet.api.packet.PacketInInteractEntity
import com.google.inject.Inject
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.plugin.Plugin

class PacketListener @Inject constructor(
private val physicObjectApi: PhysicObjectService,
private val gameService: GameService
private val gameService: GameService,
private val plugin: Plugin
) : Listener {
/**
* Is called when a new packet arrives.
*/
@EventHandler
fun onPacketEvent(event: PacketEvent) {
fun onPacketEvent(event: PacketAsyncEvent) {
val packet = event.packet

if (packet !is PacketInInteractEntity) {
return
}

if (packet.actionType != InteractionType.LEFT_CLICK) {
if (packet.actionType != InteractionType.ATTACK) {
return
}

val physicObject = physicObjectApi.findPhysicObjectById(packet.entityId) ?: return
plugin.launch {
val physicObject = physicObjectApi.findPhysicObjectById(packet.entityId) ?: return@launch

if (physicObject !is TennisBall) {
return
}
if (physicObject !is TennisBall) {
return@launch
}

val player = event.player
val game = gameService.getByPlayer(player) ?: return
val playerData = game.getPlayerData(player) ?: return
physicObject.shoot(event.player, playerData.currentPower)
val player = event.player
val game = gameService.getByPlayer(player) ?: return@launch
val playerData = game.getPlayerData(player) ?: return@launch
physicObject.shoot(event.player, playerData.currentPower)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.github.shynixn.mctennis.enumeration.Team
import com.github.shynixn.mctennis.event.TennisBallBounceGroundEvent
import com.github.shynixn.mcutils.common.toLocation
import com.github.shynixn.mcutils.common.toVector3d
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.meta.enumeration.EntityType
import com.github.shynixn.mcutils.packet.api.packet.PacketOutEntityDestroy
Expand All @@ -23,7 +22,6 @@ import org.bukkit.event.Listener
import org.bukkit.plugin.Plugin

class TennisListener @Inject constructor(
private val entityService: EntityService,
private val packetService: PacketService,
private val plugin: Plugin
) : Listener {
Expand Down Expand Up @@ -104,7 +102,7 @@ class TennisListener @Inject constructor(
*/
private fun printMessageAtScorePosition(game: TennisGame, ball: TennisBall, message: String) {
val location = ball.getLocation().toVector3d().addRelativeUp(-1.5).toLocation()
val entityId = entityService.createNewEntityId()
val entityId = packetService.getNextEntityId()
val players = game.getPlayers()

for (player in players) {
Expand Down
Loading
Loading