Implement configuration toggles for extra features
This commit is contained in:
parent
f7d9b7f30d
commit
3a0adad1f0
@ -7,4 +7,6 @@ search:
|
|||||||
==: dev.w1zzrd.invtweaks.serialization.SearchConfig
|
==: dev.w1zzrd.invtweaks.serialization.SearchConfig
|
||||||
searchRadiusX: 8
|
searchRadiusX: 8
|
||||||
searchRadiusY: 8
|
searchRadiusY: 8
|
||||||
searchRadiusZ: 8
|
searchRadiusZ: 8
|
||||||
|
ghostClick: true
|
||||||
|
capitator: true
|
@ -51,8 +51,8 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
logger.fine(LOG_PLUGIN_NAME + " Plugin enabled");
|
logger.fine(LOG_PLUGIN_NAME + " Plugin enabled");
|
||||||
|
|
||||||
initEnchantments();
|
|
||||||
enablePersistentData();
|
enablePersistentData();
|
||||||
|
initEnchantments();
|
||||||
initCommands();
|
initCommands();
|
||||||
initEvents();
|
initEvents();
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
disableEvents();
|
disableEvents();
|
||||||
disableCommands();
|
disableCommands();
|
||||||
disablePersistentData();
|
|
||||||
disableEnchantments();
|
disableEnchantments();
|
||||||
|
disablePersistentData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,8 +89,12 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initEnchantments() {
|
private void initEnchantments() {
|
||||||
capitatorEnchantmentKey = new NamespacedKey(this, ENCHANTMENT_CAPITATOR_NAME);
|
final boolean activateCapitator = getConfig().getBoolean("capitator", true);
|
||||||
capitatorEnchantment = new CapitatorEnchantment(ENCHANTMENT_CAPITATOR_NAME, capitatorEnchantmentKey);
|
|
||||||
|
if (activateCapitator) {
|
||||||
|
capitatorEnchantmentKey = new NamespacedKey(this, ENCHANTMENT_CAPITATOR_NAME);
|
||||||
|
capitatorEnchantment = new CapitatorEnchantment(ENCHANTMENT_CAPITATOR_NAME, capitatorEnchantmentKey);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Field acceptingField = Enchantment.class.getDeclaredField("acceptingNew");
|
final Field acceptingField = Enchantment.class.getDeclaredField("acceptingNew");
|
||||||
@ -98,13 +102,16 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
acceptingField.set(null, true);
|
acceptingField.set(null, true);
|
||||||
|
|
||||||
Enchantment.registerEnchantment(capitatorEnchantment);
|
if (activateCapitator)
|
||||||
|
Enchantment.registerEnchantment(capitatorEnchantment);
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableEnchantments() {
|
private void disableEnchantments() {
|
||||||
|
final boolean activateCapitator = getConfig().getBoolean("capitator", true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Field byKeyField = Enchantment.class.getDeclaredField("byKey");
|
final Field byKeyField = Enchantment.class.getDeclaredField("byKey");
|
||||||
final Field byNameField = Enchantment.class.getDeclaredField("byName");
|
final Field byNameField = Enchantment.class.getDeclaredField("byName");
|
||||||
@ -116,8 +123,11 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
final Object byName = byNameField.get(null);
|
final Object byName = byNameField.get(null);
|
||||||
|
|
||||||
if (byKey instanceof final Map<?, ?> byKeyMap && byName instanceof final Map<?, ?> byNameMap) {
|
if (byKey instanceof final Map<?, ?> byKeyMap && byName instanceof final Map<?, ?> byNameMap) {
|
||||||
byKeyMap.remove(capitatorEnchantmentKey);
|
|
||||||
byNameMap.remove(ENCHANTMENT_CAPITATOR_NAME);
|
if (activateCapitator) {
|
||||||
|
byKeyMap.remove(capitatorEnchantmentKey);
|
||||||
|
byNameMap.remove(ENCHANTMENT_CAPITATOR_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -131,14 +141,18 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
* Initialize event listeners for this plugin
|
* Initialize event listeners for this plugin
|
||||||
*/
|
*/
|
||||||
private void initEvents() {
|
private void initEvents() {
|
||||||
|
final boolean activateCapitator = getConfig().getBoolean("capitator", true);
|
||||||
|
final boolean activateGhostClick = getConfig().getBoolean("ghostClick", true);
|
||||||
|
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
final PluginManager pluginManager = getServer().getPluginManager();
|
||||||
|
|
||||||
pluginManager.registerEvents(new GhostClickListener(), this);
|
if (activateGhostClick)
|
||||||
|
pluginManager.registerEvents(new GhostClickListener(), this);
|
||||||
pluginManager.registerEvents(new StackReplaceListener(this), this);
|
pluginManager.registerEvents(new StackReplaceListener(this), this);
|
||||||
pluginManager.registerEvents(new SortListener(), this);
|
pluginManager.registerEvents(new SortListener(), this);
|
||||||
pluginManager.registerEvents(new MagnetismListener(magnetCommandExecutor), this);
|
pluginManager.registerEvents(new MagnetismListener(magnetCommandExecutor), this);
|
||||||
pluginManager.registerEvents(new TabCompletionListener(), this);
|
pluginManager.registerEvents(new TabCompletionListener(), this);
|
||||||
pluginManager.registerEvents(new TreeCapitatorListener(capitatorEnchantment), this);
|
pluginManager.registerEvents(new TreeCapitatorListener(activateCapitator ? capitatorEnchantment : null), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,16 +167,22 @@ public final class InvTweaksPlugin extends JavaPlugin {
|
|||||||
* Initialize commands registered by this plugin
|
* Initialize commands registered by this plugin
|
||||||
*/
|
*/
|
||||||
private void initCommands() {
|
private void initCommands() {
|
||||||
|
final boolean activateCapitator = getConfig().getBoolean("capitator", true);
|
||||||
|
|
||||||
sortCommandExecutor = new SortCommandExecutor();
|
sortCommandExecutor = new SortCommandExecutor();
|
||||||
magnetCommandExecutor = new MagnetCommandExecutor(this, "magnet", getPersistentData());
|
magnetCommandExecutor = new MagnetCommandExecutor(this, "magnet", getPersistentData());
|
||||||
searchCommandExecutor = new SearchCommandExecutor(this, "search");
|
searchCommandExecutor = new SearchCommandExecutor(this, "search");
|
||||||
capitatorCommand = new CapitatorCommand(capitatorEnchantment);
|
|
||||||
|
if (activateCapitator)
|
||||||
|
capitatorCommand = new CapitatorCommand(capitatorEnchantment);
|
||||||
|
|
||||||
// TODO: Bind command by annotation
|
// TODO: Bind command by annotation
|
||||||
Objects.requireNonNull(getCommand("sort")).setExecutor(sortCommandExecutor);
|
Objects.requireNonNull(getCommand("sort")).setExecutor(sortCommandExecutor);
|
||||||
Objects.requireNonNull(getCommand("magnet")).setExecutor(magnetCommandExecutor);
|
Objects.requireNonNull(getCommand("magnet")).setExecutor(magnetCommandExecutor);
|
||||||
Objects.requireNonNull(getCommand("search")).setExecutor(searchCommandExecutor);
|
Objects.requireNonNull(getCommand("search")).setExecutor(searchCommandExecutor);
|
||||||
Objects.requireNonNull(getCommand("capitator")).setExecutor(capitatorCommand);
|
|
||||||
|
if (activateCapitator)
|
||||||
|
Objects.requireNonNull(getCommand("capitator")).setExecutor(capitatorCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,11 @@ public class CapitatorCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (capitatorEnchantment == null) {
|
||||||
|
sender.spigot().sendMessage(CommandUtils.errorMessage("Tree capitation is disabled!"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (sender instanceof final Player caller) {
|
if (sender instanceof final Player caller) {
|
||||||
final ItemStack stack = caller.getInventory().getItemInMainHand();
|
final ItemStack stack = caller.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user