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

158 lines
5.7 KiB
Java
Raw Normal View History

2018-07-22 00:45:56 +00:00
package me.totalfreedom.totalfreedommod.command;
import io.papermc.lib.PaperLib;
import java.util.HashMap;
import java.util.Map;
2020-01-07 20:13:59 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData;
2018-07-22 00:45:56 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil;
2018-07-22 00:45:56 +00:00
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
2018-07-22 00:45:56 +00:00
2019-12-10 00:59:17 +00:00
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Ride on the top of the specified player.", 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)
{
2020-01-07 20:13:59 +00:00
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
if (fPlayer.getCageData().isCaged())
{
2021-04-26 06:37:16 +00:00
msg("You cannot use this command while caged.");
2020-01-07 20:13:59 +00:00
return true;
}
2018-07-22 00:45:56 +00:00
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 any pending requests.");
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.");
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(requester, "Your request has been accepted.");
if (requester.getWorld() != playerSender.getWorld())
{
PaperLib.teleportAsync(requester, playerSender.getLocation());
}
RIDE_REQUESTS.remove(playerSender);
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 any pending requests.");
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);
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(requester, "Your request has been denied.");
2019-12-10 00:59:17 +00:00
return true;
}
if (args.length >= 2)
{
if (args[0].equalsIgnoreCase("mode"))
{
if (args[1].equalsIgnoreCase("normal") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("ask"))
{
PlayerData playerDataSender = plugin.pl.getData(playerSender);
playerDataSender.setRideMode(args[1].toLowerCase());
plugin.pl.save(playerDataSender);
msg("Ride mode is now set to " + args[1].toLowerCase() + ".");
return true;
}
}
}
2020-04-23 11:18:03 +00:00
final Player player = getPlayer(args[0], true);
if (player == null)
2018-07-22 00:45:56 +00:00
{
msg(PLAYER_NOT_FOUND);
return true;
}
2020-06-30 07:25:38 +00:00
final PlayerData playerData = plugin.pl.getData(player);
2019-12-10 00:59:17 +00:00
2018-07-22 00:45:56 +00:00
if (player == playerSender)
{
msg("You can't ride yourself. smh.", ChatColor.RED);
return true;
}
if (playerData.getRideMode().equals("off") && !isAdmin(sender))
2019-12-10 00:59:17 +00:00
{
msg("That player cannot be ridden.", ChatColor.RED);
return true;
}
2020-06-30 07:25:38 +00:00
if (playerData.getRideMode().equals("ask") && !FUtil.isExecutive(playerSender.getName()))
{
2020-04-08 02:20:01 +00:00
msg("Sent a request to the player.", ChatColor.GREEN);
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(player, sender.getName() + " has requested to ride you.", ChatColor.AQUA);
msg(player, "Type " + ChatColor.GREEN + "/ride accept" + ChatColor.AQUA + " to allow the player to ride you.", ChatColor.AQUA);
msg(player, "Type " + ChatColor.RED + "/ride deny" + ChatColor.AQUA + " to deny the player permission.", ChatColor.AQUA);
msg(player, "Request will expire in 30 seconds.", ChatColor.AQUA);
RIDE_REQUESTS.put(player, playerSender);
new BukkitRunnable()
{
public void run()
{
if (!RIDE_REQUESTS.containsKey(player))
{
return;
}
RIDE_REQUESTS.remove(player);
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(playerSender, "It has been 30 seconds and " + player.getName() + " has not accepted your request.", ChatColor.RED);
msg(player, "Request expired.", ChatColor.RED);
}
}.runTaskLater(plugin, 20 * 30);
return true;
}
2019-12-14 03:17:34 +00:00
if (player.getWorld() != playerSender.getWorld())
{
PaperLib.teleportAsync(playerSender, player.getLocation());
2019-12-20 22:35:33 +00:00
}
2019-12-14 03:17:34 +00:00
2018-07-22 00:45:56 +00:00
player.addPassenger(playerSender);
msg(player, playerSender.getName() + " is now riding you, run /eject to eject them.");
2018-07-22 00:45:56 +00:00
return true;
}
}