How can I damage a player holding shift?

Discussion in 'Plugin Development' started by iScience, Jul 5, 2016.

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

    iScience

    Note: Im new to Bukkit, and am working on my first plugin RN, so I may seem look like a noob.

    So yeah. Im working on a plugin that turns you into an ironman, asked for help earlier, got a tip from a moderator, thx. Anyhow, he/she told me to work on damaging first, then particles, and I thought: Ok. Im just going to get another problem.

    What I want is so that after you type my command, holding shift will damage the entity (If there is one) you are looking directly at (With 15 true damage). Here is what I got so far:

    public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
    {
    if (commandLabel.equalsIgnoreCase("EquipIronman"))
    {
    Player thePlayer =(Player) theSender;
    thePlayer.sendMessage(ChatColor.DARK_RED + "Equipping MK7... Complete.");

    return true;
    }
    return true;
    }
    }

    Now what I want to know is where and how do I type these 2 things (For the command, I think these are what I need)

    PlayerShiftClickEntityEvent
    ^^To set off the command upon hitting shift

    and this vvvvv

    Player.getLocation().getDirection()
    ^^To get the direction the player is looking and another line of code for it to damage 15 True Damage (Which I do not know the code for that).

    Any help please?
     
  2. Offline

    Lolmewn

    What have you tried?
     
  3. Offline

    iScience

    I tried adding an "If" statement telling it to damage the player where the sender is looking

    {
    if (theSender Player.getLocation().getDirection() = getDirection.findEntity (findEntity) anEntity)
    damage anEntity 15 true;

    My friend told me to do something like that, it didnt really work.
     
  4. Offline

    Zombie_Striker

    @iScience
    What you need to do is create a Repeating Task when the player sends the command. Each time the task runs, check if the player is shifting. If he is, check if there is a entity where the player is looking. If so, damage it.
     
  5. Offline

    iScience

    Thx m8y
     
  6. Offline

    MCnumi

    Do not blind cast. before casting theSender as a player, check if he is instanceof Player first
     
  7. Offline

    iScience

    QUOTE[​IMG]="Zombie_Striker, post: 3398272, member: 90867807"]@iScience
    What you need to do is create a Repeating Taskcant extend it to when the player sends the command. Each time the task runs, check if the player is shifting. If he is, check if there is a entity where the player is looking. If so, damage it.[ QUOTE[​IMG]]Since I cant extend it to 2 different things, do you know how I can make it enable a class when the command is sent? That way I can have it extend to BukkitRunnable and JavaPlugin
     
  8. Offline

    ArsenArsen

    You can. class MyClass extends JavaPlugin,MyOtherClass

    EDIT: do
    Code:
    new BukkitRunnable() {your code here}
    You do not need new classes.
     
  9. Offline

    iScience

    Thx m8y

    new BukkitRunnable() {

    @Override
    public void run() {
    [Help Needed Here]

    }

    Ok I got that done. Where it says [Need Help Here], can someone tell me how it would get the direction, select the entity, and do damage to it (15 true) whenever someone presses shift? pls

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 7, 2016
  10. Offline

    Zombie_Striker

    @iScience
    1. First, you need to store the player variable somewhere
    2. Using Player#getNearbyEntities(x,y,z), create a collection of all the nearby entities.
    3. Get the player's direction using Player#getLocation().getDirection();
    4. Create two radios, using X as the base. One will be the Z over x, and the other is the Y over X.
    5. Create a for loop. i will increment by 0.25 untill it reaches a "max distance"
    6. Using the two ration above, get the player's location and add onto it those ratios multiplied by i. This will create a straight line in the direction you're looking.
    7. Loop through the collection from #2, and test if an entity is within 1 block of the location.
     
  11. Offline

    iScience

    @Zombie_Striker You seem to know what you are doing.

    Is this correct? I dunno...
    new BukkitRunnable() {

    @Override
    public void run() {
    getNearbyEntities(x,y,z);
    {
    ((Player) getDirection()).getLocation() ;
    }

    }

    private Player getDirection() {
    [DamageEntity( )]
    return void;
    }

    It underlined (x,y,z), along with "Void" and the last "]" (After Damage entity). If I did most of it correct, can you tell me
    A) How to damage the player and
    B) how to fix the mistakes if there are any
     
  12. cococow123 likes this.
  13. Offline

    Zombie_Striker

    @iScience
    You should not make plugins unless you have learned Java. Either you came from another language, you have no knowledge or programming at all. Either way, you need to learn Java first.

    [Edit] semi-ninja'd.
     
Thread Status:
Not open for further replies.

Share This Page