Skip to content

Commit 0021e14

Browse files
committed
init
0 parents  commit 0021e14

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

pom.xml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.affinitydev</groupId>
8+
<artifactId>Blockify</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>Blockify</name>
13+
14+
<properties>
15+
<java.version>17</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<kotlin.version>1.9.0-RC</kotlin.version>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.jetbrains.kotlin</groupId>
24+
<artifactId>kotlin-maven-plugin</artifactId>
25+
<version>${kotlin.version}</version>
26+
<executions>
27+
<execution>
28+
<id>compile</id>
29+
<phase>compile</phase>
30+
<goals>
31+
<goal>compile</goal>
32+
</goals>
33+
<configuration>
34+
<sourceDirs>
35+
<source>src/main/java</source>
36+
<source>src/main/kotlin</source>
37+
</sourceDirs>
38+
</configuration>
39+
</execution>
40+
<execution>
41+
<id>test-compile</id>
42+
<phase>test-compile</phase>
43+
<goals>
44+
<goal>test-compile</goal>
45+
</goals>
46+
</execution>
47+
</executions>
48+
<configuration>
49+
<jvmTarget>1.8</jvmTarget>
50+
</configuration>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.8.1</version>
56+
<executions>
57+
<execution>
58+
<id>compile</id>
59+
<phase>compile</phase>
60+
<goals>
61+
<goal>compile</goal>
62+
</goals>
63+
</execution>
64+
<execution>
65+
<id>testCompile</id>
66+
<phase>test-compile</phase>
67+
<goals>
68+
<goal>testCompile</goal>
69+
</goals>
70+
</execution>
71+
</executions>
72+
<configuration>
73+
<source>${java.version}</source>
74+
<target>${java.version}</target>
75+
</configuration>
76+
</plugin>
77+
</plugins>
78+
<resources>
79+
<resource>
80+
<directory>src/main/resources</directory>
81+
<filtering>true</filtering>
82+
</resource>
83+
</resources>
84+
</build>
85+
86+
<repositories>
87+
<repository>
88+
<id>spigotmc-repo</id>
89+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
90+
</repository>
91+
<repository>
92+
<id>sonatype</id>
93+
<url>https://oss.sonatype.org/content/groups/public/</url>
94+
</repository>
95+
</repositories>
96+
97+
<dependencies>
98+
<dependency>
99+
<groupId>org.spigotmc</groupId>
100+
<artifactId>spigot-api</artifactId>
101+
<version>1.19.4-R0.1-SNAPSHOT</version>
102+
<scope>provided</scope>
103+
</dependency>
104+
<dependency>
105+
<groupId>org.jetbrains.kotlin</groupId>
106+
<artifactId>kotlin-stdlib-jdk8</artifactId>
107+
<version>${kotlin.version}</version>
108+
</dependency>
109+
<dependency>
110+
<groupId>org.jetbrains.kotlin</groupId>
111+
<artifactId>kotlin-test</artifactId>
112+
<version>${kotlin.version}</version>
113+
<scope>test</scope>
114+
</dependency>
115+
</dependencies>
116+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.affinitydev.blockify
2+
3+
import org.bukkit.Bukkit
4+
import org.bukkit.ChatColor
5+
import org.bukkit.Material
6+
import org.bukkit.event.EventHandler
7+
import org.bukkit.event.Listener
8+
import org.bukkit.event.block.BlockBreakEvent
9+
import org.bukkit.plugin.java.JavaPlugin
10+
11+
class Blockify : JavaPlugin(), Listener {
12+
private var lastNotification: Long = 0
13+
14+
override fun onEnable() {
15+
saveDefaultConfig()
16+
lastNotification = 0
17+
server.pluginManager.registerEvents(this, this)
18+
}
19+
20+
override fun onDisable() {
21+
}
22+
23+
@EventHandler
24+
fun onBlockMine(e: BlockBreakEvent) {
25+
val material = e.block.type
26+
val player = e.player
27+
if (isBlockInConfig(material) && isCooldownOver()) {
28+
for (p in Bukkit.getOnlinePlayers()) {
29+
var message : String? = config.getString("notification", "§c§l[!] §b%player% §7just mined §e%block%§7!")
30+
if (message != null) {
31+
message = message.replace("%player%", player.name)
32+
message = message.replace("%block%", material.toString().replace("_", " "))
33+
p.sendMessage(ChatColor.translateAlternateColorCodes('&', message))
34+
}
35+
}
36+
lastNotification = System.currentTimeMillis()
37+
}
38+
}
39+
40+
private fun isBlockInConfig(block: Material): Boolean {
41+
return config.getStringList("blocks").contains(block.toString())
42+
}
43+
44+
private fun isCooldownOver(): Boolean {
45+
return System.currentTimeMillis() - lastNotification > getCooldownFromConfig()
46+
}
47+
48+
private fun getCooldownFromConfig(): Long {
49+
return config.getLong("cooldown-in-ms", 2000)
50+
}
51+
}

src/main/resources/config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
blocks:
2+
- "DIAMOND_ORE"
3+
- "EMERALD_ORE"
4+
- "GOLD_ORE"
5+
notification: "§c§l[!] §b%player% §7just mined §e%block%§7!"
6+
cooldown-in-ms: 2000

src/main/resources/plugin.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: Blockify
2+
version: '${project.version}'
3+
main: org.affinitydev.blockify.Blockify
4+
api-version: 1.19

0 commit comments

Comments
 (0)