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
|
|
@ -30,10 +30,12 @@ ca.affected: Player with this permission will be affected by the plugin
|
|||
ca.bypass.fuse: Allow player to combine every enchantments to every item (no custom limit)
|
||||
ca.bypass.level: Allow player to bypass every level limit (no custom limit)
|
||||
ca.command.reload: Allow administrator to reload the plugin's configs
|
||||
ca.config.edit: Allow administrator to reload the plugin's configs in game
|
||||
```
|
||||
### Commands
|
||||
```yml
|
||||
anvilconfigreload or carl: Reload every config of this plugin
|
||||
customanvilconfig: open a menu for administrator to edit plugin's config in game
|
||||
```
|
||||
---
|
||||
### Default Configuration:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "xyz.alexcrea"
|
||||
version = "1.3"
|
||||
version = "1.3.0-alpha-1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import org.bukkit.Bukkit
|
|||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
||||
import xyz.alexcrea.cuanvil.command.TestExecutor
|
||||
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.util.Metrics
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
|
|
@ -30,11 +30,13 @@ class CustomAnvil : JavaPlugin() {
|
|||
const val bypassLevelPermission = "ca.bypass.level"
|
||||
// Permission string required to reload the config
|
||||
const val commandReloadPermission = "ca.command.reload"
|
||||
// Permission string required to edit the plugin's config
|
||||
const val editConfigPermission = "ca.config.edit"
|
||||
|
||||
// Command Name to reload the config
|
||||
const val commandReloadName = "anvilconfigreload"
|
||||
// Test command name
|
||||
const val commandTestName = "test"
|
||||
const val commandTestName = "customanvilconfig"
|
||||
|
||||
// Current plugin instance
|
||||
lateinit var instance: CustomAnvil
|
||||
|
|
@ -113,7 +115,7 @@ class CustomAnvil : JavaPlugin() {
|
|||
command?.setExecutor(ReloadExecutor())
|
||||
|
||||
command = getCommand(commandTestName)
|
||||
command?.setExecutor(TestExecutor())
|
||||
command?.setExecutor(EditConfigExecutor())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
package xyz.alexcrea.cuanvil.command
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import xyz.alexcrea.cuanvil.gui.MainConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions
|
||||
|
||||
class TestExecutor : CommandExecutor {
|
||||
class EditConfigExecutor : CommandExecutor {
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
|
||||
if(!sender.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||
return false
|
||||
}
|
||||
if(sender !is HumanEntity) return false
|
||||
MainConfigGui.INSTANCE.show(sender)
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
main: io.delilaheve.CustomAnvil
|
||||
name: CustomAnvil
|
||||
prefix: "Custom Anvil"
|
||||
version: 1.3
|
||||
version: 1.3.0-alpha-1
|
||||
description: Allow to customise anvil mechanics
|
||||
api-version: 1.18
|
||||
load: POSTWORLD
|
||||
|
|
@ -18,8 +18,11 @@ commands:
|
|||
#- acreload # anvil config reload
|
||||
#- careload # custom anvil reload
|
||||
- carl # custom anvil reload
|
||||
test:
|
||||
description: test cmd
|
||||
customanvilconfig:
|
||||
description: open a menu for administrator to edit plugin's config in game
|
||||
permission: ca.config.edit
|
||||
aliases:
|
||||
- configanvil
|
||||
|
||||
permissions:
|
||||
ca.affected:
|
||||
|
|
@ -34,6 +37,9 @@ permissions:
|
|||
ca.command.reload:
|
||||
default: op
|
||||
description: Allow administrator to reload the plugin's configs
|
||||
ca.config.edit:
|
||||
default: op
|
||||
description: Allow administrator to reload the plugin's configs in game
|
||||
|
||||
# soft depend on old name so I can disable it if it is on the same server
|
||||
# as it is the old name for this plugin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue