Search in sources :

Example 1 with Type

use of com.massivecraft.massivecore.command.type.Type in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreCommandSet method setValue.

public <T extends Serializable> void setValue(EventMassiveCoreCommandSet<T> event) throws MassiveException {
    String senderId = event.getSenderId();
    String targetId = event.getTargetId();
    T after = event.getValue();
    PlayerValue<T> playerValue = event.getPlayerValue();
    String name = event.getName();
    Player player = IdUtil.getPlayer(targetId);
    if (player == null)
        return;
    T before = playerValue.getValue(player);
    Type<T> type = (Type<T>) RegistryType.getType(after.getClass());
    String afterDesc = type.getVisual(after);
    String targetDesc = this.getTargetDesc(targetId, senderId, name);
    // NoChange
    if (after == before) {
        throw new MassiveException().addMsg("%s<i> is already <h>%s<i>.", targetDesc, afterDesc);
    }
    // Apply
    playerValue.setValue(after, player);
    // Inform
    MixinMessage.get().msgOne(senderId, "%s<i> is now <h>%s<i>.", targetDesc, afterDesc);
    // Inform target
    if (!targetId.equals(senderId)) {
        MixinMessage.get().msgOne(targetId, "%s<i> is now <h>%s<i>.", getTargetDesc(targetId, targetId, name), afterDesc);
    }
}
Also used : Player(org.bukkit.entity.Player) RegistryType(com.massivecraft.massivecore.command.type.RegistryType) Type(com.massivecraft.massivecore.command.type.Type) MassiveException(com.massivecraft.massivecore.MassiveException)

Example 2 with Type

use of com.massivecraft.massivecore.command.type.Type in project MassiveCore by MassiveCraft.

the class TypeCombined method getVisualMsonInner.

// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public Mson getVisualMsonInner(T value, CommandSender sender) {
    // Create
    List<Mson> parts = new MassiveList<>();
    // Fill
    for (Entry<Type<?>, Object> entry : this.splitEntriesUser(value)) {
        Type<Object> type = (Type<Object>) entry.getKey();
        Mson part = type.getVisualMson(entry.getValue(), sender);
        if (!this.isVisualMsonNullIncluded() && part == null)
            continue;
        parts.add(part);
    }
    // Return
    return Mson.implode(parts, this.getVisualMsonSeparator());
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList) Type(com.massivecraft.massivecore.command.type.Type)

Aggregations

Type (com.massivecraft.massivecore.command.type.Type)2 MassiveException (com.massivecraft.massivecore.MassiveException)1 MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 RegistryType (com.massivecraft.massivecore.command.type.RegistryType)1 Mson (com.massivecraft.massivecore.mson.Mson)1 Player (org.bukkit.entity.Player)1