Skip to content

Instantly share code, notes, and snippets.

@jmhertlein
Created June 15, 2013 02:00
Show Gist options
  • Save jmhertlein/5786470 to your computer and use it in GitHub Desktop.
Save jmhertlein/5786470 to your computer and use it in GitHub Desktop.
private void deleteTown(ObjectOutputStream oos, ObjectInputStream ois) throws IOException, ClassNotFoundException {
//receive arguments over socket
final String townName = (String) ois.readObject();
final FutureBoolean result = new FutureBoolean();
final Object callback = this;
//prepare a Runnable object to delete the town from the server's main thread
Runnable r = new Runnable() {
@Override
public void run() {
//save the result in a FutureBoolean
result.setValue(MCTowns.getTownManager().removeTown(townName));
//notify the calling object that we've finished
synchronized(callback) {
callback.notifyAll();
}
}
};
//tell the server's main thread to run this ASAP
Bukkit.getScheduler().scheduleSyncDelayedTask(p, r);
//wait for it to complete
synchronized(this) {
try {
this.wait();
} catch (InterruptedException ex) {}
}
//send the result back over the network
oos.writeObject(result.getValue());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment