Optimize and cleanup various classes
Reformatted several classes for optimization purposes. This includes removing unnecessary try-catch blocks, redundant initializers and imports, and condensing confirmation checks. Additionally, updated the `Database` class's `createUserPointsTable` and `createQuestLogTable` methods to use try-with-resources to ensure proper resource management.
This commit is contained in:
parent
c6b186e2c6
commit
3bb822b41c
|
|
@ -11,7 +11,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandManager implements CommandExecutor, TabExecutor {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
|
@ -67,7 +66,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getName)
|
||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||
.collect(Collectors.toList())
|
||||
.toList()
|
||||
);
|
||||
} else {
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class CommandProgress extends SubCommand {
|
|||
commandSender.sendMiniMessage(MessagesConfig.NO_CONSOLE, null);
|
||||
return true;
|
||||
}
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
if (!player.hasPlayedBefore()) {
|
||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class CommandSetQuest extends SubCommand {
|
|||
switch (args.length) {
|
||||
case 2 -> res.addAll(Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
case 3 -> res.addAll(Quest.getTypes());
|
||||
case 4 -> {
|
||||
switch (args[2].toLowerCase()) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class MessagesConfig extends AbstractConfig{
|
|||
RELOAD_HELP_MESSAGE = config.getString("help.reload", RELOAD_HELP_MESSAGE);
|
||||
SET_QUEST_HELP = config.getString("help.set-quest", SET_QUEST_HELP);
|
||||
CREATE_SCRUFF_MESSAGE = config.getString("help.help-wrapper", CREATE_SCRUFF_MESSAGE);
|
||||
RE_ROLL_HELP = config.getString("help.re-roll-help", RE_ROLL_HELP);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class QuestsConfig extends AbstractConfig {
|
|||
config.readConfig(QuestsConfig.class, null);
|
||||
}
|
||||
|
||||
public static List<MineQuestObject> MINE_QUESTS = new ArrayList<>();
|
||||
public static final List<MineQuestObject> MINE_QUESTS = new ArrayList<>();
|
||||
public static String MINE_QUEST_NAME = "<green>Mining</green>";
|
||||
public static String MINE_STEP_1 = "Mined";
|
||||
public static String MINE_STEP_2 = "Turned in";
|
||||
|
|
@ -77,7 +77,7 @@ public class QuestsConfig extends AbstractConfig {
|
|||
MINE_COMMANDS = config.getStringList("mining.commands", MINE_COMMANDS);
|
||||
}
|
||||
|
||||
public static List<KillMobsQuestObject> KILL_MOB_QUEST = new ArrayList<>();
|
||||
public static final List<KillMobsQuestObject> KILL_MOB_QUEST = new ArrayList<>();
|
||||
public static String KILL_MOB_QUEST_NAME = "<green>Kill mobs</green>";
|
||||
public static String KILL_MOB_STEP_1 = "Killed";
|
||||
public static String KILL_MOB_STEP_2 = "Confirmed";
|
||||
|
|
@ -116,7 +116,7 @@ public class QuestsConfig extends AbstractConfig {
|
|||
KILL_MOB_COMMANDS = config.getStringList("kill_mobs.commands", KILL_MOB_COMMANDS);
|
||||
}
|
||||
|
||||
public static List<CollectDropsQuestObject> COLLECT_DROPS_QUEST = new ArrayList<>();
|
||||
public static final List<CollectDropsQuestObject> COLLECT_DROPS_QUEST = new ArrayList<>();
|
||||
public static String COLLECT_DROPS_QUEST_NAME = "<green>Collect drops quest</green>";
|
||||
public static String COLLECT_DROPS_STEP_1 = "Obtained";
|
||||
public static String COLLECT_DROPS_STEP_2 = "Turned in";
|
||||
|
|
@ -155,7 +155,7 @@ public class QuestsConfig extends AbstractConfig {
|
|||
COLLECT_DROPS_COMMANDS = config.getStringList("collect_drops.commands", COLLECT_DROPS_COMMANDS);
|
||||
}
|
||||
|
||||
public static List<OtherQuestObject> OTHER_QUEST = new ArrayList<>();
|
||||
public static final List<OtherQuestObject> OTHER_QUEST = new ArrayList<>();
|
||||
public static String OTHER_QUEST_NAME = "<green>Other quest</green>";
|
||||
public static String OTHER_TURN_IN = "<gold>Click here to turn in your <item></gold>";
|
||||
public static List<String> OTHER_COMMANDS = List.of("broadcast <player> Finished their daily quest!");
|
||||
|
|
@ -203,7 +203,7 @@ public class QuestsConfig extends AbstractConfig {
|
|||
OTHER_COMMANDS = config.getStringList("other.commands", OTHER_COMMANDS);
|
||||
}
|
||||
|
||||
public static List<BreedMobsQuestObject> BREED_MOB_QUEST = new ArrayList<>();
|
||||
public static final List<BreedMobsQuestObject> BREED_MOB_QUEST = new ArrayList<>();
|
||||
public static String BREED_MOB_QUEST_NAME = "<green>Breed mobs quest</green>";
|
||||
public static String BREED_STEP_1 = "Bred";
|
||||
public static String BREED_STEP_2 = "Confirmed";
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Database {
|
||||
|
|
@ -88,7 +89,6 @@ public class Database {
|
|||
}
|
||||
|
||||
private static void createUserPointsTable() {
|
||||
try {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS generic_quest_progress(" +
|
||||
"year_day INT NOT NULL, " +
|
||||
"uuid VARCHAR(36) NOT NULL, " +
|
||||
|
|
@ -100,7 +100,8 @@ public class Database {
|
|||
"reward_received BIT(1) NOT NULL, " +
|
||||
"PRIMARY KEY (uuid)" +
|
||||
")";
|
||||
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
||||
try (PreparedStatement preparedStatement = getDatabase().getConnection().prepareStatement(sql)) {
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
Logger.throwing(Database.class.getName(), "createUserPointsTable", e);
|
||||
Logger.severe("Error while trying to create user point table");
|
||||
|
|
@ -110,7 +111,6 @@ public class Database {
|
|||
}
|
||||
|
||||
private static void createQuestLogTable() {
|
||||
try {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS quest_log(" +
|
||||
"uuid VARCHAR(36) NOT NULL, " +
|
||||
"year INT NOT NULL, " +
|
||||
|
|
@ -118,7 +118,8 @@ public class Database {
|
|||
"day INT NOT NULL, " +
|
||||
"PRIMARY KEY (uuid, year, month, day)" +
|
||||
")";
|
||||
getDatabase().getConnection().prepareStatement(sql).executeUpdate();
|
||||
try (PreparedStatement preparedStatement = getDatabase().getConnection().prepareStatement(sql)) {
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
Logger.throwing(Database.class.getName(), "createQuestLogTable", e);
|
||||
Logger.severe("Error while trying to create quest log table\nShutting down AltitudeQuests");
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@ public class DataLock implements Listener {
|
|||
return;
|
||||
new LoadUser(uuid).runTaskAsynchronously(AQuest.getInstance());
|
||||
}
|
||||
case QUEUE_LOCK_FAILED -> {
|
||||
Logger.warning("Unable to queue lock");
|
||||
}
|
||||
case QUEUE_LOCK_FAILED -> Logger.warning("Unable to queue lock");
|
||||
case TRY_UNLOCK_RESULT -> {
|
||||
if (event.getResult())
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.alttd.altitudequests.events;
|
||||
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.objects.quests.CollectDropsQuest;
|
||||
import com.alttd.altitudequests.objects.quests.OtherQuest;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -9,7 +8,6 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerBucketEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EntityBucketed implements Listener {
|
||||
|
||||
|
|
@ -20,10 +18,8 @@ public class EntityBucketed implements Listener {
|
|||
if (dailyQuest == null || dailyQuest.isDone())
|
||||
return;
|
||||
if (dailyQuest instanceof OtherQuest otherQuest) {
|
||||
ItemStack itemStack = event.getEntityBucket();
|
||||
Entity entity = event.getEntity();
|
||||
if (itemStack != null && entity != null)
|
||||
otherQuest.bucket(itemStack, entity);
|
||||
otherQuest.bucket(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,8 +99,7 @@ public abstract class Quest {
|
|||
|
||||
private int loadQuestsDoneThisMonth(UUID uuid) {
|
||||
String sql = "SELECT COUNT(uuid) AS total FROM quest_log WHERE uuid = ? AND year = ? AND month = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, uuid.toString());
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new Date());
|
||||
|
|
@ -116,7 +115,7 @@ public abstract class Quest {
|
|||
}
|
||||
|
||||
public static void createDailyQuest(Player player) {
|
||||
if (possibleQuests.size() == 0) {
|
||||
if (possibleQuests.isEmpty()) {
|
||||
player.sendMiniMessage("<red>Unable to create quest, no quests in config</red>", null);
|
||||
return;
|
||||
}
|
||||
|
|
@ -222,7 +221,7 @@ public abstract class Quest {
|
|||
|
||||
public abstract TagResolver getTagResolvers();
|
||||
|
||||
public abstract int turnIn(Player player);
|
||||
public abstract void turnIn(Player player);
|
||||
|
||||
public abstract Component getDisplayName();
|
||||
|
||||
|
|
@ -260,12 +259,11 @@ public abstract class Quest {
|
|||
}
|
||||
|
||||
private void saveDone() {
|
||||
try {
|
||||
String sql = "INSERT INTO quest_log " +
|
||||
"(uuid, year, month, day) " +
|
||||
"VALUES (?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE uuid = ?";
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
String uuidString = uuid.toString();
|
||||
|
|
|
|||
|
|
@ -27,13 +27,12 @@ public class BreedMobsQuest extends Quest {
|
|||
public BreedMobsQuest(Player player) throws Exception {
|
||||
super(player, 0, 0,
|
||||
QuestsConfig.BREED_MOB_QUEST.get(Utilities.randomOr0(QuestsConfig.BREED_MOB_QUEST.size() - 1)), -1, false);
|
||||
if (getVariant() instanceof BreedMobsQuestObject breedMobsQuestObject)
|
||||
this.breedMobsQuestObject = breedMobsQuestObject;
|
||||
if (getVariant() instanceof BreedMobsQuestObject questObject)
|
||||
this.breedMobsQuestObject = questObject;
|
||||
else
|
||||
this.breedMobsQuestObject = null;
|
||||
if (breedMobsQuestObject == null) {
|
||||
Logger.warning("Tried to create breedMobQuest but unable to find variant: %.", "unknown");
|
||||
return;
|
||||
if (this.breedMobsQuestObject == null) {
|
||||
Logger.warning("Tried to create breedMobQuest but unable to find variant: %s.", "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +40,8 @@ public class BreedMobsQuest extends Quest {
|
|||
super(player, step1, step2, QuestsConfig.BREED_MOB_QUEST.stream()
|
||||
.filter(object -> variant.equals(object.getInternalName()))
|
||||
.findAny().orElse(null), amount, rewardReceived);
|
||||
if (getVariant() instanceof BreedMobsQuestObject breedMobsQuestObject)
|
||||
this.breedMobsQuestObject = breedMobsQuestObject;
|
||||
if (getVariant() instanceof BreedMobsQuestObject questObject)
|
||||
this.breedMobsQuestObject = questObject;
|
||||
else
|
||||
this.breedMobsQuestObject = null;
|
||||
if (breedMobsQuestObject == null) {
|
||||
|
|
@ -60,8 +59,7 @@ public class BreedMobsQuest extends Quest {
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
int yearDay = Utilities.getYearDay();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||
|
|
@ -107,14 +105,13 @@ public class BreedMobsQuest extends Quest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int turnIn(Player player) {
|
||||
public void turnIn(Player player) {
|
||||
int maxToTurnIn = getMaxToTurnIn();
|
||||
|
||||
if (maxToTurnIn == 0)
|
||||
return 0;
|
||||
return;
|
||||
addStep2(maxToTurnIn);
|
||||
checkDone(player);
|
||||
return maxToTurnIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.sql.SQLException;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CollectDropsQuest extends Quest {
|
||||
|
|
@ -31,13 +30,12 @@ public class CollectDropsQuest extends Quest {
|
|||
public CollectDropsQuest(Player player) throws Exception {
|
||||
super(player, 0, 0,
|
||||
QuestsConfig.COLLECT_DROPS_QUEST.get(Utilities.randomOr0(QuestsConfig.COLLECT_DROPS_QUEST.size() - 1)), -1, false);
|
||||
if (getVariant() instanceof CollectDropsQuestObject collectDropsQuestObject)
|
||||
this.collectDropsQuestObject = collectDropsQuestObject;
|
||||
if (getVariant() instanceof CollectDropsQuestObject questObject)
|
||||
this.collectDropsQuestObject = questObject;
|
||||
else
|
||||
this.collectDropsQuestObject = null;
|
||||
if (collectDropsQuestObject == null) {
|
||||
Logger.warning("Tried to create collectDropsQuest but unable to find variant: %.", "unknown");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +43,8 @@ public class CollectDropsQuest extends Quest {
|
|||
super(player, step1, step2, QuestsConfig.COLLECT_DROPS_QUEST.stream()
|
||||
.filter(object -> variant.equals(object.getInternalName()))
|
||||
.findAny().orElse(null), amount, rewardReceived);
|
||||
if (getVariant() instanceof CollectDropsQuestObject collectDropsQuestObject)
|
||||
this.collectDropsQuestObject = collectDropsQuestObject;
|
||||
if (getVariant() instanceof CollectDropsQuestObject questObject)
|
||||
this.collectDropsQuestObject = questObject;
|
||||
else
|
||||
this.collectDropsQuestObject = null;
|
||||
if (collectDropsQuestObject == null) {
|
||||
|
|
@ -64,8 +62,7 @@ public class CollectDropsQuest extends Quest {
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
int yearDay = Utilities.getYearDay();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||
|
|
@ -112,12 +109,12 @@ public class CollectDropsQuest extends Quest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int turnIn(Player player) {
|
||||
public void turnIn(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int maxToTurnIn = getMaxToTurnIn();
|
||||
|
||||
if (maxToTurnIn == 0)
|
||||
return 0;
|
||||
return;
|
||||
var ref = new Object() {
|
||||
int tmpAmount = maxToTurnIn;
|
||||
};
|
||||
|
|
@ -139,7 +136,6 @@ public class CollectDropsQuest extends Quest {
|
|||
int totalTurnedIn = maxToTurnIn - ref.tmpAmount;
|
||||
addStep2(totalTurnedIn);
|
||||
checkDone(player);
|
||||
return totalTurnedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import org.bukkit.entity.Player;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class KillMobsQuest extends Quest {
|
||||
|
|
@ -28,13 +27,12 @@ public class KillMobsQuest extends Quest {
|
|||
public KillMobsQuest(Player player) throws Exception {
|
||||
super(player, 0, 0,
|
||||
QuestsConfig.KILL_MOB_QUEST.get(Utilities.randomOr0(QuestsConfig.KILL_MOB_QUEST.size() - 1)), -1, false);
|
||||
if (getVariant() instanceof KillMobsQuestObject killMobsQuestObject)
|
||||
this.killMobsQuestObject = killMobsQuestObject;
|
||||
if (getVariant() instanceof KillMobsQuestObject questObject)
|
||||
this.killMobsQuestObject = questObject;
|
||||
else
|
||||
this.killMobsQuestObject = null;
|
||||
if (killMobsQuestObject == null) {
|
||||
Logger.warning("Tried to create killMobsQuest but unable to find variant: %.", "unknown");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,8 +40,8 @@ public class KillMobsQuest extends Quest {
|
|||
super(player, step1, step2, QuestsConfig.KILL_MOB_QUEST.stream()
|
||||
.filter(object -> variant.equals(object.getInternalName()))
|
||||
.findAny().orElse(null), amount, rewardReceived);
|
||||
if (getVariant() instanceof KillMobsQuestObject killMobsQuestObject)
|
||||
this.killMobsQuestObject = killMobsQuestObject;
|
||||
if (getVariant() instanceof KillMobsQuestObject questObject)
|
||||
this.killMobsQuestObject = questObject;
|
||||
else
|
||||
this.killMobsQuestObject = null;
|
||||
if (killMobsQuestObject == null) {
|
||||
|
|
@ -61,8 +59,7 @@ public class KillMobsQuest extends Quest {
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
int yearDay = Utilities.getYearDay();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||
|
|
@ -108,14 +105,13 @@ public class KillMobsQuest extends Quest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int turnIn(Player player) {
|
||||
public void turnIn(Player player) {
|
||||
int maxToTurnIn = getMaxToTurnIn();
|
||||
|
||||
if (maxToTurnIn == 0)
|
||||
return 0;
|
||||
return;
|
||||
addStep2(maxToTurnIn);
|
||||
checkDone(player);
|
||||
return maxToTurnIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,13 +30,12 @@ public class MineQuest extends Quest {
|
|||
public MineQuest(Player player) throws Exception {
|
||||
super(player, 0, 0,
|
||||
QuestsConfig.MINE_QUESTS.get(Utilities.randomOr0(QuestsConfig.MINE_QUESTS.size() - 1)), -1, false);
|
||||
if (getVariant() instanceof MineQuestObject mineQuestObject)
|
||||
this.mineQuestObject = mineQuestObject;
|
||||
if (getVariant() instanceof MineQuestObject questObject)
|
||||
this.mineQuestObject = questObject;
|
||||
else
|
||||
mineQuestObject = null;
|
||||
if (mineQuestObject == null) {
|
||||
Logger.warning("Tried to create MineQuest but unable to find variant: %.", "unknown");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +44,8 @@ public class MineQuest extends Quest {
|
|||
.filter(object -> variant.equals(object.getInternalName()))
|
||||
.findAny().orElse(null), amount,
|
||||
rewardReceived);
|
||||
if (getVariant() instanceof MineQuestObject mineQuestObject)
|
||||
this.mineQuestObject = mineQuestObject;
|
||||
if (getVariant() instanceof MineQuestObject questObject)
|
||||
this.mineQuestObject = questObject;
|
||||
else
|
||||
this.mineQuestObject = null;
|
||||
if (mineQuestObject == null) {
|
||||
|
|
@ -64,8 +63,7 @@ public class MineQuest extends Quest {
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
int yearDay = Utilities.getYearDay();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||
|
|
@ -111,12 +109,12 @@ public class MineQuest extends Quest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int turnIn(Player player) {
|
||||
public void turnIn(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int maxToTurnIn = getMaxToTurnIn();
|
||||
|
||||
if (maxToTurnIn == 0)
|
||||
return 0;
|
||||
return;
|
||||
var ref = new Object() {
|
||||
int tmpAmount = maxToTurnIn;
|
||||
};
|
||||
|
|
@ -138,7 +136,6 @@ public class MineQuest extends Quest {
|
|||
int totalTurnedIn = maxToTurnIn - ref.tmpAmount;
|
||||
addStep2(totalTurnedIn);
|
||||
checkDone(player);
|
||||
return totalTurnedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -158,11 +155,8 @@ public class MineQuest extends Quest {
|
|||
if (!block.getType().equals(mineQuestObject.getMaterial())) {
|
||||
return true;
|
||||
}
|
||||
else if (blockData instanceof Ageable) {
|
||||
Ageable ageable = (Ageable) blockData;
|
||||
if (ageable.getAge() != ageable.getMaximumAge()) {
|
||||
return true;
|
||||
}
|
||||
else if (blockData instanceof Ageable ageable) {
|
||||
return ageable.getAge() != ageable.getMaximumAge();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ public class OtherQuest extends Quest {
|
|||
public OtherQuest(Player player) throws Exception {
|
||||
super(player, 0, 0,
|
||||
QuestsConfig.OTHER_QUEST.get(Utilities.randomOr0(QuestsConfig.OTHER_QUEST.size() - 1)), -1, false);
|
||||
if (getVariant() instanceof OtherQuestObject otherQuestObject)
|
||||
this.otherQuestObject = otherQuestObject;
|
||||
if (getVariant() instanceof OtherQuestObject questObject)
|
||||
this.otherQuestObject = questObject;
|
||||
else
|
||||
this.otherQuestObject = null;
|
||||
if (otherQuestObject == null) {
|
||||
|
|
@ -47,8 +47,8 @@ public class OtherQuest extends Quest {
|
|||
super(player, step1, step2, QuestsConfig.OTHER_QUEST.stream()
|
||||
.filter(object -> variant.equals(object.getInternalName()))
|
||||
.findAny().orElse(null), amount, rewardReceived);
|
||||
if (getVariant() instanceof OtherQuestObject otherQuestObject)
|
||||
this.otherQuestObject = otherQuestObject;
|
||||
if (getVariant() instanceof OtherQuestObject questObject)
|
||||
this.otherQuestObject = questObject;
|
||||
else
|
||||
this.otherQuestObject = null;
|
||||
if (otherQuestObject == null) {
|
||||
|
|
@ -66,8 +66,7 @@ public class OtherQuest extends Quest {
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"quest = ?, quest_variant = ?, step_1_progress = ?, step_2_progress = ?, year_day = ?, amount = ?, reward_received = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
int yearDay = Utilities.getYearDay();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Saving user for year day %.", String.valueOf(yearDay));
|
||||
|
|
@ -114,12 +113,12 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int turnIn(Player player) {
|
||||
public void turnIn(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int maxToTurnIn = getMaxToTurnIn();
|
||||
|
||||
if (maxToTurnIn == 0)
|
||||
return 0;
|
||||
return;
|
||||
var ref = new Object() {
|
||||
int tmpAmount = maxToTurnIn;
|
||||
};
|
||||
|
|
@ -141,7 +140,6 @@ public class OtherQuest extends Quest {
|
|||
int totalTurnedIn = maxToTurnIn - ref.tmpAmount;
|
||||
addStep2(totalTurnedIn);
|
||||
checkDone(player);
|
||||
return totalTurnedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -176,7 +174,7 @@ public class OtherQuest extends Quest {
|
|||
checkDone();
|
||||
}
|
||||
|
||||
public void bucket(ItemStack bucket, Entity entity) {
|
||||
public void bucket(Entity entity) {
|
||||
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()|| !otherQuestObject.getCategory().equalsIgnoreCase("BUCKETING")) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||
|
||||
public class LoadUser extends BukkitRunnable {
|
||||
|
||||
UUID uuid;
|
||||
private final UUID uuid;
|
||||
|
||||
public LoadUser(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
|
|
@ -22,8 +22,7 @@ public class LoadUser extends BukkitRunnable {
|
|||
@Override
|
||||
public void run() {
|
||||
String sql = "SELECT * FROM generic_quest_progress WHERE uuid = ?";
|
||||
try {
|
||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||
try (PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql)) {
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next() && resultSet.getInt("year_day") == Utilities.getYearDay()) {
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ public class ProgressBookOpener {
|
|||
TagResolver.resolver(Placeholder.component("variant", dailyQuest.getVariant().getName())),
|
||||
dailyQuest.getTagResolvers()
|
||||
);
|
||||
List<String> pages = new ArrayList<>();
|
||||
pages.addAll(Config.PROGRESS_PAGES);
|
||||
List<String> pages = new ArrayList<>(Config.PROGRESS_PAGES);
|
||||
return (pages.stream()
|
||||
.map(page -> miniMessage.deserialize(page, tagResolver))
|
||||
.collect(Collectors.toList()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user