Enabling/Disabling Blood from Commands.

Discussion in 'Plugin Development' started by Epicballzy, Apr 30, 2014.

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

    Epicballzy

    I have my blood effects all set-up, but I'd like players to be able to enable and disable the blood with a command. I'd like to use only one command for this (/blood). How would I go about doing this? Would it be easy to just use HashMaps and check if the player isn't in the hashmap, add them to it and disable to blood. or is there a much easier way to do it?

    Blood:
    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageEvent event) {
    3. Entity e = event.getEntity();
    4. if(e.getType().isAlive()) {
    5. e.getWorld().playEffect(e.getLocation().add(0, 1, 0), Effect.STEP_SOUND, 55);
    6. }
    7. }


    All help is appreciated!
     
  2. Offline

    TryB4

    Epicballzy
    List<String> showFor = new ArrayList<String>();

    Use player names.
     
  3. Offline

    Epicballzy

    TryB4 Alright, Thanks!
     
    TryB4 likes this.
  4. Offline

    Jordymt

    To finish the hint from above:

    Code:java
    1. if(showFor.contains(sender)) {
    2. //code to turn it off
    3. showFor.remove(sender);
    4. }
    5.  
    6. else {
    7. showFor.add(sender)
    8. }


    This is writting on my tab so some mistakes are possible :-$
     
  5. Offline

    Epicballzy

    TryB4 Ok, I tried this:
    Code:java
    1. public static List<String> blood = new ArrayList<String>();
    2. @EventHandler
    3. public void onDamage(EntityDamageEvent event) {
    4. Entity e = event.getEntity();
    5. if(e.getType().isAlive()) {
    6. if(blood.contains(event.getEntity())) {
    7. event.setCancelled(true);
    8. } else {
    9. e.getWorld().playEffect(e.getLocation().add(0, 1, 0), Effect.STEP_SOUND, 55);
    10. }
    11. }
    12. }
    13. public boolean onCommand(CommandSender sender, Command cmd, String string,
    14. String[] args) {
    15. Player player = (Player) sender;
    16. if(cmd.getName().equalsIgnoreCase("blood")) {
    17. if(Handlers.blood.contains(player.getName())) {
    18. Handlers.blood.remove(player.getName());
    19. player.sendMessage(ChatColor.GREEN + "Blood was " + ChatColor.RED + "Enabled!");
    20. } else {
    21. player.sendMessage(ChatColor.GREEN + "Blood was " + ChatColor.RED + "Disabled!");
    22. Handlers.blood.add(player.getName());
    23. }
    24. }
    25. return false;
    26. }


    I get the messages (Blood enabled, Blood Disabled) but its not actually disabling the blood. Any suggestions?
     
  6. Offline

    TryB4

    Epicballzy
    You're checking if it has an entity ^_^
    Firstly, check if it's a player.

    Code:java
    1. if (e.getEntity() instanceof Player){
    2. if (blood.contains(((Player)e.getEntity()).getName()) { // list has player
    3.  
    4. }
    5.  
    6. }
     
  7. Offline

    Epicballzy

    TryB4 This is what I did, but it still shows effects...
    Code:java
    1. if (event.getEntity() instanceof Player){
    2. if (blood.contains(((Player)event.getEntity()).getName())) {
    3. event.setCancelled(true);
    4. } else {
    5. e.getWorld().playEffect(e.getLocation().add(0, 1, 0), Effect.STEP_SOUND, 55);
    6. }
    7. }


    Does it have to be something other than event.setCancelled(true);?
     
  8. Offline

    xTigerRebornx

    Epicballzy Because you are just canceling the event if it contains the Player's name. You need to have the code that displays the blood in the if statement, not the else. You shouldn't be canceling the event at all, since all you are doing is displaying blood
     
Thread Status:
Not open for further replies.

Share This Page