First ideas of drunken miner
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# idea
|
||||
.idea/*
|
||||
# build sources
|
||||
target/*
|
||||
# spigot test server
|
||||
spigot/*
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 sh-edraft.de
|
||||
Copyright (c) 2023 sh-edraft.de
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
@@ -1,2 +1,26 @@
|
||||
# drunken_miner
|
||||
# spigot_ontime_handler
|
||||
|
||||
Spigot plugin to send Minecraft derivates to OnMemberJoin, OnMemberRemove & OnMessage to the KDB-API to be processed
|
||||
accordingly
|
||||
|
||||
## Execute
|
||||
|
||||
### Install dependencies:
|
||||
|
||||
Install ```spigot server``` in folder ```./spigot``` first!!
|
||||
|
||||
```bash
|
||||
mvn install
|
||||
```
|
||||
|
||||
### Build and Run the plugin:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
### Build only:
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/spigot" />
|
||||
</content>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>drunken_miner</artifactId>
|
||||
<groupId>de.sh-edraft</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>drunken_miner</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.code.style>official</kotlin.code.style>
|
||||
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<version>1.7.21</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-compiler</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20220924</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.okhttp</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>20120626</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>1.7.21</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<mainClass>OntimeHandlerPlugin</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
bash build.sh
|
||||
cp target/drunken_miner-*-SNAPSHOT.jar spigot/plugins
|
||||
cd spigot
|
||||
export PLUGIN_ENVIRONMENT=development
|
||||
java -Xms1G -Xmx8G -jar spigot.jar --nogui
|
||||
@@ -0,0 +1,47 @@
|
||||
package de.sh_edraft
|
||||
|
||||
import de.sh_edraft.commands.DebugCommand
|
||||
import de.sh_edraft.commands.DifficultyCommand
|
||||
import de.sh_edraft.commands.DisableCommand
|
||||
import de.sh_edraft.commands.EnableCommand
|
||||
import de.sh_edraft.events.BlockListener
|
||||
import de.sh_edraft.events.DimensionListener
|
||||
import de.sh_edraft.events.EntityListener
|
||||
import de.sh_edraft.events.PlayerListener
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
|
||||
open class DrunkenMiner() : JavaPlugin() {
|
||||
|
||||
|
||||
private lateinit var barkeeper: Barkeeper
|
||||
|
||||
override fun onEnable() {
|
||||
logger.info("DrunkenMiner enabled :D")
|
||||
|
||||
this.barkeeper = Barkeeper(logger)
|
||||
this.barkeeper.enableDebug(true)
|
||||
|
||||
server.pluginManager.registerEvents(BlockListener(barkeeper), this)
|
||||
server.pluginManager.registerEvents(PlayerListener(barkeeper), this)
|
||||
server.pluginManager.registerEvents(DimensionListener(barkeeper), this)
|
||||
server.pluginManager.registerEvents(EntityListener(barkeeper), this)
|
||||
getCommand("dmDifficulty")?.setExecutor(DifficultyCommand(barkeeper))
|
||||
getCommand("dmDebug")?.setExecutor(DebugCommand(barkeeper))
|
||||
getCommand("dmEnable")?.setExecutor(EnableCommand(barkeeper))
|
||||
getCommand("dmDisable")?.setExecutor(DisableCommand(barkeeper))
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
try {
|
||||
for (player in Bukkit.getOnlinePlayers()) {
|
||||
logger.info("Logout player ${player.displayName}")
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
logger.severe(ex.message)
|
||||
}
|
||||
|
||||
logger.info("DrunkenMiner disabled :(")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.sh_edraft.commands
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class DebugCommand(private val barkeeper: Barkeeper) : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (!sender.isOp) {
|
||||
sender.sendMessage("Permission denied")
|
||||
return false
|
||||
}
|
||||
this.barkeeper.enableDebug(!this.barkeeper.debug)
|
||||
sender.sendMessage("Debugger set to " + this.barkeeper.debug.toString())
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package de.sh_edraft.commands
|
||||
|
||||
import de.sh_edraft.model.Difficulty
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
|
||||
class DifficultyCommand(private val barkeeper: Barkeeper) : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (!sender.isOp) {
|
||||
sender.sendMessage("Permission denied")
|
||||
}
|
||||
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage("Usage: /mycommand <Comfy|Casual|Alcoholic>")
|
||||
return true
|
||||
}
|
||||
|
||||
val arg = args[0].lowercase()
|
||||
|
||||
when (arg) {
|
||||
"comfy" -> {
|
||||
sender.sendMessage("You selected Comfy!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Comfy)
|
||||
}
|
||||
"casual" -> {
|
||||
sender.sendMessage("You selected Casual!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Casual)
|
||||
}
|
||||
"alcoholic" -> {
|
||||
sender.sendMessage("You selected Alcoholic!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Alcoholic)
|
||||
}
|
||||
"1" -> {
|
||||
sender.sendMessage("You selected Comfy!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Comfy)
|
||||
}
|
||||
"2" -> {
|
||||
sender.sendMessage("You selected Casual!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Casual)
|
||||
}
|
||||
"3" -> {
|
||||
sender.sendMessage("You selected Alcoholic!")
|
||||
this.barkeeper.setDifficulty(Difficulty.Alcoholic)
|
||||
}
|
||||
else -> sender.sendMessage("Invalid argument! Use: Comfy(1), Casual(2), or Alcoholic(3).")
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.sh_edraft.commands
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class DisableCommand(private val barkeeper: Barkeeper) : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (!sender.isOp) {
|
||||
sender.sendMessage("Permission denied")
|
||||
return false
|
||||
}
|
||||
this.barkeeper.disable()
|
||||
sender.sendMessage("Disabled")
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.sh_edraft.commands
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class EnableCommand(private val barkeeper: Barkeeper) : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (!sender.isOp) {
|
||||
sender.sendMessage("Permission denied")
|
||||
return false
|
||||
}
|
||||
this.barkeeper.enable()
|
||||
sender.sendMessage("Enabled")
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.sh_edraft.events
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
|
||||
class BlockListener(
|
||||
private val barkeeper: Barkeeper
|
||||
) : Listener {
|
||||
@EventHandler
|
||||
fun onBlockBreak(e: BlockBreakEvent) {
|
||||
if (e.player.player == null) {
|
||||
return;
|
||||
}
|
||||
this.barkeeper.order(e, e.player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.sh_edraft.events
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.entity.PlayerDeathEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerPortalEvent
|
||||
|
||||
class DimensionListener(
|
||||
private val barkeeper: Barkeeper
|
||||
) : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onJoin(e: PlayerJoinEvent) {
|
||||
if (e.player.player == null) {
|
||||
return
|
||||
}
|
||||
this.barkeeper.sayHello(e.player)
|
||||
this.barkeeper.order(e, e.player)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onJoin(e: PlayerPortalEvent) {
|
||||
if (e.player.player == null) {
|
||||
return
|
||||
}
|
||||
this.barkeeper.order(e, e.player)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package de.sh_edraft.events
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.EnderDragon
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.entity.Wither
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import org.bukkit.event.entity.PlayerDeathEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
|
||||
class EntityListener(
|
||||
private val barkeeper: Barkeeper
|
||||
) : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onDeath(e: EntityDeathEvent) {
|
||||
// filter if entity is not a dragon or wither
|
||||
if (e.entity !is EnderDragon && e.entity !is Wither) {
|
||||
return
|
||||
}
|
||||
|
||||
if (e.entity.killer == null || e.entity.killer !is Player) {
|
||||
return
|
||||
}
|
||||
this.barkeeper.order(e, e.entity.killer as Player)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package de.sh_edraft.events
|
||||
|
||||
import de.sh_edraft.service.Barkeeper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
import org.bukkit.event.entity.PlayerDeathEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
|
||||
class PlayerListener(
|
||||
private val barkeeper: Barkeeper
|
||||
) : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onDamage(e: EntityDamageEvent) {
|
||||
if (e.entity !is Player) {
|
||||
return
|
||||
}
|
||||
this.barkeeper.order(e, e.entity as Player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onDeath(e: PlayerDeathEvent) {
|
||||
val player = e.entity.player ?: return;
|
||||
this.barkeeper.order(e, player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.sh_edraft.model
|
||||
|
||||
enum class Difficulty {
|
||||
Comfy,
|
||||
Casual,
|
||||
Alcoholic
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package de.sh_edraft.service
|
||||
|
||||
import de.sh_edraft.model.Difficulty
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Event
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import java.util.logging.Logger
|
||||
|
||||
|
||||
enum class AudienceType {
|
||||
SELF,
|
||||
ALL
|
||||
}
|
||||
|
||||
data class Serving(
|
||||
val amount: Int,
|
||||
val audience: AudienceType
|
||||
)
|
||||
|
||||
class Barkeeper(
|
||||
private val logger: Logger
|
||||
) {
|
||||
var debug: Boolean = false
|
||||
private var enabled: Boolean = false
|
||||
private var difficulty = Difficulty.Comfy
|
||||
|
||||
val drinksByEvent = mapOf(
|
||||
"EntityDamageEvent" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"PlayerDeathEvent" to Serving(amount = 1, audience = AudienceType.ALL),
|
||||
"PlayerJoinEvent" to Serving(amount = 1, audience = AudienceType.ALL),
|
||||
"entityOnDeath" to mapOf(
|
||||
"Wither" to Serving(amount = 2, audience = AudienceType.ALL),
|
||||
"EnderDragon" to Serving(amount = 3, audience = AudienceType.ALL)
|
||||
),
|
||||
"blockBreak" to mapOf(
|
||||
"ANCIENT_DEBRIS" to Serving(amount = 2, audience = AudienceType.ALL),
|
||||
|
||||
"LEGACY_DIAMOND_ORE" to Serving(amount = 1, audience = AudienceType.ALL),
|
||||
"DEEPSLATE_DIAMOND_ORE" to Serving(amount = 1, audience = AudienceType.ALL),
|
||||
"DIAMOND_ORE" to Serving(amount = 1, audience = AudienceType.ALL),
|
||||
|
||||
"LEGACY_IRON_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"DEEPSLATE_IRON_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"IRON_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
|
||||
"LEGACY_COAL_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"DEEPSLATE_COAL_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"COAL_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
|
||||
"LEGACY_GOLD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"DEEPSLATE_GOLD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"GOLD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
|
||||
"LEGACY_EMERALD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"DEEPSLATE_EMERALD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
"EMERALD_ORE" to Serving(amount = 1, audience = AudienceType.SELF),
|
||||
),
|
||||
)
|
||||
|
||||
fun enableDebug(debug: Boolean) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
fun enable() {
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
fun sayHello(p: Player) {
|
||||
p.sendMessage("Hello, I'm the Barkeeper! Hope you have a good time here :D\nHave plenty of drinks ready")
|
||||
}
|
||||
|
||||
fun setDifficulty(difficulty: Difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
fun order(sourceEvent: Event, sourcePlayer: Player) {
|
||||
if (!this.enabled) return;
|
||||
val serving = getDrinkAmount(sourceEvent) ?: return;
|
||||
|
||||
val toServeDrinkAmount = serving.amount * (difficulty.ordinal + 1);
|
||||
var message = "Drink $toServeDrinkAmount"
|
||||
|
||||
if (serving.audience == AudienceType.SELF) {
|
||||
val selfMessage = message
|
||||
val allMessage = "Player ${sourcePlayer.displayName} drinks $toServeDrinkAmount"
|
||||
|
||||
sourcePlayer.server.onlinePlayers.forEach { player ->
|
||||
if (player == sourcePlayer) {
|
||||
this.sendMessage(sourceEvent, player, selfMessage)
|
||||
return
|
||||
}
|
||||
this.sendMessage(sourceEvent, player, allMessage)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
message = "Everyone has to drink $toServeDrinkAmount"
|
||||
sourcePlayer.server.onlinePlayers.forEach { player ->
|
||||
this.sendMessage(sourceEvent, player, message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendMessage(sourceEvent: Event, player: Player, message: String) {
|
||||
var toSendMessage = message
|
||||
if (debug) {
|
||||
toSendMessage = sourceEvent.eventName + " $message"
|
||||
}
|
||||
player.sendMessage(toSendMessage)
|
||||
}
|
||||
|
||||
private fun getDrinkAmount(event: Event): Serving? {
|
||||
if (event is BlockBreakEvent) {
|
||||
logger.info("BlockBreakEvent " + event.block.type)
|
||||
val drinkByEvent = drinksByEvent["blockBreak"] ?: return null;
|
||||
val drink = (drinkByEvent as Map<String, Serving>)[event.block.type.name] ?: return null;
|
||||
return drink;
|
||||
}
|
||||
|
||||
if (event is EntityDeathEvent) {
|
||||
logger.info("EntityDeathEvent " + event.entity.name)
|
||||
val drinkByEvent = drinksByEvent["entityOnDeath"] ?: return null;
|
||||
val drink = (drinkByEvent as Map<String, Serving>)[event.entity.name] ?: return null;
|
||||
return drink;
|
||||
}
|
||||
|
||||
val drinkByEvent = drinksByEvent[event.eventName] ?: return null;
|
||||
if (drinkByEvent is Serving) {
|
||||
return drinkByEvent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
name: sh_edraft.DrunkenMiner
|
||||
version: 1.0
|
||||
api-version: '1.20.5'
|
||||
main: de.sh_edraft.DrunkenMiner
|
||||
|
||||
commands:
|
||||
dmDebug:
|
||||
description: 'DrunkenMiner toggle debug'
|
||||
usage: /<command>
|
||||
|
||||
dmDifficulty:
|
||||
description: 'DrunkenMiner difficulty'
|
||||
usage: "Usage: /<command> < Comfy(1) | Casual(2) | Alcoholic(3)>"
|
||||
|
||||
|
||||
dmEnable:
|
||||
description: 'DrunkenMiner enable'
|
||||
usage: /<command>
|
||||
|
||||
dmDisable:
|
||||
description: 'DrunkenMiner disable'
|
||||
usage: /<command>
|
||||
Reference in New Issue
Block a user