quickly (Double) jumping on blocks that are placed

Discussion in 'Plugin Development' started by Weasel_Squeezer, Mar 2, 2013.

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

    Weasel_Squeezer

    The title may sound confusing, and that is because my problem is hard to explain in a short title. Pretty much I need to prevent players from jumping and placing a block under them and then jumping on that one when they are not allowed tp place or build blocks. This causes players to "double jump" in a way, and it is even possible to do a triple jump using this method. So players could get over fences and other obstacles which they should not be able to get over.
    Does a plugin exist to fix this issue? I have seen some servers where if you try to do this, when you jump on the block you placed. it will teleport to to the ground making it impossible. If those plugins are not public, how would I go about combining listeners to fix this issue?
     
  2. Offline

    Tirelessly

    if(blockplaceevent.isCancelled()) player.setVelocity(0,-1,0);

    Try something like that.
     
  3. Offline

    Weasel_Squeezer

    That would stop all movement of the player that places a block. I only want them to not be able to jump or have an upward velocity when they try to jump on a block
     
  4. Offline

    Tirelessly

    player.setVelocity(player.getVelocity().multiply(1,0.25,1));
    Play around with the values.
     
  5. Offline

    Weasel_Squeezer

    Nothing I try works. Like there is no effect to setting the velocity of the player at all.
    is there not plugins for this already?
     
  6. Offline

    Tirelessly

    Show a bit of code if you can?
     
  7. Offline

    Weasel_Squeezer

    I got it to work alright doing this:
    Code:java
    1. @EventHandler (priority = EventPriority.HIGHEST)
    2. public void onplayerDoubleJump(BlockPlaceEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.isCancelled()) {
    5. double blockX = event.getBlock().getLocation().getX();
    6. double blockY = event.getBlock().getLocation().getY();
    7. double blockZ = event.getBlock().getLocation().getZ();
    8. double playerX = player.getLocation().getX();
    9. double playerZ = player.getLocation().getZ();
    10.  
    11. double distanceX = 0;
    12. if (blockX > playerX) {
    13. distanceX = blockX - playerX;
    14. } else {
    15. distanceX = playerX - blockX;
    16. }
    17. double distanceZ = 0;
    18. if (blockZ > playerZ) {
    19. distanceZ = blockZ - playerZ;
    20. } else {
    21. distanceZ = playerZ - blockZ;
    22. }
    23. if (distanceX <= 1.5 && distanceZ <= 1.5) {
    24. Location safeLocation = new Location(player.getWorld(), blockX, blockY, blockZ, player.getLocation().getYaw(), player.getLocation().getPitch());
    25. player.teleport(safeLocation);
    26. }
    27. }
    28. }
     
  8. Offline

    Weasel_Squeezer

    OH Wow! thanks! haha after I write code to fix this problem XD. I'll probably just de-compile this plugin and add the basic even listener to one of my current plugins. i don't need to load a whole new plugin just for this...
     
  9. You should at least give the author credits for that bit because you're basically copypasting his code without his consent.
     
  10. Offline

    Weasel_Squeezer

    lol here is the entire plugin. This is almost literally what I did for the listener the first time through.

    Code:java
    1. import org.bukkit.Server;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.EventPriority;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.BlockPlaceEvent;
    7. import org.bukkit.plugin.PluginManager;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.util.Vector;
    10.  
    11. public class AntiBlockJump extends JavaPlugin
    12. implements Listener
    13. {
    14. public void onEnable()
    15. {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=false)
    20. public void onBlockPlace(BlockPlaceEvent event) {
    21. if (((!event.canBuild()) || (event.isCancelled())) && (!event.getPlayer().hasPermission("antiblockjump.bypass")))
    22. event.getPlayer().setVelocity(new Vector(0, -5, 0));
    23. }
    24. }
     
  11. Offline

    turkey2349

    I wouldn't recommend takin his code if there's no source code available. I'd at least ask the creator then give him credit for creating the code. :p
     
  12. Offline

    Weasel_Squeezer

    Look at my above post. That isn't anything to give credit for. Tirelessly gave the same exact solution and I had pretty much the same code before.

    EDIT: But I will stick with my code. It works well.
     
Thread Status:
Not open for further replies.

Share This Page