Skip to content

Commit

Permalink
Merge pull request #314 from daffyyyy/main
Browse files Browse the repository at this point in the history
2.8a
  • Loading branch information
daffyyyy authored Oct 19, 2024
2 parents fa6dc95 + ff09519 commit d518a41
Show file tree
Hide file tree
Showing 18 changed files with 744 additions and 551 deletions.
1,180 changes: 654 additions & 526 deletions Commands.cs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class Additional

[JsonPropertyName("CommandMusic")]
public List<string> CommandMusic { get; set; } = ["music"];

[JsonPropertyName("CommandPin")]
public List<string> CommandPin { get; set; } = ["pin", "pins", "coin", "coins"];

[JsonPropertyName("CommandGlove")]
public List<string> CommandGlove { get; set; } = ["gloves"];
Expand Down Expand Up @@ -65,7 +68,7 @@ public class Additional

public class WeaponPaintsConfig : BasePluginConfig
{
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 8;
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 9;

[JsonPropertyName("SkinsLanguage")]
public string SkinsLanguage { get; set; } = "en";
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
- Added command **`!knife`** to show menu with knives
- Added command **`!gloves`** to show menu with gloves
- Added command **`!agents`** to show menu with agents
- Added command **`!pins`** to show menu with pins
- Added command **`!music`** to show menu with music
- Translations support, submit a PR if you want to share your translation

## ⚙️ Requirements
Expand Down
14 changes: 14 additions & 0 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ internal static void LoadSkinsFromFile(string filePath, ILogger logger)
logger?.LogError("Not found \"skins.json\" file");
}
}

internal static void LoadPinsFromFile(string filePath, ILogger logger)
{
var json = File.ReadAllText(filePath);
try
{
var deserializedPins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.PinsList = deserializedPins ?? [];
}
catch (FileNotFoundException)
{
logger?.LogError("Not found \"pins.json\" file");
}
}

internal static void LoadGlovesFromFile(string filePath, ILogger logger)
{
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7a
2.8a
1 change: 1 addition & 0 deletions Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public partial class WeaponPaints
public static readonly ConcurrentDictionary<int, (string? CT, string? T)> GPlayersAgent = new();
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> GPlayerWeaponsInfo = new();
internal static List<JObject> SkinsList = [];
internal static List<JObject> PinsList = [];
internal static List<JObject> GlovesList = [];
internal static List<JObject> AgentsList = [];
internal static List<JObject> MusicList = [];
Expand Down
10 changes: 3 additions & 7 deletions WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,10 @@ private static void GivePlayerMusicKit(CCSPlayerController player)
private static void GivePlayerPin(CCSPlayerController player)
{
if (!GPlayersPin.TryGetValue(player.Slot, out var pin)) return;

if (player.InventoryServices == null) return;

for (var index = 0; index < player.InventoryServices.Rank.Length; index++)
{
player.InventoryServices.Rank[index] = index == 5 ? (MedalRank_t)pin : MedalRank_t.MEDAL_RANK_NONE;
Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInventoryServices");
}

player.InventoryServices.Rank[5] = pin > 0 ? (MedalRank_t)pin : MedalRank_t.MEDAL_RANK_NONE;
Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInventoryServices");
}

private void GiveOnItemPickup(CCSPlayerController player)
Expand Down
32 changes: 17 additions & 15 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override string ModuleAuthor => "Nereziel & daffyy";
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "2.7a";
public override string ModuleVersion => "2.8a";

public override void Load(bool hotReload)
{
Expand Down Expand Up @@ -53,28 +53,15 @@ public override void Load(bool hotReload)
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
});
}

AddTimer(2.0f, () => OnAllPluginsLoaded(hotReload));
}

Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
Utility.LoadGlovesFromFile(ModuleDirectory + $"/data/gloves_{_config.SkinsLanguage}.json", Logger);
Utility.LoadAgentsFromFile(ModuleDirectory + $"/data/agents_{_config.SkinsLanguage}.json", Logger);
Utility.LoadMusicFromFile(ModuleDirectory + $"/data/music_{_config.SkinsLanguage}.json", Logger);

