Skip to content

Commit

Permalink
Merge pull request #1 from BananaFalls/master
Browse files Browse the repository at this point in the history
Update messages to be in line with other bnbmc plugins.
Fix coloring and grammar issues.
Add aliases.
  • Loading branch information
Vrabbers authored Mar 26, 2020
2 parents 4920db3 + fe3f8fa commit b0a762e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public class TPRequestAcceptCommand implements CommandExecutor {
public TPRequestAcceptCommand(TPPlugin p) {
plugin = p;
}

String[] errors = {
ChatColor.RED + "" + ChatColor.BOLD + "AW SHUCKS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "OOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "ERROR! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "FAIL! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "UH OH! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "WHOOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "NOPE! " + ChatColor.RED
};

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
Expand All @@ -26,51 +36,51 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
ArrayList<String> reqs = plugin.TeleportRequests.get(player.getUniqueId().toString());
if (reqs.size() > 1) {
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "You have multiple teleport requests:");
player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "PROBLEM! " + ChatColor.YELLOW + "You have multiple teleport requests:");
ArrayList<String> reqNames = new ArrayList<>();
for(String r : reqs){
reqNames.add(Objects.requireNonNull(plugin.getServer().getPlayer(UUID.fromString(r))).getName());
}
player.sendMessage(ChatColor.RED + String.join(", ", reqNames));
player.sendMessage(ChatColor.RED + "Therefore, you must specify someone to accept.");
player.sendMessage(ChatColor.YELLOW + String.join(", ", reqNames));
player.sendMessage(ChatColor.YELLOW + "Therefore, you must specify who to accept.");
return false;
} else if (args.length > 1) return false;
else {
Player teleportingPlayer = plugin.getServer().getPlayer(args[0]);

if (teleportingPlayer == null) {
player.sendMessage(ChatColor.RED + "You invalid user");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "That player has not sent you a teleport request!");
return true;
}

if(!reqs.contains(teleportingPlayer.getUniqueId().toString())){
player.sendMessage(ChatColor.RED + "Player has not requested a teleport.");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "That player has not sent you a teleport request!");
return true;
}

teleportingPlayer.teleport(player);
plugin.removeRequest(player.getUniqueId().toString(), teleportingPlayer.getUniqueId().toString());
teleportingPlayer.sendMessage(ChatColor.AQUA + "You have been teleported!");
teleportingPlayer.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "TELEPORTED!" + ChatColor.GREEN + " You have been teleported!");
} return true;

} else {
String req = reqs.get(0);
if(args.length != 0){
player.sendMessage(ChatColor.RED + "You don't have multiple teleport requests. Use tpaccept without arguments");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "You don't have multiple teleport requests! Enter the command without any arguments.");
return true;
}
Player teleportingPlayer = plugin.getServer().getPlayer(UUID.fromString(req));
if(teleportingPlayer == null){
player.sendMessage(ChatColor.RED + "That user doesn't exist anymore(?)");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "That player isn't online anymore!");
return true;
}
teleportingPlayer.teleport(player);
plugin.removeRequest(player.getUniqueId().toString(), req);
teleportingPlayer.sendMessage(ChatColor.AQUA + "You have been teleported!");
teleportingPlayer.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "TELEPORTED!" + ChatColor.GREEN + " You have been teleported!");
return true;
}
} else {
player.sendMessage(ChatColor.RED + "You don't have any pending teleport requests");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "You don't have any pending teleport requests!");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public class TPRequestDeclineCommand implements CommandExecutor {
public TPRequestDeclineCommand(TPPlugin p) {
plugin = p;
}

String[] errors = {
ChatColor.RED + "" + ChatColor.BOLD + "AW SHUCKS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "OOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "ERROR! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "FAIL! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "UH OH! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "WHOOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "NOPE! " + ChatColor.RED
};

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
Expand All @@ -26,20 +36,22 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
ArrayList<String> reqs = plugin.TeleportRequests.get(player.getUniqueId().toString());
if (reqs.size() > 1) {
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "You have multiple teleport requests:");

player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "PROBLEM! " + ChatColor.YELLOW + "You have multiple teleport requests:");
ArrayList<String> reqNames = new ArrayList<>();
for(String r : reqs){
reqNames.add(Objects.requireNonNull(plugin.getServer().getPlayer(UUID.fromString(r))).getName());
}
player.sendMessage(ChatColor.RED + String.join(", ", reqNames));
player.sendMessage(ChatColor.RED + "Therefore, you must specify someone to decline.");
return false;
player.sendMessage(ChatColor.YELLOW + String.join(", ", reqNames));
player.sendMessage(ChatColor.YELLOW + "Therefore, you must specify someone to decline.");
return true;

} else if (args.length > 1) return false;
else {
Player teleportingPlayer = plugin.getServer().getPlayer(args[0]);

if (teleportingPlayer == null) {
player.sendMessage(ChatColor.RED + "You invalid user");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "That player has not sent you a teleport request!");
return true;
}

Expand All @@ -49,31 +61,33 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}

