Don't broadcast announcers to players in an instance world

This commit is contained in:
Daniel Saukel 2016-12-20 20:04:50 +01:00
parent 9daa1abb2f
commit ac4c807da6
2 changed files with 30 additions and 27 deletions

View File

@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.announcer.Announcer; import io.github.dre2n.dungeonsxl.announcer.Announcer;
import io.github.dre2n.dungeonsxl.announcer.Announcers; import io.github.dre2n.dungeonsxl.announcer.Announcers;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -44,7 +46,8 @@ public class AnnouncerTask extends BukkitRunnable {
Announcer announcer = announcers.get(index); Announcer announcer = announcers.get(index);
List<String> worlds = announcer.getWorlds(); List<String> worlds = announcer.getWorlds();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (plugin.getDPlayers().getByPlayer(player).isAnnouncerEnabled()) { DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
if (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) {
if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) { if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) {
announcer.send(player); announcer.send(player);
} }

View File

@ -40,7 +40,7 @@ import org.bukkit.inventory.ItemStack;
* @author Frank Baumann, Daniel Saukel * @author Frank Baumann, Daniel Saukel
*/ */
public class RewardChest extends GameBlock { public class RewardChest extends GameBlock {
static DungeonsXL plugin = DungeonsXL.getInstance(); static DungeonsXL plugin = DungeonsXL.getInstance();
// Variables // Variables
@ -49,14 +49,14 @@ public class RewardChest extends GameBlock {
private double moneyReward; private double moneyReward;
private int levelReward; private int levelReward;
private ItemStack[] itemReward; private ItemStack[] itemReward;
public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) {
super(chest); super(chest);
if (!(chest.getState() instanceof Chest)) { if (!(chest.getState() instanceof Chest)) {
return; return;
} }
this.chest = (Chest) chest.getState(); this.chest = (Chest) chest.getState();
this.moneyReward = moneyReward; this.moneyReward = moneyReward;
this.levelReward = levelReward; this.levelReward = levelReward;
@ -138,77 +138,77 @@ public class RewardChest extends GameBlock {
MessageUtil.sendMessage(plugin.getServer().getPlayer(opener.getUniqueId()), DMessages.ERROR_CHEST_IS_OPENED.getMessage()); MessageUtil.sendMessage(plugin.getServer().getPlayer(opener.getUniqueId()), DMessages.ERROR_CHEST_IS_OPENED.getMessage());
return; return;
} }
if (chest.getLocation().distance(chest.getLocation()) < 1) { if (chest.getLocation().distance(chest.getLocation()) < 1) {
addTreasure(DGroup.getByPlayer(opener)); addTreasure(DGroup.getByPlayer(opener));
used = true; used = true;
} }
} }
public void addTreasure(DGroup dGroup) { public void addTreasure(DGroup dGroup) {
if (dGroup == null) { if (dGroup == null) {
return; return;
} }
boolean hasMoneyReward = false; boolean hasMoneyReward = false;
boolean hasLevelReward = false; boolean hasLevelReward = false;
boolean hasItemReward = false; boolean hasItemReward = false;
for (Reward reward : dGroup.getRewards()) { for (Reward reward : dGroup.getRewards()) {
if (reward.getType() == RewardTypeDefault.MONEY) { if (reward.getType() == RewardTypeDefault.MONEY) {
hasMoneyReward = true; hasMoneyReward = true;
((MoneyReward) reward).addMoney(moneyReward); ((MoneyReward) reward).addMoney(moneyReward);
} else if (reward.getType() == RewardTypeDefault.LEVEL) { } else if (reward.getType() == RewardTypeDefault.LEVEL) {
hasLevelReward = true; hasLevelReward = true;
((LevelReward) reward).addLevels(levelReward); ((LevelReward) reward).addLevels(levelReward);
} else if (reward.getType() == RewardTypeDefault.ITEM) { } else if (reward.getType() == RewardTypeDefault.ITEM) {
hasItemReward = true; hasItemReward = true;
((ItemReward) reward).addItems(itemReward); ((ItemReward) reward).addItems(itemReward);
} }
} }
if (!hasMoneyReward) { if (!hasMoneyReward) {
Reward reward = Reward.create(RewardTypeDefault.MONEY); Reward reward = Reward.create(RewardTypeDefault.MONEY);
((MoneyReward) reward).addMoney(moneyReward); ((MoneyReward) reward).addMoney(moneyReward);
dGroup.addReward(reward); dGroup.addReward(reward);
} }
if (!hasLevelReward) { if (!hasLevelReward) {
Reward reward = Reward.create(RewardTypeDefault.LEVEL); Reward reward = Reward.create(RewardTypeDefault.LEVEL);
((LevelReward) reward).addLevels(levelReward); ((LevelReward) reward).addLevels(levelReward);
dGroup.addReward(reward); dGroup.addReward(reward);
} }
if (!hasItemReward) { if (!hasItemReward) {
Reward reward = Reward.create(RewardTypeDefault.ITEM); Reward reward = Reward.create(RewardTypeDefault.ITEM);
((ItemReward) reward).addItems(itemReward); ((ItemReward) reward).addItems(itemReward);
dGroup.addReward(reward); dGroup.addReward(reward);
} }
for (Player player : dGroup.getPlayers()) { for (Player player : dGroup.getPlayers()) {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) { if (dPlayer == null) {
continue; continue;
} }
if (itemReward != null) { if (itemReward != null) {
String msg = ""; String msg = "";
for (ItemStack itemStack : itemReward) { for (ItemStack itemStack : itemReward) {
if (itemStack == null) { if (itemStack == null) {
continue; continue;
} }
String name = null; String name = null;
if (itemStack.hasItemMeta()) { if (itemStack.hasItemMeta()) {
if (itemStack.getItemMeta().hasDisplayName()) { if (itemStack.getItemMeta().hasDisplayName()) {
name = itemStack.getItemMeta().getDisplayName(); name = itemStack.getItemMeta().getDisplayName();
} }
} }
if (name == null) { if (name == null) {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) { if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
ItemInfo itemInfo = Items.itemByStack(itemStack); ItemInfo itemInfo = Items.itemByStack(itemStack);
@ -217,30 +217,30 @@ public class RewardChest extends GameBlock {
} else { } else {
name = itemStack.getType().name(); name = itemStack.getType().name();
} }
} else { } else {
name = itemStack.getType().toString(); name = itemStack.getType().toString();
} }
} }
msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ","; msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ",";
} }
if (msg.length() >= 1) { if (msg.length() >= 1) {
msg = msg.substring(0, msg.length() - 1); msg = msg.substring(0, msg.length() - 1);
} }
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(msg)); MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(msg));
} }
if (moneyReward != 0 && plugin.getEconomyProvider() != null) { if (moneyReward != 0 && plugin.getEconomyProvider() != null) {
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward))); MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward)));
} }
if (levelReward != 0) { if (levelReward != 0) {
MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(levelReward + " levels")); MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(levelReward + " levels"));
} }
} }
} }
} }