mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add config menu/command name & permission. also edit version number.
This commit is contained in:
parent
321a2b1cc8
commit
6e0d1037bc
6 changed files with 54 additions and 14 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package xyz.alexcrea.cuanvil.gui.utils;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
|
|
@ -12,7 +14,8 @@ import java.util.function.Consumer;
|
|||
|
||||
public class GuiGlobalActions {
|
||||
|
||||
public static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
|
||||
public final static String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
|
||||
public final static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
|
||||
|
||||
|
||||
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(
|
||||
|
|
@ -21,11 +24,18 @@ public class GuiGlobalActions {
|
|||
@NotNull Object... args){
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to open inventory if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Constructor<? extends Gui> constructor = clazz.getConstructor(argClass);
|
||||
// Assume constructor is accessible
|
||||
Gui gui = constructor.newInstance(args);
|
||||
gui.show(event.getWhoClicked());
|
||||
gui.show(player);
|
||||
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
|
||||
InstantiationException e) {
|
||||
|
|
@ -49,8 +59,15 @@ public class GuiGlobalActions {
|
|||
|
||||
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(@NotNull Gui goal) {
|
||||
return event -> {
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to open inventory if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
goal.show(event.getWhoClicked());
|
||||
goal.show(player);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -59,14 +76,22 @@ public class GuiGlobalActions {
|
|||
@NotNull ValueUpdatableGui goal) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to save configuration if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save setting
|
||||
if(!setting.onSave()){
|
||||
event.getWhoClicked().sendMessage("\u00A7cSomething wrong happen while saving the change of value.");
|
||||
player.sendMessage("\u00A7cSomething wrong happen while saving the change of value.");
|
||||
}
|
||||
// Update gui for the one who have it open
|
||||
goal.updateGuiValues();
|
||||
// Then show
|
||||
goal.show(event.getWhoClicked());
|
||||
goal.show(player);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue