mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,7 +55,9 @@ public interface CosmeticHolder {
|
||||
|
||||
boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe);
|
||||
|
||||
void updateCosmetic(@NotNull CosmeticSlot slot);
|
||||
boolean updateCosmetic(@NotNull CosmeticSlot slot);
|
||||
|
||||
boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, final Location from, final Location to);
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility, ensures that the given viewer and the given cosmetic holder
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Updates cosmetics whenever a player moves.
|
||||
*/
|
||||
public interface CosmeticMovementBehavior {
|
||||
void dispatchMove(
|
||||
final CosmeticUser user,
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
|
||||
/**
|
||||
* Generic updates that happen every tick or when manually requested to be dispatched.
|
||||
*/
|
||||
public interface CosmeticUpdateBehavior {
|
||||
void dispatchUpdate(final CosmeticUser user);
|
||||
}
|
||||
@@ -301,36 +301,39 @@ public class CosmeticUser implements CosmeticHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCosmetic(@NotNull CosmeticSlot slot) {
|
||||
public boolean updateCosmetic(@NotNull CosmeticSlot slot) {
|
||||
final Cosmetic cosmetic = playerCosmetics.get(slot);
|
||||
if(cosmetic == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(cosmetic instanceof CosmeticUpdateBehavior behavior)) {
|
||||
throw new IllegalArgumentException("attempted to update a cosmetic that does not implement CosmeticUpdateBehavior, " +
|
||||
"please ensure this cosmetic is properly allowed to update.");
|
||||
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticUpdateBehavior");
|
||||
return false;
|
||||
}
|
||||
|
||||
behavior.dispatchUpdate(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateMovementCosmetic(CosmeticSlot slot, final Location from, final Location to) {
|
||||
@Override
|
||||
public boolean updateMovementCosmetic(CosmeticSlot slot, final Location from, final Location to) {
|
||||
final Cosmetic cosmetic = playerCosmetics.get(slot);
|
||||
if(cosmetic == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(cosmetic instanceof CosmeticMovementBehavior behavior)) {
|
||||
throw new IllegalArgumentException("attempted to update a cosmetic that does not implement CosmeticUpdateBehavior, " +
|
||||
"please ensure this cosmetic is properly allowed to update.");
|
||||
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticMovementBehavior");
|
||||
return false;
|
||||
}
|
||||
|
||||
behavior.dispatchMove(this, from, to);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateCosmetic(Cosmetic cosmetic) {
|
||||
updateCosmetic(cosmetic.getSlot());
|
||||
public boolean updateCosmetic(final Cosmetic cosmetic) {
|
||||
return updateCosmetic(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
public void updateCosmetic() {
|
||||
|
||||
Reference in New Issue
Block a user