Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • l2j/l2j-server-datapack
1 result
Show changes
Commits on Source (2)
  • Zoey76's avatar
    Fixing Warnings and Build Errors · 540bec7b
    Zoey76 authored
    Warning 1:
    WARNING: A Java agent has been loaded dynamically
    (\.m2\repository\net\bytebuddy\byte-buddy-agent\1.14.9\byte-buddy-agent-1.14.9.jar)
    WARNING: If a serviceability tool is in use, please run with
    -XX:+EnableDynamicAgentLoading to hide this warning
    WARNING: If a serviceability tool is not in use, please run with
    -Djdk.instrument.traceUsage for more information
    WARNING: Dynamic loading of agents will be disallowed by default in a
    future release
    
    Warning 2:
    Annotation processing is enabled because one or more processors were
    found on the class path. A future release of javac may disable
    annotation processing unless at least one processor is specified by name
    (-processor), or a search path is specified (--processor-path,
    --processor-module-path), or annotation processing is enabled explicitly
    (-proc:only, -proc:full).
    Use -Xlint:-options to suppress this message.
    Use -proc:none to disable annotation processing.
    
    Warning 3:
    OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot
    loader classes because bootstrap classpath has been appended.
    
    Warning 4:
    QuestManager: Replaced quest Q00372_LegacyOfInsolence (372) with a new
    version.
    540bec7b
  • Zoey76's avatar
    Updating JDA (Discord Java SDK) from 4.4.0 to 5.0.0-beta.18 · 91f76fea
    Zoey76 authored
    Followed the guide: https://jda.wiki/introduction/migration-v4-v5/
    
    The idea is to reduce the vulnerabilities, but some of them are still
    present in this version...
    
    Known vulnerabilities in JDA:
    CVE-2023-35116
    CVE-2022-24329
    CVE-2023-3635
    91f76fea
