From ac4c807da6805a02323490da52b8ca5655b23d19 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 20 Dec 2016 20:04:50 +0100 Subject: [PATCH] Don't broadcast announcers to players in an instance world --- .../dre2n/dungeonsxl/task/AnnouncerTask.java | 5 +- .../dungeonsxl/world/block/RewardChest.java | 52 +++++++++---------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java b/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java index f8701dab..6fc3d9b4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/task/AnnouncerTask.java @@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.task; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.announcer.Announcer; 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 org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -44,7 +46,8 @@ public class AnnouncerTask extends BukkitRunnable { Announcer announcer = announcers.get(index); List worlds = announcer.getWorlds(); 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())) { announcer.send(player); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java index 711a43cd..eba09ae8 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/block/RewardChest.java @@ -40,7 +40,7 @@ import org.bukkit.inventory.ItemStack; * @author Frank Baumann, Daniel Saukel */ public class RewardChest extends GameBlock { - + static DungeonsXL plugin = DungeonsXL.getInstance(); // Variables @@ -49,14 +49,14 @@ public class RewardChest extends GameBlock { private double moneyReward; private int levelReward; private ItemStack[] itemReward; - + public RewardChest(Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { super(chest); - + if (!(chest.getState() instanceof Chest)) { return; } - + this.chest = (Chest) chest.getState(); this.moneyReward = moneyReward; 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()); return; } - + if (chest.getLocation().distance(chest.getLocation()) < 1) { addTreasure(DGroup.getByPlayer(opener)); used = true; } } - + public void addTreasure(DGroup dGroup) { if (dGroup == null) { return; } - + boolean hasMoneyReward = false; boolean hasLevelReward = false; boolean hasItemReward = false; - + for (Reward reward : dGroup.getRewards()) { if (reward.getType() == RewardTypeDefault.MONEY) { hasMoneyReward = true; ((MoneyReward) reward).addMoney(moneyReward); - + } else if (reward.getType() == RewardTypeDefault.LEVEL) { hasLevelReward = true; ((LevelReward) reward).addLevels(levelReward); - + } else if (reward.getType() == RewardTypeDefault.ITEM) { hasItemReward = true; ((ItemReward) reward).addItems(itemReward); } } - + if (!hasMoneyReward) { Reward reward = Reward.create(RewardTypeDefault.MONEY); ((MoneyReward) reward).addMoney(moneyReward); dGroup.addReward(reward); } - + if (!hasLevelReward) { Reward reward = Reward.create(RewardTypeDefault.LEVEL); ((LevelReward) reward).addLevels(levelReward); dGroup.addReward(reward); } - + if (!hasItemReward) { Reward reward = Reward.create(RewardTypeDefault.ITEM); ((ItemReward) reward).addItems(itemReward); dGroup.addReward(reward); } - + for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = DGamePlayer.getByPlayer(player); if (dPlayer == null) { continue; } - + if (itemReward != null) { String msg = ""; for (ItemStack itemStack : itemReward) { - + if (itemStack == null) { continue; } - + String name = null; - + if (itemStack.hasItemMeta()) { if (itemStack.getItemMeta().hasDisplayName()) { name = itemStack.getItemMeta().getDisplayName(); } } - + if (name == null) { if (Bukkit.getPluginManager().getPlugin("Vault") != null) { ItemInfo itemInfo = Items.itemByStack(itemStack); @@ -217,30 +217,30 @@ public class RewardChest extends GameBlock { } else { name = itemStack.getType().name(); } - + } else { name = itemStack.getType().toString(); } } - + msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ","; } - + if (msg.length() >= 1) { msg = msg.substring(0, msg.length() - 1); } - + MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(msg)); } - + if (moneyReward != 0 && plugin.getEconomyProvider() != null) { MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(plugin.getEconomyProvider().format(moneyReward))); } - + if (levelReward != 0) { MessageUtil.sendMessage(player, DMessages.PLAYER_LOOT_ADDED.getMessage(levelReward + " levels")); } } } - + }