Hi! i'm trying to make a plugin that makes a player fly in the direction they looking. also they can speed up and slow down by pressing blocks (Red stone and Coal blocks), and I'm using a int for that. The problem is that once player clicks on a block, it changes the speed for all the players, and not only for him. so is there a way to do that? PLZ help p.s this is the code - Code: package me.RoBaMe; 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.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; public class MCM implements Listener { public MCM (MainClass plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } int VS = 0 ; @EventHandler public void MCE(PlayerMoveEvent e) { Player p = (Player)e.getPlayer(); if(e.getFrom().getBlockY() != e.getTo().getBlockY()-1){ if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.AIR){ p.setVelocity(p.getLocation().getDirection().multiply(VS)); public void SU(PlayerInteractEvent u){ Player pl =(Player) u.getPlayer(); ItemStack[] power = {new ItemStack(Material.SULPHUR)}; if(pl.getInventory().getItemInHand().getType() == Material.REDSTONE_BLOCK){ if(u.getAction() == Action.RIGHT_CLICK_AIR || u.getAction() == Action.RIGHT_CLICK_BLOCK){ if(VS<3){ VS = VS + 1; pl.getInventory().addItem(power); } } } else if(pl.getInventory().getItemInHand().getType() == Material.COAL_BLOCK){ if(u.getAction() == Action.RIGHT_CLICK_AIR || u.getAction() == Action.RIGHT_CLICK_BLOCK){ if(VS>0){ VS = VS - 1; pl.getInventory().removeItem(power);; } } } } } } } }
@RoBaMe You could either: Store the player's UUID and their speed in a map. Store it in a config file. I suggest storing it in a map because it's easier than having to create a config save defaults and all that. But, if you want it saved even after the server is shutting down, I'd suggest a config file instead.
You can use configs without saving them in a file. I found out that when forgot to use my saveConf() method. They will reset after reload. @RoBaMe I suggest you putting Actions in PlayerInteractEvent.