Search in sources :

Example 1 with MassiveList

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

the class Coll method logModification.

protected void logModification(E entity, Modification modification) {
    JsonObject lastRaw = entity.getLastRaw();
    if (lastRaw == null) {
        List<String> messages = new MassiveList<>();
        messages.add(Txt.parse("<pink>%s", this.getDebugName()));
        messages.add(Txt.parse("<aqua>%s", entity.getId()));
        messages.add(Txt.parse("<blue>%s", modification));
        String message = Txt.implode(messages, Txt.parse("<silver> | "));
        message = Txt.parse("<b>[lastRaw null] %s", message);
        MassiveCore.get().log(message);
        return;
    }
    JsonObject currentRaw = this.getGson().toJsonTree(entity).getAsJsonObject();
    List<String> changes = new MassiveList<>();
    // Check removal and modification.
    for (Entry<String, JsonElement> entry : lastRaw.entrySet()) {
        String name = entry.getKey();
        JsonElement currentValue = currentRaw.get(name);
        if (currentValue == null) {
            changes.add(Txt.parse("<b>%s", name));
            continue;
        }
        JsonElement lastValue = entry.getValue();
        if (MStore.equal(currentValue, lastValue))
            continue;
        changes.add(Txt.parse("<i>%s", name));
    }
    // Check for addition
    for (Entry<String, JsonElement> entry : currentRaw.entrySet()) {
        String name = entry.getKey();
        if (lastRaw.has(name))
            continue;
        changes.add(Txt.parse("<g>%s", name));
    }
    // Log
    if (changes.isEmpty())
        return;
    changes.add(0, Txt.parse("<pink>%s", this.getDebugName()));
    changes.add(1, Txt.parse("<aqua>%s", entity.getId()));
    String change = Txt.implode(changes, Txt.parse("<silver> | "));
    String message = Txt.parse("<b>[Unreported Modification] %s", change);
    MassiveCore.get().log(message);
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject)

Example 2 with MassiveList

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

the class Mson method fromParsedMessage.

public static Mson fromParsedMessage(String message) {
    if (message == null)
        throw new NullPointerException("message");
    // Everything must have a color.
    // Because when we split, we assume that each part starts with a color code.
    // Here we assure it starts with one.
    message = ensureStartsWithColorCode(message);
    // We split at color/format change.
    String[] parts = PATTERN_PARSE_PREFIX.split(message);
    // Since we start with a color, the first element will be empty.
    // We don't want that empty element.
    parts = Arrays.copyOfRange(parts, 1, parts.length);
    List<Mson> msons = new MassiveList<>();
    ChatColor latestColor = null;
    Boolean bold = null;
    Boolean italic = null;
    Boolean underlined = null;
    Boolean strikethrough = null;
    Boolean obfuscated = null;
    for (String part : parts) {
        ChatColor color = ChatColor.getByChar(part.charAt(0));
        String text = part.substring(1);
        if ((color != null && color.isColor()) || color == ChatColor.RESET) {
            latestColor = color;
            bold = null;
            italic = null;
            underlined = null;
            strikethrough = null;
            obfuscated = null;
        }
        if (color == ChatColor.RESET)
            latestColor = null;
        else if (color == ChatColor.BOLD)
            bold = true;
        else if (color == ChatColor.ITALIC)
            italic = true;
        else if (color == ChatColor.UNDERLINE)
            underlined = true;
        else if (color == ChatColor.STRIKETHROUGH)
            strikethrough = true;
        else if (color == ChatColor.MAGIC)
            obfuscated = true;
        // Don't add empty msons.
        if (text.isEmpty())
            continue;
        Mson mson = Mson.valueOf(text, latestColor, bold, italic, underlined, strikethrough, obfuscated, null, null, null, null, null);
        msons.add(mson);
    }
    return Mson.mson(msons);
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) ChatColor(org.bukkit.ChatColor)

Example 3 with MassiveList

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

the class PredicateElementRegexes method asPatterns.

// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
protected List<Pattern> asPatterns(Iterable<String> regexes) {
    // Create
    List<Pattern> ret = new MassiveList<>();
    // Fill
    for (String regex : regexes) {
        Pattern pattern = Pattern.compile(regex);
        ret.add(pattern);
    }
    // Return
    return ret;
}
Also used : Pattern(java.util.regex.Pattern) MassiveList(com.massivecraft.massivecore.collections.MassiveList)

Example 4 with MassiveList

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

the class CommandEditItemStacksOpen method asList.

public List<ItemStack> asList(Inventory inventory) {
    // Dodge Null
    if (inventory == null)
        return null;
    // Create Ret
    List<ItemStack> ret = new MassiveList<>();
    // Fill Ret
    for (int i = 0; i < inventory.getSize(); i++) {
        ItemStack itemStack = inventory.getItem(i);
        if (InventoryUtil.isNothing(itemStack))
            continue;
        itemStack = new ItemStack(itemStack);
        ret.add(itemStack);
    }
    // Return Ret
    return ret;
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with MassiveList

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

the class TypeStringCommand method getTabList.

@Override
public Collection<String> getTabList(CommandSender sender, String arg) {
    // Split the arg into a list of args #inception-the-movie!
    String[] args = argAsArgs(arg);
    // Tab completion of base commands
    if (args.length <= 1)
        return getKnownCommands().keySet();
    // Get command alias and subargs
    String alias = args[0];
    // Attempt using the tab completion of that command.
    Command command = getCommandSmart(alias);
    if (command == null)
        return Collections.emptySet();
    List<String> subcompletions = command.tabComplete(sender, alias, Arrays.copyOfRange(args, 1, args.length));
    String prefix = Txt.implode(Arrays.copyOfRange(args, 0, args.length - 1), " ") + " ";
    List<String> ret = new MassiveList<>();
    for (String subcompletion : subcompletions) {
        String completion = prefix + subcompletion;
        ret.add(completion);
    }
    return ret;
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) Command(org.bukkit.command.Command)

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