Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@narrowtux
Created September 24, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narrowtux/3778394 to your computer and use it in GitHub Desktop.
Save narrowtux/3778394 to your computer and use it in GitHub Desktop.
Endless event-style methods for Components
public class ComponentHolder {
// ...
public void onEvent(String methodName) {
for (Component c:getComponents()) {
if (c.getClass().hasMethod(methodName)) {
c.getClass().getMethod(methodName).execute(c);
}
}
}
// ...
}
public class GuiComponent extends Component {
public void onBuy() {
updateGui();
}
}
public class TradeComponent extends Component {
@Override
public void onTick() {
if (someCondition) {
getHolder().onEvent("onBuy");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment