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