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; 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.playerverification.VPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -8,10 +11,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @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 public class Command_ride extends FreedomCommand
{ {
private final Map<Player, Player> RIDE_REQUESTS = new HashMap<>(); // requested, requester
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -21,14 +24,56 @@ public class Command_ride extends FreedomCommand
return false; return false;
} }
if (args[0].equalsIgnoreCase("toggle")) 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"))
{
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); VPlayer vPlayerSender = plugin.pv.getVerificationPlayer(playerSender);
vPlayerSender.setRideToggle(!vPlayerSender.isRideToggle()); vPlayerSender.setRideMode(args[1].toLowerCase());
plugin.pv.saveVerificationData(vPlayerSender); msg("Ride mode is now set to " + args[1].toLowerCase() + ".");
msg("Other players n" + (vPlayerSender.isRideToggle() ? "ow" : "o longer") + " have the ability to ride you.");
return true; return true;
} }
}
final Player player = getPlayer(args[0]); final Player player = getPlayer(args[0]);
if (player == null) if (player == null)
@ -45,12 +90,37 @@ public class Command_ride extends FreedomCommand
return true; return true;
} }
if (!vPlayer.isRideToggle() && !isAdmin(sender)) if (vPlayer.getRideMode().equals("off") && !isAdmin(sender))
{ {
msg("That player cannot be ridden.", ChatColor.RED); msg("That player cannot be ridden.", ChatColor.RED);
return true; 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); player.addPassenger(playerSender);
return true; return true;

View File

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

View File

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