mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2024-09-19 19:25:45 +00:00
feat(gui): 重构部分GUI代码,新增填充空格功能
This commit is contained in:
parent
d26987c0d2
commit
de4dbbe637
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -19,7 +19,7 @@ import java.util.stream.IntStream;
|
|||||||
public class GUI {
|
public class GUI {
|
||||||
|
|
||||||
private static JavaPlugin plugin;
|
private static JavaPlugin plugin;
|
||||||
private static final HashMap<UUID, GUI> openedGUIs = new HashMap<>();
|
private static final Map<UUID, GUI> openedGUIs = new HashMap<>();
|
||||||
|
|
||||||
public static void initialize(JavaPlugin plugin) {
|
public static void initialize(JavaPlugin plugin) {
|
||||||
GUI.plugin = plugin;
|
GUI.plugin = plugin;
|
||||||
@ -29,42 +29,32 @@ public class GUI {
|
|||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<UUID, GUI> getOpenedGUIs() {
|
public static Map<UUID, GUI> getOpenedGUIs() {
|
||||||
return openedGUIs;
|
return openedGUIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GUIType type;
|
protected final @NotNull GUIType type;
|
||||||
protected String title;
|
protected @NotNull String title;
|
||||||
public HashMap<Integer, GUIItem> items;
|
protected Inventory inv;
|
||||||
public Inventory inv;
|
|
||||||
|
|
||||||
/**
|
protected final SortedMap<Integer, GUIItem> items = new TreeMap<>();
|
||||||
* 当玩家点击目标GUI时是否取消
|
protected ItemStack emptyItem = null;
|
||||||
*/
|
|
||||||
boolean cancelOnTarget = true;
|
|
||||||
|
|
||||||
/**
|
protected boolean cancelOnTarget = true; // 当玩家点击GUI时是否取消对应事件
|
||||||
* 当玩家点击自己背包时是否取消
|
protected boolean cancelOnSelf = true; // 当玩家点击自己背包时是否取消对应事件
|
||||||
*/
|
protected boolean cancelOnOuter = true; // 当玩家点击界面外时是否取消对应事件
|
||||||
boolean cancelOnSelf = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当玩家点击界面外时是否取消
|
|
||||||
*/
|
|
||||||
boolean cancelOnOuter = true;
|
|
||||||
|
|
||||||
protected final Map<String, Object> flags = new LinkedHashMap<>();
|
protected final Map<String, Object> flags = new LinkedHashMap<>();
|
||||||
|
|
||||||
protected GUIListener listener;
|
protected GUIListener listener;
|
||||||
|
|
||||||
public GUI(GUIType type, String title) {
|
public GUI(@NotNull GUIType type, @NotNull String title) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.title = ColorParser.parse(title);
|
this.title = ColorParser.parse(title);
|
||||||
this.items = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<@NotNull Integer, @NotNull GUIItem> getItems() {
|
public SortedMap<@NotNull Integer, @NotNull GUIItem> getItems() {
|
||||||
return new HashMap<>(items);
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setItem(int index, @Nullable GUIItem item) {
|
public final void setItem(int index, @Nullable GUIItem item) {
|
||||||
@ -75,16 +65,51 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setItemStack(int index, @Nullable ItemStack item) {
|
||||||
|
setItem(index, item == null ? null : new GUIItem(item));
|
||||||
|
}
|
||||||
|
|
||||||
public void setItem(GUIItem item, int... index) {
|
public void setItem(GUIItem item, int... index) {
|
||||||
for (int i : index) {
|
for (int i : index) {
|
||||||
setItem(i, item);
|
setItem(i, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setItemStack(ItemStack item, int... index) {
|
||||||
|
for (int i : index) {
|
||||||
|
setItemStack(i, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GUIItem getItem(int index) {
|
public GUIItem getItem(int index) {
|
||||||
return this.items.get(index);
|
return this.items.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEmptyItem(ItemStack item) {
|
||||||
|
this.emptyItem = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||||
|
if (emptyItem == null) return;
|
||||||
|
IntStream.range(0, inventory.getSize())
|
||||||
|
.filter(i -> inventory.getItem(i) == null)
|
||||||
|
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void applyToInventory(Inventory inventory) {
|
||||||
|
IntStream.range(0, inventory.getSize()).forEach(index -> inventory.setItem(index, new ItemStack(Material.AIR)));
|
||||||
|
getItems().forEach((index, item) -> inventory.setItem(index, item.getDisplay()));
|
||||||
|
fillEmptySlots(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTitle(@NotNull String title) {
|
||||||
|
this.title = ColorParser.parse(title);
|
||||||
|
if (this.inv != null) {
|
||||||
|
this.inv = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
||||||
|
applyToInventory(this.inv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新玩家箱子的视图
|
* 更新玩家箱子的视图
|
||||||
*/
|
*/
|
||||||
@ -92,8 +117,7 @@ public class GUI {
|
|||||||
this.onUpdate();
|
this.onUpdate();
|
||||||
if (this.inv != null) {
|
if (this.inv != null) {
|
||||||
List<HumanEntity> viewers = this.inv.getViewers();
|
List<HumanEntity> viewers = this.inv.getViewers();
|
||||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
applyToInventory(this.inv);
|
||||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
|
||||||
viewers.forEach(p -> ((Player) p).updateInventory());
|
viewers.forEach(p -> ((Player) p).updateInventory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,22 +172,22 @@ public class GUI {
|
|||||||
throw new IllegalStateException("被取消或不存在的GUI");
|
throw new IllegalStateException("被取消或不存在的GUI");
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
Inventory ui = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
||||||
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
applyToInventory(ui);
|
||||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
|
||||||
|
|
||||||
GUI previous = getOpenedGUI(player);
|
GUI previous = getOpenedGUI(player);
|
||||||
if (previous != null) {
|
if (previous != null && previous.listener != null) {
|
||||||
previous.listener.close(player);
|
previous.listener.close(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenedGUI(player, this);
|
setOpenedGUI(player, this);
|
||||||
|
|
||||||
this.inv = inv;
|
this.inv = ui;
|
||||||
player.openInventory(inv);
|
player.openInventory(ui);
|
||||||
|
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
Bukkit.getPluginManager().registerEvents(listener = new GUIListener(this), getPlugin());
|
this.listener = new GUIListener(this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(this.listener, getPlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,4 +235,11 @@ public class GUI {
|
|||||||
getOpenedGUIs().remove(player.getUniqueId());
|
getOpenedGUIs().remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void closeAll() {
|
||||||
|
Set<HumanEntity> viewers = new HashSet<>();
|
||||||
|
getOpenedGUIs().values().stream().flatMap(gui -> gui.inv.getViewers().stream()).forEach(viewers::add);
|
||||||
|
viewers.forEach(HumanEntity::closeInventory);
|
||||||
|
getOpenedGUIs().clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class GUIItem {
|
public class GUIItem {
|
||||||
|
|
||||||
ItemStack display;
|
protected ItemStack display;
|
||||||
boolean actionActive = true;
|
protected boolean actionActive = true;
|
||||||
|
|
||||||
public Set<GUIClickAction> actions = new HashSet<>();
|
protected final Set<GUIClickAction> actions = new HashSet<>();
|
||||||
public Set<GUIClickAction> actionsIgnoreActive = new HashSet<>();
|
protected final Set<GUIClickAction> actionsIgnoreActive = new HashSet<>();
|
||||||
|
|
||||||
public GUIItem(ItemStack display) {
|
public GUIItem(ItemStack display) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
|
|
||||||
public class GUIListener implements Listener {
|
public class GUIListener implements Listener {
|
||||||
|
|
||||||
GUI currentGUI;
|
protected final GUI currentGUI;
|
||||||
|
|
||||||
public GUIListener(GUI gui) {
|
public GUIListener(GUI gui) {
|
||||||
this.currentGUI = gui;
|
this.currentGUI = gui;
|
||||||
|
@ -12,6 +12,7 @@ public enum GUIType {
|
|||||||
FOUR_BY_NINE(4, 36),
|
FOUR_BY_NINE(4, 36),
|
||||||
FIVE_BY_NINE(5, 45),
|
FIVE_BY_NINE(5, 45),
|
||||||
SIX_BY_NINE(6, 54),
|
SIX_BY_NINE(6, 54),
|
||||||
|
|
||||||
CANCEL(0, 0);
|
CANCEL(0, 0);
|
||||||
|
|
||||||
private final int lines;
|
private final int lines;
|
||||||
|
@ -4,36 +4,54 @@ import cc.carm.lib.easyplugin.gui.GUIItem;
|
|||||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class AutoPagedGUI extends CommonPagedGUI {
|
public class AutoPagedGUI extends CommonPagedGUI {
|
||||||
|
|
||||||
public static Function<Player, ItemStack> defaultPreviousPage = null;
|
public static Function<Player, ItemStack> defaultPreviousPage = null;
|
||||||
public static Function<Player, ItemStack> defaultNextPage = null;
|
public static Function<Player, ItemStack> defaultNextPage = null;
|
||||||
|
|
||||||
ItemStack previousPageUI;
|
protected ItemStack previousPageUI;
|
||||||
ItemStack nextPageUI;
|
protected ItemStack nextPageUI;
|
||||||
int previousPageSlot = -1;
|
protected ItemStack noPreviousPageUI;
|
||||||
int nextPageSlot = -1;
|
protected ItemStack noNextPageUI;
|
||||||
|
protected int previousPageSlot = -1;
|
||||||
|
protected int nextPageSlot = -1;
|
||||||
|
|
||||||
public AutoPagedGUI(GUIType type, String name, int[] range) {
|
public AutoPagedGUI(@NotNull GUIType type, @NotNull String title, int[] range) {
|
||||||
super(type, name, range);
|
super(type, title, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoPagedGUI(GUIType type, String name, int a, int b) {
|
public AutoPagedGUI(@NotNull GUIType type, @NotNull String title, int a, int b) {
|
||||||
super(type, name, a, b);
|
super(type, title, a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreviousPageUI(ItemStack lastPageUI) {
|
public void setPreviousPageUI(@Nullable ItemStack lastPageUI) {
|
||||||
this.previousPageUI = lastPageUI;
|
this.previousPageUI = lastPageUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextPageUI(ItemStack nextPageUI) {
|
public void setNoPreviousPageUI(@Nullable ItemStack noPreviousPageUI) {
|
||||||
|
this.noPreviousPageUI = noPreviousPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageUI(@Nullable ItemStack nextPageUI) {
|
||||||
this.nextPageUI = nextPageUI;
|
this.nextPageUI = nextPageUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNoNextPageUI(@Nullable ItemStack noNextPageUI) {
|
||||||
|
this.noNextPageUI = noNextPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPreviousPageSlot(int slot) {
|
public void setPreviousPageSlot(int slot) {
|
||||||
this.previousPageSlot = slot;
|
this.previousPageSlot = slot;
|
||||||
}
|
}
|
||||||
@ -42,12 +60,24 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
|||||||
this.nextPageSlot = slot;
|
this.nextPageSlot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||||
|
if (emptyItem == null) return;
|
||||||
|
Set<Integer> rangeSet = Arrays.stream(this.range).boxed().collect(Collectors.toSet());
|
||||||
|
if (previousPageSlot >= 0) rangeSet.add(previousPageSlot);
|
||||||
|
if (nextPageSlot >= 0) rangeSet.add(nextPageSlot);
|
||||||
|
IntStream.range(0, inventory.getSize())
|
||||||
|
.filter(i -> inventory.getItem(i) == null)
|
||||||
|
.filter(i -> !rangeSet.contains(i))
|
||||||
|
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openGUI(Player user) {
|
public void openGUI(Player user) {
|
||||||
if (previousPageSlot >= 0) {
|
if (previousPageSlot >= 0) {
|
||||||
if (hasPreviousPage()) {
|
if (hasPreviousPage()) {
|
||||||
setItem(previousPageSlot, new GUIItem(
|
setItem(previousPageSlot, new GUIItem(Optional.ofNullable(defaultPreviousPage).map(d -> d.apply(user)).orElse(previousPageUI)) {
|
||||||
previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(Player clicker, ClickType type) {
|
public void onClick(Player clicker, ClickType type) {
|
||||||
if (type == ClickType.RIGHT) {
|
if (type == ClickType.RIGHT) {
|
||||||
@ -59,14 +89,13 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setItem(previousPageSlot, null);
|
setItem(previousPageSlot, this.noPreviousPageUI == null ? null : new GUIItem(noPreviousPageUI));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextPageSlot >= 0) {
|
if (nextPageSlot >= 0) {
|
||||||
if (hasNextPage()) {
|
if (hasNextPage()) {
|
||||||
setItem(nextPageSlot, new GUIItem(
|
setItem(nextPageSlot, new GUIItem(Optional.ofNullable(defaultNextPage).map(d -> d.apply(user)).orElse(nextPageUI)) {
|
||||||
nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(Player clicker, ClickType type) {
|
public void onClick(Player clicker, ClickType type) {
|
||||||
if (type == ClickType.RIGHT) {
|
if (type == ClickType.RIGHT) {
|
||||||
@ -78,19 +107,12 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setItem(nextPageSlot, null);
|
setItem(nextPageSlot, this.noNextPageUI == null ? null : new GUIItem(noNextPageUI));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
super.openGUI(user);
|
super.openGUI(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack getDefaultNextPage(Player player) {
|
|
||||||
return defaultNextPage != null ? defaultNextPage.apply(player) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ItemStack getDefaultPreviousPage(Player player) {
|
|
||||||
return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,70 +4,38 @@ package cc.carm.lib.easyplugin.gui.paged;
|
|||||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class CommonPagedGUI extends PagedGUI {
|
public class CommonPagedGUI extends PagedGUI {
|
||||||
|
|
||||||
private int[] range;
|
protected final int[] range;
|
||||||
|
|
||||||
private CommonPagedGUI(GUIType type, String name) {
|
public CommonPagedGUI(@NotNull GUIType type, @NotNull String title, int a, int b) {
|
||||||
super(type, name);
|
this(type, title, toRange(type, a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommonPagedGUI(GUIType type, String Name, int a, int b) {
|
public CommonPagedGUI(@NotNull GUIType type, @NotNull String title, int[] range) {
|
||||||
this(type, Name, toRange(type, a, b));
|
super(type, title);
|
||||||
}
|
|
||||||
|
|
||||||
public CommonPagedGUI(GUIType type, String Name, int[] range) {
|
|
||||||
super(type, Name);
|
|
||||||
Arrays.sort(range);
|
Arrays.sort(range);
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||||
/*
|
if (emptyItem == null) return;
|
||||||
int[] matrix = new int[]{
|
Set<Integer> rangeSet = Arrays.stream(this.range).boxed().collect(Collectors.toSet());
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
IntStream.range(0, inventory.getSize())
|
||||||
9, 10, 11, 12, 13, 14, 15, 16, 17,
|
.filter(i -> inventory.getItem(i) == null)
|
||||||
18, 19, 20, 21, 22, 23, 24, 25, 26,
|
.filter(i -> !rangeSet.contains(i))
|
||||||
27, 28, 29, 30, 31, 32, 33, 34, 35,
|
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||||
36, 37, 38, 39, 40, 41, 42, 43, 44,
|
|
||||||
45, 46, 47, 48, 49, 50, 51, 52, 53
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static int[] toRange(GUIType type, int a, int b) {
|
|
||||||
if (a > b) {
|
|
||||||
a = a ^ b;
|
|
||||||
b = a ^ b;
|
|
||||||
a = a ^ b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int lineA = getLine(a);
|
|
||||||
int columnA = getColumn(a);
|
|
||||||
int lineB = getLine(b);
|
|
||||||
int columnB = getColumn(b);
|
|
||||||
|
|
||||||
if (lineB > type.getLines())
|
|
||||||
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
|
||||||
|
|
||||||
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
|
||||||
|
|
||||||
for (int i = 0, l = 0; i < type.getSize(); i++) {
|
|
||||||
int li = getLine(i);
|
|
||||||
int ci = getColumn(i);
|
|
||||||
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
|
||||||
range[l] = i;
|
|
||||||
l++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getLine(int i) {
|
private static int getLine(int i) {
|
||||||
@ -155,4 +123,44 @@ public class CommonPagedGUI extends PagedGUI {
|
|||||||
super.openGUI(player);
|
super.openGUI(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
int[] matrix = new int[]{
|
||||||
|
0, 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
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
private static int[] toRange(GUIType type, int a, int b) {
|
||||||
|
if (a > b) {
|
||||||
|
a = a ^ b;
|
||||||
|
b = a ^ b;
|
||||||
|
a = a ^ b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineA = getLine(a);
|
||||||
|
int columnA = getColumn(a);
|
||||||
|
int lineB = getLine(b);
|
||||||
|
int columnB = getColumn(b);
|
||||||
|
|
||||||
|
if (lineB > type.getLines())
|
||||||
|
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
||||||
|
|
||||||
|
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
||||||
|
|
||||||
|
int l = 0;
|
||||||
|
for (int i = 0; i < type.getSize(); i++) {
|
||||||
|
int li = getLine(i);
|
||||||
|
int ci = getColumn(i);
|
||||||
|
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
||||||
|
range[l] = i;
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return range;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,44 +4,55 @@ package cc.carm.lib.easyplugin.gui.paged;
|
|||||||
import cc.carm.lib.easyplugin.gui.GUI;
|
import cc.carm.lib.easyplugin.gui.GUI;
|
||||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class PagedGUI extends GUI {
|
public abstract class PagedGUI extends GUI {
|
||||||
|
|
||||||
List<GUIItem> container = new ArrayList<>();
|
protected List<GUIItem> container = new ArrayList<>();
|
||||||
public int page = 1;
|
protected int page = 1;
|
||||||
|
|
||||||
public PagedGUI(GUIType type, String name) {
|
protected PagedGUI(@NotNull GUIType type, @NotNull String title) {
|
||||||
super(type, name);
|
super(type, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int addItem(GUIItem i) {
|
public int addItem(@NotNull GUIItem i) {
|
||||||
container.add(i);
|
container.add(i);
|
||||||
return container.size() - 1;
|
return container.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int addItem(int index, @NotNull GUIItem i) {
|
||||||
|
container.add(index, i);
|
||||||
|
return container.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int addItemStack(@NotNull ItemStack itemStack) {
|
||||||
|
return addItem(new GUIItem(itemStack));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从GUI中移除一个物品
|
* 从GUI中移除一个物品
|
||||||
*
|
*
|
||||||
* @param item 物品
|
* @param item 物品
|
||||||
*/
|
*/
|
||||||
public void removeItem(GUIItem item) {
|
public void removeItem(@NotNull GUIItem item) {
|
||||||
container.remove(item);
|
container.remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从GUI中移除一个物品
|
* 从GUI中移除一个物品
|
||||||
*
|
*
|
||||||
* @param slot 物品格子数
|
* @param index 物品格子数
|
||||||
*/
|
*/
|
||||||
public void removeItem(int slot) {
|
public void removeItem(int index) {
|
||||||
container.remove(slot);
|
container.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GUIItem> getItemsContainer() {
|
public @NotNull List<GUIItem> getPagedContainer() {
|
||||||
return new ArrayList<>(container);
|
return this.container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
2
pom.xml
2
pom.xml
@ -15,7 +15,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.5.9</version>
|
<version>1.5.10</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>base/color</module>
|
<module>base/color</module>
|
||||||
<module>base/utils</module>
|
<module>base/utils</module>
|
||||||
|
Loading…
Reference in New Issue
Block a user