-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from Auxilor/develop
Additions and fixes
- Loading branch information
Showing
13 changed files
with
413 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/items/ArgParserEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.willfp.eco.internal.items | ||
|
||
import com.willfp.eco.core.items.args.LookupArgParser | ||
import org.bukkit.block.CreatureSpawner | ||
import org.bukkit.entity.EntityType | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.BlockStateMeta | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import java.util.function.Predicate | ||
|
||
object ArgParserEntity : LookupArgParser { | ||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? { | ||
if (meta !is BlockStateMeta) { | ||
return null | ||
} | ||
|
||
if (meta.hasBlockState() || meta.blockState !is CreatureSpawner) { | ||
return null | ||
} | ||
|
||
val state = meta.blockState as CreatureSpawner | ||
|
||
var type: String? = null | ||
|
||
for (arg in args) { | ||
val argSplit = arg.split(":") | ||
if (!argSplit[0].equals("entity", ignoreCase = true)) { | ||
continue | ||
} | ||
if (argSplit.size < 2) { | ||
continue | ||
} | ||
type = argSplit[1] | ||
} | ||
|
||
type ?: return null | ||
|
||
val entityType = runCatching { EntityType.valueOf(type.uppercase()) }.getOrNull() ?: return null | ||
|
||
state.spawnedType = entityType | ||
|
||
meta.blockState = state | ||
|
||
return Predicate { | ||
val testMeta = ((it.itemMeta as? BlockStateMeta) as? CreatureSpawner) ?: return@Predicate false | ||
|
||
testMeta.spawnedType?.name?.equals(type, true) == true | ||
} | ||
} | ||
|
||
override fun serializeBack(meta: ItemMeta): String? { | ||
if (meta !is BlockStateMeta) { | ||
return null | ||
} | ||
|
||
if (meta.hasBlockState() || meta.blockState !is CreatureSpawner) { | ||
return null | ||
} | ||
|
||
val state = meta.blockState as CreatureSpawner | ||
|
||
return state.spawnedType?.let { "entity:${state.spawnedType!!.name}" } ?: return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
.../main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefHuskClaims.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.willfp.eco.internal.spigot.integrations.antigrief | ||
|
||
import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration | ||
import net.crashcraft.crashclaim.CrashClaim | ||
import net.crashcraft.crashclaim.permissions.PermissionRoute | ||
import net.william278.huskclaims.api.HuskClaimsAPI | ||
import net.william278.huskclaims.libraries.cloplib.operation.Operation | ||
import net.william278.huskclaims.libraries.cloplib.operation.OperationPosition | ||
import net.william278.huskclaims.libraries.cloplib.operation.OperationType | ||
import net.william278.huskclaims.position.Position | ||
import net.william278.huskclaims.position.World | ||
import org.bukkit.Location | ||
import org.bukkit.block.Block | ||
import org.bukkit.entity.LivingEntity | ||
import org.bukkit.entity.Monster | ||
import org.bukkit.entity.Player | ||
import kotlin.jvm.optionals.getOrElse | ||
|
||
class AntigriefHuskClaims : AntigriefIntegration { | ||
override fun canBreakBlock( | ||
player: Player, | ||
block: Block | ||
): Boolean { | ||
val api = HuskClaimsAPI.getInstance() ?: return true | ||
|
||
val user = api.getOnlineUser(player.uniqueId) ?: return true | ||
|
||
return api.isOperationAllowed( | ||
Operation.of( | ||
user, | ||
OperationType.BLOCK_BREAK, | ||
Position.at( | ||
block.x.toDouble(), | ||
block.y.toDouble(), | ||
block.z.toDouble(), | ||
api.getWorld(block.location.world.name) | ||
), | ||
true | ||
) | ||
) | ||
} | ||
|
||
override fun canCreateExplosion( | ||
player: Player, | ||
location: Location | ||
): Boolean { | ||
val api = HuskClaimsAPI.getInstance() ?: return true | ||
|
||
val user = api.getOnlineUser(player.uniqueId) ?: return true | ||
|
||
return api.isOperationAllowed( | ||
Operation.of( | ||
user, | ||
OperationType.EXPLOSION_DAMAGE_ENTITY, | ||
Position.at( | ||
location.x, | ||
location.y, | ||
location.z, | ||
api.getWorld(location.world.name) | ||
), | ||
true | ||
) | ||
) | ||
} | ||
|
||
override fun canPlaceBlock( | ||
player: Player, | ||
block: Block | ||
): Boolean { | ||
val api = HuskClaimsAPI.getInstance() ?: return true | ||
|
||
val user = api.getOnlineUser(player.uniqueId) ?: return true | ||
|
||
return api.isOperationAllowed( | ||
Operation.of( | ||
user, | ||
OperationType.BLOCK_PLACE, | ||
Position.at( | ||
block.x.toDouble(), | ||
block.y.toDouble(), | ||
block.z.toDouble(), | ||
api.getWorld(block.location.world.name) | ||
), | ||
true | ||
) | ||
) | ||
} | ||
|
||
override fun canInjure( | ||
player: Player, | ||
victim: LivingEntity | ||
): Boolean { | ||
val api = HuskClaimsAPI.getInstance() ?: return true | ||
|
||
val user = api.getOnlineUser(player.uniqueId) ?: return true | ||
|
||
return api.isOperationAllowed( | ||
Operation.of( | ||
user, | ||
when (victim) { | ||
is Monster -> OperationType.PLAYER_DAMAGE_MONSTER | ||
is Player -> OperationType.PLAYER_DAMAGE_PLAYER | ||
else -> OperationType.PLAYER_DAMAGE_ENTITY | ||
}, | ||
Position.at( | ||
victim.x, | ||
victim.y, | ||
victim.z, | ||
api.getWorld(victim.location.world.name) | ||
), | ||
true | ||
) | ||
) | ||
} | ||
|
||
override fun canPickupItem(player: Player, location: Location): Boolean { | ||
return true | ||
} | ||
|
||
override fun getPluginName(): String { | ||
return "HuskClaims" | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is AntigriefIntegration) { | ||
return false | ||
} | ||
|
||
return other.pluginName == this.pluginName | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return this.pluginName.hashCode() | ||
} | ||
} |
Oops, something went wrong.