Skip to content

Commit

Permalink
Updated to 4.6.1.0
Browse files Browse the repository at this point in the history
Updated for latest rocket version, added cooldown, translations and
check if player is in car.
  • Loading branch information
LeeIzaZombie committed Aug 11, 2015
1 parent 5c70356 commit fbd2225
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 37 deletions.
8 changes: 4 additions & 4 deletions RocketMod_TPA/RocketMod_TPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\Unturned Projects\Lib\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\Lib\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Unturned\Unturned_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Rocket.API">
<HintPath>..\..\..\..\Unturned Projects\Lib\Rocket.API.dll</HintPath>
<HintPath>..\..\Lib\Rocket.API.dll</HintPath>
</Reference>
<Reference Include="Rocket.Core">
<HintPath>..\..\..\..\Unturned Projects\Lib\Rocket.Core.dll</HintPath>
<HintPath>..\..\Lib\Rocket.Core.dll</HintPath>
</Reference>
<Reference Include="Rocket.Unturned">
<HintPath>..\..\..\..\Unturned Projects\Lib\Rocket.Unturned.dll</HintPath>
<HintPath>..\..\Lib\Rocket.Unturned.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
129 changes: 100 additions & 29 deletions RocketMod_TPA/cmd_tpa.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Rocket.Unturned;
using Rocket.API;
using Rocket.Unturned;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,6 +15,24 @@ namespace RocketMod_TPA
public class CommandTPA : IRocketCommand
{
#region Delcarations
public bool AllowFromConsole
{
get
{
return false;
}
}

public List<string> Permissions
{
get
{
return new List<string>() {
"CommandTPA.tpa"
};
}
}

public bool RunFromConsole
{
get { return false; }
Expand Down Expand Up @@ -42,80 +62,131 @@ public List<string> Aliases
}

Dictionary<Steamworks.CSteamID, Steamworks.CSteamID> requests = new Dictionary<Steamworks.CSteamID, Steamworks.CSteamID>();
Dictionary<Steamworks.CSteamID, DateTime> coolDown = new Dictionary<Steamworks.CSteamID, DateTime>();
#endregion

public void Execute(RocketPlayer caller, string[] command)
public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;
if (command.Length < 1)
{
RocketChat.Say(caller, "TPA allows you to request a teleport to another player.", Color.yellow);
RocketChat.Say(caller, "/tpa (playerName) - Sends a teleport request.", Color.yellow);
RocketChat.Say(caller, "/tpa accept - Accepts your latest TPA request.", Color.yellow);
RocketChat.Say(caller, "/tpa deny - Denys your latest TPA request.", Color.yellow);

Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("help_line_1"), Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("help_line_2"), Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("help_line_3"), Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("help_line_4"), Color.yellow);
return;
}

