mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 10:36:09 +01:00
Improve code syntax, part 5
This commit is contained in:
parent
2383bafc98
commit
222313083e
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -13,5 +13,5 @@
|
||||
package me.blackvein.quests.interfaces;
|
||||
|
||||
public interface ReloadCallback<T> {
|
||||
public void execute(T response);
|
||||
void execute(T response);
|
||||
}
|
||||
|
@ -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("<journal>", title));
|
||||
} else {
|
||||
int currentLength = 0;
|
||||
int currentLines = 0;
|
||||
String page = "";
|
||||
final List<Quest> 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("<journal>", title));
|
||||
} else {
|
||||
int currentLength = 0;
|
||||
int currentLines = 0;
|
||||
StringBuilder page = new StringBuilder();
|
||||
final List<Quest> 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() {
|
||||
|
@ -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<String> dispatchedBreakQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedPlaceQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedCutQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedBreakQuestIDs = new HashSet<>();
|
||||
final Set<String> dispatchedPlaceQuestIDs = new HashSet<>();
|
||||
final Set<String> 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<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> 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<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> 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<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
|
@ -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<String, Integer> commands = new HashMap<String, Integer>();
|
||||
private final Map<String, Integer> adminCommands = new HashMap<String, Integer>();
|
||||
private final Map<String, Integer> commands = new HashMap<>();
|
||||
private final Map<String, Integer> 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("<time>", ChatColor.AQUA + getTime(q.redoDelay) + ChatColor.DARK_AQUA);
|
||||
cs.sendMessage(ChatColor.DARK_AQUA + msg);
|
||||
}
|
||||
}*/
|
||||
if (q.getNpcStart() != null) {
|
||||
String msg = Lang.get("speakTo");
|
||||
msg = msg.replace("<npc>", q.getNpcStart().getName());
|
||||
@ -368,10 +358,10 @@ public class CmdExecutor implements CommandExecutor {
|
||||
cs.sendMessage(ChatColor.YELLOW + q.getDescription());
|
||||
}
|
||||
cs.sendMessage(" ");
|
||||
if (plugin.getSettings().canShowQuestReqs() == true) {
|
||||
if (plugin.getSettings().canShowQuestReqs()) {
|
||||
cs.sendMessage(ChatColor.GOLD + Lang.get("requirements"));
|
||||
final Requirements reqs = q.getRequirements();
|
||||
if (reqs.getPermissions().isEmpty() == false) {
|
||||
if (!reqs.getPermissions().isEmpty()) {
|
||||
for (final String perm : reqs.getPermissions()) {
|
||||
if (plugin.getDependencies().getVaultPermission().has(player, perm)) {
|
||||
cs.sendMessage(ChatColor.GREEN + Lang.get("permissionDisplay") + " " + perm);
|
||||
@ -400,7 +390,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
|
||||
}
|
||||
}
|
||||
if (reqs.getMcmmoSkills().isEmpty() == false) {
|
||||
if (!reqs.getMcmmoSkills().isEmpty()) {
|
||||
for (final String skill : reqs.getMcmmoSkills()) {
|
||||
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
|
||||
.getMcMMOSkill(skill), player.getName());
|
||||
@ -442,16 +432,16 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reqs.getItems().isEmpty() == false) {
|
||||
if (!reqs.getItems().isEmpty()) {
|
||||
for (final ItemStack is : reqs.getItems()) {
|
||||
if (plugin.getQuester(player.getUniqueId()).hasItem(is) == true) {
|
||||
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reqs.getNeededQuests().isEmpty() == false) {
|
||||
if (!reqs.getNeededQuests().isEmpty()) {
|
||||
for (final Quest quest : reqs.getNeededQuests()) {
|
||||
if (quester.getCompletedQuests().contains(quest)) {
|
||||
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
|
||||
@ -462,7 +452,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reqs.getBlockQuests().isEmpty() == false) {
|
||||
if (!reqs.getBlockQuests().isEmpty()) {
|
||||
for (final Quest quest : reqs.getBlockQuests()) {
|
||||
if (quester.getCompletedQuests().contains(quest)) {
|
||||
String msg = Lang.get("haveCompleted");
|
||||
@ -559,7 +549,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
if (args.length > 2) {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_TOP_USAGE"));
|
||||
} else {
|
||||
int topNumber;
|
||||
final int topNumber;
|
||||
if (args.length == 1) {
|
||||
topNumber = 5; // default
|
||||
} else {
|
||||
@ -575,41 +565,36 @@ public class CmdExecutor implements CommandExecutor {
|
||||
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
|
||||
return true;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final File folder = new File(plugin.getDataFolder(), "data");
|
||||
final File[] playerFiles = folder.listFiles();
|
||||
final Map<String, Integer> questPoints = new HashMap<String, Integer>();
|
||||
if (playerFiles != null) {
|
||||
for (final File f : playerFiles) {
|
||||
if (!f.isDirectory()) {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
try {
|
||||
data.load(f);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
questPoints.put(data.getString("lastKnownName", "Unknown"),
|
||||
data.getInt("quest-points", 0));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
final File folder = new File(plugin.getDataFolder(), "data");
|
||||
final File[] playerFiles = folder.listFiles();
|
||||
final Map<String, Integer> questPoints = new HashMap<>();
|
||||
if (playerFiles != null) {
|
||||
for (final File f : playerFiles) {
|
||||
if (!f.isDirectory()) {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
try {
|
||||
data.load(f);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
questPoints.put(data.getString("lastKnownName", "Unknown"),
|
||||
data.getInt("quest-points", 0));
|
||||
}
|
||||
}
|
||||
final LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
|
||||
int numPrinted = 0;
|
||||
String msg = Lang.get("topQuestersTitle");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
for (final Entry<String, Integer> entry : sortedMap.entrySet()) {
|
||||
numPrinted++;
|
||||
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
|
||||
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
|
||||
+ Lang.get("questPoints"));
|
||||
if (numPrinted == topNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
final LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
|
||||
int numPrinted = 0;
|
||||
String msg = Lang.get("topQuestersTitle");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
for (final Entry<String, Integer> entry : sortedMap.entrySet()) {
|
||||
numPrinted++;
|
||||
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
|
||||
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
|
||||
+ Lang.get("questPoints"));
|
||||
if (numPrinted == topNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -657,10 +642,10 @@ public class CmdExecutor implements CommandExecutor {
|
||||
final StringBuilder completed = new StringBuilder(" ");
|
||||
int index = 1;
|
||||
for (final Quest q : quester.getCompletedQuests()) {
|
||||
|
||||
completed.append(ChatColor.DARK_PURPLE + q.getName());
|
||||
completed.append(ChatColor.DARK_PURPLE).append(q.getName());
|
||||
if (quester.getAmountsCompleted().containsKey(q) && quester.getAmountsCompleted().get(q) > 1) {
|
||||
completed.append(ChatColor.LIGHT_PURPLE + " (x" + quester.getAmountsCompleted().get(q) + ")");
|
||||
completed.append(ChatColor.LIGHT_PURPLE).append(" (x").append(quester.getAmountsCompleted()
|
||||
.get(q)).append(")");
|
||||
}
|
||||
if (index < (quester.getCompletedQuests().size())) {
|
||||
completed.append(", ");
|
||||
@ -688,12 +673,11 @@ public class CmdExecutor implements CommandExecutor {
|
||||
inv.setItem(index, null);
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalPutAway")
|
||||
.replace("<journal>", Lang.get(player, "journalTitle")));
|
||||
} else if (player.getItemInHand() == null || player.getItemInHand().getType().equals(Material.AIR)) {
|
||||
} else if (player.getItemInHand().getType().equals(Material.AIR)) {
|
||||
final QuestJournal journal = new QuestJournal(quester);
|
||||
player.setItemInHand(journal.toItemStack());
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalTaken")
|
||||
.replace("<journal>", Lang.get(player, "journalTitle")));
|
||||
//quester.updateJournal();
|
||||
} else if (inv.firstEmpty() != -1) {
|
||||
final ItemStack[] arr = inv.getContents();
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
@ -702,7 +686,6 @@ public class CmdExecutor implements CommandExecutor {
|
||||
inv.setItem(i, journal.toItemStack());
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalTaken")
|
||||
.replace("<journal>", Lang.get(player, "journalTitle")));
|
||||
//quester.updateJournal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -761,7 +744,6 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//quester.setQuestToTake(questToFind);
|
||||
quester.offerQuest(questToFind, true);
|
||||
} else {
|
||||
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questNotFound"));
|
||||
@ -797,12 +779,11 @@ public class CmdExecutor implements CommandExecutor {
|
||||
|
||||
plugin.listQuests(quester, 1);
|
||||
} else if (args.length == 2) {
|
||||
int page = 1;
|
||||
final int page;
|
||||
try {
|
||||
page = Integer.parseInt(args[1]);
|
||||
if (page < 1) {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("pageSelectionPosNum"));
|
||||
return;
|
||||
} else {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final QuestsCommandPreQuestsListEvent preEvent = new QuestsCommandPreQuestsListEvent(quester, page);
|
||||
@ -815,7 +796,6 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("pageSelectionNum"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -926,18 +906,15 @@ public class CmdExecutor implements CommandExecutor {
|
||||
|
||||
private void adminReload(final CommandSender cs) {
|
||||
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.reload")) {
|
||||
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
|
||||
@Override
|
||||
public void execute(final Boolean response) {
|
||||
if (response) {
|
||||
cs.sendMessage(ChatColor.GOLD + Lang.get("questsReloaded"));
|
||||
String msg = Lang.get("numQuestsLoaded");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + String.valueOf(plugin.getLoadedQuests().size())
|
||||
+ ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("unknownError"));
|
||||
}
|
||||
final ReloadCallback<Boolean> callback = response -> {
|
||||
if (response) {
|
||||
cs.sendMessage(ChatColor.GOLD + Lang.get("questsReloaded"));
|
||||
String msg = Lang.get("numQuestsLoaded");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + String.valueOf(plugin.getLoadedQuests().size())
|
||||
+ ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("unknownError"));
|
||||
}
|
||||
};
|
||||
plugin.reload(callback);
|
||||
@ -957,7 +934,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int points;
|
||||
final int points;
|
||||
try {
|
||||
points = Integer.parseInt(args[2]);
|
||||
} catch (final NumberFormatException e) {
|
||||
@ -994,7 +971,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int points;
|
||||
final int points;
|
||||
try {
|
||||
points = Integer.parseInt(args[2]);
|
||||
} catch (final NumberFormatException e) {
|
||||
@ -1031,7 +1008,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int points;
|
||||
final int points;
|
||||
try {
|
||||
points = Integer.parseInt(args[2]);
|
||||
} catch (final NumberFormatException e) {
|
||||
@ -1068,21 +1045,21 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Quest questToGive;
|
||||
String name = "";
|
||||
final Quest questToGive;
|
||||
StringBuilder name = new StringBuilder();
|
||||
if (args.length == 3) {
|
||||
name = args[2].toLowerCase();
|
||||
name = new StringBuilder(args[2].toLowerCase());
|
||||
} else {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
final int lastIndex = args.length - 1;
|
||||
if (i == lastIndex) {
|
||||
name = name + args[i].toLowerCase();
|
||||
name.append(args[i].toLowerCase());
|
||||
} else {
|
||||
name = name + args[i].toLowerCase() + " ";
|
||||
name.append(args[i].toLowerCase()).append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
questToGive = plugin.getQuest(name);
|
||||
questToGive = plugin.getQuest(name.toString());
|
||||
if (questToGive == null) {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("questNotFound"));
|
||||
} else {
|
||||
@ -1135,55 +1112,40 @@ public class CmdExecutor implements CommandExecutor {
|
||||
for (final Quester q : plugin.getOfflineQuesters()) {
|
||||
q.setQuestPoints(amount);
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final File questerFolder = new File(plugin.getDataFolder(), "data");
|
||||
if (questerFolder.exists() && questerFolder.isDirectory()) {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
final File[] files = questerFolder.listFiles();
|
||||
int failCount = 0;
|
||||
boolean suppressed = false;
|
||||
if (files != null) {
|
||||
for (final File f : files) {
|
||||
try {
|
||||
data.load(f);
|
||||
data.set("quest-points", amount);
|
||||
data.save(f);
|
||||
} catch (final IOException e) {
|
||||
if (failCount < 10) {
|
||||
String msg = Lang.get("errorReading");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
failCount++;
|
||||
} else if (suppressed == false) {
|
||||
String msg = Lang.get("errorReadingSuppress");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
suppressed = true;
|
||||
}
|
||||
} catch (final InvalidConfigurationException e) {
|
||||
if (failCount < 10) {
|
||||
String msg = Lang.get("errorReading");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
failCount++;
|
||||
} else if (suppressed == false) {
|
||||
String msg = Lang.get("errorReadingSuppress");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
suppressed = true;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
final File questerFolder = new File(plugin.getDataFolder(), "data");
|
||||
if (questerFolder.exists() && questerFolder.isDirectory()) {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
final File[] files = questerFolder.listFiles();
|
||||
int failCount = 0;
|
||||
boolean suppressed = false;
|
||||
if (files != null) {
|
||||
for (final File f : files) {
|
||||
try {
|
||||
data.load(f);
|
||||
data.set("quest-points", amount);
|
||||
data.save(f);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
if (failCount < 10) {
|
||||
String msg = Lang.get("errorReading");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
failCount++;
|
||||
} else if (!suppressed) {
|
||||
String msg = Lang.get("errorReadingSuppress");
|
||||
msg = msg.replace("<file>", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED);
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
suppressed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
cs.sendMessage(ChatColor.GREEN + Lang.get("done"));
|
||||
String msg = Lang.get("allQuestPointsSet").replace("<points>", Lang.get("questPoints"));
|
||||
msg = msg.replace("<number>", ChatColor.AQUA + "" + amount + ChatColor.GOLD);
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW + "" + ChatColor.GOLD + msg);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("errorDataFolder"));
|
||||
}
|
||||
cs.sendMessage(ChatColor.GREEN + Lang.get("done"));
|
||||
String msg = Lang.get("allQuestPointsSet").replace("<points>", Lang.get("questPoints"));
|
||||
msg = msg.replace("<number>", ChatColor.AQUA + "" + amount + ChatColor.GOLD);
|
||||
plugin.getServer().broadcastMessage(ChatColor.YELLOW + "" + ChatColor.GOLD + msg);
|
||||
} else {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("errorDataFolder"));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@ -1203,7 +1165,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
final Quester quester = plugin.getQuester(target.getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty()) {
|
||||
if (quester.getCurrentQuests().isEmpty() && target.getName() != null) {
|
||||
String msg = Lang.get("noCurrentQuest");
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
@ -1255,7 +1217,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
final Quester quester = plugin.getQuester(target.getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty()) {
|
||||
if (quester.getCurrentQuests().isEmpty() && target.getName() != null) {
|
||||
String msg = Lang.get("noCurrentQuest");
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
@ -1291,7 +1253,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
final Quester quester = plugin.getQuester(target.getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty()) {
|
||||
if (quester.getCurrentQuests().isEmpty() && target.getName() != null) {
|
||||
String msg = Lang.get("noCurrentQuest");
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
@ -1332,7 +1294,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
final Quester quester = plugin.getQuester(target.getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty()) {
|
||||
if (quester.getCurrentQuests().isEmpty() && target.getName() != null) {
|
||||
String msg = Lang.get("noCurrentQuest");
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
@ -1369,11 +1331,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
final UUID id = target.getUniqueId();
|
||||
final ConcurrentSkipListSet<Quester> temp = (ConcurrentSkipListSet<Quester>) plugin.getOfflineQuesters();
|
||||
for (final Iterator<Quester> itr = temp.iterator(); itr.hasNext();) {
|
||||
if (itr.next().getUUID().equals(id)) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
temp.removeIf(quester -> quester.getUUID().equals(id));
|
||||
plugin.setOfflineQuesters(temp);
|
||||
Quester quester = plugin.getQuester(id);
|
||||
try {
|
||||
@ -1391,7 +1349,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
cs.sendMessage(ChatColor.DARK_PURPLE + " UUID: " + ChatColor.DARK_AQUA + id);
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().info("Data file does not exist for " + id.toString());
|
||||
plugin.getLogger().info("Data file does not exist for " + id);
|
||||
}
|
||||
quester = new Quester(plugin, id);
|
||||
quester.saveData();
|
||||
@ -1532,23 +1490,13 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
|
||||
private static Map<String, Integer> sort(final Map<String, Integer> unsortedMap) {
|
||||
final List<Entry<String, Integer>> list = new LinkedList<Entry<String, Integer>>(unsortedMap.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<String, Integer>>() {
|
||||
|
||||
@Override
|
||||
public int compare(final Entry<String, Integer> o1, final Entry<String, Integer> o2) {
|
||||
final int i = o1.getValue();
|
||||
final int i2 = o2.getValue();
|
||||
if (i < i2) {
|
||||
return 1;
|
||||
} else if (i == i2) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
final List<Entry<String, Integer>> list = new LinkedList<>(unsortedMap.entrySet());
|
||||
list.sort((o1, o2) -> {
|
||||
final int i = o1.getValue();
|
||||
final int i2 = o2.getValue();
|
||||
return Integer.compare(i2, i);
|
||||
});
|
||||
final Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
|
||||
final Map<String, Integer> sortedMap = new LinkedHashMap<>();
|
||||
for (final Entry<String, Integer> entry : list) {
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@ -1564,13 +1512,14 @@ public class CmdExecutor implements CommandExecutor {
|
||||
* @param delimiter the character for which the array was split
|
||||
* @return a String or null
|
||||
*/
|
||||
private static String concatArgArray(final String[] args, final int startingIndex, final int endingIndex, final char delimiter) {
|
||||
String s = "";
|
||||
private static String concatArgArray(final String[] args, final int startingIndex, final int endingIndex,
|
||||
final char delimiter) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = startingIndex; i <= endingIndex; i++) {
|
||||
s += args[i] + delimiter;
|
||||
s.append(args[i]).append(delimiter);
|
||||
}
|
||||
s = s.substring(0, s.length());
|
||||
return s.trim().equals("") ? null : s.trim();
|
||||
s = new StringBuilder(s.substring(0, s.length()));
|
||||
return s.toString().trim().equals("") ? null : s.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,9 +12,10 @@
|
||||
|
||||
package me.blackvein.quests.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.enums.ObjectiveType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -28,10 +29,8 @@ import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.enums.ObjectiveType;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemListener implements Listener {
|
||||
|
||||
@ -52,7 +51,7 @@ public class ItemListener implements Listener {
|
||||
final ItemStack craftedItem = getCraftedItem(evt);
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.CRAFT_ITEM;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -103,7 +102,7 @@ public class ItemListener implements Listener {
|
||||
if (evt.getSlotType() == SlotType.RESULT) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.SMELT_ITEM;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -126,7 +125,7 @@ public class ItemListener implements Listener {
|
||||
if (evt.getSlotType() == SlotType.CRAFTING) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.BREW_ITEM;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -161,7 +160,7 @@ public class ItemListener implements Listener {
|
||||
}
|
||||
final Quester quester = plugin.getQuester(evt.getEnchanter().getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.ENCHANT_ITEM;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -190,7 +189,7 @@ public class ItemListener implements Listener {
|
||||
consumedItem.setAmount(1);
|
||||
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.CONSUME_ITEM;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
|
@ -62,16 +62,15 @@ public class NpcListener implements Listener {
|
||||
+ Lang.get("id") + ": " + evt.getNPC().getId());
|
||||
return;
|
||||
}
|
||||
if (evt.getClicker().isConversing() == false) {
|
||||
if (!evt.getClicker().isConversing()) {
|
||||
final Player player = evt.getClicker();
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
boolean delivery = false;
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)
|
||||
&& player.getItemInHand() != null) {
|
||||
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.DELIVER_ITEM)) {
|
||||
player.getItemInHand();
|
||||
final ItemStack hand = player.getItemInHand();
|
||||
int currentIndex = -1;
|
||||
final LinkedList<Integer> matches = new LinkedList<Integer>();
|
||||
final LinkedList<Integer> matches = new LinkedList<>();
|
||||
int reasonCode = 0;
|
||||
for (final ItemStack is : quester.getCurrentStage(quest).getItemsToDeliver()) {
|
||||
currentIndex++;
|
||||
@ -86,7 +85,6 @@ public class NpcListener implements Listener {
|
||||
final Integer id = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match);
|
||||
if (id.equals(clicked.getId())) {
|
||||
quester.deliverToNPC(quest, clicked, hand);
|
||||
delivery = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -94,19 +92,19 @@ public class NpcListener implements Listener {
|
||||
for (final Integer n : quester.getCurrentStage(quest).getItemDeliveryTargets()) {
|
||||
if (n.equals(clicked.getId())) {
|
||||
String text = "";
|
||||
final boolean hasMeta = hand.hasItemMeta();
|
||||
final boolean hasMeta = hand.getItemMeta() != null;
|
||||
if (hasMeta) {
|
||||
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC
|
||||
+ (hand.getItemMeta().hasDisplayName() ? hand.getItemMeta().getDisplayName()
|
||||
+ ChatColor.GRAY + " (" : "");
|
||||
}
|
||||
text += ChatColor.AQUA + "<item>" + (hand.getDurability() != 0 ? (":" + ChatColor.BLUE
|
||||
text += ChatColor.AQUA + "<item>" + (hand.getDurability() != 0 ? (":" + ChatColor.BLUE
|
||||
+ hand.getDurability()) : "") + ChatColor.GRAY;
|
||||
if (hasMeta) {
|
||||
text += (hand.getItemMeta().hasDisplayName() ? ")" : "");
|
||||
}
|
||||
text += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.GRAY;
|
||||
if (plugin.getSettings().canTranslateNames() && !hasMeta
|
||||
if (plugin.getSettings().canTranslateNames() && !hasMeta
|
||||
&& !hand.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleManager().sendMessage(player, Lang
|
||||
.get(player, "questInvalidDeliveryItem").replace("<item>", text), hand
|
||||
@ -166,14 +164,13 @@ public class NpcListener implements Listener {
|
||||
}
|
||||
if (hasMeta) {
|
||||
if (hand.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
final EnchantmentStorageMeta esmeta = (EnchantmentStorageMeta) hand.getItemMeta();
|
||||
if (esmeta.hasStoredEnchants()) {
|
||||
for (final Entry<Enchantment, Integer> e : esmeta.getStoredEnchants()
|
||||
final EnchantmentStorageMeta esMeta = (EnchantmentStorageMeta) hand.getItemMeta();
|
||||
if (esMeta.hasStoredEnchants()) {
|
||||
for (final Entry<Enchantment, Integer> e : esMeta.getStoredEnchants()
|
||||
.entrySet()) {
|
||||
final HashMap<Enchantment, Integer> single
|
||||
= new HashMap<Enchantment, Integer>();
|
||||
final HashMap<Enchantment, Integer> single = new HashMap<>();
|
||||
single.put(e.getKey(), e.getValue());
|
||||
plugin.getLocaleManager().sendMessage(player, ChatColor.GRAY + "\u2515 "
|
||||
plugin.getLocaleManager().sendMessage(player, ChatColor.GRAY + "\u2515 "
|
||||
+ ChatColor.DARK_GREEN + "<enchantment> <level>\n", single);
|
||||
}
|
||||
}
|
||||
@ -200,7 +197,7 @@ public class NpcListener implements Listener {
|
||||
}
|
||||
if (!hasObjective) {
|
||||
boolean hasAtLeastOneGUI = false;
|
||||
final LinkedList<Quest> npcQuests = new LinkedList<Quest>();
|
||||
final LinkedList<Quest> npcQuests = new LinkedList<>();
|
||||
for (final Quest q : plugin.getLoadedQuests()) {
|
||||
if (quester.getCurrentQuests().containsKey(q))
|
||||
continue;
|
||||
@ -284,7 +281,7 @@ public class NpcListener implements Listener {
|
||||
return;
|
||||
}
|
||||
final ObjectiveType type = ObjectiveType.KILL_NPC;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
Player player = null;
|
||||
if (damager instanceof Projectile
|
||||
&& evt.getNPC().getEntity().getLastDamageCause().getEntity() instanceof Player) {
|
||||
|
@ -235,10 +235,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedBlockStarts();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getQuestFactory().setSelectedBlockStarts(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation")
|
||||
+ " " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation")
|
||||
+ " " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getActionFactory().getSelectedExplosionLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -250,10 +252,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedExplosionLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getActionFactory().setSelectedExplosionLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getActionFactory().getSelectedEffectLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -265,10 +269,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedEffectLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getActionFactory().setSelectedEffectLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getActionFactory().getSelectedMobLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -280,10 +286,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedMobLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getActionFactory().setSelectedMobLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getActionFactory().getSelectedLightningLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -295,10 +303,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedLightningLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getActionFactory().setSelectedLightningLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getActionFactory().getSelectedTeleportLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -310,10 +320,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedTeleportLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getActionFactory().setSelectedTeleportLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getQuestFactory().getSelectedKillLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -325,10 +337,12 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedKillLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getQuestFactory().setSelectedKillLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY()
|
||||
+ ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (plugin.getQuestFactory().getSelectedReachLocations().containsKey(evt.getPlayer()
|
||||
.getUniqueId())) {
|
||||
@ -340,14 +354,16 @@ public class PlayerListener implements Listener {
|
||||
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedReachLocations();
|
||||
temp.put(player.getUniqueId(), block);
|
||||
plugin.getQuestFactory().setSelectedReachLocations(temp);
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", "
|
||||
+ loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
if (loc.getWorld() != null) {
|
||||
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
|
||||
+ ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", "
|
||||
+ loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN
|
||||
+ ItemUtil.getName(new ItemStack(block.getType())) + ChatColor.GOLD + ")");
|
||||
}
|
||||
evt.setCancelled(true);
|
||||
} else if (!player.isConversing()) {
|
||||
for (final Quest q : plugin.getLoadedQuests()) {
|
||||
if (q.getBlockStart() != null) {
|
||||
if (q.getBlockStart() != null && evt.getClickedBlock() != null) {
|
||||
if (q.getBlockStart().equals(evt.getClickedBlock().getLocation())) {
|
||||
if (quester.getCurrentQuests().size() >= plugin.getSettings().getMaxQuests()
|
||||
&& plugin.getSettings().getMaxQuests() > 0) {
|
||||
@ -429,12 +445,12 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerBucketFill(final PlayerBucketFillEvent evt) {
|
||||
if (evt.getItemStack().getType() == Material.MILK_BUCKET) {
|
||||
if (evt.getItemStack() != null && evt.getItemStack().getType() == Material.MILK_BUCKET) {
|
||||
final Player player = evt.getPlayer();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.MILK_COW;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -486,7 +502,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
final ObjectiveType type = ObjectiveType.PASSWORD;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
if (quester.getCurrentStage(quest).containsObjective(type)) {
|
||||
for (final String pass : quester.getCurrentStage(quest).getPasswordPhrases()) {
|
||||
if (pass.equalsIgnoreCase(evt.getMessage())) {
|
||||
@ -554,7 +570,7 @@ public class PlayerListener implements Listener {
|
||||
final Sheep sheep = (Sheep) evt.getEntity();
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.SHEAR_SHEEP;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -584,7 +600,7 @@ public class PlayerListener implements Listener {
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.TAME_MOB;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -612,30 +628,28 @@ public class PlayerListener implements Listener {
|
||||
if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
|
||||
final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause();
|
||||
final Entity damager = damageEvent.getDamager();
|
||||
|
||||
if (damager != null) {
|
||||
if (damager instanceof Projectile) {
|
||||
final Projectile projectile = (Projectile) damager;
|
||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
|
||||
preKillMob((Entity)projectile.getShooter(), evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof TNTPrimed) {
|
||||
final TNTPrimed tnt = (TNTPrimed) damager;
|
||||
final Entity source = tnt.getSource();
|
||||
if (source != null && source.isValid()) {
|
||||
preKillMob(source, evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof Wolf) {
|
||||
final Wolf wolf = (Wolf) damager;
|
||||
if (wolf.isTamed() && wolf.getOwner() != null) {
|
||||
final Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
|
||||
if (quester != null) {
|
||||
preKillPlayer(quester.getPlayer(), evt.getEntity());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
preKillMob(damager, evt.getEntity());
|
||||
|
||||
if (damager instanceof Projectile) {
|
||||
final Projectile projectile = (Projectile) damager;
|
||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
|
||||
preKillMob((Entity)projectile.getShooter(), evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof TNTPrimed) {
|
||||
final TNTPrimed tnt = (TNTPrimed) damager;
|
||||
final Entity source = tnt.getSource();
|
||||
if (source != null && source.isValid()) {
|
||||
preKillMob(source, evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof Wolf) {
|
||||
final Wolf wolf = (Wolf) damager;
|
||||
if (wolf.isTamed() && wolf.getOwner() != null) {
|
||||
final Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
|
||||
if (quester != null) {
|
||||
preKillPlayer(quester.getPlayer(), evt.getEntity());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
preKillMob(damager, evt.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -657,7 +671,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
final Quester quester = plugin.getQuester(damager.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.KILL_MOB;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -685,33 +699,30 @@ public class PlayerListener implements Listener {
|
||||
final EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause();
|
||||
final Entity damager = damageEvent.getDamager();
|
||||
|
||||
if (damager != null) {
|
||||
//Ignore suicide
|
||||
if (evt.getEntity().getUniqueId().equals(damager.getUniqueId())) {
|
||||
return;
|
||||
if (evt.getEntity().getUniqueId().equals(damager.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
if (damager instanceof Projectile) {
|
||||
final Projectile projectile = (Projectile) damager;
|
||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
|
||||
preKillPlayer((Entity)projectile.getShooter(), evt.getEntity());
|
||||
}
|
||||
if (damager instanceof Projectile) {
|
||||
final Projectile projectile = (Projectile) damager;
|
||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Entity) {
|
||||
preKillPlayer((Entity)projectile.getShooter(), evt.getEntity());
|
||||
} else if (damager instanceof TNTPrimed) {
|
||||
final TNTPrimed tnt = (TNTPrimed) damager;
|
||||
final Entity source = tnt.getSource();
|
||||
if (source != null) {
|
||||
if (source.isValid()) {
|
||||
preKillPlayer(source, evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof TNTPrimed) {
|
||||
final TNTPrimed tnt = (TNTPrimed) damager;
|
||||
final Entity source = tnt.getSource();
|
||||
if (source != null) {
|
||||
if (source.isValid()) {
|
||||
preKillPlayer(source, evt.getEntity());
|
||||
}
|
||||
}
|
||||
} else if (damager instanceof Wolf) {
|
||||
final Wolf wolf = (Wolf) damager;
|
||||
if (wolf.isTamed()) {
|
||||
final Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
|
||||
preKillPlayer(quester.getPlayer(), evt.getEntity());
|
||||
}
|
||||
} else {
|
||||
preKillPlayer(damager, evt.getEntity());
|
||||
}
|
||||
} else if (damager instanceof Wolf) {
|
||||
final Wolf wolf = (Wolf) damager;
|
||||
if (wolf.isTamed() && wolf.getOwner() != null) {
|
||||
final Quester quester = plugin.getQuester(wolf.getOwner().getUniqueId());
|
||||
preKillPlayer(quester.getPlayer(), evt.getEntity());
|
||||
}
|
||||
} else {
|
||||
preKillPlayer(damager, evt.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@ -762,7 +773,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
final Quester quester = plugin.getQuester(damager.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.KILL_PLAYER;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -790,7 +801,7 @@ public class PlayerListener implements Listener {
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final ObjectiveType type = ObjectiveType.CATCH_FISH;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
@ -821,9 +832,7 @@ public class PlayerListener implements Listener {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
quester.findCompassTarget();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
}
|
||||
quester.meetsCondition(quest, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -833,13 +842,7 @@ public class PlayerListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
quester.findCompassTarget();
|
||||
}
|
||||
}, 10);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, quester::findCompassTarget, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -851,45 +854,38 @@ public class PlayerListener implements Listener {
|
||||
noobCheck.saveData();
|
||||
}
|
||||
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final CompletableFuture<Quester> cf = plugin.getStorage().loadQuester(evt.getPlayer().getUniqueId());
|
||||
try {
|
||||
final Quester quester = cf.get();
|
||||
if (quester == null) {
|
||||
return;
|
||||
}
|
||||
for (final Quest q : quester.getCompletedQuests()) {
|
||||
if (q != null) {
|
||||
if (!quester.getCompletedTimes().containsKey(q) && q.getPlanner().getCooldown() > -1) {
|
||||
quester.getCompletedTimes().put(q, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
quester.checkQuest(quest);
|
||||
}
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
if (quester.getCurrentStage(quest).getDelay() > -1 /*&& !quester.getQuestData(quest).isDelayOver()*/) {
|
||||
quester.startStageTimer(quest);
|
||||
}
|
||||
}
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (quester.hasJournal()) {
|
||||
quester.updateJournal();
|
||||
}
|
||||
if (quester.canUseCompass()) {
|
||||
quester.resetCompass();
|
||||
}
|
||||
}
|
||||
}, 40L);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
final CompletableFuture<Quester> cf = plugin.getStorage().loadQuester(evt.getPlayer().getUniqueId());
|
||||
try {
|
||||
final Quester quester = cf.get();
|
||||
if (quester == null) {
|
||||
return;
|
||||
}
|
||||
for (final Quest q : quester.getCompletedQuests()) {
|
||||
if (q != null) {
|
||||
if (!quester.getCompletedTimes().containsKey(q) && q.getPlanner().getCooldown() > -1) {
|
||||
quester.getCompletedTimes().put(q, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
quester.checkQuest(quest);
|
||||
}
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
if (quester.getCurrentStage(quest).getDelay() > -1) {
|
||||
quester.startStageTimer(quest);
|
||||
}
|
||||
}
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
if (quester.hasJournal()) {
|
||||
quester.updateJournal();
|
||||
}
|
||||
if (quester.canUseCompass()) {
|
||||
quester.resetCompass();
|
||||
}
|
||||
}, 40L);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -965,45 +961,33 @@ public class PlayerListener implements Listener {
|
||||
* @since 3.8.2
|
||||
*/
|
||||
public void playerMove(final UUID uuid, final Location location) {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Quester quester = plugin.getQuester(uuid);
|
||||
if (quester != null) {
|
||||
if (plugin.canUseQuests(uuid)) {
|
||||
final ObjectiveType type = ObjectiveType.REACH_LOCATION;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quester.getCurrentQuests().containsKey(quest)) {
|
||||
if (quester.getCurrentStage(quest) != null
|
||||
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
quester.reachLocation(quest, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
||||
(final Quester q, final Quest cq) -> {
|
||||
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
q.reachLocation(cq, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
final Quester quester = plugin.getQuester(uuid);
|
||||
if (quester != null) {
|
||||
if (plugin.canUseQuests(uuid)) {
|
||||
final ObjectiveType type = ObjectiveType.REACH_LOCATION;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||
for (final Quest quest : plugin.getLoadedQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quester.getCurrentQuests().containsKey(quest)) {
|
||||
if (quester.getCurrentStage(quest) != null
|
||||
&& quester.getCurrentStage(quest).containsObjective(type)) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> quester
|
||||
.reachLocation(quest, location));
|
||||
}
|
||||
}
|
||||
|
||||
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
|
||||
(final Quester q, final Quest cq) -> {
|
||||
if (!dispatchedQuestIDs.contains(cq.getId())) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> q
|
||||
.reachLocation(cq, location));
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class UniteListener implements Listener {
|
||||
if (p != null && Lang.get("questPartiesLeave").length() > 0) {
|
||||
Lang.send(p, ChatColor.GREEN + Lang.get(p, "questPartiesJoin"));
|
||||
if (Lang.get("questPartiesJoinBroadcast").length() > 0) {
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
for (final Player online : Bukkit.getOnlinePlayers()) {
|
||||
if (event.getPlayer().equals(online.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public class UniteListener implements Listener {
|
||||
if (p != null && Lang.get("questPartiesLeave").length() > 0) {
|
||||
Lang.send(p, ChatColor.RED + Lang.get(p, "questPartiesLeave"));
|
||||
if (Lang.get("questPartiesLeaveBroadcast").length() > 0) {
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
for (final Player online : Bukkit.getOnlinePlayers()) {
|
||||
if (event.getPlayer().equals(online.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
|
@ -12,13 +12,13 @@
|
||||
|
||||
package me.blackvein.quests.particle;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ParticleProvider {
|
||||
|
||||
private static ParticleProvider loaded;
|
||||
@ -33,7 +33,7 @@ public abstract class ParticleProvider {
|
||||
} else {
|
||||
loaded = new ParticleProvider_Bukkit();
|
||||
}
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||
| ClassCastException exception) {
|
||||
Bukkit.getLogger().severe("[Quests] Could not find a valid implementation for this server version.");
|
||||
}
|
||||
@ -70,7 +70,7 @@ public abstract class ParticleProvider {
|
||||
*/
|
||||
public static void sendToPlayer(final Player player, final Location location, final String particleId, final float offsetX, final float offsetY,
|
||||
final float offsetZ, final float speed, final int count, final int[] data) {
|
||||
Object particle;
|
||||
final Object particle;
|
||||
final PreBuiltParticle pbp = PreBuiltParticle.fromIdentifier(particleId);
|
||||
if (pbp != null) {
|
||||
particle = loaded.getParticleMap().get(pbp);
|
||||
|
@ -12,16 +12,16 @@
|
||||
|
||||
package me.blackvein.quests.particle;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class ParticleProvider_Bukkit extends ParticleProvider {
|
||||
|
||||
private static Map<PreBuiltParticle, Object> PARTICLES = new HashMap<>();
|
||||
private static final Map<PreBuiltParticle, Object> PARTICLES = new HashMap<>();
|
||||
|
||||
static {
|
||||
PARTICLES.put(PreBuiltParticle.ENCHANT, Particle.ENCHANTMENT_TABLE);
|
||||
|
@ -29,9 +29,12 @@ public enum PreBuiltParticle {
|
||||
SPLASH("splash", 0, 0, 0, 1, 4, new Vector(0, .5, 0)),
|
||||
SMOKE("smoke", 0, 1, 0, 1, 20);
|
||||
|
||||
private String identifier;
|
||||
private float offsetX, offsetY, offsetZ, speed;
|
||||
private int count;
|
||||
private final String identifier;
|
||||
private final float offsetX;
|
||||
private final float offsetY;
|
||||
private final float offsetZ;
|
||||
private final float speed;
|
||||
private final int count;
|
||||
private Vector vector;
|
||||
|
||||
PreBuiltParticle(final String identifier, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int count) {
|
||||
|
@ -12,15 +12,13 @@
|
||||
|
||||
package me.blackvein.quests.reflect.denizen;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
public class DenizenAPI {
|
||||
private Class<?> denizen_1_0_9 = null;
|
||||
@ -79,7 +77,7 @@ public class DenizenAPI {
|
||||
containsScriptMethod = scriptRegistry.getMethod("containsScript", String.class);
|
||||
getScriptNamesMethod = scriptRegistry.getMethod("_getScriptNames");
|
||||
getScriptContainerAsMethod = scriptRegistry
|
||||
.getMethod("getScriptContainerAs", String.class, taskScriptContainer.getClass());
|
||||
.getMethod("getScriptContainerAs", String.class, taskScriptContainer);
|
||||
mirrorBukkitPlayerMethod = dPlayer.getMethod("mirrorBukkitPlayer", OfflinePlayer.class);
|
||||
mirrorCitizensNPCMethod = dNPC.getMethod("mirrorCitizensNPC", NPC.class);
|
||||
} catch (final Exception e) {
|
||||
@ -88,12 +86,10 @@ public class DenizenAPI {
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
if (denizen_1_1_1 != null || denizen_1_1_0 != null || denizen_1_0_9 != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return denizen_1_1_1 != null || denizen_1_1_0 != null || denizen_1_0_9 != null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Class<?> getDenizenClass() {
|
||||
if (denizen_1_1_1 != null) {
|
||||
return denizen_1_1_1;
|
||||
@ -105,7 +101,6 @@ public class DenizenAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public boolean containsScript(final String input) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
return DenizenAPI_1_1_1.containsScript(input);
|
||||
@ -116,7 +111,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public String getScriptContainerName(final String input) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
@ -128,7 +123,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Set<String> getScriptNames() {
|
||||
if (denizen_1_1_1 != null) {
|
||||
@ -140,7 +135,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Object getScriptContainerAs(final String scriptName) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
@ -152,7 +147,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Object mirrorBukkitPlayer(final Player player) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
@ -164,7 +159,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Object mirrorCitizensNPC(final NPC npc) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
@ -176,8 +171,7 @@ public class DenizenAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
public void runTaskScript(final String scriptName, final Player player) {
|
||||
if (denizen_1_1_1 != null) {
|
||||
DenizenAPI_1_1_1.runTaskScript(scriptName, player);
|
||||
|
@ -12,29 +12,26 @@
|
||||
|
||||
package me.blackvein.quests.reflect.denizen;
|
||||
|
||||
import me.blackvein.quests.Quests;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.blackvein.quests.Quests;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class DenizenAPI_1_0_9 {
|
||||
|
||||
private static Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenApi();
|
||||
private static final Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static final DenizenAPI api = quests != null ? quests.getDependencies().getDenizenApi() : null;
|
||||
|
||||
@Nullable
|
||||
public static boolean containsScript(final String input) {
|
||||
if (api.scriptRegistry == null || api.containsScriptMethod == null) return false;
|
||||
if (quests == null || api.scriptRegistry == null || api.containsScriptMethod == null) return false;
|
||||
boolean script = false;
|
||||
try {
|
||||
script = (boolean)api.containsScriptMethod.invoke(api.scriptRegistry, input);
|
||||
@ -46,9 +43,9 @@ public class DenizenAPI_1_0_9 {
|
||||
|
||||
@Nullable
|
||||
public static String getScriptContainerName(final String input) {
|
||||
if (api.scriptRegistry == null || api.scriptContainer == null) return null;
|
||||
if (quests == null || api.scriptRegistry == null || api.scriptContainer == null) return null;
|
||||
String name = null;
|
||||
Object instance;
|
||||
final Object instance;
|
||||
try {
|
||||
final Constructor<?> constructor = api.scriptRegistry.getConstructor(YamlConfiguration.class, String.class);
|
||||
instance = constructor.newInstance(null, input);
|
||||
@ -62,7 +59,7 @@ public class DenizenAPI_1_0_9 {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public static Set<String> getScriptNames() {
|
||||
if (api.scriptRegistry == null || api.getScriptNamesMethod == null) return null;
|
||||
if (quests == null || api.scriptRegistry == null || api.getScriptNamesMethod == null) return null;
|
||||
Set<String> names = null;
|
||||
try {
|
||||
names = (Set<String>)api.getScriptNamesMethod.invoke(api.scriptRegistry);
|
||||
@ -74,7 +71,7 @@ public class DenizenAPI_1_0_9 {
|
||||
|
||||
@Nullable
|
||||
public static Object getScriptContainerAs(final String scriptName) {
|
||||
if (api.scriptRegistry == null || api.taskScriptContainer == null) return null;
|
||||
if (quests == null || api.scriptRegistry == null || api.taskScriptContainer == null) return null;
|
||||
Object container = null;
|
||||
try {
|
||||
container = api.getScriptContainerAsMethod.invoke(api.scriptRegistry, scriptName, api.taskScriptContainer);
|
||||
@ -86,7 +83,7 @@ public class DenizenAPI_1_0_9 {
|
||||
|
||||
@Nullable
|
||||
public static Object mirrorBukkitPlayer(final Player player) {
|
||||
if (api.dPlayer == null || api.mirrorBukkitPlayerMethod == null) return null;
|
||||
if (quests == null || api.dPlayer == null || api.mirrorBukkitPlayerMethod == null) return null;
|
||||
Object dp = null;
|
||||
try {
|
||||
dp = api.mirrorBukkitPlayerMethod.invoke(api.dPlayer, player);
|
||||
@ -98,7 +95,7 @@ public class DenizenAPI_1_0_9 {
|
||||
|
||||
@Nullable
|
||||
public static Object mirrorCitizensNPC(final NPC npc) {
|
||||
if (api.dNPC == null || api.mirrorCitizensNPCMethod == null) return null;
|
||||
if (quests == null || api.dNPC == null || api.mirrorCitizensNPCMethod == null) return null;
|
||||
Object dp = null;
|
||||
try {
|
||||
dp = api.mirrorCitizensNPCMethod.invoke(api.dNPC, npc);
|
||||
@ -108,14 +105,15 @@ public class DenizenAPI_1_0_9 {
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
if (api.scriptRegistry == null || api.bukkitScriptEntryData == null || api.scriptEntryData == null) return;
|
||||
if (quests == null || api.scriptRegistry == null || api.bukkitScriptEntryData == null || api.scriptEntryData == null) return;
|
||||
try {
|
||||
final Constructor<?> constructor = api.bukkitScriptEntryData.getConstructors()[0];
|
||||
final Object tsc = getScriptContainerAs(scriptName);
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
if (tsc != null) {
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
quests.getLogger().log(Level.WARNING, "Error invoking Denizen TaskScriptContainer#runTaskScript", e);
|
||||
}
|
||||
|
@ -12,31 +12,28 @@
|
||||
|
||||
package me.blackvein.quests.reflect.denizen;
|
||||
|
||||
import com.denizenscript.denizen.objects.NPCTag;
|
||||
import com.denizenscript.denizen.objects.PlayerTag;
|
||||
import com.denizenscript.denizencore.scripts.ScriptRegistry;
|
||||
import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer;
|
||||
import me.blackvein.quests.Quests;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.denizenscript.denizen.objects.NPCTag;
|
||||
import com.denizenscript.denizen.objects.PlayerTag;
|
||||
import com.denizenscript.denizencore.scripts.ScriptRegistry;
|
||||
import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer;
|
||||
|
||||
import me.blackvein.quests.Quests;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class DenizenAPI_1_1_0 {
|
||||
|
||||
private static Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static DenizenAPI api = quests.getDependencies().getDenizenApi();
|
||||
private static final Quests quests = (Quests) Bukkit.getPluginManager().getPlugin("Quests");
|
||||
private static final DenizenAPI api = quests != null ? quests.getDependencies().getDenizenApi() : null;
|
||||
|
||||
@Nullable
|
||||
public static boolean containsScript(final String input) {
|
||||
return ScriptRegistry.containsScript(input);
|
||||
}
|
||||
@ -49,7 +46,7 @@ public class DenizenAPI_1_1_0 {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public static Set<String> getScriptNames() {
|
||||
if (api.scriptRegistry == null || api.getScriptNamesMethod == null) return null;
|
||||
if (quests == null || api.scriptRegistry == null || api.getScriptNamesMethod == null) return null;
|
||||
Set<String> names = null;
|
||||
try {
|
||||
names = (Set<String>)api.getScriptNamesMethod.invoke(api.scriptRegistry);
|
||||
@ -69,18 +66,21 @@ public class DenizenAPI_1_1_0 {
|
||||
return PlayerTag.mirrorBukkitPlayer(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object mirrorCitizensNPC(final NPC npc) {
|
||||
public static @NotNull Object mirrorCitizensNPC(final NPC npc) {
|
||||
return NPCTag.mirrorCitizensNPC(npc);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
if (quests == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final Constructor<?> constructor = api.bukkitScriptEntryData.getConstructors()[0];
|
||||
final Object tsc = getScriptContainerAs(scriptName);
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
if (tsc != null) {
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
quests.getLogger().log(Level.WARNING, "Error invoking Denizen TaskScriptContainer#runTaskScript", e);
|
||||
}
|
||||
|
@ -12,12 +12,6 @@
|
||||
|
||||
package me.blackvein.quests.reflect.denizen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.denizenscript.denizen.objects.NPCTag;
|
||||
import com.denizenscript.denizen.objects.PlayerTag;
|
||||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
|
||||
@ -25,12 +19,15 @@ import com.denizenscript.denizencore.scripts.ScriptRegistry;
|
||||
import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer;
|
||||
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;
|
||||
import com.denizenscript.denizencore.scripts.queues.core.InstantQueue;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class DenizenAPI_1_1_1 {
|
||||
|
||||
@Nullable
|
||||
public static boolean containsScript(final String input) {
|
||||
return ScriptRegistry.containsScript(input);
|
||||
}
|
||||
@ -40,8 +37,7 @@ public class DenizenAPI_1_1_1 {
|
||||
return ScriptRegistry.getScriptContainer(input).getName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Set<String> getScriptNames() {
|
||||
public static @NotNull Set<String> getScriptNames() {
|
||||
return ScriptRegistry.scriptContainers.keySet();
|
||||
}
|
||||
|
||||
@ -55,12 +51,10 @@ public class DenizenAPI_1_1_1 {
|
||||
return PlayerTag.mirrorBukkitPlayer(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object mirrorCitizensNPC(final NPC npc) {
|
||||
public static @NotNull Object mirrorCitizensNPC(final NPC npc) {
|
||||
return NPCTag.mirrorCitizensNPC(npc);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
final TaskScriptContainer taskScript = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class);
|
||||
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player), null);
|
||||
|
@ -12,25 +12,23 @@
|
||||
|
||||
package me.blackvein.quests.reflect.worldguard;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldGuardAPI {
|
||||
private Object worldGuard7 = null;
|
||||
@ -60,7 +58,7 @@ public class WorldGuardAPI {
|
||||
}
|
||||
|
||||
protected RegionAssociable getAssociable(final Player player) {
|
||||
RegionAssociable associable;
|
||||
final RegionAssociable associable;
|
||||
if (player == null) {
|
||||
associable = Associables.constant(Association.NON_MEMBER);
|
||||
} else {
|
||||
|
@ -12,17 +12,17 @@
|
||||
|
||||
package me.blackvein.quests.reflect.worldguard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WorldGuardAPI_7_0_0 {
|
||||
|
||||
@ -36,13 +36,13 @@ public class WorldGuardAPI_7_0_0 {
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ApplicableRegionSet getApplicableRegions(final World world, final Location location) {
|
||||
return getRegionManager(world).getApplicableRegions(BukkitAdapter.asBlockVector(location));
|
||||
public static @NotNull ApplicableRegionSet getApplicableRegions(final World world, final Location location) {
|
||||
return Objects.requireNonNull(getRegionManager(world)).getApplicableRegions(BukkitAdapter
|
||||
.asBlockVector(location));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<String> getApplicableRegionsIDs(final World world, final Location location) {
|
||||
return getRegionManager(world).getApplicableRegionsIDs(BukkitAdapter.asBlockVector(location));
|
||||
public static @NotNull List<String> getApplicableRegionsIDs(final World world, final Location location) {
|
||||
return Objects.requireNonNull(getRegionManager(world)).getApplicableRegionsIDs(BukkitAdapter
|
||||
.asBlockVector(location));
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,13 @@
|
||||
|
||||
package me.blackvein.quests.statistics;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -39,14 +46,6 @@ import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Metrics {
|
||||
|
||||
private final Plugin plugin;
|
||||
@ -57,8 +56,6 @@ public class Metrics {
|
||||
* Creates a new Metrics instance.
|
||||
*
|
||||
* @param plugin Your plugin instance.
|
||||
* @param serviceId The id of the service. It can be found at <a
|
||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
public Metrics(final JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -324,11 +321,11 @@ public class Metrics {
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
try (final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader =
|
||||
try (final BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
@ -371,7 +368,7 @@ public class Metrics {
|
||||
return null;
|
||||
}
|
||||
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
try (final GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
|
@ -58,10 +58,7 @@ public class Storage {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (final Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new CompletionException(e);
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -89,9 +86,7 @@ public class Storage {
|
||||
}
|
||||
|
||||
public CompletableFuture<Quester> loadQuester(final UUID uniqueId) {
|
||||
return makeFuture(() -> {
|
||||
return implementation.loadQuester(uniqueId);
|
||||
});
|
||||
return makeFuture(() -> implementation.loadQuester(uniqueId));
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> saveQuester(final Quester quester) {
|
||||
|
@ -12,14 +12,7 @@
|
||||
|
||||
package me.blackvein.quests.storage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.storage.implementation.StorageImplementation;
|
||||
import me.blackvein.quests.storage.implementation.custom.CustomStorageProviders;
|
||||
@ -27,6 +20,11 @@ import me.blackvein.quests.storage.implementation.file.SeparatedYamlStorage;
|
||||
import me.blackvein.quests.storage.implementation.sql.SqlStorage;
|
||||
import me.blackvein.quests.storage.implementation.sql.connection.hikari.MySqlConnectionFactory;
|
||||
import me.blackvein.quests.storage.misc.StorageCredentials;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class StorageFactory {
|
||||
private final Quests plugin;
|
||||
@ -41,8 +39,7 @@ public class StorageFactory {
|
||||
}
|
||||
|
||||
public Storage getInstance() {
|
||||
Storage storage;
|
||||
|
||||
final Storage storage;
|
||||
final StorageType type = StorageType.parse(plugin.getConfig().getString("storage-method.player-data", "yaml"),
|
||||
StorageType.YAML);
|
||||
plugin.getLogger().info("Loading storage implementation: " + type.name());
|
||||
|
@ -27,7 +27,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
@ -83,10 +82,7 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (final InvalidConfigurationException e) {
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -106,14 +102,14 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
}
|
||||
if (data.contains("amountsCompletedQuests")) {
|
||||
final List<String> questIds = data.getStringList("amountsCompletedQuests");
|
||||
final List<Integer> questAmts = data.getIntegerList("amountsCompleted");
|
||||
final List<Integer> questAmounts = data.getIntegerList("amountsCompleted");
|
||||
final ConcurrentHashMap<Quest, Integer> amountsCompleted = quester.getAmountsCompleted();
|
||||
for (int i = 0; i < questIds.size(); i++) {
|
||||
if (plugin.getQuestById(questIds.get(i)) != null) {
|
||||
amountsCompleted.put(plugin.getQuestById(questIds.get(i)), questAmts.get(i));
|
||||
amountsCompleted.put(plugin.getQuestById(questIds.get(i)), questAmounts.get(i));
|
||||
} else if (plugin.getQuest(questIds.get(i)) != null) {
|
||||
// Legacy
|
||||
amountsCompleted.put(plugin.getQuest(questIds.get(i)), questAmts.get(i));
|
||||
amountsCompleted.put(plugin.getQuest(questIds.get(i)), questAmounts.get(i));
|
||||
}
|
||||
}
|
||||
quester.setAmountsCompleted(amountsCompleted);
|
||||
@ -322,7 +318,7 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
}
|
||||
if (questSec.contains("has-talked-to")) {
|
||||
final List<Boolean> talkAmount = questSec.getBooleanList("has-talked-to");
|
||||
quester.getQuestData(quest).setCitizensInteracted(new LinkedList<Boolean>(talkAmount));
|
||||
quester.getQuestData(quest).setCitizensInteracted(new LinkedList<>(talkAmount));
|
||||
}
|
||||
if (questSec.contains("citizen-ids-killed")) {
|
||||
final List<Integer> ids = questSec.getIntegerList("citizen-ids-killed");
|
||||
@ -344,7 +340,7 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
quester.getQuestData(quest).setPlayersKilled(questSec.getInt("players-killed"));
|
||||
}
|
||||
if (questSec.contains("mobs-killed")) {
|
||||
final LinkedList<EntityType> mobs = new LinkedList<EntityType>();
|
||||
final LinkedList<EntityType> mobs = new LinkedList<>();
|
||||
final List<Integer> amounts = questSec.getIntegerList("mobs-killed-amounts");
|
||||
for (final String s : questSec.getStringList("mobs-killed")) {
|
||||
final EntityType mob = MiscUtil.getProperMobType(s);
|
||||
@ -361,23 +357,23 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
}
|
||||
if (questSec.contains("locations-to-reach")) {
|
||||
final List<Boolean> hasReached = questSec.getBooleanList("has-reached-location");
|
||||
quester.getQuestData(quest).setLocationsReached(new LinkedList<Boolean>(hasReached));
|
||||
quester.getQuestData(quest).setLocationsReached(new LinkedList<>(hasReached));
|
||||
}
|
||||
if (questSec.contains("mob-tame-amounts")) {
|
||||
final List<Integer> tameAmounts = questSec.getIntegerList("mob-tame-amounts");
|
||||
quester.getQuestData(quest).setMobsTamed(new LinkedList<Integer>(tameAmounts));
|
||||
quester.getQuestData(quest).setMobsTamed(new LinkedList<>(tameAmounts));
|
||||
}
|
||||
if (questSec.contains("sheep-sheared")) {
|
||||
final List<Integer> sheepAmounts = questSec.getIntegerList("sheep-sheared");
|
||||
quester.getQuestData(quest).setSheepSheared(new LinkedList<Integer>(sheepAmounts));
|
||||
quester.getQuestData(quest).setSheepSheared(new LinkedList<>(sheepAmounts));
|
||||
}
|
||||
if (questSec.contains("passwords-said")) {
|
||||
final List<Boolean> passAmounts = questSec.getBooleanList("passwords-said");
|
||||
quester.getQuestData(quest).setPasswordsSaid(new LinkedList<Boolean>(passAmounts));
|
||||
quester.getQuestData(quest).setPasswordsSaid(new LinkedList<>(passAmounts));
|
||||
}
|
||||
if (questSec.contains("custom-objective-counts")) {
|
||||
final List<Integer> customObjCounts = questSec.getIntegerList("custom-objective-counts");
|
||||
quester.getQuestData(quest).setCustomObjectiveCounts(new LinkedList<Integer>(customObjCounts));
|
||||
quester.getQuestData(quest).setCustomObjectiveCounts(new LinkedList<>(customObjCounts));
|
||||
}
|
||||
if (questSec.contains("stage-delay")) {
|
||||
quester.getQuestData(quest).setDelayTimeLeft(questSec.getLong("stage-delay"));
|
||||
@ -416,25 +412,20 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
|
||||
@Override
|
||||
public Collection<UUID> getSavedUniqueIds() throws Exception {
|
||||
final Collection<UUID> ids = new ConcurrentSkipListSet<UUID>();
|
||||
final Collection<UUID> ids = new ConcurrentSkipListSet<>();
|
||||
final File folder = new File(directoryPath);
|
||||
if (!folder.exists()) {
|
||||
return ids;
|
||||
}
|
||||
final File[] listOfFiles = folder.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".yml");
|
||||
}
|
||||
});
|
||||
final File[] listOfFiles = folder.listFiles((dir, name) -> name.endsWith(".yml"));
|
||||
|
||||
if (listOfFiles == null) {
|
||||
return ids;
|
||||
}
|
||||
for (File listOfFile : listOfFiles) {
|
||||
for (final File listOfFile : listOfFiles) {
|
||||
if (listOfFile.isFile()) {
|
||||
final String name = listOfFile.getName().substring(0, listOfFile.getName().lastIndexOf("."));
|
||||
UUID id = null;
|
||||
final UUID id;
|
||||
try {
|
||||
id = UUID.fromString(name);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
|
@ -12,16 +12,15 @@
|
||||
|
||||
package me.blackvein.quests.tasks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.particle.ParticleProvider;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NpcEffectThread implements Runnable {
|
||||
|
||||
@ -36,7 +35,7 @@ public class NpcEffectThread implements Runnable {
|
||||
for (final Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final List<Entity> nearby = player.getNearbyEntities(32.0, 32.0, 32.0);
|
||||
if (nearby.isEmpty() == false) {
|
||||
if (!nearby.isEmpty()) {
|
||||
for (final Entity e : nearby) {
|
||||
if (plugin.getDependencies().getCitizens() != null
|
||||
&& plugin.getDependencies().getCitizens().getNPCRegistry() != null) {
|
||||
|
@ -12,23 +12,23 @@
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import me.blackvein.quests.Dependencies;
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.blackvein.quests.Dependencies;
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConfigUtil {
|
||||
|
||||
private static Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%");
|
||||
private static final Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%");
|
||||
|
||||
/**
|
||||
* Checks whether items in a list are instances of a class<p>
|
||||
@ -44,7 +44,7 @@ public class ConfigUtil {
|
||||
return false;
|
||||
}
|
||||
for (final Object o : list) {
|
||||
if (clazz.isAssignableFrom(o.getClass()) == false) {
|
||||
if (!clazz.isAssignableFrom(o.getClass())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -69,16 +69,16 @@ public class ConfigUtil {
|
||||
if (index == 0) {
|
||||
sb.append(s);
|
||||
} else {
|
||||
sb.append(" " + s);
|
||||
sb.append(" ").append(s);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
final String world = sb.toString();
|
||||
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
final double x;
|
||||
final double y;
|
||||
final double z;
|
||||
try {
|
||||
x = Double.parseDouble(info[xIndex]);
|
||||
y = Double.parseDouble(info[yIndex]);
|
||||
@ -92,12 +92,12 @@ public class ConfigUtil {
|
||||
Bukkit.getLogger().severe("Quests could not locate world " + world + ", is it loaded?");
|
||||
return null;
|
||||
}
|
||||
final Location finalLocation = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
return finalLocation;
|
||||
return new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
}
|
||||
|
||||
public static String getLocationInfo(final Location loc) {
|
||||
return loc.getWorld().getName() + " " + loc.getX() + " " + loc.getY() + " " + loc.getZ();
|
||||
return Objects.requireNonNull(loc.getWorld()).getName() + " " + loc.getX() + " " + loc.getY() + " "
|
||||
+ loc.getZ();
|
||||
}
|
||||
|
||||
public static String[] parseStringWithPossibleLineBreaks(final String s, final Quest quest, final Player player) {
|
||||
@ -197,8 +197,8 @@ public class ConfigUtil {
|
||||
final StringBuilder hex = new StringBuilder();
|
||||
hex.append(ChatColor.COLOR_CHAR + "x");
|
||||
final char[] chars = matcher.group(1).toCharArray();
|
||||
for (int index = 0; index < chars.length; index++) {
|
||||
hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(chars[index]));
|
||||
for (final char aChar : chars) {
|
||||
hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(aChar));
|
||||
}
|
||||
parsed = parsed.replace(matcher.group(), hex.toString());
|
||||
}
|
||||
|
@ -37,25 +37,26 @@ public class FakeConversable implements Conversable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void acceptConversationInput(@NotNull String input) {
|
||||
public void acceptConversationInput(@NotNull final String input) {
|
||||
}
|
||||
|
||||
public boolean beginConversation(Conversation conversation) {
|
||||
public boolean beginConversation(final Conversation conversation) {
|
||||
begunConversation = conversation;
|
||||
conversation.outputNextPrompt();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void abandonConversation(@NotNull Conversation conversation) {
|
||||
public void abandonConversation(@NotNull final Conversation conversation) {
|
||||
abandonedConverstion = conversation;
|
||||
}
|
||||
|
||||
public void abandonConversation(@NotNull Conversation conversation, @NotNull ConversationAbandonedEvent details) {
|
||||
public void abandonConversation(@NotNull final Conversation conversation,
|
||||
@NotNull final ConversationAbandonedEvent details) {
|
||||
abandonedConverstion = conversation;
|
||||
abandonedConversationEvent = details;
|
||||
}
|
||||
|
||||
public void sendRawMessage(@NotNull String message) {
|
||||
public void sendRawMessage(@NotNull final String message) {
|
||||
lastSentMessage = message;
|
||||
}
|
||||
|
||||
@ -67,39 +68,40 @@ public class FakeConversable implements Conversable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPermissionSet(String name) {
|
||||
public boolean isPermissionSet(final String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
public boolean isPermissionSet(final Permission perm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(String name) {
|
||||
public boolean hasPermission(final String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(Permission perm) {
|
||||
public boolean hasPermission(final Permission perm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
public PermissionAttachment addAttachment(final Plugin plugin, final String name, final boolean value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
public PermissionAttachment addAttachment(final Plugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
public PermissionAttachment addAttachment(final Plugin plugin, final String name, final boolean value,
|
||||
final int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
public PermissionAttachment addAttachment(final Plugin plugin, final int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
public void removeAttachment(final PermissionAttachment attachment) {
|
||||
}
|
||||
|
||||
public void recalculatePermissions() {
|
||||
@ -113,7 +115,7 @@ public class FakeConversable implements Conversable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setOp(boolean value) {
|
||||
public void setOp(final boolean value) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,15 +12,15 @@
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InventoryUtil {
|
||||
|
||||
/**
|
||||
@ -36,11 +36,9 @@ public class InventoryUtil {
|
||||
}
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
final HashMap<Integer, ItemStack> leftovers = inv.addItem(item);
|
||||
if (leftovers != null) {
|
||||
if (leftovers.isEmpty() == false) {
|
||||
for (final ItemStack leftover : leftovers.values()) {
|
||||
player.getWorld().dropItem(player.getLocation(), leftover);
|
||||
}
|
||||
if (!leftovers.isEmpty()) {
|
||||
for (final ItemStack leftover : leftovers.values()) {
|
||||
player.getWorld().dropItem(player.getLocation(), leftover);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,26 +53,20 @@ public class InventoryUtil {
|
||||
public static boolean canRemoveItem(final Inventory inventory, final ItemStack item) {
|
||||
final int amount = item.getAmount();
|
||||
final HashMap<Integer, ? extends ItemStack> allItems = inventory.all(item.getType());
|
||||
final HashMap<Integer, Integer> removeFrom = new HashMap<Integer, Integer>();
|
||||
int foundAmount = 0;
|
||||
for (final Map.Entry<Integer, ? extends ItemStack> items : allItems.entrySet()) {
|
||||
if (ItemUtil.compareItems(item, items.getValue(), true) == 0) {
|
||||
if (items.getValue().getAmount() >= amount - foundAmount) {
|
||||
removeFrom.put(items.getKey(), amount - foundAmount);
|
||||
foundAmount = amount;
|
||||
} else {
|
||||
foundAmount += items.getValue().getAmount();
|
||||
removeFrom.put(items.getKey(), items.getValue().getAmount());
|
||||
}
|
||||
if (foundAmount >= amount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (foundAmount == amount) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return foundAmount == amount;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +79,7 @@ public class InventoryUtil {
|
||||
public static boolean removeItem(final Inventory inventory, final ItemStack item) {
|
||||
final int amount = item.getAmount();
|
||||
final HashMap<Integer, ? extends ItemStack> allItems = inventory.all(item.getType());
|
||||
final HashMap<Integer, Integer> removeFrom = new HashMap<Integer, Integer>();
|
||||
final HashMap<Integer, Integer> removeFrom = new HashMap<>();
|
||||
int foundAmount = 0;
|
||||
for (final Map.Entry<Integer, ? extends ItemStack> items : allItems.entrySet()) {
|
||||
if (ItemUtil.compareItems(item, items.getValue(), true) == 0) {
|
||||
@ -106,11 +98,13 @@ public class InventoryUtil {
|
||||
if (foundAmount == amount) {
|
||||
for (final Map.Entry<Integer, Integer> toRemove : removeFrom.entrySet()) {
|
||||
final ItemStack i = inventory.getItem(toRemove.getKey());
|
||||
if (i.getAmount() - toRemove.getValue() <= 0) {
|
||||
inventory.clear(toRemove.getKey());
|
||||
} else {
|
||||
i.setAmount(i.getAmount() - toRemove.getValue());
|
||||
inventory.setItem(toRemove.getKey(), i);
|
||||
if (i != null) {
|
||||
if (i.getAmount() - toRemove.getValue() <= 0) {
|
||||
inventory.clear(toRemove.getKey());
|
||||
} else {
|
||||
i.setAmount(i.getAmount() - toRemove.getValue());
|
||||
inventory.setItem(toRemove.getKey(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -128,7 +122,7 @@ public class InventoryUtil {
|
||||
public static boolean stripItem(final EntityEquipment equipment, final ItemStack item) {
|
||||
final int amount = item.getAmount();
|
||||
final ItemStack[] allItems = equipment.getArmorContents();
|
||||
final HashMap<Integer, Integer> removeFrom = new HashMap<Integer, Integer>();
|
||||
final HashMap<Integer, Integer> removeFrom = new HashMap<>();
|
||||
int foundAmount = 0;
|
||||
|
||||
int index = 0;
|
||||
|
@ -38,43 +38,6 @@ import java.util.Map.Entry;
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ItemUtil {
|
||||
|
||||
/*public static String toBase64(ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final ByteArrayOutputStream io = new ByteArrayOutputStream();
|
||||
final BukkitObjectOutputStream os = new BukkitObjectOutputStream(io);
|
||||
os.writeObject(itemStack);
|
||||
os.flush();
|
||||
|
||||
final byte[] serializedObject = io.toByteArray();
|
||||
return Base64.getEncoder().encodeToString(serializedObject);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack fromBase64(String encodedObject) {
|
||||
if (encodedObject == null) {
|
||||
return null;
|
||||
}
|
||||
final byte[] serializedObject = Base64.getDecoder().decode(encodedObject);
|
||||
|
||||
try {
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream((serializedObject));
|
||||
final BukkitObjectInputStream is = new BukkitObjectInputStream(in);
|
||||
final Object object = is.readObject();
|
||||
if (object instanceof ItemStack) {
|
||||
return (ItemStack)object;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Compare two stacks by name, amount, durability, display name, lore, enchantments, stored enchants and item flags
|
||||
*
|
||||
@ -123,34 +86,34 @@ public class ItemUtil {
|
||||
if (one == null || two == null) {
|
||||
return 1;
|
||||
}
|
||||
if (one.getType().name().equals(two.getType().name()) == false) {
|
||||
if (!one.getType().name().equals(two.getType().name())) {
|
||||
return -1;
|
||||
} else if ((one.getAmount() != two.getAmount()) && ignoreAmount == false) {
|
||||
} else if ((one.getAmount() != two.getAmount()) && !ignoreAmount) {
|
||||
return -2;
|
||||
} else if ((one.getDurability() != two.getDurability()) && ignoreDurability == false) {
|
||||
} else if ((one.getDurability() != two.getDurability()) && !ignoreDurability) {
|
||||
if (one.getDurability() < 999 && two.getDurability() < 999) { // wildcard value
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
if (one.hasItemMeta() || two.hasItemMeta()) {
|
||||
if (one.hasItemMeta() && two.hasItemMeta() == false) {
|
||||
if (one.getItemMeta() != null || two.getItemMeta() != null) {
|
||||
if (one.getItemMeta() != null && two.getItemMeta() != null) {
|
||||
return -4;
|
||||
} else if (one.hasItemMeta() == false && two.hasItemMeta()) {
|
||||
} else if (!one.hasItemMeta() && two.hasItemMeta()) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasDisplayName() && two.getItemMeta().hasDisplayName() == false) {
|
||||
} else if (one.getItemMeta().hasDisplayName() && !two.getItemMeta().hasDisplayName()) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasDisplayName() == false && two.getItemMeta().hasDisplayName()) {
|
||||
} else if (!one.getItemMeta().hasDisplayName() && two.getItemMeta().hasDisplayName()) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasLore() && two.getItemMeta().hasLore() == false) {
|
||||
} else if (one.getItemMeta().hasLore() && !two.getItemMeta().hasLore()) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasLore() == false && two.getItemMeta().hasLore()) {
|
||||
} else if (!one.getItemMeta().hasLore() && two.getItemMeta().hasLore()) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasDisplayName() && two.getItemMeta().hasDisplayName()
|
||||
&& ChatColor.stripColor(one.getItemMeta().getDisplayName())
|
||||
.equals(ChatColor.stripColor(two.getItemMeta().getDisplayName())) == false) {
|
||||
&& !ChatColor.stripColor(one.getItemMeta().getDisplayName())
|
||||
.equals(ChatColor.stripColor(two.getItemMeta().getDisplayName()))) {
|
||||
return -4;
|
||||
} else if (one.getItemMeta().hasLore() && two.getItemMeta().hasLore()
|
||||
&& one.getItemMeta().getLore().equals(two.getItemMeta().getLore()) == false) {
|
||||
&& !one.getItemMeta().getLore().equals(two.getItemMeta().getLore())) {
|
||||
return -4;
|
||||
}
|
||||
try {
|
||||
@ -158,7 +121,7 @@ public class ItemUtil {
|
||||
test.setUnbreakable(true);
|
||||
// We're on 1.11+ so check ItemFlags
|
||||
for (final ItemFlag flag : ItemFlag.values()) {
|
||||
if (one.getItemMeta().hasItemFlag(flag) == false && two.getItemMeta().hasItemFlag(flag)) {
|
||||
if (!one.getItemMeta().hasItemFlag(flag) && two.getItemMeta().hasItemFlag(flag)) {
|
||||
return -7;
|
||||
}
|
||||
}
|
||||
@ -166,11 +129,11 @@ public class ItemUtil {
|
||||
// We're below 1.11 so don't check ItemFlags
|
||||
}
|
||||
if (one.getType().equals(Material.WRITTEN_BOOK)) {
|
||||
final BookMeta bmeta1 = (BookMeta) one.getItemMeta();
|
||||
final BookMeta bmeta2 = (BookMeta) two.getItemMeta();
|
||||
if (bmeta1.getTitle().equals(bmeta2.getTitle()) == false) {
|
||||
if (bmeta1.getAuthor().equals(bmeta2.getAuthor()) == false) {
|
||||
if (bmeta1.getPages().equals(bmeta2.getPages()) == false) {
|
||||
final BookMeta bMeta1 = (BookMeta) one.getItemMeta();
|
||||
final BookMeta bMeta2 = (BookMeta) two.getItemMeta();
|
||||
if (!bMeta1.getTitle().equals(bMeta2.getTitle())) {
|
||||
if (!bMeta1.getAuthor().equals(bMeta2.getAuthor())) {
|
||||
if (!bMeta1.getPages().equals(bMeta2.getPages())) {
|
||||
return -8;
|
||||
}
|
||||
}
|
||||
@ -181,16 +144,15 @@ public class ItemUtil {
|
||||
// Bukkit version is 1.9+
|
||||
if (one.getType().equals(Material.POTION) || one.getType().equals(Material.LINGERING_POTION)
|
||||
|| one.getType().equals(Material.SPLASH_POTION)) {
|
||||
final PotionMeta pmeta1 = (PotionMeta) one.getItemMeta();
|
||||
final PotionMeta pmeta2 = (PotionMeta) two.getItemMeta();
|
||||
if (pmeta1.getBasePotionData().getType()
|
||||
.equals(pmeta2.getBasePotionData().getType()) == false) {
|
||||
final PotionMeta pMeta1 = (PotionMeta) one.getItemMeta();
|
||||
final PotionMeta pMeta2 = (PotionMeta) two.getItemMeta();
|
||||
if (!pMeta1.getBasePotionData().getType().equals(pMeta2.getBasePotionData().getType())) {
|
||||
return -9;
|
||||
}
|
||||
if (pmeta1.getBasePotionData().isExtended() != pmeta2.getBasePotionData().isExtended()) {
|
||||
if (pMeta1.getBasePotionData().isExtended() != pMeta2.getBasePotionData().isExtended()) {
|
||||
return -9;
|
||||
}
|
||||
if (pmeta1.getBasePotionData().isUpgraded() != pmeta2.getBasePotionData().isUpgraded()) {
|
||||
if (pMeta1.getBasePotionData().isUpgraded() != pMeta2.getBasePotionData().isUpgraded()) {
|
||||
return -9;
|
||||
}
|
||||
}
|
||||
@ -202,24 +164,21 @@ public class ItemUtil {
|
||||
// Bukkit version is below 1.9
|
||||
final Potion pot1 = new Potion(one.getDurability());
|
||||
final Potion pot2 = new Potion(two.getDurability());
|
||||
if (pot1.getType() == null || pot2.getType() == null) {
|
||||
return -9;
|
||||
}
|
||||
if (!pot1.getType().equals(pot2.getType())) {
|
||||
return -9;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (one.getEnchantments().equals(two.getEnchantments()) == false) {
|
||||
if (!one.getEnchantments().equals(two.getEnchantments())) {
|
||||
return -5;
|
||||
}
|
||||
if (one.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
final EnchantmentStorageMeta esmeta1 = (EnchantmentStorageMeta) one.getItemMeta();
|
||||
final EnchantmentStorageMeta esmeta2 = (EnchantmentStorageMeta) two.getItemMeta();
|
||||
if (esmeta1.hasStoredEnchants() && esmeta2.hasStoredEnchants() == false) {
|
||||
final EnchantmentStorageMeta esMeta1 = (EnchantmentStorageMeta) one.getItemMeta();
|
||||
final EnchantmentStorageMeta esMeta2 = (EnchantmentStorageMeta) two.getItemMeta();
|
||||
if (esMeta1.hasStoredEnchants() && !esMeta2.hasStoredEnchants()) {
|
||||
return -6;
|
||||
}
|
||||
if (esmeta1.getStoredEnchants().equals(esmeta2.getStoredEnchants()) == false) {
|
||||
if (!esMeta1.getStoredEnchants().equals(esMeta2.getStoredEnchants())) {
|
||||
return -6;
|
||||
}
|
||||
}
|
||||
@ -278,21 +237,21 @@ public class ItemUtil {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack stack = null;
|
||||
final ItemStack stack;
|
||||
final String[] args = data.split(":");
|
||||
String name = null;
|
||||
int amount = 0;
|
||||
short durability = 0;
|
||||
final Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
||||
final Map<Enchantment, Integer> enchs = new HashMap<>();
|
||||
String display = null;
|
||||
final LinkedList<String> lore = new LinkedList<String>();
|
||||
final LinkedList<String> lore = new LinkedList<>();
|
||||
final String[] flags = new String[10];
|
||||
final LinkedHashMap<Enchantment, Integer> stored = new LinkedHashMap<Enchantment, Integer>();
|
||||
final LinkedHashMap<Enchantment, Integer> stored = new LinkedHashMap<>();
|
||||
int potionColor = -1;
|
||||
final LinkedHashMap<String, Object> extra = new LinkedHashMap<String, Object>();
|
||||
final LinkedHashMap<String, Object> extra = new LinkedHashMap<>();
|
||||
ItemMeta meta = null;
|
||||
PotionMeta pmeta = null;
|
||||
EnchantmentStorageMeta esmeta = null;
|
||||
final PotionMeta pMeta;
|
||||
final EnchantmentStorageMeta esMeta;
|
||||
for (final String targ : args) {
|
||||
final String arg = targ.replace("minecraft|", "minecraft:");
|
||||
if (arg.equals("")) {
|
||||
@ -314,7 +273,7 @@ public class ItemUtil {
|
||||
if (e != null) {
|
||||
enchs.put(e, Integer.parseInt(temp[1]));
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Legacy enchantment name \'" + temp[0] + "\' on " + name
|
||||
Bukkit.getLogger().severe("Legacy enchantment name '" + temp[0] + "' on " + name
|
||||
+ " is invalid. Make sure it is spelled correctly");
|
||||
}
|
||||
} else {
|
||||
@ -322,12 +281,12 @@ public class ItemUtil {
|
||||
if (Enchantment.getByName(temp[0]) != null) {
|
||||
enchs.put(Enchantment.getByName(temp[0]), Integer.parseInt(temp[1]));
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Enum enchantment name \'" + temp[0] + "\' on " + name
|
||||
Bukkit.getLogger().severe("Enum enchantment name '" + temp[0] + "' on " + name
|
||||
+ " is invalid. Make sure it is spelled correctly");
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
Bukkit.getLogger().severe("The enchantment name \'" + temp[0] + "\' on " + name
|
||||
Bukkit.getLogger().severe("The enchantment name '" + temp[0] + "' on " + name
|
||||
+ " is invalid. Make sure quests.yml is UTF-8 encoded");
|
||||
return null;
|
||||
}
|
||||
@ -362,7 +321,7 @@ public class ItemUtil {
|
||||
int i = -1;
|
||||
try {
|
||||
// Num such as book generation
|
||||
i = Integer.valueOf(value);
|
||||
i = Integer.parseInt(value);
|
||||
} catch (final NumberFormatException e) {
|
||||
// Do nothing
|
||||
}
|
||||
@ -376,7 +335,7 @@ public class ItemUtil {
|
||||
} else if (value.startsWith("{") && value.endsWith("}")) {
|
||||
// For nested mappings. Does NOT handle stored enchants, see earlier code
|
||||
final String[] mapping = value.replace("{", "").replace("}", "").split(", ");
|
||||
final Map<String, String> nested = new HashMap<String, String>();
|
||||
final Map<String, String> nested = new HashMap<>();
|
||||
for (final String s : mapping) {
|
||||
if (s.contains("=")) {
|
||||
final String[] keyval = s.split("=");
|
||||
@ -395,7 +354,7 @@ public class ItemUtil {
|
||||
meta.setUnbreakable(true);
|
||||
}
|
||||
} catch (final Throwable tr) {
|
||||
// ItemMeta.setUnbrekable() not introduced until 1.11
|
||||
// ItemMeta.setUnbreakable() not introduced until 1.11
|
||||
// However, NBT tags could be set by Spigot-only methods, so show error
|
||||
Bukkit.getLogger().info("You are running a version of CraftBukkit"
|
||||
+ " for which Quests cannot set the NBT tag " + key);
|
||||
@ -407,7 +366,7 @@ public class ItemUtil {
|
||||
if (arg.contains("rgb")) {
|
||||
// Custom potion color
|
||||
final String[] mapping = arg.replace("[", "").replace("]", "").split("x");
|
||||
potionColor = Integer.valueOf(mapping[1]);
|
||||
potionColor = Integer.parseInt(mapping[1]);
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Quests does not know how to handle "
|
||||
+ arg + " so please contact the developer on Github");
|
||||
@ -423,45 +382,46 @@ public class ItemUtil {
|
||||
return null;
|
||||
}
|
||||
meta = stack.getItemMeta();
|
||||
if (!extra.isEmpty()) {
|
||||
ItemMeta toLoad = null;
|
||||
toLoad = ItemUtil.deserializeItemMeta(meta.getClass(), extra);
|
||||
if (toLoad != null) {
|
||||
meta = toLoad;
|
||||
}
|
||||
}
|
||||
if (!enchs.isEmpty()) {
|
||||
for (final Enchantment e : enchs.keySet()) {
|
||||
try {
|
||||
meta.addEnchant(e, enchs.get(e), true);
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
Bukkit.getLogger().severe("Enchantment on " + name + " cannot be null. Skipping for that quest");
|
||||
if (meta != null) {
|
||||
if (!extra.isEmpty()) {
|
||||
final ItemMeta toLoad = ItemUtil.deserializeItemMeta(meta.getClass(), extra);
|
||||
if (toLoad != null) {
|
||||
meta = toLoad;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (display != null) {
|
||||
meta.setDisplayName(display);
|
||||
}
|
||||
if (!lore.isEmpty()) {
|
||||
meta.setLore(lore);
|
||||
}
|
||||
for (final String flag : flags) {
|
||||
if (flag != null && !flag.equals("")) {
|
||||
try {
|
||||
meta.addItemFlags(ItemFlag.valueOf(flag));
|
||||
} catch (final NullPointerException npe) {
|
||||
Bukkit.getLogger().severe(flag + " is not a valid ItemFlag");
|
||||
} catch (final Throwable tr) {
|
||||
// ItemMeta.addItemFlags() not introduced until 1.8.3
|
||||
Bukkit.getLogger().info("You are running a version of CraftBukkit"
|
||||
+ " for which Quests cannot add the item flag " + flag);
|
||||
if (!enchs.isEmpty()) {
|
||||
for (final Enchantment e : enchs.keySet()) {
|
||||
try {
|
||||
meta.addEnchant(e, enchs.get(e), true);
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
Bukkit.getLogger().severe("Enchantment on " + name + " cannot be null. Skipping for that quest");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (display != null) {
|
||||
meta.setDisplayName(display);
|
||||
}
|
||||
if (!lore.isEmpty()) {
|
||||
meta.setLore(lore);
|
||||
}
|
||||
for (final String flag : flags) {
|
||||
if (flag != null && !flag.equals("")) {
|
||||
try {
|
||||
meta.addItemFlags(ItemFlag.valueOf(flag));
|
||||
} catch (final NullPointerException npe) {
|
||||
Bukkit.getLogger().severe(flag + " is not a valid ItemFlag");
|
||||
} catch (final Throwable tr) {
|
||||
// ItemMeta.addItemFlags() not introduced until 1.8.3
|
||||
Bukkit.getLogger().info("You are running a version of CraftBukkit"
|
||||
+ " for which Quests cannot add the item flag " + flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (potionColor != -1) {
|
||||
pmeta = (PotionMeta) meta;
|
||||
pMeta = (PotionMeta) meta;
|
||||
try {
|
||||
pmeta.setColor(Color.fromRGB(potionColor));
|
||||
pMeta.setColor(Color.fromRGB(potionColor));
|
||||
} catch (final Throwable tr) {
|
||||
// PotionMeta.setColor() not introduced until 1.11 (?)
|
||||
Bukkit.getLogger().info("You are running a version of CraftBukkit"
|
||||
@ -469,11 +429,13 @@ public class ItemUtil {
|
||||
}
|
||||
}
|
||||
if (stack.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
esmeta = (EnchantmentStorageMeta) meta;
|
||||
for (final Entry<Enchantment, Integer> e : stored.entrySet()) {
|
||||
esmeta.addStoredEnchant(e.getKey(), e.getValue(), true);
|
||||
esMeta = (EnchantmentStorageMeta) meta;
|
||||
if (esMeta != null) {
|
||||
for (final Entry<Enchantment, Integer> e : stored.entrySet()) {
|
||||
esMeta.addStoredEnchant(e.getKey(), e.getValue(), true);
|
||||
}
|
||||
}
|
||||
stack.setItemMeta(esmeta);
|
||||
stack.setItemMeta(esMeta);
|
||||
} else {
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
@ -500,7 +462,7 @@ public class ItemUtil {
|
||||
if (is.getDurability() != 0) {
|
||||
serial += ":data-" + is.getDurability();
|
||||
}
|
||||
if (is.getEnchantments().isEmpty() == false) {
|
||||
if (!is.getEnchantments().isEmpty()) {
|
||||
for (final Entry<Enchantment, Integer> e : is.getEnchantments().entrySet()) {
|
||||
serial += ":enchantment-" + e.getKey().getName() + " " + e.getValue();
|
||||
}
|
||||
@ -554,27 +516,28 @@ public class ItemUtil {
|
||||
* @return true display or item name, plus durability and amount, plus enchantments
|
||||
*/
|
||||
public static String getDisplayString(final ItemStack is) {
|
||||
String text;
|
||||
StringBuilder text;
|
||||
if (is == null) {
|
||||
return null;
|
||||
}
|
||||
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
|
||||
text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName() + ChatColor.RESET
|
||||
+ ChatColor.AQUA + " x " + is.getAmount();
|
||||
text = new StringBuilder("" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName()
|
||||
+ ChatColor.RESET + ChatColor.AQUA + " x " + is.getAmount());
|
||||
} else {
|
||||
text = ChatColor.AQUA + getName(is);
|
||||
text = new StringBuilder(ChatColor.AQUA + getName(is));
|
||||
if (is.getDurability() != 0) {
|
||||
text += ChatColor.AQUA + ":" + is.getDurability();
|
||||
text.append(ChatColor.AQUA).append(":").append(is.getDurability());
|
||||
}
|
||||
if (!is.getEnchantments().isEmpty()) {
|
||||
text += " " + ChatColor.GRAY + Lang.get("with") + ChatColor.DARK_PURPLE;
|
||||
text.append(" ").append(ChatColor.GRAY).append(Lang.get("with")).append(ChatColor.DARK_PURPLE);
|
||||
for (final Entry<Enchantment, Integer> e : is.getEnchantments().entrySet()) {
|
||||
text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":" + e.getValue();
|
||||
text.append(" ").append(ItemUtil.getPrettyEnchantmentName(e.getKey())).append(":")
|
||||
.append(e.getValue());
|
||||
}
|
||||
}
|
||||
text += ChatColor.AQUA + " x " + is.getAmount();
|
||||
text.append(ChatColor.AQUA).append(" x ").append(is.getAmount());
|
||||
}
|
||||
return text;
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -590,7 +553,7 @@ public class ItemUtil {
|
||||
return null;
|
||||
}
|
||||
String text;
|
||||
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
|
||||
if (is.getItemMeta() != null && is.getItemMeta().hasDisplayName()) {
|
||||
text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName() + ChatColor.RESET
|
||||
+ ChatColor.AQUA + " x " + is.getAmount();
|
||||
} else {
|
||||
@ -614,7 +577,7 @@ public class ItemUtil {
|
||||
return null;
|
||||
}
|
||||
String text = "";
|
||||
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
|
||||
if (is.getItemMeta() != null && is.getItemMeta().hasDisplayName()) {
|
||||
text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName();
|
||||
} else {
|
||||
text = ChatColor.AQUA + getPrettyItemName(is.getType().name());
|
||||
@ -645,7 +608,7 @@ public class ItemUtil {
|
||||
if (is == null) {
|
||||
return false;
|
||||
}
|
||||
if (!is.hasItemMeta()) {
|
||||
if (is.getItemMeta() == null) {
|
||||
return false;
|
||||
}
|
||||
if (!is.getItemMeta().hasDisplayName()) {
|
||||
@ -784,7 +747,7 @@ public class ItemUtil {
|
||||
|
||||
public static Enchantment getEnchantmentFromPrettyName(String enchant) {
|
||||
if (enchant != null) {
|
||||
while (MiscUtil.spaceToCapital(enchant) != null) {
|
||||
if (MiscUtil.spaceToCapital(enchant) != null) {
|
||||
enchant = MiscUtil.spaceToCapital(enchant);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import me.blackvein.quests.Dependencies;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -25,18 +26,20 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Lang {
|
||||
|
||||
private static String iso = "en-US";
|
||||
private static final LinkedHashMap<String, String> langMap = new LinkedHashMap<String, String>();
|
||||
private static final LinkedHashMap<String, String> langMap = new LinkedHashMap<>();
|
||||
private static final Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%");
|
||||
|
||||
public static String getISO() {
|
||||
@ -117,7 +120,7 @@ public class Lang {
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static void send(final Player player, String message) {
|
||||
public static void send(final Player player, final String message) {
|
||||
if (message != null && !ChatColor.stripColor(message).equals("")) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
@ -129,14 +132,14 @@ public class Lang {
|
||||
final File langFile_new = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + iso
|
||||
+ File.separator + "strings_new.yml");
|
||||
final boolean exists_new = langFile_new.exists();
|
||||
final LinkedHashMap<String, String> allStrings = new LinkedHashMap<String, String>();
|
||||
final LinkedHashMap<String, String> allStrings = new LinkedHashMap<>();
|
||||
if (langFile.exists() && iso.split("-").length > 1) {
|
||||
final FileConfiguration config= YamlConfiguration
|
||||
.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), "UTF-8"));
|
||||
.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), StandardCharsets.UTF_8));
|
||||
FileConfiguration config_new = null;
|
||||
if (exists_new) {
|
||||
config_new = YamlConfiguration
|
||||
.loadConfiguration(new InputStreamReader(new FileInputStream(langFile_new), "UTF-8"));
|
||||
config_new = YamlConfiguration.loadConfiguration(new InputStreamReader(
|
||||
new FileInputStream(langFile_new), StandardCharsets.UTF_8));
|
||||
}
|
||||
// Load user's lang file and determine new strings
|
||||
for (final String key : config.getKeys(false)) {
|
||||
@ -170,8 +173,8 @@ public class Lang {
|
||||
plugin.getLogger()
|
||||
.info("For help, visit https://github.com/PikaMug/Quests/wiki/Casual-%E2%80%90-Translations");
|
||||
iso = "en-US";
|
||||
final FileConfiguration config = YamlConfiguration
|
||||
.loadConfiguration(new InputStreamReader(plugin.getResource("strings.yml"), "UTF-8"));
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects
|
||||
.requireNonNull(plugin.getResource("strings.yml")), StandardCharsets.UTF_8));
|
||||
for (final String key : config.getKeys(false)) {
|
||||
allStrings.put(key, config.getString(key));
|
||||
}
|
||||
@ -214,7 +217,7 @@ public class Lang {
|
||||
|
||||
private static class LangToken {
|
||||
|
||||
static Map<String, String> tokenMap = new HashMap<String, String>();
|
||||
static Map<String, String> tokenMap = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
tokenMap.put("%br%", "\n");
|
||||
@ -257,7 +260,7 @@ public class Lang {
|
||||
final StringBuilder hex = new StringBuilder();
|
||||
hex.append(ChatColor.COLOR_CHAR + "x");
|
||||
final char[] chars = matcher.group(1).toCharArray();
|
||||
for (char aChar : chars) {
|
||||
for (final char aChar : chars) {
|
||||
hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(aChar));
|
||||
}
|
||||
s = s.replace(matcher.group(), hex.toString());
|
||||
@ -271,7 +274,7 @@ public class Lang {
|
||||
}
|
||||
s = convertString(s);
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null ) {
|
||||
if (!Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI").isEnabled()) {
|
||||
if (Dependencies.placeholder.isEnabled()) {
|
||||
s = PlaceholderAPI.setPlaceholders(p, s);
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,14 @@
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MiscUtil {
|
||||
|
||||
/**
|
||||
@ -91,8 +91,7 @@ public class MiscUtil {
|
||||
}
|
||||
final String firstLetter = input.substring(0, 1);
|
||||
final String remainder = input.substring(1);
|
||||
final String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();
|
||||
return capitalized;
|
||||
return firstLetter.toUpperCase() + remainder.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +121,7 @@ public class MiscUtil {
|
||||
/**
|
||||
* Convert text from snake_case to UpperCamelCase
|
||||
*
|
||||
* @param type To convert
|
||||
* @param input To convert
|
||||
* @return Converted text
|
||||
*/
|
||||
public static String snakeCaseToUpperCamelCase(final String input) {
|
||||
@ -186,7 +185,7 @@ public class MiscUtil {
|
||||
/**
|
||||
* Gets player-friendly name from type. 'LIGHT_BLUE' becomes 'Light Blue'
|
||||
*
|
||||
* @param type any dye type, ideally
|
||||
* @param color any dye type, ideally
|
||||
* @return cleaned-up string, or 'White' if null
|
||||
*/
|
||||
public static String getPrettyDyeColorName(final DyeColor color) {
|
||||
@ -253,32 +252,33 @@ public class MiscUtil {
|
||||
* @param lineColor Color to use at start of each new line
|
||||
* @return Converted text
|
||||
*/
|
||||
public static LinkedList<String> makeLines(final String input, final String wordDelimiter, final int lineLength
|
||||
, final ChatColor lineColor) {
|
||||
final LinkedList<String> toReturn = new LinkedList<String>();
|
||||
public static LinkedList<String> makeLines(final String input, final String wordDelimiter, final int lineLength,
|
||||
final ChatColor lineColor) {
|
||||
final LinkedList<String> toReturn = new LinkedList<>();
|
||||
final String[] split = input.split(wordDelimiter);
|
||||
String line = "";
|
||||
StringBuilder line = new StringBuilder();
|
||||
int currentLength = 0;
|
||||
for (final String piece : split) {
|
||||
if ((currentLength + piece.length()) > (lineLength + 1)) {
|
||||
// TODO - determine whether replaceAll and carots (^) are necessary here
|
||||
final String s = line.toString().replaceAll("^" + wordDelimiter, "");
|
||||
if (lineColor != null) {
|
||||
toReturn.add(lineColor + line.replaceAll("^" + wordDelimiter, ""));
|
||||
toReturn.add(lineColor + s);
|
||||
} else {
|
||||
toReturn.add(line.replaceAll("^" + wordDelimiter, ""));
|
||||
toReturn.add(s);
|
||||
}
|
||||
line = piece + wordDelimiter;
|
||||
line = new StringBuilder(piece + wordDelimiter);
|
||||
currentLength = piece.length() + 1;
|
||||
} else {
|
||||
line += piece + wordDelimiter;
|
||||
line.append(piece).append(wordDelimiter);
|
||||
currentLength += piece.length() + 1;
|
||||
}
|
||||
}
|
||||
if (line.equals("") == false)
|
||||
if (!line.toString().equals(""))
|
||||
if (lineColor != null) {
|
||||
toReturn.add(lineColor + line);
|
||||
toReturn.add(lineColor + line.toString());
|
||||
} else {
|
||||
toReturn.add(line);
|
||||
toReturn.add(line.toString());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
@ -288,7 +288,7 @@ public class MiscUtil {
|
||||
*
|
||||
* Unused internally. Left for external use
|
||||
*
|
||||
* @param s string to process
|
||||
* @param input string to process
|
||||
* @return processed string
|
||||
*/
|
||||
public static String capitalsToSpaces(String input) {
|
||||
@ -306,7 +306,7 @@ public class MiscUtil {
|
||||
/**
|
||||
* Capitalize character after space
|
||||
*
|
||||
* @param s string to process
|
||||
* @param input string to process
|
||||
* @return processed string
|
||||
*/
|
||||
public static String spaceToCapital(String input) {
|
||||
|
@ -16,7 +16,7 @@ import java.util.TreeMap;
|
||||
|
||||
public class RomanNumeral {
|
||||
|
||||
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
|
||||
private final static TreeMap<Integer, String> map = new TreeMap<>();
|
||||
|
||||
static {
|
||||
map.put(1000, "M");
|
||||
@ -34,7 +34,7 @@ public class RomanNumeral {
|
||||
map.put(1, "I");
|
||||
}
|
||||
|
||||
public final static String getNumeral(final int number) {
|
||||
public static String getNumeral(final int number) {
|
||||
final int l = map.floorKey(number);
|
||||
if ( number == l ) {
|
||||
return map.get(number);
|
||||
|
Loading…
Reference in New Issue
Block a user