Implement the Things API for rewards (including boss wave rewards).
This commit is contained in:
@@ -16,6 +16,7 @@ import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.repairable.Repairable;
|
||||
import com.garbagemule.MobArena.repairable.RepairableComparator;
|
||||
import com.garbagemule.MobArena.repairable.RepairableContainer;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.time.Time;
|
||||
import com.garbagemule.MobArena.time.TimeStrategy;
|
||||
import com.garbagemule.MobArena.time.TimeStrategyLocked;
|
||||
@@ -114,7 +115,7 @@ public class ArenaImpl implements Arena
|
||||
private WaveManager waveManager;
|
||||
private MASpawnThread spawnThread;
|
||||
private SheepBouncer sheepBouncer;
|
||||
private Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
|
||||
private Map<Integer,List<Thing>> everyWaveMap, afterWaveMap;
|
||||
|
||||
// Misc
|
||||
private ArenaListener eventListener;
|
||||
@@ -293,12 +294,12 @@ public class ArenaImpl implements Arena
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<Integer,List<ItemStack>>> getEveryWaveEntrySet() {
|
||||
public Set<Map.Entry<Integer,List<Thing>>> getEveryWaveEntrySet() {
|
||||
return everyWaveMap.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getAfterWaveReward(int wave) {
|
||||
public List<Thing> getAfterWaveReward(int wave) {
|
||||
return afterWaveMap.get(wave);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.garbagemule.MobArena.repairable.RepairableBlock;
|
||||
import com.garbagemule.MobArena.repairable.RepairableContainer;
|
||||
import com.garbagemule.MobArena.repairable.RepairableDoor;
|
||||
import com.garbagemule.MobArena.repairable.RepairableSign;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.util.ClassChests;
|
||||
import com.garbagemule.MobArena.waves.MABoss;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -601,16 +602,9 @@ public class ArenaListener
|
||||
}
|
||||
MABoss boss = monsters.getBoss(damagee);
|
||||
if (boss != null) {
|
||||
ItemStack reward = boss.getReward();
|
||||
Thing reward = boss.getReward();
|
||||
if (reward != null) {
|
||||
String msg = p.getName() + " killed the boss and won: ";
|
||||
if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||
plugin.giveMoney(p, reward);
|
||||
msg += plugin.economyFormat(reward);
|
||||
} else {
|
||||
arena.getRewardManager().addReward((Player) damager, reward);
|
||||
msg += MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount();
|
||||
}
|
||||
String msg = p.getName() + " killed the boss and won: " + reward;
|
||||
for (Player q : arena.getPlayersInArena()) {
|
||||
arena.getMessenger().tell(q, msg);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.garbagemule.MobArena.events.ArenaCompleteEvent;
|
||||
import com.garbagemule.MobArena.events.NewWaveEvent;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.waves.MABoss;
|
||||
import com.garbagemule.MobArena.waves.MACreature;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
@@ -17,7 +18,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -291,13 +291,13 @@ public class MASpawnThread implements Runnable
|
||||
}
|
||||
|
||||
private void grantRewards(int wave) {
|
||||
for (Map.Entry<Integer, List<ItemStack>> entry : arena.getEveryWaveEntrySet()) {
|
||||
for (Map.Entry<Integer, List<Thing>> entry : arena.getEveryWaveEntrySet()) {
|
||||
if (wave > 0 && wave % entry.getKey() == 0) {
|
||||
addReward(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> after = arena.getAfterWaveReward(wave);
|
||||
List<Thing> after = arena.getAfterWaveReward(wave);
|
||||
if (after != null) {
|
||||
addReward(after);
|
||||
}
|
||||
@@ -326,25 +326,17 @@ public class MASpawnThread implements Runnable
|
||||
/**
|
||||
* Rewards all players with an item from the input String.
|
||||
*/
|
||||
private void addReward(List<ItemStack> rewards) {
|
||||
private void addReward(List<Thing> rewards) {
|
||||
for (Player p : arena.getPlayersInArena()) {
|
||||
ItemStack reward = MAUtils.getRandomReward(rewards);
|
||||
Thing reward = rewards.get(MobArena.random.nextInt(rewards.size()));
|
||||
rewardManager.addReward(p, reward);
|
||||
|
||||
if (reward == null) {
|
||||
arena.getMessenger().tell(p, "ERROR! Problem with rewards. Notify server host!");
|
||||
plugin.getLogger().warning("Could not add null reward. Please check the config-file!");
|
||||
}
|
||||
else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||
if (plugin.giveMoney(p, reward)) { // Money already awarded here, not needed at end of match as well
|
||||
arena.getMessenger().tell(p, Msg.WAVE_REWARD, plugin.economyFormat(reward));
|
||||
}
|
||||
else {
|
||||
plugin.getLogger().warning("Tried to add money, but no economy plugin detected!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
arena.getMessenger().tell(p, Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount());
|
||||
arena.getMessenger().tell(p, Msg.WAVE_REWARD, reward.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.garbagemule.MobArena;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.util.EntityPosition;
|
||||
import com.garbagemule.MobArena.util.ItemParser;
|
||||
import com.garbagemule.MobArena.util.TextUtils;
|
||||
@@ -50,10 +51,10 @@ public class MAUtils
|
||||
* type of wave ("after" or "every") and the config-file. If
|
||||
* no keys exist in the config-file, an empty map is returned.
|
||||
*/
|
||||
public static Map<Integer,List<ItemStack>> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type)
|
||||
public static Map<Integer,List<Thing>> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type)
|
||||
{
|
||||
//String arenaPath = "arenas." + arena + ".rewards.waves.";
|
||||
Map<Integer,List<ItemStack>> result = new HashMap<>();
|
||||
Map<Integer,List<Thing>> result = new HashMap<>();
|
||||
|
||||
String typePath = "rewards.waves." + type;
|
||||
if (!config.contains(typePath)) return result;
|
||||
@@ -71,31 +72,22 @@ public class MAUtils
|
||||
String path = typePath + "." + wave;
|
||||
String rewards = config.getString(path);
|
||||
|
||||
result.put(wave, ItemParser.parseItems(rewards));
|
||||
List<Thing> things = new ArrayList<>();
|
||||
for (String reward : rewards.split(",")) {
|
||||
Thing thing = plugin.getThingManager().parse(reward.trim());
|
||||
if (thing == null) {
|
||||
plugin.getLogger().warning("Failed to parse reward: " + reward.trim());
|
||||
} else {
|
||||
things.add(thing);
|
||||
}
|
||||
}
|
||||
result.put(wave, things);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ///////////////////////////////////////////////////////////////////// //
|
||||
|
||||
INVENTORY AND REWARD METHODS
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/* Helper method for grabbing a random reward */
|
||||
public static ItemStack getRandomReward(List<ItemStack> rewards)
|
||||
{
|
||||
if (rewards.isEmpty())
|
||||
return null;
|
||||
|
||||
Random ran = new Random();
|
||||
return rewards.get(ran.nextInt(rewards.size()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ///////////////////////////////////////////////////////////////////// //
|
||||
|
||||
PET CLASS METHODS
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -18,7 +18,7 @@ public class RewardManager
|
||||
private MobArena plugin;
|
||||
@SuppressWarnings("unused")
|
||||
private Arena arena;
|
||||
private Map<Player,List<ItemStack>> players;
|
||||
private Map<Player,List<Thing>> players;
|
||||
private Set<Player> rewarded;
|
||||
|
||||
public RewardManager(Arena arena) {
|
||||
@@ -33,35 +33,29 @@ public class RewardManager
|
||||
rewarded.clear();
|
||||
}
|
||||
|
||||
public void addReward(Player p, ItemStack stack) {
|
||||
public void addReward(Player p, Thing thing) {
|
||||
if (!players.containsKey(p)) {
|
||||
players.put(p, new ArrayList<ItemStack>());
|
||||
players.put(p, new ArrayList<Thing>());
|
||||
}
|
||||
players.get(p).add(stack);
|
||||
players.get(p).add(thing);
|
||||
}
|
||||
|
||||
public List<ItemStack> getRewards(Player p) {
|
||||
List<ItemStack> rewards = players.get(p);
|
||||
return (rewards == null ? new ArrayList<ItemStack>(1) : Collections.unmodifiableList(rewards));
|
||||
public List<Thing> getRewards(Player p) {
|
||||
List<Thing> rewards = players.get(p);
|
||||
return (rewards == null ? new ArrayList<Thing>(1) : Collections.unmodifiableList(rewards));
|
||||
}
|
||||
|
||||
public void grantRewards(Player p) {
|
||||
if (rewarded.contains(p)) return;
|
||||
|
||||
List<ItemStack> rewards = players.get(p);
|
||||
List<Thing> rewards = players.get(p);
|
||||
if (rewards == null) return;
|
||||
|
||||
for (ItemStack stack : rewards) {
|
||||
if (stack == null) {
|
||||
for (Thing reward : rewards) {
|
||||
if (reward == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||
// plugin.giveMoney(p, stack.getAmount()); - removed to fix double money rewards
|
||||
continue;
|
||||
}
|
||||
|
||||
p.getInventory().addItem(stack);
|
||||
reward.giveTo(p);
|
||||
}
|
||||
rewarded.add(p);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.garbagemule.MobArena.ScoreboardManager;
|
||||
import com.garbagemule.MobArena.leaderboards.Leaderboard;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.repairable.Repairable;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.util.inventory.InventoryManager;
|
||||
import com.garbagemule.MobArena.util.timer.AutoStartTimer;
|
||||
import com.garbagemule.MobArena.waves.WaveManager;
|
||||
@@ -64,9 +65,9 @@ public interface Arena
|
||||
|
||||
List<ItemStack> getEntryFee();
|
||||
|
||||
Set<Map.Entry<Integer,List<ItemStack>>> getEveryWaveEntrySet();
|
||||
Set<Map.Entry<Integer,List<Thing>>> getEveryWaveEntrySet();
|
||||
|
||||
List<ItemStack> getAfterWaveReward(int wave);
|
||||
List<Thing> getAfterWaveReward(int wave);
|
||||
|
||||
Set<Player> getPlayersInArena();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.garbagemule.MobArena.waves;
|
||||
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -10,7 +11,7 @@ public class MABoss
|
||||
{
|
||||
private LivingEntity entity;
|
||||
private boolean dead;
|
||||
private ItemStack reward;
|
||||
private Thing reward;
|
||||
private List<ItemStack> drops;
|
||||
|
||||
/**
|
||||
@@ -74,11 +75,11 @@ public class MABoss
|
||||
this.dead = dead;
|
||||
}
|
||||
|
||||
public void setReward(ItemStack reward) {
|
||||
public void setReward(Thing reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
public ItemStack getReward() {
|
||||
public Thing getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.garbagemule.MobArena.waves;
|
||||
import com.garbagemule.MobArena.ArenaClass;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.util.ItemParser;
|
||||
import com.garbagemule.MobArena.util.PotionEffectParser;
|
||||
import com.garbagemule.MobArena.waves.ability.Ability;
|
||||
@@ -24,6 +25,7 @@ import com.garbagemule.MobArena.waves.types.UpgradeWave.GenericUpgrade;
|
||||
import com.garbagemule.MobArena.waves.types.UpgradeWave.PermissionUpgrade;
|
||||
import com.garbagemule.MobArena.waves.types.UpgradeWave.Upgrade;
|
||||
import com.garbagemule.MobArena.waves.types.UpgradeWave.WeaponUpgrade;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -305,8 +307,12 @@ public class WaveParser
|
||||
// Rewards!
|
||||
String rew = config.getString("reward");
|
||||
if (rew != null) {
|
||||
ItemStack item = ItemParser.parseItem(rew);
|
||||
if (item != null) result.setReward(item);
|
||||
Thing reward = arena.getPlugin().getThingManager().parse(rew);
|
||||
if (reward == null) {
|
||||
Bukkit.getLogger().warning("[MobArena] Failed to parse boss reward: " + rew);
|
||||
} else {
|
||||
result.setReward(reward);
|
||||
}
|
||||
}
|
||||
|
||||
// Drops!
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.garbagemule.MobArena.waves.types;
|
||||
|
||||
import com.garbagemule.MobArena.Msg;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.waves.AbstractWave;
|
||||
import com.garbagemule.MobArena.waves.BossAbilityThread;
|
||||
import com.garbagemule.MobArena.waves.MABoss;
|
||||
@@ -37,7 +38,7 @@ public class BossWave extends AbstractWave
|
||||
|
||||
private int abilityInterval;
|
||||
|
||||
private ItemStack reward;
|
||||
private Thing reward;
|
||||
private List<ItemStack> drops;
|
||||
private List<PotionEffect> potions;
|
||||
|
||||
@@ -121,11 +122,11 @@ public class BossWave extends AbstractWave
|
||||
this.abilityAnnounce = abilityAnnounce;
|
||||
}
|
||||
|
||||
public ItemStack getReward() {
|
||||
public Thing getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public void setReward(ItemStack reward) {
|
||||
public void setReward(Thing reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user