This is all Bukkit but that's kind of irrelevant to the topic. I have three classes who purpose is to certain objects (inventories) depending on which group a player is in.
That method has even more else-ifs but I cut it off for readability. Obviously I could also use a switch statement but that still seems like a ridiculous amount of code to achieve what I need.
That method loads an inventory with the necessary items as defined by the array parameter and presents it to the player.
Finally that class contains all of the arrays for each group, and yes I'm well aware that many of my Abilities need renamed since some of them are literally just one character. 😝 Surely there is a way to size this shit down.
Code
public void loadAbilityBar(Player p, boolean forceReload){
//Space Marine
if(ThunderSuite.perms.getPrimaryGroup(p).equals("Scout")){
loadArray(p, aa.scoutAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("SpaceMarine")){
loadArray(p, aa.spaceMarineAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("AssaultMarine")){
loadArray(p, aa.assaultMarineAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("GreyKnight")){
loadArray(p, aa.greyKnightAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("Terminator")){
loadArray(p, aa.terminatorAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("AssaultTerminator")){
loadArray(p, aa.aTerminatorAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("ForceCommander")){
loadArray(p, aa.forceCommanderAbilities, forceReload);
}
//Chaos
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("Cultist")){
loadArray(p, aa.cultistAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("ChaosMarine")){
loadArray(p, aa.chaosMarineAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("ChaosRaptor")){
loadArray(p, aa.chaosRaptorAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("Horror")){
loadArray(p, aa.horrorAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("KhorneBerserker")){
loadArray(p, aa.khorneBerserkerAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("PossessedMarine")){
loadArray(p, aa.possessedMarineAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("ChaosLord")){
loadArray(p, aa.chaosLordAbilities, forceReload);
}
//Ork
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("Gretchin")){
loadArray(p, aa.gretchinAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("SluggaBoy")){
loadArray(p, aa.sluggaAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("ShootaBoy")){
loadArray(p, aa.shootaAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("StormBoy")){
loadArray(p, aa.stormBoyAbility, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("Nob")){
loadArray(p, aa.nobAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("FlashGit")){
loadArray(p, aa.flashGitAbilities, forceReload);
}
else if(ThunderSuite.perms.getPrimaryGroup(p).equals("WarBoss")){
loadArray(p, aa.warBossAbilities, forceReload);
}
}That method has even more else-ifs but I cut it off for readability. Obviously I could also use a switch statement but that still seems like a ridiculous amount of code to achieve what I need.
Code
public void loadArray(Player p, Ability[] array, boolean forceReload){
Inventory inv = toolbars.get(p.getName());
if((inv == null) || (ThunderSuite.perms.getPrimaryGroup(p) != JoinListener.groups.get(p.getName())) || forceReload){
inv = Bukkit.createInventory(p, 9, ChatColor.DARK_BLUE + "Abilities");
for(int i = 0; i < array.length; i++){
inv.setItem(i, array[i].getItem());
}
JoinListener.groups.put(p.getName(), ThunderSuite.perms.getPrimaryGroup(p));
toolbars.put(p.getName(), inv);
}
p.openInventory(inv);
}That method loads an inventory with the necessary items as defined by the array parameter and presents it to the player.
Code
public class AbilityArrays {
StrafeRun sr = new StrafeRun();
JetPack jp = new JetPack();
Infiltration inf = new Infiltration();
Zeal zeal = new Zeal();
LiberDaemonicus lb = new LiberDaemonicus();
TacticalDreadnoughtArmour tda = new TacticalDreadnoughtArmour();
CruxTerminatus ct = new CruxTerminatus();
ThunderHammer th = new ThunderHammer();
MarkOfChaos moc = new MarkOfChaos();
WarpFlames wf = new WarpFlames();
BloodRage br = new BloodRage();
RuinousPowers rp = new RuinousPowers();
Tendrils t = new Tendrils();
ToughSkin ts = new ToughSkin();
Slugga sl = new Slugga();
Shoota sh = new Shoota();
PowerClaw pc = new PowerClaw();
KustomShoota ks = new KustomShoota();
Roks r = new Roks();
//Space Marine
public Ability[] scoutAbilities = new Ability[]{
sr,
inf
};
public Ability[] spaceMarineAbilities = new Ability[]{
zeal
};
public Ability[] assaultMarineAbilities = new Ability[]{
jp
};
public Ability[] greyKnightAbilities = new Ability[]{
lb
};
public Ability[] terminatorAbilities = new Ability[]{
tda,
ct
};
public Ability[] aTerminatorAbilities = new Ability[]{
tda,
ct
};
public Ability[] forceCommanderAbilities = new Ability[]{
th
};
//Chaos
public Ability[] cultistAbilities = new Ability[]{
inf
};
public Ability[] chaosMarineAbilities = new Ability[]{
moc
};
public Ability[] chaosRaptorAbilities = new Ability[]{
jp
};
public Ability[] horrorAbilities = new Ability[]{
wf
};
public Ability[] khorneBerserkerAbilities = new Ability[]{
br
};
public Ability[] chaosLordAbilities = new Ability[]{
rp
};
public Ability[] possessedMarineAbilities = new Ability[]{
t
};
//Orkz
public Ability[] gretchinAbilities = new Ability[]{
inf
};
public Ability[] sluggaAbilities = new Ability[]{
ts,
sl
};
public Ability[] shootaAbilities = new Ability[]{
ts,
sh
};
public Ability[] stormBoyAbility = new Ability[]{
jp
};
public Ability[] nobAbilities = new Ability[]{
pc
};
public Ability[] flashGitAbilities = new Ability[]{
ks
};
public Ability[] warBossAbilities = new Ability[]{
r
};
}Finally that class contains all of the arrays for each group, and yes I'm well aware that many of my Abilities need renamed since some of them are literally just one character. 😝 Surely there is a way to size this shit down.



jmrapp1270