Skip to content

Commit

Permalink
- Added CustomBiomesManager to add support for custom world generator…
Browse files Browse the repository at this point in the history
…s and their biomes

- Added a Terra generator integration for Custom Biomes
- Added an entity arg parser to set entity type for spawners (`item: spawner entity:zombie`)
  • Loading branch information
0ft3n committed Dec 3, 2023
1 parent 59dfeeb commit 67d7009
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 58 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ allprojects {

// Denizen
maven("https://maven.citizensnpcs.co/repo")

// FoliaLib
maven("https://nexuslite.gcnt.net/repos/other/")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.willfp.eco.core.integrations.custombiomes;

public class CustomBiome {
private final String name;

public CustomBiome(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.willfp.eco.core.integrations.custombiomes;

import com.willfp.eco.core.integrations.Integration;
import org.bukkit.Location;

import javax.annotation.Nullable;

/**
* Wrapper class for custom biome integrations.
*/
public interface CustomBiomesIntegration extends Integration {
/**
* Get a biome at given location. (Supports vanilla biomes as well)
*
* @param location The location to get the biome at.
* @return The found biome, null otherwise
*/
@Nullable
CustomBiome getBiome(Location location);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.willfp.eco.core.integrations.custombiomes;

import com.willfp.eco.core.Eco;
import com.willfp.eco.core.integrations.IntegrationRegistry;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class CustomBiomesManager {
/**
* A set of all registered biomes.
*/
private static final IntegrationRegistry<CustomBiomesIntegration> REGISTRY = new IntegrationRegistry<>();

/**
* Register a new biomes integration.
*
* @param biomesIntegration The biomes integration to register.
*/
public static void register(@NotNull final CustomBiomesIntegration biomesIntegration) {
if (biomesIntegration instanceof Listener) {
Eco.get().getEcoPlugin().getEventManager().registerListener((Listener) biomesIntegration);
}
REGISTRY.register(biomesIntegration);
}

@Nullable
public static CustomBiome getBiomeAt(@NotNull Location location) {
World world = location.getWorld();

if (world == null) {
return null;
}

Biome vanilla = world.getBiome(location);

if (vanilla.name().equalsIgnoreCase("custom")) {
for (CustomBiomesIntegration integration : REGISTRY) {
CustomBiome biome = integration.getBiome(location);

if (biome != null) {
return biome;
}
}

return null;
} else {
return new CustomBiome(vanilla.name());
}
}

private CustomBiomesManager() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}
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
}
}
2 changes: 2 additions & 0 deletions eco-core/core-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
compileOnly("com.denizenscript:denizen:1.2.7-SNAPSHOT") {
exclude(group = "*", module = "*")
}
compileOnly("com.dfsek.terra:common:6.4.1-BETA+3aef97738")


compileOnly(fileTree("../../lib") {
include("*.jar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.willfp.eco.core.integrations.IntegrationLoader
import com.willfp.eco.core.integrations.afk.AFKManager
import com.willfp.eco.core.integrations.anticheat.AnticheatManager
import com.willfp.eco.core.integrations.antigrief.AntigriefManager
import com.willfp.eco.core.integrations.custombiomes.CustomBiomesManager
import com.willfp.eco.core.integrations.customentities.CustomEntitiesManager
import com.willfp.eco.core.integrations.customitems.CustomItemsManager
import com.willfp.eco.core.integrations.economy.EconomyManager
Expand All @@ -22,34 +23,8 @@ import com.willfp.eco.core.particle.Particles
import com.willfp.eco.core.price.Prices
import com.willfp.eco.internal.data.MavenVersionToStringAdapter
import com.willfp.eco.internal.data.VersionToStringAdapter
import com.willfp.eco.internal.entities.EntityArgParserAdult
import com.willfp.eco.internal.entities.EntityArgParserAttackDamage
import com.willfp.eco.internal.entities.EntityArgParserAttackSpeed
import com.willfp.eco.internal.entities.EntityArgParserBaby
import com.willfp.eco.internal.entities.EntityArgParserCharged
import com.willfp.eco.internal.entities.EntityArgParserEquipment
import com.willfp.eco.internal.entities.EntityArgParserExplosionRadius
import com.willfp.eco.internal.entities.EntityArgParserFlySpeed
import com.willfp.eco.internal.entities.EntityArgParserFollowRange
import com.willfp.eco.internal.entities.EntityArgParserHealth
import com.willfp.eco.internal.entities.EntityArgParserJumpStrength
import com.willfp.eco.internal.entities.EntityArgParserKnockback
import com.willfp.eco.internal.entities.EntityArgParserKnockbackResistance
import com.willfp.eco.internal.entities.EntityArgParserName
import com.willfp.eco.internal.entities.EntityArgParserNoAI
import com.willfp.eco.internal.entities.EntityArgParserSilent
import com.willfp.eco.internal.entities.EntityArgParserSize
import com.willfp.eco.internal.entities.EntityArgParserSpawnReinforcements
import com.willfp.eco.internal.entities.EntityArgParserSpeed
import com.willfp.eco.internal.items.ArgParserColor
import com.willfp.eco.internal.items.ArgParserCustomModelData
import com.willfp.eco.internal.items.ArgParserEnchantment
import com.willfp.eco.internal.items.ArgParserFlag
import com.willfp.eco.internal.items.ArgParserHead
import com.willfp.eco.internal.items.ArgParserName
import com.willfp.eco.internal.items.ArgParserTexture
import com.willfp.eco.internal.items.ArgParserTrim
import com.willfp.eco.internal.items.ArgParserUnbreakable
import com.willfp.eco.internal.entities.*
import com.willfp.eco.internal.items.*
import com.willfp.eco.internal.lookup.SegmentParserGroup
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
import com.willfp.eco.internal.particle.ParticleFactoryRGB
Expand All @@ -69,37 +44,11 @@ import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorListener
import com.willfp.eco.internal.spigot.gui.GUIListener
import com.willfp.eco.internal.spigot.integrations.afk.AFKIntegrationCMI
import com.willfp.eco.internal.spigot.integrations.afk.AFKIntegrationEssentials
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatAAC
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatAlice
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatMatrix
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatNCP
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatSpartan
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatVulcan
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefBentoBox
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV10
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV11
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCrashClaim
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefDeluxeCombat
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFabledSkyBlock
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFactionsUUID
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefGriefPrevention
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefIridiumSkyblock
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefKingdoms
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefLands
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefPvPManager
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefRPGHorses
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefSuperiorSkyblock2
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefTowny
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefWorldGuard
import com.willfp.eco.internal.spigot.integrations.anticheat.*
import com.willfp.eco.internal.spigot.integrations.antigrief.*
import com.willfp.eco.internal.spigot.integrations.custombiomes.CustomBiomesTerra
import com.willfp.eco.internal.spigot.integrations.customentities.CustomEntitiesMythicMobs
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsCustomCrafting
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsDenizen
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsExecutableItems
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsHeadDatabase
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsItemsAdder
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsMythicMobs
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsOraxen
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsScyther
import com.willfp.eco.internal.spigot.integrations.customitems.*
import com.willfp.eco.internal.spigot.integrations.customrecipes.CustomRecipeCustomCrafting
import com.willfp.eco.internal.spigot.integrations.economy.EconomyVault
import com.willfp.eco.internal.spigot.integrations.entitylookup.EntityLookupModelEngine
Expand Down Expand Up @@ -149,6 +98,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
Items.registerArgParser(ArgParserUnbreakable)
Items.registerArgParser(ArgParserName)
Items.registerArgParser(ArgParserHead)
Items.registerArgParser(ArgParserEntity)
if (Prerequisite.HAS_1_20.isMet) {
Items.registerArgParser(ArgParserTrim)
}
Expand Down Expand Up @@ -374,6 +324,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
}
},

// Biomes
IntegrationLoader("Terra") { CustomBiomesManager.register(CustomBiomesTerra()) },

// Placeholder
IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) },

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.willfp.eco.internal.spigot.integrations.custombiomes

import com.dfsek.terra.bukkit.world.BukkitAdapter
import com.willfp.eco.core.integrations.custombiomes.CustomBiome
import com.willfp.eco.core.integrations.custombiomes.CustomBiomesIntegration
import org.bukkit.Location

class CustomBiomesTerra: CustomBiomesIntegration {
override fun getPluginName(): String {
return "Terra"
}

override fun getBiome(location: Location?): CustomBiome? {
if (location == null || location.world == null) {
return null
}

val terraLocation = BukkitAdapter.adapt(location) ?: return null
val terraWorld = BukkitAdapter.adapt(location.world!!) ?: return null
val biomeProvider = terraWorld.biomeProvider ?: return null
val biome = biomeProvider.getBiome(terraLocation, terraWorld.seed) ?: return null

return CustomBiome(biome.id)
}
}
4 changes: 4 additions & 0 deletions eco-core/core-plugin/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ api-version: 1.19
load: STARTUP

dependencies:
- name: Terra
required: false
bootstrap: false

- name: ProtocolLib
required: false
bootstrap: false
Expand Down
1 change: 1 addition & 0 deletions eco-core/core-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors: [ Auxilor ]
website: willfp.com
load: STARTUP
softdepend:
- Terra
- ProtocolLib
- WorldGuard
- GriefPrevention
Expand Down

0 comments on commit 67d7009

Please sign in to comment.