From f0aec561860b709b34ba84146dab1a6c3c85bb0b Mon Sep 17 00:00:00 2001 From: Super_ Date: Fri, 13 Dec 2019 19:38:36 -0500 Subject: [PATCH] new ride mode: ask ask players to ride them --- .../totalfreedommod/command/Command_ride.java | 86 +++++++++++++++++-- .../command/FreedomCommand.java | 2 + .../playerverification/VPlayer.java | 6 +- 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 57cfdaad..4fcfa8db 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.HashMap; +import java.util.Map; +import java.util.TimerTask; import me.totalfreedom.totalfreedommod.playerverification.VPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.ChatColor; @@ -8,10 +11,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Make other people your bitch.", usage = "/ ") +@CommandParameters(description = "Make other people your bitch.", usage = "/ >") public class Command_ride extends FreedomCommand { - + private final Map RIDE_REQUESTS = new HashMap<>(); // requested, requester @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -21,15 +24,57 @@ public class Command_ride extends FreedomCommand return false; } - if (args[0].equalsIgnoreCase("toggle")) + if (args[0].equalsIgnoreCase("accept") || args[0].equalsIgnoreCase("yes")) { - VPlayer vPlayerSender = plugin.pv.getVerificationPlayer(playerSender); - vPlayerSender.setRideToggle(!vPlayerSender.isRideToggle()); - plugin.pv.saveVerificationData(vPlayerSender); - msg("Other players n" + (vPlayerSender.isRideToggle() ? "ow" : "o longer") + " have the ability to ride you."); + if (!RIDE_REQUESTS.containsKey(playerSender)) + { + msg("You don't have a request currently."); + return true; + } + Player requester = RIDE_REQUESTS.get(playerSender); + if (requester == null) + { + msg("The player who sent the request is no longer online."); + RIDE_REQUESTS.remove(playerSender); + return true; + } + msg("Request accepted."); + requester.sendMessage(ChatColor.GRAY + "Your request has been accepted."); + playerSender.addPassenger(requester); return true; } + if (args[0].equalsIgnoreCase("deny") || args[0].equalsIgnoreCase("no")) + { + if (!RIDE_REQUESTS.containsKey(playerSender)) + { + msg("You don't have a request currently."); + return true; + } + Player requester = RIDE_REQUESTS.get(playerSender); + if (requester == null) + { + msg("The player who sent the request is no longer online."); + RIDE_REQUESTS.remove(playerSender); + return true; + } + msg("Request denied."); + RIDE_REQUESTS.remove(playerSender); + requester.sendMessage(ChatColor.GRAY + "Your request has been denied."); + return true; + } + + if (args[0].equalsIgnoreCase("mode")) + { + if (args[1].equalsIgnoreCase("normal") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("ask")) + { + VPlayer vPlayerSender = plugin.pv.getVerificationPlayer(playerSender); + vPlayerSender.setRideMode(args[1].toLowerCase()); + msg("Ride mode is now set to " + args[1].toLowerCase() + "."); + return true; + } + } + final Player player = getPlayer(args[0]); if (player == null) { @@ -45,12 +90,37 @@ public class Command_ride extends FreedomCommand return true; } - if (!vPlayer.isRideToggle() && !isAdmin(sender)) + if (vPlayer.getRideMode().equals("off") && !isAdmin(sender)) { msg("That player cannot be ridden.", ChatColor.RED); return true; } + if (vPlayer.getRideMode().equals("ask") && !isAdmin(sender)) + { + msg("Sent a request to the player."); + player.sendMessage(ChatColor.GRAY + sender.getName() + " has requested to ride you."); + player.sendMessage(ChatColor.GRAY + "Type " + ChatColor.DARK_GRAY + "/ride accept" + ChatColor.GRAY + " to allow the player to ride you."); + player.sendMessage(ChatColor.GRAY + "Type " + ChatColor.DARK_GRAY + "/ride deny" + ChatColor.GRAY + " to deny the player permission."); + player.sendMessage(ChatColor.GRAY + "Request will expire after 30 seconds."); + RIDE_REQUESTS.put(player, playerSender); + timer.schedule(new TimerTask() + { + @Override + public void run() + { + if (!RIDE_REQUESTS.containsKey(player)) + { + return; + } + RIDE_REQUESTS.remove(player); + msg("Request expired."); + player.sendMessage(ChatColor.GRAY + "Request expired."); + } + }, 30000); + return true; + } + player.addPassenger(playerSender); return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index 870190be..44780209 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -32,6 +32,8 @@ public abstract class FreedomCommand extends AbstractCommandBase getIps()