Do not send empty language strings, see #1738

This commit is contained in:
PikaMug 2021-07-11 05:06:13 -04:00
parent c760f1b82b
commit d064a14574
8 changed files with 127 additions and 97 deletions

View File

@ -557,9 +557,7 @@ public class Quest implements Comparable<Quest> {
}
}
quester.hardQuit(this);
if (!quester.completedQuests.contains(this)) {
quester.completedQuests.add(this);
}
quester.completedQuests.add(this);
for (final Map.Entry<Integer, Quest> entry : quester.timers.entrySet()) {
if (entry.getValue().getName().equals(getName())) {
plugin.getServer().getScheduler().cancelTask(entry.getKey());
@ -616,6 +614,9 @@ public class Quest implements Comparable<Quest> {
}
}
for (final String s : rews.getCommands()) {
if (player.getName() == null) {
continue;
}
String temp = s.replace("<player>", player.getName());
if (depends.getPlaceholderApi() != null && player.isOnline()) {
temp = PlaceholderAPI.setPlaceholders((Player)player, temp);
@ -760,7 +761,7 @@ public class Quest implements Comparable<Quest> {
// Inform player
if (player.isOnline()) {
final Player p = (Player)player;
quester.sendMessage(ChatColor.GOLD + Lang.get(p, "questCompleteTitle").replace("<quest>",
Lang.send(p, ChatColor.GOLD + Lang.get(p, "questCompleteTitle").replace("<quest>",
ChatColor.YELLOW + name + ChatColor.GOLD));
if (plugin.getSettings().canShowQuestTitles()) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName()
@ -769,7 +770,7 @@ public class Quest implements Comparable<Quest> {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "title " + player.getName()
+ " subtitle " + "{\"text\":\"" + name + "\",\"color\":\"yellow\"}");
}
p.sendMessage(ChatColor.GREEN + Lang.get(p, "questRewardsTitle"));
Lang.send(p, ChatColor.GREEN + Lang.get(p, "questRewardsTitle"));
if (!issuedReward) {
p.sendMessage(ChatColor.GRAY + "- (" + Lang.get("none") + ")");
} else if (!rews.getDetailsOverride().isEmpty()) {

View File

@ -580,7 +580,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (quester.saveData()) {
getLogger().info("Created new data for player " + player.getName());
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "questSaveError"));
Lang.send(player, ChatColor.RED + Lang.get(player, "questSaveError"));
}
}
final String questIdToTake = quester.questIdToTake;
@ -598,13 +598,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
return Prompt.END_OF_CONVERSATION;
} else if (s != null && s.equalsIgnoreCase(Lang.get("noWord"))) {
player.sendMessage(ChatColor.YELLOW + Lang.get("cancelled"));
Lang.send(player, ChatColor.YELLOW + Lang.get("cancelled"));
return Prompt.END_OF_CONVERSATION;
} else {
final String msg = Lang.get(player, "questInvalidChoice")
.replace("<yes>", Lang.get(player, "yesWord"))
.replace("<no>", Lang.get(player, "noWord"));
player.sendMessage(ChatColor.RED + msg);
Lang.send(player, ChatColor.RED + msg);
return new QuestAcceptPrompt();
}
}
@ -1501,9 +1501,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
if ((available.size() + rows) <= (page * rows) || available.size() == 0) {
quester.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
} else {
quester.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questListTitle"));
int fromOrder = (page - 1) * rows;
List<Quest> subQuests;
if (available.size() >= (fromOrder + rows)) {
@ -1524,13 +1524,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
String msg = Lang.get(player, "pageFooter");
msg = msg.replace("<current>", String.valueOf(page));
msg = msg.replace("<all>", String.valueOf(numPages));
quester.sendMessage(ChatColor.GOLD + msg);
Lang.send(player, ChatColor.GOLD + msg);
}
} else {
if ((quests.size() + rows) <= (page * rows) || quests.size() == 0) {
quester.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "pageNotExist"));
} else {
quester.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle"));
Lang.send(player, ChatColor.GOLD + Lang.get(player, "questListTitle"));
int fromOrder = (page - 1) * rows;
List<Quest> subQuests;
if (quests.size() >= (fromOrder + rows)) {
@ -1541,9 +1541,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
fromOrder++;
for (final Quest q : subQuests) {
if (quester.canAcceptOffer(q, false)) {
quester.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName());
Lang.send(player, ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName());
} else {
quester.sendMessage(ChatColor.GRAY + Integer.toString(fromOrder) + ". " + q.getName());
Lang.send(player, ChatColor.GRAY + Integer.toString(fromOrder) + ". " + q.getName());
}
fromOrder++;
}
@ -1551,7 +1551,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
String msg = Lang.get(player, "pageFooter");
msg = msg.replace("<current>", String.valueOf(page));
msg = msg.replace("<all>", String.valueOf(numPages));
quester.sendMessage(ChatColor.GOLD + msg);
Lang.send(player, ChatColor.GOLD + msg);
}
}
}

