-
Notifications
You must be signed in to change notification settings - Fork 1
Start to code
Let us display our fist MapGUI to a player, it's easy!
import io.github.tonodus.bukkit.MapGUI.MapGUIPlugin;
import io.github.tonodus.bukkit.MapGUI.api.ComponentWindow;
import io.github.tonodus.bukkit.MapGUI.api.MapGUI;
import io.github.tonodus.bukkit.MapGUI.core.BaseWindow;
Player player = (/* the player the map will displayed to */);
Plugin plugin = this; //Your plugin instance, _this_ if the method is called in your main class
MapGUI gui = MapGUIPlugin.registerMapGuiForPlayer(plugin, player);
ComponentWindow window = new BaseWindow();
gui.setWindow(window);
gui.show();
So what did we?
First, we need a MapGUI, thats our basic object. We get one by calling MapGUIPlugin.registerMapGuiForPlayer(Plugin, Player).
Second, we want to add some content. A MapGUI can only display one Window at the same time. Since we we want to add some fancy components to our window later, we use a ComponentWindow (it can display components, OMG). ComponentWindow is an interface implemented by BaseWindow.
Last, we set the window of the MapGUI and show the MapGUI to the player. The player can close it by pressing Q, the MapGUI will be fully disposed then.
We see a nice white map now, if we try our first plugin. We're going to add some more content now!
MapGUI gui = MapGUIPlugin.registerMapGuiForPlayer(this, e.getPlayer());
ComponentWindow window = new BaseWindow();
TextLabel label = new TextLabel("Awesome text");
Button button = new Button("Click me!");
label.setPosition(5, 5);
button.setPosition(5, 20);
label.calcPreferredSizeNextFrame();
window.addComponent(label, button);
gui.setWindow(window);
gui.show();
So what did we now? First, we create two Components: a Button and a TextLabel. Components can be added to a ComponentContainer (f.e. a ComponentWindow). So the get displayed to your MapGUI.
Then we set the position of these (in pixels), currently a MapGUI is 128x128 pixel big (since bukkit use this value), but the whole layout system may changed soon.
We also MUST set the size of components! We can call #setSize(width, height), otherwise the component has a size of 0x0 pixels and won't be displayed. Only the button resizes itself for now, the label resizes if we call TextLabel#calcPreferredSizeNextFrame(). As stated above, this may changed soon.
Last, we add the components to our ComponentWindow.