Skip to content

Commit a8047fd

Browse files
committed
Fixed port data type and implemented sending messages on player join/quit
1 parent 058fe64 commit a8047fd

5 files changed

Lines changed: 85 additions & 10 deletions

File tree

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,27 @@
4747
<plugins>
4848
<plugin>
4949
<groupId>org.apache.maven.plugins</groupId>
50-
<artifactId>maven-compiler-plugin</artifactId>
51-
<configuration>
52-
<source>1.8</source>
53-
<target>1.8</target>
54-
</configuration>
50+
<artifactId>maven-assembly-plugin</artifactId>
51+
<executions>
52+
<execution>
53+
<phase>package</phase>
54+
<goals>
55+
<goal>single</goal>
56+
</goals>
57+
<configuration>
58+
<archive>
59+
<manifest>
60+
<mainClass>
61+
nl.ordewittetafel.minecom_plugin.Main
62+
</mainClass>
63+
</manifest>
64+
</archive>
65+
<descriptorRefs>
66+
<descriptorRef>jar-with-dependencies</descriptorRef>
67+
</descriptorRefs>
68+
</configuration>
69+
</execution>
70+
</executions>
5571
</plugin>
5672
</plugins>
5773
</build>
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package nl.ordewittetafel.minecom_plugin;
22

33
import nl.ordewittetafel.minecom_plugin.listeners.ChatListener;
4+
import nl.ordewittetafel.minecom_plugin.listeners.JoinQuitListener;
45
import org.bukkit.Bukkit;
56
import org.bukkit.configuration.file.FileConfiguration;
67
import org.bukkit.plugin.java.JavaPlugin;
78

89
public class Main extends JavaPlugin {
10+
private FileConfiguration config;
11+
912
@Override
1013
public void onEnable() {
11-
FileConfiguration config = getConfig();
14+
config = getConfig();
1215
/*
13-
* The next config values may be changed according to your Discord bot setting in config.yml after the plugin
16+
* The next config values may be changed according to your Discord bot settings in config.yml after the plugin
1417
* has been run once
1518
*/
1619
config.addDefault(Constants.DC_BOT_IP_KEY, "127.0.0.1"); // The address of the Discord bot
17-
config.addDefault(Constants.DC_BOT_PORT_KEY, "500"); // The port of the Discord bot
20+
config.addDefault(Constants.DC_BOT_PORT_KEY, 500); // The port of the Discord bot
1821
config.options().copyDefaults(true);
1922
saveConfig();
2023

24+
Bukkit.getPluginManager().registerEvents(new JoinQuitListener(this), this);
2125
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
2226
}
2327
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package nl.ordewittetafel.minecom_plugin.listeners;
2+
3+
import nl.ordewittetafel.minecom_plugin.Constants;
4+
import nl.ordewittetafel.minecom_plugin.network.MessageTransmitter;
5+
import org.bukkit.configuration.file.FileConfiguration;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.Listener;
8+
import org.bukkit.event.player.PlayerJoinEvent;
9+
import org.bukkit.event.player.PlayerQuitEvent;
10+
import org.bukkit.plugin.java.JavaPlugin;
11+
import org.json.JSONObject;
12+
13+
import java.io.IOException;
14+
15+
public class JoinQuitListener implements Listener {
16+
private final JavaPlugin plugin;
17+
private final FileConfiguration config;
18+
19+
public JoinQuitListener(JavaPlugin plugin) {
20+
this.plugin = plugin;
21+
config = plugin.getConfig();
22+
}
23+
24+
@EventHandler
25+
public void onJoin(PlayerJoinEvent e) {
26+
JSONObject messageData = new JSONObject();
27+
messageData.put("message", e.getPlayer().getName() + " joined");
28+
29+
try {
30+
MessageTransmitter.transmit(
31+
config.getString(Constants.DC_BOT_IP_KEY),
32+
config.getInt(Constants.DC_BOT_PORT_KEY),
33+
messageData
34+
);
35+
} catch (IOException err) {
36+
err.printStackTrace();
37+
}
38+
}
39+
40+
@EventHandler
41+
public void onQuit(PlayerQuitEvent e) {
42+
JSONObject messageData = new JSONObject();
43+
messageData.put("message", e.getPlayer().getName() + " left");
44+
45+
try {
46+
MessageTransmitter.transmit(
47+
config.getString(Constants.DC_BOT_IP_KEY),
48+
config.getInt(Constants.DC_BOT_PORT_KEY),
49+
messageData
50+
);
51+
} catch (IOException err) {
52+
err.printStackTrace();
53+
}
54+
}
55+
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: MineCom-Plugin
2-
main: nl.ordewittetafel.minecom_plugin
2+
main: nl.ordewittetafel.minecom_plugin.Main
33
version: 1.0
44
author: Kelvin Bouma

0 commit comments

Comments
 (0)