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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations