Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Nov 30, 2014
1 parent 5782279 commit 525dc06
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ If you get an error, please post it to https://gist.github.com/ and then post th
##Donate
[Donate with PayPal](https://www.paypal.com/cgi-bin/webscr?return=http%3A%2F%2Fdev.bukkit.org%2Fbukkit-plugins%2Fslack%2F&cn=Add+special+instructions+to+the+addon+author%28s%29&business=circuitsoft%40outlook.com&bn=PP-DonationsBF%3Abtn_donateCC_LG.gif%3ANonHosted&cancel_return=http%3A%2F%2Fdev.bukkit.org%2Fbukkit-plugins%2Fslack%2F&lc=US&item_name=Slack+%28from+Bukkit.org%29&cmd=_donations&rm=1&no_shipping=1&currency_code=USD)

##Source
https://github.com/CircuitSoftGroup/SlackBukkit
##Bukkit Dev
http://dev.bukkit.org/bukkit-plugins/slack/
Binary file removed Slack-1.1.0.jar
Binary file not shown.
Binary file added Slack.jar
Binary file not shown.
12 changes: 3 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.CircuitSoft.Slack</groupId>
<artifactId>Slack</artifactId>
<version>1.0</version>
<version>1.2.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.9-R0.2</version>
<version>1.8-R0.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>
99 changes: 84 additions & 15 deletions src/main/java/us/circuitsoft/slack/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
Expand All @@ -17,15 +20,15 @@

public class Slack extends JavaPlugin implements Listener {

private boolean setWebhook;
private boolean n;

@Override
public void onEnable() {
getLogger().info("Slack has been enabled.");
getServer().getPluginManager().registerEvents(this, this);
this.saveDefaultConfig();
setWebhook = !getConfig().getString("webhook").equals("https://hooks.slack.com/services/");
if (!setWebhook) {
updateConfig("1.2.0");
n = getConfig().getString("webhook").equals("https://hooks.slack.com/services/");
if (n) {
getLogger().severe("You have not set your webhook URL in the config!");
}
}
Expand All @@ -37,35 +40,70 @@ public void onDisable() {

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
payload('"' + event.getMessage() + '"', event.getPlayer().getName());
if (permCheck("slack.hide.chat", event.getPlayer())) {
payload('"' + event.getMessage() + '"', event.getPlayer().getName());
}
}

@EventHandler
public void onLogin(PlayerLoginEvent event) {
payload("logged in", event.getPlayer().getName());
if (permCheck("slack.hide.logout", event.getPlayer())) {
payload("logged in", event.getPlayer().getName());
}
}

@EventHandler
public void onQuit(PlayerQuitEvent event) {
payload("logged out", event.getPlayer().getName());
if(permCheck("slack.hide.logout", event.getPlayer())) {
payload("logged out", event.getPlayer().getName());
}
}

@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
payload(event.getMessage(), event.getPlayer().getName());
if (blacklist(event.getMessage()) && permCheck("slack.hide.command", event.getPlayer())) {
payload(event.getMessage(), event.getPlayer().getName());
}
}

public void payload(String m, String p) {
/**
* Send a message to Slack.
* @param m The message sent to Slack.
* @param p The name of the sender of the message sent to Slack.
* @return True if the message was successfully sent to Slack.
*/
public boolean payload(String m, String p) {
JSONObject j = new JSONObject();
j.put("text", m);
j.put("text", p + ": " + m);
j.put("username", p);
j.put("icon_url", "https://minotar.net/avatar/" + p + "/100.png");
j.put("icon_url", "https://cravatar.eu/helmhead/" + p + "/100.png");
String b = "payload=" + j.toJSONString();
post(b);
return post(b);
}

/**
* Send a message to Slack with a custom user icon.
* @param m The message sent to Slack.
* @param p The name of the sender of the message sent to Slack.
* @param i The URL of an image of the sender of the message sent to Slack. (recommended for non player messages).
* @return True if the message was successfully sent to Slack.
*/
public boolean payload(String m, String p, String i) {
if(permCheck("slack.hide.*", getServer().getPlayer(p))) {
JSONObject j = new JSONObject();
j.put("text", p + ": " + m);
j.put("username", p);
j.put("icon_url", i);
String b = "payload=" + j.toJSONString();
return post(b);
} else {
return false;
}
}

public void post(String b) {
if (!setWebhook) {
private boolean post(String b) {
int i = 0;
if (n) {
getLogger().severe("You have not set your webhook URL in the config!");
} else {
try {
Expand All @@ -77,7 +115,7 @@ public void post(String b) {
B.write(b.getBytes("utf8"));
B.flush();
}
int i = C.getResponseCode();
i = C.getResponseCode();
String o = Integer.toString(i);
String c = C.getResponseMessage();
getLogger().log(Level.INFO, "{0} {1}", new Object[]{o, c});
Expand All @@ -88,5 +126,36 @@ public void post(String b) {
getLogger().log(Level.SEVERE, "IO exception: ", e);
}
}
return i == 200;
}

private boolean blacklist(String m) {
return !getConfig().getStringList("blacklist").contains(m);
}

private void updateConfig(String v) {
this.saveDefaultConfig();
if (getConfig().getString("v") == null ? v != null : !getConfig().getString("v").equals(v)) {
getConfig().options().copyDefaults(true);
getConfig().set("version", v);
}
this.saveConfig();
}

private boolean permCheck(String c, Player p) {
return !p.hasPermission(c);
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("slack")) {
this.reloadConfig();
sender.sendMessage("Slack has been reloaded.");
if (sender.getName() == null ? getServer().getConsoleSender().getName() != null : !sender.getName().equals(getServer().getConsoleSender().getName())) {
getServer().getConsoleSender().sendMessage("Slack has been reloaded.");
}
return true;
}
return false;
}
}
9 changes: 8 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
webhook: https://hooks.slack.com/services/
#The version. Do not touch this.
version: 1.2.0
#The incoming webhook URL you got from Slack.
webhook: https://hooks.slack.com/services/
#Commands that will not show up in Slack when they are executed.
blacklist:
- /login
- /register
30 changes: 29 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
name: Slack
version: 1.2.0
description: Link your server to Slack!
author: CircuitSoft
website: https://circuitsoft.us

main: us.circuitsoft.slack.Slack
version: 1.1.0

permissions:
slack.hide.command:
description: Does not post commands you do to Slack.
default: false
slack.reload:
description: Allows you to reload the plugin's config.
slack.hide.login:
description: Does not post to Slack when you login.
default: false
slack.hide.logout:
description: Does not post to Slack when you logout.
default: false
slack.hide.chat:
description: Does not post your chats to Slack.
default: false
slack.hide.*:
description: Does not post API events to Slack.
default: false
commands:
slack:
description: Reloads the plugin's config.
permission: slack.reload
usage: Do /slack to reload the plugin's config.

0 comments on commit 525dc06

Please sign in to comment.