mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 03:39:37 +00:00 
			
		
		
		
	Add gameplay feature.
This commit is contained in:
		@ -3,13 +3,13 @@ package cloud.kubelet.foundation.core
 | 
				
			|||||||
import cloud.kubelet.foundation.core.abstraction.FoundationPlugin
 | 
					import cloud.kubelet.foundation.core.abstraction.FoundationPlugin
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.backup.BackupFeature
 | 
					import cloud.kubelet.foundation.core.features.backup.BackupFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.dev.DevFeature
 | 
					import cloud.kubelet.foundation.core.features.dev.DevFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.endergrief.EndergriefFeature
 | 
					import cloud.kubelet.foundation.core.features.gameplay.GameplayFeature
 | 
				
			||||||
 | 
					import cloud.kubelet.foundation.core.features.persist.PersistenceFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.player.PlayerFeature
 | 
					import cloud.kubelet.foundation.core.features.player.PlayerFeature
 | 
				
			||||||
 | 
					import cloud.kubelet.foundation.core.features.scheduler.SchedulerFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.stats.StatsFeature
 | 
					import cloud.kubelet.foundation.core.features.stats.StatsFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.update.UpdateFeature
 | 
					import cloud.kubelet.foundation.core.features.update.UpdateFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.world.WorldFeature
 | 
					import cloud.kubelet.foundation.core.features.world.WorldFeature
 | 
				
			||||||
import cloud.kubelet.foundation.core.features.persist.PersistenceFeature
 | 
					 | 
				
			||||||
import cloud.kubelet.foundation.core.features.scheduler.SchedulerFeature
 | 
					 | 
				
			||||||
import org.koin.dsl.module
 | 
					import org.koin.dsl.module
 | 
				
			||||||
