Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ private void reportImportFailure(User user, World world, Exception e)


/**
* This method loads downloaded challenges into memory.
* This method loads downloaded challenges into memory. Any challenges and levels that the
* game mode already has are replaced, the same as for file imports. Player data is kept.
* @param user User who calls downloaded challenge loading
* @param world Target world.
* @param downloadString String that need to be loaded via DefaultDataHolder.
Expand All @@ -776,30 +777,47 @@ public void loadDownloadedChallenges(User user, World world, String downloadStri
return;
}

ChallengesManager manager = this.addon.getChallengesManager();
Optional<GameModeAddon> optional = this.addon.getPlugin().getIWM().getAddon(world);

// If exist any challenge or level that is bound to current world, then do not load default challenges.
if (manager.hasAnyChallengeData(world.getName()))
if (optional.isEmpty())
{
if (user.isPlayer())
if (user != null && user.isPlayer())
{
Utils.sendMessage(user, world, Constants.ERRORS + "exist-challenges-or-levels");
}
else
{
this.addon.logWarning("challenges.errors.exist-challenges-or-levels");
Utils.sendMessage(user,
world,
Constants.ERRORS + "not-a-gamemode-world",
Constants.PARAMETER_WORLD, world.getName());
}

this.addon.logWarning("Given world is not a gamemode world.");

return;
}

// Challenges and levels are stored under the lowercase game mode name.
final String gameMode = optional.get().getDescription().getName().toLowerCase();

ChallengesManager manager = this.addon.getChallengesManager();

try
{
// This prefix will be used to all challenges. That is a unique way how to separate challenged for
// each game mode.
String uniqueIDPrefix = Utils.getGameMode(world).toLowerCase() + "_";
String uniqueIDPrefix = gameMode + "_";
DefaultDataHolder downloadedChallenges = new DefaultJSONHandler(this.addon).loadWebObject(downloadString);

if (downloadedChallenges == null)
{
return;
}

// The admin has confirmed that the current challenges should be replaced. Wipe them only
// now that the download has parsed, so a broken download cannot leave the world empty.
if (manager.hasAnyChallengeData(world.getName()))
{
manager.wipeDatabase(gameMode);
}

// All new challenges should get correct ID. So we need to map it to loaded challenges.
downloadedChallenges.getChallengeList().forEach(challenge -> {
// Set correct challenge ID
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,6 @@ challenges:
load-error: "<red>Chyba: Nelze načíst [value]."
no-rank: "<red>Na toto nemáš hodnost."
cannot-remove-items: "<red>Některé předměty nelze odebrat z tvého inventáře!"
exist-challenges-or-levels: "<red>Ve tvém světě již existují výzvy. Nelze pokračovat!"
no-challenges: "<red>Výzvy nejsou v aktuálním světě implementovány!"
no-challenges-admin: "<red>Výzvy nejsou v aktuálním světě implementovány! Měl bys použít <dark_purple>/[command] <red>k jejich přidání!"
missing-arguments: "<red>Příkaz postrádá argumenty."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,6 @@ challenges:
load-error: "<red>Fehler: [value] kann nicht geladen werden."
no-rank: "<red>Du hast keinen Rang, der hoch genug ist, um das zu tun."
cannot-remove-items: "<red>Einige Items können nicht aus deinem Inventar entfernt werden!"
exist-challenges-or-levels: "<red>Die Herausforderung existiert bereits in deiner Welt. Kann nicht fortfahren!"
no-challenges: "<red>Die Herausforderungen sind in dieser Welt noch nicht implementiert!"
no-challenges-admin: "<red>Die Herausforderungen sind in dieser Welt noch nicht implementiert! Verwende <dark_purple>/[command] <red>um sie hinzuzufügen!"
missing-arguments: "<red>Dem Befehl fehlen Argumente."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ challenges:
import-failed: "<red>Could not import challenges: [message]. Check the server console for details."
no-rank: "<red>You do not have a high enough rank to do that."
cannot-remove-items: "<red>Some items cannot be removed from your inventory!"
exist-challenges-or-levels: "<red>Challenges already exist in your world. Cannot proceed!"
no-challenges: "<red>Challenges are not implemented in this world yet!"
no-challenges-admin: "<red>Challenges are not implemented in this world yet! Use <dark_purple>/[command] <red>to add them!"
missing-arguments: "<red>The command is missing arguments."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,6 @@ challenges:
load-error: "<red>Error: No se pudo cargar [value]."
no-rank: "<red>No tienes un rango lo suficientemente alto como para hacer eso."
cannot-remove-items: "<red>¡Algunos items no se pueden eliminar de tu inventario!"
exist-challenges-or-levels: "<red>Los desafíos ya existen en tu mundo. ¡No se puede proceder!"
no-challenges: "<red>¡Los desafíos aún no se han implementado en este mundo!"
no-challenges-admin: "<red>¡Los desafíos aún no se han implementado en este mundo! ¡Usa <dark_purple>/[command] <red>para agregarlos!"
missing-arguments: "<red>Faltan argumentos de comando."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,6 @@ challenges:
load-error: "<red>Erreur: Impossible de charger [value]."
no-rank: "<red>Vous n'avez pas un rang assez élevé pour faire cela."
cannot-remove-items: "<red>Certains objets ne peuvent pas être supprimés de votre inventaire !"
exist-challenges-or-levels: "<red>Dans votre monde il existe déjà des challenges. Impossible de continuer !"
no-challenges: "<red>Les challenges ne sont pas actifs dans le monde actuel !"
no-challenges-admin: "<red>Les Challenges ne sont pas actifs dans le monde actuel ! Vous devez utiliser <dark_purple>/[command] <red>pour ajouter cela !"
missing-arguments: "<red>La commande n'a pas d'arguments."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,6 @@ challenges:
load-error: "<red>Hiba: Nem lehet betölteni az [value] értéket."
no-rank: "<red>Nincs elég magas rangod ahhoz."
cannot-remove-items: "<red>Néhány elem nem távolítható el a készletből!"
exist-challenges-or-levels: "<red>A világban már léteznek kihívások. Nem lehet folytatni!"
no-challenges: "<red>A kihívások még nem valósultak meg ezen a világon!"
no-challenges-admin: "<red>A kihívások még nem valósultak meg ezen a világon! Használja a <dark_purple>/[command] <red>billentyűket a hozzáadásukhoz!"
missing-arguments: "<red>A parancsból hiányoznak az argumentumok."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,6 @@ challenges:
load-error: &cエラー:[value]をロードできません。
no-rank: &cあなたにはそれをするランクがありません。
cannot-remove-items: &c一部のアイテムはインベントリから削除できません!
exist-challenges-or-levels: &c世界にはすでに課題が存在します。続行できません!
no-challenges: &cチャレンジは現在の世界では実装されていません!
no-challenges-admin: &cチャレンジは現在の世界では実装されていません!それらを追加するには&5 / [command]&cを使用する必要があります。
missing-arguments: &cコマンドに引数がありません。
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,6 @@ challenges:
load-error: '<red>Kļūda: Nevar ielādēt [value].'
no-rank: "<red>Tavs ranks nav pietiekoši augsts, lai veiktu šo darbību."
cannot-remove-items: '<red>Dažus priekšmetus neizdevās izņemt no tava inventāra!'
exist-challenges-or-levels: '<red>Šajā pasaulē jau existē uzdevumi, nevar turpināt!'
no-challenges: '<red>Uzdevumi nav izveidoti šajā pasaulē!'
no-challenges-admin: '<red>Uzdevumi nav izveidoti šajā pasaulē! Izmanto <dark_purple>/[command], <red>lai tos pievienotu!'
missing-arguments: '<red>Pietrūkst komandas parametri.'
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,6 @@ challenges:
load-error: "<red>Error: Nie można załadować [value]."
no-rank: "<red> Nie masz wystarczająco wysokiej rangi, aby to zrobić."
cannot-remove-items: "<red> Niektórych przedmiotów nie można usunąć z ekwipunku!"
exist-challenges-or-levels: "<red>Zadania już istnieją w twoim świecie. Nie można kontynuować!"
no-challenges: "<red>Zadania nie są jeszcze zaimplementowane na tym świecie!"
no-challenges-admin: "<red>Zadania nie są jeszcze zaimplementowane na tym świecie! Użyj <dark_purple>/[command] i <red>, aby je dodać!"
missing-arguments: "<red>Poleceniu brakuje argumentów."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,6 @@ challenges:
load-error: "<red>Erro: Não é possível carregar [value]."
no-rank: "<red>Você não tem uma classificação alta o suficiente para fazer isso."
cannot-remove-items: "<red>Alguns itens não podem ser removidos do seu inventário!"
exist-challenges-or-levels: "<red>Desafios já existem em seu mundo. Não é possível prosseguir!"
no-challenges: "<red>Os desafios ainda não foram implementados neste mundo!"
no-challenges-admin: "<red>Os desafios ainda não foram implementados neste mundo! Use <dark_purple>/[command] <red>para adicioná-los!"
missing-arguments: "<red>O comando não tem argumentos."
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,6 @@ challenges:
missing-arguments: "<red>В команде отсутствуют аргументы."
wrong-environment: "<red>Вы находитесь в неправильном окружении!"
missing-addon: "<red>Невозможно выполнить задание: отсутствует обязательный аддон или плагин."
exist-challenges-or-levels: "<red>Челленджи уже существуют в вашем мире. Не могу продолжить!"
no-challenges: "<red>Челленджи еще не реализованы в этом мире!"
no-challenges-admin: "<red>Челленджи еще не реализованы в этом мире! Используйте <dark_purple>/[command] <red>чтобы добавить их!"
missing-level: "<red>Уровень челленджа [level] не определен в базе данных. Это может привести к ошибкам!"
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,6 @@ challenges:
load-error: "<red>Помилка: неможливо завантажити [value]."
no-rank: "<red>Ви не маєте достатньо високого рангу, щоб це зробити."
cannot-remove-items: "<red>Деякі предмети не можна видалити з вашого інвентарю!"
exist-challenges-or-levels: "<red>Проблеми вже існують у вашому світі. Неможливо продовжити!"
no-challenges: "<red>Виклики ще не реалізовані в цьому світі!"
no-challenges-admin: "<red>Виклики ще не реалізовані в цьому світі! Використовуйте <dark_purple>/[command] <red>, щоб додати їх!"
missing-arguments: У команді <red>відсутні аргументи.
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,6 @@ challenges:
load-error: "<red>错误: 无法载入 <reset>[value]<red>。"
no-rank: "<red>你没有等级可以做到这一点."
cannot-remove-items: "<red>有些物品无法从你的物品栏中删除!"
exist-challenges-or-levels: "&c挑战已经存在于您的世界中。无法继续!"
no-challenges: "<red>这个游戏模式没有可进行的挑战!"
no-challenges-admin: "<red>这个游戏模式还没有可进行的挑战!请使用 <white>/[command] <red>来添加挑战。"
missing-arguments: "<red>命令缺少参数。"
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/zh-HK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,6 @@ challenges:
load-error: '<red>錯誤: 無法載入 [value].'
no-rank: '<red>你還未達到足夠的頭銜等級以完成挑戰。'
cannot-remove-items: '<red>部分物品無法從你的背包內移除!'
exist-challenges-or-levels: '<red>你的世界內已經有了這挑戰。 無法進行!'
no-challenges: '<red>這個世界尚未開放挑戰功能!'
no-challenges-admin: '<red>這個世界尚未開放挑戰功能! 使用<dark_purple>/[command] <red>添加挑戰!'
missing-arguments: '<red>指令不完整。'
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ challenges:
no-rank: <red>你的權限等級不足,無法執行此操作。
wrong-biome: <red>你必須站在 [biome] 生態域內才能完成此挑戰!
cannot-remove-items: <red>部分物品無法從你的背包中移除!
exist-challenges-or-levels: <red>此世界已存在挑戰或等級,無法繼續!
no-challenges: <red>此世界尚未設定挑戰!
no-challenges-admin: <red>此世界尚未設定挑戰!請使用 <dark_purple>/[command] <red>新增挑戰!
missing-arguments: <red>指令缺少必要參數。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,38 @@ void testLoadDownloadedChallengesNullWorld() {
}

@Test
void testLoadDownloadedChallengesExistingData() {
void testLoadDownloadedChallengesNotAGameModeWorld() {
when(iwm.getAddon(any())).thenReturn(java.util.Optional.empty());
when(cm.hasAnyChallengeData(anyString())).thenReturn(true);
when(user.isPlayer()).thenReturn(true);
cim.loadDownloadedChallenges(user, world, "{}");
verify(user).getTranslation(any(World.class), eq("challenges.errors.exist-challenges-or-levels"));
verify(cm, never()).loadChallenge(any(), any(), anyBoolean(), any(), anyBoolean());
verify(addon).logWarning("Given world is not a gamemode world.");
verify(cm, never()).wipeDatabase(anyString());
verify(cm, never()).saveChallenges();
}

@Test
void testLoadDownloadedChallengesExistingDataConsoleUser() {
void testLoadDownloadedChallengesExistingDataIsReplaced() {
when(cm.hasAnyChallengeData(anyString())).thenReturn(true);
when(user.isPlayer()).thenReturn(false);
cim.loadDownloadedChallenges(user, world, "{}");
verify(addon).logWarning("challenges.errors.exist-challenges-or-levels");
verify(cm).wipeDatabase("bskyblock");
verify(user, never()).getTranslation(any(World.class), eq("challenges.errors.exist-challenges-or-levels"));
verify(cm).saveChallenges();
verify(cm).saveLevels();
}

@Test
void testLoadDownloadedChallengesNoExistingDataDoesNotWipe() {
when(cm.hasAnyChallengeData(anyString())).thenReturn(false);
cim.loadDownloadedChallenges(user, world, "{}");
verify(cm, never()).wipeDatabase(anyString());
}

@Test
void testLoadDownloadedChallengesBrokenDownloadKeepsExistingData() {
when(cm.hasAnyChallengeData(anyString())).thenReturn(true);
cim.loadDownloadedChallenges(user, world, "{ this is not json");
verify(cm, never()).wipeDatabase(anyString());
verify(cm, never()).saveChallenges();
}

@Test
Expand Down
Loading