diff --git a/docs/source/customizing/placeholders.rst b/docs/source/customizing/placeholders.rst index c94a0748a..d519338b9 100644 --- a/docs/source/customizing/placeholders.rst +++ b/docs/source/customizing/placeholders.rst @@ -5,7 +5,7 @@ The following placeholders are available in BlockBall and can also be used via P .. note:: PlaceHolders can be used in Messages, Signs, Scoreboards, BossBars and Holograms. -.. note:: In order to use BlockBall placeholders in external plugins, the player has to be in a BlockBall game or append the id of the arena to the placeholder e.g. "%blockball_game_blueScore_1%". +.. note:: In order to use BlockBall placeholders in external plugins, the player has to be in a BlockBall game or append the id of the arena to the placeholder e.g. "%blockball_game_blueScore_arena_1%". Placeholderlist ~~~~~~~~~~~~~~~ diff --git a/src/main/java/com/github/shynixn/blockball/BlockBallDependencyInjectionModule.kt b/src/main/java/com/github/shynixn/blockball/BlockBallDependencyInjectionModule.kt index b98d4e3dc..bca8b9d96 100644 --- a/src/main/java/com/github/shynixn/blockball/BlockBallDependencyInjectionModule.kt +++ b/src/main/java/com/github/shynixn/blockball/BlockBallDependencyInjectionModule.kt @@ -6,11 +6,8 @@ import com.github.shynixn.blockball.entity.Arena import com.github.shynixn.blockball.entity.PlayerInformation import com.github.shynixn.blockball.enumeration.PluginDependency import com.github.shynixn.blockball.impl.service.* -import com.github.shynixn.blockball.impl.service.nms.v1_13_R2.Particle113R2ServiceImpl -import com.github.shynixn.blockball.impl.service.nms.v1_8_R3.Particle18R3ServiceImpl import com.github.shynixn.mcutils.common.ConfigurationService import com.github.shynixn.mcutils.common.ConfigurationServiceImpl -import com.github.shynixn.mcutils.common.Version import com.github.shynixn.mcutils.common.chat.ChatMessageService import com.github.shynixn.mcutils.common.item.ItemService import com.github.shynixn.mcutils.common.repository.CacheRepository @@ -101,11 +98,6 @@ class BlockBallDependencyInjectionModule( addService() addService() - when { - Version.serverVersion.isVersionSameOrGreaterThan(Version.VERSION_1_13_R2) -> addService() - else -> addService() - } - if (Bukkit.getPluginManager().getPlugin(PluginDependency.PLACEHOLDERAPI.pluginName) != null) { addService() plugin.logger.log(Level.INFO, "Loaded dependency ${PluginDependency.PLACEHOLDERAPI.pluginName}.") diff --git a/src/main/java/com/github/shynixn/blockball/contract/ParticleService.kt b/src/main/java/com/github/shynixn/blockball/contract/ParticleService.kt deleted file mode 100644 index 1c35aec0d..000000000 --- a/src/main/java/com/github/shynixn/blockball/contract/ParticleService.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.shynixn.blockball.contract - -import com.github.shynixn.blockball.entity.Particle -import org.bukkit.Location -import org.bukkit.entity.Player - -interface ParticleService { - /** - * Plays the given [particle] at the given [location] for the given [players]. - */ - fun playParticle(location: Location, particle: Particle, players: Collection) -} diff --git a/src/main/java/com/github/shynixn/blockball/entity/ArenaMeta.kt b/src/main/java/com/github/shynixn/blockball/entity/ArenaMeta.kt index a0f71fa54..3fb867e38 100644 --- a/src/main/java/com/github/shynixn/blockball/entity/ArenaMeta.kt +++ b/src/main/java/com/github/shynixn/blockball/entity/ArenaMeta.kt @@ -1,7 +1,6 @@ package com.github.shynixn.blockball.entity import com.github.shynixn.blockball.enumeration.BallActionType -import com.github.shynixn.blockball.enumeration.ParticleType import com.github.shynixn.mcutils.common.sound.SoundMeta class ArenaMeta { @@ -72,46 +71,6 @@ class ArenaMeta { private val internalHologramMetas: ArrayList = ArrayList() init { - val partMetaSpawn = Particle() - partMetaSpawn.typeName = ParticleType.EXPLOSION_NORMAL.name - partMetaSpawn.amount = 10 - partMetaSpawn.speed = 0.1 - partMetaSpawn.offset.x = 2.0 - partMetaSpawn.offset.y = 2.0 - partMetaSpawn.offset.z = 2.0 - - ballMeta.particleEffects[BallActionType.ONSPAWN] = partMetaSpawn - - val partMetaInteraction = Particle() - partMetaInteraction.typeName = ParticleType.CRIT.name - partMetaInteraction.amount = 5 - partMetaInteraction.speed = 0.1 - partMetaInteraction.offset.x = 2.0 - partMetaInteraction.offset.y = 2.0 - partMetaInteraction.offset.z = 2.0 - - ballMeta.particleEffects[BallActionType.ONINTERACTION] = partMetaInteraction - - val partMetaKick = Particle() - partMetaKick.typeName = ParticleType.EXPLOSION_LARGE.name - partMetaKick.amount = 5 - partMetaKick.speed = 0.1 - partMetaKick.offset.x = 0.2 - partMetaKick.offset.y = 0.2 - partMetaKick.offset.z = 0.2 - - ballMeta.particleEffects[BallActionType.ONKICK] = partMetaKick - - val partMetaShoot = Particle() - partMetaShoot.typeName = ParticleType.EXPLOSION_NORMAL.name - partMetaShoot.amount = 5 - partMetaShoot.speed = 0.1 - partMetaShoot.offset.x = 0.1 - partMetaShoot.offset.y = 0.1 - partMetaShoot.offset.z = 0.1 - - ballMeta.particleEffects[BallActionType.ONPASS] = partMetaShoot - val soundMetaKick = SoundMeta() soundMetaKick.name = "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR,ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,ZOMBIE_WOOD" soundMetaKick.volume = 10.0 diff --git a/src/main/java/com/github/shynixn/blockball/entity/BallMeta.kt b/src/main/java/com/github/shynixn/blockball/entity/BallMeta.kt index cb5d54bb7..4b8ac9a22 100644 --- a/src/main/java/com/github/shynixn/blockball/entity/BallMeta.kt +++ b/src/main/java/com/github/shynixn/blockball/entity/BallMeta.kt @@ -79,11 +79,6 @@ class BallMeta { */ val movementModifier: MovementConfiguration = MovementConfiguration() - /** - * Particle effects. - */ - val particleEffects: MutableMap = HashMap() - /** * Particle effects. */ diff --git a/src/main/java/com/github/shynixn/blockball/entity/DoubleJumpMeta.kt b/src/main/java/com/github/shynixn/blockball/entity/DoubleJumpMeta.kt index ed35545f2..e93b43d9c 100644 --- a/src/main/java/com/github/shynixn/blockball/entity/DoubleJumpMeta.kt +++ b/src/main/java/com/github/shynixn/blockball/entity/DoubleJumpMeta.kt @@ -1,9 +1,7 @@ package com.github.shynixn.blockball.entity -import com.github.shynixn.blockball.enumeration.ParticleType import com.github.shynixn.mcutils.common.sound.SoundMeta - class DoubleJumpMeta { /** Is the effect enabled or disabled?*/ var enabled: Boolean = true @@ -14,19 +12,10 @@ class DoubleJumpMeta { /** Horizontal strength modifier.*/ var horizontalStrength: Double = 2.0 /** ParticleEffect being played when activating this.*/ - val particleEffect: Particle = Particle(ParticleType.EXPLOSION_NORMAL.name) /** SoundEffect being played when activating this.*/ val soundEffect: SoundMeta = SoundMeta().also { it.name = "ENTITY_GHAST_SHOOT,GHAST_FIREBALL" it.pitch = 1.0 it.volume = 10.0 } - - init { - particleEffect.amount = 4 - particleEffect.speed = 0.0002 - particleEffect.offset.x = 2.0 - particleEffect.offset.y = 2.0 - particleEffect.offset.z = 2.0 - } } diff --git a/src/main/java/com/github/shynixn/blockball/entity/Particle.kt b/src/main/java/com/github/shynixn/blockball/entity/Particle.kt deleted file mode 100644 index 2cda1c7d9..000000000 --- a/src/main/java/com/github/shynixn/blockball/entity/Particle.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.shynixn.blockball.entity - -import com.github.shynixn.blockball.enumeration.ParticleType - - -class Particle( - var typeName: String = ParticleType.NONE.name -) { - /** - * Database Id. - */ - var id: Long = 0 - /** - * Amount of particles. - */ - var amount: Int = 1 - /** - * Particle speed. - */ - var speed: Double = 1.0 - /** - * Offset for the x coordinate. - */ - var offset: Offset = Offset() - /** - * Material value. - */ - var materialName: String? = null - /** - * Data value. - */ - var data: Int = 0 - - /** - * RGB Color code of red. - */ - var colorRed: Int - get() = this.offset.x.toInt() - set(value) { - this.offset.x = value.toDouble() - } - - /** - * RGB Color code of green. - */ - var colorGreen: Int - get() = this.offset.y.toInt() - set(value) { - this.offset.y = value.toDouble() - } - /** - * RGB Color code of blue. - */ - var colorBlue: Int - get() = this.offset.z.toInt() - set(value) { - this.offset.z = value.toDouble() - } -} diff --git a/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/ArenaCommandExecutor.kt b/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/ArenaCommandExecutor.kt index af485429c..74bb9db38 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/ArenaCommandExecutor.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/ArenaCommandExecutor.kt @@ -32,7 +32,6 @@ class ArenaCommandExecutor @Inject constructor( bossbarPage: BossbarPage, signSettingsPage: SignSettingsPage, rewardsPage: RewardsPage, - particlesPage: ParticleEffectPage, soundsPage: SoundEffectPage, abilitiesPage: AbilitiesSettingsPage, doubleJumpPage: DoubleJumpPage, @@ -71,7 +70,6 @@ class ArenaCommandExecutor @Inject constructor( bossbarPage, signSettingsPage, rewardsPage, - particlesPage, soundsPage, abilitiesPage, doubleJumpPage, diff --git a/src/main/java/com/github/shynixn/blockball/impl/commandmenu/BallSettingsPage.kt b/src/main/java/com/github/shynixn/blockball/impl/commandmenu/BallSettingsPage.kt index 8cb9ca3ec..02eb4df42 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/commandmenu/BallSettingsPage.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/commandmenu/BallSettingsPage.kt @@ -2,7 +2,6 @@ package com.github.shynixn.blockball.impl.commandmenu import com.github.shynixn.blockball.entity.Arena import com.github.shynixn.blockball.entity.ChatBuilder -import com.github.shynixn.blockball.entity.Particle import com.github.shynixn.blockball.enumeration.* import com.github.shynixn.mcutils.common.sound.SoundMeta @@ -54,8 +53,6 @@ class BallSettingsPage : Page(BallSettingsPage.ID, MainSettingsPage.ID) { ballMeta.alwaysBounce = !ballMeta.alwaysBounce } else if (command == MenuCommand.BALL_TOGGLE_ROTATING) { ballMeta.rotating = !ballMeta.rotating - } else if (command == MenuCommand.BALL_PARTICLEACTION_CALLBACK && args.size == 3) { - cache[5] = ballMeta.particleEffects[BallActionType.values()[args[2].toInt()]] } else if (command == MenuCommand.BALL_SOUNDACTION_CALLBACK && args.size == 3) { cache[5] = ballMeta.soundEffects[BallActionType.values()[args[2].toInt()]] } @@ -128,23 +125,12 @@ class BallSettingsPage : Page(BallSettingsPage.ID, MainSettingsPage.ID) { .setClickAction(ChatClickAction.RUN_COMMAND, MenuCommand.LIST_BALL_SOUNDEFFECTS.command) .setHoverText("Opens the selection page for action binders.") .builder().nextLine() - .component("- Particle Effect: ").builder() - .component(MenuClickableItem.SELECT.text).setColor(MenuClickableItem.SELECT.color) - .setClickAction(ChatClickAction.RUN_COMMAND, MenuCommand.LIST_BALL_PARTICLEFFECTS.command) - .setHoverText("Opens the selection page for action binders.") - .builder().nextLine() if (cache[5] != null && cache[5] is SoundMeta) { builder.component("- Selected Sound-effect: ").builder().component(MenuClickableItem.PAGE.text) .setColor(MenuClickableItem.PAGE.color) .setClickAction(ChatClickAction.RUN_COMMAND, MenuCommand.SOUND_BALL.command) .setHoverText("Opens the page for editing sound effects.") .builder().nextLine() - } else if (cache[5] != null && cache[5] is Particle) { - builder.component("- Selected Particle-effect: ").builder().component(MenuClickableItem.PAGE.text) - .setColor(MenuClickableItem.PAGE.color) - .setClickAction(ChatClickAction.RUN_COMMAND, MenuCommand.PARTICLE_BALL.command) - .setHoverText("Opens the page for editing particle effects.") - .builder().nextLine() } return builder } diff --git a/src/main/java/com/github/shynixn/blockball/impl/commandmenu/ParticleEffectPage.kt b/src/main/java/com/github/shynixn/blockball/impl/commandmenu/ParticleEffectPage.kt deleted file mode 100644 index 4baac5745..000000000 --- a/src/main/java/com/github/shynixn/blockball/impl/commandmenu/ParticleEffectPage.kt +++ /dev/null @@ -1,127 +0,0 @@ -package com.github.shynixn.blockball.impl.commandmenu - -import com.github.shynixn.blockball.entity.Arena -import com.github.shynixn.blockball.entity.ChatBuilder -import com.github.shynixn.blockball.entity.Particle -import com.github.shynixn.blockball.enumeration.* - -/** - * Created by Shynixn 2018. - *

- * Version 1.2 - *

- * MIT License - *

- * Copyright (c) 2018 by Shynixn - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -class ParticleEffectPage : Page(ParticleEffectPage.ID, MainConfigurationPage.ID) { - companion object { - /** Id of the page. */ - const val ID = 20 - } - - override fun getPreviousIdFrom(cache: Array): Int { - return cache[4] as Int - } - - /** - * Returns the key of the command when this page should be executed. - * - * @return key - */ - override fun getCommandKey(): MenuPageKey { - return MenuPageKey.PARTICLEFFECTS - } - - /** - * Executes actions for this page. - * - * @param cache cache - */ - override fun

execute(player: P, command: MenuCommand, cache: Array, args: Array): MenuCommandResult { - val arena = cache[0] as Arena - if (command == MenuCommand.PARTICLE_DOUBLEJUMP) { - cache[5] = arena.meta.doubleJumpMeta.particleEffect - cache[4] = DoubleJumpPage.ID - } else if (command == MenuCommand.PARTICLE_BALL) { - cache[4] = BallSettingsPage.ID - } else if (command == MenuCommand.PARTICLE_CALLBACK_TYPE && args.size >= 3 && args[2].toIntOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.typeName = (ParticleType.values()[args[2].toInt()]).name - } else if (command == MenuCommand.PARTICLE_AMOUNT && args[2].toIntOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.amount = (args[2].toInt()) - } else if (command == MenuCommand.PARTICLE_SPEED && args[2].toDoubleOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.speed = args[2].toDouble() - } else if (command == MenuCommand.PARTICLE_OFFSET_X && args[2].toDoubleOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.offset.x = (args[2].toDouble()) - } else if (command == MenuCommand.PARTICLE_OFFSET_Y && args[2].toDoubleOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.offset.y = (args[2].toDouble()) - } else if (command == MenuCommand.PARTICLE_OFFSET_Z && args[2].toDoubleOrNull() != null) { - val particleEffect = cache[5] as Particle - particleEffect.offset.z = (args[2].toDouble()) - } - return super.execute(player, command, cache, args) - } - - /** - * Builds this page for the player. - * - * @return page - */ - override fun buildPage(cache: Array): ChatBuilder? { - val particleEffect = cache[5] as Particle - return ChatBuilder() - .component("- Type: " + particleEffect.typeName).builder() - .component(MenuClickableItem.SELECT.text).setColor(MenuClickableItem.SELECT.color) - .setClickAction(ChatClickAction.RUN_COMMAND, MenuCommand.LIST_PARTICLE_TYPES.command) - .setHoverText("Opens the selectionbox for types.") - .builder().nextLine() - .component("- Amount: " + particleEffect.amount).builder() - .component(MenuClickableItem.EDIT.text).setColor(MenuClickableItem.EDIT.color) - .setClickAction(ChatClickAction.SUGGEST_COMMAND, MenuCommand.PARTICLE_AMOUNT.command) - .setHoverText("Changes the amount of particles.") - .builder().nextLine() - .component("- Speed: " + particleEffect.speed).builder() - .component(MenuClickableItem.EDIT.text).setColor(MenuClickableItem.EDIT.color) - .setClickAction(ChatClickAction.SUGGEST_COMMAND, MenuCommand.PARTICLE_SPEED.command) - .setHoverText("Changes the speed of the particles.") - .builder().nextLine() - .component("- Offset X: " + particleEffect.offset.x).builder() - .component(MenuClickableItem.EDIT.text).setColor(MenuClickableItem.EDIT.color) - .setClickAction(ChatClickAction.SUGGEST_COMMAND, MenuCommand.PARTICLE_OFFSET_X.command) - .setHoverText("Changes the offset X.") - .builder().nextLine() - .component("- Offset Y: " + particleEffect.offset.y).builder() - .component(MenuClickableItem.EDIT.text).setColor(MenuClickableItem.EDIT.color) - .setClickAction(ChatClickAction.SUGGEST_COMMAND, MenuCommand.PARTICLE_OFFSET_Y.command) - .setHoverText("Changes the offset Y.") - .builder().nextLine() - .component("- Offset Z: " + particleEffect.offset.z).builder() - .component(MenuClickableItem.EDIT.text).setColor(MenuClickableItem.EDIT.color) - .setClickAction(ChatClickAction.SUGGEST_COMMAND, MenuCommand.PARTICLE_OFFSET_Z.command) - .setHoverText("Changes the offset Z.") - .builder().nextLine() - } -} diff --git a/src/main/java/com/github/shynixn/blockball/impl/listener/BallListener.kt b/src/main/java/com/github/shynixn/blockball/impl/listener/BallListener.kt index 203f8a2cb..5d68bdf5e 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/listener/BallListener.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/listener/BallListener.kt @@ -2,7 +2,6 @@ package com.github.shynixn.blockball.impl.listener import com.github.shynixn.blockball.contract.Ball import com.github.shynixn.blockball.contract.BallEntityService -import com.github.shynixn.blockball.contract.ParticleService import com.github.shynixn.blockball.enumeration.BallActionType import com.github.shynixn.blockball.event.* import com.github.shynixn.mcutils.common.sound.SoundService @@ -15,7 +14,6 @@ import org.bukkit.event.Listener */ class BallListener @Inject constructor( private val ballEntityService: BallEntityService, - private val particleService: ParticleService, private val soundService: SoundService ) : Listener { /** @@ -88,14 +86,6 @@ class BallListener @Inject constructor( * Plays effects. */ private fun playEffects(ball: Ball, actionEffect: BallActionType) { - if (ball.meta.particleEffects.containsKey(actionEffect)) { - this.particleService.playParticle( - ball.getLocation(), - ball.meta.particleEffects[actionEffect]!!, - ball.getLocation().world!!.players - ) - } - if (ball.meta.soundEffects.containsKey(actionEffect)) { this.soundService.playSound( ball.getLocation(), diff --git a/src/main/java/com/github/shynixn/blockball/impl/listener/DoubleJumpListener.kt b/src/main/java/com/github/shynixn/blockball/impl/listener/DoubleJumpListener.kt index af2fb43f4..44a00d430 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/listener/DoubleJumpListener.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/listener/DoubleJumpListener.kt @@ -3,7 +3,6 @@ package com.github.shynixn.blockball.impl.listener import com.github.shynixn.blockball.contract.GameService -import com.github.shynixn.blockball.contract.ParticleService import com.github.shynixn.mcutils.common.sound.SoundService import com.google.inject.Inject import org.bukkit.GameMode @@ -12,7 +11,7 @@ import org.bukkit.event.Listener import org.bukkit.event.player.PlayerMoveEvent import org.bukkit.event.player.PlayerToggleFlightEvent -class DoubleJumpListener @Inject constructor(private val gameService: GameService, private val soundService: SoundService, private val particleService: ParticleService) : Listener { +class DoubleJumpListener @Inject constructor(private val gameService: GameService, private val soundService: SoundService) : Listener { /** * Gets called when a player moves. Allows the executing player to start flying * for double jump calculation if the action is enabled and the player is in a game. @@ -63,6 +62,5 @@ class DoubleJumpListener @Inject constructor(private val gameService: GameServic .setY(meta.verticalStrength) soundService.playSound(player.location,player.world.players, meta.soundEffect) - particleService.playParticle(player.location, meta.particleEffect, player.world.players) } } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt index 1a455c93d..f8e372ef4 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt @@ -64,10 +64,25 @@ class DependencyPlaceHolderServiceImpl @Inject constructor( } val parts = params.split("_") - val finalPart = parts[parts.size - 1] - val newParams = parts.dropLast(1).joinToString("_") + val gamePart = StringBuilder() + val newParams = StringBuilder() + for (i in parts.indices) { + if (i < 2) { + if (newParams.isNotEmpty()) { + newParams.append("_") + } + + newParams.append(parts[i]) + } else { + if (gamePart.isNotEmpty()) { + gamePart.append("_") + } + + gamePart.append(parts[i]) + } + } - var optSelectedGame = gameService.getGameFromName(finalPart) + var optSelectedGame = gameService.getGameFromName(gamePart.toString()) if (optSelectedGame.isPresent) { val selectedGame = optSelectedGame.get() val teamPair = if (player != null && selectedGame.redTeam.contains(player)) { diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_13_R2/Particle113R2ServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_13_R2/Particle113R2ServiceImpl.kt deleted file mode 100644 index fd2f97e17..000000000 --- a/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_13_R2/Particle113R2ServiceImpl.kt +++ /dev/null @@ -1,80 +0,0 @@ -@file:Suppress("DEPRECATION", "UNCHECKED_CAST") - -package com.github.shynixn.blockball.impl.service.nms.v1_13_R2 - -import com.github.shynixn.blockball.contract.ParticleService -import com.github.shynixn.blockball.entity.Particle -import com.github.shynixn.blockball.enumeration.ParticleType -import com.google.inject.Inject -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.entity.Player -import java.util.logging.Level - -class Particle113R2ServiceImpl @Inject constructor() : - ParticleService { - /** - * Plays the given [particle] at the given [location] for the given [player] or - * all players in the world if the config option all alwaysVisible is enabled. - */ - override fun playParticle(location: Location, particle: Particle, players: Collection) { - try { - if (particle.typeName.equals("NONE", true)) { - return - } - - val partType = findParticleType(particle.typeName) - val bukkitType = org.bukkit.Particle.values().asSequence() - .firstOrNull() { p -> p.name.equals(particle.typeName, true) || partType.name == p.name } - - if (bukkitType == null) { - return - } - - val dataType = bukkitType.dataType - - for (player in players) { - when (dataType) { - Void::class.java -> player.spawnParticle( - bukkitType, - location, - particle.amount, - particle.offset.x, - particle.offset.y, - particle.offset.z, - particle.speed - ) - org.bukkit.Particle.DustOptions::class.java -> { - val dustOptions = - org.bukkit.Particle.DustOptions( - org.bukkit.Color.fromRGB( - particle.colorRed, - particle.colorGreen, - particle.colorBlue - ), 1.0F - ) - player.spawnParticle(bukkitType, location, 0, dustOptions) - } - else -> { - throw IllegalArgumentException("Unknown particle!") - } - } - } - } catch (e: Exception) { - Bukkit.getServer().logger.log(Level.WARNING, "Failed to send particle.", e) - } - } - - /** - * Finds the particle type. - */ - private fun findParticleType(item: String): ParticleType { - ParticleType.values().forEach { p -> - if (p.name == item || p.gameId_18 == item || p.gameId_113 == item || p.minecraftId_112 == item) { - return p - } - } - - return ParticleType.NONE - } -} diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_8_R3/Particle18R3ServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_8_R3/Particle18R3ServiceImpl.kt deleted file mode 100644 index 767acf229..000000000 --- a/src/main/java/com/github/shynixn/blockball/impl/service/nms/v1_8_R3/Particle18R3ServiceImpl.kt +++ /dev/null @@ -1,161 +0,0 @@ -@file:Suppress("UNCHECKED_CAST") - -package com.github.shynixn.blockball.impl.service.nms.v1_8_R3 - -import com.github.shynixn.blockball.contract.ParticleService -import com.github.shynixn.blockball.entity.Particle -import com.github.shynixn.blockball.enumeration.ParticleType -import com.github.shynixn.mcutils.common.Version -import com.github.shynixn.mcutils.packet.api.PacketService -import com.google.inject.Inject -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.Material -import org.bukkit.entity.Player -import org.bukkit.plugin.Plugin -import java.lang.reflect.Method -import java.util.logging.Level - -class Particle18R3ServiceImpl @Inject constructor( - private val plugin: Plugin, - private val packetService: PacketService -) : ParticleService { - private val getIdFromMaterialMethod: Method = { Material::class.java.getDeclaredMethod("getId") }.invoke() - - /** - * Plays the given [particle] at the given [location] for the given [player] or - * all players in the world if the config option all alwaysVisible is enabled. - */ - override fun playParticle(location: Location, particle: Particle, players: Collection) { - val partType = findParticleType(particle.typeName) - - if (partType == ParticleType.NONE) { - return - } - - val targets = players.toTypedArray() - - if (partType == ParticleType.REDSTONE || partType == ParticleType.NOTE) { - particle.amount = 0 - particle.speed = 1.0f.toDouble() - } - - val internalParticleType = getInternalEnumValue(partType) - - var additionalPayload: IntArray? = null - - if (particle.materialName != null) { - additionalPayload = if (partType == ParticleType.ITEM_CRACK) { - intArrayOf( - getIdFromMaterialMethod.invoke(Material.getMaterial(particle.materialName!!)) as Int, - particle.data - ) - } else { - intArrayOf( - getIdFromMaterialMethod.invoke(Material.getMaterial(particle.materialName!!)) as Int, - (particle.data shl 12) - ) - } - } - - val packet = if (partType == ParticleType.REDSTONE) { - var red = particle.colorRed.toFloat() / 255.0F - if (red <= 0) { - red = Float.MIN_VALUE - } - - val constructor = Version.findClass( "net.minecraft.server.VERSION.PacketPlayOutWorldParticles") - .getDeclaredConstructor( - internalParticleType.javaClass, - Boolean::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Int::class.javaPrimitiveType, - IntArray::class.java - ) - constructor.newInstance( - internalParticleType, - isLongDistance(location, targets), - location.x.toFloat(), - location.y.toFloat(), - location.z.toFloat(), - red, - particle.colorGreen.toFloat() / 255.0f, - particle.colorBlue.toFloat() / 255.0f, - particle.speed.toFloat(), - particle.amount, - additionalPayload - ) - } else { - val constructor = Version.findClass("net.minecraft.server.VERSION.PacketPlayOutWorldParticles") - .getDeclaredConstructor( - internalParticleType.javaClass, - Boolean::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Float::class.javaPrimitiveType, - Int::class.javaPrimitiveType, - IntArray::class.java - ) - constructor.newInstance( - internalParticleType, - isLongDistance(location, targets), - location.x.toFloat(), - location.y.toFloat(), - location.z.toFloat(), - particle.offset.x.toFloat(), - particle.offset.y.toFloat(), - particle.offset.z.toFloat(), - particle.speed.toFloat(), - particle.amount, - additionalPayload - ) - } - - try { - players.forEach { p -> - packetService.sendNativePacket(p, packet) - } - } catch (e: Exception) { - Bukkit.getServer().logger.log(Level.WARNING, "Failed to send particle.", e) - } - } - - private fun isLongDistance(location: Location, players: Array): Boolean { - return players.any { location.world!!.name == it.location.world!!.name && it.location.distanceSquared(location) > 65536 } - } - - /** - * Finds the particle type. - */ - private fun findParticleType(item: String): ParticleType { - ParticleType.values().forEach { p -> - if (p.name == item || p.gameId_18 == item || p.gameId_113 == item || p.minecraftId_112 == item) { - return p - } - } - - return ParticleType.NONE - } - - private fun getInternalEnumValue(particle: ParticleType): Any { - try { - val clazz = - Version.findClass("net.minecraft.server.VERSION.EnumParticle") - val method = clazz.getDeclaredMethod("valueOf", String::class.java) - return method.invoke(null, particle.name) - } catch (e: Exception) { - plugin.logger.log(Level.WARNING,"Failed to load enum value.") - throw RuntimeException(e) - } - } -}