Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 3.82 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.github.cman85.ArtePVP;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8. import java.util.HashMap;
  9. import java.util.Random;
  10. import java.util.logging.Level;
  11. import java.util.logging.Logger;
  12.  
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.configuration.file.FileConfiguration;
  17. import org.bukkit.configuration.file.YamlConfiguration;
  18. import org.bukkit.entity.EntityType;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.Listener;
  22. import org.bukkit.event.entity.PlayerDeathEvent;
  23. import org.bukkit.plugin.java.JavaPlugin;
  24.  
  25. public class ArtePVP extends JavaPlugin implements Listener{
  26.         File configFile;
  27.         FileConfiguration config;
  28.         HashMap<String, Integer> pointCount = new HashMap<String, Integer>();
  29.         HashMap<String, Integer> streak = new HashMap<String, Integer>();
  30.         public static final Logger log = Logger.getLogger("Minecraft");
  31.         int pointgain=0;
  32.         int kik=0;
  33.  
  34.         public void onEnable(){
  35.                 getLogger().info("ArtePVP has been enabled.");
  36.                 getServer().getPluginManager().registerEvents(this, this);
  37.                 configFile = new File(getDataFolder(), "config.yml");
  38.                 try {
  39.                         firstRun();
  40.                 } catch (Exception e) {
  41.                         e.printStackTrace();
  42.                 }
  43.                 config = new YamlConfiguration();
  44.                 loadYamls();
  45.         }
  46.  
  47.         public void onDisable(){
  48.                 getLogger().info("ArtePVP has been disabled.");
  49.         }
  50.         private void firstRun() throws Exception {
  51.                 if(configFile.exists()){
  52.                         log.log(Level.INFO, "Config file found!");
  53.                 }else{
  54.                         log.log(Level.INFO, "Config file NOT found, creating now!");
  55.                         configFile.getParentFile().mkdirs();
  56.                         copy(getResource("config.yml"), configFile);
  57.                 }
  58.         }
  59.  
  60.         private void copy(InputStream in, File file) {
  61.                 try {
  62.                         OutputStream out = new FileOutputStream(file);
  63.                         byte[] buf = new byte[1024];
  64.                         int len;
  65.                         while((len=in.read(buf))>0){
  66.                                 out.write(buf,0,len);
  67.                         }
  68.                         out.close();
  69.                         in.close();
  70.                 } catch (Exception e) {
  71.                         e.printStackTrace();
  72.                 }
  73.         }
  74.  
  75.         public void loadYamls() {
  76.                 try {
  77.                         config.load(configFile);
  78.                 }catch (Exception e) {
  79.                         e.printStackTrace();
  80.                 }
  81.         }
  82.  
  83.         public void saveYamls() {
  84.                 try {
  85.                         config.save(configFile);
  86.                 } catch (IOException e) {
  87.                         e.printStackTrace();
  88.                 }
  89.         }
  90.         @EventHandler
  91.         public void onDeath(PlayerDeathEvent e){
  92.                 //&&e.getEntity().getWorld().equals("world")
  93.                 if(e.getEntity() instanceof Player){
  94.                         if(!e.getEntity().getLastDamageCause().getEntityType().equals(EntityType.PLAYER)){
  95.                                 return;
  96.                         }else{
  97.                                 Player killer=e.getEntity().getKiller();
  98.                                 Player killee=e.getEntity();
  99.                                 if(streak.containsKey(killer.getName())){
  100.                                         streak.put(killer.getName(), streak.get(killer.getName())+1);
  101.                                 }else{
  102.                                         streak.put(killer.getName(), 1);
  103.                                 }
  104.                                 streak.put(killee.getName(), 0);
  105.  
  106.                                 Random rand=new Random();
  107.                                 Random rany=new Random();
  108.                                 int ry=rany.nextInt(5);
  109.                                 int r=rand.nextInt(20);
  110.                                 int ki=(int)Math.ceil(streak.get(killee.getName())*1.3);
  111.                                 if(pointCount.containsKey(killee.getName())){
  112.                                         kik=(int)Math.ceil(pointCount.get(killee.getName())/64);
  113.                                 }else{
  114.                                         kik=1;
  115.                                 }
  116.                                 if(pointCount.containsKey(killer.getName())){
  117.                                         pointgain=ki*kik;
  118.                                         if(pointgain>=35){
  119.                                                 pointgain=r+20;
  120.                                         }
  121.                                         else if(pointgain==0){
  122.                                                 pointgain=ry+1;
  123.                                         }
  124.                                         pointCount.put(killer.getName(), pointCount.get(killer.getName())+pointgain);
  125.                                 }else{
  126.                                         pointCount.put(killer.getName(), pointgain);
  127.                                 }
  128.                                 getServer().broadcastMessage(killer.getName()+" got "+pointgain);
  129.                         }
  130.                 }
  131.         }
  132.         public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  133.                 if (cmd.getName().equalsIgnoreCase("points")) {
  134.                         if(sender instanceof Player){
  135.                                 Player p = (Player)sender;
  136.                                 p.sendMessage(ChatColor.GRAY+"You have "+pointCount.get(p.getName())+" points.");
  137.                         }
  138.                 }
  139.                 return true;
  140.         }
  141. }