Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SPLEEF CLASS
- package me.kahjiit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Spleef extends JavaPlugin {
- public Arena arena = new Arena(this);
- public String tag = ("[" + ChatColor.AQUA + "Spleef" + ChatColor.WHITE + "] ");
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this.arena, this);
- getConfig().options().copyDefaults(true);
- saveConfig();
- }
- public void onDisable() {
- saveConfig();
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(command.getName().equalsIgnoreCase("spleef")) {
- Player player = (Player) sender;
- if(args.length == 0) {
- player.sendMessage(tag + ChatColor.DARK_AQUA + "= Spleef Commands =");
- player.sendMessage(tag + ChatColor.AQUA + "/Spleef join" + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY + "Joins the game");
- player.sendMessage(tag + ChatColor.AQUA + "/Spleef leave" + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY + "Leaves the game");
- player.sendMessage(tag + ChatColor.AQUA + "/Spleef version" + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY + "See the version");
- if(player.hasPermission("spleef.admin")) {
- player.sendMessage(tag + ChatColor.AQUA + "/Spleef setlobby" + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY + "Sets the lobby");
- player.sendMessage(tag + ChatColor.AQUA + "/Spleef setspawn" + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY + "Sets the arena spawn");
- }
- }
- if(args.length == 1) {
- if(args[0].equalsIgnoreCase("join")) {
- arena.addPlayer(player);
- if(arena.players.size() == 1) {
- player.sendMessage(tag + ChatColor.AQUA + "You have joined the Spleef queue! Waiting for more players...");
- }
- else {
- player.sendMessage(tag + ChatColor.AQUA + "You have joined the Spleef queue!");
- arena.start();
- }
- }
- if(args[0].equalsIgnoreCase("leave")) {
- arena.removePlayer(player);
- player.sendMessage(tag + ChatColor.AQUA + "You have left the Spleef queue, thanks for playing!");
- }
- if(args[0].equalsIgnoreCase("version")) {
- arena.setLobby(player);
- player.sendMessage(tag + ChatColor.AQUA + "Running " + ChatColor.DARK_AQUA + "Spleef v1.0 " + ChatColor.AQUA + "by Kahjiit");
- }
- if(args[0].equalsIgnoreCase("setlobby")) {
- if(player.hasPermission("spleef.admin")) {
- arena.setLobby(player);
- player.sendMessage(tag + ChatColor.AQUA + "You have successfully set the lobby!");
- }
- else {
- player.sendMessage(ChatColor.RED + "You don't have permission.");
- }
- }
- if(args[0].equalsIgnoreCase("setspawn")) {
- if(player.hasPermission("spleef.admin")) {
- arena.setSpawn(player);
- player.sendMessage(tag + ChatColor.AQUA + "You have successfully set the spawn!");
- }
- else {
- player.sendMessage(ChatColor.RED + "You don't have permission.");
- }
- }
- if(args[0].equalsIgnoreCase("start")) {
- arena.start();
- }
- }
- if(args.length > 1) {
- player.sendMessage(tag + ChatColor.AQUA + "Too many arguments!");
- player.sendMessage(tag + ChatColor.AQUA + "Use /spleef instead.");
- }
- }
- return true;
- }
- }
- ARENA CLASS
- package me.kahjiit;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.inventory.ItemStack;
- public class Arena implements Listener {
- Spleef plugin;
- public Arena(Spleef plugin) {
- this.plugin = plugin;
- }
- public List<UUID> players = new ArrayList<UUID>();
- private int countdown;
- private int game;
- public void addPlayer(Player player) {
- if(!this.players.contains(player.getUniqueId())) {
- this.players.add(player.getUniqueId());
- }
- }
- public void removePlayer(Player player) {
- if(this.players.contains(player.getUniqueId())) {
- this.players.remove(player.getUniqueId());
- }
- }
- public void cycleMessage(String message) {
- for(UUID uuid : this.players) {
- if(Bukkit.getPlayer(uuid) != null) {
- Bukkit.getPlayer(uuid).sendMessage(message);
- }
- }
- }
- public void setGameInventories() {
- for(UUID uuid : this.players) {
- if(Bukkit.getPlayer(uuid) != null) {
- Bukkit.getPlayer(uuid).getInventory().clear();
- Player player = Bukkit.getPlayer(uuid);
- if(Bukkit.getPlayer(uuid).hasPermission("spleef.perks")) {
- ItemStack diamond_shovel = new ItemStack(Material.DIAMOND_SPADE);
- player.getInventory().addItem(new ItemStack[] { diamond_shovel });
- }
- else {
- ItemStack iron_shovel = new ItemStack(Material.IRON_SPADE);
- player.getInventory().addItem(new ItemStack[] { iron_shovel });
- }
- }
- }
- }
- public void setLobby(Player player) {
- if(!this.plugin.getConfig().contains("Spleef.Lobby")) {
- this.plugin.getConfig().addDefault("Spleef.Lobby" + ".X", player.getLocation().getX());
- this.plugin.getConfig().addDefault("Spleef.Lobby" + ".Y", player.getLocation().getY());
- this.plugin.getConfig().addDefault("Spleef.Lobby" + ".Z", player.getLocation().getZ());
- this.plugin.saveConfig();
- }
- else {
- this.plugin.getConfig().set("Spleef.Lobby.X", Double.valueOf(player.getLocation().getX()));
- this.plugin.getConfig().set("Spleef.Lobby.Y", Double.valueOf(player.getLocation().getY()));
- this.plugin.getConfig().set("Spleef.Lobby.Z", Double.valueOf(player.getLocation().getZ()));
- this.plugin.saveConfig();
- }
- }
- public void setSpawn(Player player) {
- if(!this.plugin.getConfig().contains("Spleef.Spawn")) {
- this.plugin.getConfig().addDefault("Spleef.Spawn" + ".X", player.getLocation().getX());
- this.plugin.getConfig().addDefault("Spleef.Spawn" + ".Y", player.getLocation().getY());
- this.plugin.getConfig().addDefault("Spleef.Spawn" + ".Z", player.getLocation().getZ());
- this.plugin.saveConfig();
- }
- else {
- this.plugin.getConfig().set("Spleef.Spawn.X", Double.valueOf(player.getLocation().getX()));
- this.plugin.getConfig().set("Spleef.Spawn.Y", Double.valueOf(player.getLocation().getY()));
- this.plugin.getConfig().set("Spleef.Spawn.Z", Double.valueOf(player.getLocation().getZ()));
- this.plugin.saveConfig();
- }
- }
- public void teleportLobby() {
- for(UUID uuid : this.players) {
- if(Bukkit.getPlayer(uuid) != null) {
- Player victim = Bukkit.getPlayer(uuid);
- if(this.plugin.getConfig().contains("Spleef.Lobby")) {
- double x = this.plugin.getConfig().getDouble("Spleef.Lobby.X");
- double y = this.plugin.getConfig().getDouble("Spleef.Lobby.Y");
- double z = this.plugin.getConfig().getDouble("Spleef.Lobby.Z");
- Location lobby = new Location(victim.getWorld(), x, y ,z);
- victim.teleport(lobby);
- }
- else {
- victim.sendMessage(plugin.tag + ChatColor.AQUA + "Couldn't teleport as there is no lobby set!");
- }
- }
- }
- }
- public void teleportSpawn() {
- for(UUID uuid : this.players) {
- if(Bukkit.getPlayer(uuid) != null) {
- Player player = Bukkit.getPlayer(uuid);
- if(this.plugin.getConfig().contains("Spleef.Spawn")) {
- double x = this.plugin.getConfig().getDouble("Spleef.Spawn.X");
- double y = this.plugin.getConfig().getDouble("Spleef.Spawn.Y");
- double z = this.plugin.getConfig().getDouble("Spleef.Spawn.Z");
- Location spawn = new Location(player.getWorld(), x, y ,z);
- player.teleport(spawn);
- }
- else {
- player.sendMessage(plugin.tag + ChatColor.AQUA + "Couldn't teleport as there is no spawn set!");
- }
- }
- }
- }
- public void start() {
- if(this.players.size() > 1) {
- this.countdown = plugin.getConfig().getInt("Spleef.Countdown");
- this.game = Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
- public void run() {
- if (Arena.this.countdown > 0) {
- if(Arena.this.countdown == 5 || Arena.this.countdown == 10) {
- Bukkit.broadcastMessage(plugin.tag + ChatColor.AQUA + "The game will be starting in " + Arena.this.countdown + " seconds!");
- }
- Arena.this.countdown --;
- }
- else {
- Bukkit.getScheduler().cancelTask(Arena.this.game);
- if(Arena.this.players.size() < 2) {
- Bukkit.broadcastMessage(plugin.tag + ChatColor.AQUA + "The game has been cancelled! Waiting for more players...");
- return;
- }
- Arena.this.setGameInventories();
- Arena.this.teleportSpawn();
- Arena.this.countdown += plugin.getConfig().getInt("Spleef.Countdown");
- }
- }
- }, 0, 20);
- }
- }
- @EventHandler
- public void onDamage(EntityDamageEvent event) {
- if(event.getCause().equals(EntityDamageEvent.DamageCause.LAVA)) {
- Player player = (Player) event.getEntity();
- if(this.players.contains(player.getUniqueId())) {
- this.teleportLobby();
- player.getInventory().clear();
- this.cycleMessage(plugin.tag + ChatColor.DARK_AQUA + player.getName() + ChatColor.AQUA + " has been defeated!");
- player.sendMessage(plugin.tag + ChatColor.AQUA + "You have been defeated! Type /spleef join again to join the next game.");
- if(this.players.size() == 1) {
- Player winner = Bukkit.getPlayer(this.players.get(0));
- Bukkit.broadcastMessage(plugin.tag + ChatColor.DARK_AQUA + winner.getName() + ChatColor.AQUA + " has won the game!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement