Skip to content

Instantly share code, notes, and snippets.

@Techno3600
Created February 9, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Techno3600/526d21c32164747310b3b1b0f23fd355 to your computer and use it in GitHub Desktop.
Save Techno3600/526d21c32164747310b3b1b0f23fd355 to your computer and use it in GitHub Desktop.
package com.nationmc.me.commands;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.nationmc.me.functions.F;
import net.minecraft.server.v1_8_R3.Item;
import net.minecraft.server.v1_8_R3.ItemStack;
public class QueuePvPCommand implements CommandExecutor {
public static Player QueueOne;
public static Player QueueTwo;
public static String PvPState;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = null;
//queuepvp <player> - Queues player for PvP (console command)
ItemStack[] armor;
armor[0] = new ItemStack(Material.DIAMOND_HELMET);
armor[1] = new ItemStack(Material.DIAMOND_CHESTPLATE);
armor[2] = new ItemStack(Material.DIAMOND_LEGGINGS);
armor[3] = new ItemStack(Material.DIAMOND_BOOTS);
if (sender.hasPermission("group.admin"))
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("end"))
{
PvPState = "IDLE";
sender.sendMessage(ChatColor.BOLD + "Force ending PvP.");
for (Player lp : Arrays.asList(QueueOne, QueueTwo))
{
lp.getInventory().clear();
lp.sendMessage(F.adminAction("PvP", "PvP has been force-ended. There is no winner"));
lp.chat("/spawn");
lp.getInventory().setHelmet(null);
lp.getInventory().setChestplate(null);
lp.getInventory().setLeggings(null);
lp.getInventory().setBoots(null);
}
QueuePvPCommand.QueueOne = null;
QueuePvPCommand.QueueTwo = null;
} else
{
p = Bukkit.getPlayer(args[0]);
sender.sendMessage(F.adminAction("PvP", "Force-queued PvP for:" + F.value(p.getName(), ".")));
}
} else
{
p = (Player) sender;
}
} else
{
p = (Player) sender;
}
if (QueueOne == null)
{
QueueOne = p;
p.sendMessage(F.main("PvP", "You have been queued for PvP."));
} else if (QueueTwo == null)
{
if (p != QueueOne)
{
QueueTwo = p;
startpvp(QueueOne, QueueTwo);
p.sendMessage(F.main("PvP", "You have been queued for PvP."));
QueueOne.sendMessage(F.main("PvP", "Your match is starting..."));
QueueTwo.sendMessage(F.main("PvP", "Your match is starting..."));
} else
{
p.sendMessage(F.main("PvP", "You have been unqueued from PvP."));
QueueOne = null;
}
} else if (QueueOne != null && QueueTwo != null)
{
p.sendMessage(F.error("PvP", "Two players are already queued, please wait and try again later."));
}
return false;
}
public static void startpvp(Player p1, Player p2)
{
PvPState = "ACTIVE";
for(Player p : Arrays.asList(p1, p2))
{
p.teleport(new Location(p.getWorld(), -669, 3, 403));
p.playSound(p.getLocation(), Sound.PORTAL_TRAVEL, 1F, 1F);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kit pvp " + p.getName());
p.setHealth(20L);
p.setSaturation(20L);
p.sendMessage(F.miniAnnouncement("PvP", "Put on your armor and FIGHT!"));
p.getInventory().getBoots().setType(Material.DIAMOND_BOOTS);
}
}
public static void endpvp(Player p1, Player p2, Player winner)
{
PvPState = "IDLE";
for (Player lp : Arrays.asList(p1, p2))
{
lp.getInventory().clear();
lp.sendMessage(F.main("PvP", "PvP ended, winner is..." + F.value(winner.getName(), ".")));
lp.chat("/spawn");
lp.getInventory().setHelmet(null);
lp.getInventory().setChestplate(null);
lp.getInventory().setLeggings(null);
lp.getInventory().setBoots(null);
}
QueuePvPCommand.QueueOne = null;
QueuePvPCommand.QueueTwo = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment