More work on SaneEconomyMobKills.

This commit is contained in:
AppleDash 2016-12-28 00:12:21 -05:00
parent 510d0e63d0
commit 378a722ae2
3 changed files with 72 additions and 5 deletions

View File

@ -2,22 +2,54 @@ package org.appledash.saneeconomymobkills;
import org.appledash.saneeconomy.SaneEconomy;
import org.appledash.saneeconomymobkills.listeners.EntityDamageListener;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/**
* Created by appledash on 12/27/16.
* Blackjack is still best pony.
*/
public class SaneEconomyMobKills extends JavaPlugin {
private SaneEconomy saneEconomy;
private final Map<String, Double> killAmounts = new HashMap<>();
@Override
public void onEnable() {
saneEconomy = (SaneEconomy)getServer().getPluginManager().getPlugin("SaneEconomy");
YamlConfiguration amountsConfig;
if (!(new File(getDataFolder(), "amounts.yml").exists())) {
amountsConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(getClass().getResourceAsStream("amounts.yml")));
try {
amountsConfig.save(new File(getDataFolder(), "amounts.yml"));
} catch (IOException e) {
throw new RuntimeException("Failed to save amounts.yml to plugin data folder!");
}
} else {
amountsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "amounts.yml"));
}
for (String entityTypeName : amountsConfig.getKeys(false)) {
double value = amountsConfig.getDouble(entityTypeName);
killAmounts.put(entityTypeName, value);
}
getServer().getPluginManager().registerEvents(new EntityDamageListener(this), this);
}
public SaneEconomy getSaneEconomy() {
return saneEconomy;
}
public Map<String, Double> getKillAmounts() {
return killAmounts;
}
}

View File

@ -7,9 +7,7 @@ import org.appledash.saneeconomy.utils.MessageUtils;
import org.appledash.saneeconomymobkills.SaneEconomyMobKills;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -26,7 +24,6 @@ import java.util.UUID;
public class EntityDamageListener implements Listener {
private SaneEconomyMobKills plugin;
private Map<Integer, Map<UUID, Double>> damageDealt = new HashMap<>();
private Map<EntityType, Double> awardsForKills = new HashMap<>();
public EntityDamageListener(SaneEconomyMobKills plugin) {
this.plugin = plugin;
@ -41,6 +38,10 @@ public class EntityDamageListener implements Listener {
Player damager = ((Player) evt.getDamager());
Entity damagee = evt.getEntity();
if (!plugin.getKillAmounts().containsKey(getEntityType(damagee))) {
return;
}
Map<UUID, Double> damageDoneToThisEntity = new HashMap<>();
if (damageDealt.containsKey(damagee.getEntityId())) {
@ -74,7 +75,7 @@ public class EntityDamageListener implements Listener {
for (Map.Entry<UUID, Double> entry : damageDoneToThisEntity.entrySet()) {
double thisDmg = entry.getValue();
double thisPercent = (thisDmg / totalDmg) * 100.0D;
double thisAmount = awardsForKills.get(entity.getType()) * (thisPercent / 100);
double thisAmount = plugin.getKillAmounts().get(getEntityType(entity)) * (thisPercent / 100);
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(entry.getKey());
if (offlinePlayer.isOnline()) {
@ -89,6 +90,20 @@ public class EntityDamageListener implements Listener {
}
private String getEntityType(Entity entity) {
EntityType entityType = entity.getType();
if ((entityType == EntityType.SKELETON) && (((Skeleton) entity).getSkeletonType() == Skeleton.SkeletonType.WITHER)) {
return "WITHER_SKELETON";
}
if ((entityType == EntityType.GUARDIAN) && ((Guardian) entity).isElder()) {
return "ELDER_GUARDIAN";
}
return entityType.toString();
}
private double sumValues(Map<?, Double> map) {
double sum = 0;

View File

@ -0,0 +1,20 @@
ZOMBIE: 2.0
SKELETON: 3.0
SPIDER: 1.0
CREEPER: 3.0
SLIME: 0.2
SILVERFISH: 1.2
CAVE_SPIDER: 1.5
WITCH: 5.0
PIG_ZOMBIE: 3.0
BLAZE: 5.5
GHAST: 7.0
MAGMA_CUBE: 0.4
WITHER_SKELETON: 5.5
ENDERMAN: 4.0
ENDERMITE: 1.0
SHULKER: 2.0
GUARDIAN: 2.5
ELDER_GUARDIAN: 50.0
WITHER: 150.0
ENDER_DRAGON: 1000.0