Skip to content

Commit

Permalink
VoteRewards 3.0
Browse files Browse the repository at this point in the history
Receive rewards for voting on Unturned-Servers.net or UnturnedSL.com
Rewards can include Kits, Items, XP, Permission groups, Uconomy currency*, or CustomKits slots*
Easy to configure
  • Loading branch information
Teyhota6 authored Mar 8, 2018
1 parent 3c8e3f0 commit f7ecb48
Show file tree
Hide file tree
Showing 15 changed files with 665 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Commands/Command_Reward.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using Rocket.Unturned.Player;
using Rocket.Unturned.Chat;
using Rocket.API;

namespace Teyhota.VoteRewards.Commands
{
public class Command_Reward : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Both;

public string Name => "reward";

public string Help => "Redeem reward after successfully voting";

public string Syntax => "";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>() { "voterewards.reward" };

public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length == 0)
{
if (caller is ConsolePlayer)
{
Plugin.VoteRewardsPlugin.Write("<player>", ConsoleColor.Red);
return;
}

VoteRewards.HandleVote((UnturnedPlayer)caller);
}
else
{
if (caller.HasPermission("voterewards.givereward") || caller is ConsolePlayer)
{
UnturnedPlayer toPlayer = UnturnedPlayer.FromName(command[0]);

if (toPlayer != null)
{
VoteRewards.GiveReward(toPlayer);

if (caller is ConsolePlayer)
{
Plugin.VoteRewardsPlugin.Write(Plugin.VoteRewardsPlugin.Instance.Translate("free_reward", toPlayer.CharacterName));
}
else
{
UnturnedChat.Say(caller, Plugin.VoteRewardsPlugin.Instance.Translate("free_reward", toPlayer.CharacterName));
}
}
}
}
}
}
}
42 changes: 42 additions & 0 deletions Commands/Command_Vote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Diagnostics;
using Rocket.Unturned.Player;
using Rocket.Unturned.Chat;
using Rocket.API;
using SDG.Unturned;

namespace Teyhota.VoteRewards.Commands
{
public class Command_Vote : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "vote";

public string Help => "Vote for the server to receive a reward";

public string Syntax => "";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>() { "voterewards.vote" };

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;

if (command.Length == 0)
{
player.Player.askBrowserRequest(player.CSteamID, Plugin.VoteRewardsPlugin.Instance.Translate("vote_page_msg", Provider.serverName), Plugin.VoteRewardsPlugin.Instance.Configuration.Instance.VotePageURL);
}
else
{
if (command[0] == "force")
{
UnturnedChat.Say(caller, Plugin.VoteRewardsPlugin.Instance.Translate("vote_page_msg", Provider.serverName));
Process.Start(Plugin.VoteRewardsPlugin.Instance.Configuration.Instance.VotePageURL);
}
}
}
}
}
Binary file added Libraries/CustomKits.dll
Binary file not shown.
Binary file added Libraries/Uconomy.dll
Binary file not shown.
68 changes: 68 additions & 0 deletions Plugin/VoteRewardsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using Rocket.API;

namespace Teyhota.VoteRewards.Plugin
{
public class VoteRewardsConfig : IRocketPluginConfiguration
{
public static VoteRewardsConfig Instance;

public string DisableAutoUpdate;
public string VotePageURL;
public List<Reward> Rewards;
public List<Service> Services;

public class Reward
{
public Reward() { }

internal Reward(string type, string value, short chance)
{
Type = type;
Value = value;
Chance = chance;
}

[XmlAttribute]
public string Type;
[XmlAttribute]
public string Value;
[XmlAttribute]
public short Chance;
}
public class Service
{
public Service() { }

internal Service(string url, string apiKey)
{
Name = url;
APIKey = apiKey;
}

[XmlAttribute]
public string Name;
[XmlAttribute]
public string APIKey;
}

public void LoadDefaults()
{
Instance = this;
VotePageURL = "https://unturned-servers.net/my_server_vote_page";
Rewards = new List<Reward>()
{
new Reward("item", "235,236,237,238,253,1369,1371,1371,297,298,298,298,15,15,15,15,15", 40),
new Reward("xp", "1400", 50),
new Reward("group", "VIP", 10)
};
Services = new List<Service>()
{
new Service("unturned-servers", ""),
new Service("unturnedsl", ""),
new Service("obs.erve.me", "")
};
}
}
}
180 changes: 180 additions & 0 deletions Plugin/VoteRewardsPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using System;
using System.IO;
using System.Net;
using System.Xml;
using Rocket.Core.Plugins;
using Rocket.API.Collections;
using Logger = Rocket.Core.Logging.Logger;

namespace Teyhota.VoteRewards.Plugin
{
public class VoteRewardsPlugin : RocketPlugin<VoteRewardsConfig>
{
public static string PluginName = "VoteRewards";
public static string PluginVersion = "3.0.0";
public static string BuildVersion = "12";
public static string RocketVersion = "4.9.3.0";
public static string UnturnedVersion = "3.23.5.0";
public static string ThisDirectory = System.IO.Directory.GetCurrentDirectory() + @"\Plugins\VoteRewards\";

public static bool CustomKits;
public static bool Uconomy;
public static VoteRewardsPlugin Instance;

public static void Write(string message)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
Console.ResetColor();
}
public static void Write(string message, ConsoleColor color)
{
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ResetColor();
}
public void CheckForUpdates(string xmlUrl)
{
string updateDir = System.IO.Directory.GetCurrentDirectory() + @"\Updates\VoteRewards\";
string downloadURL = "";
string newVersion = "";
string newBuild = "";
string updateInfo = "";
XmlTextReader reader = null;

try
{
reader = new XmlTextReader(xmlUrl);
reader.MoveToContent();
string elementName = "";

if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
elementName = reader.Name;
}
else
{
if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
{
switch (elementName)
{
case "version":
newVersion = reader.Value;
break;
case "build":
newBuild = reader.Value;
break;
case "url":
downloadURL = reader.Value;
break;
case "about":
updateInfo = reader.Value;
break;
}
}
}
}
}
}
catch
{
Logger.LogError("Update server down, please try again later\n");
return;
}
finally
{
if (reader != null)
{
reader.Close();
}
}

if (newVersion == PluginVersion)
{
if (newBuild == BuildVersion)
{
return;
}
}

if (!System.IO.Directory.Exists(updateDir))
{
System.IO.Directory.CreateDirectory(updateDir);
}

if (File.Exists(updateDir + "Update-" + newVersion + ".zip"))
return;

try
{
new WebClient().DownloadFile(downloadURL, updateDir + "Update-" + newVersion + ".zip");

Write(string.Format(updateInfo) + "\n", ConsoleColor.Green);
}
catch
{
Logger.LogError("The update has failed to download\n");
}
}

protected override void Load()
{
Instance = this;

Write("\n" + PluginName + " " + PluginVersion + " BETA-" + BuildVersion, ConsoleColor.Cyan);
Write("Made by Teyhota", ConsoleColor.Cyan);
Write("for Rocket " + RocketVersion + "\n", ConsoleColor.Cyan);

// update check
if (Instance.Configuration.Instance.DisableAutoUpdate != "true")
{
CheckForUpdates("http://plugins.4unturned.tk/plugins/VoteRewards/update.xml");
}

// optional dependencies
if (File.Exists(System.IO.Directory.GetCurrentDirectory() + @"\Plugins\CustomKits.dll"))
{
CustomKits = true;
Write("Optional dependency CustomKits has been detected", ConsoleColor.Green);
}
else
{
CustomKits = false;
}

if (File.Exists(System.IO.Directory.GetCurrentDirectory() + @"\Plugins\Uconomy.dll"))
{
Uconomy = true;
Write("Optional dependency Uconomy has been detected", ConsoleColor.Green);
}
else
{
Uconomy = false;
}
}

protected override void Unload()
{
Write("Visit Plugins.4Unturned.tk for more!", ConsoleColor.Green);
}

public override TranslationList DefaultTranslations
{
get
{
return new TranslationList()
{
{"vote_page_msg", "Vote for {0} and receive a reward!"},
{"already_voted", "You have already voted in the last 24 hours."},
{"not_yet_voted", "You have not voted yet. Type /vote"},
{"free_reward", "You gave {0} a free reward!"},
{"reward", "You've been rewarded {0}. Thanks for voting!"}
};
}
}
}
}
15 changes: 15 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("VoteRewards")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VoteRewards")]
[assembly: AssemblyCopyright("Copyright © Teyhota 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("e62d7463-577c-418a-90bd-ec9f9fec4077")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
Loading

0 comments on commit f7ecb48

Please sign in to comment.