Conversation
|
|
||
| //Check box has been selected and should be updated to the server | ||
| if (tempBox.isSelected() && !bannedAmmo.containsKey(ammo)) | ||
| if (tempBox.isSelected() && !bannedAmmo.containsKey(ammo) |
There was a problem hiding this comment.
Since this is essentially checking whether the selection state differs from whether the ammo is banned, you could simplify it to:
if (tempBox.isSelected() != bannedAmmo.containsKey(ammo))
| //Check box has been selected and should be updated to the server | ||
| if (tempBox.isSelected() && !bannedAmmo.containsKey(ammo)) | ||
| if (tempBox.isSelected() && !bannedAmmo.containsKey(ammo) | ||
| || !tempBox.isSelected() && bannedAmmo.containsKey(ammo)) { |
There was a problem hiding this comment.
tempBox.isSelected() can't be null at this point, but what about bannedAmmo? bannedAmmo is from:
mwclient.getData().getServerBannedAmmo()
| else if (!tempBox.isSelected() && bannedAmmo.containsKey(ammo)) | ||
| mwclient.sendChat(GameHost.CAMPAIGN_PREFIX + "c adminsetserverammoban#" | ||
| + munitionTypes.get(tempBox.getText())); | ||
| + munitionTypes.get(tempBox.getText()).ordinal()); |
There was a problem hiding this comment.
Using .ordinal() is usually avoided because it's brittle - in our case, if the order of enums in this changes:
megamek.common.AmmoType.Munitions;
Then the result of this will change:
munitionTypes.get(tempBox.getText()).ordinal());
The fear is that Munitions is a fairly large enum, written like:
public enum Munitions {
M_STANDARD,
// AC Munition Types
M_CLUSTER,
...
But, if the intention is that each should map to a numeral, it should have been written like:
public enum Munitions {
M_STANDARD(0),
// AC Munition Types
M_CLUSTER(1),
...
with each numeral accessed through a public getter.
It seems this is all kind of out of our hands unless we use a secondhand mapping enum, so this comment is mostly just for situational awareness. Because we don't necessarily track every change in the megamek project, it is possible that one day someone's innocent reordering/organization of the Munitions enum causes strange and wonky behavior in a downstream project!
There was a problem hiding this comment.
Yup I rather dislike this PR because it uses a lot of values and ordinal which seem to both be bad, but would rather have this feature working than not. Also, after doing this PR I'm under the impression that MegaMek circa 2010's only had Munitions and later came AmmoType which is a list of static final int that solves this issue.
I say this because I noticed in CampaignData we map the enum to string, specifically "LBX Cluster -> M_CLUSTER", however M_CLUSTER but seems to include LBX, Silver bullet Gauss Rifle Ammo, and artillery cluster munitions.
There was a problem hiding this comment.
Hmm very interesting! Yeah would rather have it working than not, 100%
| private Hashtable<String, Integer> commands = new Hashtable<>(); | ||
| private TreeMap<String, String> planetOpFlags = new TreeMap<>(); | ||
|
|
||
| private Hashtable<String, AmmoType.Munitions> munitionsByName; |
There was a problem hiding this comment.
HashMap<K, V>
Hashtable not used anymore
There was a problem hiding this comment.
Great optimization for sure
sandysimonton
left a comment
There was a problem hiding this comment.
Some notes on possible things to look at
At your discretion for merge!
Changes:
AdminListHouseBannedAmmoCommand now works properly.
AdminListFactionBannedAmmoCommand now works properly.
BannedAmmoDialog now checks banned ammo.
BannedAmmoDialog now correctly bans ammo.