Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb3efac
commit 522efd8
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
package net.aufdemrand.denizen; | ||
|
||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLEncoder; | ||
import java.util.*; | ||
|
||
import net.aufdemrand.denizen.listeners.AbstractListener; | ||
|
@@ -697,13 +703,52 @@ public void chatbot(CommandContext args, CommandSender sender, NPC npc) throws C | |
} | ||
|
||
|
||
/* | ||
* DENIZEN SUBMIT | ||
*/ | ||
@Command( | ||
aliases = { "denizen" }, usage = "submit", | ||
desc = "Submits recorded logs triggered by /denizen debug -r", modifiers = { "submit" }, | ||
min = 1, max = 3, permission = "denizen.submit") | ||
public void submit(CommandContext args, CommandSender sender, NPC npc) throws CommandException { | ||
if (!dB.record) { | ||
Messaging.send(sender, ChatColor.RED + "Use /denizen debug -r to record debug information to be submitted"); | ||
return; | ||
} | ||
dB.record = false; | ||
try { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mcmonkey4eva
Author
Member
|
||
URL url = new URL("http://mcmonkey4eva.dyndns.org/paste"); | ||
HttpURLConnection uc = (HttpURLConnection) url.openConnection(); | ||
uc.setDoInput(true); | ||
uc.setDoOutput(true); | ||
uc.setConnectTimeout(10000); // Max 10 seconds - don't crash a server if the pastebin is down! | ||
uc.connect(); | ||
uc.getOutputStream().write( | ||
("postid=pastetext&pastetype=log" | ||
+ "&response=micro&pastetitle=Denizen+Debug+Logs+From+" + URLEncoder.encode(Bukkit.getServer().getMotd().replace(ChatColor.COLOR_CHAR, (char)0x01)) | ||
+ "&pastecontents=" + dB.Recording) | ||
.getBytes("UTF-8")); | ||
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream())); | ||
Messaging.send(sender, ChatColor.GREEN + "Successfully submitted to http://mcmonkey4eva.dyndns.org" + in.readLine()); | ||
in.close(); | ||
dB.Recording = ""; | ||
} | ||
catch (Exception e) { | ||
if (dB.showStackTraces) { | ||
e.printStackTrace(); | ||
} | ||
dB.Recording = ""; | ||
Messaging.send(sender, ChatColor.RED + "Error while submitting."); | ||
} | ||
} | ||
|
||
/* | ||
* DENIZEN DEBUG | ||
*/ | ||
@Command( | ||
aliases = { "denizen" }, usage = "debug", | ||
desc = "Toggles debug mode for Denizen.", modifiers = { "debug", "de", "db" }, | ||
min = 1, max = 3, permission = "denizen.debug", flags = "sceb") | ||
min = 1, max = 3, permission = "denizen.debug", flags = "scebr") | ||
public void debug(CommandContext args, CommandSender sender, NPC npc) throws CommandException { | ||
if (args.hasFlag('s')) { | ||
if (!dB.debugMode) dB.toggle(); | ||
|
@@ -717,10 +762,13 @@ public void debug(CommandContext args, CommandSender sender, NPC npc) throws Com | |
} else if (args.hasFlag('b')) { | ||
if (!dB.debugMode) dB.toggle(); | ||
dB.showScriptBuilder = !dB.showScriptBuilder; | ||
} else if (args.hasFlag('r')) { | ||
dB.record = !dB.record; | ||
dB.Recording = ""; | ||
} else dB.toggle(); | ||
|
||
Messaging.send(sender, ChatColor.YELLOW + "Denizen debugger is " + (dB.debugMode ? | ||
((dB.showStackTraces) ? "enabled and showing stack-traces." : "enabled.") : "disabled.")); | ||
((dB.showStackTraces) ? "enabled and showing stack-traces." : "enabled.") : "disabled.") + (dB.record ? " (Recording Active)": "")); | ||
} | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import java.net.URLEncoder; | ||
import java.util.Calendar; | ||
|
||
/** | ||
* Preferred method of outputting debugger information with Denizen and | ||
|
@@ -59,6 +61,8 @@ public class dB { | |
public static boolean showScriptBuilder = false; | ||
public static boolean showColor = true; | ||
public static boolean showEventsFiring = false; | ||
public static boolean record = false; | ||
public static String Recording = ""; | ||
|
||
/** | ||
* Can be used with echoDebug(...) to output a header, footer, | ||
|
@@ -132,9 +136,26 @@ public static void sendMessage(String string) { | |
} // 16:05:06 [INFO] | ||
} | ||
// Send buffer to the player | ||
dB.Recording += URLEncoder.encode(getDate() + " [INFO] " + buffer.replace(ChatColor.COLOR_CHAR, (char)0x01) + "\n"); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
if (showColor) | ||
commandSender.sendMessage(buffer); | ||
else commandSender.sendMessage(ChatColor.stripColor(buffer)); | ||
|
||
|
||
} | ||
|
||
static String getDate() { | ||
Calendar calendar = Calendar.getInstance(); | ||
This comment has been minimized.
Sorry, something went wrong.
fullwall
Contributor
|
||
int h = calendar.get(Calendar.HOUR_OF_DAY); | ||
int m = calendar.get(Calendar.MINUTE); | ||
int s = calendar.get(Calendar.SECOND); | ||
String toret = ""; | ||
if (h < 10) toret += "0" + h; else toret += h; | ||
toret += ":"; | ||
if (m < 10) toret += "0" + m; else toret += m; | ||
toret += ":"; | ||
if (s < 10) toret += "0" + s; else toret += s; | ||
return toret; | ||
} | ||
} | ||
|
||
|
URL requests should be in a separate thread.