Showing
with 163 additions and 141 deletions
......@@ -13,16 +13,24 @@ pipelines:
script:
- microdnf update -y
- microdnf install -y git
- git clone --depth=1 https://bitbucket.org/l2jserver/l2j-server-game.git
- cd l2j-server-game
- /bin/sh mvnw install -DskipTests -Ddependency-check.skip=true
- |
if [ -d "l2j-server-game" ]; then
echo "Directory exists, pulling changes..."
cd l2j-server-game
git pull
else
echo "Directory does not exist, cloning repository..."
git clone --depth=1 https://bitbucket.org/l2jserver/l2j-server-game.git
cd l2j-server-game
fi
- /bin/sh mvnw clean install -DskipTests -Ddependency-check.skip=true
- cd ..
- step:
caches:
- maven
- game-server
script:
- /bin/sh mvnw install
- /bin/sh mvnw clean install
artifacts:
- target/*.zip
- step:
......
......@@ -20,6 +20,7 @@
<assertj-core.version>3.24.2</assertj-core.version>
<!-- Plugins -->
<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-install-plugin.version>3.1.1</maven-install-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
......@@ -74,6 +75,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>-XX:+EnableDynamicAgentLoading -Xshare:off</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<proc>full</proc>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -25,10 +25,12 @@ import java.util.ArrayList;
import java.util.List;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
......@@ -39,6 +41,10 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
*/
public abstract class AbstractCommand extends ListenerAdapter {
public static final EmojiUnion CROSS_MARK = Emoji.fromFormatted("\u274C");
public static final EmojiUnion CHECK_MARK = Emoji.fromFormatted("\u2705");
public abstract String[] getCommands();
public abstract void executeCommand(MessageReceivedEvent event, String[] args);
......@@ -71,8 +77,8 @@ public abstract class AbstractCommand extends ListenerAdapter {
// Only Server owner and members with the specified role assigned can execute the command.
if ((guildMember == null) || (gameMaster == null) || !guildMember.isOwner() || !guildMember.getRoles().contains(gameMaster)) {
eb.setDescription("Only Staff members can use this command!");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return false;
}
return true;
......
......@@ -22,8 +22,6 @@ import static com.l2jserver.gameserver.config.Configuration.discord;
import java.awt.Color;
import javax.security.auth.login.LoginException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -41,7 +39,6 @@ import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
......@@ -86,7 +83,7 @@ public class DiscordBot {
.awaitReady(); // Blocking guarantees that JDA will be completely loaded.
jda.getPresence().setPresence(OnlineStatus.ONLINE, Activity.listening(": -- L2J"));
LOG.info("Discord Bot Started.");
} catch (InterruptedException | LoginException ex) {
} catch (InterruptedException ex) {
LOG.error("Failed to start the Discord Bot!", ex);
}
}
......@@ -106,7 +103,7 @@ public class DiscordBot {
* @param channelId the channel to send the embed. // planned to be used by console logs
*/
public static void sendMessageTo(EmbedBuilder ed, String channelId) {
MessageChannel channel = jda.getTextChannelById(channelId);
final var channel = jda.getTextChannelById(channelId);
if (channel != null) {
channel.sendMessageEmbeds(ed.build()).queue(); // this actually sends the information to discord.
}
......
......@@ -52,8 +52,8 @@ public class OnlineCommand extends AbstractCommand {
if (args.length != 1) {
eb.setColor(Color.RED);
eb.setDescription("Please use the command without any Arguments");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue(); // Bot reacts with X mark.
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue(); // Bot reacts with X mark.
return;
}
......@@ -65,6 +65,6 @@ public class OnlineCommand extends AbstractCommand {
eb.addBlankField(false);
eb.addField("Online GM's", String.valueOf(gmCount), false);
event.getChannel().sendMessageEmbeds(eb.build()).queue(); // this actually sends the information to discord.
event.getMessage().addReaction("\u2705").queue(); // Bot reacts with check mark.
event.getMessage().addReaction(CHECK_MARK).queue(); // Bot reacts with check mark.
}
}
......@@ -87,8 +87,8 @@ public class TopCommand extends AbstractCommand {
if ((args.length == 1) || !Arrays.asList(choice).contains(args[1])) {
eb.setColor(Color.RED).setDescription("Wrong Arguments.");
eb.addField(discord().getPrefix() + " " + String.join(", ", getCommands()) + " <choice>", "Choice: \n```css\n" + String.join(", ", choice) + "```", false);
event.getTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -97,8 +97,8 @@ public class TopCommand extends AbstractCommand {
if ((args.length == 2) || (args.length > 3) || !Arrays.asList(params).contains(args[2])) {
eb.setColor(Color.RED).setDescription("Wrong Arguments.");
eb.addField("Example:", discord().getPrefix() + " top players \nParams: \n```css\n" + String.join(", ", params) + "```", false);
event.getTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
eb.setDescription("***___TOP 10 " + args[2].toUpperCase() + " PLAYERS___***");
......@@ -160,15 +160,15 @@ public class TopCommand extends AbstractCommand {
eb.setFooter("Total Players: " + getAllPlayers().size(), event.getGuild().getIconUrl());
}
eb.setThumbnail(event.getGuild().getIconUrl());
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
event.getChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(60, TimeUnit.SECONDS));
}
case "clans" -> {
if (args.length > 2) {
eb.setColor(Color.RED).setDescription("Wrong Arguments.");
eb.addField(discord().getPrefix() + " " + String.join(", ", getCommands()) + " <choice>", "Choice: \n```css\n" + String.join(", ", choice) + "```", false);
event.getTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
eb.setDescription("***___TOP 10 CLANS___***");
......@@ -204,7 +204,7 @@ public class TopCommand extends AbstractCommand {
eb.setFooter("Total Clans: " + ClanTable.getInstance().getClans().size(), event.getGuild().getIconUrl());
}
eb.setThumbnail(event.getGuild().getIconUrl());
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
event.getChannel().sendMessageEmbeds(eb.build()).queue(message -> message.delete().queueAfter(60, TimeUnit.SECONDS));
}
}
......
......@@ -55,8 +55,8 @@ public class AbortCommand extends AbstractCommand {
if (args.length != 1) {
eb.setDescription("Please use the command without any Arguments");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -65,6 +65,6 @@ public class AbortCommand extends AbstractCommand {
Shutdown.getInstance().telnetAbort(event.getAuthor().getName()); // Using telnet method.
eb.setDescription("GM: {" + gmName + "} issued command. **" + commandName + "** --- Shutdown/Restart Aborted.");
event.getChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
}
}
\ No newline at end of file
......@@ -55,8 +55,8 @@ public class AnnounceCommand extends AbstractCommand {
if (args.length <= 2) {
eb.setDescription("Wrong Arguments. Please type the message to be sent.");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -73,7 +73,7 @@ public class AnnounceCommand extends AbstractCommand {
Broadcast.toAllOnlinePlayers(screenMessage);
}
eb.setDescription("**In game Announcement have been sent**.");
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
event.getChannel().sendMessageEmbeds(eb.build()).queue();
}
}
......@@ -55,8 +55,8 @@ public class RestartCommand extends AbstractCommand {
if (args.length != 2) {
eb.setDescription("Wrong Arguments. Please just provide a number in seconds.");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -66,7 +66,7 @@ public class RestartCommand extends AbstractCommand {
} catch (NumberFormatException e) {
eb.setDescription("Wrong Arguments. Please just provide a number in seconds.");
event.getChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -76,6 +76,6 @@ public class RestartCommand extends AbstractCommand {
eb.setColor(Color.GREEN);
eb.setDescription("GM: {" + gmName + "} issued command. **" + commandName + "** in " + seconds + " " + "seconds!");
event.getChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
}
}
\ No newline at end of file
......@@ -56,8 +56,8 @@ public class ShutdownCommand extends AbstractCommand {
if (args.length != 2) {
eb.setColor(Color.RED);
eb.setDescription("Wrong Arguments. Please just provide a number in seconds.");
event.getTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getChannel().asTextChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -68,7 +68,7 @@ public class ShutdownCommand extends AbstractCommand {
eb.setColor(Color.RED);
eb.setDescription("Wrong Arguments. Please just provide a number in seconds.");
event.getChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u274C").queue();
event.getMessage().addReaction(CROSS_MARK).queue();
return;
}
......@@ -78,6 +78,6 @@ public class ShutdownCommand extends AbstractCommand {
eb.setColor(Color.GREEN);
eb.setDescription("GM: {" + gmName + "} issued command. **" + commandName + "** in " + seconds + " " + "seconds!");
event.getChannel().sendMessageEmbeds(eb.build()).queue();
event.getMessage().addReaction("\u2705").queue();
event.getMessage().addReaction(CHECK_MARK).queue();
}
}
\ No newline at end of file
......@@ -23,13 +23,13 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.datapack.custom.service.discord.DiscordBot;
import net.dv8tion.jda.api.events.DisconnectEvent;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.ReconnectedEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.events.session.SessionDisconnectEvent;
import net.dv8tion.jda.api.events.session.SessionResumeEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
/**
* Basic Listener
* Basic Listener.
* @author Stalitsa
* @version 2.6.2.0
*/
......@@ -42,14 +42,14 @@ public class BasicListener extends ListenerAdapter {
}
@Override
public void onDisconnect(DisconnectEvent event) {
public void onSessionDisconnect(SessionDisconnectEvent event) {
if (event.isClosedByServer()) {
LOG.info(event.getJDA().getSelfUser().getName() + " disconnected (closed by the server) with code: " + event.getServiceCloseFrame().getCloseCode() + " " + event.getCloseCode());
}
}
@Override
public void onReconnected(ReconnectedEvent event) {
public void onSessionResume(SessionResumeEvent event) {
LOG.info(event.getJDA().getSelfUser().getName() + " has reconnected.");
}
}
......@@ -25,10 +25,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.l2jserver.datapack.ai.npc.AbstractNpcAI;
import com.l2jserver.gameserver.model.actor.L2Npc;
/**
* Corpse test.
* @author Noé Caratini aka Kita
*/
@ExtendWith(MockitoExtension.class)
......@@ -38,8 +38,8 @@ public class CorpseTest {
private L2Npc npc;
@Test
void shouldDieOnSpawn() {
AbstractNpcAI corpseAi = new Corpse();
void testShouldDieOnSpawn() {
final var corpseAi = new Corpse();
corpseAi.onSpawn(npc);
......
......@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
......@@ -36,7 +37,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import com.l2jserver.gameserver.model.actor.L2Npc;
......@@ -85,8 +85,7 @@ public class Q00372LegacyOfInsolenceTest {
@Mock
private QuestState qs;
@Spy
private final Quest quest = new Q00372_LegacyOfInsolence();
private static final Quest QUEST = spy(new Q00372_LegacyOfInsolence());
@BeforeEach
void setUp() {
......@@ -95,295 +94,295 @@ public class Q00372LegacyOfInsolenceTest {
}
@Test
public void shouldInitQuestCorrectly() {
assertThat(quest.getId()).isEqualTo(372);
assertThat(quest.getRegisteredIds(ListenerRegisterType.NPC)).containsExactlyInAnyOrder(TRADER_HOLLY, WAREHOUSE_KEEPER_WALDERAL, MAGISTER_DESMOND, ANTIQUE_DEALER_PATRIN, CLAUDIA_ATHEBALDT, CORRUPT_SAGE, ERIN_EDIUNCE, HALLATES_INSPECTOR, PLATINUM_TRIBE_OVERLORD, MESSENGER_ANGEL, PLATINUM_GUARDIAN_PREFECT);
void testShouldInitQuestCorrectly() {
assertThat(QUEST.getId()).isEqualTo(372);
assertThat(QUEST.getRegisteredIds(ListenerRegisterType.NPC)).containsExactlyInAnyOrder(TRADER_HOLLY, WAREHOUSE_KEEPER_WALDERAL, MAGISTER_DESMOND, ANTIQUE_DEALER_PATRIN, CLAUDIA_ATHEBALDT, CORRUPT_SAGE, ERIN_EDIUNCE, HALLATES_INSPECTOR, PLATINUM_TRIBE_OVERLORD, MESSENGER_ANGEL, PLATINUM_GUARDIAN_PREFECT);
}
@Test
public void onAdvEventWithNoQuestStateShouldReturnNull() {
void testOnAdvEventWithNoQuestStateShouldReturnNull() {
when(player.getQuestState(QUEST_NAME)).thenReturn(null);
String result = quest.onAdvEvent("30844-04.htm", npc, player);
String result = QUEST.onAdvEvent("30844-04.htm", npc, player);
assertThat(result).isNull();
}
@Test
public void onAdvEventWithUnsupportedEventShouldReturnNull() {
void testOnAdvEventWithUnsupportedEventShouldReturnNull() {
String event = "00001-01.htm";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isNull();
}
@Test
public void onAdvEventWalderalStartQuest() {
void testOnAdvEventWalderalStartQuest() {
String event = "30844-04.htm";
when(qs.isCreated()).thenReturn(true);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
verify(qs).startQuest();
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalQuestAlreadyStarted() {
void testOnAdvEventWalderalQuestAlreadyStarted() {
String event = "30844-04.htm";
when(qs.isCreated()).thenReturn(false);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
verify(qs, never()).startQuest();
assertThat(result).isNull();
}
@Test
public void onAdvEventWalderalOtherBooks() {
void testOnAdvEventWalderalOtherBooks() {
String event = "30844-05b.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
verify(qs).setCond(2);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalNotAllBlueprints() {
void testOnAdvEventWalderalNotAllBlueprints() {
String event = "30844-07.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo("30844-06.html");
}
@Test
public void onAdvEventWalderalAllBlueprints() {
void testOnAdvEventWalderalAllBlueprints() {
String event = "30844-07.html";
L2ItemInstance item = mock(L2ItemInstance.class);
BLUEPRINTS.forEach(itemId -> when(inventory.getItemByItemId(itemId)).thenReturn(item));
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalDarkCrystalAllBlueprints() {
void testOnAdvEventWalderalDarkCrystalAllBlueprints() {
String event = "30844-07a.html";
BLUEPRINTS.forEach(this::stubInventoryItem);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalDarkCrystalNotAllBlueprints() {
void testOnAdvEventWalderalDarkCrystalNotAllBlueprints() {
String event = "30844-07a.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo("30844-07e.html");
}
@Test
public void onAdvEventWalderalTallumAllBlueprints() {
void testOnAdvEventWalderalTallumAllBlueprints() {
String event = "30844-07b.html";
BLUEPRINTS.forEach(this::stubInventoryItem);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalTallumNotAllBlueprints() {
void testOnAdvEventWalderalTallumNotAllBlueprints() {
String event = "30844-07b.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo("30844-07e.html");
}
@Test
public void onAdvEventWalderalNightmareAllBlueprints() {
void testOnAdvEventWalderalNightmareAllBlueprints() {
String event = "30844-07c.html";
BLUEPRINTS.forEach(this::stubInventoryItem);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalNightmareNotAllBlueprints() {
void testOnAdvEventWalderalNightmareNotAllBlueprints() {
String event = "30844-07c.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo("30844-07e.html");
}
@Test
public void onAdvEventWalderalMajesticAllBlueprints() {
void testOnAdvEventWalderalMajesticAllBlueprints() {
String event = "30844-07c.html";
BLUEPRINTS.forEach(this::stubInventoryItem);
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventWalderalMajesticNotAllBlueprints() {
void testOnAdvEventWalderalMajesticNotAllBlueprints() {
String event = "30844-07c.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo("30844-07e.html");
}
@Test
public void onAdvEventWalderalAbortQuest() {
void testOnAdvEventWalderalAbortQuest() {
String event = "30844-09.html";
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
verify(qs).exitQuest(true, true);
assertThat(result).isEqualTo(event);
}
@Test
public void onAdvEventOtherSupportedEvents() {
void testOnAdvEventOtherSupportedEvents() {
List.of("30844-03.htm", "30844-05.html", "30844-05a.html", "30844-08.html", "30844-10.html", "30844-11.html")
.forEach(event -> {
String result = quest.onAdvEvent(event, npc, player);
String result = QUEST.onAdvEvent(event, npc, player);
assertThat(result).isEqualTo(event);
});
}
@Test
public void onTalkShouldInitQuestStateForPlayer() {
void testOnTalkShouldInitQuestStateForPlayer() {
when(player.getQuestState(QUEST_NAME)).thenReturn(null);
quest.onTalk(npc, player);
QUEST.onTalk(npc, player);
verify(quest).newQuestState(player);
verify(QUEST).newQuestState(player);
}
@Test
public void onTalkToWrongNpcWithStateCreated() {
void testOnTalkToWrongNpcWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(WRONG_NPC);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToWalderalWithStateCreatedAndLevelTooLow() {
void testOnTalkToWalderalWithStateCreatedAndLevelTooLow() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(WAREHOUSE_KEEPER_WALDERAL);
when(player.getLevel()).thenReturn(MIN_LEVEL - 1);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(WAREHOUSE_KEEPER_WALDERAL + "-01.htm");
}
@Test
public void onTalkToWalderalWithStateCreated() {
void testOnTalkToWalderalWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(WAREHOUSE_KEEPER_WALDERAL);
when(player.getLevel()).thenReturn(MIN_LEVEL);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(WAREHOUSE_KEEPER_WALDERAL + "-02.htm");
}
@Test
public void onTalkToHollyWithStateCreated() {
void testOnTalkToHollyWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(TRADER_HOLLY);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToDesmondWithStateCreated() {
void testOnTalkToDesmondWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(MAGISTER_DESMOND);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToPatrinWithStateCreated() {
void testOnTalkToPatrinWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(ANTIQUE_DEALER_PATRIN);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToClaudiaWithStateCreated() {
void testOnTalkToClaudiaWithStateCreated() {
when(qs.isCreated()).thenReturn(true);
when(npc.getId()).thenReturn(CLAUDIA_ATHEBALDT);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToWrongNpcWithStateStarted() {
void testOnTalkToWrongNpcWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(WRONG_NPC);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(Quest.getNoQuestMsg(player));
}
@Test
public void onTalkToWalderalWithStateStarted() {
void testOnTalkToWalderalWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(WAREHOUSE_KEEPER_WALDERAL);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(WAREHOUSE_KEEPER_WALDERAL + "-05.html");
}
@Test
public void onTalkToHollyWithStateStarted() {
void testOnTalkToHollyWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(TRADER_HOLLY);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(TRADER_HOLLY + "-01.html");
}
@Test
public void onTalkToHollyWithStateStartedAndAllItems() {
void testOnTalkToHollyWithStateStartedAndAllItems() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(TRADER_HOLLY);
IMPERIAL_GENEALOGY.forEach(this::stubInventoryItem);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
List<Integer> removedItemIds = verifyItemsRemoved(player, IMPERIAL_GENEALOGY);
assertThat(removedItemIds).containsExactlyInAnyOrderElementsOf(IMPERIAL_GENEALOGY);
......@@ -391,22 +390,22 @@ public class Q00372LegacyOfInsolenceTest {
}
@Test
public void onTalkToDesmondWithStateStarted() {
void testOnTalkToDesmondWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(MAGISTER_DESMOND);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(MAGISTER_DESMOND + "-01.html");
}
@Test
public void onTalkToDesmondWithStateStartedAndAllItems() {
void testOnTalkToDesmondWithStateStartedAndAllItems() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(MAGISTER_DESMOND);
REVELATION_OF_THE_SEALS.forEach(this::stubInventoryItem);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
List<Integer> removedItemIds = verifyItemsRemoved(player, REVELATION_OF_THE_SEALS);
assertThat(removedItemIds).containsExactlyInAnyOrderElementsOf(REVELATION_OF_THE_SEALS);
......@@ -414,22 +413,22 @@ public class Q00372LegacyOfInsolenceTest {
}
@Test
public void onTalkToPatrinWithStateStarted() {
void testOnTalkToPatrinWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(ANTIQUE_DEALER_PATRIN);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(ANTIQUE_DEALER_PATRIN + "-01.html");
}
@Test
public void onTalkToPatrinWithStateStartedAndAllItems() {
void testOnTalkToPatrinWithStateStartedAndAllItems() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(ANTIQUE_DEALER_PATRIN);
ANCIENT_EPIC.forEach(this::stubInventoryItem);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
List<Integer> removedItemIds = verifyItemsRemoved(player, ANCIENT_EPIC);
assertThat(removedItemIds).containsExactlyInAnyOrderElementsOf(ANCIENT_EPIC);
......@@ -437,22 +436,22 @@ public class Q00372LegacyOfInsolenceTest {
}
@Test
public void onTalkToClaudiaWithStateStarted() {
void testOnTalkToClaudiaWithStateStarted() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(CLAUDIA_ATHEBALDT);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
assertThat(result).isEqualTo(CLAUDIA_ATHEBALDT + "-01.html");
}
@Test
public void onTalkToClaudiaWithStateStartedAndAllItems() {
void testOnTalkToClaudiaWithStateStartedAndAllItems() {
when(qs.isStarted()).thenReturn(true);
when(npc.getId()).thenReturn(CLAUDIA_ATHEBALDT);
REVELATION_OF_THE_SEALS.forEach(this::stubInventoryItem);
String result = quest.onTalk(npc, player);
String result = QUEST.onTalk(npc, player);
List<Integer> removedItemIds = verifyItemsRemoved(player, REVELATION_OF_THE_SEALS);
assertThat(removedItemIds).containsExactlyInAnyOrderElementsOf(REVELATION_OF_THE_SEALS);
......@@ -460,57 +459,57 @@ public class Q00372LegacyOfInsolenceTest {
}
@Test
public void onKillCorruptSageShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillCorruptSageShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(CORRUPT_SAGE);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 1, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 1, npc);
}
@Test
public void onKillErinEdiunceShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillErinEdiunceShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(ERIN_EDIUNCE);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 1, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 1, npc);
}
@Test
public void onKillHallatesInspectorShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillHallatesInspectorShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(HALLATES_INSPECTOR);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 3, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 3, npc);
}
@Test
public void onKillPlatinumOverlordShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillPlatinumOverlordShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(PLATINUM_TRIBE_OVERLORD);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 3, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 3, npc);
}
@Test
public void onKillMessengerAngelShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillMessengerAngelShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(MESSENGER_ANGEL);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 1, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 1, npc);
}
@Test
public void onKillPlatinumPrefectShouldGetQuestStateWithCorrectPlayerChance() {
void testOnKillPlatinumPrefectShouldGetQuestStateWithCorrectPlayerChance() {
when(npc.getId()).thenReturn(PLATINUM_GUARDIAN_PREFECT);
quest.onKill(npc, player, false);
QUEST.onKill(npc, player, false);
verify(quest).getRandomPartyMemberState(player, -1, 1, npc);
verify(QUEST).getRandomPartyMemberState(player, -1, 1, npc);
}
private void stubInventoryItem(Integer itemId) {
......