import java.nio.file.Path
 | 
					import java.nio.file.Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -44,11 +44,11 @@ class FoundationCorePlugin : FoundationPlugin() {
 | 
				
			|||||||
    PersistenceFeature(),
 | 
					    PersistenceFeature(),
 | 
				
			||||||
    BackupFeature(),
 | 
					    BackupFeature(),
 | 
				
			||||||
    DevFeature(),
 | 
					    DevFeature(),
 | 
				
			||||||
 | 
					    GameplayFeature(),
 | 
				
			||||||
    PlayerFeature(),
 | 
					    PlayerFeature(),
 | 
				
			||||||
    StatsFeature(),
 | 
					    StatsFeature(),
 | 
				
			||||||
    UpdateFeature(),
 | 
					    UpdateFeature(),
 | 
				
			||||||
    WorldFeature(),
 | 
					    WorldFeature(),
 | 
				
			||||||
    EndergriefFeature(),
 | 
					 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun createModule() = module {
 | 
					  override fun createModule() = module {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,21 +0,0 @@
 | 
				
			|||||||
package cloud.kubelet.foundation.core.features.endergrief
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import cloud.kubelet.foundation.core.abstraction.Feature
 | 
					 | 
				
			||||||
import org.bukkit.entity.EntityType
 | 
					 | 
				
			||||||
import org.bukkit.event.EventHandler
 | 
					 | 
				
			||||||
import org.bukkit.event.EventPriority
 | 
					 | 
				
			||||||
import org.bukkit.event.entity.EntityChangeBlockEvent
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class EndergriefFeature : Feature() {
 | 
					 | 
				
			||||||
  override fun enable() {
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  override fun disable() {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  @EventHandler(priority = EventPriority.HIGHEST)
 | 
					 | 
				
			||||||
  fun onEntityChangeBlock(event: EntityChangeBlockEvent) {
 | 
					 | 
				
			||||||
    if (event.entity.type == EntityType.ENDERMAN) {
 | 
					 | 
				
			||||||
      event.isCancelled = true
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					package cloud.kubelet.foundation.core.features.gameplay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kotlinx.serialization.Serializable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Serializable
 | 
				
			||||||
 | 
					data class GameplayConfig(
 | 
				
			||||||
 | 
					  val mobs: MobsConfig,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Serializable
 | 
				
			||||||
 | 
					data class MobsConfig(
 | 
				
			||||||
 | 
					  val disableEndermanGriefing: Boolean,
 | 
				
			||||||
 | 
					  val disableFreezeDamage: Boolean,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					package cloud.kubelet.foundation.core.features.gameplay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cloud.kubelet.foundation.core.FoundationCorePlugin
 | 
				
			||||||
 | 
					import cloud.kubelet.foundation.core.Util
 | 
				
			||||||
 | 
					import cloud.kubelet.foundation.core.abstraction.Feature
 | 
				
			||||||
 | 
					import com.charleskorn.kaml.Yaml
 | 
				
			||||||
 | 
					import org.bukkit.entity.EntityType
 | 
				
			||||||
 | 
					import org.bukkit.entity.Mob
 | 
				
			||||||
 | 
					import org.bukkit.event.EventHandler
 | 
				
			||||||
 | 
					import org.bukkit.event.EventPriority
 | 
				
			||||||
 | 
					import org.bukkit.event.entity.EntityChangeBlockEvent
 | 
				
			||||||
 | 
					import org.bukkit.event.entity.EntityDamageEvent
 | 
				
			||||||
 | 
					import org.koin.core.component.inject
 | 
				
			||||||
 | 
					import org.koin.dsl.module
 | 
				
			||||||
 | 
					import kotlin.io.path.inputStream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GameplayFeature : Feature() {
 | 
				
			||||||
 | 
					  private val config by inject<GameplayConfig>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun enable() {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun disable() {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun module() = module {
 | 
				
			||||||
 | 
					    single {
 | 
				
			||||||
 | 
					      val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
 | 
				
			||||||
 | 
					        plugin.slF4JLogger,
 | 
				
			||||||
 | 
					        plugin.pluginDataPath,
 | 
				
			||||||
 | 
					        "gameplay.yaml",
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      return@single Yaml.default.decodeFromStream(
 | 
				
			||||||
 | 
					        GameplayConfig.serializer(),
 | 
				
			||||||
 | 
					        configPath.inputStream()
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @EventHandler(priority = EventPriority.HIGHEST)
 | 
				
			||||||
 | 
					  private fun onEntityDamage(e: EntityDamageEvent) {
 | 
				
			||||||
 | 
					    // If freeze damage is disabled, cancel the event.
 | 
				
			||||||
 | 
					    if (config.mobs.disableFreezeDamage) {
 | 
				
			||||||
 | 
					      if (e.entity is Mob && e.cause == EntityDamageEvent.DamageCause.FREEZE) {
 | 
				
			||||||
 | 
					        e.isCancelled = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @EventHandler(priority = EventPriority.HIGHEST)
 | 
				
			||||||
 | 
					  private fun onEntityChangeBlock(event: EntityChangeBlockEvent) {
 | 
				
			||||||
 | 
					    // If enderman griefing is disabled, cancel the event.
 | 
				
			||||||
 | 
					    if (config.mobs.disableEndermanGriefing) {
 | 
				
			||||||
 | 
					      if (event.entity.type == EntityType.ENDERMAN) {
 | 
				
			||||||
 | 
					        event.isCancelled = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								foundation-core/src/main/resources/gameplay.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								foundation-core/src/main/resources/gameplay.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					# Configuration that allows fine-tuning of various gameplay aspects.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Settings which affect mob entities.
 | 
				
			||||||
 | 
					mobs:
 | 
				
			||||||
 | 
					  # Disable the ability for an Enderman to pick up blocks.
 | 
				
			||||||
 | 
					  # When set to true, an Enderman cannot pick up or place blocks. :(
 | 
				
			||||||
 | 
					  # When set to false, an Enderman is allowed to pick up blocks.
 | 
				
			||||||
 | 
					  disableEndermanGriefing: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # Disable freeze damage that occurs to all mobs.
 | 
				
			||||||
 | 
					  # Note: This does not impact players, that is still controlled with the freezeDamage game-rule.
 | 
				
			||||||
 | 
					  # When set to true, mobs will not take damage from freezing.
 | 
				
			||||||
 | 
					  # When set to false, mobs take damage from freezing.
 | 
				
			||||||
 | 
					  disableFreezeDamage: false
 | 
				
			||||||
		Reference in New Issue
	
	Block a user