Implement item linking

This commit is contained in:
Draycia committed 2021-10-18 22:43:58 -07:00
1 parent 5b72fce0f0
commit 6269f52349
13 files changed
+132 -35

No files matched your search

@@ -142,7 +142,7 @@ public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Resu
*/
public record Result(boolean cancelled, Component reason) implements ResultedCarbonEvent.Result {
private static final Result ALLOWED = new Result(true, empty());
private static final Result ALLOWED = new Result(false, empty());
/**
* Returns a Result that denotes the event was allowed and not cancelled.
@@ -162,7 +162,7 @@ public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Resu
* @since 2.0.0
*/
public static Result denied(final Component reason) {
return new Result(false, reason);
return new Result(true, reason);
}
}
@@ -20,6 +20,7 @@ public final class CarbonEventHandler {
if (event instanceof ResultedCarbonEvent<@NonNull ?> rce) {
return !rce.result().cancelled();
}
return true;
});
@@ -6,6 +6,7 @@ import java.util.Objects;
import java.util.UUID;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.punishments.MuteEntry;
import net.draycia.carbon.api.util.InventorySlot;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.text.Component;
@@ -101,12 +102,13 @@ public interface CarbonPlayer extends Audience, Identified {
UUID uuid();
/**
* Creates a {@link Component} with a content and item hover given the player's actively held item.
* Creates the chat component for the item in the {@link InventorySlot}, or null if the slot is empty.
*
* @return the player's held item as an item hover component
* @param slot the inventory slot containing the item
* @return the chat component for the item in the slot, or null if the slot is empty
* @since 2.0.0
*/
Component createItemHoverComponent();
@Nullable Component createItemHoverComponent(final InventorySlot slot);
/**
* The player's locale.
@@ -0,0 +1,25 @@
package net.draycia.carbon.api.util;
import java.util.List;
public final class InventorySlot {
public static InventorySlot of(final String... placeholders) {
return new InventorySlot(placeholders);
}
private List<String> placeholders;
private InventorySlot() {
}
private InventorySlot(final String... placeholders) {
this.placeholders = List.of(placeholders);
}
public List<String> placeholders() {
return this.placeholders;
}
}
@@ -0,0 +1,16 @@
package net.draycia.carbon.api.util;
import java.util.List;
public final class InventorySlots {
public static final InventorySlot HELMET = InventorySlot.of("helm", "helmet", "hat", "head");
public static final InventorySlot CHEST = InventorySlot.of("chest", "chestplate");
public static final InventorySlot LEGS = InventorySlot.of("legs", "leggings");
public static final InventorySlot BOOTS = InventorySlot.of("boots", "feet");
public static final InventorySlot MAIN_HAND = InventorySlot.of("main_hand", "hand", "item");
public static final InventorySlot OFF_HAND = InventorySlot.of("off_hand");
public static List<InventorySlot> VALUES = List.of(HELMET, CHEST, LEGS, BOOTS, MAIN_HAND, OFF_HAND);
}