Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a ton of stuff #9

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a546c9c
basic implimentation of ParkourRun variables
nice6599 May 22, 2020
f695c3b
add class methods
nice6599 May 24, 2020
75c3198
fix some stuff for testing and formatting
nice6599 May 24, 2020
74aa079
added switch statement
nice6599 May 24, 2020
f2524b3
added more stuff to switch statement and removed redundnt code
nice6599 May 24, 2020
736ac6f
add functionality to set start and end
nice6599 May 26, 2020
131c246
add spawn to ParkourMap class
nice6599 May 26, 2020
c3621f2
add setspawn function to the pk admin command
nice6599 May 26, 2020
4b0bbdc
add bounding box information
nice6599 May 26, 2020
a96d101
Merge branch 'master' into parkour-command
nice6599 May 26, 2020
3c2bccb
adds some stuff and fixes things
nice6599 May 26, 2020
b5ad130
add getTime() method and calculate time
nice6599 May 26, 2020
8afc2fc
Merge branch 'master' into parkour-command
nice6599 May 26, 2020
23ea1b7
remove bounding box info as it is unneccisary
nice6599 May 26, 2020
3f750d6
removes bounding box info from the ParkourMap class
nice6599 May 26, 2020
72ccdde
cleans up some files
nice6599 May 26, 2020
a47df3b
now automatically adds spawnpoint to maps without it
nice6599 May 26, 2020
bd3ecb3
adds getCheckpointLocation()
nice6599 May 26, 2020
641f717
update parkourRun class
nice6599 May 26, 2020
efdf66c
Merge branch 'master' into ParkourRun
nice6599 May 26, 2020
6f047a3
Merge branch 'ParkourRun' into parkour-command
nice6599 May 26, 2020
67176bf
adds PlayerUtils and fixes some stuff
nice6599 May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.hackclub.hackcraft.parkour.ParkourPlugin;
import com.hackclub.hackcraft.parkour.objects.ParkourMap;
import com.hackclub.hackcraft.parkour.utils.Util;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.md_5.bungee.api.ChatColor;