plugin.removeRequest(player.getUniqueId().toString(), teleportingPlayer.getUniqueId().toString());
teleportingPlayer.sendMessage(ChatColor.RED + "Your teleport request("+ player.getName() + ") has been declined");
player.sendMessage(ChatColor.AQUA + "Done!");
teleportingPlayer.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "DECLINED! " + ChatColor.RED + "Your teleport request to " + player.getName() + " has been declined :(");
player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "DECLINED! " + ChatColor.GREEN + "Successfully declined " + teleportingPlayer.getName + "'s teleport request!");
return true;
}

} else {
String req = reqs.get(0);
if(args.length != 0){
player.sendMessage(ChatColor.RED + "You don't have multiple teleport requests. Use tpdecline without arguments");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "You don't have multiple teleport requests! Enter the command without any arguments.");
return true;
}
Player teleportingPlayer = plugin.getServer().getPlayer(UUID.fromString(req));
if(teleportingPlayer == null){
player.sendMessage(ChatColor.RED + "That user doesn't exist anymore(?)");
player.sendMessage(errors[new Random().nextInt(errors.length)] + "That player isn't online anymore!");
return true;
}
plugin.removeRequest(player.getUniqueId().toString(), teleportingPlayer.getUniqueId().toString());
teleportingPlayer.sendMessage(ChatColor.RED + "Your teleport request to "+ player.getName() + " has been declined");
player.sendMessage(ChatColor.AQUA + "Done!");
teleportingPlayer.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "DECLINED! " + ChatColor.RED + "Your teleport request to " + player.getName() + " has been declined :(");
player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "DECLINED! " + ChatColor.GREEN + "Successfully declined " + teleportingPlayer.getName + "'s teleport request!");
return true;

}
} else {
player.sendMessage(ChatColor.RED + "You don't have any pending teleport requests");

player.sendMessage(errors[new Random().nextInt(errors.length)] + "You don't have any pending teleport requests!");
return true;

}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@ public TeleportRequestCommand(TPPlugin p) {
plugin = p;
}

String[] errors = {
ChatColor.RED + "" + ChatColor.BOLD + "AW SHUCKS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "OOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "ERROR! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "FAIL! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "UH OH! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "WHOOPS! " + ChatColor.RED,
ChatColor.RED + "" + ChatColor.BOLD + "NOPE! " + ChatColor.RED
};

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (commandSender instanceof Player) {
Player playerSender = (Player) commandSender;
if (args.length != 1) return false;
Player playerReceiver = plugin.getServer().getPlayer(args[0]);
if (playerReceiver == null) {
playerSender.sendMessage(ChatColor.RED + "No users match your query.");
playerSender.sendMessage(errors[new Random().nextInt(errors.length)] + "Can't find a user by that name!");
} else {
String receiverID = playerReceiver.getUniqueId().toString();
String senderID = playerSender.getUniqueId().toString();
if(receiverID.equals(senderID)){
playerSender.sendMessage(ChatColor.RED + "You can't send yourself a teleport request!");
playerSender.sendMessage(errors[new Random().nextInt(errors.length)] + "You can't send yourself a teleport request, silly!");
return true;
}
if (plugin.TeleportRequests.containsKey(receiverID)) {
if (plugin.TeleportRequests.get(receiverID).contains(senderID)) {
playerSender.sendMessage(ChatColor.RED + "You have already sent that user a teleport request!");
playerSender.sendMessage(errors[new Random().nextInt(errors.length)] + "You have already sent that player a teleport request!");
return true;
}
} else {
Expand All @@ -46,18 +56,18 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
ArrayList<String> reqs = plugin.TeleportRequests.get(receiverID);
reqs.add(senderID);
plugin.TeleportRequests.replace(receiverID, reqs);
playerSender.sendMessage(ChatColor.AQUA + "You have sent a teleport request to " + playerSender.getName() + ". They have " +
plugin.getConfig().getInt("tpplugin-request-expiration")/20 + "seconds to accept it.");
playerReceiver.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "You have recieved a teleport request from " + playerSender.getName());
playerReceiver.sendMessage(ChatColor.AQUA + "To accept this, run </tpaccept>, otherwise, run </tpdecline>. You have " +
plugin.getConfig().getInt("tpplugin-request-expiration")/20 + "seconds to accept it.");
playerSender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "SENT!" + ChatColor.GREEN + "You have sent a teleport request to " + playerSender.getName() + ". They have " +
plugin.getConfig().getInt("tpplugin-request-expiration")/20) + " seconds to accept it.");
playerReceiver.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "TPA RECIEVED!" + ChatColor.GREEN + "You have recieved a teleport request from " + playerSender.getName());
playerReceiver.sendMessage(ChatColor.GREEN + "To accept this, type /tpaccept, otherwise, type /tpdeny. You have " +
plugin.getConfig().getInt("tpplugin-request-expiration")/20) + " seconds to accept it.");
BukkitScheduler scheduler = plugin.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(plugin, () -> {
if (plugin.TeleportRequests.containsKey(receiverID)) {
ArrayList<String> req2s = plugin.TeleportRequests.get(receiverID);
if (req2s.contains(senderID)) {
playerReceiver.sendMessage(ChatColor.RED + "The teleport request from " + playerSender.getName() + " has expired");
playerSender.sendMessage(ChatColor.RED + "The teleport request for " + playerReceiver.getName() + " has expired");
playerReceiver.sendMessage(errors[new Random().nextInt(errors.length)] + "The teleport request from " + playerSender.getName() + " has expired!");
playerSender.sendMessage(errors[new Random().nextInt(errors.length)] + "The teleport request to " + playerReceiver.getName() + " has expired!");
plugin.removeRequest(receiverID, senderID);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ commands:
tpaccept:
description: Accepts someone's teleport request
usage: /tpaccept [username]
aliases: [tpallow, tpyes]

tpdecline:
description: Decline someone's teleport request
usage: /tpdecline [username]
usage: /tpdecline [username]
aliases: [tpdeny, tpno]

0 comments on commit b0a762e

Please sign in to comment.