Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 29, 2021
1 parent 2ff1458 commit 4cbb33b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.internal.config.updating

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.config.interfaces.LoadableConfig
import com.willfp.eco.core.config.updating.ConfigHandler
import com.willfp.eco.core.config.updating.ConfigUpdater
Expand All @@ -14,8 +13,8 @@ import org.reflections.scanners.MethodAnnotationsScanner
import java.lang.reflect.Modifier

class EcoConfigHandler(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), ConfigHandler {
private val plugin: EcoPlugin
) : ConfigHandler {
private val reflections: Reflections = Reflections(
this.plugin::class.java.classLoader,
MethodAnnotationsScanner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.bukkit.util.Vector

open class EcoDropQueue(player: Player) : InternalDropQueue {
val items = mutableListOf<ItemStack>()
var xp: Int
var xp: Int = 0
val player: Player
var loc: Location
var hasTelekinesis = false
Expand Down Expand Up @@ -79,7 +79,6 @@ open class EcoDropQueue(player: Player) : InternalDropQueue {
}

init {
xp = 0
this.player = player
loc = player.location
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.willfp.eco.internal.events

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.events.EventManager
import org.bukkit.Bukkit
import org.bukkit.event.HandlerList
import org.bukkit.event.Listener

class EcoEventManager constructor(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), EventManager {
class EcoEventManager constructor(private val plugin: EcoPlugin) : EventManager {
override fun registerListener(listener: Listener) {
Bukkit.getPluginManager().registerEvents(listener, plugin)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.willfp.eco.internal.extensions

import com.google.common.collect.ImmutableSet
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.config.yaml.YamlTransientConfig
import com.willfp.eco.core.extensions.Extension
import com.willfp.eco.core.extensions.ExtensionLoader
Expand All @@ -16,8 +15,8 @@ import java.net.URL
import java.net.URLClassLoader

class EcoExtensionLoader(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), ExtensionLoader {
private val plugin: EcoPlugin
) : ExtensionLoader {
private val extensions = mutableMapOf<Extension, URLClassLoader>()

override fun loadExtensions() {
Expand All @@ -43,7 +42,7 @@ class EcoExtensionLoader(

@Throws(MalformedExtensionException::class)
private fun loadExtension(extensionJar: File) {
lateinit var url : URL
lateinit var url: URL

try {
url = extensionJar.toURI().toURL()
Expand All @@ -53,7 +52,7 @@ class EcoExtensionLoader(

val classLoader = URLClassLoader(arrayOf(url), this.plugin::class.java.classLoader)
val ymlIn = classLoader.getResourceAsStream("extension.yml")
?: throw MalformedExtensionException ("No extension.yml found in " + extensionJar.name)
?: throw MalformedExtensionException("No extension.yml found in " + extensionJar.name)

val extensionYml = YamlTransientConfig(YamlConfiguration.loadConfiguration(InputStreamReader(ymlIn)))

Expand All @@ -64,7 +63,7 @@ class EcoExtensionLoader(


if (mainClass == null) {
throw MalformedExtensionException ("Invalid extension.yml found in " + extensionJar.name)
throw MalformedExtensionException("Invalid extension.yml found in " + extensionJar.name)
}

if (name == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.willfp.eco.internal.factory

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.factory.MetadataValueFactory
import org.bukkit.metadata.FixedMetadataValue

class EcoMetadataValueFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), MetadataValueFactory {
class EcoMetadataValueFactory(private val plugin: EcoPlugin) : MetadataValueFactory {
override fun create(value: Any): FixedMetadataValue {
return FixedMetadataValue(plugin, value)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.willfp.eco.internal.factory

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.factory.NamespacedKeyFactory
import org.bukkit.NamespacedKey

class EcoNamespacedKeyFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), NamespacedKeyFactory {
class EcoNamespacedKeyFactory(private val plugin: EcoPlugin) : NamespacedKeyFactory {
override fun create(key: String): NamespacedKey {
return NamespacedKey(plugin, key)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.willfp.eco.internal.factory

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.factory.RunnableFactory
import com.willfp.eco.core.scheduling.RunnableTask
import com.willfp.eco.internal.scheduling.EcoRunnableTask
import java.util.function.Consumer

class EcoRunnableFactory(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), RunnableFactory {
class EcoRunnableFactory(private val plugin: EcoPlugin) : RunnableFactory {
override fun create(consumer: Consumer<RunnableTask>): RunnableTask {
return object : EcoRunnableTask(plugin) {
override fun run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.internal.proxy

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.proxy.AbstractProxy
import com.willfp.eco.core.proxy.ProxyConstants
import com.willfp.eco.core.proxy.ProxyFactory
Expand All @@ -11,8 +10,8 @@ import java.net.URLClassLoader
import java.util.*

class EcoProxyFactory(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), ProxyFactory {
private val plugin: EcoPlugin
) : ProxyFactory {
private val proxyClassLoader: ClassLoader = plugin::class.java.classLoader
private val cache: MutableMap<Class<out AbstractProxy>, AbstractProxy> = IdentityHashMap()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.willfp.eco.internal.scheduling

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.scheduling.Scheduler
import org.bukkit.Bukkit
import org.bukkit.scheduler.BukkitTask

class EcoScheduler(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Scheduler {
class EcoScheduler(private val plugin: EcoPlugin) : Scheduler {
override fun runLater(
runnable: Runnable,
ticksLater: Long
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.spigot.arrows

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import org.bukkit.Material
import org.bukkit.entity.Arrow
import org.bukkit.entity.LivingEntity
Expand All @@ -11,8 +10,8 @@ import org.bukkit.event.Listener
import org.bukkit.event.entity.ProjectileLaunchEvent

class ArrowDataListener(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), Listener {
private val plugin: EcoPlugin
) : Listener {

@EventHandler(priority = EventPriority.LOWEST)
fun onLaunch(event:ProjectileLaunchEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.spigot.eventlisteners

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import org.bukkit.entity.LivingEntity
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
Expand All @@ -11,8 +10,8 @@ import org.bukkit.event.entity.EntityDeathEvent
import java.util.concurrent.atomic.AtomicReference

class EntityDeathByEntityListeners(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), Listener {
private val plugin: EcoPlugin
) : Listener {
private val events = HashSet<EntityDeathByEntityBuilder>()

@EventHandler(priority = EventPriority.HIGH)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.spigot.gui

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.internal.gui.menu.EcoMenu
import com.willfp.eco.internal.gui.menu.MenuHandler
Expand All @@ -16,7 +15,7 @@ import org.bukkit.event.inventory.ClickType
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryCloseEvent

class GUIListener(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Listener {
class GUIListener(private val plugin: EcoPlugin) : Listener {
@EventHandler
fun handleSlotClick(event: InventoryClickEvent) {
val player = event.whoClicked
Expand All @@ -39,7 +38,7 @@ class GUIListener(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Liste

val extendedInventory = MenuHandler.getExtendedInventory(event.clickedInventory!!) ?: return

plugin.scheduler.run{ extendedInventory.refresh(player) }
plugin.scheduler.run { extendedInventory.refresh(player) }
}

@EventHandler
Expand All @@ -52,7 +51,7 @@ class GUIListener(plugin: EcoPlugin) : PluginDependent<EcoPlugin>(plugin), Liste
MenuHandler.getMenu(player.openInventory.topInventory) ?: return
MenuHandler.getExtendedInventory(player.openInventory.topInventory) ?: return

plugin.scheduler.run{ MenuHandler.getExtendedInventory(player.openInventory.topInventory)?.refresh(player) }
plugin.scheduler.run { MenuHandler.getExtendedInventory(player.openInventory.topInventory)?.refresh(player) }
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.willfp.eco.spigot.integrations.antigrief

import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.PluginDependent
import com.willfp.eco.core.integrations.antigrief.AntigriefWrapper
import me.angeschossen.lands.api.integration.LandsIntegration
import me.angeschossen.lands.api.role.enums.RoleSetting
Expand All @@ -10,8 +9,8 @@ import org.bukkit.block.Block
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player

class AntigriefLands(plugin: EcoPlugin) : PluginDependent<EcoPlugin?>(plugin), AntigriefWrapper {
private val landsIntegration = LandsIntegration(this.plugin!!)
class AntigriefLands(private val plugin: EcoPlugin) : AntigriefWrapper {
private val landsIntegration = LandsIntegration(this.plugin)
override fun canBreakBlock(
player: Player,
block: Block
Expand Down

0 comments on commit 4cbb33b

Please sign in to comment.