new ride mode: ask

ask players to ride them
This commit is contained in:
Super_ 2019-12-13 19:38:36 -05:00
parent a0571b0175
commit f0aec56186
3 changed files with 83 additions and 11 deletions

View File

@ -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 = "/<command> <playername>")
@CommandParameters(description = "Make other people your bitch.", usage = "/<command> <playername | mode <normal | off | ask>>")
public class Command_ride extends FreedomCommand
{
private final Map<Player, Player> 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;

View File

@ -32,6 +32,8 @@ public abstract class FreedomCommand extends AbstractCommandBase<TotalFreedomMod
private final CommandParameters params;
@Getter
private final CommandPermissions perms;
//
public final Timer timer = new Timer();
public FreedomCommand()
{

View File

@ -36,7 +36,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
private boolean clearChatOptOut = false;
@Getter
@Setter
private boolean rideToggle = true;
private String rideMode = "normal";
public VPlayer(String name)
{
@ -58,7 +58,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
enabled = cs.getBoolean("enabled", false);
tag = cs.getString("tag", null);
clearChatOptOut = cs.getBoolean("clearChatOptOut", false);
rideToggle = cs.getBoolean("rideToggle", true);
rideMode = cs.getString("rideToggle", rideMode);
}
@Override
@ -71,7 +71,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
cs.set("tag", tag);
cs.set("ips", Lists.newArrayList(ips));
cs.set("clearChatOptOut", clearChatOptOut);
cs.set("rideToggle", rideToggle);
cs.set("rideToggle", rideMode);
}
public List<String> getIps()