Skip to content

Commit

Permalink
Merge pull request #23 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master --release
  • Loading branch information
Shynixn authored Apr 21, 2024
2 parents 99cc195 + f3f7916 commit 86a3621
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 154 deletions.
13 changes: 7 additions & 6 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.3.0"
version = "1.4.0"

repositories {
mavenCentral()
Expand All @@ -29,17 +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.13.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.13.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.15.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.15.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:1.0.65")
implementation("com.github.shynixn.mcutils:packet:1.0.86")
implementation("com.github.shynixn.mcutils:common:1.0.75")
implementation("com.github.shynixn.mcutils:guice:1.0.4")
implementation("com.github.shynixn.mcutils:packet:1.0.91")
implementation("com.github.shynixn.mcutils:sign:1.0.17")

// Test
Expand Down Expand Up @@ -108,7 +109,7 @@ tasks.register("pluginJarLatest", com.github.jengelman.gradle.plugins.shadow.tas
dependsOn("relocatePluginJar")
from(zipTree(File("./build/libs/" + (tasks.getByName("relocatePluginJar") as Jar).archiveName)))
archiveName = "${baseName}-${version}-latest.${extension}"
// destinationDir = File("C:\\temp\\plugins")
destinationDir = File("C:\\temp\\plugins")

exclude("com/github/shynixn/mctennis/lib/com/github/shynixn/mcutils/packet/nms/v1_8_R3/**")
exclude("com/github/shynixn/mctennis/lib/com/github/shynixn/mcutils/packet/nms/v1_9_R2/**")
Expand Down
4 changes: 3 additions & 1 deletion docs/wiki/docs/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ game1 [My first game] [enabled]

### Changing more options

Further customization options can be found in the plugins/MCTennis/arena/<name>.yml file.
Further customization options can be found in the ``plugins/MCTennis/arena/<name>.yml`` file.

The ``arena_sample.yml`` file contains explanations for each property.

Execute the reload command to load your file changes.

Expand Down
11 changes: 9 additions & 2 deletions docs/wiki/docs/placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ The following placeholders are available in MCTennis and can also be used via Pl
| %mctennis_game_stateDisplayName% | State of the game with color codes |
| %mctennis_game_players% | Current amount of players in the game |
| %mctennis_game_maxPlayers% | Max amount of players who can join this game |
| %mctennis_ball_locationWorld% | Name of the world the ball has spawned |
| %mctennis_ball_locationX% | X coordinate location of the ball |
| %mctennis_ball_locationY% | Y coordinate location of the ball |
| %mctennis_ball_locationZ% | Z coordinate location of the ball |
| %mctennis_ball_locationYaw% | Yaw rotation of the ball |
| %mctennis_ball_locationPitch% | Pitch rotation of the ball |

| Player PlaceHolders | Description |
|---------------------|-------------------------------------------------|
| Player PlaceHolders | Description |
|----------------------------|-------------------------------------------------|
| %mctennis_player_isInGame% | true if the player is in the game, false if not |
| %mctennis_player_name% | Name of the player |

| Game and Player PlaceHolders | Description |
|----------------------------------|--------------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.github.shynixn.mcutils.common.repository.Repository
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
Expand All @@ -34,14 +35,11 @@ import com.github.shynixn.mcutils.packet.impl.service.PacketServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.RayTracingServiceImpl
import com.github.shynixn.mcutils.sign.SignService
import com.github.shynixn.mcutils.sign.SignServiceImpl
import com.google.inject.AbstractModule
import com.google.inject.Scopes
import com.google.inject.TypeLiteral
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.util.logging.Level

class MCTennisDependencyInjectionBinder(private val plugin: Plugin) : AbstractModule() {
class MCTennisDependencyInjectionModule(private val plugin: Plugin) : DependencyInjectionModule() {
companion object {
val areLegacyVersionsIncluded: Boolean by lazy {
try {
Expand All @@ -57,50 +55,44 @@ class MCTennisDependencyInjectionBinder(private val plugin: Plugin) : AbstractMo
* Configures the business logic tree.
*/
override fun configure() {
bind(Plugin::class.java).toInstance(plugin)
// Common
addService<Plugin>(plugin)

// Repositories
val tennisArenaRepository = YamlFileRepositoryImpl<TennisArena>(
plugin,
val tennisArenaRepository = YamlFileRepositoryImpl<TennisArena>(plugin,
"arena",
listOf(Pair("arena_sample.yml", "arena_sample.yml")),
listOf("arena_sample.yml"),
object : TypeReference<TennisArena>() {})
val cacheTennisArenaRepository = CachedRepositoryImpl(tennisArenaRepository)
bind(object : TypeLiteral<Repository<TennisArena>>() {}).toInstance(cacheTennisArenaRepository)
bind(object : TypeLiteral<CacheRepository<TennisArena>>() {}).toInstance(cacheTennisArenaRepository)
bind(Repository::class.java).toInstance(cacheTennisArenaRepository)
bind(CacheRepository::class.java).toInstance(cacheTennisArenaRepository)
addService<Repository<TennisArena>>(cacheTennisArenaRepository)
addService<CacheRepository<TennisArena>>(cacheTennisArenaRepository)

// Services
bind(SignService::class.java).toInstance(
SignServiceImpl(
plugin,
CommandServiceImpl(),
MCTennisLanguage.noPermissionMessage
)
)
val physicObjectDispatcher = PhysicObjectDispatcherImpl(plugin)
bind(EntityService::class.java).toInstance(EntityServiceImpl())
bind(ChatMessageService::class.java).toInstance(ChatMessageServiceImpl())
bind(RayTracingService::class.java).toInstance(RayTracingServiceImpl())
bind(PacketService::class.java).toInstance(PacketServiceImpl(plugin))
bind(PhysicObjectDispatcher::class.java).toInstance(physicObjectDispatcher)
bind(ConfigurationService::class.java).toInstance(ConfigurationServiceImpl(plugin))
bind(PhysicObjectService::class.java).toInstance(PhysicObjectServiceImpl(plugin, physicObjectDispatcher))
bind(ItemService::class.java).toInstance(ItemServiceImpl())
bind(BedrockService::class.java).to(BedrockServiceImpl::class.java).`in`(Scopes.SINGLETON)
bind(GameService::class.java).to(GameServiceImpl::class.java).`in`(Scopes.SINGLETON)
bind(SoundService::class.java).toInstance(SoundServiceImpl(plugin))
bind(CommandService::class.java).to(CommandServiceImpl::class.java).`in`(Scopes.SINGLETON)
bind(TennisBallFactory::class.java).to(TennisBallFactoryImpl::class.java).`in`(Scopes.SINGLETON)
addService<SignService> {
SignServiceImpl(plugin, getService(), MCTennisLanguage.noPermissionMessage)
}
addService<PhysicObjectService> {
PhysicObjectServiceImpl(plugin, getService())
}
addService<CommandService>(CommandServiceImpl(plugin))
addService<PhysicObjectDispatcher>(PhysicObjectDispatcherImpl(plugin))
addService<ConfigurationService>(ConfigurationServiceImpl(plugin))
addService<SoundService>(SoundServiceImpl(plugin))
addService<PacketService>(PacketServiceImpl(plugin))
addService<ItemService>(ItemServiceImpl())
addService<EntityService, EntityServiceImpl>()
addService<ChatMessageService, ChatMessageServiceImpl>()
addService<RayTracingService, RayTracingServiceImpl>()
addService<BedrockService, BedrockServiceImpl>()
addService<GameService, GameServiceImpl>()
addService<TennisBallFactory, TennisBallFactoryImpl>()

if (Bukkit.getPluginManager().getPlugin(PluginDependency.PLACEHOLDERAPI.pluginName) != null) {
bind(PlaceHolderService::class.java).to(DependencyPlaceholderApiServiceImpl::class.java)
.`in`(Scopes.SINGLETON)
addService<PlaceHolderService, DependencyPlaceholderApiServiceImpl>()
plugin.logger.log(Level.INFO, "Loaded dependency ${PluginDependency.PLACEHOLDERAPI.pluginName}.")
} else {
bind(PlaceHolderService::class.java).to(PlaceHolderServiceImpl::class.java).`in`(Scopes.SINGLETON)
addService<PlaceHolderService, PlaceHolderServiceImpl>()
}
}
}
65 changes: 24 additions & 41 deletions src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import com.github.shynixn.mcutils.common.repository.Repository
import com.github.shynixn.mcutils.packet.api.PacketInType
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.sign.SignService
import com.google.inject.Guice
import com.google.inject.Injector
import com.google.inject.Key
import com.google.inject.TypeLiteral
import kotlinx.coroutines.runBlocking
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.plugin.ServicePriority
Expand All @@ -32,7 +27,8 @@ import java.util.logging.Level

class MCTennisPlugin : JavaPlugin() {
private val prefix: String = org.bukkit.ChatColor.BLUE.toString() + "[MCTennis] " + org.bukkit.ChatColor.WHITE
private var injector: Injector? = null
private var isLoaded = false
private lateinit var module: MCTennisDependencyInjectionModule

/**
* Called when this plugin is enabled.
Expand All @@ -41,7 +37,7 @@ class MCTennisPlugin : JavaPlugin() {
Bukkit.getServer().consoleSender.sendMessage(prefix + ChatColor.GREEN + "Loading MCTennis ...")
this.saveDefaultConfig()

val versions = if (MCTennisDependencyInjectionBinder.areLegacyVersionsIncluded) {
val versions = if (MCTennisDependencyInjectionModule.areLegacyVersionsIncluded) {
listOf(
Version.VERSION_1_8_R3,
Version.VERSION_1_9_R2,
Expand Down Expand Up @@ -83,53 +79,52 @@ class MCTennisPlugin : JavaPlugin() {
logger.log(Level.INFO, "Loaded NMS version ${Version.serverVersion.bukkitId}.")

// Guice
this.injector = Guice.createInjector(MCTennisDependencyInjectionBinder(this))
this.module = MCTennisDependencyInjectionModule(this).build()
this.reloadConfig()

resolve(PacketService::class.java).registerPacketListening(PacketInType.USEENTITY)
// Register Packet
module.getService<PacketService>().registerPacketListening(PacketInType.USEENTITY)

// Register Listeners
Bukkit.getPluginManager().registerEvents(resolve(GameListener::class.java), this)
Bukkit.getPluginManager().registerEvents(resolve(TennisListener::class.java), this)
Bukkit.getPluginManager().registerEvents(resolve(PacketListener::class.java), this)
Bukkit.getPluginManager().registerEvents(resolve(BedrockService::class.java), this)
Bukkit.getPluginManager().registerEvents(module.getService<GameListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<PacketListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<TennisListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<BedrockService>(), this)

// Register CommandExecutor
resolve(MCTennisCommandExecutor::class.java)
module.getService<MCTennisCommandExecutor>()

// Register Dependencies
if (Bukkit.getPluginManager().getPlugin(PluginDependency.GEYSER_SPIGOT.pluginName) != null) {
logger.log(Level.INFO, "Loaded dependency ${PluginDependency.GEYSER_SPIGOT.pluginName}.")
}

// Service dependencies
resolve(MCTennisCommandExecutor::class.java)
Bukkit.getServicesManager().register(
TennisBallFactory::class.java,
resolve(TennisBallFactory::class.java),
module.getService(),
this,
ServicePriority.Normal
)
Bukkit.getServicesManager()
.register(GameService::class.java, resolve(GameService::class.java), this, ServicePriority.Normal)
.register(GameService::class.java, module.getService(), this, ServicePriority.Normal)

val plugin = this
runBlocking {
plugin.launch {
// Load Language
val configurationService = resolve(ConfigurationService::class.java)
val configurationService = module.getService<ConfigurationService>()
val language = configurationService.findValue<String>("language")
reloadTranslation(language, MCTennisLanguage::class.java, "en_us")
logger.log(Level.INFO, "Loaded language file $language.properties.")

// Load Games
val gameService = resolve(GameService::class.java)
val gameService = module.getService<GameService>()
gameService.reloadAll()

// Load Signs
val placeHolderService = resolve(PlaceHolderService::class.java)
val signService = resolve(SignService::class.java)
val arenaService =
injector!!.getBinding(Key.get(object : TypeLiteral<Repository<TennisArena>>() {})).provider.get()
val placeHolderService = module.getService<PlaceHolderService>()
val signService = module.getService<SignService>()
val arenaService = module.getService<Repository<TennisArena>>()
signService.onSignDestroy = { signMeta ->
plugin.launch {
val arenas = arenaService.getAll()
Expand Down Expand Up @@ -157,6 +152,7 @@ class MCTennisPlugin : JavaPlugin() {

resolvedText
}
isLoaded = true
Bukkit.getServer().consoleSender.sendMessage(prefix + ChatColor.GREEN + "Enabled MCTennis " + plugin.description.version + " by Shynixn")
}
}
Expand All @@ -165,28 +161,15 @@ class MCTennisPlugin : JavaPlugin() {
* Called when this plugin is disabled
*/
override fun onDisable() {
if (injector == null) {
if (!isLoaded) {
return
}

val packetService = resolve(PacketService::class.java)
val packetService = module.getService<PacketService>()
packetService.close()
val physicObjectService = resolve(PhysicObjectService::class.java)
val physicObjectService = module.getService<PhysicObjectService>()
physicObjectService.close()
val gameService = resolve(GameService::class.java)
val gameService = module.getService<GameService>()
gameService.close()
}

/**
* Gets a business logic from the MCTennis plugin.
* All types in the service package can be accessed.
* Throws a [IllegalArgumentException] if the service could not be found.
*/
private fun <S> resolve(service: Class<S>): S {
try {
return this.injector!!.getBinding(service).provider.get() as S
} catch (e: Exception) {
throw IllegalArgumentException("Service ${service.name} could not be resolved.", e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.shynixn.mctennis.contract

import com.github.shynixn.mcutils.common.Vector3d
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.util.Vector
Expand All @@ -11,6 +10,11 @@ interface TennisBall {
*/
var allowActions: Boolean

/**
* Checks if the ball is dead.
*/
val isDead: Boolean

/**
* Sets the velocity of the tennis ball.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ interface TennisGame {
*/
val servingTeam: Team

/**
* Ball.
*/
val ball: TennisBall?

/**
* Gets the team from a player.
* Returns null if the player is not in the game.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ class TeamMetadata {
* Commands executed on player leave.
*/
var leaveCommands: List<CommandMeta> = ArrayList()

/**
* Commands which are executed every game tick.
*/
var tickCommands: List<CommandMeta> = ArrayList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonPropertyOrder
import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.command.CommandMeta
import com.github.shynixn.mcutils.common.repository.Element
import com.github.shynixn.mcutils.sign.SignMeta

Expand Down Expand Up @@ -70,6 +71,11 @@ class TennisArena : Element {
*/
var signs = ArrayList<SignMeta>()

/**
* Commands which are executed every game tick.
*/
var tickCommands: List<CommandMeta> = ArrayList()

@JsonProperty("ball")
var ballSettings: TennisBallSettings = TennisBallSettings()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.shynixn.mctennis.entity

import com.github.shynixn.mctennis.enumeration.VisibilityType
import com.github.shynixn.mcutils.common.EffectTargetType
import com.github.shynixn.mcutils.common.command.CommandMeta
import com.github.shynixn.mcutils.common.sound.SoundMeta

class TennisBallSettings {
Expand Down Expand Up @@ -124,4 +125,9 @@ class TennisBallSettings {
it.volume = 5.0
it.effectType = EffectTargetType.EVERYONE
}

/**
* Commands which are executed every game tick.
*/
var tickCommands: List<CommandMeta> = ArrayList()
}
Loading

0 comments on commit 86a3621

Please sign in to comment.