Before diving into contributing to NamelessMC or creating your own modules, we recommend you have a good idea of how everything fits together to make NamelessMC work.
Please note, this may not always be 100% up to date - but we will certainly do our best to maintain it.
99% of the files you will need to work with live inside 3 folders, core
, custom
and modules
;
core
assets
folder.avatar
folder.classes
, and then specific folders within this folder.
includes
folder contains rarely edited files, such as the upgrade scripts, password encryption, etc. You will not need to worry about this folder unless you are making changes to NamelessMC itself.installation
has files for the installation process of NamelessMC.integration
, but these will likely be moved to their own module soon.templates
contains template initialization files.
backend_init.php
is run when StaffCP is being accessed. It defines Smarty variables which are used on most StaffCP pages such as $PANEL_LOGO_IMAGE
, $PAGE_TITLE
and $FAVICON
.cc_navbar.php
defines the $CC_NAV_LINKS
Smarty variable which contains the side nav bar on the user's account page ("Overview", "Alerts", "OAuth", etc)footer.php
is executed on any frontend pages to assign social media Smarty variables, privacy & terms links, etc.frontend_init.php
does similar tasks as the backend_init.php
file, but for the frontend (shocking, I know!). This file checks if the user has outstanding infractions, or needs to validate their account, as well as define Smarty variables like $PAGE_DESCRIPTION
(SEO) and $ANALYTICS_ID
.navbar.php
generates the top navigation links (like: Alerts, StaffCP, and the users' dropdown) on the frontend, as well as setting the $NAV_LINKS
Smarty variable to generate the main navigation bar.panel_navbar.php
sets Smarty variables for StaffCP side navbar such as $NAV_LINKS
.init.php
does a lot of heavy lifting during the initialization/booting phase of each request.
custom
languages
contains a folder for each installed language, each with different files to help split our language terms into slightly more managable forms.
panel_templates
contains each of the installed StaffCP templates Smarty .tpl
files.templates
contains each of the installed frontend templates Smarty .tpl
files.modules
init.php
is ran during the initialization phase of NamelessMC on each of the installed & enabled plugins. This creates an instance of the module's main class.module.php
this contains the module's main class (often named <module name>_Module
) which extends the built-in Module
class.classes
this folder contains PHP classes specifically used by this module. It is generally not safe to use these classes in other modules.hooks
this folder contains listeners for NamelessMC events, such as userValidated
or reportCreated
.includes
folder houses a couple important things:
endpoints
subfolder, typically)admin_widgets
subfolder mainly)pages
is where 90% of the code for most modules lives.
pages
PHP code folder the same as your Smarty .tpl
folder.
modules/Core/pages/login.php
related Smarty file is custom/templates/DefaultRevamp/login.tpl
, and modules/Core/pages/user/oauth.php
Smarty file is custom/templates/DefaultRevamp/user/oauth.tpl
.queries
this contains PHP files which are often called in the background using AJAX, these often return raw JSON. Think of them as internal API endpoints.
admin_users.php
in the Core module returns a list of all registered users to render in the StaffCP -> User Management page.widgets
, self explainitory hopefully - this contains all of this module's widget classes.Our classes are split into a few subfolders to help organize them a bit. We will explain the use of each folder, and then explain the use of each of the classes in the "Core" folder - since these are the most commonly used classes by external modules.
Note that although they are split into subfolders, we do not use PHP namespaces! This is unlikely to change in the future.
Avatars
Collections
Core
Database
QueryRecorder
class which records all queries made during a request to display on the stack trace page if an exception occurs.Endpoints
Events
EventHandler
class which lets modules listen for events and executes said events.Group_Sync
GroupSyncManager
class which handles group sync logic, as well as the GroupSyncInjector
interface which modules can implement to create custom injectors for the group syncronization function of NamelessMC.Minecraft
Misc
To learn how to use our classes, check out our PHPDoc site, or out the source code of NamelessMC to see how we use them. Feel free to ask for support on how to use them in our Discord too!
Perhaps the most common question from new NamelessMC contributors: "how the heck does all of this fit together?".
The entry point for most requests is the index.php
file in the root of any NamelessMC installation.
php.ini
variables.Control is then passed to the core/init.php
file to continue booting the application before the request is given back to the index.php
file.
core/init.php
does a lot of stuff to help get things up and running:
FORCE_SSL
, FRIENDLY_URLS
, NAMELESS_VERSION
etcinit.php
file (usually the constructors!)
After all of these tasks have been completed, control is given back to index.php
to handle routing.
install.php
.404.php
.Assuming all went well, control has been given to the module's PHP file for the page the user is visiting. For this example we will use the modules/Core/pages/home.php
file since it is basic but contains all the generic pieces.
PAGE
constantcore/templates/frontend_init.php
(we discussed this file earlier!)Module::loadPage(...)
onPageLoad(...)
method on all enabled modules!$template->onPageLoad()
core/templates/navbar.php
and core/templates/footer.php
files (we discussed these earlier!).tpl
file that is shown to the userThe request is complete!
A (bad) visual representation of this process: