|
In your Player #onLogin() method.
Replace the add item garbage lines with this
Then declare this in the GameConstants class.Code:for (int[] item : GameConstants.startKit) { getInventory().add((item[0]), item[1]); }
Adjust your starter kid to whatever your eco/pvp preferences are (item, amount).Code:public static final int[][] startKit = { { 995, 500000000 }, { 4151, 1 }, { 4153, 1 }, { 1215, 1 }, { 9185, 1 }, { 11235, 1 }, { 9244, 5000 }, { 11212, 1000 }, { 386, 500 }, { 2441, 100 }, { 2437, 100 }, { 2443, 100 }, { 2445, 100 }, { 2435, 100 }, { 3041, 100 }, { 2431, 100 }, { 1163, 1 }, { 1127, 1 }, { 1079, 1 }, { 12954, 1 }, { 4089, 1 }, { 4091, 1 }, { 4093, 1 }, { 4095, 1 }, { 4097, 1 }, { 2503, 1 }, { 2497, 1 }, { 2491, 1 } };
Simple shit, just trying to help newcomers out to the source/java functions.
startKit is constant and should therefore be STARTER_KIT.
Also why isn't the array Item[] instead of int[]? Does this source not have a constructor class for items?
No to the constructor, cbf to convert all that shit then release. No performance changes just preferences but I'll eventually get to it later.
Yeah that's fair enough, I had this all done in a class prior I just ported the constant over to the GameConstants and forgot to uppercase the constant.
Using int[][] is fine, it will create a new item from the data anyway and use that method instead.Code:/** * Adds an item to the item container. * @param id The id of the item. * @param amount The amount of the item. * @return The ItemContainer instance. */ public ItemContainer add(int id, int amount) { return add(new Item(id, amount)); }
Thanks for this, it's much cleaner than the old code which was added there 10 minutes before the beta haha.
Could probs do this:
Code:public static final ImmutableSet<Item> STATER_KIT = ImmutableSet.of(new Item(995, 500000000), new Item(4151, 1), new Item(4153, 1), new Item(1215, 1), new Item(9185, 1), new Item(11235, 1), new Item(9244, 5000), new Item(11212, 1000), new Item(386, 500), new Item(2441, 100), new Item(2437, 100), new Item(2443, 100), new Item(2445, 100), new Item(2435, 100), new Item(3041, 100), new Item(2431, 100), new Item(1163, 1), new Item(1127, 1), new Item(1079, 1), new Item(12954, 1), new Item(4089, 1), new Item(4091, 1), new Item(4093, 1), new Item(4095, 1), new Item(4097, 1), new Item(2503, 1), new Item(2497, 1), new Item(2491, 1));Not sure about efficiency tho -- wont matter thoCode:STATER_KIT.forEach(player.getInventory()::add);
Seems like a bad habit hes carried over from PI based servers since they do not make use of an Item or ItemContainer system.
ImmutableSet works here but the Item[] array would work just as fine. Either way you are iterating through the array or set of items and then giving them to the player.
Incorrect. Arrays are mutable, regardless of the usage of the final modifier.
If you run that you will notice that it is possible to modify the array. As stated, a common work around to this is to use an ImmutableCollection implementation.Code:class Foo { static final int[] items = { 1 }; @Test public void mutableArrayTest() { System.out.printf("value=%s\n", items[0]); items[0] = 2; System.out.printf("modified value=%s", items[0]); } }
I completely disagree, it absolutely should not be treated as an immutable reference because it is not. This is literally the reason why we have a global standard called convention. If the object cannot be mutated during runtime and is defined static and final, it is permitted to follow the constant naming convention. Otherwise, it is not immutable, and shouldn't be treated as such.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |