Commit 835d14ad authored by Ashijin's avatar Ashijin
Browse files

Fixed several issues with gestures

parent 2880853f
......@@ -4,6 +4,7 @@ import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.constants.Permissions;
import io.lumine.cosmetics.managers.gestures.Gesture;
import io.lumine.cosmetics.managers.gestures.GestureManager;
import io.lumine.cosmetics.players.Profile;
import io.lumine.utils.commands.Command;
import org.bukkit.command.CommandSender;
......@@ -22,16 +23,22 @@ public class EmotesCommand extends Command<MCCosmeticsPlugin> {
@Override
public boolean onCommand(CommandSender commandSender, String[] strings) {
if(strings.length == 0){
if(strings.length == 0) {
CommandHelper.sendError(commandSender, "Syntax: /emote [emote_name]");
return false;
}
Optional<Profile> profile = plugin.getProfiles().getProfile(((Player)commandSender).getName());
Optional<Profile> maybeProfile = plugin.getProfiles().getProfile(((Player)commandSender).getName());
var cosmetic = getPlugin().getGestureManager().getCosmetic(strings[0]);
maybeProfile.ifPresent(profile -> {
var maybeCosmetic = getPlugin().getGestureManager().getCosmetic(strings[0]);
maybeCosmetic.ifPresent(gesture -> {
gesture.equip(profile);
((GestureManager) gesture.getManager()).playGesture(profile);
});
});
profile.ifPresent(value -> cosmetic.ifPresent(gesture -> gesture.equip(value)));
/**TODO: Make it silently tell you if you only typed /emote instead of erroring **/
return true;
}
......
......@@ -70,6 +70,7 @@ public class Gesture extends AbstractCosmetic {
.click((prof,p) -> {
if(prof.getPlayer().isOp() || prof.has(this)) {
prof.equip(this);
((GestureManager) getManager()).playGesture(prof);
CommandHelper.sendSuccess(p, "Now playing gesture: " + getDisplay());
p.closeInventory();
} else {
......
......@@ -58,7 +58,21 @@ public class GestureManager extends MCCosmeticsManager<Gesture> {
@Override
public void equip(CosmeticProfile profile) {
// Gestures aren't really equipped
}
@Override
public void unequip(CosmeticProfile profile) {
stopGesture(profile);
}
public void playGesture(CosmeticProfile profile) {
if(ticking.containsKey(profile.getPlayer())) {
return;
}
final var maybeEquipped = profile.getEquipped(Gesture.class);
if(maybeEquipped.isEmpty()) {
return;
}
......@@ -68,26 +82,25 @@ public class GestureManager extends MCCosmeticsManager<Gesture> {
return;
}
final var player = profile.getPlayer();
CustomPlayerModel model = new CustomPlayerModel(player, gesture.getQuitMethod(), gesture.isCanLook(), () -> profile.unequip(gesture));
ticking.put(player, model);
final var animation = model.getTexture().isSlim() ? gesture.getSlimGesture() : gesture.getDefaultGesture();
model.playAnimation(animation);
final var player = profile.getPlayer();
CustomPlayerModel model = new CustomPlayerModel(player, gesture.getQuitMethod(), gesture.isCanLook(), () -> profile.unequip(gesture));
ticking.put(player, model);
final var animation = model.getTexture().isSlim() ? gesture.getSlimGesture() : gesture.getDefaultGesture();
model.playAnimation(animation);
((VolatileEquipmentHelper) getNMSHelper()).apply(profile);
((VolatileEquipmentHelper) getNMSHelper()).apply(profile);
}
@Override
public void unequip(CosmeticProfile profile) {
CustomPlayerModel model = ticking.remove(profile.getPlayer());
if(model == null)
return;
model.despawn();
((VolatileEquipmentHelper) getNMSHelper()).unapply(profile);
public void stopGesture(CosmeticProfile profile) {
CustomPlayerModel model = ticking.remove(profile.getPlayer());
if(model == null) {
return;
}
model.despawn();
((VolatileEquipmentHelper) getNMSHelper()).unapply(profile);
}
private void loadGestures() {
PlayerAnimator.api.getAnimationManager().clearRegistry();
final String type = CosmeticType.folder(cosmeticClass);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment