Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Dec 8, 2014
1 parent 650fc24 commit 6fcffa2
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 254 deletions.
Binary file modified Slack.jar
Binary file not shown.
27 changes: 12 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.circuitsoft.slack</groupId>
<artifactId>Slack</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -13,27 +13,24 @@
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.8-SNAPSHOT</version>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord</artifactId>
<artifactId>bungeecord-api</artifactId>
<version>1.8-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
Expand Down
116 changes: 0 additions & 116 deletions src/main/java/us/circuitsoft/slack/Slack.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
package us.circuitsoft.slack;
package us.circuitsoft.slack.api;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONObject;
import static us.circuitsoft.slack.bukkit.SlackBukkit.getWebhook;

public class Poster extends BukkitRunnable {
/**
* Posts a message to Slack when using Bukkit.
*/
public class BukkitPoster extends BukkitRunnable {

private final JavaPlugin plugin;
private final String p;
private final String m;
private final String w;
private final String i;

public Poster (JavaPlugin plugin, String m, String p, String w, String i) {
this.plugin = plugin;
/**
* Prepares the message to send to Slack.
* @param m The message to send to Slack.
* @param p The username of the message to send to Slack.
* @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.
*/
public BukkitPoster (String m, String p, String i) {
this.p = p;
this.m = m;
this.w = w;
this.i = i;
this.w = getWebhook();
}

@Override
public void run() {
int res;
JSONObject j = new JSONObject();
j.put("text", p + ": " + m);
j.put("username", p);
Expand All @@ -48,17 +51,6 @@ public void run() {
B.flush();
}
C.disconnect();
res = C.getResponseCode();
String o = Integer.toString(res);
String c = C.getResponseMessage();
if (plugin.getConfig().getBoolean("debug")) {
plugin.getLogger().log(Level.INFO, "{0} {1}", new Object[]{o, c});
}
C.disconnect();
} catch (MalformedURLException e) {
plugin.getLogger().log(Level.SEVERE, "URL is not valid: ", e);
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "IO exception: ", e);
}
} catch (Exception e) {}
}
}
56 changes: 56 additions & 0 deletions src/main/java/us/circuitsoft/slack/api/BungeePoster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package us.circuitsoft.slack.api;

import java.io.BufferedOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.google.gson.JsonObject;

import static us.circuitsoft.slack.bungee.SlackBungee.getWebhook;

/**
* Posts a message to Slack when using Bungee.
*/
public class BungeePoster implements Runnable {

private final String p;
private final String m;
private final String w = getWebhook();
private final String i;

/**
* Prepares the message to send to Slack.
* @param m The message to send to Slack.
* @param p The username of the message to send to Slack.
* @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.
*/
public BungeePoster (String m, String p, String i) {
this.p = p;
this.m = m;
this.i = i;
}

@Override
public void run() {
JsonObject j = new JsonObject();
j.addProperty("text", p + ": " + m);
j.addProperty("username", p);
if (i == null) {
j.addProperty("icon_url", "https://cravatar.eu/helmhead/" + p + "/100.png");
} else {
j.addProperty("icon_url", i);
}
String b = "payload=" + j.toString();
try {
URL u = new URL(w);
HttpURLConnection C = (HttpURLConnection)u.openConnection();
C.setRequestMethod("POST");
C.setDoOutput(true);
try (BufferedOutputStream B = new BufferedOutputStream(C.getOutputStream())) {
B.write(b.getBytes("utf8"));
B.flush();
}
C.disconnect();
} catch (Exception e) {}
}
}
Loading

0 comments on commit 6fcffa2

Please sign in to comment.