if (Config.Additional.KnifeEnabled)
SetupKnifeMenu();
if (Config.Additional.SkinEnabled)
SetupSkinsMenu();
if (Config.Additional.GloveEnabled)
SetupGlovesMenu();
if (Config.Additional.AgentEnabled)
SetupAgentsMenu();
if (Config.Additional.MusicEnabled)
SetupMusicMenu();
Utility.LoadPinsFromFile(ModuleDirectory + $"/data/collectibles_{_config.SkinsLanguage}.json", Logger);

RegisterListeners();
RegisterCommands();
}

public void OnConfigParsed(WeaponPaintsConfig config)
Expand Down Expand Up @@ -122,6 +109,21 @@ public override void OnAllPluginsLoaded(bool hotReload)
try
{
MenuApi = MenuCapability.Get();

if (Config.Additional.KnifeEnabled)
SetupKnifeMenu();
if (Config.Additional.SkinEnabled)
SetupSkinsMenu();
if (Config.Additional.GloveEnabled)
SetupGlovesMenu();
if (Config.Additional.AgentEnabled)
SetupAgentsMenu();
if (Config.Additional.MusicEnabled)
SetupMusicMenu();
if (Config.Additional.PinsEnabled)
SetupPinsMenu();

RegisterCommands();
}
catch (Exception)
{
Expand Down
22 changes: 21 additions & 1 deletion WeaponSynchronization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private void GetWeaponPaintsFromDatabase(PlayerInfo? player, MySqlConnection con
float weaponWear = row?.weapon_wear ?? 0f;
int weaponSeed = row?.weapon_seed ?? 0;
string weaponNameTag = row?.weapon_nametag ?? "";
bool weaponStatTrak = row?.weapon_stattrak ?? false;
int weaponStatTrakCount = row?.weapon_stattrak_count ?? 0;

string[]? keyChainParts = row?.weapon_keychain?.ToString().Split(';');

Expand Down Expand Up @@ -167,7 +169,9 @@ private void GetWeaponPaintsFromDatabase(PlayerInfo? player, MySqlConnection con
Seed = weaponSeed,
Wear = weaponWear,
Nametag = weaponNameTag,
KeyChain = keyChainInfo
KeyChain = keyChainInfo,
StatTrak = weaponStatTrak,
StatTrakCount = weaponStatTrakCount,
};

// Retrieve and parse sticker data (up to 5 slots)
Expand Down Expand Up @@ -371,6 +375,22 @@ internal async Task SyncMusicToDatabase(PlayerInfo player, ushort music)
{
Utility.Log($"Error syncing music kit to database: {e.Message}");
}
}

internal async Task SyncPinToDatabase(PlayerInfo player, ushort pin)
{
if (!_config.Additional.PinsEnabled || string.IsNullOrEmpty(player.SteamId)) return;

try
{
await using var connection = await _database.GetConnectionAsync();
const string query = "INSERT INTO `wp_player_pins` (`steamid`, `id`) VALUES(@steamid, @newPin) ON DUPLICATE KEY UPDATE `id` = @newPin";
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newPin = pin });
}
catch (Exception e)
{
Utility.Log($"Error syncing pin to database: {e.Message}");
}
}

