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