Jump Pads not working.

Discussion in 'Plugin Development' started by ksbdude, Dec 28, 2013.

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

    ksbdude

    Im trying to add a feature to my plugin that will make pressure plates work as jump pads. I don't get why this code isn't working. I think it should be. Any idea why its not?
    Code:java
    1. public void onPlayerStep(PlayerMoveEvent e) {
    2. Player p = e.getPlayer();
    3. Block standingOn = p.getWorld().getBlockAt(0, -1, 0);
    4. if(standingOn.getType().equals(Material.STONE_PLATE)) {
    5. e.getPlayer().sendMessage(ChatColor.GREEN + "Woosh!");
    6. Player player = e.getPlayer();
    7. Vector dir = player.getLocation().getDirection();
    8. Vector vec = new Vector(dir.getX() * 0.8D, 0.8D, dir.getZ() * 0.8D);
    9. player.setVelocity(vec);
    10. player.setFallDistance(-100.0F);
    11. }
    12. }
     
  2. Offline

    Blingdaddy1

    Here's one that works
    try this:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onLaunchMove(PlayerMoveEvent event) {
    4. Player player = event.getPlayer();
    5. Location playerLoc = player.getLocation();
    6. int ID = playerLoc.getWorld().getBlockAt(playerLoc).getRelative(0, -1, 0).getTypeId();
    7. int plate = playerLoc.getWorld().getBlockAt(playerLoc).getTypeId();
    8. if (((player instanceof Player) && player.hasPermission("perm.perm"))) {
    9. if (ID == 133) {
    10. if (plate == 70) {
    11. player.setVelocity(player.getLocation().getDirection().multiply(3));
    12. player.setVelocity(new Vector(player.getVelocity().getX(), 1.0D, player.getVelocity().getZ()));
    13. player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1, 1);
    14. }
    15. }
    16. }
    17. }
     
    GrandmaJam likes this.
  3. Offline

    user_90854156

    Show the whole class.
    Do you get any errors? Remember to register the events.
     
  4. Offline

    Draconwolver

    ksbdude The problem with your code is that you are getting the block under the player, but don't forget that the pressure plate is not part of that block; it occupies the block you are standing in. So instead of getting the block under the player, get the block at the player's location.
     
    bennie3211 and AGuyWhoSkis like this.
  5. Offline

    ShearsSheep

  6. Offline

    xTrollxDudex

    ksbdude
    You have no idea how many times PlayerMoveEvent is fired, but let me tell you: An INSANE amount of times. use PlayerInteractEvent instead, at least it doesnt fire every other tick (pretty much) like PlayerMoveEvent.

    You can use the same implementation, but instead of getting the block by location, use PlayerInteractEvent#getClickedBlock(). Make sure to check that the Action is Action.PHYSICAL first though. Then you can launch the player.

    Note to self: The description to Action.PHYSICAL is surprisingly hilarious:
     
    DogeDev, sgavster and Garris0n like this.
  7. Offline

    ksbdude

    @xTrollxDudex and @ShearsSheep
    Im still getting some problems
    This does not work

    Code:java
    1. public void onLaunchMove(PlayerMoveEvent event) {
    2. Player player = event.getPlayer();
    3. Location playerLoc = player.getLocation();
    4. int ID = playerLoc.getWorld().getBlockAt(playerLoc).getRelative(0, -1, 0).getTypeId();
    5. int plate = playerLoc.getWorld().getBlockAt(playerLoc).getTypeId();
    6. if (ID == 133) {
    7. if (plate == 70) {
    8. player.setVelocity(player.getLocation().getDirection().multiply(3));
    9. player.setVelocity(new Vector(player.getVelocity().getX(), 1.0D, player.getVelocity().getZ()));
    10. player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1, 1);
    11. }
    12. }
    13. }


    I then tried to use something like this as Troll said which also isnt working
    Code:java
    1. @EventHandler
    2. public static final Action PHYSICAL(){
    3. return null;
    4.  
    5. }
     
  8. Offline

    _Filip

    ksb, it was already explained not to get the block below the player, but the block the player is in.

    There is also no need to get the id, since they are going to be removed soon.
    Get the Material.
     
  9. Offline

    ShearsSheep

    Okay here is my code for the jumpPads!

    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. private ArrayList<Player> jumpers = new ArrayList<Player>();
    4.  
    5. public void onEnable() {
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7. }
    8.  
    9. @EventHandler
    10. public void onPlayerMove(PlayerMoveEvent e) {
    11. if (e.getTo().getBlock().getRelative(BlockFace.DOWN).getType() == Material.STONE_PLATE) {
    12. e.getPlayer().setVelocity(e.getPlayer().getLocation().getDirection().multiply(4));
    13. e.getPlayer().setVelocity(new Vector(e.getPlayer().getVelocity().getX(), 1.0D, e.getPlayer().getVelocity().getZ()));
    14. jumpers.add(e.getPlayer());
    15. }
    16. }
    17.  
    Mhm...I will not spoon feed you , if you really need help msg me on skype.
     
  10. Offline

    Deleted user

    ShearsSheep

    Thank goodness you're not spoon-feeding, because there's two things wrong with that code that I can see off the bat.

    1) Why are you using PlayerMoveEvent? That's called over 40 times with one little bit of movement. (From Bukkit code comment) Just use PlayerInteract and Action.PHYSICAL

    2) You're storing Player objects, which, if you do it right, is fine. But you've made an arraylist and are repeatedly storing people, possibly more than once every time they jump, and you never clear it

    If someone was in need of 'spoon-feeding', you assume that they do not understand code very well. Your code, in the hands of someone new, could crash a server over time given enough players
     
    GrandmaJam likes this.
  11. Offline

    Garris0n

    PlayerMoveEvent shouldn't be called more than 20 times per second(unless there's lag or the player is using timer hacks), but whatever.
     
    GrandmaJam likes this.
  12. Offline

    Deleted user

    Garris0n
    idk. I remember going through the CraftBukkit section of Bukkit to check out NMS, and that's what I read in a comment.
     
  13. Offline

    bennie3211

    Quote from xTrollxDudex

    @ksbdude
    You have no idea how many times PlayerMoveEvent is fired, but let me tell you: An INSANE amount of times. use PlayerInteractEvent instead, at least it doesnt fire every other tick (pretty much) like PlayerMoveEvent.

    You can use the same implementation, but instead of getting the block by location, usePlayerInteractEvent#getClickedBlock(). Make sure to check that the Action is Action.PHYSICAL first though. Then you can launch the player.

    //end quote:

    Something like this :)


    Code:java
    1. @EventHandler
    2. public void onPlayerPush(PlayerInteractEvent event) {
    3.  
    4. if (event.getAction() == Action.PHYSICAL) {
    5.  
    6. //get location and if there is a pressureplate ON THAT LOCATION, dont look beneath it, because player will be "In the pressureplate"
    7. //If so, then launch them
    8. }
    9. }
     
    GrandmaJam and xTrollxDudex like this.
Thread Status:
Not open for further replies.

Share This Page