public class ParkourAdminCommand implements CommandExecutor {

Expand All @@ -20,7 +20,8 @@ public ParkourAdminCommand(ParkourPlugin plugin) {
this.plugin = plugin;
}

public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
public boolean onCommand(CommandSender commandSender, Command command, String label,
String[] args) {

Player sender = (Player) commandSender;

Expand All @@ -29,106 +30,204 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
return true;
}

if (args[0].equalsIgnoreCase("details")) {
Optional<ParkourMap> pm = plugin.parkourUtil.getFromID(args[1]);
// define global variables
Optional<ParkourMap> pm = null;
ParkourMap pm2 = null;

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");


switch (args[0].toLowerCase()) {

case "details":
pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

sender.sendMessage(ChatColor.AQUA + "Map \"" + ChatColor.GREEN + pm.get().getName()
+ ChatColor.AQUA + "\": ");
sender.sendMessage(
"Start at " + ChatColor.BLUE + Util.locationToChat(pm.get().getStart()));
sender.sendMessage(
"End at " + ChatColor.BLUE + Util.locationToChat(pm.get().getEnd()));
sender.sendMessage(
"Spawn at " + ChatColor.BLUE + Util.locationToChat(pm.get().getSpawn()));
sender.sendMessage("Checkpoints: ");
for (int i = 0; i < pm.get().getCheckpoints().size(); i++) {
Location l = pm.get().getCheckpoints().get(i);

plugin.getLogger().info(String.valueOf(l.distance(sender.getLocation())));

if (l.distance(sender.getLocation()) < 5) {
sender.sendMessage(ChatColor.GREEN + String.valueOf(i) + ": "
+ ChatColor.BLUE + Util.locationToChat(l) + ChatColor.GREEN
+ " (You are next to this one!)");
continue;
}

sender.sendMessage(ChatColor.GREEN + String.valueOf(i) + ": " + ChatColor.BLUE
+ Util.locationToChat(l));
}
return true;
}

sender.sendMessage(ChatColor.AQUA + "Map \"" + ChatColor.GREEN + pm.get().getName() + ChatColor.AQUA + "\": ");
sender.sendMessage("Start at " + ChatColor.BLUE + Util.locationToChat(pm.get().getStart()));
sender.sendMessage("End at " + ChatColor.BLUE + Util.locationToChat(pm.get().getEnd()));
sender.sendMessage("Checkpoints: ");
for (int i = 0; i < pm.get().getCheckpoints().size(); i++) {
Location l = pm.get().getCheckpoints().get(i);

plugin.getLogger().info(String.valueOf(l.distance(sender.getLocation())));
// admin wants to make new parkour
case "new":
// args[1] is id, args[2] is name
pm2 = new ParkourMap(args[1], args[2]);

pm2.setStart(sender.getLocation().getBlock().getLocation());
pm2.setEnd(sender.getLocation().getBlock().getLocation());
pm2.setSpawn(sender.getLocation().getBlock().getLocation());

if (l.distance(sender.getLocation()) < 5) {
sender.sendMessage(ChatColor.GREEN + String.valueOf(i) + ": " + ChatColor.BLUE + Util.locationToChat(l) + ChatColor.GREEN + " (You are next to this one!)");
continue;

if (plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Parkour map successfully created!");
return true;
}

sender.sendMessage(ChatColor.GREEN + String.valueOf(i) + ": " + ChatColor.BLUE + Util.locationToChat(l));
}
return true;
}
sender.sendMessage(ChatColor.RED + "Sorry! It didn't save :(");
return false;

// admin wants to make new parkour
if (args[0].equalsIgnoreCase("new")) {
// args[1] is id, args[2] is name
ParkourMap pm = new ParkourMap(args[1], args[2]);

pm.setStart(sender.getLocation().getBlock().getLocation());
pm.setEnd(sender.getLocation().getBlock().getLocation());

case "adch":
// admin wants to add checkpoint

if (plugin.parkourUtil.saveParkourMap(pm)) {
sender.sendMessage(ChatColor.GREEN + "Parkour map successfully created!");
return true;
}
// #getLocation gives the block that the feet are in so you just get what's
// facing down
Block standingIn = sender.getLocation().getBlock();

sender.sendMessage(ChatColor.RED + "Sorry! It didn't save :(");
return false;
pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

}
pm2 = pm.get();

// admin wants to add checkpoint
if (args[0].equalsIgnoreCase("adch")) {
// #getLocation gives the block that the feet are in so you just get what's facing down
Block standingIn = sender.getLocation().getBlock();
if (args.length == 3) {
// we've specified a before
pm2.addCheckpoint(standingIn.getLocation(), Integer.parseInt(args[2]));
if (plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(
ChatColor.GREEN + "Checkpoint added before index " + args[2] + "!");
return true;
}
}

Optional<ParkourMap> pm = plugin.parkourUtil.getFromID(args[1]);
if (pm2.addCheckpoint(standingIn.getLocation())
&& plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Checkpoint added!");
return true;
}

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}
sender.sendMessage(
ChatColor.RED + "An error occured whilst trying to add your checkpoint!");
return false;



case "rmch":
// admin wants to remove checkpoint

pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

pm2 = pm.get();

if (pm2.removeCheckpoint(Integer.parseInt(args[2]))
&& plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Checkpoint removed!");
return true;
} else {
sender.sendMessage(ChatColor.RED + "Error while removing checkpoint!");
return true;

}

ParkourMap pm2 = pm.get();

if (args.length == 3) {
// we've specified a before
pm2.addCheckpoint(standingIn.getLocation(), Integer.parseInt(args[2]));
case "setstart":
// used for setting the start of a parkour map
pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

pm2 = pm.get();

pm2.setStart(sender.getLocation().getBlock().getLocation());
if (plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Checkpoint added before index " + args[2] + "!");
sender.sendMessage(ChatColor.GREEN + "New startpoint set!");
return true;
}
}

if(pm2.addCheckpoint(standingIn.getLocation()) && plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Checkpoint added!");
return true;
}
sender.sendMessage(
ChatColor.RED + "An error occured whilst trying to add your startpoint!");
return false;

sender.sendMessage(ChatColor.RED + "An error occured whilst trying to add your checkpoint!");
return false;
}

// admin wants to remove checkpoint
if (args[0].equalsIgnoreCase("rmch")) {
Optional<ParkourMap> pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}
case "setend":
// used for setting the end of a parkour map

ParkourMap pm2 = pm.get();
pm = plugin.parkourUtil.getFromID(args[1]);

if (pm2.removeCheckpoint(Integer.parseInt(args[2])) && plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "Checkpoint removed!");
return true;
} else {
sender.sendMessage(ChatColor.RED + "Error while removing checkpoint!");
return true;
}
}
if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

pm2 = pm.get();


pm2.setEnd(sender.getLocation().getBlock().getLocation());
if (plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "New endpoint set!");
return true;
}


sender.sendMessage(
ChatColor.RED + "An error occured whilst trying to add your endpoint!");
return false;

case "setspawn":
// used for setting the spawnpoint for a parkour map

pm = plugin.parkourUtil.getFromID(args[1]);

if (!pm.isPresent()) {
sender.sendMessage(ChatColor.RED + "That map doesn't exist!");
return true;
}

pm2 = pm.get();


return false;
pm2.setSpawn(sender.getLocation().getBlock().getLocation());
if (plugin.parkourUtil.saveParkourMap(pm2)) {
sender.sendMessage(ChatColor.GREEN + "New spawnpoint set!");
return true;
}

sender.sendMessage(
ChatColor.RED + "An error occured whilst trying to add your spawnpoint!");
return false;


default:
return false;
}

}
}
Loading