Skip to content

Commit

Permalink
Prevent threading errors in debug Submit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 21, 2013
1 parent 7572f06 commit cb9c81b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.JSONException;


Expand Down Expand Up @@ -704,18 +705,31 @@ public void chatbot(CommandContext args, CommandSender sender, NPC npc) throws C
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 {
public void submit(CommandContext args, final 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;
Messaging.send(sender, ChatColor.GREEN + "Submitting...");
DebugSubmit submit = new DebugSubmit();
submit.sender = sender;
final DebugSubmit submit = new DebugSubmit();
submit.recording = dB.Recording;
dB.Recording = "";
submit.start();
BukkitRunnable task = new BukkitRunnable() {
public void run() {
if (!submit.isAlive()) {
if (submit.Result == null) {
Messaging.send(sender, ChatColor.RED + "Error while submitting.");
}
else {
Messaging.send(sender, ChatColor.GREEN + "Successfully submitted to http://mcmonkey4eva.dyndns.org" + submit.Result);
}
this.cancel();
}
}
};
task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 20);
}

/*
Expand All @@ -739,6 +753,7 @@ public void debug(CommandContext args, CommandSender sender, NPC npc) throws Com
if (!dB.debugMode) dB.toggle();
dB.showScriptBuilder = !dB.showScriptBuilder;
} else if (args.hasFlag('r')) {
if (!dB.debugMode) dB.toggle();
dB.record = !dB.record;
dB.Recording = "";
} else dB.toggle();
Expand Down
@@ -1,9 +1,7 @@
package net.aufdemrand.denizen.utilities.debugging;

import net.citizensnpcs.api.util.Messaging;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand All @@ -12,8 +10,8 @@
import java.net.URLEncoder;

public class DebugSubmit extends Thread {
public CommandSender sender;
public String recording;
public String Result = null;
@Override
public void run() {
try {
Expand All @@ -29,14 +27,13 @@ public void run() {
+ "&pastecontents=" + 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());
Result = in.readLine();
in.close();
}
catch (Exception e) {
if (dB.showStackTraces) {
e.printStackTrace();
}
Messaging.send(sender, ChatColor.RED + "Error while submitting.");
}
}
}

0 comments on commit cb9c81b

Please sign in to comment.