-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdf3ab7
commit 8da304b
Showing
1 changed file
with
131 additions
and
108 deletions.
There are no files selected for viewing
239 changes: 131 additions & 108 deletions
239
src/main/java/io/papermc/collabcraft/collabcraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,131 @@ | ||
package io.papermc.collabcraft; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.*; | ||
import org.bukkit.command.*; | ||
import org.bukkit.boss.*; | ||
import org.bukkit.inventory.*; | ||
import org.bukkit.*; | ||
import org.bukkit.entity.*; | ||
import org.bukkit.event.player.*; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import java.util.*; | ||
import java.lang.*; | ||
|
||
public class collabcraft extends JavaPlugin implements Listener,CommandExecutor { | ||
private Player controller; | ||
private ArrayList<Player> waiting = new ArrayList<Player>(); | ||
private int time = 30; //in seconds | ||
private BossBar turnTime = Bukkit.createBossBar("PlayerNameHere's turn",BarColor.BLUE,BarStyle.SOLID); | ||
private Runnable createRunnable(Player p){ | ||
Runnable r = new Runnable(){ | ||
public void run(){ | ||
String name = p.getName(); | ||
double progress = 0.0; | ||
turnTime.setTitle(name + "'s turn"); | ||
while (waiting.get(0) == p){ | ||
if (progress >= 100.0){ | ||
waiting.remove(0); | ||
if (!(waiting.size() == 0)){ | ||
Player author = waiting.get(0); | ||
p.setGameMode(GameMode.SPECTATOR); | ||
author.getInventory().setArmorContents(p.getInventory().getArmorContents()); | ||
author.getInventory().setExtraContents(p.getInventory().getExtraContents()); | ||
author.teleport(p.getLocation()); | ||
author.setGameMode(GameMode.SURVIVAL); | ||
turnThread = new Thread(createRunnable(author)); | ||
turnThread.start(); | ||
} | ||
} | ||
progress = progress + 1.0; | ||
turnTime.setProgress(progress); | ||
try{ | ||
Thread.sleep(time*10); | ||
}catch(Exception e){ | ||
|
||
} | ||
} | ||
} | ||
}; | ||
return r; | ||
} | ||
private Thread turnThread; | ||
public void onEnable() { | ||
Bukkit.getPluginManager().registerEvents(this, this); | ||
turnTime.setVisible(true); | ||
} | ||
public void onPlayerJoin(Player p){ | ||
p.setGameMode(GameMode.SPECTATOR); | ||
} | ||
public void onPlayerQuit(Player p){ | ||
if (waiting.get(0) == p){ | ||
waiting.remove(p); | ||
} | ||
} | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ | ||
if (sender instanceof Player) { | ||
Player author = (Player) sender; | ||
if (cmd.getName().equalsIgnoreCase("bypassturn")){ | ||
waiting.add(0,author); | ||
controller.setGameMode(GameMode.SPECTATOR); | ||
author.getInventory().setArmorContents(controller.getInventory().getArmorContents()); | ||
author.getInventory().setExtraContents(controller.getInventory().getExtraContents()); | ||
author.teleport(controller.getLocation()); | ||
controller = author; | ||
controller.setGameMode(GameMode.SURVIVAL); | ||
turnThread = new Thread(createRunnable(controller)); | ||
turnThread.start(); | ||
return true; | ||
}else if (cmd.getName().equalsIgnoreCase("endturn")){ | ||
if (waiting.contains(author)){ | ||
waiting.remove(author); | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else if (cmd.getName().equalsIgnoreCase("taketurn")){ | ||
if (!(waiting.contains(author))){ | ||
waiting.add(author); | ||
if (waiting.get(0) == author){ | ||
turnThread = new Thread(createRunnable(author)); | ||
turnThread.start(); | ||
} | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else if (cmd.getName().equalsIgnoreCase("controllertp")) { | ||
author.teleport(controller.getLocation()); | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else{ | ||
return false; | ||
} | ||
} | ||
} | ||
package io.papermc.collabcraft; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.*; | ||
import org.bukkit.command.*; | ||
import org.bukkit.boss.*; | ||
import org.bukkit.inventory.*; | ||
import org.bukkit.*; | ||
import org.bukkit.entity.*; | ||
import org.bukkit.event.inventory.*; | ||
import org.bukkit.event.player.*; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import java.util.*; | ||
import java.lang.*; | ||
|
||
public class collabcraft extends JavaPlugin implements Listener,CommandExecutor { | ||
private Player controller; | ||
private ArrayList<Player> waiting = new ArrayList<Player>(); | ||
private int time = 30; //in seconds | ||
private BossBar turnTime = Bukkit.createBossBar("PlayerNameHere's turn",BarColor.BLUE,BarStyle.SOLID); | ||
private PlayerInventory inventory = null; | ||
private Location location = Bukkit.getWorld("world").getSpawnLocation(); | ||
private Location spawn = Bukkit.getWorld("world").getSpawnLocation(); | ||
private Runnable createRunnable(Player p){ | ||
Runnable r = new Runnable(){ | ||
public void run(){ | ||
String name = p.getName(); | ||
double progress = 0.0; | ||
turnTime.setTitle(name + "'s turn"); | ||
turnTime.setProgress(0.0); | ||
while (waiting.get(0) == p){ | ||
if (progress >= 100.0){ | ||
waiting.remove(0); | ||
inventory = p.getInventory(); | ||
location = p.getLocation(); | ||
spawn = p.getBedSpawnLocation(); | ||
if (!(waiting.size() == 0)){ | ||
Player author = waiting.get(0); | ||
p.setGameMode(GameMode.SPECTATOR); | ||
author.getInventory().setArmorContents(p.getInventory().getArmorContents()); | ||
author.getInventory().setExtraContents(p.getInventory().getExtraContents()); | ||
author.teleport(p.getLocation()); | ||
author.setBedSpawnLocation(p.getBedSpawnLocation()); | ||
author.setGameMode(GameMode.SURVIVAL); | ||
turnThread = new Thread(createRunnable(author)); | ||
turnThread.start(); | ||
} | ||
} | ||
progress = progress + 1.0; | ||
turnTime.setProgress(progress); | ||
try{ | ||
Thread.sleep(time*10); | ||
}catch(Exception e){ | ||
|
||
} | ||
} | ||
} | ||
}; | ||
return r; | ||
} | ||
private Thread turnThread; | ||
public void onEnable() { | ||
Bukkit.getPluginManager().registerEvents(this, this); | ||
turnTime.setVisible(true); | ||
} | ||
public void onPlayerJoin(Player p){ | ||
p.setGameMode(GameMode.SPECTATOR); | ||
} | ||
public void onPlayerQuit(Player p){ | ||
if (waiting.contains(p)){ | ||
waiting.remove(p); | ||
} | ||
} | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ | ||
if (sender instanceof Player) { | ||
Player author = (Player) sender; | ||
if (cmd.getName().equalsIgnoreCase("bypassturn")){ | ||
waiting.add(0,author); | ||
inventory = controller.getInventory(); | ||
location = controller.getLocation(); | ||
spawn = controller.getBedSpawnLocation(); | ||
controller.setGameMode(GameMode.SPECTATOR); | ||
author.getInventory().setArmorContents(controller.getInventory().getArmorContents()); | ||
author.getInventory().setExtraContents(controller.getInventory().getExtraContents()); | ||
author.teleport(controller.getLocation()); | ||
author.setBedSpawnLocation(spawn); | ||
controller = author; | ||
controller.setGameMode(GameMode.SURVIVAL); | ||
turnThread = new Thread(createRunnable(controller)); | ||
turnThread.start(); | ||
return true; | ||
}else if (cmd.getName().equalsIgnoreCase("endturn")){ | ||
if (waiting.contains(author)){ | ||
if (waiting.get(0) == author){ | ||
inventory = author.getInventory(); | ||
location = author.getLocation(); | ||
spawn = author.getBedSpawnLocation(); | ||
} | ||
waiting.remove(author); | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else if (cmd.getName().equalsIgnoreCase("taketurn")){ | ||
if (!(waiting.contains(author))){ | ||
waiting.add(author); | ||
if (waiting.get(0) == author){ | ||
author.setGameMode(GameMode.SURVIVAL); | ||
author.getInventory().setArmorContents(inventory.getArmorContents()); | ||
author.getInventory().setExtraContents(inventory.getExtraContents()); | ||
author.teleport(location); | ||
author.setBedSpawnLocation(spawn); | ||
turnThread = new Thread(createRunnable(author)); | ||
turnThread.start(); | ||
} | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else if (cmd.getName().equalsIgnoreCase("controllertp")) { | ||
author.teleport(controller.getLocation()); | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
}else{ | ||
return false; | ||
} | ||
} | ||
} |