View File

@ -75,7 +75,7 @@ public class BlockListener implements Listener {
if (quester.getCurrentStage(quest).containsObjective(breakType)) {
if (quest.getOptions().canIgnoreSilkTouch()
&& player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
player.sendMessage(ChatColor.RED + Lang.get(player, "optionSilkTouchFail")
Lang.send(player, ChatColor.RED + Lang.get(player, "optionSilkTouchFail")
.replace("<quest>", quest.getName()));
} else {
quester.breakBlock(quest, blockItemStack);
@ -249,7 +249,7 @@ public class BlockListener implements Listener {
return;
}
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (evt.isCancelled() == false) {
if (!evt.isCancelled()) {
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt
.getClickedBlock().getState().getData().toItemStack().getDurability());
final ObjectiveType type = ObjectiveType.USE_BLOCK;

View File

@ -205,7 +205,7 @@ public class CmdExecutor implements CommandExecutor {
if (plugin.getQuester(player.getUniqueId()).getQuestData(q).getDelayStartTime() == 0) {
final String msg = Lang.get(player, "questObjectivesTitle")
.replace("<quest>", q.getName());
quester.sendMessage(ChatColor.GOLD + msg);
Lang.send(player, ChatColor.GOLD + msg);
plugin.showObjectives(q, quester, false);
} else {
final long time = plugin.getQuester(player.getUniqueId()).getStageTime(q);
@ -213,11 +213,11 @@ public class CmdExecutor implements CommandExecutor {
+ Lang.get(player, "plnTooEarly");
msg = msg.replace("<quest>", q.getName());
msg = msg.replace("<time>", MiscUtil.getTime(time));
quester.sendMessage(msg);
Lang.send(player, msg);
}
}
} else {
quester.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
}
} else {
showQuestDetails(cs, args);
@ -686,12 +686,12 @@ public class CmdExecutor implements CommandExecutor {
final int index = quester.getJournalIndex();
if (index != -1) {
inv.setItem(index, null);
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalPutAway")
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)) {
final QuestJournal journal = new QuestJournal(quester);
player.setItemInHand(journal.toItemStack());
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalTaken")
.replace("<journal>", Lang.get(player, "journalTitle")));
//quester.updateJournal();
} else if (inv.firstEmpty() != -1) {
@ -700,14 +700,14 @@ public class CmdExecutor implements CommandExecutor {
if (arr[i] == null) {
final QuestJournal journal = new QuestJournal(quester);
inv.setItem(i, journal.toItemStack());
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalTaken")
.replace("<journal>", Lang.get(player, "journalTitle")));
//quester.updateJournal();
break;
}
}
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalNoRoom")
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "journalNoRoom")
.replace("<journal>", Lang.get(player, "journalTitle")));
}
}
@ -716,11 +716,11 @@ public class CmdExecutor implements CommandExecutor {
private void questsQuit(final Player player, final String[] args) {
if (player.hasPermission("quests.quit")) {
if (args.length == 1) {
player.sendMessage(ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP"));
Lang.send(player, ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP"));
return;
}
final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester.getCurrentQuests().isEmpty() == false) {
if (!quester.getCurrentQuests().isEmpty()) {
final Quest quest = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
if (quest != null) {
if (quest.getOptions().canAllowQuitting()) {
@ -733,45 +733,45 @@ public class CmdExecutor implements CommandExecutor {
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW);
quester.quitQuest(quest, msg);
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questQuitDisabled"));
}
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "questNotFound"));
Lang.send(player, ChatColor.RED + Lang.get(player, "questNotFound"));
}
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
}
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "noPermission"));
Lang.send(player, ChatColor.RED + Lang.get(player, "noPermission"));
}
}
private void questsTake(final Player player, final String[] args) {
if (plugin.getSettings().canAllowCommands() == true) {
if (plugin.getSettings().canAllowCommands()) {
if (player.hasPermission("quests.take")) {
if (args.length == 1) {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE"));
} else {
final Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
final Quester quester = plugin.getQuester(player.getUniqueId());
if (questToFind != null) {
for (final Quest q : quester.getCurrentQuests().keySet()) {
if (q.getId().equals(questToFind.getId())) {
player.sendMessage(ChatColor.RED + Lang.get(player, "questAlreadyOn"));
Lang.send(player, ChatColor.RED + Lang.get(player, "questAlreadyOn"));
return;
}
}
//quester.setQuestToTake(questToFind);
quester.offerQuest(questToFind, true);
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questNotFound"));
}
}
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "noPermission"));
Lang.send(player, ChatColor.RED + Lang.get(player, "noPermission"));
}
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questTakeDisabled"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questTakeDisabled"));
}
}

View File

@ -28,14 +28,16 @@ public class DungeonsListener implements Listener {
@EventHandler
public void onGroupCreate(final GroupCreateEvent event) {
if (Lang.get("questDungeonsCreate").length() > 0) {
event.getCreator().sendMessage(ChatColor.YELLOW + Lang.get("questDungeonsCreate"));
final Player p = event.getCreator().getPlayer();
Lang.send(p, ChatColor.YELLOW + Lang.get("questDungeonsCreate"));
}
}
@EventHandler
public void onGroupDisbandEvent(final GroupDisbandEvent event) {
if (Lang.get("questDungeonsDisband").length() > 0) {
event.getDisbander().sendMessage(ChatColor.RED + Lang.get("questDungeonsDisband"));
final Player p = event.getDisbander().getPlayer();
Lang.send(p, ChatColor.RED + Lang.get("questDungeonsDisband"));
}
}
@ -46,11 +48,11 @@ public class DungeonsListener implements Listener {
final Player p = event.getPlayer().getPlayer();
if (i != null && p != null) {
if (Lang.get("questDungeonsInvite").length() > 0) {
i.sendMessage(ChatColor.GREEN + Lang.get(i, "questDungeonsInvite")
Lang.send(i, ChatColor.GREEN + Lang.get(i, "questDungeonsInvite")
.replace("<player>", p.getName()));
}
if (Lang.get("questDungeonsJoin").length() > 0) {
p.sendMessage(ChatColor.GREEN + Lang.get(p, "questDungeonsJoin").replace("<player>", i.getName()));
Lang.send(p, ChatColor.GREEN + Lang.get(p, "questDungeonsJoin").replace("<player>", i.getName()));
}
}
}
@ -63,10 +65,10 @@ public class DungeonsListener implements Listener {
final Player p = event.getPlayer().getPlayer();
if (k != null && p != null) {
if (Lang.get("questDungeonsKicked").length() > 0) {
k.sendMessage(ChatColor.RED + Lang.get(k, "questDungeonsKicked").replace("<player>", k.getName()));
Lang.send(k, ChatColor.RED + Lang.get(k, "questDungeonsKicked").replace("<player>", k.getName()));
}
if (Lang.get("questDungeonsLeave").length() > 0) {
p.sendMessage(ChatColor.RED + Lang.get(p, "questDungeonsLeave").replace("<player>", p.getName()));
Lang.send(p, ChatColor.RED + Lang.get(p, "questDungeonsLeave").replace("<player>", p.getName()));
}
}
}

View File

@ -32,7 +32,7 @@ public class PartiesListener implements Listener {
final Player p = Bukkit.getServer().getPlayer(event.getCreator().getPlayerUUID());
if (p != null) {
if (Lang.get("questPartiesCreate").length() > 0) {
p.sendMessage(ChatColor.YELLOW + Lang.get("questPartiesCreate"));
Lang.send(p, ChatColor.YELLOW + Lang.get("questPartiesCreate"));
}
}
}
@ -42,7 +42,7 @@ public class PartiesListener implements Listener {
public void onPlayerJoinEvent(final BukkitPartiesPlayerPostJoinEvent event) {
final Player p = Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID());
if (p != null && Lang.get("questPartiesLeave").length() > 0) {
p.sendMessage(ChatColor.GREEN + Lang.get(p, "questPartiesJoin"));
Lang.send(p, ChatColor.GREEN + Lang.get(p, "questPartiesJoin"));
event.getParty().broadcastMessage(ChatColor.GREEN + Lang.get("questPartiesJoinBroadcast").replace("<player>", event.getPartyPlayer().getName()), event.getPartyPlayer());
}
}
@ -51,7 +51,7 @@ public class PartiesListener implements Listener {
public void onPlayerLeaveEvent(final BukkitPartiesPlayerPostLeaveEvent event) {
final Player p = Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID());
if (p != null && Lang.get("questPartiesLeave").length() > 0) {
p.sendMessage(ChatColor.RED + Lang.get(p, "questPartiesLeave"));
Lang.send(p, ChatColor.RED + Lang.get(p, "questPartiesLeave"));
event.getParty().broadcastMessage(ChatColor.RED + Lang.get("questPartiesLeaveBroadcast").replace("<player>", event.getPartyPlayer().getName()), event.getPartyPlayer());
}
}

View File

@ -180,17 +180,21 @@ public class PlayerListener implements Listener {
}
if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand)
if (ItemUtil.isJournal(evt.getPlayer().getItemInHand())) {
final Player player = evt.getPlayer();
if (evt.hasBlock()) {
if (evt.getClickedBlock() == null) {
return;
}
if (evt.getClickedBlock().getType().name().equals("LECTERN")) {
evt.setCancelled(true);
evt.getPlayer().sendMessage(ChatColor.RED + Lang.get(evt.getPlayer(), "journalDenied")
Lang.send(player, ChatColor.RED + Lang.get(evt.getPlayer(), "journalDenied")
.replace("<journal>", Lang.get(evt.getPlayer(), "journalTitle")));
return;
}
if (plugin.getSettings().canAllowPranks()
&& evt.getClickedBlock().getType().name().contains("PORTAL")) {
evt.setCancelled(true);
evt.getPlayer().sendMessage(" " + ChatColor.AQUA + ChatColor.UNDERLINE
Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
return;
}
@ -200,7 +204,7 @@ public class PlayerListener implements Listener {
&& (evt.getPlayer().getInventory().getHelmet().getType().name().equals("PUMPKIN")
|| evt.getPlayer().getInventory().getHelmet().getType().name().equals("CARVED_PUMPKIN"))) {
if (!evt.getAction().equals(Action.RIGHT_CLICK_AIR)) {
evt.getPlayer().sendMessage(" " + ChatColor.AQUA + ChatColor.UNDERLINE
Lang.send(player, " " + ChatColor.AQUA + ChatColor.UNDERLINE
+ "https://www.youtube.com/watch?v=v4IC7qaNr7I");
}
evt.setCancelled(true);
@ -224,11 +228,14 @@ public class PlayerListener implements Listener {
if (plugin.getQuestFactory().getSelectedBlockStarts().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedBlockStarts();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getQuestFactory().setSelectedBlockStarts(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation")
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 + ")");
@ -236,11 +243,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getActionFactory().getSelectedExplosionLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedExplosionLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getActionFactory().setSelectedExplosionLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -248,11 +258,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getActionFactory().getSelectedEffectLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedEffectLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getActionFactory().setSelectedEffectLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -260,11 +273,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getActionFactory().getSelectedMobLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedMobLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getActionFactory().setSelectedMobLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -272,11 +288,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getActionFactory().getSelectedLightningLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedLightningLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getActionFactory().setSelectedLightningLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -284,11 +303,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getActionFactory().getSelectedTeleportLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getActionFactory().getSelectedTeleportLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getActionFactory().setSelectedTeleportLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -296,11 +318,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getQuestFactory().getSelectedKillLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedKillLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getQuestFactory().setSelectedKillLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -308,11 +333,14 @@ public class PlayerListener implements Listener {
} else if (plugin.getQuestFactory().getSelectedReachLocations().containsKey(evt.getPlayer()
.getUniqueId())) {
final Block block = evt.getClickedBlock();
if (block == null) {
return;
}
final Location loc = block.getLocation();
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedReachLocations();
temp.put(evt.getPlayer().getUniqueId(), block);
temp.put(player.getUniqueId(), block);
plugin.getQuestFactory().setSelectedReachLocations(temp);
evt.getPlayer().sendMessage(ChatColor.GOLD + Lang.get(player, "questSelectedLocation") + " "
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 + ")");
@ -326,7 +354,7 @@ public class PlayerListener implements Listener {
String msg = Lang.get(player, "questMaxAllowed");
msg = msg.replace("<number>", String
.valueOf(plugin.getSettings().getMaxQuests()));
player.sendMessage(ChatColor.YELLOW + msg);
Lang.send(player, ChatColor.YELLOW + msg);
} else {
if (quester.getCompletedQuests().contains(q)) {
if (q.getPlanner().getCooldown() > -1
@ -337,14 +365,14 @@ public class PlayerListener implements Listener {
early = early.replace("<time>", ChatColor.DARK_PURPLE
+ MiscUtil.getTime(quester.getCooldownDifference(q))
+ ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early);
Lang.send(player, ChatColor.YELLOW + early);
continue;
} else if (quester.getCompletedQuests().contains(q)
&& q.getPlanner().getCooldown() < 0) {
String completed = Lang.get(player, "questAlreadyCompleted");
completed = completed.replace("<quest>", ChatColor.AQUA
+ q.getName() + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + completed);
Lang.send(player, ChatColor.YELLOW + completed);
continue;
}
}
@ -357,7 +385,7 @@ public class PlayerListener implements Listener {
+ quest.getName() + ChatColor.GOLD + " -\n" + "\n"
+ ChatColor.RESET + quest.getDescription() + "\n";
for (final String msg : s.split("<br>")) {
player.sendMessage(msg);
Lang.send(player, msg);
}
plugin.getConversationFactory().buildConversation(player).begin();
}
@ -376,7 +404,7 @@ public class PlayerListener implements Listener {
if (evt.getAction().equals(Action.LEFT_CLICK_AIR)
|| evt.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
quester.resetCompass();
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "compassReset"));
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "compassReset"));
} else if (evt.getAction().equals(Action.RIGHT_CLICK_AIR)
|| evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
quester.findNextCompassTarget(true);
@ -390,10 +418,11 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerInteractEntity(final PlayerInteractEntityEvent evt) {
if (evt.getRightClicked().getType() == EntityType.ITEM_FRAME) {
if (ItemUtil.isJournal(evt.getPlayer().getItemInHand())) {
final Player player = evt.getPlayer();
if (ItemUtil.isJournal(player.getItemInHand())) {
evt.setCancelled(true);
evt.getPlayer().sendMessage(ChatColor.RED + Lang.get(evt.getPlayer(), "journalDenied")
.replace("<journal>", Lang.get(evt.getPlayer(), "journalTitle")));
Lang.send(player, ChatColor.RED + Lang.get(player, "journalDenied")
.replace("<journal>", Lang.get(player, "journalTitle")));
}
}
}
@ -488,10 +517,11 @@ public class PlayerListener implements Listener {
for (final Quest quest : quester.getCurrentQuests().keySet()) {
if (!quest.getOptions().canAllowCommands()) {
if (!evt.getMessage().startsWith("/quest")) {
evt.getPlayer().sendMessage(ChatColor.RED + Lang.get(evt.getPlayer(), "optCommandsDenied")
final Player player = evt.getPlayer();
Lang.send(player, ChatColor.RED + Lang.get(player, "optCommandsDenied")
.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED));
evt.setCancelled(true);
plugin.getLogger().info("Player " + evt.getPlayer().getName() + " tried to use command "
plugin.getLogger().info("Player " + player.getName() + " tried to use command "
+ evt.getMessage() + " but was denied because they are currently on quest "
+ quest.getName());
return;

View File

@ -12,6 +12,15 @@
package me.blackvein.quests.util;
import me.blackvein.quests.Quests;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -24,21 +33,11 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import me.blackvein.quests.Quests;
import me.clip.placeholderapi.PlaceholderAPI;
public class Lang {
private static String iso = "en-US";
private static final LinkedHashMap<String, String> langMap = new LinkedHashMap<String, String>();
private static Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%");
private static final Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%");
public static String getISO() {
return iso;
@ -55,12 +54,12 @@ public class Lang {
/**
* Get lang string AND pass Player for use with PlaceholderAPI, if installed
*
* @param p the Player whom will receive the string
* @param player the Player whom will receive the string
* @param key label as it appears in lang file, such as "journalNoQuests"
* @return formatted string, plus processing through PlaceholderAPI by clip
*/
public static String get(final Player p, final String key) {
return langMap.containsKey(key) ? LangToken.convertString(p, langMap.get(key)) : "NULL";
public static String get(final Player player, final String key) {
return langMap.containsKey(key) ? LangToken.convertString(player, langMap.get(key)) : "NULL";
}
/**
@ -118,12 +117,10 @@ public class Lang {
return orig;
}
/**
* @deprecated Use {@link #init(Quests)}
*/
@Deprecated
public static void loadLang(final Quests plugin) throws InvalidConfigurationException, IOException {
init(plugin);
public static void send(final Player player, String message) {
if (message != null && !ChatColor.stripColor(message).equals("")) {
player.sendMessage(message);
}
}
public static void init(final Quests plugin) throws InvalidConfigurationException, IOException {
@ -260,8 +257,8 @@ public class Lang {
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 (char aChar : chars) {
hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(aChar));
}
s = s.replace(matcher.group(), hex.toString());
}