use of io.xol.chunkstories.api.plugin.ChunkStoriesPlugin in project chunkstories by Hugobros3.
the class DefaultPluginManager method enablePlugins.
private void enablePlugins(LinkedList<PluginInformationImplementation> pluginsToInitialize) {
logger().info(pluginsToInitialize.size() + " plugins to initialize");
Deque<PluginInformationImplementation> order = new LinkedBlockingDeque<PluginInformationImplementation>();
// TODO sort plugins requirements (requires/before)
for (PluginInformationImplementation pluginInformation : pluginsToInitialize) {
order.add(pluginInformation);
}
// Loads each provided plugin
for (PluginInformationImplementation pluginInformation : order) {
try {
// Add commands support
for (Command command : pluginInformation.getCommands()) {
// Checks the command isn't already defined
if (commands.contains(command)) {
logger().warn("Plugin " + pluginInformation.getName() + " can't define the command " + command.getName() + " as it's already defined by another plugin.");
continue;
}
commands.add(command);
for (String alias : command.aliases()) if (commandsAliases.put(alias, command) != null)
logger().warn("Plugin " + pluginInformation + " tried to register alias " + alias + " for command " + command + ".");
}
// Instanciate the plugin after all
ChunkStoriesPlugin pluginInstance = pluginInformation.createInstance(pluginExecutionContext);
activePlugins.add(pluginInstance);
pluginInstance.onEnable();
} catch (PluginCreationException pce) {
logger().error("Couldn't create plugin " + pluginInformation + " : " + pce.getMessage());
pce.printStackTrace();
}
}
}
use of io.xol.chunkstories.api.plugin.ChunkStoriesPlugin in project chunkstories by Hugobros3.
the class ChatManager method processTextInput.
private void processTextInput(String input) {
String username = ingame.getGameWindow().getClient().username();
if (input.startsWith("/")) {
String chatMsg = input;
chatMsg = chatMsg.substring(1, chatMsg.length());
String cmdName = chatMsg.toLowerCase();
String[] args = {};
if (chatMsg.contains(" ")) {
cmdName = chatMsg.substring(0, chatMsg.indexOf(" "));
args = chatMsg.substring(chatMsg.indexOf(" ") + 1, chatMsg.length()).split(" ");
}
if (ingame.getGameWindow().getClient().getPluginManager().dispatchCommand(Client.getInstance().getPlayer(), cmdName, args)) {
if (sent.size() == 0 || !sent.get(0).equals(input)) {
sent.add(0, input);
sentMessages++;
}
return;
} else if (cmdName.equals("plugins")) {
String list = "";
Iterator<ChunkStoriesPlugin> i = ingame.getGameWindow().getClient().getPluginManager().activePlugins();
while (i.hasNext()) {
ChunkStoriesPlugin plugin = i.next();
list += plugin.getName() + (i.hasNext() ? ", " : "");
}
if (Client.getInstance().getWorld() instanceof WorldClientLocal)
insert("#00FFD0" + i + " active client [master] plugins : " + list);
else
insert("#74FFD0" + i + " active client [remote] plugins : " + list);
if (sent.size() == 0 || !sent.get(0).equals(input)) {
sent.add(0, input);
sentMessages++;
}
} else if (cmdName.equals("mods")) {
String list = "";
int i = 0;
for (Mod mod : Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods()) {
i++;
list += mod.getModInfo().getName() + (i == Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods().size() ? "" : ", ");
}
if (Client.getInstance().getWorld() instanceof WorldClientLocal)
insert("#FF0000" + i + " active client [master] mods : " + list);
else
insert("#FF7070" + i + " active client [remote] mods : " + list);
if (sent.size() == 0 || !sent.get(0).equals(input)) {
sent.add(0, input);
sentMessages++;
}
}
}
if (input.equals("/locclear")) {
chat.clear();
} else if (input.equals("I am Mr Debug")) {
// it was you this whole time
ClientLimitations.isDebugAllowed = true;
}
if (ingame.getGameWindow().getClient().getWorld() instanceof WorldClientRemote)
((WorldClientRemote) ingame.getGameWindow().getClient().getWorld()).getConnection().sendTextMessage("chat/" + input);
else
insert(ColorsTools.getUniqueColorPrefix(username) + username + "#FFFFFF > " + input);
System.out.println(username + " > " + input);
if (sent.size() == 0 || !sent.get(0).equals(input)) {
sent.add(0, input);
sentMessages++;
}
}
use of io.xol.chunkstories.api.plugin.ChunkStoriesPlugin in project chunkstories by Hugobros3.
the class DefaultPluginManager method disablePlugins.
@Override
public void disablePlugins() {
// Call onDisable for plugins
for (ChunkStoriesPlugin plugin : activePlugins) plugin.onDisable();
// Remove one by one each listener
for (Entry<EventListeners, RegisteredListener> e : registeredEventListeners.entrySet()) {
e.getKey().unRegisterListener(e.getValue());
}
// Remove registered commands
// TODO only remove plugins commands
commandsAliases.clear();
commands.clear();
// At last clear the plugins list
activePlugins.clear();
}
use of io.xol.chunkstories.api.plugin.ChunkStoriesPlugin in project chunkstories by Hugobros3.
the class InfoCommands method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command cmd, String[] arguments) {
if (cmd.getName().equals("uptime")) {
emitter.sendMessage("#00FFD0The server has been running for " + server.getUptime() + " seconds.");
return true;
} else if (cmd.getName().equals("info")) {
emitter.sendMessage("#00FFD0The server's ip is " + server.getPublicIp());
emitter.sendMessage("#00FFD0It's running version " + VersionInfo.version + " of the server software.");
emitter.sendMessage("#00FFD0" + server.getWorld());
emitter.sendMessage("#00FFD0" + Runtime.getRuntime().freeMemory() / 1024 / 1024 + "Mb used out of " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "Mb allocated");
return true;
} else if (cmd.getName().equals("help")) {
emitter.sendMessage("#00FFD0Avaible commands :");
emitter.sendMessage("#00FFD0" + " /plugins");
emitter.sendMessage("#00FFD0" + " /mods");
emitter.sendMessage("#00FFD0" + " /list");
emitter.sendMessage("#00FFD0" + " /info");
emitter.sendMessage("#00FFD0" + " /uptime");
for (Command command : server.getPluginManager().commands()) {
emitter.sendMessage("#00FFD0 /" + command.getName());
}
return true;
} else if (cmd.getName().equals("plugins")) {
String list = "";
Iterator<ChunkStoriesPlugin> i = server.getPluginManager().activePlugins();
while (i.hasNext()) {
ChunkStoriesPlugin plugin = i.next();
list += plugin.getName() + (i.hasNext() ? ", " : "");
}
emitter.sendMessage("#00FFD0" + i + " active server plugins : " + list);
return true;
} else if (cmd.getName().equals("mods")) {
String list = "";
int i = 0;
for (Mod csp : server.getContent().modsManager().getCurrentlyLoadedMods()) {
i++;
list += csp.getModInfo().getName() + (i == server.getContent().modsManager().getCurrentlyLoadedMods().size() ? "" : ", ");
}
emitter.sendMessage("#FF0000" + i + " active server mods : " + list);
return true;
}
System.out.println("fuck off");
return false;
}
Aggregations