Skip to content

Commit

Permalink
Fix server commands from IRC
Browse files Browse the repository at this point in the history
The dispatchCommand() method is not thread safe, and therefore should be
wrapped in a runnable and dispatched from a synchronized task. As well,
before, executing a command did not use getCommandSender(), instead
parsing the IRC nickname into a CommandSender, which causes problems if
your IRC nick is not the same as your ingame nick.

I also removed Eclipse specific files and added them to the gitignore,
as they aren't required for compilation and only clutter the required
code
  • Loading branch information
chyyran committed Apr 17, 2013
1 parent 2c42fcc commit 33bc0e2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
8 changes: 0 additions & 8 deletions .classpath

This file was deleted.

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.class
.classpath
.project

# Package Files #
*.jar
*.war
*.ear

target/
.settings/
17 changes: 0 additions & 17 deletions .project

This file was deleted.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>dynmap-repo</id>
<url>http://repo.mikeprimm.com/</url>
<id>dynmap-repo</id>
<url>http://repo.mikeprimm.com/</url>
</repository>
</repositories>

Expand Down
20 changes: 20 additions & 0 deletions src/com/Jdbye/BukkitIRCd/BukkitCommandExecutorRunnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.Jdbye.BukkitIRCd;

import org.bukkit.scheduler.BukkitRunnable;

public class BukkitCommandExecutorRunnable extends BukkitRunnable{

private String command;
private final BukkitIRCdPlugin instance;
public BukkitCommandExecutorRunnable(BukkitIRCdPlugin instance, String command){
this.command = command;
this.instance = instance;
}

public void run() {
instance.getServer().dispatchCommand(instance.getServer().getConsoleSender(), command);

}


}
5 changes: 3 additions & 2 deletions src/com/Jdbye/BukkitIRCd/IRCd.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;

import org.bukkit.scheduler.BukkitTask;
public class IRCd implements Runnable {


Expand Down Expand Up @@ -1602,7 +1602,8 @@ public static String join(String[] strArray, String delimiter, int start) {
public static boolean executeCommand(String command) {
try {
if ((commandSender != null) && (bukkitServer != null)) {
return bukkitServer.dispatchCommand(commandSender, convertColors(command, true));
BukkitTask commandTask = new BukkitCommandExecutorRunnable(BukkitIRCdPlugin.thePlugin,command).runTaskLater(BukkitIRCdPlugin.thePlugin,1L);
return true;
}
else return false;
} catch (Exception e) {
Expand Down

1 comment on commit 33bc0e2

@WizardCM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed issue #13

Please sign in to comment.