Skip to content

Commit 6fcffa2

Browse files
committed
1.4.0
1 parent 650fc24 commit 6fcffa2

File tree

14 files changed

+514
-254
lines changed

14 files changed

+514
-254
lines changed

Slack.jar

8.02 KB
Binary file not shown.

pom.xml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>us.circuitsoft.slack</groupId>
55
<artifactId>Slack</artifactId>
6-
<version>1.3.0</version>
6+
<version>1.4.0</version>
77
<packaging>jar</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -13,27 +13,24 @@
1313
<repositories>
1414
<repository>
1515
<id>bungeecord-repo</id>
16-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
16+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
17+
</repository>
18+
<repository>
19+
<id>bukkit-repo</id>
20+
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
1721
</repository>
1822
</repositories>
1923
<dependencies>
20-
<dependency>
21-
<groupId>org.bukkit</groupId>
22-
<artifactId>bukkit</artifactId>
23-
<version>1.8-R0.1</version>
24-
<type>jar</type>
25-
<scope>provided</scope>
26-
</dependency>
27-
<dependency>
28-
<groupId>net.md-5</groupId>
29-
<artifactId>bungeecord-api</artifactId>
30-
<version>1.8-SNAPSHOT</version>
24+
<dependency>
25+
<groupId>org.bukkit</groupId>
26+
<artifactId>bukkit</artifactId>
27+
<version>1.8-R0.1-SNAPSHOT</version>
3128
<type>jar</type>
3229
<scope>provided</scope>
3330
</dependency>
34-
<dependency>
31+
<dependency>
3532
<groupId>net.md-5</groupId>
36-
<artifactId>bungeecord</artifactId>
33+
<artifactId>bungeecord-api</artifactId>
3734
<version>1.8-SNAPSHOT</version>
3835
<type>jar</type>
3936
<scope>provided</scope>

src/main/java/us/circuitsoft/slack/Slack.java

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
package us.circuitsoft.slack;
1+
package us.circuitsoft.slack.api;
22

33
import java.io.BufferedOutputStream;
4-
import java.io.IOException;
54
import java.net.HttpURLConnection;
6-
import java.net.MalformedURLException;
75
import java.net.URL;
8-
import java.util.logging.Level;
9-
import org.bukkit.plugin.java.JavaPlugin;
106
import org.bukkit.scheduler.BukkitRunnable;
117
import org.json.simple.JSONObject;
8+
import static us.circuitsoft.slack.bukkit.SlackBukkit.getWebhook;
129

13-
public class Poster extends BukkitRunnable {
10+
/**
11+
* Posts a message to Slack when using Bukkit.
12+
*/
13+
public class BukkitPoster extends BukkitRunnable {
1414

15-
private final JavaPlugin plugin;
1615
private final String p;
1716
private final String m;
1817
private final String w;
1918
private final String i;
2019

21-
public Poster (JavaPlugin plugin, String m, String p, String w, String i) {
22-
this.plugin = plugin;
20+
/**
21+
* Prepares the message to send to Slack.
22+
* @param m The message to send to Slack.
23+
* @param p The username of the message to send to Slack.
24+
* @param i The image URL of the user that sends the message to Slack. Make this null if the username is a Minecraft player name.
25+
*/
26+
public BukkitPoster (String m, String p, String i) {
2327
this.p = p;
2428
this.m = m;
25-
this.w = w;
2629
this.i = i;
30+
this.w = getWebhook();
2731
}
2832

2933
@Override
3034
public void run() {
31-
int res;
3235
JSONObject j = new JSONObject();
3336
j.put("text", p + ": " + m);
3437
j.put("username", p);
@@ -48,17 +51,6 @@ public void run() {
4851
B.flush();
4952
}
5053
C.disconnect();
51-
res = C.getResponseCode();
52-
String o = Integer.toString(res);
53-
String c = C.getResponseMessage();
54-
if (plugin.getConfig().getBoolean("debug")) {
55-
plugin.getLogger().log(Level.INFO, "{0} {1}", new Object[]{o, c});
56-
}
57-
C.disconnect();
58-
} catch (MalformedURLException e) {
59-
plugin.getLogger().log(Level.SEVERE, "URL is not valid: ", e);
60-
} catch (IOException e) {
61-
plugin.getLogger().log(Level.SEVERE, "IO exception: ", e);
62-
}
54+
} catch (Exception e) {}
6355
}
6456
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package us.circuitsoft.slack.api;
2+
3+
import java.io.BufferedOutputStream;
4+
import java.net.HttpURLConnection;
5+
import java.net.URL;
6+
7+
import com.google.gson.JsonObject;
8+
9+
import static us.circuitsoft.slack.bungee.SlackBungee.getWebhook;
10+
11+
/**
12+
* Posts a message to Slack when using Bungee.
13+
*/
14+
public class BungeePoster implements Runnable {
15+
16+
private final String p;
17+
private final String m;
18+
private final String w = getWebhook();
19+
private final String i;
20+
21+
/**
22+
* Prepares the message to send to Slack.
23+
* @param m The message to send to Slack.
24+
* @param p The username of the message to send to Slack.
25+
* @param i The image URL of the user that sends the message to Slack. Make this null if the username is a Minecraft player name.
26+
*/
27+
public BungeePoster (String m, String p, String i) {
28+
this.p = p;
29+
this.m = m;
30+
this.i = i;
31+
}
32+
33+
@Override
34+
public void run() {
35+
JsonObject j = new JsonObject();
36+
j.addProperty("text", p + ": " + m);
37+
j.addProperty("username", p);
38+
if (i == null) {
39+
j.addProperty("icon_url", "https://cravatar.eu/helmhead/" + p + "/100.png");
40+
} else {
41+
j.addProperty("icon_url", i);
42+
}
43+
String b = "payload=" + j.toString();
44+
try {
45+
URL u = new URL(w);
46+
HttpURLConnection C = (HttpURLConnection)u.openConnection();
47+
C.setRequestMethod("POST");
48+
C.setDoOutput(true);
49+
try (BufferedOutputStream B = new BufferedOutputStream(C.getOutputStream())) {
50+
B.write(b.getBytes("utf8"));
51+
B.flush();
52+
}
53+
C.disconnect();
54+
} catch (Exception e) {}
55+
}
56+
}

0 commit comments

Comments
 (0)