Skip to content

Commit

Permalink
Merge branch '0.7.0' (forgot to actually merge it last commit :P)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsimmo committed Dec 12, 2021
2 parents 0b369c0 + 71a8327 commit b4fb7b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 59 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ dependencies {
compileOnly "com.sk89q.worldedit:worldedit-bukkit:7.0.0"
testImplementation "com.sk89q.worldedit:worldedit-bukkit:7.0.0"

<<<<<<< HEAD
compileOnly 'me.clip:placeholderapi:2.10.9'
testImplementation 'me.clip:placeholderapi:2.10.9'
=======
compileOnly 'me.clip:placeholderapi:2.9+'
testImplementation 'me.clip:placeholderapi:2.9+'
>>>>>>> 0.6.6

testImplementation "junit:junit:4.13.+"
testImplementation "org.mockito:mockito-core:3.3.+"
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/io/github/mdsimmo/bomberman/game/GamePlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter
import io.github.mdsimmo.bomberman.Bomberman
import io.github.mdsimmo.bomberman.events.*
import io.github.mdsimmo.bomberman.messaging.Text
import io.github.mdsimmo.bomberman.utils.BukkitUtils
import io.github.mdsimmo.bomberman.utils.WorldEditUtils
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.Location
Expand Down Expand Up @@ -50,10 +48,8 @@ class GamePlayer private constructor(private val player: Player, private val gam
dataFile.save(tempDataFile(player))

// Add a permission group for WorldGuard compatibility (must be done before teleporting)
// Wrap in try loop because it is quite dodgy how other plugins implement
try {
val playerPermissions = BukkitUtils.getPermissibleBase(player)
playerPermissions?.addAttachment(plugin, "group.bomberman", true)
player.addAttachment(plugin, "group.bomberman", true)
} catch (e: Exception) {
plugin.logger.log(Level.WARNING, "Unable to add permissions", e)
}
Expand Down Expand Up @@ -157,8 +153,7 @@ class GamePlayer private constructor(private val player: Player, private val gam
player.removeScoreboardTag("bm_player")

try {
val playerPermissions = BukkitUtils.getPermissibleBase(player)
playerPermissions?.addAttachment(plugin, "group.bomberman", false)
player.addAttachment(plugin, "group.bomberman", false)
} catch (e: Exception) {
plugin.logger.log(Level.WARNING, "Unable to remove permissions", e)
}
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/io/github/mdsimmo/bomberman/utils/BukkitUtils.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package io.github.mdsimmo.bomberman.utils

import io.github.mdsimmo.bomberman.Bomberman
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.World
import org.bukkit.entity.HumanEntity
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.PotionMeta
import org.bukkit.permissions.PermissibleBase
import org.bukkit.potion.PotionData
import org.bukkit.potion.PotionType
import org.bukkit.util.BoundingBox
import java.lang.reflect.Field
import java.util.regex.Pattern
import javax.annotation.CheckReturnValue

object BukkitUtils {
Expand Down Expand Up @@ -46,50 +40,4 @@ object BukkitUtils {
return Location(loc.world,
loc.blockX.toDouble(), loc.blockY.toDouble(), loc.blockZ.toDouble())
}

/**
* Attempts to get the PermissibleBase object of the player. Null if cannot be gained.
* @param player the player to get the PermissibleBase of
* @return the base
*/
fun getPermissibleBase(player: HumanEntity) : PermissibleBase? {
return try {
HUMAN_ENTITY_PERMISSIBLE_FIELD.value?.get(player) as? PermissibleBase
} catch (e: Exception) {
throw e
}
}

// The reflex field containing the PermissibleBase object
// Adapted from LuckPerms code:
// me.lucko.luckperms.bukkit.util.CraftBukkitImplementation
private val HUMAN_ENTITY_PERMISSIBLE_FIELD: Lazy<Field?> = lazy {
val humanEntityPermissibleField = try {
// CraftBukkit
val serverPacketVersion = run {
val server = Bukkit.getServer().javaClass
val matcher = Pattern.compile("^org\\.bukkit\\.craftbukkit\\.(\\w+)\\.CraftServer$")
.matcher(server.name)
if (matcher.matches()) {
'.' + matcher.group(1) + '.'
} else {
"."
}
}
val craftBukkitClassName = "org.bukkit.craftbukkit${serverPacketVersion}entity.CraftHumanEntity"
Class.forName(craftBukkitClassName).getDeclaredField("perm")
} catch (e: Exception) {
try {
// glowstone
Class.forName("net.glowstone.entity.GlowHumanEntity").getDeclaredField("permissions")
} catch (e: Exception) {
// Cannot find anything
Bomberman.instance.logger.warning("Unsupported server - Cannot modify players permissions.")
null
}
}
humanEntityPermissibleField?.isAccessible = true
humanEntityPermissibleField
}

}

0 comments on commit b4fb7b1

Please sign in to comment.