Skip to content

Commit

Permalink
misc: 一些调整
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Oct 27, 2024
1 parent 755e078 commit ebe9c3a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/main/java/xyz/nifeather/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,8 @@ public boolean registerProviders(List<DisguiseProvider> providers)
* @param player 发起玩家
* @return 操作是否成功
*/
public boolean doQuickDisguise(Player player, boolean ignoreActionItem)
public boolean tryQuickDisguise(Player player)
{
var actionItem = ignoreActionItem ? null : getActionItem();
var state = this.getDisguiseStateFor(player);
var mainHandItem = player.getEquipment().getItemInMainHand();
var mainHandItemType = mainHandItem.getType();
Expand Down Expand Up @@ -527,9 +526,6 @@ public boolean doQuickDisguise(Player player, boolean ignoreActionItem)
}
else
{
if (actionItem != null && !mainHandItemType.equals(actionItem))
return false;

var targetedEntity = player.getTargetEntity(5);

if (targetedEntity != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args)
return true;
}

item = ItemUtils.buildSkillItemFrom(item);
item = ItemUtils.buildDisguiseToolFrom(item);
player.getEquipment().setItemInMainHand(item);

sender.sendMessage(MessageUtils.prefixes(sender, CommandStrings.success()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ private boolean invokeOrDisguise(Player player, Action action, EquipmentSlot slo
{
if (action.isRightClick()) // 下蹲+右键:快速伪装、打开伪装菜单
{
boolean isDisguiseTool = ItemUtils.isSkillActivateItem(mainHandItem);
boolean isDisguiseTool = ItemUtils.isDisguiseTool(mainHandItem);
boolean isValidItem = mainHandItem.getType() == Material.PLAYER_HEAD || isDisguiseTool;

if (!isValidItem || action == Action.RIGHT_CLICK_BLOCK) return false;

if (!morphs.doQuickDisguise(player, true))
if (!morphs.tryQuickDisguise(player))
{
if (isDisguiseTool && InventoryGui.getOpen(player) == null)
{
Expand All @@ -267,15 +267,15 @@ private boolean invokeOrDisguise(Player player, Action action, EquipmentSlot slo
}
else // 下蹲+左键:取消伪装
{
if (!ItemUtils.isSkillActivateItem(mainHandItem) || disguiseState == null)
if (!ItemUtils.isDisguiseTool(mainHandItem) || disguiseState == null)
return false;

morphs.unMorph(player);
}
}
else
{
if (!ItemUtils.isSkillActivateItem(mainHandItem) || disguiseState == null)
if (!ItemUtils.isDisguiseTool(mainHandItem) || disguiseState == null)
return false;

if (action.isRightClick()) // 站立+右键:技能
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void prepareRecipe()

private void buildAndAddRecipe(RecipeProperty recipeProperty)
{
var resultItem = ItemUtils.buildSkillItemFrom(ItemStack.of(recipeProperty.resultMaterial()));
var resultItem = ItemUtils.buildDisguiseToolFrom(ItemStack.of(recipeProperty.resultMaterial()));
resultItem.editMeta(meta ->
{
meta.setRarity(ItemRarity.UNCOMMON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public void onMorphCommand(C2SMorphCommand c2SMorphCommand)
var id = c2SMorphCommand.getArgumentAt(0, "");

if (id.isEmpty() || id.isBlank())
manager.doQuickDisguise(player, true);
manager.tryQuickDisguise(player);
else if (manager.canMorph(player))
manager.morph(player, player, id, player.getTargetEntity(5));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xyz/nifeather/morph/utilities/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static String itemToStr(ItemStack stack)

public static final String SKILL_ACTIVATE_ITEM_KEY = "feathermorph:is_disguise_tool";

public static ItemStack buildSkillItemFrom(ItemStack stack)
public static ItemStack buildDisguiseToolFrom(ItemStack stack)
{
var nms = net.minecraft.world.item.ItemStack.fromBukkitCopy(stack);
var customData = nms.getComponents().get(DataComponents.CUSTOM_DATA);
Expand All @@ -89,7 +89,7 @@ public static ItemStack buildSkillItemFrom(ItemStack stack)
return nms.asBukkitMirror();
}

public static boolean isSkillActivateItem(ItemStack stack)
public static boolean isDisguiseTool(ItemStack stack)
{
var nms = net.minecraft.world.item.ItemStack.fromBukkitCopy(stack);
var customData = nms.getComponents().get(DataComponents.CUSTOM_DATA);
Expand Down

0 comments on commit ebe9c3a

Please sign in to comment.