Skip to content

Commit

Permalink
[plugin] refactor worldguard compatibility modules
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM authored and Gabriel Dumitru committed Feb 21, 2022
1 parent 10d6e00 commit 9b88c9d
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 34 deletions.
4 changes: 1 addition & 3 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ dependencies {
compileOnly('com.arcaniax:HeadDatabase-API:1.3.1') { transitive false }

// WorldGuard compatibility
implementation project(':worldguard_compat')
implementation project(':worldguard_compat_v6')
implementation project(':worldguard_compat_v7')
['base', 'v6', 'v7'].forEach {implementation project(':plugin:compatibility:worldguard:' + it) }

// bStats
implementation 'org.bstats:bstats-bukkit:2.2.1'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.gabytm.minecraft.arcanevouchers.compatibility.worldguard

import org.bukkit.Location

interface WorldGuardCompatibility {

/**
* Gets the id of all regions from a certain [Location]
* @return set of region ids
*/
fun getRegions(location: Location): Set<String>

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ repositories {
}

dependencies {
compileOnly project(':worldguard_compat')
compileOnly project(':plugin:compatibility:worldguard:base')
compileOnly 'com.sk89q:worldguard:6.1'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package me.gabytm.minecraft.arcanevouchers.compat.worldguard
package me.gabytm.minecraft.arcanevouchers.compatibility.worldguard

import com.sk89q.worldguard.bukkit.WorldGuardPlugin
import org.bukkit.Location

class WorldGuard6Compat : WorldGuardCompat {
class WorldGuard6Compatibility : WorldGuardCompatibility {

/**
* Gets the id of all regions from a certain [Location]
* @return set of region ids
*/
override fun getRegions(location: Location): Set<String> {
return WorldGuardPlugin.inst().regionContainer.createQuery().getApplicableRegions(location)
.map { it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ repositories {
}

dependencies {
compileOnly project(':worldguard_compat')
compileOnly project(':plugin:compatibility:worldguard:base')
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.5'
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package me.gabytm.minecraft.arcanevouchers.compat.worldguard
package me.gabytm.minecraft.arcanevouchers.compatibility.worldguard

import com.sk89q.worldedit.bukkit.BukkitAdapter
import com.sk89q.worldguard.WorldGuard
import org.bukkit.Location

class WorldGuard7Compat : WorldGuardCompat {
class WorldGuard7Compatibility : WorldGuardCompatibility {

/**
* Gets the id of all regions from a certain [Location]
* @return set of region ids
*/
override fun getRegions(location: Location): Set<String> {
return WorldGuard.getInstance().platform.regionContainer.createQuery().getApplicableRegions(BukkitAdapter.adapt(location))
.map { it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.gabytm.minecraft.arcanevouchers

import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.commands.CommandManager
import me.gabytm.minecraft.arcanevouchers.compat.CompatHandler
import me.gabytm.minecraft.arcanevouchers.compatibility.CompatibilityHandler
import me.gabytm.minecraft.arcanevouchers.config.Config
import me.gabytm.minecraft.arcanevouchers.functions.color
import me.gabytm.minecraft.arcanevouchers.items.ItemCreator
Expand All @@ -22,7 +22,7 @@ class ArcaneVouchers : JavaPlugin() {
lateinit var settings: Settings private set

lateinit var audiences: BukkitAudiences private set
lateinit var compatHandler: CompatHandler private set
lateinit var compatibilityHandler: CompatibilityHandler private set

lateinit var vouchersConfig: Config private set
private lateinit var langFile: Config
Expand Down Expand Up @@ -58,7 +58,7 @@ class ArcaneVouchers : JavaPlugin() {
this.settings = Settings(this.config)

this.audiences = BukkitAudiences.create(this)
this.compatHandler = CompatHandler(this)
this.compatibilityHandler = CompatibilityHandler(this)

this.vouchersConfig = Config(this, "vouchers.yml", false)
this.langFile = Config(this, "lang.yml")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package me.gabytm.minecraft.arcanevouchers.compat
package me.gabytm.minecraft.arcanevouchers.compatibility

import me.gabytm.minecraft.arcanevouchers.ArcaneVouchers
import me.gabytm.minecraft.arcanevouchers.compat.worldguard.WorldGuard6Compat
import me.gabytm.minecraft.arcanevouchers.compat.worldguard.WorldGuard7Compat
import me.gabytm.minecraft.arcanevouchers.compat.worldguard.WorldGuardCompat
import me.gabytm.minecraft.arcanevouchers.compatibility.worldguard.WorldGuard6Compatibility
import me.gabytm.minecraft.arcanevouchers.compatibility.worldguard.WorldGuard7Compatibility
import me.gabytm.minecraft.arcanevouchers.compatibility.worldguard.WorldGuardCompatibility
import org.bukkit.Bukkit

class CompatHandler(plugin: ArcaneVouchers) {
class CompatibilityHandler(plugin: ArcaneVouchers) {

/**
* **ALWAYS** check if [hasWorldGuardSupport] is true before accessing [worldGuardCompat]
* **ALWAYS** check if [hasWorldGuardSupport] is true before accessing [worldGuardCompatibility]
*/
var hasWorldGuardSupport: Boolean = false; private set
lateinit var worldGuardCompat: WorldGuardCompat private set
lateinit var worldGuardCompatibility: WorldGuardCompatibility private set

init {
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
val version = Bukkit.getPluginManager().getPlugin("WorldGuard")!!.description.version

when {
version.startsWith("6.") -> WorldGuard6Compat()
version.startsWith("7.") -> WorldGuard7Compat()
version.startsWith("6.") -> WorldGuard6Compatibility()
version.startsWith("7.") -> WorldGuard7Compatibility()
else -> {
plugin.logger.warning("Found an unsupported WorldGuard version, $version")
null
}
}?.let {
plugin.logger.info("Added support for WorldGuard v${version[0]} ($version)")
this.hasWorldGuardSupport = true
this.worldGuardCompat = it
this.worldGuardCompatibility = it
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VoucherUseListener(private val plugin: ArcaneVouchers) : Listener {
private val useActions = EnumSet.of(Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK)
private val voucherManager = plugin.voucherManager
private val limitManager = voucherManager.limitManager
private val compatHandler = plugin.compatHandler
private val compatHandler = plugin.compatibilityHandler
private val audiences = plugin.audiences

private fun NBTCompound.getArgs(): MutableMap<String, String> {
Expand Down Expand Up @@ -136,7 +136,7 @@ class VoucherUseListener(private val plugin: ArcaneVouchers) : Listener {

if (compatHandler.hasWorldGuardSupport) {
val regions = settings.regions
val worldGuardRegions = compatHandler.worldGuardCompat.getRegions(player.location)
val worldGuardRegions = compatHandler.worldGuardCompatibility.getRegions(player.location)

// The player is inside a blacklisted region
if (regions.isBlacklisted(worldGuardRegions, placeholders, values)) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'arcane-vouchers'
include(':plugin')
include(':worldguard_compat', ':worldguard_compat_v6', ':worldguard_compat_v7')
['base', 'v6', 'v7'].forEach { include(':plugin:compatibility:worldguard:' + it) }
include(':comet')

This file was deleted.

0 comments on commit 9b88c9d

Please sign in to comment.