if (command[0].ToString().ToLower() == "accept" || command[0].ToString().ToLower() == "a" || command[0].ToString().ToLower() == "yes")
{
if (requests.ContainsKey(caller.CSteamID))

if (!player.HasPermission("tpa.accept"))
{
Rocket.Unturned.Chat.UnturnedChat.Say(player, PluginTPA.Instance.Translate("nopermission_accept"), Color.red);
return;
}

if (requests.ContainsKey(player.CSteamID))
{
RocketPlayer tpP = RocketPlayer.FromCSteamID(requests[caller.CSteamID]);
tpP.Teleport(caller);
requests.Remove(caller.CSteamID);
RocketChat.Say(caller, "You have accepted " + tpP.CharacterName + "'s tpa request!", Color.yellow);
RocketChat.Say(tpP, caller.CharacterName + " has accepted your tpa request!", Color.yellow);
UnturnedPlayer tpP = UnturnedPlayer.FromCSteamID(requests[player.CSteamID]);
if (tpP.Stance == EPlayerStance.DRIVING || tpP.Stance == EPlayerStance.SITTING)
{
Rocket.Unturned.Chat.UnturnedChat.Say(tpP, PluginTPA.Instance.Translate("YouInCar"), Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("PlayerInCar"), Color.red);
requests.Remove(player.CSteamID);
return;
}
tpP.Teleport(player);
requests.Remove(player.CSteamID);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_accepted") + " " + tpP.CharacterName, Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(tpP, player.CharacterName + " " + PluginTPA.Instance.Translate("request_accepted_1"), Color.yellow);
}
else
{
RocketChat.Say(caller, "Error: You don't have any tpa requests!", Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_none"), Color.red);
}

}
else if (command[0].ToString() == "deny" || command[0].ToString().ToLower() == "d" || command[0].ToString().ToLower() == "no")
{
if (requests.ContainsKey(caller.CSteamID))
if (!player.HasPermission("tpa.deny"))
{
RocketPlayer tpP = RocketPlayer.FromCSteamID(requests[caller.CSteamID]);
requests.Remove(caller.CSteamID);
RocketChat.Say(caller, "You have denied " + tpP.CharacterName + "'s tpa request!", Color.yellow);
RocketChat.Say(tpP, caller.CharacterName + " has denied your tpa request!", Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(player, PluginTPA.Instance.Translate("nopermission_deny"), Color.red);
return;
}

if (requests.ContainsKey(player.CSteamID))
{
UnturnedPlayer tpP = UnturnedPlayer.FromCSteamID(requests[player.CSteamID]);
requests.Remove(player.CSteamID);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_denied") + " " + tpP.CharacterName, Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(tpP, player.CharacterName + " " + PluginTPA.Instance.Translate("request_denied_1"), Color.red);
}
else
{
RocketChat.Say(caller, "Error: You don't have any tpa requests!", Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_none"), Color.red);
}
}
else //Try sending a tpa request to a player.
{
RocketPlayer rTo = RocketPlayer.FromName(command[0].ToString());
if (!player.HasPermission("tpa.send"))
{
Rocket.Unturned.Chat.UnturnedChat.Say(player, PluginTPA.Instance.Translate("nopermission_send"), Color.red);
return;
}


UnturnedPlayer rTo = UnturnedPlayer.FromName(command[0].ToString());

#region Error Checking
if (rTo == null)
{
RocketChat.Say(caller, "Error: Could not find player!", Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("playerNotFound"), Color.red);
return;
}
//Need to prevent spam requests.
if (requests.ContainsKey(rTo.CSteamID))
{
if (requests[rTo.CSteamID] == caller.CSteamID)
if (requests[rTo.CSteamID] == player.CSteamID)
{
RocketChat.Say(caller, "Error: You already have a request pending to " + rTo.CharacterName, Color.red);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_pending") + " " + rTo.CharacterName, Color.red);
return;
}
}
#endregion

if (coolDown.ContainsKey(player.CSteamID))
{
//Rocket.Unturned.Chat.UnturnedChat.Say(caller, "Debug: " + (DateTime.Now - coolDown[player.CSteamID]).TotalSeconds);
if ((DateTime.Now - coolDown[player.CSteamID]).TotalSeconds < PluginTPA.Instance.Configuration.Instance.TPACoolDownSeconds)
{
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("error_cooldown"), Color.red);
return;
}
coolDown.Remove(player.CSteamID);
}

if (coolDown.ContainsKey(player.CSteamID))
{
coolDown[player.CSteamID] = DateTime.Now;
}
else
{
coolDown.Add(player.CSteamID, DateTime.Now);
}

if (requests.ContainsKey(rTo.CSteamID))
{
requests[rTo.CSteamID] = caller.CSteamID;
RocketChat.Say(caller, "You have sent a tpa request to " + rTo.CharacterName, Color.yellow);
RocketChat.Say(rTo, caller.CharacterName + " has sent you a tpa request! use /tpa accept or /tpa deny", Color.yellow);
requests[rTo.CSteamID] = player.CSteamID;
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_sent") + " " + rTo.CharacterName, Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(rTo, player.CharacterName + " " + PluginTPA.Instance.Translate("request_sent_1"), Color.yellow);
}
else
{
requests.Add(rTo.CSteamID, caller.CSteamID);
RocketChat.Say(caller, "You have sent a tpa request to " + rTo.CharacterName, Color.yellow);
RocketChat.Say(rTo, caller.CharacterName + " has sent you a tpa request! use /tpa accept if you want them to teleport to you!", Color.yellow);
requests.Add(rTo.CSteamID, player.CSteamID);
Rocket.Unturned.Chat.UnturnedChat.Say(caller, PluginTPA.Instance.Translate("request_sent") + " " + rTo.CharacterName, Color.yellow);
Rocket.Unturned.Chat.UnturnedChat.Say(rTo, player.CharacterName + " " + PluginTPA.Instance.Translate("request_sent_1"), Color.yellow);
}
}

Expand Down
Binary file modified RocketMod_TPA/obj/Debug/RocketMod_TPA.dll
Binary file not shown.
54 changes: 50 additions & 4 deletions RocketMod_TPA/plugin_tpa.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Rocket.Unturned.Plugins;
using Rocket.API;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using Rocket.Unturned.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,9 +10,52 @@

namespace RocketMod_TPA
{
public class PluginTPA : RocketPlugin
public class PluginTPA : RocketPlugin<TPAConfiguration>
{
//Nothing needed here I guess... :)
//Just need plugin name to load the command.
public static PluginTPA Instance;

protected override void Load()
{
Instance = this;
}

public override TranslationList DefaultTranslations
{
get
{
return new TranslationList
{
{ "help_line_1", "TPA allows you to request a teleport to another player." },
{ "help_line_2", "/tpa (playerName) - Sends a teleport request." },
{ "help_line_3", "/tpa accept - Accepts your latest TPA request." },
{ "help_line_4", "/tpa deny - Denys your latest TPA request." },
{ "playerNotFound", "Could not find that player!" },
{ "playerInCar", "Teleport failed, the player is in a car." },
{ "YouInCar", "Teleport failed, you can't teleport in a car." },
{ "nopermission_send", "You do not have permission to send TPA requests." },
{ "nopermission_accept", "You do not have permission to accept TPA requests." },
{ "nopermission_deny", "You do not have permission to deny TPA requests." },
{ "error_cooldown", "You may only send requests every 10 seconds." },
{ "request_accepted", "You've accepted the tpa request from: " },
{ "request_denied", "You've denied the tpa request from: " },
{ "request_accepted_1", "has accepted your tpa request!" },
{ "request_denied_1", "has denied your tpa request!" },
{ "request_sent", "You have sent a tpa request to: " },
{ "request_sent_1", "has sent you a tpa request, you can use /tpa accept to let them teleport to you!" },
{ "request_none", "You have no requests available!" },
{ "request_pending", "You're already pending a tpa request to: " }
};
}
}

}

public class TPAConfiguration : IRocketPluginConfiguration
{
public int TPACoolDownSeconds;
public void LoadDefaults()
{
TPACoolDownSeconds = 10;
}
}
}

0 comments on commit fbd2225

Please sign in to comment.