TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java

136 lines
4.9 KiB
Java
Raw Normal View History

2018-07-22 00:45:56 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;
2019-12-10 00:59:17 +00:00
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
2018-07-22 00:45:56 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
2019-12-14 03:17:34 +00:00
import org.bukkit.Location;
2018-07-22 00:45:56 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2019-12-10 00:59:17 +00:00
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Make other people your bitch.", usage = "/<command> <playername | mode <normal | off | ask>>")
2018-07-22 00:45:56 +00:00
public class Command_ride extends FreedomCommand
{
private final Map<Player, Player> RIDE_REQUESTS = new HashMap<>(); // requested, requester
2018-07-22 00:45:56 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
if (args[0].equalsIgnoreCase("accept") || args[0].equalsIgnoreCase("yes"))
{
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"))
2019-12-10 00:59:17 +00:00
{
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.");
2019-12-10 00:59:17 +00:00
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;
}
}
2018-07-22 00:45:56 +00:00
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
2019-12-10 00:59:17 +00:00
final VPlayer vPlayer = plugin.pv.getVerificationPlayer(player);
2018-07-22 00:45:56 +00:00
if (player == playerSender)
{
msg("You can't ride yourself. smh.", ChatColor.RED);
return true;
}
if (vPlayer.getRideMode().equals("off") && !isAdmin(sender))
2019-12-10 00:59:17 +00:00
{
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;
}
2019-12-14 03:17:34 +00:00
if (player.getWorld() != playerSender.getWorld())
{
2019-12-14 13:12:26 +00:00
msg("Player is in another world. (" + player.getWorld().getName() + ")");
2019-12-14 04:33:16 +00:00
return true;
2019-12-14 03:17:34 +00:00
}
2018-07-22 00:45:56 +00:00
player.addPassenger(playerSender);
return true;
}
}