Created
January 21, 2011 08:44
-
-
Save rmichela/789430 to your computer and use it in GitHub Desktop.
Sender example for the IPC bukkit plugin
This file contains 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
package bukkit.deltahat.IPC.TestA; | |
import java.io.File; | |
import java.util.Random; | |
import org.bukkit.Server; | |
import org.bukkit.command.Command; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.PluginDescriptionFile; | |
import org.bukkit.plugin.PluginLoader; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import bukkit.deltahat.IPC.IpcEvent; | |
import bukkit.deltahat.IPC.IpcMethod; | |
import bukkit.deltahat.IPC.IpcMethodResult; | |
import bukkit.deltahat.IPC.IpcRegistry; | |
public class TestA extends JavaPlugin{ | |
public TestA(PluginLoader pluginLoader, Server instance, | |
PluginDescriptionFile desc, File folder, File plugin, | |
ClassLoader cLoader) { | |
super(pluginLoader, instance, desc, folder, plugin, cLoader); | |
// TODO Auto-generated constructor stub | |
} | |
@Override | |
public void onDisable() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onEnable() { | |
IpcRegistry.publishIpcMethod(new Die3()); | |
System.out.println("[IPC Test A] Loaded."); | |
} | |
@Override | |
public boolean onCommand(Player player, Command cmd, String commandLabel, | |
String[] args) { | |
if(commandLabel.equals("divide")) | |
{ | |
player.sendMessage("Dividing " + args[1] + " and " + args[2]); | |
try | |
{ | |
IpcMethod divideMethod = IpcRegistry.getIpcMethod("IPCTestB", "Divide"); | |
int result = divideMethod.invoke(Integer.parseInt(args[1]), Integer.parseInt(args[2])); | |
player.sendMessage("Result: " + result); | |
} | |
catch(Exception e) | |
{ | |
player.sendMessage(e.getMessage()); | |
System.out.println("[IPC Test A] " + e.getMessage()); | |
} | |
} | |
if(commandLabel.equals("roll")) | |
{ | |
try | |
{ | |
IpcMethod[] dice = IpcRegistry.getAllIpcMethods("Roll"); | |
for(IpcMethod die : dice) | |
{ | |
player.sendMessage(die.getPluginName() + " rolled a " + die.<Integer>invoke()); | |
} | |
} | |
catch(Exception e) | |
{ | |
player.sendMessage(e.getMessage()); | |
System.out.println("[IPC Test A] " + e.getMessage()); | |
} | |
} | |
if(commandLabel.equals("shout")) | |
{ | |
System.out.println("[IPC Test A] Shouting"); | |
player.sendMessage("Shouting..."); | |
getServer().getPluginManager().callEvent(new IpcEvent("shoutEvent", player, args[1])); | |
} | |
return super.onCommand(player, cmd, commandLabel, args); | |
} | |
private class Die3 extends IpcMethod | |
{ | |
public Die3() | |
{ | |
super(TestA.this, "Roll"); | |
} | |
@Override | |
protected IpcMethodResult invokeImpl(Object[] args) | |
{ | |
return new IpcMethodResult("Die 3: " + (new Random()).nextInt()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment