I just started coding Bukkit and I have been trying to code a plugin that enable pvp for a certain player, and can disable it but only for themselves. It was working fine until I found I needed an event to make this work, yet I have not learned of the event I need. After looking at a few videos/things online I cannot find anything to help me. If you could tell me how I would do this, that would be great. Also if you could explain more about events that would also be appreciated :)
package me.impatheimpaler.test;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class togglepvp extends JavaPlugin implements Listener{
public void onEnable() {
}
public void onDisable() {
}
List<String> toggled = new ArrayList<String>();
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("togglepvp")) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only a Player can run this command.");
return false;
}
Player player = (Player) sender;
if (toggled.contains(player.getName())) {
player.sendMessage(ChatColor.RED + "Outgoing PvP - ON");
toggled.add(player.getName());
return true;
}
player.sendMessage(ChatColor.GREEN + "Outgoing PvP - OFF");
toggled.remove(player.getName());
return true;
}
}
}