- package com.github.cman85.ArtePVP;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.HashMap;
- import java.util.Random;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class ArtePVP extends JavaPlugin implements Listener{
- File configFile;
- FileConfiguration config;
- HashMap<String, Integer> pointCount = new HashMap<String, Integer>();
- HashMap<String, Integer> streak = new HashMap<String, Integer>();
- public static final Logger log = Logger.getLogger("Minecraft");
- int pointgain=0;
- int kik=0;
- public void onEnable(){
- getLogger().info("ArtePVP has been enabled.");
- getServer().getPluginManager().registerEvents(this, this);
- configFile = new File(getDataFolder(), "config.yml");
- try {
- firstRun();
- } catch (Exception e) {
- e.printStackTrace();
- }
- config = new YamlConfiguration();
- loadYamls();
- }
- public void onDisable(){
- getLogger().info("ArtePVP has been disabled.");
- }
- private void firstRun() throws Exception {
- if(configFile.exists()){
- log.log(Level.INFO, "Config file found!");
- }else{
- log.log(Level.INFO, "Config file NOT found, creating now!");
- configFile.getParentFile().mkdirs();
- copy(getResource("config.yml"), configFile);
- }
- }
- private void copy(InputStream in, File file) {
- try {
- OutputStream out = new FileOutputStream(file);
- byte[] buf = new byte[1024];
- int len;
- while((len=in.read(buf))>0){
- out.write(buf,0,len);
- }
- out.close();
- in.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void loadYamls() {
- try {
- config.load(configFile);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void saveYamls() {
- try {
- config.save(configFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @EventHandler
- public void onDeath(PlayerDeathEvent e){
- //&&e.getEntity().getWorld().equals("world")
- if(e.getEntity() instanceof Player){
- if(!e.getEntity().getLastDamageCause().getEntityType().equals(EntityType.PLAYER)){
- return;
- }else{
- Player killer=e.getEntity().getKiller();
- Player killee=e.getEntity();
- if(streak.containsKey(killer.getName())){
- streak.put(killer.getName(), streak.get(killer.getName())+1);
- }else{
- streak.put(killer.getName(), 1);
- }
- streak.put(killee.getName(), 0);
- Random rand=new Random();
- Random rany=new Random();
- int ry=rany.nextInt(5);
- int r=rand.nextInt(20);
- int ki=(int)Math.ceil(streak.get(killee.getName())*1.3);
- if(pointCount.containsKey(killee.getName())){
- kik=(int)Math.ceil(pointCount.get(killee.getName())/64);
- }else{
- kik=1;
- }
- if(pointCount.containsKey(killer.getName())){
- pointgain=ki*kik;
- if(pointgain>=35){
- pointgain=r+20;
- }
- else if(pointgain==0){
- pointgain=ry+1;
- }
- pointCount.put(killer.getName(), pointCount.get(killer.getName())+pointgain);
- }else{
- pointCount.put(killer.getName(), pointgain);
- }
- getServer().broadcastMessage(killer.getName()+" got "+pointgain);
- }
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
- if (cmd.getName().equalsIgnoreCase("points")) {
- if(sender instanceof Player){
- Player p = (Player)sender;
- p.sendMessage(ChatColor.GRAY+"You have "+pointCount.get(p.getName())+" points.");
- }
- }
- return true;
- }
- }