From 222313083e30a261b8d5af877a931cedce4796c0 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Wed, 8 Sep 2021 03:17:38 -0400 Subject: [PATCH] Improve code syntax, part 5 --- .../blackvein/quests/events/QuestsEvent.java | 3 +- .../conditions/ConditionsEditorEvent.java | 9 +- ...tionsEditorPostOpenNumericPromptEvent.java | 3 +- ...itionsEditorPostOpenStringPromptEvent.java | 3 +- .../editor/quests/QuestsEditorEvent.java | 9 +- ...uestsEditorPostOpenNumericPromptEvent.java | 3 +- ...QuestsEditorPostOpenStringPromptEvent.java | 3 +- .../quests/events/misc/MiscEditorEvent.java | 3 +- .../misc/MiscPostNpcOfferQuestEvent.java | 3 +- .../events/misc/MiscPostQuestAcceptEvent.java | 3 +- .../quests/events/quest/QuestEvent.java | 3 +- .../quests/events/quest/QuestQuitEvent.java | 3 +- .../quests/events/quest/QuestTakeEvent.java | 3 +- .../events/quest/QuestUpdateCompassEvent.java | 3 +- .../quests/events/quester/QuesterEvent.java | 3 +- .../quester/QuesterPostChangeStageEvent.java | 3 +- .../QuesterPostCompleteQuestEvent.java | 3 +- .../quester/QuesterPostFailQuestEvent.java | 3 +- .../quester/QuesterPostStartQuestEvent.java | 3 +- .../QuesterPostUpdateObjectiveEvent.java | 3 +- .../quester/QuesterPreChangeStageEvent.java | 3 +- .../quester/QuesterPreCompleteQuestEvent.java | 3 +- .../quester/QuesterPreFailQuestEvent.java | 3 +- .../quester/QuesterPreOpenGUIEvent.java | 12 +- .../quester/QuesterPreStartQuestEvent.java | 3 +- .../QuesterPreUpdateObjectiveEvent.java | 3 +- .../quests/interfaces/ReloadCallback.java | 2 +- .../blackvein/quests/item/QuestJournal.java | 111 +++--- .../quests/listeners/BlockListener.java | 16 +- .../quests/listeners/CmdExecutor.java | 287 +++++++-------- .../quests/listeners/ItemListener.java | 23 +- .../quests/listeners/NpcListener.java | 31 +- .../quests/listeners/PlayerListener.java | 332 +++++++++--------- .../quests/listeners/UniteListener.java | 4 +- .../quests/particle/ParticleProvider.java | 8 +- .../particle/ParticleProvider_Bukkit.java | 8 +- .../quests/particle/PreBuiltParticle.java | 9 +- .../quests/reflect/denizen/DenizenAPI.java | 34 +- .../reflect/denizen/DenizenAPI_1_0_9.java | 44 ++- .../reflect/denizen/DenizenAPI_1_1_0.java | 44 +-- .../reflect/denizen/DenizenAPI_1_1_1.java | 20 +- .../reflect/worldguard/WorldGuardAPI.java | 26 +- .../worldguard/WorldGuardAPI_7_0_0.java | 26 +- .../blackvein/quests/statistics/Metrics.java | 23 +- .../me/blackvein/quests/storage/Storage.java | 9 +- .../quests/storage/StorageFactory.java | 15 +- .../file/SeparatedYamlStorage.java | 39 +- .../quests/tasks/NpcEffectThread.java | 13 +- .../me/blackvein/quests/util/ConfigUtil.java | 38 +- .../quests/util/FakeConversable.java | 32 +- .../blackvein/quests/util/InventoryUtil.java | 38 +- .../me/blackvein/quests/util/ItemUtil.java | 231 +++++------- .../java/me/blackvein/quests/util/Lang.java | 25 +- .../me/blackvein/quests/util/MiscUtil.java | 38 +- .../blackvein/quests/util/RomanNumeral.java | 4 +- 55 files changed, 758 insertions(+), 871 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/events/QuestsEvent.java b/main/src/main/java/me/blackvein/quests/events/QuestsEvent.java index 513796899..9e535b008 100644 --- a/main/src/main/java/me/blackvein/quests/events/QuestsEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/QuestsEvent.java @@ -14,6 +14,7 @@ package me.blackvein.quests.events; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; public abstract class QuestsEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -26,7 +27,7 @@ public abstract class QuestsEvent extends Event { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorEvent.java index dadfcc826..58e0c9f18 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorEvent.java @@ -19,6 +19,9 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quests; import me.blackvein.quests.conditions.ConditionFactory; import me.blackvein.quests.events.QuestsEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; /** * Represents an Conditions Editor-related event @@ -31,14 +34,14 @@ public abstract class ConditionsEditorEvent extends QuestsEvent { public ConditionsEditorEvent(final ConversationContext context, final Prompt prompt) { this.context = context; - this.factory = ((Quests)context.getPlugin()).getConditionFactory(); + this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getConditionFactory(); this.prompt = prompt; } public ConditionsEditorEvent(final ConversationContext context, final Prompt prompt, final boolean async) { super(async); this.context = context; - this.factory = ((Quests)context.getPlugin()).getConditionFactory(); + this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getConditionFactory(); this.prompt = prompt; } @@ -70,7 +73,7 @@ public abstract class ConditionsEditorEvent extends QuestsEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenNumericPromptEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenNumericPromptEvent.java index 25411e3b4..827ecb5d1 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenNumericPromptEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenNumericPromptEvent.java @@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext; import org.bukkit.event.HandlerList; import me.blackvein.quests.convo.conditions.ConditionsEditorNumericPrompt; +import org.jetbrains.annotations.NotNull; public class ConditionsEditorPostOpenNumericPromptEvent extends ConditionsEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,7 +39,7 @@ public class ConditionsEditorPostOpenNumericPromptEvent extends ConditionsEditor } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenStringPromptEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenStringPromptEvent.java index 25b646abb..373243860 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenStringPromptEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/conditions/ConditionsEditorPostOpenStringPromptEvent.java @@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext; import org.bukkit.event.HandlerList; import me.blackvein.quests.convo.conditions.ConditionsEditorStringPrompt; +import org.jetbrains.annotations.NotNull; public class ConditionsEditorPostOpenStringPromptEvent extends ConditionsEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,7 +39,7 @@ public class ConditionsEditorPostOpenStringPromptEvent extends ConditionsEditorE } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorEvent.java index 8eedde573..6352b2496 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorEvent.java @@ -19,6 +19,9 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.QuestFactory; import me.blackvein.quests.Quests; import me.blackvein.quests.events.QuestsEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; /** * Represents a Quests Editor-related event @@ -31,14 +34,14 @@ public abstract class QuestsEditorEvent extends QuestsEvent { public QuestsEditorEvent(final ConversationContext context, final Prompt prompt) { this.context = context; - this.factory = ((Quests)context.getPlugin()).getQuestFactory(); + this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getQuestFactory(); this.prompt = prompt; } public QuestsEditorEvent(final ConversationContext context, final Prompt prompt, final boolean async) { super(async); this.context = context; - this.factory = ((Quests)context.getPlugin()).getQuestFactory(); + this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getQuestFactory(); this.prompt = prompt; } @@ -70,7 +73,7 @@ public abstract class QuestsEditorEvent extends QuestsEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenNumericPromptEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenNumericPromptEvent.java index 834ef3165..049e0513b 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenNumericPromptEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenNumericPromptEvent.java @@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext; import org.bukkit.event.HandlerList; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import org.jetbrains.annotations.NotNull; public class QuestsEditorPostOpenNumericPromptEvent extends QuestsEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,7 +39,7 @@ public class QuestsEditorPostOpenNumericPromptEvent extends QuestsEditorEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenStringPromptEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenStringPromptEvent.java index 83cd08155..de757a3eb 100644 --- a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenStringPromptEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenStringPromptEvent.java @@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext; import org.bukkit.event.HandlerList; import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; +import org.jetbrains.annotations.NotNull; public class QuestsEditorPostOpenStringPromptEvent extends QuestsEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,7 +39,7 @@ public class QuestsEditorPostOpenStringPromptEvent extends QuestsEditorEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/misc/MiscEditorEvent.java b/main/src/main/java/me/blackvein/quests/events/misc/MiscEditorEvent.java index be65900d1..bfd46010c 100644 --- a/main/src/main/java/me/blackvein/quests/events/misc/MiscEditorEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/misc/MiscEditorEvent.java @@ -16,6 +16,7 @@ import me.blackvein.quests.events.QuestsEvent; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; /** * Represents a miscellaneous editor-related event @@ -55,7 +56,7 @@ public class MiscEditorEvent extends QuestsEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/misc/MiscPostNpcOfferQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/misc/MiscPostNpcOfferQuestEvent.java index a774483ed..de6a64358 100644 --- a/main/src/main/java/me/blackvein/quests/events/misc/MiscPostNpcOfferQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/misc/MiscPostNpcOfferQuestEvent.java @@ -15,6 +15,7 @@ package me.blackvein.quests.events.misc; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; public class MiscPostNpcOfferQuestEvent extends MiscEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -45,7 +46,7 @@ public class MiscPostNpcOfferQuestEvent extends MiscEditorEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/misc/MiscPostQuestAcceptEvent.java b/main/src/main/java/me/blackvein/quests/events/misc/MiscPostQuestAcceptEvent.java index fd1e8fdd9..f43bfbd2a 100644 --- a/main/src/main/java/me/blackvein/quests/events/misc/MiscPostQuestAcceptEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/misc/MiscPostQuestAcceptEvent.java @@ -15,6 +15,7 @@ package me.blackvein.quests.events.misc; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; public class MiscPostQuestAcceptEvent extends MiscEditorEvent { private static final HandlerList HANDLERS = new HandlerList(); @@ -45,7 +46,7 @@ public class MiscPostQuestAcceptEvent extends MiscEditorEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quest/QuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quest/QuestEvent.java index fce84d591..9ba6805d8 100644 --- a/main/src/main/java/me/blackvein/quests/events/quest/QuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quest/QuestEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.events.QuestsEvent; +import org.jetbrains.annotations.NotNull; /** * Represents a quest-related event @@ -43,7 +44,7 @@ public abstract class QuestEvent extends QuestsEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quest/QuestQuitEvent.java b/main/src/main/java/me/blackvein/quests/events/quest/QuestQuitEvent.java index 06427d071..ff08e0594 100644 --- a/main/src/main/java/me/blackvein/quests/events/quest/QuestQuitEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quest/QuestQuitEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called when a quest is quit by a quester @@ -51,7 +52,7 @@ public class QuestQuitEvent extends QuestEvent implements Cancellable { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quest/QuestTakeEvent.java b/main/src/main/java/me/blackvein/quests/events/quest/QuestTakeEvent.java index ff15ce4dc..bd5380044 100644 --- a/main/src/main/java/me/blackvein/quests/events/quest/QuestTakeEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quest/QuestTakeEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called when a quest is taken by a quester @@ -51,7 +52,7 @@ public class QuestTakeEvent extends QuestEvent implements Cancellable { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quest/QuestUpdateCompassEvent.java b/main/src/main/java/me/blackvein/quests/events/quest/QuestUpdateCompassEvent.java index 068d65e17..15510c5c5 100644 --- a/main/src/main/java/me/blackvein/quests/events/quest/QuestUpdateCompassEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quest/QuestUpdateCompassEvent.java @@ -18,6 +18,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called when a quest has its compass target updated for a quester @@ -63,7 +64,7 @@ public class QuestUpdateCompassEvent extends QuestEvent implements Cancellable { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterEvent.java index 3600c28c2..3a39110e3 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quester; import me.blackvein.quests.events.QuestsEvent; +import org.jetbrains.annotations.NotNull; /** * Represents a quester-related event @@ -44,7 +45,7 @@ public abstract class QuesterEvent extends QuestsEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java index ddfb38a1f..b474b34df 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostChangeStageEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; import me.blackvein.quests.Stage; +import org.jetbrains.annotations.NotNull; /** * Called after an online quester changes stage @@ -52,7 +53,7 @@ public class QuesterPostChangeStageEvent extends QuesterEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java index f00d7e644..6ce71cd5c 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostCompleteQuestEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called after an online quester completes a quest @@ -39,7 +40,7 @@ public class QuesterPostCompleteQuestEvent extends QuesterEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java index 3fad3fedf..1de5625b9 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostFailQuestEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called after a quester fails a quest @@ -39,7 +40,7 @@ public class QuesterPostFailQuestEvent extends QuesterEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java index 7ecb114cc..7d5979bb4 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostStartQuestEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called after an online quester starts a quest @@ -39,7 +40,7 @@ public class QuesterPostStartQuestEvent extends QuesterEvent { } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostUpdateObjectiveEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostUpdateObjectiveEvent.java index 64970bd57..3ea107f5b 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostUpdateObjectiveEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPostUpdateObjectiveEvent.java @@ -18,6 +18,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Objective; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called after a quester progresses an objective @@ -63,7 +64,7 @@ public class QuesterPostUpdateObjectiveEvent extends QuesterEvent implements Can } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java index 5f6ad8d9c..5c96158b7 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreChangeStageEvent.java @@ -18,6 +18,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; import me.blackvein.quests.Stage; +import org.jetbrains.annotations.NotNull; /** * Called before an online quester changes stage @@ -64,7 +65,7 @@ public class QuesterPreChangeStageEvent extends QuesterEvent implements Cancella } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java index 96641596c..2877da33a 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreCompleteQuestEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called before an online quester completes a quest @@ -56,7 +57,7 @@ public class QuesterPreCompleteQuestEvent extends QuesterEvent implements Cancel } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java index 15a18907f..c9ed780c5 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreFailQuestEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called before a quester fails a quest @@ -51,7 +52,7 @@ public class QuesterPreFailQuestEvent extends QuesterEvent implements Cancellabl } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java index bc994e136..4c4494a9d 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java @@ -12,14 +12,14 @@ package me.blackvein.quests.events.quester; -import java.util.LinkedList; - -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; - import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; import net.citizensnpcs.api.npc.NPC; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedList; /** * Called before a quester opens a quest selection GUI @@ -65,7 +65,7 @@ public class QuesterPreOpenGUIEvent extends QuesterEvent implements Cancellable } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java index 95ed9a627..4f370a6f1 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreStartQuestEvent.java @@ -17,6 +17,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called before a quester starts a quest @@ -51,7 +52,7 @@ public class QuesterPreStartQuestEvent extends QuesterEvent implements Cancellab } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreUpdateObjectiveEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreUpdateObjectiveEvent.java index 7d1e21256..4caad8be4 100644 --- a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreUpdateObjectiveEvent.java +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreUpdateObjectiveEvent.java @@ -18,6 +18,7 @@ import org.bukkit.event.HandlerList; import me.blackvein.quests.Objective; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; +import org.jetbrains.annotations.NotNull; /** * Called before a quester progresses an objective @@ -63,7 +64,7 @@ public class QuesterPreUpdateObjectiveEvent extends QuesterEvent implements Canc } @Override - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { return HANDLERS; } diff --git a/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java b/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java index 36979997f..f24bfa3be 100644 --- a/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java +++ b/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java @@ -13,5 +13,5 @@ package me.blackvein.quests.interfaces; public interface ReloadCallback { - public void execute(T response); + void execute(T response); } diff --git a/main/src/main/java/me/blackvein/quests/item/QuestJournal.java b/main/src/main/java/me/blackvein/quests/item/QuestJournal.java index c44b6b60d..310a5d71b 100644 --- a/main/src/main/java/me/blackvein/quests/item/QuestJournal.java +++ b/main/src/main/java/me/blackvein/quests/item/QuestJournal.java @@ -12,19 +12,18 @@ package me.blackvein.quests.item; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - +import me.blackvein.quests.Quest; +import me.blackvein.quests.Quester; +import me.blackvein.quests.util.Lang; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import me.blackvein.quests.Quest; -import me.blackvein.quests.Quester; -import me.blackvein.quests.util.Lang; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; public class QuestJournal { @@ -34,59 +33,61 @@ public class QuestJournal { public QuestJournal(final Quester owner) { this.owner = owner; final BookMeta book = (BookMeta) journal.getItemMeta(); - final Player player = owner.getPlayer(); - final String title = Lang.get(player, "journalTitle"); - book.setDisplayName(ChatColor.LIGHT_PURPLE + title); - book.setTitle(ChatColor.LIGHT_PURPLE + title); - book.setAuthor(player.getName()); - if (owner.getCurrentQuests().isEmpty()) { - book.addPage(ChatColor.DARK_RED + Lang.get(player, "journalNoQuests").replace("", title)); - } else { - int currentLength = 0; - int currentLines = 0; - String page = ""; - final List sortedList = owner.getCurrentQuests().keySet().stream() - .sorted(Comparator.comparing(Quest::getName)) - .collect(Collectors.toList()); - for (final Quest quest : sortedList) { - if ((currentLength + quest.getName().length() > 240) || (currentLines - + ((quest.getName().length() % 19) == 0 ? (quest.getName().length() / 19) - : ((quest.getName().length() / 19) + 1))) > 13) { - book.addPage(page); - page += ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + quest.getName() + "\n"; - currentLength = quest.getName().length(); - currentLines = (quest.getName().length() % 19) == 0 ? (quest.getName().length() / 19) - : (quest.getName().length() + 1); - } else { - page += ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + quest.getName() + "\n"; - currentLength += quest.getName().length(); - currentLines += (quest.getName().length() / 19); - } - if (owner.getCurrentObjectives(quest, false) != null) { - for (final String obj : owner.getCurrentObjectives(quest, false)) { - // Length/Line check - if ((currentLength + obj.length() > 240) || (currentLines + ((obj.length() % 19) - == 0 ? (obj.length() / 19) : ((obj.length() / 19) + 1))) > 13) { - book.addPage(page); - page = obj + "\n"; - currentLength = obj.length(); - currentLines = (obj.length() % 19) == 0 ? (obj.length() / 19) : (obj.length() + 1); - } else { - page += obj + "\n"; - currentLength += obj.length(); - currentLines += (obj.length() / 19); + if (book != null) { + final Player player = owner.getPlayer(); + final String title = Lang.get(player, "journalTitle"); + book.setDisplayName(ChatColor.LIGHT_PURPLE + title); + book.setTitle(ChatColor.LIGHT_PURPLE + title); + book.setAuthor(player.getName()); + if (owner.getCurrentQuests().isEmpty()) { + book.addPage(ChatColor.DARK_RED + Lang.get(player, "journalNoQuests").replace("", title)); + } else { + int currentLength = 0; + int currentLines = 0; + StringBuilder page = new StringBuilder(); + final List sortedList = owner.getCurrentQuests().keySet().stream() + .sorted(Comparator.comparing(Quest::getName)) + .collect(Collectors.toList()); + for (final Quest quest : sortedList) { + if ((currentLength + quest.getName().length() > 240) || (currentLines + + ((quest.getName().length() % 19) == 0 ? (quest.getName().length() / 19) + : ((quest.getName().length() / 19) + 1))) > 13) { + book.addPage(page.toString()); + page.append(ChatColor.DARK_PURPLE).append(ChatColor.BOLD).append(quest.getName()).append("\n"); + currentLength = quest.getName().length(); + currentLines = (quest.getName().length() % 19) == 0 ? (quest.getName().length() / 19) + : (quest.getName().length() + 1); + } else { + page.append(ChatColor.DARK_PURPLE).append(ChatColor.BOLD).append(quest.getName()).append("\n"); + currentLength += quest.getName().length(); + currentLines += (quest.getName().length() / 19); + } + if (owner.getCurrentObjectives(quest, false) != null) { + for (final String obj : owner.getCurrentObjectives(quest, false)) { + // Length/Line check + if ((currentLength + obj.length() > 240) || (currentLines + ((obj.length() % 19) + == 0 ? (obj.length() / 19) : ((obj.length() / 19) + 1))) > 13) { + book.addPage(page.toString()); + page = new StringBuilder(obj + "\n"); + currentLength = obj.length(); + currentLines = (obj.length() % 19) == 0 ? (obj.length() / 19) : (obj.length() + 1); + } else { + page.append(obj).append("\n"); + currentLength += obj.length(); + currentLines += (obj.length() / 19); + } } } + if (currentLines < 13) + page.append("\n"); + book.addPage(page.toString()); + page = new StringBuilder(); + currentLines = 0; + currentLength = 0; } - if (currentLines < 13) - page += "\n"; - book.addPage(page); - page = ""; - currentLines = 0; - currentLength = 0; } + journal.setItemMeta(book); } - journal.setItemMeta(book); } public Quester getOwner() { diff --git a/main/src/main/java/me/blackvein/quests/listeners/BlockListener.java b/main/src/main/java/me/blackvein/quests/listeners/BlockListener.java index 6c21b6649..be9eb170c 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/BlockListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/BlockListener.java @@ -59,9 +59,9 @@ public class BlockListener implements Listener { final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK; final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK; final ObjectiveType cutType = ObjectiveType.CUT_BLOCK; - final Set dispatchedBreakQuestIDs = new HashSet(); - final Set dispatchedPlaceQuestIDs = new HashSet(); - final Set dispatchedCutQuestIDs = new HashSet(); + final Set dispatchedBreakQuestIDs = new HashSet<>(); + final Set dispatchedPlaceQuestIDs = new HashSet<>(); + final Set dispatchedCutQuestIDs = new HashSet<>(); for (final Quest quest : plugin.getLoadedQuests()) { if (!evt.isCancelled()) { if (!quester.meetsCondition(quest, true)) { @@ -179,7 +179,7 @@ public class BlockListener implements Listener { .getData().toItemStack().getDurability()); final Quester quester = plugin.getQuester(player.getUniqueId()); final ObjectiveType type = ObjectiveType.DAMAGE_BLOCK; - final Set dispatchedQuestIDs = new HashSet(); + final Set dispatchedQuestIDs = new HashSet<>(); for (final Quest quest : plugin.getLoadedQuests()) { if (!quester.meetsCondition(quest, true)) { continue; @@ -210,9 +210,9 @@ public class BlockListener implements Listener { .getData().toItemStack().getDurability()); final Quester quester = plugin.getQuester(player.getUniqueId()); final ObjectiveType type = ObjectiveType.PLACE_BLOCK; - final Set dispatchedQuestIDs = new HashSet(); + final Set dispatchedQuestIDs = new HashSet<>(); for (final Quest quest : plugin.getLoadedQuests()) { - if (evt.isCancelled() == false) { + if (!evt.isCancelled()) { if (!quester.meetsCondition(quest, true)) { continue; } @@ -251,11 +251,11 @@ public class BlockListener implements Listener { return; } if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { - if (!evt.isCancelled()) { + if (!evt.isCancelled() && evt.getClickedBlock() != null) { final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt .getClickedBlock().getState().getData().toItemStack().getDurability()); final ObjectiveType type = ObjectiveType.USE_BLOCK; - final Set dispatchedQuestIDs = new HashSet(); + final Set dispatchedQuestIDs = new HashSet<>(); for (final Quest quest : plugin.getLoadedQuests()) { if (!quester.meetsCondition(quest, true)) { continue; diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index e4acd6122..29f875afa 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -42,13 +42,11 @@ import org.bukkit.conversations.Conversation; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -59,8 +57,8 @@ import java.util.concurrent.ConcurrentSkipListSet; public class CmdExecutor implements CommandExecutor { private final Quests plugin; - private final Map commands = new HashMap(); - private final Map adminCommands = new HashMap(); + private final Map commands = new HashMap<>(); + private final Map adminCommands = new HashMap<>(); public CmdExecutor(final Quests plugin) { this.plugin = plugin; @@ -68,7 +66,8 @@ public class CmdExecutor implements CommandExecutor { } @Override - public boolean onCommand(final CommandSender cs, final Command cmd, final String label, final String[] args) { + public boolean onCommand(final @NotNull CommandSender cs, final @NotNull Command cmd, + final @NotNull String label, final String[] args) { if (plugin.isLoading()) { cs.sendMessage(ChatColor.RED + Lang.get("errorLoading")); return true; @@ -194,7 +193,7 @@ public class CmdExecutor implements CommandExecutor { private boolean questCommandHandler(final CommandSender cs, final String[] args) { if (cs instanceof Player) { - if (((Player) cs).hasPermission("quests.quest")) { + if (cs.hasPermission("quests.quest")) { if (args.length == 0) { final Player player = (Player) cs; final Quester quester = plugin.getQuester(player.getUniqueId()); @@ -330,36 +329,27 @@ public class CmdExecutor implements CommandExecutor { } public void showQuestDetails(final CommandSender cs, final String[] args) { - if (((Player) cs).hasPermission("quests.questinfo")) { - String name = ""; + if (cs.hasPermission("quests.questinfo")) { + StringBuilder name = new StringBuilder(); if (args.length == 1) { - name = args[0].toLowerCase(); + name = new StringBuilder(args[0].toLowerCase()); } else { int index = 0; for (final String s : args) { if (index == (args.length - 1)) { - name = name + s.toLowerCase(); + name.append(s.toLowerCase()); } else { - name = name + s.toLowerCase() + " "; + name.append(s.toLowerCase()).append(" "); } index++; } } - final Quest q = plugin.getQuest(name); + final Quest q = plugin.getQuest(name.toString()); if (q != null) { final Player player = (Player) cs; final Quester quester = plugin.getQuester(player.getUniqueId()); cs.sendMessage(ChatColor.GOLD + "- " + q.getName() + " -"); cs.sendMessage(" "); - /*if (q.redoDelay > -1) { - if (q.redoDelay == 0) { - cs.sendMessage(ChatColor.DARK_AQUA + Lang.get("readoable")); - } else { - String msg = Lang.get("redoableEvery"); - msg = msg.replace("