Extension Table now handles Optionals

Updated mcMMO Extension to R1.2

Affects issues:
- Fixed #1643
This commit is contained in:
Risto Lahtela 2021-01-03 12:27:49 +02:00
parent b894656d66
commit 1664199574
4 changed files with 77 additions and 4 deletions

View File

@ -3,7 +3,8 @@ plugins {
}
dependencies {
compileOnly group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compileOnly "org.apache.commons:commons-text:$commonsTextVersion"
testCompile "org.apache.commons:commons-text:$commonsTextVersion"
compileOnly "com.google.code.gson:gson:$gsonVersion"
}

View File

@ -22,8 +22,9 @@ import com.djrapitops.plan.extension.icon.Icon;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* Object for giving Plan table data.
@ -186,7 +187,17 @@ public final class Table {
return this; // Ignore row when all values are null or no values are present.
}
building.rows.add(Arrays.copyOf(values, 5));
Object[] row = new Object[5];
for (int i = 0; i < Math.min(values.length, 5); i++) {
Object value = values[i];
if (value instanceof Optional) {
value = ((Optional<?>) value).map(Objects::toString).orElse("-");
}
row[i] = value;
}
building.rows.add(row);
return this;
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.extension.table;
import com.djrapitops.plan.extension.icon.Icon;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TableTest {
@Test
void tableWithVaryingRowLengthsHasNoErrors() {
Table.Factory table = Table.builder()
.columnOne("", Icon.called("").build())
.columnTwo("", Icon.called("").build())
.columnThree("", Icon.called("").build())
.columnFour("", Icon.called("").build())
.columnFive("", Icon.called("").build());
table.addRow();
table.addRow("a");
table.addRow("a", "b");
table.addRow("a");
table.addRow("a", "b", "c", "d", "e", "f");
table.addRow("a", "b", "c", "d");
List<Object[]> expected = Arrays.asList(
new Object[]{"a", null, null, null, null},
new Object[]{"a", "b", null, null, null},
new Object[]{"a", null, null, null, null},
new Object[]{"a", "b", "c", "d", "e"},
new Object[]{"a", "b", "c", "d", null}
);
List<Object[]> result = table.build().getRows();
for (int i = 0; i < expected.size(); i++) {
assertArrayEquals(expected.get(i), result.get(i));
}
assertEquals(expected.size(), result.size());
}
}

View File

@ -21,7 +21,7 @@ dependencies {
compile 'com.djrapitops:Extension-Jobs:4.13.1-R0.1'
compile 'com.djrapitops:Extension-Litebans:0.3.2-R0.1'
compile 'com.djrapitops:Extension-LuckPerms:5.0-R0.2'
compile 'com.djrapitops:Extension-McMMO:2.1.149-R1.1'
compile 'com.djrapitops:Extension-McMMO:2.1.149-R1.2'
compile 'com.djrapitops:Extension-MinigamesLib:1.14.17-R0.2'
compile 'com.djrapitops:Extension-Nucleus:1.14.0-R0.1'
compile 'com.djrapitops:Extension-nuVotifier:2.3.4-R0.3'