Skip to content

Commit

Permalink
cleanup codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Oct 28, 2023
1 parent 33e184a commit f23a005
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/ChatLinkItem.cs → src/ChatLinkItemMod.cs
@@ -1,39 +1,39 @@
using Vintagestory.API.Common;
using Vintagestory.API.Datastructures;
using Vintagestory.API.Server;
using Vintagestory.GameContent;

namespace PlayerList;

public class ChatLinkItem : ModSystem {
private ICoreServerAPI? api;

public override bool ShouldLoad(EnumAppSide forSide) {
return forSide.IsServer();
}

public override void StartServerSide(ICoreServerAPI api) {
this.api = api;
api.Event.PlayerChat += OnPlayerChat;
}

public override void Dispose() {
if (api != null) {
api.Event.PlayerChat -= OnPlayerChat;
}
}

private void OnPlayerChat(IServerPlayer sender, int channel, ref string message, ref string data, BoolRef consumed) {
if (!message.Contains("[item]")) {
return;
}

int slotNum = sender.InventoryManager.ActiveHotbarSlotNumber;
ItemStack itemStack = sender.InventoryManager.GetHotbarItemstack(slotNum);
string pageCode = GuiHandbookItemStackPage.PageCodeForStack(itemStack);

if (pageCode != null && pageCode.Length > 0) {
message = message.Replace("[item]", $"<a href=\"handbook://{pageCode}\">{itemStack.GetName()}</a>");
}
}
}
using Vintagestory.API.Common;
using Vintagestory.API.Datastructures;
using Vintagestory.API.Server;
using Vintagestory.GameContent;

namespace ChatLinkItem;

public class ChatLinkItemMod : ModSystem {
private ICoreServerAPI? sapi;

public override bool ShouldLoad(EnumAppSide forSide) {
return forSide.IsServer();
}

public override void StartServerSide(ICoreServerAPI api) {
sapi = api;
sapi.Event.PlayerChat += OnPlayerChat;
}

public override void Dispose() {
if (sapi != null) {
sapi.Event.PlayerChat -= OnPlayerChat;
}
}

private static void OnPlayerChat(IServerPlayer sender, int channel, ref string message, ref string data, BoolRef consumed) {
if (!message.Contains("[item]")) {
return;
}

int slotNum = sender.InventoryManager.ActiveHotbarSlotNumber;
ItemStack itemStack = sender.InventoryManager.GetHotbarItemstack(slotNum);
string pageCode = GuiHandbookItemStackPage.PageCodeForStack(itemStack);

if (pageCode is { Length: > 0 }) {
message = message.Replace("[item]", $"<a href=\"handbook://{pageCode}\">{itemStack.GetName()}</a>");
}
}
}

0 comments on commit f23a005

Please sign in to comment.