Hello, Ok so I am currently developing a plugin that allows people to have a bank, every hour they play they get an x amount of money on top of that. But I am stuck, I am currently working on the Algorithm that allows me to do this, but I do not know how to run though a list of Integer's and do the same Algorithm to each one. So how would I do this? Thank's, Panda .
List<Integer> list; //Initialize it int size = list.size(); for(int i = 0; i < size; i++) { Integer value = list.get(i); //Get the value at index value += 10; //Algorithm: add 10 list.set(i, value); //Set the new value at index }
What about starting a task when a Player X joins and then every hour, you can get the Bank of the player and add some money to it... Don't forget to cancel the task, when the player leaves...
Can't be some money, the money they put in calculates the amount that is added to their bank per hour. If I just added some fixed amount to their bank, it wouldn't actually fuel the economy inspiration that I am trying to create on my own server.
Maybe this helps a bit: http://stackoverflow.com/questions/18410035/ways-to-iterate-over-a-list-in-java
Java programmers really do not know how to write an incrementing/decrementing loop? Incredibly sad. Backwards iteration. Also safe to use this to delete list entries inside the loop (which is impossible for for-each or forward iteration) Code (Java): int len = somearray.length; ( or list.size(); ) while(--len>-1) { somearray[len].stuff(); // do a thing } Forward interation. slightly more complex. Code (Java): int len = somearray.length; ( or list.size(); ) int index = -1; while(++index<len) { somearray[index].things(); // do a thing }
People do not know for loops: Code (Text): for(int i = 0; i < array.length, i++){ //Do stuff } (This may be more code but its 1. easier to read and 2. takes the same amount of time from a bytecode level of perspective.)
I'm not sure if I've understood this correctly, but wouldn't a Map be more suitable? Considering each player have a bank, the map would look like UUID, Integer (or something like that). It would be easy to loop through (you could even just get a player's bank directly and set value).
while and for loops used to be part of what people learned before they even wrote their first piece of code.. I guess that is too much to expect in the modern world of API-spoonfeeding and shortcuts.
Minecraft server plugin development is not really a good place to start learning Java, because @FlyingLlama is correct above, that many projects that programmers work on do not APIs that you can call. But yeah, @TheMasteredPanda, you really need to do some research and not give up so easily, what you are asking is incredibly simple, so search Google, struggle for a awhile, then ask for help. Struggle like the rest of us once did.