internal async Task SyncStatTrakToDatabase(PlayerInfo player, ConcurrentDictionary<int,WeaponInfo> weaponInfos)
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Type {lime}!gloves{default} to open gloves menu",
"wp_info_agent": "Type {lime}!agents{default} to open agents menu",
"wp_info_music": "Type {lime}!music{default} to open music menu",
"wp_info_pin": "Type {lime}!pins{default} to open pins menu",
"wp_command_cooldown": "{lightred}You can't refresh weapon paints right now",
"wp_command_refresh_done": "{lime}Refreshing weapon paints",
"wp_knife_menu_select": "You have chosen {lime}{0}{default} as your knife",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Agents Menu",
"wp_music_menu_title": "Music Menu",
"wp_music_menu_select": "You have chosen {lime}{0}{default} as your music kit",
"wp_pins_menu_title": "Pins Menu",
"wp_pins_menu_select": "You have chosen {lime}{0}{default} as your pin",
"wp_skin_menu_weapon_title": "Weapon Menu",
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
"wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin",
Expand Down
3 changes: 3 additions & 0 deletions lang/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Ievadiet {lime}!gloves{default}, lai atvērtu cimdi izvēlni",
"wp_info_agent": "Ievadiet {lime}!agents{default}, lai atvērtu aģentu izvēlni",
"wp_info_music": "Ievadiet {lime}!music{default}, lai atvērtu mūzikas izvēlni",
"wp_info_pin": "Ierakstiet {lime}!pins{default}, lai atvērtu piespraudes izvēlni",
"wp_command_cooldown": "{lightred}Šobrīd nevarat atsvaidzināt ieroča krāsas",
"wp_command_refresh_done": "{lime}Atsvaidzinot ieroča krāsas",
"wp_knife_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu nazi",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Aģentu Izvēlne",
"wp_music_menu_title": "Mūzikas Izvēlne",
"wp_music_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu mūzikas komplektu",
"wp_pins_menu_title": "Piespraužu izvēlne",
"wp_pins_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu piespraudi",
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
"wp_skin_menu_skin_title": "Izvēlieties ādu priekš {lime}{0}{default}",
"wp_skin_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu ādu",
Expand Down
3 changes: 3 additions & 0 deletions lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Wpisz {lime}!gloves{default}, aby otworzyć menu rękawic",
"wp_info_agent": "Wpisz {lime}!agents{default}, aby otworzyć menu agentów",
"wp_info_music": "Wpisz {lime}!music{default}, aby otworzyć menu muzyczne",
"wp_info_pin": "Wpisz {lime}!pins{default}, aby otworzyć menu pinów",
"wp_command_cooldown": "{lightred}Nie możesz teraz odświeżyć kolorów broni",
"wp_command_refresh_done": "{lime}Odświeżanie kolorów broni",
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Menu Agentów",
"wp_music_menu_title": "Menu Muzyczne",
"wp_music_menu_select": "Wybrałeś {lime}{0}{default} jako swój zestaw muzyczny",
"wp_pins_menu_title": "Menu Pinów",
"wp_pins_menu_select": "Wybrałeś {lime}{0}{default} jako swój pin",
"wp_skin_menu_weapon_title": "Menu Broni",
"wp_skin_menu_skin_title": "Wybierz skórkę dla {lime}{0}{default}",
"wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swoją skórkę",
Expand Down
3 changes: 3 additions & 0 deletions lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Digite {lime}!gloves{default} para abrir o menu de luvas",
"wp_info_agent": "Digite {lime}!agents{default} para abrir o menu de agentes",
"wp_info_music": "Digite {lime}!music{default} para abrir o menu de música",
"wp_info_pin": "Digite {lime}!pins{default} para abrir o menu de pins",
"wp_command_cooldown": "{lightred}Você não pode atualizar as skins de armas agora",
"wp_command_refresh_done": "{lime}Atualizando as skins de armas",
"wp_knife_menu_select": "Você escolheu {lime}{0}{default} como sua faca",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Menu de Agentes",
"wp_music_menu_title": "Menu de Música",
"wp_music_menu_select": "Você escolheu {lime}{0}{default} como seu kit de música",
"wp_pins_menu_title": "Menu de Pins",
"wp_pins_menu_select": "Escolheu {lime}{0}{default} como o seu pin",
"wp_skin_menu_weapon_title": "Menu de Armas",
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin",
Expand Down
3 changes: 3 additions & 0 deletions lang/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Digite {lime}!gloves{default} para abrir o menu de luvas",
"wp_info_agent": "Digite {lime}!agents{default} para abrir o menu de agentes",
"wp_info_music": "Digite {lime}!music{default} para abrir o menu de música",
"wp_info_pin": "Escreva {lime}!pins{default} para abrir o menu de pins",
"wp_command_cooldown": "{lightred}Não pode atualizar as skins de armas de momento",
"wp_command_refresh_done": "{lime}Atualizando as skins de armas",
"wp_knife_menu_select": "Escolheu {lime}{0}{default} como a sua faca",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Menu de Agentes",
"wp_music_menu_title": "Menu de Música",
"wp_music_menu_select": "Escolheu {lime}{0}{default} como o seu kit de música",
"wp_pins_menu_title": "Menu de Pins",
"wp_pins_menu_select": "Escolheu {lime}{0}{default} como o seu pin",
"wp_skin_menu_weapon_title": "Menu de Armas",
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
"wp_skin_menu_select": "Escolheu {lime}{0}{default} como a sua skin",
Expand Down
3 changes: 3 additions & 0 deletions lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Введите {lime}!gloves{default}, чтобы открыть меню перчаток",
"wp_info_agent": "Введите {lime}!agents{default}, чтобы открыть меню агентов",
"wp_info_music": "Введите {lime}!music{default}, чтобы открыть меню музыки",
"wp_info_pin": "Введите {lime}!pins{default}, чтобы открыть меню пинов",
"wp_command_cooldown": "{lightred}Вы не можете обновить раскраску оружия сейчас",
"wp_command_refresh_done": "{lime}Обновление раскраски оружия",
"wp_knife_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего ножа",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Меню Агентов",
"wp_music_menu_title": "Меню Музыки",
"wp_music_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего музыкального набора",
"wp_pins_menu_title": "Меню пинов",
"wp_pins_menu_select": "Вы выбрали {lime}{0}{default} в качестве своего пина",
"wp_skin_menu_weapon_title": "Меню Оружия",
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",
Expand Down
3 changes: 3 additions & 0 deletions lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Handskar menüsünü açmak için {lime}!gloves{default} yazın",
"wp_info_agent": "Ajan menüsünü açmak için {lime}!agents{default} yazın",
"wp_info_music": "Müzik menüsünü açmak için {lime}!music{default} yazın",
"wp_info_pin": "{lime}!pins{default} yazarak pinler menüsünü açın",
"wp_command_cooldown": "{lightred}Şu anda silah boyalarını yenileyemezsiniz",
"wp_command_refresh_done": "{lime}Silah boyaları yenileniyor",
"wp_knife_menu_select": "{lime}{0}{default} olarak bıçağınızı seçtiniz",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Ajanlar Menüsü",
"wp_music_menu_title": "Müzik Menüsü",
"wp_music_menu_select": "{lime}{0}{default} olarak müzik setinizi seçtiniz",
"wp_pins_menu_title": "Pinler Menüsü",
"wp_pins_menu_select": "{lime}{0}{default} pinini seçtiniz",
"wp_skin_menu_weapon_title": "Silah Menüsü",
"wp_skin_menu_skin_title": "{lime}{0}{default} için cilt seçin",
"wp_skin_menu_select": "{lime}{0}{default} olarak cildinizi seçtiniz",
Expand Down
3 changes: 3 additions & 0 deletions lang/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "Введіть {lime}!gloves{default}, щоб відкрити меню рукавичок",
"wp_info_agent": "Введіть {lime}!agents{default}, щоб відкрити меню агентів",
"wp_info_music": "Введіть {lime}!music{default}, щоб відкрити меню музики",
"wp_info_pin": "Введіть {lime}!pins{default}, щоб відкрити меню пінів",
"wp_command_cooldown": "{lightred}Ви не можете оновити фарби зброї зараз",
"wp_command_refresh_done": "{lime}Оновлення фарби зброї",
"wp_knife_menu_select": "Ви обрали {lime}{0}{default} як свій ніж",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "Меню Агентів",
"wp_music_menu_title": "Меню Музики",
"wp_music_menu_select": "Ви обрали {lime}{0}{default} як свій набір музики",
"wp_pins_menu_title": "Меню пінів",
"wp_pins_menu_select": "Ви вибрали {lime}{0}{default} як свій пін",
"wp_skin_menu_weapon_title": "Меню Зброї",
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"wp_info_glove": "输入 {lime}!gloves{default} 打开手套菜单",
"wp_info_agent": "输入 {lime}!agents{default} 打开代理菜单",
"wp_info_music": "输入 {lime}!music{default} 打开音乐菜单",
"wp_info_pin": "输入 {lime}!pins{default} 来打开固定项菜单",
"wp_command_cooldown": "{lightred}您现在无法刷新武器涂装",
"wp_command_refresh_done": "{lime}正在刷新武器涂装",
"wp_knife_menu_select": "您选择了 {lime}{0}{default} 作为您的刀具",
Expand All @@ -17,6 +18,8 @@
"wp_agent_menu_title": "代理菜单",
"wp_music_menu_title": "音乐菜单",
"wp_music_menu_select": "您选择了 {lime}{0}{default} 作为您的音乐包",
"wp_pins_menu_title": "固定项菜单",
"wp_pins_menu_select": "您已选择 {lime}{0}{default} 作为您的固定项",
"wp_skin_menu_weapon_title": "武器菜单",
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",
Expand Down

0 comments on commit d518a41

Please sign in to comment.