Skip to content

Commit

Permalink
Version 6.7
Browse files Browse the repository at this point in the history
Move to the goo.gl URL shortener for better reliability.
  • Loading branch information
LeeMcNeil committed May 20, 2014
1 parent d5cbb2f commit 50abf1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Use of http://api.buycraft.net is only for this plugin and integrating Buycraft

---- CHANGE LOG ------------------------------------------------------------

Version 6.7

- Moved to a different URL shortener for better reliability.

Version 6.6

- Bug fixes
Expand Down
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Buycraft
main: net.buycraft.Plugin
version: 6.6
author: Tebex Technologies Ltd
version: 6.7
author: Tebex Limited
website: http://buycraft.net
commands:
ec:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Buycraft-Plugin</groupId>
<artifactId>Buycraft</artifactId>
<version>6.6</version>
<version>6.7</version>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}_${project.version}</finalName>
Expand Down
9 changes: 9 additions & 0 deletions src/net/buycraft/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public JSONObject categoriesAction() {

return call(apiCallParams);
}

public JSONObject urlAction(String url) {
HashMap<String, String> apiCallParams = new HashMap<String, String>();

apiCallParams.put("action", "url");
apiCallParams.put("url", url);

return call(apiCallParams);
}

public JSONObject packagesAction() {
HashMap<String, String> apiCallParams = new HashMap<String, String>();
Expand Down
16 changes: 7 additions & 9 deletions src/net/buycraft/tasks/VisitLinkTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void call(Player player, String URL) {
private VisitLinkTask(String playerName, String URL) {
try {
this.playerName = playerName;
this.URL = "http://is.gd/create.php?format=json&url=" + URLEncoder.encode(URL, "UTF-8");
this.URL = URLEncoder.encode(URL, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
ReportTask.setLastException(e);
Expand All @@ -34,23 +34,21 @@ private VisitLinkTask(String playerName, String URL) {
public void run() {
Player player = Bukkit.getPlayerExact(playerName);
try {
String httpResponse = getApi().HttpRequest(URL);

if (httpResponse != null) {
JSONObject jsonResponse = new JSONObject(httpResponse);

if (jsonResponse.has("shorturl")) {
JSONObject jsonResponse = getApi().urlAction(URL).getJSONObject("payload");

if (jsonResponse != null) {
if (jsonResponse.has("url") && !jsonResponse.isNull("url")) {

if (player != null) {
player.sendMessage(new String[] {Chat.header(), Chat.seperator(),
Chat.seperator() + ChatColor.GREEN + getLanguage().getString("pleaseVisit") + ":",
Chat.seperator(), Chat.seperator() + jsonResponse.getString("shorturl"),
Chat.seperator(), Chat.seperator() + jsonResponse.getString("url"),
Chat.seperator(), Chat.seperator() + ChatColor.RED + getLanguage().getString("turnChatBackOn"), Chat.seperator(), Chat.footer()});
}

disableChat(playerName);

getLogger().info("Generated short URL " + jsonResponse.getString("shorturl") + ".");
getLogger().info("Generated short URL " + jsonResponse.getString("url") + ".");

return;
} else {
Expand Down

0 comments on commit 50abf1c

Please sign in to comment.