Search in sources :

Example 16 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class CommandEditContainerAbstract method attemptSetPerform.

@SuppressWarnings("unchecked")
@Override
public void attemptSetPerform(V after) {
    V before = this.getInheritedValue();
    Mson descProperty = this.getProperty().getDisplayNameMson();
    // Apply
    // We set the new property value.
    this.setValue(after);
    // Create messages
    List<Mson> messages = new MassiveList<>();
    messages.add(mson(descProperty, mson(" for ").color(ChatColor.GRAY), this.getObjectVisual(), mson(" edited:").color(ChatColor.GRAY)));
    // Note: The result of getAdditions is not actually V, but the implementation doesn't care.
    Collection<Object> additions = ContainerUtil.getAdditions(before, after);
    if (!additions.isEmpty()) {
        messages.add(Mson.prepondfix(mson("Additions:").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) additions, sender), null));
    }
    // Note: The result of getDeletions is not actually V, but the implementation doesn't care.
    Collection<Object> deletions = ContainerUtil.getDeletions(before, after);
    if (!deletions.isEmpty()) {
        messages.add(Mson.prepondfix(mson("Deletions:").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) deletions, sender), null));
    }
    message(messages);
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList)

Example 17 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class Txt method getPage.

@SuppressWarnings("unchecked")
public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, int pageheight, MassiveCommand command, List<String> args) {
    // Create Ret
    List<Mson> ret = new MassiveList<>();
    int pageZeroBased = pageHumanBased - 1;
    int pagecount = (int) Math.ceil(((double) lines.size()) / pageheight);
    // Add Title
    Mson msonTitle = Txt.titleizeMson(title, pagecount, pageHumanBased, command, args);
    ret.add(msonTitle);
    // Check empty and invalid
    if (pagecount == 0) {
        ret.add(getMessageEmpty());
        return ret;
    } else if (pageZeroBased < 0 || pageHumanBased > pagecount) {
        ret.add(getMessageInvalid(pagecount));
        return ret;
    }
    // Get Lines
    int from = pageZeroBased * pageheight;
    int to = from + pageheight;
    if (to > lines.size()) {
        to = lines.size();
    }
    // Check object type and add lines
    Object first = lines.get(0);
    if (first instanceof String) {
        for (String line : (List<String>) lines.subList(from, to)) {
            ret.add(Mson.fromParsedMessage(line));
        }
    } else if (first instanceof Mson) {
        ret.addAll((List<Mson>) lines.subList(from, to));
    } else {
        throw new IllegalArgumentException("The lines must be either String or Mson.");
    }
    // Return Ret
    return ret;
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList) ArrayList(java.util.ArrayList) MassiveList(com.massivecraft.massivecore.collections.MassiveList) List(java.util.List)

Example 18 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class TestTypeEnchantment method test.

// -------------------------------------------- //
// TEST
// -------------------------------------------- //
@Override
public void test() {
    final List<Enchantment> enchantments = new MassiveList<>(Arrays.asList(Enchantment.values()));
    for (Iterator<Enchantment> iterator = enchantments.iterator(); iterator.hasNext(); ) {
        Enchantment enchantment = iterator.next();
        if (TypeEnchantment.ID_TO_RAWNAMES.containsKey(enchantment.getId())) {
            iterator.remove();
        }
    }
    for (Enchantment enchantment : enchantments) {
        String issue = Txt.parse("<i>The enchantment <h>%s (%d)<i> lacks nicename in TypeEnchantment.", enchantment.getName(), enchantment.getId());
        this.addIssue(issue);
    }
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) TypeEnchantment(com.massivecraft.massivecore.command.type.TypeEnchantment) Enchantment(org.bukkit.enchantments.Enchantment)

Example 19 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class BoardUtil method setActiveInner.

// -------------------------------------------- //
// UPDATE
// -------------------------------------------- //
@Override
public void setActiveInner(boolean active) {
    if (active) {
    // We do not trigger an update here.
    // We must wait for the first server tick.
    // Otherwise the Scoreboard manager is null.
    } else {
        // We delete everything marked as temporary on deactivation.
        List<Objective> objectives = new MassiveList<>(getTemporaryObjectives());
        for (Objective objective : objectives) {
            deleteObjective(objective);
        }
        List<Team> teams = new MassiveList<>(getTemporaryTeams());
        for (Team team : teams) {
            deleteTeam(team);
        }
    }
}
Also used : Objective(org.bukkit.scoreboard.Objective) MassiveList(com.massivecraft.massivecore.collections.MassiveList) Team(org.bukkit.scoreboard.Team)

Example 20 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class InventoryUtil method getChangesDrag.

// Drag events by nature only matters when they affect the top inventory.
// What you are holding in the cursor is already yours.
// If you drag it into your own inventory you are not really taking anything.
// If you drag into the top inventory however, you may both give and take.
// You "take" by dragging over an existing item (since we don't do any math).
protected static List<Entry<ItemStack, Integer>> getChangesDrag(InventoryDragEvent event) {
    // Create
    List<Entry<ItemStack, Integer>> ret = new MassiveList<>();
    // Fill
    final Inventory inventory = event.getInventory();
    for (Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) {
        int rawSlot = entry.getKey();
        if (InventoryUtil.isBottomInventory(rawSlot, inventory))
            continue;
        ItemStack take = inventory.getItem(rawSlot);
        if (isSomething(take))
            ret.add(new SimpleEntry<>(take, +take.getAmount()));
        ItemStack give = entry.getValue();
        if (isSomething(give))
            ret.add(new SimpleEntry<>(give, -give.getAmount()));
    }
    // Return
    return ret;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) MassiveList(com.massivecraft.massivecore.collections.MassiveList) SimpleEntry(java.util.AbstractMap.SimpleEntry) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) MixinInventory(com.massivecraft.massivecore.mixin.MixinInventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Aggregations

MassiveList (com.massivecraft.massivecore.collections.MassiveList)22 Mson (com.massivecraft.massivecore.mson.Mson)7 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 Entry (java.util.Map.Entry)4 ItemStack (org.bukkit.inventory.ItemStack)3 ChatColor (org.bukkit.ChatColor)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 MassiveException (com.massivecraft.massivecore.MassiveException)1 EditorType (com.massivecraft.massivecore.command.editor.annotation.EditorType)1 EditorTypeInner (com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner)1 Requirement (com.massivecraft.massivecore.command.requirement.Requirement)1 Type (com.massivecraft.massivecore.command.type.Type)1 TypeEnchantment (com.massivecraft.massivecore.command.type.TypeEnchantment)1 TypeEntityType (com.massivecraft.massivecore.command.type.enumeration.TypeEntityType)1 TypeFireworkEffectType (com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType)1 TypeOcelotType (com.massivecraft.massivecore.command.type.enumeration.TypeOcelotType)1 TypeRabbitType (com.massivecraft.massivecore.command.type.enumeration.TypeRabbitType)1 TypeSkeletonType (com.massivecraft.massivecore.command.type.enumeration.TypeSkeletonType)1 TypeWorldType (com.massivecraft.massivecore.command.type.enumeration.TypeWorldType)1 EventMassiveCoreLorePriority (com.massivecraft.massivecore.event.EventMassiveCoreLorePriority)1