The F keybind can now be fully customized

THIS DOES NOT MEAN YOU CAN CHANGE THE KEY!!!
This means you can change what happens when pressing F or when pressing F when sneaking. Check newest config.yml for more information
This commit is contained in:
ASangarin 2020-12-19 21:49:34 +01:00
parent 753f63104a
commit 89dbb4a980
3 changed files with 45 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.listener;
import net.Indyuce.mmocore.manager.ConfigManager;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
@ -20,9 +21,11 @@ public class SpellCast implements Listener {
@EventHandler
public void a(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
return;
ConfigManager.SwapAction action = player.isSneaking()
? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction;
if(action == ConfigManager.SwapAction.VANILLA) return;
PlayerData playerData = PlayerData.get(player);
event.setCancelled(true);
@ -30,7 +33,7 @@ public class SpellCast implements Listener {
* hotbar swap feature only if the player is sneaking while entering
* skill casting mode
*/
if (player.isSneaking() && MMOCore.plugin.configManager.hotbarSwap) {
if (action == ConfigManager.SwapAction.HOTBAR_SWAP) {
player.playSound(player.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1, 1);
for (int j = 0; j < 9; j++) {
ItemStack replaced = player.getInventory().getItem(j + 9 * 3);
@ -40,7 +43,8 @@ public class SpellCast implements Listener {
return;
}
if (!playerData.isCasting() && playerData.getBoundSkills().size() > 0) {
if (!((!MMOCore.plugin.configManager.canCreativeCast && player.getGameMode() == GameMode.CREATIVE) || player.getGameMode() == GameMode.SPECTATOR)
&& !playerData.isCasting() && playerData.getBoundSkills().size() > 0) {
playerData.skillCasting = new SkillCasting(playerData);
player.playSound(player.getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1, 2);
}
@ -93,7 +97,10 @@ public class SpellCast implements Listener {
@EventHandler
public void stopCasting(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if(!playerData.isOnline()) return;
ConfigManager.SwapAction action = player.isSneaking()
? MMOCore.plugin.configManager.sneakingSwapAction
: MMOCore.plugin.configManager.normalSwapAction;
if(action != ConfigManager.SwapAction.SPELL_CAST || !playerData.isOnline()) return;
if (event.getPlayer().equals(playerData.getPlayer()) && !player.isSneaking()) {
player.playSound(player.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 2);
MMOCore.plugin.configManager.getSimpleMessage("casting.no-longer").send(playerData.getPlayer());

View File

@ -9,6 +9,7 @@ import net.Indyuce.mmocore.api.util.input.PlayerInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.util.EnumUtils;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -28,6 +29,8 @@ public class ConfigManager {
public String partyChatPrefix, noSkillBoundPlaceholder;
public ChatColor staminaFull, staminaHalf, staminaEmpty;
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown;
public SwapAction normalSwapAction, sneakingSwapAction;
public boolean canCreativeCast;
private final FileConfiguration messages;
private final boolean chatInput;
@ -100,6 +103,14 @@ public class ConfigManager {
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
normalSwapAction = EnumUtils.getIfPresent(SwapAction.class,
MMOCore.plugin.getConfig().getString("swap-keybind.normal")
.toUpperCase()).orElse(SwapAction.VANILLA);
sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class,
MMOCore.plugin.getConfig().getString("swap-keybind.sneaking")
.toUpperCase()).orElse(SwapAction.VANILLA);
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
}
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
@ -172,4 +183,10 @@ public class ConfigManager {
return !msg.isEmpty();
}
}
public enum SwapAction {
VANILLA,
SPELL_CAST,
HOTBAR_SWAP
}
}

View File

@ -8,7 +8,7 @@
# a Spigot Plugin by Team Requiem
# DO NOT TOUCH
config-version: 3
config-version: 4
# Auto-Save feature automatically saves playerdata
# (class, level, etc.) and guild data
@ -119,10 +119,24 @@ death-exp-loss:
# Allows to toggle exp hologram from gaining experience
display-exp-holograms: true
# Put the "value" of the action you want.
# If the value is invalid or empty it will
# default to the vanilla minecraft action.
# spell_cast
# Enters the default spell casting mode
# hotbar_swap
# Players can swap their hotbar with the 9 inventory slots
# right above it by pressing [swap items] while crouching.
# THis allows players to have two combat item sets.
hotbar-swap: true
# - vanilla
# The default F action, swapping main hand and offhand.
swap-keybind:
normal: spell_cast
sneaking: hotbar_swap
# Set this to true to allow players
# in creative mode to enter casting mode
can-creative-cast: false
# Use this option if you're having issue with Anvil GUIs.
# This replaces anvil inputs by chat inputs.