use of io.xol.chunkstories.api.content.mods.Mod in project chunkstories by Hugobros3.
the class ModsSelection method buildModsList.
private void buildModsList() {
modsContainer.elements.clear();
Collection<String> currentlyEnabledMods = Arrays.asList(Client.getInstance().getContent().modsManager().getEnabledModsString());
Set<String> uniqueMods = new HashSet<String>();
// First put in already loaded mods
for (Mod mod : Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods()) {
// Should use md5 hash instead ;)
if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
modsContainer.elements.add(modsContainer.new ModItem(mod, true));
}
// Then look for mods in folder fashion
for (File f : new File(GameDirectory.getGameFolderPath() + "/mods/").listFiles()) {
if (f.isDirectory()) {
File txt = new File(f.getAbsolutePath() + "/mod.txt");
if (txt.exists()) {
try {
ModFolder mod = new ModFolder(f);
// Should use md5 hash instead ;)
if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
modsContainer.elements.add(modsContainer.new ModItem(mod, currentlyEnabledMods.contains(mod.getModInfo().getName())));
System.out.println("mod:" + mod.getModInfo().getName() + " // " + currentlyEnabledMods.contains(mod.getModInfo().getName()));
} catch (ModLoadFailureException e) {
e.printStackTrace();
}
}
}
}
// First look for mods in folder fashion
for (File f : new File(GameDirectory.getGameFolderPath() + "/mods/").listFiles()) {
if (f.getName().endsWith(".zip")) {
try {
ModZip mod = new ModZip(f);
// Should use md5 hash instead ;)
if (uniqueMods.add(mod.getModInfo().getName().toLowerCase()))
modsContainer.elements.add(modsContainer.new ModItem(mod, currentlyEnabledMods.contains(mod.getModInfo().getName())));
} catch (ModLoadFailureException e) {
e.printStackTrace();
}
}
}
}
use of io.xol.chunkstories.api.content.mods.Mod 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.content.mods.Mod in project chunkstories by Hugobros3.
the class ModsManagerImplementation method buildModsFileSystem.
private void buildModsFileSystem() {
avaibleAssets.clear();
avaibleForeignClasses.clear();
pluginsWithinEnabledMods.clear();
// Obtain a cache folder
if (cacheFolder == null) {
cacheFolder = new File(GameDirectory.getGameFolderPath() + "/cache/" + ((int) (Math.random() * 10000)));
cacheFolder.mkdirs();
// cacheFolder.deleteOnExit();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println("Deleting cache folder " + cacheFolder);
FoldersUtils.deleteFolder(cacheFolder);
}
});
}
// Checks for the base assets folder presence and sanity
try {
if (coreContentLocation.isDirectory())
baseAssets = new ModFolder(coreContentLocation);
else
baseAssets = new ModZip(coreContentLocation);
} catch (ModLoadFailureException e) {
logger().error("Fatal : failed to load in the base assets folder. Exception : {}", e);
// e.printStackTrace(logger().getPrintWriter());
}
ClassLoader childClassLoader = loadModAssets(baseAssets, Thread.currentThread().getContextClassLoader());
// Iterates over mods, in order of priority (lowest to highest)
for (Mod mod : enabledMods) {
childClassLoader = loadModAssets((ModImplementation) mod, childClassLoader);
}
finalClassLoader = childClassLoader;
}
use of io.xol.chunkstories.api.content.mods.Mod 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