mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 13:36:06 +01:00
Remove various code smells.
This commit is contained in:
parent
6c0915544e
commit
9cccfa02ba
@ -4,7 +4,6 @@ package world.bentobox.challenges.commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
@ -118,8 +117,7 @@ public class CompleteChallengeCommand extends CompositeCommand
|
|||||||
stream().
|
stream().
|
||||||
filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") ||
|
filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") ||
|
||||||
challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")).
|
challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")).
|
||||||
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
|
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
|
||||||
collect(Collectors.toList()));
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// Suggest a number of completions.
|
// Suggest a number of completions.
|
||||||
|
@ -2,11 +2,9 @@ package world.bentobox.challenges.commands.admin;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
@ -101,7 +99,7 @@ public class CompleteCommand extends CompositeCommand
|
|||||||
Challenge challenge = this.addon.getChallengesManager().getChallenge(challengeName);
|
Challenge challenge = this.addon.getChallengesManager().getChallenge(challengeName);
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
|
|
||||||
if (challenge != null && target != null)
|
if (challenge != null)
|
||||||
{
|
{
|
||||||
if (!this.addon.getChallengesManager().isChallengeComplete(targetUUID, this.getWorld(), challenge))
|
if (!this.addon.getChallengesManager().isChallengeComplete(targetUUID, this.getWorld(), challenge))
|
||||||
{
|
{
|
||||||
@ -174,10 +172,9 @@ public class CompleteCommand extends CompositeCommand
|
|||||||
case 4 ->
|
case 4 ->
|
||||||
// Create suggestions with all challenges that is available for users.
|
// Create suggestions with all challenges that is available for users.
|
||||||
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
|
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
|
||||||
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
|
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
|
||||||
collect(Collectors.toList()));
|
|
||||||
default ->
|
default ->
|
||||||
returnList.addAll(Collections.singletonList("help"));
|
returnList.add("help");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(Util.tabLimit(returnList, lastString));
|
return Optional.of(Util.tabLimit(returnList, lastString));
|
||||||
|
@ -2,11 +2,9 @@ package world.bentobox.challenges.commands.admin;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
@ -191,12 +189,11 @@ public class ResetCommand extends CompositeCommand
|
|||||||
case 4 -> {
|
case 4 -> {
|
||||||
// Create suggestions with all challenges that is available for users.
|
// Create suggestions with all challenges that is available for users.
|
||||||
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
|
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
|
||||||
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
|
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
|
||||||
collect(Collectors.toList()));
|
|
||||||
returnList.add("all");
|
returnList.add("all");
|
||||||
}
|
}
|
||||||
default ->
|
default ->
|
||||||
returnList.addAll(Collections.singletonList("help"));
|
returnList.add("help");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(Util.tabLimit(returnList, lastString));
|
return Optional.of(Util.tabLimit(returnList, lastString));
|
||||||
|
@ -56,20 +56,18 @@ public class StatisticRequirements extends Requirements
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this.statistic.getType())
|
return switch (this.statistic.getType())
|
||||||
{
|
{
|
||||||
case ITEM -> {
|
case ITEM -> this.material != null && this.material.isItem();
|
||||||
return this.material != null && this.material.isItem();
|
|
||||||
}
|
case BLOCK -> this.material != null && this.material.isBlock();
|
||||||
case BLOCK -> {
|
|
||||||
return this.material != null && this.material.isBlock();
|
case ENTITY -> this.entity != null;
|
||||||
}
|
|
||||||
case ENTITY -> {
|
case UNTYPED -> true;
|
||||||
return this.entity != null;
|
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
import lv.id.bonne.panelutils.PanelUtils;
|
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -232,10 +232,6 @@ public class ChallengesManager
|
|||||||
this.savePlayersData();
|
this.savePlayersData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.challengeDatabase = new Database<>(addon, Challenge.class);
|
|
||||||
// this.levelDatabase = new Database<>(addon, ChallengeLevel.class);
|
|
||||||
// this.playersDatabase = new Database<>(addon, ChallengesPlayerData.class);
|
|
||||||
|
|
||||||
this.loadAndValidate();
|
this.loadAndValidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,12 +430,6 @@ public class ChallengesManager
|
|||||||
public void removeFromCache(UUID playerID)
|
public void removeFromCache(UUID playerID)
|
||||||
{
|
{
|
||||||
// Remove due possible issues with saving... (#246)
|
// Remove due possible issues with saving... (#246)
|
||||||
// if (!this.settings.isStoreAsIslandData() && this.playerCacheData.containsKey(playerID.toString()))
|
|
||||||
// {
|
|
||||||
// // save before remove
|
|
||||||
// this.savePlayerData(playerID.toString());
|
|
||||||
// this.playerCacheData.remove(playerID.toString());
|
|
||||||
// }
|
|
||||||
|
|
||||||
this.savePlayerData(playerID.toString());
|
this.savePlayerData(playerID.toString());
|
||||||
|
|
||||||
@ -841,8 +831,6 @@ public class ChallengesManager
|
|||||||
{
|
{
|
||||||
// Challenges and Levels are saved on modifications only to avoid issues with
|
// Challenges and Levels are saved on modifications only to avoid issues with
|
||||||
// NULL's in data after interrupting server while in saving stage.
|
// NULL's in data after interrupting server while in saving stage.
|
||||||
// this.saveChallenges();
|
|
||||||
// this.saveLevels();
|
|
||||||
|
|
||||||
this.savePlayersData();
|
this.savePlayersData();
|
||||||
}
|
}
|
||||||
|
@ -289,8 +289,7 @@ public abstract class CommonPanel
|
|||||||
// Yes list duplication for complete menu.
|
// Yes list duplication for complete menu.
|
||||||
List<String> missingPermissions = challenge.getRequirements().getRequiredPermissions().stream().
|
List<String> missingPermissions = challenge.getRequirements().getRequiredPermissions().stream().
|
||||||
filter(permission -> target == null || !target.hasPermission(permission)).
|
filter(permission -> target == null || !target.hasPermission(permission)).
|
||||||
sorted().
|
sorted().toList();
|
||||||
collect(Collectors.toList());
|
|
||||||
|
|
||||||
StringBuilder permissionBuilder = new StringBuilder();
|
StringBuilder permissionBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
@ -582,12 +582,12 @@ public class AdminPanel extends CommonPanel
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This indicate if Reset Challenges must work as reset all.
|
* This indicates if Reset Challenges must work as reset all.
|
||||||
*/
|
*/
|
||||||
private boolean resetAllMode;
|
private boolean resetAllMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This indicate if wipe button should clear all data, or only challenges.
|
* This indicates if wipe button should clear all data, or only challenges.
|
||||||
*/
|
*/
|
||||||
private boolean wipeAll;
|
private boolean wipeAll;
|
||||||
}
|
}
|
@ -260,6 +260,7 @@ public class EditChallengePanel extends CommonPanel
|
|||||||
case ITEM -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ITEMS));
|
case ITEM -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ITEMS));
|
||||||
case BLOCK -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_BLOCKS));
|
case BLOCK -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_BLOCKS));
|
||||||
case ENTITY -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ENTITIES));
|
case ENTITY -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ENTITIES));
|
||||||
|
default -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,13 +334,12 @@ public class ListUsersPanel extends CommonPagedPanel<Player>
|
|||||||
if (clickType.isRightClick())
|
if (clickType.isRightClick())
|
||||||
{
|
{
|
||||||
this.mode = Utils.getPreviousValue(ViewMode.values(), this.mode);
|
this.mode = Utils.getPreviousValue(ViewMode.values(), this.mode);
|
||||||
this.onlineUsers = this.collectUsers(this.mode);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.mode = Utils.getNextValue(ViewMode.values(), this.mode);
|
this.mode = Utils.getNextValue(ViewMode.values(), this.mode);
|
||||||
this.onlineUsers = this.collectUsers(this.mode);
|
|
||||||
}
|
}
|
||||||
|
this.onlineUsers = this.collectUsers(this.mode);
|
||||||
|
|
||||||
// Reset search
|
// Reset search
|
||||||
this.searchString = "";
|
this.searchString = "";
|
||||||
|
@ -273,7 +273,6 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
Bukkit.getOnlinePlayers().stream().
|
Bukkit.getOnlinePlayers().stream().
|
||||||
map(User::getInstance).
|
map(User::getInstance).
|
||||||
filter(Objects::nonNull).
|
|
||||||
forEach(user -> Utils.sendMessage(user, user.getTranslation(
|
forEach(user -> Utils.sendMessage(user, user.getTranslation(
|
||||||
"challenges.messages.name-has-completed-challenge",
|
"challenges.messages.name-has-completed-challenge",
|
||||||
Constants.PARAMETER_NAME, this.user.getName(),
|
Constants.PARAMETER_NAME, this.user.getName(),
|
||||||
@ -380,7 +379,6 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
Bukkit.getOnlinePlayers().stream().
|
Bukkit.getOnlinePlayers().stream().
|
||||||
map(User::getInstance).
|
map(User::getInstance).
|
||||||
filter(Objects::nonNull).
|
|
||||||
forEach(user -> Utils.sendMessage(user, user.getTranslation(
|
forEach(user -> Utils.sendMessage(user, user.getTranslation(
|
||||||
"challenges.messages.name-has-completed-level",
|
"challenges.messages.name-has-completed-level",
|
||||||
Constants.PARAMETER_NAME, this.user.getName(),
|
Constants.PARAMETER_NAME, this.user.getName(),
|
||||||
|
@ -14,10 +14,9 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -154,7 +153,7 @@ public class ChallengesAddonTest {
|
|||||||
File jFile = new File("addon.jar");
|
File jFile = new File("addon.jar");
|
||||||
List<String> lines = Arrays.asList("# ChallengesAddon Configuration", "uniqueId: config");
|
List<String> lines = Arrays.asList("# ChallengesAddon Configuration", "uniqueId: config");
|
||||||
Path path = Paths.get("config.yml");
|
Path path = Paths.get("config.yml");
|
||||||
Files.write(path, lines, Charset.forName("UTF-8"));
|
Files.write(path, lines, StandardCharsets.UTF_8);
|
||||||
try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
|
try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
|
||||||
addToJar(tempJarOutputStream, path);
|
addToJar(tempJarOutputStream, path);
|
||||||
addToJar(tempJarOutputStream, Paths.get("src/main/resources/panels/gamemode_panel.yml"));
|
addToJar(tempJarOutputStream, Paths.get("src/main/resources/panels/gamemode_panel.yml"));
|
||||||
@ -206,7 +205,7 @@ public class ChallengesAddonTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToJar(JarOutputStream tempJarOutputStream, Path path) throws FileNotFoundException, IOException {
|
private void addToJar(JarOutputStream tempJarOutputStream, Path path) throws IOException {
|
||||||
//Added the new files to the jar.
|
//Added the new files to the jar.
|
||||||
try (FileInputStream fis = new FileInputStream(path.toFile())) {
|
try (FileInputStream fis = new FileInputStream(path.toFile())) {
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import static org.mockito.Mockito.when;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -105,10 +104,9 @@ public class ChallengesManagerTest {
|
|||||||
// Variable fields
|
// Variable fields
|
||||||
private ChallengesManager cm;
|
private ChallengesManager cm;
|
||||||
private File database;
|
private File database;
|
||||||
private String uuid;
|
|
||||||
private Challenge challenge;
|
private Challenge challenge;
|
||||||
private @NonNull ChallengeLevel level;
|
private @NonNull ChallengeLevel level;
|
||||||
private UUID playerID = UUID.randomUUID();
|
private final UUID playerID = UUID.randomUUID();
|
||||||
private String cName;
|
private String cName;
|
||||||
private String levelName;
|
private String levelName;
|
||||||
|
|
||||||
@ -159,7 +157,7 @@ public class ChallengesManagerTest {
|
|||||||
|
|
||||||
// Challenge
|
// Challenge
|
||||||
challenge = new Challenge();
|
challenge = new Challenge();
|
||||||
uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
challenge.setUniqueId(GAME_MODE_NAME + "_" + uuid);
|
challenge.setUniqueId(GAME_MODE_NAME + "_" + uuid);
|
||||||
challenge.setFriendlyName("name");
|
challenge.setFriendlyName("name");
|
||||||
challenge.setLevel(GAME_MODE_NAME + "_novice");
|
challenge.setLevel(GAME_MODE_NAME + "_novice");
|
||||||
@ -438,7 +436,7 @@ public class ChallengesManagerTest {
|
|||||||
removeLine(check);
|
removeLine(check);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeLine(File inputFile) {
|
private void removeLine(File inputFile) {
|
||||||
File tempFile = new File("myTempFile.json");
|
File tempFile = new File("myTempFile.json");
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) {
|
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) {
|
||||||
@ -454,13 +452,11 @@ public class ChallengesManagerTest {
|
|||||||
writer.write(currentLine + System.getProperty("line.separator"));
|
writer.write(currentLine + System.getProperty("line.separator"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempFile.renameTo(inputFile);
|
tempFile.renameTo(inputFile);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Test method for {@link ChallengesManager#saveLevel(world.bentobox.challenges.database.object.ChallengeLevel)}.
|
* Test method for {@link ChallengesManager#saveLevel(world.bentobox.challenges.database.object.ChallengeLevel)}.
|
||||||
|
@ -60,7 +60,6 @@ public class ChallengesCommandTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CompositeCommand ic;
|
private CompositeCommand ic;
|
||||||
private UUID uuid;
|
|
||||||
@Mock
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
@Mock
|
@Mock
|
||||||
@ -79,13 +78,10 @@ public class ChallengesCommandTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private GameModeAddon gameModeAddon;
|
private GameModeAddon gameModeAddon;
|
||||||
|
|
||||||
private Settings settings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
@ -125,7 +121,7 @@ public class ChallengesCommandTest {
|
|||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
when(user.getPlayer()).thenReturn(p);
|
when(user.getPlayer()).thenReturn(p);
|
||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
@ -152,7 +148,7 @@ public class ChallengesCommandTest {
|
|||||||
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
settings = new Settings();
|
Settings settings = new Settings();
|
||||||
when(addon.getChallengesSettings()).thenReturn(settings);
|
when(addon.getChallengesSettings()).thenReturn(settings);
|
||||||
settings.setVisibilityMode(VisibilityMode.VISIBLE);
|
settings.setVisibilityMode(VisibilityMode.VISIBLE);
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemFactory;
|
import org.bukkit.inventory.ItemFactory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -64,7 +63,6 @@ public class CompleteChallengeCommandTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CompositeCommand ic;
|
private CompositeCommand ic;
|
||||||
private UUID uuid;
|
|
||||||
@Mock
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
@Mock
|
@Mock
|
||||||
@ -84,16 +82,14 @@ public class CompleteChallengeCommandTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private GameModeAddon gameModeAddon;
|
private GameModeAddon gameModeAddon;
|
||||||
|
|
||||||
private Settings settings;
|
|
||||||
@Mock
|
@Mock
|
||||||
private Challenge challenge;
|
private Challenge challenge;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
@ -129,7 +125,7 @@ public class CompleteChallengeCommandTest {
|
|||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
when(user.getPlayer()).thenReturn(p);
|
when(user.getPlayer()).thenReturn(p);
|
||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
@ -159,7 +155,7 @@ public class CompleteChallengeCommandTest {
|
|||||||
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
settings = new Settings();
|
Settings settings = new Settings();
|
||||||
when(addon.getChallengesSettings()).thenReturn(settings);
|
when(addon.getChallengesSettings()).thenReturn(settings);
|
||||||
settings.setVisibilityMode(VisibilityMode.VISIBLE);
|
settings.setVisibilityMode(VisibilityMode.VISIBLE);
|
||||||
|
|
||||||
@ -184,13 +180,6 @@ public class CompleteChallengeCommandTest {
|
|||||||
cc = new CompleteChallengeCommand(addon, ic);
|
cc = new CompleteChallengeCommand(addon, ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.challenges.commands.CompleteChallengeCommand#CompleteChallengeCommand(world.bentobox.bentobox.api.addons.Addon, world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
* Test method for {@link world.bentobox.challenges.commands.CompleteChallengeCommand#CompleteChallengeCommand(world.bentobox.bentobox.api.addons.Addon, world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||||
*/
|
*/
|
||||||
|
@ -15,7 +15,7 @@ import world.bentobox.bentobox.api.flags.Flag;
|
|||||||
|
|
||||||
public class TestWorldSetting implements WorldSettings {
|
public class TestWorldSetting implements WorldSettings {
|
||||||
|
|
||||||
private Map<String, Boolean> flags = new HashMap<>();
|
private final Map<String, Boolean> flags = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameMode getDefaultGameMode() {
|
public GameMode getDefaultGameMode() {
|
||||||
|
@ -36,7 +36,6 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -86,17 +85,15 @@ public class TryToCompleteTest {
|
|||||||
|
|
||||||
private TryToComplete ttc;
|
private TryToComplete ttc;
|
||||||
private Challenge challenge;
|
private Challenge challenge;
|
||||||
private @NonNull ChallengeLevel level;
|
|
||||||
@Mock
|
@Mock
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
@Mock
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
private String topLabel = "island";
|
private final String topLabel = "island";
|
||||||
private String permissionPrefix = "perm.";
|
private final String permissionPrefix = "perm.";
|
||||||
|
|
||||||
private String levelName;
|
|
||||||
@Mock
|
@Mock
|
||||||
private ChallengesManager cm;
|
private ChallengesManager cm;
|
||||||
@Mock
|
@Mock
|
||||||
@ -115,18 +112,16 @@ public class TryToCompleteTest {
|
|||||||
private Settings settings;
|
private Settings settings;
|
||||||
@Mock
|
@Mock
|
||||||
private WorldSettings mySettings;
|
private WorldSettings mySettings;
|
||||||
private Map<String, Boolean> map;
|
|
||||||
@Mock
|
@Mock
|
||||||
private @Nullable PlayerInventory inv;
|
private @Nullable PlayerInventory inv;
|
||||||
private ItemStack[] contents = {};
|
private final ItemStack[] contents = {};
|
||||||
@Mock
|
@Mock
|
||||||
private BoundingBox bb;
|
private BoundingBox bb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
when(addon.getPlugin()).thenReturn(plugin);
|
when(addon.getPlugin()).thenReturn(plugin);
|
||||||
@ -143,8 +138,8 @@ public class TryToCompleteTest {
|
|||||||
when(gameMode.getDescription()).thenReturn(desc2);
|
when(gameMode.getDescription()).thenReturn(desc2);
|
||||||
|
|
||||||
// Challenge Level
|
// Challenge Level
|
||||||
level = new ChallengeLevel();
|
@NonNull ChallengeLevel level = new ChallengeLevel();
|
||||||
levelName = GAME_MODE_NAME + "_novice";
|
String levelName = GAME_MODE_NAME + "_novice";
|
||||||
level.setUniqueId(levelName);
|
level.setUniqueId(levelName);
|
||||||
level.setFriendlyName("Novice");
|
level.setFriendlyName("Novice");
|
||||||
// Set up challenge
|
// Set up challenge
|
||||||
@ -239,19 +234,19 @@ public class TryToCompleteTest {
|
|||||||
Map<UUID, String> online = new HashMap<>();
|
Map<UUID, String> online = new HashMap<>();
|
||||||
|
|
||||||
Set<Player> onlinePlayers = new HashSet<>();
|
Set<Player> onlinePlayers = new HashSet<>();
|
||||||
for (int j = 0; j < NAMES.length; j++) {
|
for (String name : NAMES) {
|
||||||
Player p1 = mock(Player.class);
|
Player p1 = mock(Player.class);
|
||||||
UUID uuid2 = UUID.randomUUID();
|
UUID uuid2 = UUID.randomUUID();
|
||||||
when(p1.getUniqueId()).thenReturn(uuid2);
|
when(p1.getUniqueId()).thenReturn(uuid2);
|
||||||
when(p1.getName()).thenReturn(NAMES[j]);
|
when(p1.getName()).thenReturn(name);
|
||||||
online.put(uuid2, NAMES[j]);
|
online.put(uuid2, name);
|
||||||
onlinePlayers.add(p1);
|
onlinePlayers.add(p1);
|
||||||
}
|
}
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers);
|
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers);
|
||||||
|
|
||||||
// World settings
|
// World settings
|
||||||
map = new HashMap<>();
|
Map<String, Boolean> map = new HashMap<>();
|
||||||
when(mySettings.getWorldFlags()).thenReturn(map);
|
when(mySettings.getWorldFlags()).thenReturn(map);
|
||||||
when(iwm.getWorldSettings(any())).thenReturn(mySettings);
|
when(iwm.getWorldSettings(any())).thenReturn(mySettings);
|
||||||
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true);
|
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true);
|
||||||
@ -265,13 +260,6 @@ public class TryToCompleteTest {
|
|||||||
when(ChatColor.stripColor(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
when(ChatColor.stripColor(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#TryToComplete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
|
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#TryToComplete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
|
@ -51,20 +51,18 @@ public class TryToCompleteTestOld {
|
|||||||
};
|
};
|
||||||
List<ItemStack> required;
|
List<ItemStack> required;
|
||||||
private ChallengesAddon addon;
|
private ChallengesAddon addon;
|
||||||
private PlayerInventory inv;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
when(Bukkit.getBukkitVersion()).thenReturn("1.13.2");
|
when(Bukkit.getBukkitVersion()).thenReturn("1.13.2");
|
||||||
|
|
||||||
user = mock(User.class);
|
user = mock(User.class);
|
||||||
inv = mock(PlayerInventory.class);
|
PlayerInventory inv = mock(PlayerInventory.class);
|
||||||
when(inv.getContents()).thenReturn(stacks);
|
when(inv.getContents()).thenReturn(stacks);
|
||||||
when(user.getInventory()).thenReturn(inv);
|
when(user.getInventory()).thenReturn(inv);
|
||||||
addon = mock(ChallengesAddon.class);
|
addon = mock(ChallengesAddon.class);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package world.bentobox.challenges.utils;
|
package world.bentobox.challenges.utils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@ -18,7 +17,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.inventory.ItemFactory;
|
import org.bukkit.inventory.ItemFactory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -49,10 +47,9 @@ public class UtilsTest {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
@ -71,13 +68,6 @@ public class UtilsTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.challenges.utils.Utils#groupEqualItems(java.util.List, java.util.Set)}.
|
* Test method for {@link world.bentobox.challenges.utils.Utils#groupEqualItems(java.util.List, java.util.Set)}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user