Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package empire;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Set;
- import java.util.UUID;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Server;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.FileConfigurationOptions;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class KillsPrefix
- extends JavaPlugin
- implements Listener
- {
- public static Logger log = ;
- String killFormat = getConfig().getString("format");
- public void onEnable()
- {
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- getConfig().options().copyDefaults(true);
- saveDefaultConfig();
- getKill();
- }
- public void onDisable()
- {
- saveDefaultConfig();
- }
- Map<String, Integer> playerKills = new HashMap();
- public boolean canGet(ConfigurationSection config)
- {
- try
- {
- config.getKeys(false);
- return true;
- }
- catch (NullPointerException e)
- {
- log.info("[KillPrefix] No Kills Found!");
- }
- return false;
- }
- public void getKill()
- {
- ConfigurationSection config = getConfig().getConfigurationSection("kills");
- if (canGet(config))
- {
- Set<String> all = config.getKeys(false);
- for (String b : all)
- {
- String id = b;
- int kills = getConfig().getInt("kills." + b + ".amount");
- this.playerKills.put(id, Integer.valueOf(kills));
- }
- }
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent e)
- {
- Player p = e.getPlayer();
- String id = p.getUniqueId().toString();
- if (!this.playerKills.containsKey(id)) {
- this.playerKills.put(id, Integer.valueOf(0));
- }
- }
- @EventHandler
- public void onKill(PlayerDeathEvent e)
- {
- if ((e.getEntity().getKiller() instanceof Player))
- {
- Player killer = e.getEntity().getKiller();
- String id = killer.getUniqueId().toString();
- int currentKills = ((Integer)this.playerKills.get(id)).intValue();
- this.playerKills.put(id, Integer.valueOf(currentKills + 1));
- getConfig().set("kills." + id + ".amount", Integer.valueOf(currentKills + 1));
- saveConfig();
- }
- }
- @EventHandler
- public void onChat(AsyncPlayerChatEvent e)
- {
- Player p = e.getPlayer();
- String id = p.getUniqueId().toString();
- String kills = ChatColor.translateAlternateColorCodes('&', this.killFormat.replace("%kills", Integer.toString(((Integer)this.playerKills.get(id)).intValue())));
- e.setFormat(kills + e.getFormat());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement