Freeze

Discussion in 'Spigot Plugin Development' started by KingDotCom, May 28, 2016.

  1. Hi Spigot, I was wondering if someone could help me with my plugin and totally edit it. I am trying to freeze the player with a command /ff <player> and if the player disconnects it will ban them for perm. This is my code.

    Code (Text):
    package me.dragon.fam;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements CommandExecutor {

        public boolean ffs = false;

        public void onEnable() {
            System.out.println("Enabled");

        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            int length = args.length;
            if (label.equalsIgnoreCase("ff")) {
                if(ffs == false){
                    ffs = true;


                }else{
                    Player targetPlayer = player.getServer().getPlayer(args[0]);
                    targetPlayer.setWalkSpeed(1);
                    ffs = false;
                }
                if (sender instanceof Player) {
                    if (length == 1) {
                        if (ffs == true) {
                            Player targetPlayer = player.getServer().getPlayer(args[0]);
                            targetPlayer.setWalkSpeed(-0);
                            player.sendMessage(ChatColor.DARK_RED + "IF YOU LOG OUT YOU WILL BE BANNED!");

                        }
                           
                       
                    }
                }
            }
            return false;
        }

        public void ffQuit(PlayerQuitEvent event) {
            Player p = event.getPlayer();
            if(event.getPlayer().isOp()){
                return;
            }else{
                if(ffs == true){
                    Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(), "/ban " + p.getName());
                    ffs = false;
                   
                   
                }
            }
             

    }
    }
     
  2. Why not just use an arraylist
     
  3. eqx

    eqx

    PlayerQuitEvent
    Check if frozen
    Ban
     
  4. they can still move if you use your method. You could remove the player entity from the world.
     
  5. Basically add them to an array list when frozen, when a player leaves, check if they are in the array list, then ban them.
     
  6. could you possibly help me with it @SamB440 im new to coding
     
  7. Use a arrayList and create a FreezeUtil command and a FreezeCommand
     
  8. @Angeles Can you help me more than that? Possibly like doing it for me? I don't know what you mean AS I said I am new to coding.
     
  9. You need to register your PlayerQuitEvent in the onEnable, and take the tips that the other's have given you.

    "Can you help me more than that? Possibly like doing it for me? I don't know what you mean AS I said I am new to coding."

    We aren't here to make the plugin for you, we are here to help. If you want the plugin done for you completely pay someone or find a public plugin.

    no spoon feeding zone
     
  10. PlayerQuitEvent event for the player disconnect

    check if the player is frozen , if so setBanned(true);

    if he tried to join at PlayerJoinEvent check if the player is banned , if so cancel the event
     
  11. This code makes me weep.

    • You have an unsafe cast with Player.
    • You don't check to see if the target player is null.
    • Don't use label, use cmd.getName()#
    • You really need to learn the basics of Java before you start writing plugins.
    • No @EventHandler notation.
    • No registration of Your events.
    • Unessecary return statement.
    • Unessecary check to see if player is OP. Check permission instead.
    • When banning a player you need to use the UUID.
    • Use an ArrayList that stores the player's UUID as previously stated above by other users.

    Please read everything in this completely before developing spigot plugins.
     
    • Agree Agree x 1