Skip to content

Commit

Permalink
Update to Rocket 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamirathe committed Jul 27, 2015
1 parent 904d062 commit bc046a9
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 126 deletions.
11 changes: 7 additions & 4 deletions CommandBuy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ZaupShop
{
public class CommandBuy : IRocketCommand
{
public bool RunFromConsole
public bool AllowFromConsole
{
get
{
Expand Down Expand Up @@ -40,10 +40,13 @@ public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer playerid, string[] msg)
public List<string> Permissions
{
get { return new List<string>(); }
}
public void Execute(IRocketPlayer playerid, string[] msg)
{
ZaupShop.Instance.Buy(playerid, msg);
ZaupShop.Instance.Buy((UnturnedPlayer)playerid, msg);
}
}
}
12 changes: 8 additions & 4 deletions CommandCost.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;

using Rocket.API;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
Expand All @@ -12,7 +13,7 @@ namespace ZaupShop
{
public class CommandCost : IRocketCommand
{
public bool RunFromConsole
public bool AllowFromConsole
{
get
{
Expand Down Expand Up @@ -44,10 +45,13 @@ public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer playerid, string[] msg)
public List<string> Permissions
{
get { return new List<string>(); }
}
public void Execute(IRocketPlayer playerid, string[] msg)
{
ZaupShop.Instance.Cost(playerid, msg);
ZaupShop.Instance.Cost((UnturnedPlayer)playerid, msg);
}
}
}
12 changes: 8 additions & 4 deletions CommandSell.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;

using Rocket.API;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
Expand All @@ -8,7 +9,7 @@ namespace ZaupShop
{
public class CommandSell : IRocketCommand
{
public bool RunFromConsole
public bool AllowFromConsole
{
get
{
Expand Down Expand Up @@ -40,10 +41,13 @@ public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer playerid, string[] msg)
public List<string> Permissions
{
get { return new List<string>(); }
}
public void Execute(IRocketPlayer playerid, string[] msg)
{
ZaupShop.Instance.Sell(playerid, msg);
ZaupShop.Instance.Sell((UnturnedPlayer)playerid, msg);
}
}
}
36 changes: 22 additions & 14 deletions CommandShop.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Collections.Generic;

using Rocket.API;
using Rocket.Core;
using Rocket.Core.Logging;
using Rocket.Core.Permissions;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Logging;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;
Expand All @@ -13,7 +17,7 @@ namespace ZaupShop
{
public class CommandShop : IRocketCommand
{
public bool RunFromConsole
public bool AllowFromConsole
{
get
{
Expand Down Expand Up @@ -45,15 +49,19 @@ public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer playerid, string[] msg)
public List<string> Permissions
{
get { return new List<string>() { "shop.*", "shop.add", "shop.rem", "shop.chng", "shop.buy" }; }
}
public void Execute(IRocketPlayer caller, string[] msg)
{
bool console = (playerid == null) ? true : false;
bool console = (caller is ConsolePlayer);
UnturnedPlayer playerid = (UnturnedPlayer)caller;
string[] permnames = { "shop.*", "shop.add", "shop.rem", "shop.chng", "shop.buy" };
bool[] perms = { false, false, false, false, false };
bool anyuse = false;
string message;
List<string> permlist = (console) ? new List<string>() : playerid.Permissions;
List<string> permlist = (console) ? new List<string>() : R.Permissions.GetPermissions(playerid);
foreach (string s in permlist)
{
switch (s)
Expand Down Expand Up @@ -100,7 +108,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
if (!anyuse)
{
// Assume this is a player
RocketChat.Say(playerid, "You don't have permission to use the /shop command.");
UnturnedChat.Say(playerid, "You don't have permission to use the /shop command.");
return;
}
if (msg.Length == 0)
Expand Down Expand Up @@ -177,7 +185,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
switch (type[0])
{
case "v":
VehicleAsset va = (VehicleAsset)Assets.find(EAssetType.Vehicle, id);
VehicleAsset va = (VehicleAsset)Assets.find(EAssetType.VEHICLE, id);
message = ZaupShop.Instance.Translate("changed_or_added_to_shop", new object[] {
ac,
va.Name,
Expand All @@ -191,7 +199,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
this.sendMessage(playerid, message, console);
break;
default:
ItemAsset ia = (ItemAsset)Assets.find(EAssetType.Item, id);
ItemAsset ia = (ItemAsset)Assets.find(EAssetType.ITEM, id);
message = ZaupShop.Instance.Translate("changed_or_added_to_shop", new object[] {
ac,
ia.Name,
Expand All @@ -216,7 +224,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
switch (type[0])
{
case "v":
VehicleAsset va = (VehicleAsset)Assets.find(EAssetType.Vehicle, id);
VehicleAsset va = (VehicleAsset)Assets.find(EAssetType.VEHICLE, id);
message = ZaupShop.Instance.Translate("removed_from_shop", new object[] { va.Name });
success = ZaupShop.Instance.ShopDB.DeleteVehicle((int)id);
if (!success)
Expand All @@ -226,7 +234,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
this.sendMessage(playerid, message, console);
break;
default:
ItemAsset ia = (ItemAsset)Assets.find(EAssetType.Item, id);
ItemAsset ia = (ItemAsset)Assets.find(EAssetType.ITEM, id);
message = ZaupShop.Instance.Translate("removed_from_shop", new object[] { ia.Name });
success = ZaupShop.Instance.ShopDB.DeleteItem((int)id);
if (!success)
Expand All @@ -244,7 +252,7 @@ public void Execute(RocketPlayer playerid, string[] msg)
this.sendMessage(playerid, message, console);
return;
}
ItemAsset iab = (ItemAsset)Assets.find(EAssetType.Item, id);
ItemAsset iab = (ItemAsset)Assets.find(EAssetType.ITEM, id);
decimal buyb;
decimal.TryParse(msg[2], out buyb);
message = ZaupShop.Instance.Translate("set_buyback_price", new object[] {
Expand All @@ -266,15 +274,15 @@ public void Execute(RocketPlayer playerid, string[] msg)
}
}
}
private void sendMessage(RocketPlayer playerid, string message, bool console)
private void sendMessage(UnturnedPlayer playerid, string message, bool console)
{
if (console)
{
Logger.Log(message);
}
else
{
RocketChat.Say(playerid, message);
UnturnedChat.Say(playerid, message);
}
}
}
Expand Down
48 changes: 24 additions & 24 deletions DatabaseMgr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using I18N.West;
using MySql.Data.MySqlClient;
using Rocket.Unturned.Logging;
using Rocket.Core.Logging;
using Rocket.API;
using System;
using unturned.ROCKS.Uconomy;
Expand All @@ -23,11 +23,11 @@ internal void CheckSchema()
{
MySqlConnection mySqlConnection = this.createConnection();
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat("show tables like '", ZaupShop.Instance.Configuration.ItemShopTableName, "'");
mySqlCommand.CommandText = string.Concat("show tables like '", ZaupShop.Instance.Configuration.Instance.ItemShopTableName, "'");
mySqlConnection.Open();
if (mySqlCommand.ExecuteScalar() == null)
{
mySqlCommand.CommandText = string.Concat("CREATE TABLE `", ZaupShop.Instance.Configuration.ItemShopTableName, "` (`id` int(6) NOT NULL,`itemname` varchar(32) NOT NULL,`cost` decimal(15,2) NOT NULL DEFAULT '20.00',`buyback` decimal(15,2) NOT NULL DEFAULT '0.00',PRIMARY KEY (`id`)) ");
mySqlCommand.CommandText = string.Concat("CREATE TABLE `", ZaupShop.Instance.Configuration.Instance.ItemShopTableName, "` (`id` int(6) NOT NULL,`itemname` varchar(32) NOT NULL,`cost` decimal(15,2) NOT NULL DEFAULT '20.00',`buyback` decimal(15,2) NOT NULL DEFAULT '0.00',PRIMARY KEY (`id`)) ");
mySqlCommand.ExecuteNonQuery();
}
mySqlConnection.Close();
Expand All @@ -40,11 +40,11 @@ internal void CheckSchema()
{
MySqlConnection mySqlConnection = this.createConnection();
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat("show tables like '", ZaupShop.Instance.Configuration.VehicleShopTableName, "'");
mySqlCommand.CommandText = string.Concat("show tables like '", ZaupShop.Instance.Configuration.Instance.VehicleShopTableName, "'");
mySqlConnection.Open();
if (mySqlCommand.ExecuteScalar() == null)
{
mySqlCommand.CommandText = string.Concat("CREATE TABLE `", ZaupShop.Instance.Configuration.VehicleShopTableName, "` (`id` int(6) NOT NULL,`vehiclename` varchar(32) NOT NULL,`cost` decimal(15,2) NOT NULL DEFAULT '100.00',PRIMARY KEY (`id`)) ");
mySqlCommand.CommandText = string.Concat("CREATE TABLE `", ZaupShop.Instance.Configuration.Instance.VehicleShopTableName, "` (`id` int(6) NOT NULL,`vehiclename` varchar(32) NOT NULL,`cost` decimal(15,2) NOT NULL DEFAULT '100.00',PRIMARY KEY (`id`)) ");
mySqlCommand.ExecuteNonQuery();
}
mySqlConnection.Close();
Expand All @@ -57,11 +57,11 @@ internal void CheckSchema()
{
MySqlConnection mySqlConnection = this.createConnection();
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat("show columns from `", ZaupShop.Instance.Configuration.ItemShopTableName, "` like 'buyback'");
mySqlCommand.CommandText = string.Concat("show columns from `", ZaupShop.Instance.Configuration.Instance.ItemShopTableName, "` like 'buyback'");
mySqlConnection.Open();
if (mySqlCommand.ExecuteScalar() == null)
{
mySqlCommand.CommandText = string.Concat("ALTER TABLE `", ZaupShop.Instance.Configuration.ItemShopTableName, "` ADD `buyback` decimal(15,2) NOT NULL DEFAULT '0.00'");
mySqlCommand.CommandText = string.Concat("ALTER TABLE `", ZaupShop.Instance.Configuration.Instance.ItemShopTableName, "` ADD `buyback` decimal(15,2) NOT NULL DEFAULT '0.00'");
mySqlCommand.ExecuteNonQuery();
}
mySqlConnection.Close();
Expand All @@ -77,16 +77,16 @@ private MySqlConnection createConnection()
MySqlConnection mySqlConnection = null;
try
{
if (Uconomy.Instance.Configuration.DatabasePort == 0)
if (Uconomy.Instance.Configuration.Instance.DatabasePort == 0)
{
Uconomy.Instance.Configuration.DatabasePort = 3306;
Uconomy.Instance.Configuration.Instance.DatabasePort = 3306;
}
mySqlConnection = new MySqlConnection(string.Format("SERVER={0};DATABASE={1};UID={2};PASSWORD={3};PORT={4};", new object[] {
Uconomy.Instance.Configuration.DatabaseAddress,
Uconomy.Instance.Configuration.DatabaseName,
Uconomy.Instance.Configuration.DatabaseUsername,
Uconomy.Instance.Configuration.DatabasePassword,
Uconomy.Instance.Configuration.DatabasePort}));
Uconomy.Instance.Configuration.Instance.DatabaseAddress,
Uconomy.Instance.Configuration.Instance.DatabaseName,
Uconomy.Instance.Configuration.Instance.DatabaseUsername,
Uconomy.Instance.Configuration.Instance.DatabasePassword,
Uconomy.Instance.Configuration.Instance.DatabasePort}));
}
catch (Exception exception)
{
Expand All @@ -106,7 +106,7 @@ public bool AddItem(int id, string name, decimal cost, bool change)
mySqlCommand.CommandText = string.Concat(
new string[] {
"Insert into `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` (`id`, `itemname`, `cost`) VALUES ('",
id.ToString(),
"', '",
Expand All @@ -121,7 +121,7 @@ public bool AddItem(int id, string name, decimal cost, bool change)
mySqlCommand.CommandText = string.Concat(
new string[] {
"update `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` set itemname='",
name,
"', cost='",
Expand Down Expand Up @@ -161,7 +161,7 @@ public bool AddVehicle(int id, string name, decimal cost, bool change)
mySqlCommand.CommandText = string.Concat(
new string[] {
"Insert into `",
ZaupShop.Instance.Configuration.VehicleShopTableName,
ZaupShop.Instance.Configuration.Instance.VehicleShopTableName,
"` (`id`, `vehiclename`, `cost`) VALUES ('",
id.ToString(),
"', '",
Expand All @@ -176,7 +176,7 @@ public bool AddVehicle(int id, string name, decimal cost, bool change)
mySqlCommand.CommandText = string.Concat(
new string[] {
"update `",
ZaupShop.Instance.Configuration.VehicleShopTableName,
ZaupShop.Instance.Configuration.Instance.VehicleShopTableName,
"` set vehiclename='",
name,
"', cost='",
Expand Down Expand Up @@ -214,7 +214,7 @@ public decimal GetItemCost(int id)
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat(new string[] {
"select `cost` from `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` where `id` = '",
id.ToString(),
"';"
Expand Down Expand Up @@ -243,7 +243,7 @@ public decimal GetVehicleCost(int id)
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat(new string[] {
"select `cost` from `",
ZaupShop.Instance.Configuration.VehicleShopTableName,
ZaupShop.Instance.Configuration.Instance.VehicleShopTableName,
"` where `id` = '",
id.ToString(),
"';"
Expand Down Expand Up @@ -272,7 +272,7 @@ public bool DeleteItem(int id)
mySqlCommand.CommandText = string.Concat(
new string[] {
"delete from `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` where id='",
id.ToString(),
"';"
Expand Down Expand Up @@ -305,7 +305,7 @@ public bool DeleteVehicle(int id)
mySqlCommand.CommandText = string.Concat(
new string[] {
"delete from `",
ZaupShop.Instance.Configuration.VehicleShopTableName,
ZaupShop.Instance.Configuration.Instance.VehicleShopTableName,
"` where id='",
id.ToString(),
"';"
Expand Down Expand Up @@ -338,7 +338,7 @@ public bool SetBuyPrice(int id, decimal cost)
mySqlCommand.CommandText = string.Concat(
new string[] {
"update `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` set `buyback`='",
cost.ToString(),
"' where id='",
Expand Down Expand Up @@ -373,7 +373,7 @@ public decimal GetItemBuyPrice(int id)
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = string.Concat(new string[] {
"select `buyback` from `",
ZaupShop.Instance.Configuration.ItemShopTableName,
ZaupShop.Instance.Configuration.Instance.ItemShopTableName,
"` where `id` = '",
id.ToString(),
"';"
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.2.5")]
[assembly: AssemblyFileVersion("1.2.2.5")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
Loading

0 comments on commit bc046a9

Please sign in to comment.