👍🎉 First, thank you for contribute to the MyJailbreak project! 👍🎉
This should be a small guide to avoid unnecessary problems when contributing code to MyJB. We're aware that the current code of MyJB doesn't fully follow this rules. We'll update the code to fit these guidelines in future. Maybe these guidelines could change in future.
“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
- John F. Woods
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
- Martin Fowler
to avoid double work
Split different features/edits/changes to different PRs
don't forget to credit yourself
doing some magic? explain it!
you don't need to comment "standard" code
(re)use code from an other author? give him credits as a comment above the snippet
activate 'show spaces & tabs' in your editor
examples:
✅ good:
if (check)
{
function();
}
else
{
function2();
}
if (check)
{
function();
return;
}
❌ bad:
if (check) {
function(); }
if (check) { function(); }
if (check) {
function();
}
if (check)
{ function(); }
if (check)
{
function();
}
if (check)
{
function();
}
if (check)
function();
if (check) function();
if (check) function();
return;
... and variants
👽 exception only on a return immediately after check:
if (check)
return Plugin_Continue;
if (check)
continue; //break, ...
examples:
✅ good:
function()
{
if (!check1)
return;
if (!check2)
return;
if (!check3)
return;
if (!check4)
return;
function2();
}
❌ bad:
function()
{
if (check1)
{
if (check2)
{
if (check3)
{
if (check4)
{
function2();
}
}
}
}
}
examples:
✅ good:
function1()
{
function3()
}
function2()
{
function3()
}
function3()
{
g_iInteger++;
function4(g_iInteger, g_fFloat, g_bBool);
function5(g_fFloat);
function6(g_bBool);
}
❌ bad:
function1()
{
g_iInteger++;
function4(g_iInteger, g_fFloat, g_bBool);
function5(g_fFloat);
function6(g_bBool);
}
function2()
{
g_iInteger++;
function4(g_iInteger, g_fFloat, g_bBool);
function5(g_fFloat);
function6(g_bBool);
}
activate 'show spaces & tabs' in your editor
examples:
✅ good:
if (check)
{
bool bBool = true;
int iInteger;
float fFloat = 0.1;
int iInteger = function(iInteger);
function2(iInteger, fFloat, bBool);
function3(fFloat); // no tabs in space lines
function4(bBool);
return Plugin_Handled;
}
❌ bad:
if (check)
{
bool bBool = true;
int iInteger;
float fFloat = 0.1;
int iInteger = function(iInteger);
function2(iInteger, fFloat, bBool);
function3(fFloat);
function4(bBool);
return Plugin_Handled;
}
if (check)
{
bool bBool = true;
int iInteger;
float fFloat = 0.1;
//here are tabs
int iInteger = function(iInteger);
function2(iInteger, fFloat, bBool);
//here are tabs
function3(fFloat);
//here are tabs
function4(bBool);
return Plugin_Handled;
}
examples:
✅ good:
Example(integer, float, bool);
if (check)
for (int i = 1; i <= MaxClients; i++)
❌ bad:
Example(integer,float,bool);
Example( integer , float , bool );
if(check)
for(int i = 1;i <= MaxClients;i++)
examples:
✅ good:
if (1 + 2 == 3)
for (int i = 1; i <= MaxClients; i++)
❌ bad:
if (1+2==3)
for (int i=1; i<=MaxClients; i++)
examples:
✅ good:
iInteger++;
iInteger--;
iInteger1 += iInteger2;
iInteger1 -= iInteger2;
❌ bad:
iInteger = iInteger + 1;
iInteger = iInteger - 1;
iInteger += 1;
iInteger -= 1;
iInteger1 = iInteger1 + iInteger2;
iInteger1 = iInteger1 - iInteger2;
try to use methodmaps for arrays, tries, datapacks, ... examples:
✅ good:
Panel menu = new Panel();
menu.SetTitle("Title");
menu.DrawItem("Item");
menu.Send(client, Handler, MENU_TIME);
Menu menu = CreateMenu(Handler);
menu.SetTitle(sBuffer);
menu.AddItem("1", "Item")
menu.Display(client, MENU_TIME);
... and variants
❌ bad:
Handle panel = CreatePanel();
SetPanelTitle(panel, "Title");
DrawPanelItem(panel, "Item");
SendPanelToClient(panel, client, Handler, MENU_TIME);
Handle menu = CreateMenu(Handler);
SetMenuTitle(menu, "Title");
AddMenuItem(menu, "1", "Item");
DisplayMenu(menu, client, MENU_TIME);
... and variants
examples:
✅ good:
CreateTimer(0.1, Timer_Example, GetClientUserId(client));
}
public Action Timer_Example(Handle tmr, int userid)
{
int client = GetClientOfUserId(userid);
//code
}
❌ bad:
CreateTimer(0.1, Timer_Example, client);
}
public Action Timer_Example(Handle tmr, int client)
{
//code
}
When possible add chat prints to end of a function - so when a translation is missing the function still works
examples:
✅ good:
function()
{
function2(); // will fire when "translation_phrass" is missing
PrintToChatAll("%t", "translation_phrass");
}
❌ bad:
function()
{
PrintToChatAll("%t", "translation_phrass");
function2(); // will not fire when "translation_phrass" is missing
}
use English language
non global - except 'client', 'attacker', 'victim'
iBetHRSmall
| | | |
| | | └ Name
| | |
| | └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
| |
| └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
|
└ bool, char, float, handle, integer
global
g_iTimerRollStart
| | | | |
| | | | └ Name
| | | |
| | | └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
| | |
| | └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
| |
| └ bool, char, float, handle, integer
|
└ global
global Convar
gc_iTimerRollStart
| | | | |
| | | | └ Name
| | | |
| | | └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
| | |
| | └ optional - if concerning to a repeating special function like timer or more variables belongs to a single function
| |
| └ bool, char, float, handle, integer
|
└ global convar
Functions
examples:
Command_Example(int client);
Menu_Example(int client);
Panel_Example(int client);
Handler_Example(Menu menu, MenuAction action, int client, int itemNum);
The parameters of the functions should keep their original description, if not given use lowercase characters without the bool, char, float, handle, integer prefix
Version 1.0 of MyJailbreaks Code Contribution Guidelines