-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGuiManager.java
More file actions
53 lines (45 loc) · 2.19 KB
/
Copy pathGuiManager.java
File metadata and controls
53 lines (45 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package dev.brauw.mapper.gui;
import dev.brauw.mapper.MapperPlugin;
import dev.brauw.mapper.gui.common.GuiSetName;
import dev.brauw.mapper.gui.metadata.GuiMetadata;
import dev.brauw.mapper.gui.selector.GuiColorSelect;
import dev.brauw.mapper.metadata.MapMetadata;
import dev.brauw.mapper.region.RegionOptions;
import dev.brauw.mapper.session.EditSession;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import xyz.xenondevs.invui.gui.structure.Structure;
import xyz.xenondevs.invui.item.builder.ItemBuilder;
import xyz.xenondevs.invui.window.AnvilWindow;
import xyz.xenondevs.invui.window.Window;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
public class GuiManager {
private final MapperPlugin mapperPlugin;
public GuiManager(MapperPlugin mapperPlugin) {
this.mapperPlugin = mapperPlugin;
Structure.addGlobalIngredient('#', new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(""));
}
public void openRegionCreateGui(EditSession session, BiConsumer<String, RegionOptions> regionCreator, Runnable onClose) {
AtomicReference<String> name = new AtomicReference<>("");
final RegionOptions.RegionOptionsBuilder builder = RegionOptions.builder();
final GuiSetName setNameGui = new GuiSetName(name, () -> builder.build().getColor().getMaterial(), () -> regionCreator.accept(name.get(), builder.build()));
final GuiColorSelect colorGui = new GuiColorSelect(builder, setNameGui::update);
AnvilWindow.split()
.setUpperGui(setNameGui)
.setLowerGui(colorGui)
.addRenameHandler(updated -> {
name.set(updated);
setNameGui.update();
})
.setTitle("Create a new region")
.addCloseHandler(onClose)
.open(session.getOwner().getPlayer());
}
public void openMetadataEditor(Player player, MapMetadata mapMetadata) {
Window.single()
.setTitle("Map Metadata")
.setGui(new GuiMetadata(mapperPlugin.getTaskScheduler(), this, mapperPlugin.getMetadataManager(), player, mapMetadata))
.open(player);
}
}