When player walks over pressure plate

Discussion in 'Plugin Development' started by xXLightbulbXx, Sep 7, 2015.

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

    xXLightbulbXx

    Hey, I've got this issue, I can't figure out why its not working. When a player walks over a pressure plate it doesn't do what i want it to.
    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player player = e.getPlayer();
    
            if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getTypeId() == 147) {
                player.sendMessage(ChatColor.GREEN + "I believe i can fly...");
                player.setVelocity(player.getEyeLocation().getDirection().multiply(3.0));
            }
        }
     
  2. Offline

    Zombie_Striker

    @xXLightbulbXx
    That is because playerInteractEvent only is triggered when a player is INTERACTING (rightclick,leftclick) with a block.

    What you want is a Runnable or PlayerMoveEvent

    Also, it's a really bad idea to use ItemID. Those are deprecated and have no reason to be used.
     
  3. Offline

    Xerox262

    Player interact is called when you depress a pressure plate, he is correct with what he's doing.
    You should change the getTypeId() to getType() then check if it's == to Material.GOLD_PLATE then you should cancel the event so that multiple people can step on it and be launched at the same time. Btw check make sure you registered the listener
     
    Last edited: Sep 7, 2015
    mine-care likes this.
  4. Offline

    ToadFungoso

    @xXLightbulbXx Try this:

    Code:
      @EventHandler
      public void onPlayerInteract(PlayerInteractEvent e)
      {
    if(e.getAction().equals(Action.PHYSICAL) && (e.getClickedBlock().getType() == Material.STONE_PLATE) || (e.getClickedBlock().getType() == Material.WOOD_PLATE) || (e.getClickedBlock().getType() == Material.IRON_PLATE) || (e.getClickedBlock().getType() == Material.GOLD_PLATE)){
    player.sendMessage(ChatColor.GREEN + "I believe i can fly...");
    player.setVelocity(player.getEyeLocation().getDirection().multiply(3.0));
    }
     
  5. Offline

    xXLightbulbXx

  6. Offline

    Xerox262

    Can we see the rest of your class? And if it's in a separate class can we see your JavaPlugin class, because I did test this when I posted my command and it worked
     
  7. Offline

    xXLightbulbXx

    @Xerox262
    Code:
    package xXLightbulbXx.JumpPads;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class JumpPads extends JavaPlugin implements Listener {
    
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
    
        public void onDisable() {
        }
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player player = e.getPlayer();
    
            if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.GOLD_PLATE) {
                player.sendMessage(ChatColor.GREEN + "I believe i can fly...");
                player.setVelocity(player.getEyeLocation().getDirection().multiply(3.0));
            }
        }
    }
     
  8. Offline

    Gamesareme

    @xXLightbulbXx is the plugin being registered on the server? Can you see a message saying your plugin has been enabled? Also are there any stack traces that occur?
     
  9. Offline

    Xerox262

    There we go, your error is this
    import net.md_5.bungee.api.ChatColor;
    You want the Bukkit import, not the bungee one
     
  10. Offline

    WPM

    Don't even think that will change anything.
     
  11. Offline

    Xerox262

    I bet it will since it's happened to me before (I mash ctrl shift o for imports >.<), We'll see when OP tries and tells us
     
  12. Offline

    xXLightbulbXx

    @Gamesareme There are no errors/stack traces. It is being enabled.
     
  13. Offline

    SyTeck

    Tried debugging?
     
  14. Offline

    SuperSniper

    @xXLightbulbXx
    Code:
      @EventHandler
      public void onPlayerMove(PlayerMoveEvent e) {
        if (e.getTo().getBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE_PLATE) {
          // Do Stuff
    
    This code should work perfectly. It's from my previous plugin and works like a charm
     
  15. Offline

    Zombie_Striker

    I want to point this out before this thread is moved. This type of chatcolor would cause some errors if A) the server is not Bunggee/spigot and B) This chat color is not the same as org.bukkit.ChatColor;

    First, JavaNamingConventions: Do not use capital letters for package the package name. Secondly, you should not have the class name be the same as a section of the package (JumpPads). Finally, your config might be messed up if you forgot to add Jumpads twice (this is the reason why you don't have same package/class names), meaning that it should like like this
    Code:
    xXLightbulbXx.JumpPads.JumpPads
    Also, are you sure that you are looking for Action.PHYSICAL? What if you remove this check, would it work?
     
  16. Offline

    xXLightbulbXx

    Thanks for the help, i got it to work :D
     
Thread Status:
Not open for further replies.

Share This Page