Minecraft bukkit scheduler and procedural instance naming -


this question pretty obvious person knows how use bukkit properly, , i'm sorry if missed solution in others, kicking ass , don't know else do, tutorials have been utterly useless. there 2 things need doing:

  1. i need learn how create indefinite number of instances of object. figure it'd this:

int num = 0;

public void create(){      string name = chocolate + num;     thingy name = new thingy();   } 

so see i'm saying? need change name given each new instance doesn't overwrite last 1 when created. swear i've looked everywhere, i've asked java professor , can't answers.

2: need learn how use stupid scheduler, , can't understand far. basically, when event detected, 2 things called: 1 method activates instantly, , 1 needs given 5 second delay, called. code this:

public onevent(event e){     thingy thing = new thingy();     thing.method1();     thing.doondelay(method2(), 100 ticks);  } 

once again, apologize if not giving many specifics, cannot life of me find bukkit event scheduler can understand.

do not leave me links bukkit official tutorials, cannot understand them @ , it'll waste of answer. need can me, starting plugin writer.

i've had programming , ii focus in java, many basic things know, need bukkit-specific second one.

the first 1 has had me confused since started programming.

ok, first question think want use data structure. depending on you're doing, there different data structures use. data structure container can use store many instances of type of object. data structures available are:

  • hashmap
  • hashset
  • treemap
  • list
  • arraylist
  • vector

there more, these big ones. hashmap, hashset, , treemap part of map class, notable it's speedy operations. use hashmap, instantiate hashmap<keything, valuethingy> thing = new hashmap<keything, valuething>(); add elements thing.put(key, value). thn when want value out of it, use thing.get(key) hashmaps use algorithm that's super fast values, consequence of hashmap doesn't store it's entries in particular order. therefore when want loop though loop, randomly returns it's entries (not random because memory , stuff). also, it's important note can have 1 of each individual key. if try put in key exists in map, over-right value key.

the hashset hashmap without storing values go it. it's pretty container if need use determine if object inside it.

the treemap 1 of maps store it's values in particular order. have provide comparator (something tells if object less object) knows order put values if wants them in ascending order.

list , arraylist not maps. elements put in index address. list, have specify number of elements you're going putting it. lists not change size. arraylists lists in each element can retrieved arraylistthing.get(index) arraylist can change size. add elements arraylist arraylistthing.add(thing).

the vector lot arraylist. functions same , i'm not quite sure difference between them is.

at rate, can use these data structures store lot of objects making loop. here's example vector.

vector<thing> thing = new vector<thing>(); int numberofthings = 100; for(int = 0; < numberofthings; i++) {     thing.add(new thing()); } 

that give vector full of things can iterate through for(thing elem:thing) { thing.dostuff }

ok, second problem. correct need use bukkit scheduler. here how:

make class extends bukkitrunnable

public class runnablething extends bukkitrunnable {      public void run() {         //what want do. have make method.     }  } 

then want when want execute thing make new bukkittask object using runnablething

bukkittask example = new runnablething().runtasklater(plugin, ticks) 

you have math figure out how many ticks want. 20 ticks = 1 second. other think covers questions.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -