Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33e184a
commit f23a005
Showing
1 changed file
with
39 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>"); | ||
} | ||
} | ||
} |