Fight-Point System

Discussion in 'Plugin Development' started by TheReelaatiiv, Jan 29, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    TheReelaatiiv

    Hello,

    i am currently writing a plugin which shoul'd do the following:

    Everytime player1 damages player2 the plugin gives player1 +<damage>+1 points and takes -<damage> points from player2.
    Everytime player1 damages a mob the plugin gives player1 +<damage>+1 points.
    Everytime player2 got damaged by a mob, lava. etc. the plugin takes -<damage> points from player2.
    Every minute this plugin gives a player 0.1 points.
    This data shoul'd be storaged in the database.
    Every 15 minutes the plugin shoul'd print the best xxx(configurable) players and its points.

    My code:
    PointSys.java
    Code:
    package org.fusl.ps;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class PointSys extends JavaPlugin {
     
    public final PointSysListener entityListener = new PointSysListener(this);
     
    public void onEnable(){
    registerEvents();
    //setupConfig();
    }
     
    public void onDisable(){
     
    }
     
    public void registerEvents() {
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this);
    }
     
    public void setupConfig(){
    if(getConfig().getString("Version") == null){
    getConfig().set("Version", "0.0.1");
    saveConfig();
    }
    }
     
    public boolean onCommand(CommandSender s, Command c, String l, String [] args){
    if(l.equalsIgnoreCase("psversion")){
    s.sendMessage(" ____________________ ");
    s.sendMessage("/                    \\");
    s.sendMessage("| PointSys v0.0.1    |");
    s.sendMessage("\\____________________/");
    }
    return true;
    }
     
    }
    PointSysListener.java
    Code:
    package org.fusl.ps;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.Event;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityListener;
     
    public class PointSysListener extends EntityListener {
    public static PointSys plugin;
     
    public PointSysListener(PointSys mp){
    plugin = mp;
    }
     
        public void onEntityDamage(EntityDamageEvent e){
      int thedamage = e.getDamage();
    String reason = e.getCause().toString();
     
    if(reason == "ENTITY_ATTACK") {
     
    if(e.getEntity() instanceof Player) {
    Player receiver = (Player) e.getEntity();
    receiver.sendMessage("R " + thedamage);
    }
     
    if(((EntityDamageByEntityEvent) e).getDamager() instanceof Player) {
    Player sender = (Player)((EntityDamageByEntityEvent) e).getDamager();
    sender.sendMessage("S " + thedamage);
    }
     
    }
    /*else if(reason == "PROJECTILE") {
    if(e.getEntity() instanceof Player) {
    Player receiver = (Player) e.getEntity();
    receiver.sendMessage("R " + thedamage);
    }
    if(((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
    Entity attacker = ((Projectile)((EntityDamageByEntityEvent) e).getDamager()).getShooter();
     
    if(attacker instanceof Player) {
    Player sender = attacker;
    System.out.println("==> " + attacker + "<==");
    attacker.sendMessage("S " + thedamage);
    }
    }
    }*/
    else if(reason == "CONTACT" || reason == "SUFFOCATION" || reason == "FALL" || reason == "FIRE" || reason == "FIRE_TICK" || reason == "LAVA" || reason == "DROWNING" || reason == "BLOCK_EXPLOSION" || reason == "ENTITY_EXPLOSION" || reason == "VOID" || reason == "LIGHTNING" || reason == "SUICIDE" || reason == "STARVATION" || reason == "POISON" || reason == "MAGIC" || reason == "CUSTOM") {
    if(e.getEntity() instanceof Player) {
    Player receiver = (Player) e.getEntity();
    receiver.sendMessage("R " + reason + " " + thedamage);
    }
    }
    }
    }
    But it works only when player1 hits player2 with a block, sword, etc.
    If player1 hits player2 with an arrow, there is only a message (currently to test) to player2. (Currently commented out at PointSysListener.java)
    How can i read out, which player damages a player with an arrow and send a message to player1?

    I hope there aren't much misspellings (i'm from austria and i can not speak really good english).
     
Thread Status:
Not open for further replies.

Share This Page