Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cramer.jason;
- import org.bukkit.Bukkit;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.entity.Player;
- import java.util.ArrayList;
- import java.util.Random;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- /**
- *
- * @author Jason
- * Description:
- * Type command to get name added to volunteer list. when there are 3 players in it, it will run a method that picks a
- * random name from he volunteer list and adds it to the chosen list. When a chosen dies, it will pick another random
- * player if there are 3 players at least. Object of game is to kill the chosen player, it's like a manhunt. I realize
- * this is pretty simple stuff but I literally just made it today and I'm planning on adding a method that gives a reward
- * to whoever kills the chosen one (if applicable), also a second command that tells you who the chosen one is.
- */
- public class BlankPlugin extends JavaPlugin implements Listener {
- @Override
- public void onEnable() {
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable() {
- }
- ArrayList<String> chosen = new ArrayList<String>();
- ArrayList<String> volunteer = new ArrayList<String>();
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- if (cmd.getName().equalsIgnoreCase("volunteer")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "The console cannot be chosen!");
- return true;
- }
- Player player = (Player) sender;
- if (volunteer.contains(player.getName())) {
- volunteer.remove(player.getName());
- sender.sendMessage(ChatColor.GREEN + "Player " + player.getName() + " has been removed from the volunteer list.");
- return true;
- } else {
- volunteer.add(player.getName());
- if (volunteer.size() == 3) {
- choosePlayer();
- }
- sender.sendMessage(ChatColor.GREEN + "Player " + player.getName() + " has been added to the volunteer list.");
- }
- }
- return true;
- }
- public void choosePlayer() {
- Random r = new Random();
- String s = volunteer.get(r.nextInt(volunteer.size()));
- chosen.add(s);
- Bukkit.broadcastMessage(ChatColor.GREEN + "Player " + s + " has been chosen!");
- }
- @EventHandler
- public void onPlayerDeath(PlayerDeathEvent e) {
- Player p = e.getEntity().getPlayer();
- if (chosen.contains(p.getName())) {
- Bukkit.broadcastMessage(ChatColor.RED + "The Chosen player " + p.getName() + " has died!");
- chosen.remove(p.getName());
- if (volunteer.size() >= 3) {
- choosePlayer();
- }
- }
- }
- @EventHandler
- public void onPlayerQuit(PlayerQuitEvent e) {
- Player p = e.getPlayer();
- if (chosen.contains(p.getName())) {
- Bukkit.broadcastMessage(ChatColor.RED + "The Chosen player " + p.getName() + " has quit!");
- chosen.remove(p.getName());
- if (volunteer.size() >= 3) {
- choosePlayer();
- }
- }
- if (volunteer.contains(p.getName())) {
- volunteer.remove(p.getName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement