-1

So im creating a simple freeze plugin which is supposed to freeze me. Somehow it does not work because it does not recognize my oncommand. The plugin is supposed to toggle it on by adding the player who wrote the plugin onto the toggleList. i have 3 classes.

main class (Freeze.java)

package net.parinacraft.freeze;

    import org.bukkit.material.Command;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    import net.parinacraft.freeze.player.commands.komento;
    import net.parinacraft.freeze.komento;

    public class Freeze extends JavaPlugin {
        public static List<UUID> toggleList = new ArrayList<UUID>();

        @Override
        public void onEnable(){
            registerCommands();
            registerEvents();
        }

        public void registerCommands() {
            getCommand("freeze").setExecutor(new komento());
        }

        public void registerEvents(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Toggle(), this);
        }
    }

second class for the command i suppose (komento.java)

    package net.parinacraft.freeze;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.material.Command;

public class komento implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command Freeze, String label, String[] args){
        if(!(sender instanceof Player)){
            sender.sendMessage(ChatColor.RED + "Sinun pitää olla pelaaja käyttääkseen tätä komentoa");
            return true;
        }
        Player player = (Player) sender;
        if(!Freeze.toggleList.contains(player.getUniqueId())){
            player.sendMessage(ChatColor.GREEN + "sinut on jäädytetty tutkinnan ajaksi");
            Freeze.toggleList.add(player.getUniqueId());
        } else{
            player.sendMessage(ChatColor.RED +"Et ole enään jäädytetty");
            Freeze.toggleList.remove(player.getUniqueId());
        }
        return true;
    }

}

Then my third class for toggling the command on/off (Toggle.java)

package net.parinacraft.freeze;


import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;

import package net.parinacraft.;


public class Toggle implements Listener {
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent evt) {
        Player player = evt.getPlayer();
        if (Freeze.togglelist.contains(player.getUniqueId())){
            Location back = new Location(evt.getFrom().getWorld(), evt.getFrom().getX(), evt.getFrom().getY(), evt.getFrom().getZ());
            evt.getPlayer().teleport(back);
        }
    }
}

Also what am I supposed to add to the plugin.yml?

1 Answers1

1

Because you did not post plugin.yml file I suppose you are missing definition of the freeze command in it.

Typical plugin.yml file contains commands section where all command of plugin are defined.

name: Inferno
version: 1.4.1
description: This plugin is so 31337. You can set yourself on fire.
author: CaptainInflamo
authors: [Cogito, verrier, EvilSeph] 
website: http://forums.bukkit.org/threads/MyPlugin.31337/

main: com.captaininflamo.bukkit.inferno.Inferno
database: false
depend: [NewFire, FlameWire]

commands:
  flagrate:
    description: Set yourself on fire.
    aliases: [combust_me, combustMe]
    permission: inferno.flagrate
    usage: Syntax error! Simply type /&lt;command&gt; to ignite yourself.

In your case you should probably add:

commands:
  freeze:
    description: Freeze yourself.
    usage: Syntax error! Simply type /freeze to freeze yourself.

You can read about plugin.yml at:

Matej Kormuth
  • 2,139
  • 3
  • 35
  • 52