diff --git a/Core/src/main/java/net/bteuk/network/core/Constants.java b/Core/src/main/java/net/bteuk/network/core/Constants.java index b55864c1..d3f773bf 100644 --- a/Core/src/main/java/net/bteuk/network/core/Constants.java +++ b/Core/src/main/java/net/bteuk/network/core/Constants.java @@ -7,9 +7,10 @@ public record Constants(String serverName, ServerType serverType, boolean standalone, boolean regionsEnabled, long regionInactivity, boolean tpllEnabled, boolean tpllRequiresPermission, int maxY, int minY, String earthWorld, boolean staffChat, boolean tips, boolean tutorials, boolean ll, boolean progressMap, boolean progression, boolean announceOveralLevelUps, boolean announceSeasonLevelUps, boolean sidebarEnabled, String sidebarTitle, - List sidebarContent, boolean motdEnabled, String motdContent, String minrankGeneration, String minrankRegionClaim, String minrankZoneJoin, boolean plotSystemEnabled, boolean moderationEnabled, boolean warpsEnabled, + List sidebarContent, boolean motdEnabled, String motdContent, String minrankGeneration, String minrankRegionClaim, String minrankZoneJoin, + boolean plotSystemEnabled, boolean moderationEnabled, boolean warpsEnabled, boolean homesEnabled, boolean announcePromotions, String discordLink, boolean skullsEnabled, String progressMapLink, String chatSocketOutputIP, int chatSocketOutputPort, int chatSocketInputPort, int tipsFrequency, boolean regionStaffRequestAlways, int regionStaffRequestRadius, int progressMapID, String mapHubAPIKey, int navigationRadius, boolean compulsoryTutorial, int afkTime, boolean mapEnabled, String mapServer, NetworkLocation mapLocation, - NetworkLocation spawnLocation) { + NetworkLocation spawnLocation, boolean UKSurvey) { } \ No newline at end of file diff --git a/Plugin/src/main/java/net/bteuk/network/Network.java b/Plugin/src/main/java/net/bteuk/network/Network.java index 2ab78777..1cc0cba8 100644 --- a/Plugin/src/main/java/net/bteuk/network/Network.java +++ b/Plugin/src/main/java/net/bteuk/network/Network.java @@ -38,6 +38,7 @@ import net.bteuk.network.commands.Reply; import net.bteuk.network.commands.Rules; import net.bteuk.network.commands.Speed; +import net.bteuk.network.commands.Survey; import net.bteuk.network.commands.TipsToggle; import net.bteuk.network.commands.Where; import net.bteuk.network.commands.Zone; @@ -418,13 +419,16 @@ public void enablePlugin() { commandManager.registerCommand(new Homes(this)); } + if (constants.UKSurvey()) { + commandManager.registerCommand(new Survey(this, globalSQL)); + } + /* * Utility commands. */ commandManager.registerCommand(new Buildings(this, plotSQL, constants)); commandManager.registerCommand(new Discord(this, roleAPI, constants, messageSender)); commandManager.registerCommand(new Focus(this, messageSender)); - commandManager.registerCommand(new Buildings(this, plotSQL, constants)); commandManager.registerCommand(nightvision); commandManager.registerCommand(new Speed()); diff --git a/Plugin/src/main/java/net/bteuk/network/commands/Survey.java b/Plugin/src/main/java/net/bteuk/network/commands/Survey.java new file mode 100644 index 00000000..e8122fde --- /dev/null +++ b/Plugin/src/main/java/net/bteuk/network/commands/Survey.java @@ -0,0 +1,115 @@ +package net.bteuk.network.commands; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import lombok.extern.java.Log; +import net.bteuk.network.CustomChat; +import net.bteuk.network.Network; +import net.bteuk.network.core.Time; +import net.bteuk.network.lib.dto.UserUpdate; +import net.bteuk.network.lib.utils.ChatUtils; +import net.bteuk.network.socket.MessageSender; +import net.bteuk.network.sql.GlobalSQL; +import net.bteuk.network.survey.SurveyAnswerOption; +import net.bteuk.network.survey.SurveyBook; +import net.bteuk.network.utils.NetworkUser; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.NonNull; + +import java.util.logging.Level; + +@Log +public class Survey extends AbstractCommand { + + private final Network instance; + private final GlobalSQL globalSQL; + + public Survey(Network instance, GlobalSQL globalSQL) { + this.instance = instance; + this.globalSQL = globalSQL; + } + + @Override + public void execute(@NotNull CommandSourceStack stack, String @NonNull [] args) { + + // Check if the sender is a player. + Player player = getPlayer(stack); + if (player == null) { + return; + } + + NetworkUser user = instance.getUser(player); + + // If u is null, cancel. + if (user == null) { + log.severe("User " + player.getName() + " can not be found!"); + player.sendMessage(ChatUtils.error("User can not be found, please relog!")); + return; + } + + if (args.length == 0) { + SurveyBook.openSurvey(user, globalSQL); + } else if (args.length == 1 && args[0].equalsIgnoreCase("save")) { + SurveyBook surveyBook = SurveyBook.getOpenSurvey(user); + if (surveyBook != null) { + surveyBook.saveSurvey(); + } + } else if (args.length == 2) { + SurveyBook surveyBook = SurveyBook.getOpenSurvey(user); + if (surveyBook == null) + return; + + SurveyAnswerOption answerOption; + + try { + answerOption = SurveyAnswerOption.valueOf(args[0].toUpperCase()); + } + catch (IllegalArgumentException e) { + log.log(Level.WARNING, "Invalid answer option at command survey: " + args[0], e); + return; + } + + boolean bYes = args[1].equals("Y"); + switch (answerOption) { + case Q1_BTUK -> surveyBook.getSurvey().setBFoundViaBTUK(bYes); + case Q1_BTE -> surveyBook.getSurvey().setBFoundViaBTE(bYes); + case Q1_BTUK_EXTERNAL -> surveyBook.getSurvey().setBFoundViaBTUKExternal(bYes); + case Q1_BTE_EXTERNAL -> surveyBook.getSurvey().setBFoundViaBTEExternal(bYes); + case Q1_FRIEND -> surveyBook.getSurvey().setBFoundViaFriend(bYes); + case Q2_TIKTOK -> surveyBook.getSurvey().setBMediumTiktok(bYes); + case Q2_YT_SHORT -> surveyBook.getSurvey().setBMediumYoutubeShorts(bYes); + case Q2_YT_LONG -> surveyBook.getSurvey().setBMediumYoutubeLongform(bYes); + case Q2_INSTAGRAM -> surveyBook.getSurvey().setBMediumInstagram(bYes); + case Q2_SEARCH -> surveyBook.getSurvey().setBSearchEngineBrowsing(bYes); + case Q2_ONLINE_NEWS -> surveyBook.getSurvey().setBOnlineNews(bYes); + case Q2_TV_NEWS -> surveyBook.getSurvey().setBTVNews(bYes); + case Q2_NEWSPAPER -> surveyBook.getSurvey().setBPhysicalNewspaper(bYes); + case Q3_TIKTOK -> surveyBook.getSurvey().setBSocialsTiktok(bYes); + case Q3_YOUTUBE_SHORTS -> surveyBook.getSurvey().setBSocialsYoutubeShorts(bYes); + case Q3_YOUTUBE_LONG -> surveyBook.getSurvey().setBSocialsYoutubeLongform(bYes); + case Q3_INSTAGRAM -> surveyBook.getSurvey().setBSocialsInstagram(bYes); + case CHANGE_PAGE -> { + try { + int toPage = Integer.parseInt(args[1]); + surveyBook.changePage(toPage); + } + catch (NumberFormatException e) { + log.log(Level.WARNING, "Invalid page number: " + args[1], e); + } + } + } + surveyBook.updateSurveyBooks(); + surveyBook.openCurrentPage(); + } + } + + @Override + public String getLabel() { + return "survey"; + } + + @Override + public String getDescription() { + return "Complete the UK Survey"; + } +} diff --git a/Plugin/src/main/java/net/bteuk/network/gui/NavigatorGui.java b/Plugin/src/main/java/net/bteuk/network/gui/NavigatorGui.java index 48f5cbc1..3d543932 100644 --- a/Plugin/src/main/java/net/bteuk/network/gui/NavigatorGui.java +++ b/Plugin/src/main/java/net/bteuk/network/gui/NavigatorGui.java @@ -1,5 +1,6 @@ package net.bteuk.network.gui; +import net.bteuk.network.Network; import net.bteuk.network.api.EventAPI; import net.bteuk.network.api.ServerAPI; import net.bteuk.network.api.entity.NetworkLocation; @@ -14,6 +15,7 @@ import net.bteuk.network.papercore.LocationAdapter; import net.bteuk.network.papercore.PlayerAdapter; import net.bteuk.network.sql.GlobalSQL; +import net.bteuk.network.survey.SurveyBook; import net.bteuk.network.utils.LightsOut; import net.bteuk.network.utils.NetworkUser; import net.bteuk.network.utils.Utils; @@ -104,6 +106,12 @@ public NavigatorGui(GuiProvider provider) { Utils.line("You can also use the command ").append(Component.text("/nightvision", NamedTextColor.GRAY)).append(Utils.line(" or ")) .append(Component.text("/nv", NamedTextColor.GRAY))), nightvision::toggleNightvision); + // Survey + if (constants.UKSurvey()) + setItem(18, Utils.createItem(Material.PAPER, 1, Utils.title("UK Survey"), Utils.line("Assist us with our PR strategy.")), (NetworkUser u) -> { + SurveyBook.openSurvey(u, globalSQL); + }); + setItem(19, Utils.createItem(Material.REDSTONE_LAMP, 1, Utils.title("Lights Out"), Utils.line("Play a game of Lights Out.")), (NetworkUser u) -> { if (u.lightsOut == null) { diff --git a/Plugin/src/main/java/net/bteuk/network/sql/GlobalSQL.java b/Plugin/src/main/java/net/bteuk/network/sql/GlobalSQL.java index 708cdf37..ed999564 100644 --- a/Plugin/src/main/java/net/bteuk/network/sql/GlobalSQL.java +++ b/Plugin/src/main/java/net/bteuk/network/sql/GlobalSQL.java @@ -7,6 +7,7 @@ import net.bteuk.network.core.Time; import net.bteuk.network.core.sql.AbstractSQL; import net.bteuk.network.lib.dto.DirectMessage; +import net.bteuk.network.survey.Survey; import net.bteuk.network.utils.Coordinate; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import org.bukkit.Bukkit; @@ -19,8 +20,12 @@ import java.sql.SQLException; import java.sql.Statement; import java.time.LocalDateTime; +import java.sql.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import java.util.logging.Level; @Log public class GlobalSQL extends AbstractSQL { @@ -320,4 +325,82 @@ public boolean createUser(String uuid, String name, String playerSkin) { } else return true; } + + public Survey getSurveyOfUser(UUID uuid) { + Survey survey; + try ( + Connection conn = conn(); + PreparedStatement statement = conn.prepareStatement( + "SELECT survey_completed_at, survey_last_edited, found_via_btuk, found_via_bte, found_via_btuk_external, found_via_bte_external,found_via_friend," + + "medium_tiktok, medium_youtube_shorts, medium_youtube_longform, medium_instagram," + + "medium_search_engine_browsing, medium_online_news, medium_tvnews, medium_physical_newspaper," + + "socials_tiktok, socials_youtube_shorts, socials_youtube_longform, socials_instagram FROM survey WHERE player=?;" + ) + ) { + statement.setString(1, uuid.toString()); + ResultSet results = statement.executeQuery(); + + if (results.next()) { + survey = new Survey(true, results.getTimestamp(1), results.getTimestamp(2), + results.getBoolean(3), results.getBoolean(4), results.getBoolean(5), results.getBoolean(6), results.getBoolean(7), + results.getBoolean(8), results.getBoolean(9), results.getBoolean(10), results.getBoolean(11), + results.getBoolean(12), results.getBoolean(13), results.getBoolean(14), results.getBoolean(15), + results.getBoolean(16), results.getBoolean(17), results.getBoolean(18), results.getBoolean(19)); + return survey; + } else + return null; + + } catch (SQLException e) { + log.log(Level.SEVERE, e.getMessage(), e); + return null; + } + } + + public void saveSurveyOfUser(UUID user, Survey survey) { + try ( + Connection conn = conn(); + PreparedStatement statement = (survey.isExisting()) ? + conn.prepareStatement("UPDATE survey SET survey_last_edited=?, found_via_btuk=?, found_via_bte=?, " + + "found_via_btuk_external=?, found_via_bte_external=?, found_via_friend=?," + + "medium_tiktok=?, medium_youtube_shorts=?, medium_youtube_longform=?, medium_instagram=?," + + "medium_search_engine_browsing=?, medium_online_news=?, medium_tvnews=?, medium_physical_newspaper=?," + + "socials_tiktok=?, socials_youtube_shorts=?, socials_youtube_longform=?, socials_instagram=? WHERE player=?;") + : + conn.prepareStatement("INSERT INTO survey (survey_completed_at, survey_last_edited, found_via_btuk, found_via_bte, " + + "found_via_btuk_external, found_via_bte_external, found_via_friend, " + + "medium_tiktok, medium_youtube_shorts, medium_youtube_longform, medium_instagram, " + + "medium_search_engine_browsing, medium_online_news, medium_tvnews, medium_physical_newspaper, " + + "socials_tiktok, socials_youtube_shorts, socials_youtube_longform, socials_instagram, player)" + + "VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);") + ) { + statement.setTimestamp(1, Timestamp.from(Instant.now())); + statement.setBoolean(2, survey.isBFoundViaBTUK()); + statement.setBoolean(3, survey.isBFoundViaBTE()); + statement.setBoolean(4, survey.isBFoundViaBTUKExternal()); + statement.setBoolean(5, survey.isBFoundViaBTEExternal()); + statement.setBoolean(6, survey.isBFoundViaFriend()); + + statement.setBoolean(7, survey.isBMediumTiktok()); + statement.setBoolean(8, survey.isBMediumYoutubeShorts()); + statement.setBoolean(9, survey.isBMediumYoutubeLongform()); + statement.setBoolean(10, survey.isBMediumInstagram()); + statement.setBoolean(11, survey.isBSearchEngineBrowsing()); + statement.setBoolean(12, survey.isBOnlineNews()); + statement.setBoolean(13, survey.isBTVNews()); + statement.setBoolean(14, survey.isBPhysicalNewspaper()); + + statement.setBoolean(15, survey.isBSocialsTiktok()); + statement.setBoolean(16, survey.isBSocialsYoutubeShorts()); + statement.setBoolean(17, survey.isBSocialsYoutubeLongform()); + statement.setBoolean(18, survey.isBSocialsInstagram()); + + statement.setString(19, user.toString()); + + if (statement.executeUpdate() == 1) + survey.setExisting(true); + + } catch (SQLException sql) { + log.log(Level.SEVERE, sql.getMessage(), sql); + } + } } diff --git a/Plugin/src/main/java/net/bteuk/network/survey/Survey.java b/Plugin/src/main/java/net/bteuk/network/survey/Survey.java new file mode 100644 index 00000000..1551d753 --- /dev/null +++ b/Plugin/src/main/java/net/bteuk/network/survey/Survey.java @@ -0,0 +1,41 @@ +package net.bteuk.network.survey; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.sql.Timestamp; + +/** + * Stores survey answers + */ +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class Survey { + private boolean isExisting; + + Timestamp SurveyCompleted; + Timestamp SurveyLastEdited; + boolean bFoundViaBTUK; + boolean bFoundViaBTE; + boolean bFoundViaBTUKExternal; + boolean bFoundViaBTEExternal; + boolean bFoundViaFriend; + + boolean bMediumTiktok; + boolean bMediumYoutubeShorts; + boolean bMediumYoutubeLongform; + boolean bMediumInstagram; + boolean bSearchEngineBrowsing; + boolean bOnlineNews; + boolean bTVNews; + boolean bPhysicalNewspaper; + + boolean bSocialsTiktok; + boolean bSocialsYoutubeShorts; + boolean bSocialsYoutubeLongform; + boolean bSocialsInstagram; +} diff --git a/Plugin/src/main/java/net/bteuk/network/survey/SurveyAnswerOption.java b/Plugin/src/main/java/net/bteuk/network/survey/SurveyAnswerOption.java new file mode 100644 index 00000000..7081222c --- /dev/null +++ b/Plugin/src/main/java/net/bteuk/network/survey/SurveyAnswerOption.java @@ -0,0 +1,22 @@ +package net.bteuk.network.survey; + +public enum SurveyAnswerOption { + Q1_BTUK, + Q1_BTE, + Q1_BTUK_EXTERNAL, + Q1_BTE_EXTERNAL, + Q1_FRIEND, + Q2_TIKTOK, + Q2_YT_SHORT, + Q2_YT_LONG, + Q2_INSTAGRAM, + Q2_SEARCH, + Q2_ONLINE_NEWS, + Q2_TV_NEWS, + Q2_NEWSPAPER, + Q3_TIKTOK, + Q3_YOUTUBE_SHORTS, + Q3_YOUTUBE_LONG, + Q3_INSTAGRAM, + CHANGE_PAGE +} \ No newline at end of file diff --git a/Plugin/src/main/java/net/bteuk/network/survey/SurveyBook.java b/Plugin/src/main/java/net/bteuk/network/survey/SurveyBook.java new file mode 100644 index 00000000..b33cfb99 --- /dev/null +++ b/Plugin/src/main/java/net/bteuk/network/survey/SurveyBook.java @@ -0,0 +1,230 @@ +package net.bteuk.network.survey; + +import lombok.Getter; +import net.bteuk.network.lib.utils.ChatUtils; +import net.bteuk.network.sql.GlobalSQL; +import net.bteuk.network.utils.NetworkUser; +import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.format.TextDecoration; + +import java.util.HashMap; + +public class SurveyBook { + private final NetworkUser user; + private final GlobalSQL globalSQL; + @Getter + private final Survey survey; + private final Book[] books = new Book[5]; + /** + * The current open page of the book, zero indexed + */ + private int iCurrentPage; + + private static final HashMap openSurveys = new HashMap<>(); + + public SurveyBook(NetworkUser user, GlobalSQL globalSQL) { + this.user = user; + this.globalSQL = globalSQL; + + // Get survey details + Survey existingSurvey = globalSQL.getSurveyOfUser(user.player.getUniqueId()); + this.survey = (existingSurvey == null) ? new Survey() : existingSurvey; + + iCurrentPage = 0; + + // Update survey with answers + updateSurveyBooks(); + + openSurveys.put(user, this); + } + + /** + * Opens a survey for a user + */ + public static void openSurvey(NetworkUser user, GlobalSQL globalSQL) { + SurveyBook openSurvey = SurveyBook.getOpenSurvey(user); + if (openSurvey == null) { + openSurvey = new SurveyBook(user, globalSQL); + } + openSurvey.openCurrentPage(); + } + + /** + * Changes the open page dof the survey. + * + * @param iPage The page to change to, 1 indexed. + */ + public void changePage(int iPage) { + iCurrentPage = iPage - 1; + } + + /** + * Open page iPage of the survey. + */ + public void openCurrentPage() { + user.player.openBook(books[iCurrentPage]); + } + + public void saveSurvey() { + globalSQL.saveSurveyOfUser(user.player.getUniqueId(), survey); + user.sendMessage(ChatUtils.success("Thank you! Survey has been saved!")); + openSurveys.remove(user); + } + + /** + * @param user The user whom to get the open survey of. + * @return The open survey of the given user, or null if the user has no open survey. + */ + public static SurveyBook getOpenSurvey(NetworkUser user) { + return openSurveys.get(user); + } + + /** + * Update book based on survey responses + */ + public void updateSurveyBooks() { + + // Page 1 - Which outlet + Component page1 = Component.empty(); + // Question 1 + page1 = page1.append(Component.text("Question 1").decorate(TextDecoration.BOLD)); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = page1.append(Component.text("Prior to joining the server, who did you find out about BTUK (Formerly BTE UK) from?")); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = page1.append(Component.text("Answer on next page !")); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = page1.appendNewline(); + page1 = appendPageChangeOption(page1, false, true, 1); + + this.books[0] = Book.book(Component.text(""), ChatUtils.line(user.player.getName()), page1); + + // Page 2 Question 1 answers + Component page2 = Component.empty(); + page2 = appendOptionYesNo("Build the UK", page2, SurveyAnswerOption.Q1_BTUK, survey.bFoundViaBTUK, !survey.bFoundViaBTUK); + page2 = page2.appendNewline(); // Extra line + page2 = appendOptionYesNo("Build The Earth", page2, SurveyAnswerOption.Q1_BTE, survey.bFoundViaBTE, !survey.bFoundViaBTE); + page2 = page2.appendNewline(); // Extra line + page2 = appendOptionYesNo("External Media Mentioning Build the UK", page2, SurveyAnswerOption.Q1_BTUK_EXTERNAL, survey.bFoundViaBTUKExternal, !survey.bFoundViaBTUKExternal); + page2 = page2.appendNewline(); // Extra line + page2 = appendOptionYesNo("External Media Mentioning Build The Earth", page2, SurveyAnswerOption.Q1_BTE_EXTERNAL, survey.bFoundViaBTEExternal, !survey.bFoundViaBTEExternal); + page2 = page2.appendNewline(); // Extra line + page2 = appendOptionYesNo("From a Friend", page2, SurveyAnswerOption.Q1_FRIEND, survey.bFoundViaFriend, !survey.bFoundViaFriend); + page2 = appendPageChangeOption(page2, true, true, 2); + + this.books[1] = Book.book(Component.text(""), ChatUtils.line(user.player.getName()), page2); + + // Page 3 Question 2 - Which medium + Component page3 = Component.empty(); + // Question 2 + page3 = page3.append(Component.text("Question 2").decorate(TextDecoration.BOLD)); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = page3.append(Component.text("Prior to joining, through which mediums did you hear about Build the UK or Build The Earth?")); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = page3.append(Component.text("Answer on next page !")); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = page3.appendNewline(); + page3 = appendPageChangeOption(page3, true, true, 3); + + this.books[2] = Book.book(Component.text(""), ChatUtils.line(user.player.getName()), page3); + + // Page 4 Question 2 answers + Component page4 = Component.empty(); + page4 = appendOptionYesNo("TikTok", page4, SurveyAnswerOption.Q2_TIKTOK, survey.bMediumTiktok, !survey.bMediumTiktok); + page4 = appendOptionYesNo("YouTube Short", page4, SurveyAnswerOption.Q2_YT_SHORT, survey.bMediumYoutubeShorts, !survey.bMediumYoutubeShorts); + page4 = appendOptionYesNo("YouTube Longform", page4, SurveyAnswerOption.Q2_YT_LONG, survey.bMediumYoutubeLongform, !survey.bMediumYoutubeLongform); + page4 = appendOptionYesNo("YouTube Instagram", page4, SurveyAnswerOption.Q2_INSTAGRAM, survey.bMediumInstagram, !survey.bMediumInstagram); + page4 = appendOptionYesNo("YouTube Search Engine - Browsing", page4, SurveyAnswerOption.Q2_SEARCH, survey.bSearchEngineBrowsing, !survey.bSearchEngineBrowsing); + page4 = appendOptionYesNo("Online News", page4, SurveyAnswerOption.Q2_ONLINE_NEWS, survey.bOnlineNews, !survey.bOnlineNews); + page4 = appendOptionYesNo("TV News", page4, SurveyAnswerOption.Q2_TV_NEWS, survey.bTVNews, !survey.bTVNews); + page4 = appendOptionYesNo("Physical Newspaper", page4, SurveyAnswerOption.Q2_NEWSPAPER, survey.bPhysicalNewspaper, !survey.bPhysicalNewspaper); + page4 = appendPageChangeOption(page4, true, true, 4); + + this.books[3] = Book.book(Component.text(""), ChatUtils.line(user.player.getName()), page4); + + // Page 5 Question 3 Which socials + Component page5 = Component.empty(); + page5 = page5.append(Component.text("Question 3").decorate(TextDecoration.BOLD)); + page5 = page5.appendNewline(); + page5 = page5.append(Component.text("What social media platforms do you use regularly?")); + page5 = page5.appendNewline(); + page5 = page5.appendNewline(); + page5 = appendOptionYesNo("TikTok", page5, SurveyAnswerOption.Q3_TIKTOK, survey.bSocialsTiktok, !survey.bSocialsTiktok); + page5 = appendOptionYesNo("YouTube Shorts", page5, SurveyAnswerOption.Q3_YOUTUBE_SHORTS, survey.bSocialsYoutubeShorts, !survey.bSocialsYoutubeShorts); + page5 = appendOptionYesNo("YouTube Longform", page5, SurveyAnswerOption.Q3_YOUTUBE_LONG, survey.bSocialsYoutubeLongform, !survey.bSocialsYoutubeLongform); + page5 = appendOptionYesNo("Instagram", page5, SurveyAnswerOption.Q3_INSTAGRAM, survey.bSocialsInstagram, !survey.bSocialsInstagram); + page5 = page5.appendNewline(); + page5 = page5.append(Component.text("Save Survey")); + page5 = page5.appendSpace(); + page5 = page5.append(Component.text("[Save]") + .color(TextColor.color(NamedTextColor.GREEN.value())) + .clickEvent(ClickEvent.runCommand("/survey save"))); + page5 = page5.appendNewline(); + page5 = appendPageChangeOption(page5, true, false, 5); + + this.books[4] = Book.book(Component.text(""), ChatUtils.line(user.player.getName()), page5); + } + + private Component appendOptionYesNo(String optionName, Component component, SurveyAnswerOption option, boolean bYSelected, boolean bNSelected) { + component = component.append(Component.text(optionName)); + component = component.appendSpace(); + + //[Y] + component = component.append(Component.text("[")); + Component Y = Component.text("Y").color(TextColor.color(NamedTextColor.GREEN.value())) + .clickEvent(ClickEvent.runCommand("/survey " + option.name() + " Y")); + if (bYSelected) { + component = component.append(Y.decorate(TextDecoration.BOLD).decorate(TextDecoration.UNDERLINED)); + } + else { + component = component.append(Y); + } + component = component.append(Component.text("]")); + component = component.appendSpace(); + //[N] + component = component.append(Component.text("[")); + Component N = Component.text("N").color(TextColor.color(NamedTextColor.RED.value())) + .clickEvent(ClickEvent.runCommand("/survey " + option.name() + " N")); + if (bNSelected) { + component = component.append(N.decorate(TextDecoration.BOLD).decorate(TextDecoration.UNDERLINED)); + } + else { + component = component.append(N); + } + component = component.append(Component.text("]")); + + component = component.appendNewline(); + return component; + } + + private Component appendPageChangeOption(Component component, boolean bIncludeBack, boolean bIncludeForwards, int iCurrentPage) { + + if (bIncludeBack) { + component = component.append(Component.text("[Previous]").color(TextColor.color(NamedTextColor.LIGHT_PURPLE.value())) + .clickEvent(ClickEvent.runCommand("/survey " + SurveyAnswerOption.CHANGE_PAGE.name() + " " + (iCurrentPage - 1)))); + if (bIncludeForwards) { + component = component.append(Component.text(" ")); + component = component.append(Component.text("[Next]").color(TextColor.color(NamedTextColor.LIGHT_PURPLE.value())) + .clickEvent(ClickEvent.runCommand("/survey " + SurveyAnswerOption.CHANGE_PAGE.name() + " " + (iCurrentPage + 1)))); + } + } else if (bIncludeForwards) { + component = component.append(Component.text(" ")); + component = component.append(Component.text("[Next]").color(TextColor.color(NamedTextColor.LIGHT_PURPLE.value())) + .clickEvent(ClickEvent.runCommand("/survey " + SurveyAnswerOption.CHANGE_PAGE.name() + " " + (iCurrentPage + 1)))); + } + return component; + } +} diff --git a/Plugin/src/main/java/net/bteuk/network/utils/NetworkConfig.java b/Plugin/src/main/java/net/bteuk/network/utils/NetworkConfig.java index 0383e013..726e5e22 100644 --- a/Plugin/src/main/java/net/bteuk/network/utils/NetworkConfig.java +++ b/Plugin/src/main/java/net/bteuk/network/utils/NetworkConfig.java @@ -43,7 +43,7 @@ private String configVersion() { private String latestVersion() { String version = Objects.requireNonNull(config.getDefaults()).getString("version"); // If null return default. - return Objects.requireNonNullElse(version, "1.8.0"); + return Objects.requireNonNullElse(version, "1.10.0"); } // Update config if the version is outdated. @@ -202,11 +202,14 @@ public net.bteuk.network.core.Constants getConstants() { NetworkLocation spawnLocation = new NetworkLocation(config.getString("spawn.world"), config.getDouble("spawn.x"), config.getDouble("spawn.y"), config.getDouble("spawn.z"), (float) config.getDouble("spawn.yaw"), (float) config.getDouble("spawn.pitch")); + boolean UKSurvey = config.getBoolean("UKSurvey_enabled"); + log.info("Loaded constants from config."); return new Constants(serverName, serverType, standalone, regionsEnabled, regionInactivity, tpllEnabled, tpllRequiredPermission, maxY, minY, earthWorld, staffChat, tips, tutorials, llEnabled, progressMap, progression, announceOverallLevelUps, announceSeasonalLevelUps, sidebarEnabled, sidebarTitle, sidebarTextList, motdEnabled, - motdText, minrankGeneration, minrankRegionClaim, minrankZoneJoin, plotSystemEnabled, moderationEnabled, warpsEnabled, homesEnabled, announcePromotions, discordLink, skullsEnabled, progressMapLink, chatSocketOutputIP, + motdText, minrankGeneration, minrankRegionClaim, minrankZoneJoin, plotSystemEnabled, moderationEnabled, warpsEnabled, homesEnabled, announcePromotions, discordLink, + skullsEnabled, progressMapLink, chatSocketOutputIP, chatSocketOutputPort, chatSocketInputPort, tipsFrequency, regionStaffRequestAlways, regionStaffRequestRadius, progressMapID, mapHubAPIKey, navigationRadius, - compulsoryTutorial, afkTime, mapEnabled, mapServer, mapLocation, spawnLocation); + compulsoryTutorial, afkTime, mapEnabled, mapServer, mapLocation, spawnLocation, UKSurvey); } } \ No newline at end of file diff --git a/Plugin/src/main/resources/config.yml b/Plugin/src/main/resources/config.yml index 73a9e1d4..eb2351c4 100644 --- a/Plugin/src/main/resources/config.yml +++ b/Plugin/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Config version; do not update this manually as it could break the config. -version: 1.8.1 +version: 1.10.0 # MySQL is mandatory for this plugin. # Login information @@ -176,4 +176,7 @@ skulls_plugin_enabled: true minrank_generation: Jr.Builder minrank_regionclaim: Jr.Builder minrank_zonejoin: Jr.Builder -minrank_publicjoin: Jr.Builder \ No newline at end of file +minrank_publicjoin: Jr.Builder + +# Whether the UK Survey is enabled +UKSurvey_enabled: false \ No newline at end of file