Created
June 15, 2013 02:00
-
-
Save jmhertlein/5786470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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