mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Keep track of current game mode (#1053)
* GetGamemode() * GetGamemode() * ChangeGamemode() * GetGamemode() * Update ChatBot.cs code refractor * Update Inventory.cs Gamemode check added * Update Protocol18.cs * Update Protocol18.cs * Update Protocol18.cs code refractor * Update IMinecraftComHandler.cs code refractor * Update IMinecraftComHandler.cs * Update McTcpClient.cs fix * Update McTcpClient.cs fix * Fix duplicate gamemode event Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
This commit is contained in:
parent
27f35ee7a9
commit
87302bafab
4 changed files with 32 additions and 13 deletions
|
|
@ -837,7 +837,16 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
return Handler.GetUsername();
|
return Handler.GetUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the Gamemode of the current account
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Username of the current account</returns>
|
||||||
|
protected int GetGamemode()
|
||||||
|
{
|
||||||
|
return Handler.GetGamemode();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the UserUUID of the current account
|
/// Return the UserUUID of the current account
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,14 @@ namespace MinecraftClient.Commands
|
||||||
ItemType itemType = ItemType.Stone;
|
ItemType itemType = ItemType.Stone;
|
||||||
if (Enum.TryParse(args[2], out itemType))
|
if (Enum.TryParse(args[2], out itemType))
|
||||||
{
|
{
|
||||||
int count = int.Parse(args[3]);
|
if (handler.GetGamemode() == 1)
|
||||||
if (handler.DoCreativeGive(slot, itemType, count))
|
{
|
||||||
return "Requested " + itemType + " x" + count + " in slot #" + slot;
|
int count = int.Parse(args[3]);
|
||||||
else return "Failed to request Creative Give";
|
if (handler.DoCreativeGive(slot, itemType, count))
|
||||||
|
return "Requested " + itemType + " x" + count + " in slot #" + slot;
|
||||||
|
else return "Failed to request Creative Give";
|
||||||
|
}
|
||||||
|
else return "You need Gamemode Creative";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ namespace MinecraftClient
|
||||||
private DateTime lastKeepAlive;
|
private DateTime lastKeepAlive;
|
||||||
private object lastKeepAliveLock = new object();
|
private object lastKeepAliveLock = new object();
|
||||||
private int respawnTicks = 0;
|
private int respawnTicks = 0;
|
||||||
|
private int gamemode = 0;
|
||||||
|
|
||||||
private int playerEntityID;
|
private int playerEntityID;
|
||||||
|
|
||||||
|
|
@ -88,6 +89,7 @@ namespace MinecraftClient
|
||||||
public int GetLevel() { return playerLevel; }
|
public int GetLevel() { return playerLevel; }
|
||||||
public int GetTotalExperience() { return playerTotalExperience; }
|
public int GetTotalExperience() { return playerTotalExperience; }
|
||||||
public byte GetCurrentSlot() { return CurrentSlot; }
|
public byte GetCurrentSlot() { return CurrentSlot; }
|
||||||
|
public int GetGamemode() { return gamemode; }
|
||||||
|
|
||||||
// get bots list for unloading them by commands
|
// get bots list for unloading them by commands
|
||||||
public List<ChatBot> GetLoadedChatBots()
|
public List<ChatBot> GetLoadedChatBots()
|
||||||
|
|
@ -1269,14 +1271,20 @@ namespace MinecraftClient
|
||||||
/// Called when the Game Mode has been updated for a player
|
/// Called when the Game Mode has been updated for a player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="playername">Player Name</param>
|
/// <param name="playername">Player Name</param>
|
||||||
/// <param name="uuid">Player UUID</param>
|
/// <param name="uuid">Player UUID (Empty for initial gamemode on login)</param>
|
||||||
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
|
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
|
||||||
public void OnGamemodeUpdate(Guid uuid, int gamemode)
|
public void OnGamemodeUpdate(Guid uuid, int gamemode)
|
||||||
{
|
{
|
||||||
string playerName = null;
|
// Initial gamemode on login
|
||||||
|
if (uuid == Guid.Empty)
|
||||||
|
this.gamemode = gamemode;
|
||||||
|
|
||||||
|
// Further regular gamemode change events
|
||||||
if (onlinePlayers.ContainsKey(uuid))
|
if (onlinePlayers.ContainsKey(uuid))
|
||||||
{
|
{
|
||||||
playerName = onlinePlayers[uuid];
|
string playerName = onlinePlayers[uuid];
|
||||||
|
if (playerName == this.username)
|
||||||
|
this.gamemode = gamemode;
|
||||||
foreach (ChatBot bot in bots.ToArray())
|
foreach (ChatBot bot in bots.ToArray())
|
||||||
bot.OnGamemodeUpdate(playerName, uuid, gamemode);
|
bot.OnGamemodeUpdate(playerName, uuid, gamemode);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
handler.OnGameJoined();
|
handler.OnGameJoined();
|
||||||
int playerEntityID = dataTypes.ReadNextInt(packetData);
|
int playerEntityID = dataTypes.ReadNextInt(packetData);
|
||||||
handler.SetPlayerEntityID(playerEntityID);
|
handler.SetPlayerEntityID(playerEntityID);
|
||||||
dataTypes.ReadNextByte(packetData);
|
handler.OnGamemodeUpdate(Guid.Empty, dataTypes.ReadNextByte(packetData));
|
||||||
if (protocolversion >= MC191Version)
|
if (protocolversion >= MC191Version)
|
||||||
this.currentDimension = dataTypes.ReadNextInt(packetData);
|
this.currentDimension = dataTypes.ReadNextInt(packetData);
|
||||||
else
|
else
|
||||||
|
|
@ -437,15 +437,14 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (dataTypes.ReadNextBool(packetData))
|
if (dataTypes.ReadNextBool(packetData))
|
||||||
dataTypes.ReadNextString(packetData);
|
dataTypes.ReadNextString(packetData);
|
||||||
}
|
}
|
||||||
dataTypes.ReadNextVarInt(packetData);
|
handler.OnGamemodeUpdate(uuid, dataTypes.ReadNextVarInt(packetData));
|
||||||
dataTypes.ReadNextVarInt(packetData);
|
dataTypes.ReadNextVarInt(packetData);
|
||||||
if (dataTypes.ReadNextBool(packetData))
|
if (dataTypes.ReadNextBool(packetData))
|
||||||
dataTypes.ReadNextString(packetData);
|
dataTypes.ReadNextString(packetData);
|
||||||
handler.OnPlayerJoin(uuid, name);
|
handler.OnPlayerJoin(uuid, name);
|
||||||
break;
|
break;
|
||||||
case 0x01: //Update gamemode
|
case 0x01: //Update gamemode
|
||||||
int gamemode = dataTypes.ReadNextVarInt(packetData);
|
handler.OnGamemodeUpdate(uuid, dataTypes.ReadNextVarInt(packetData));
|
||||||
handler.OnGamemodeUpdate(uuid, gamemode);
|
|
||||||
break;
|
break;
|
||||||
case 0x02: //Update latency
|
case 0x02: //Update latency
|
||||||
int latency = dataTypes.ReadNextVarInt(packetData);
|
int latency = dataTypes.ReadNextVarInt(packetData);
|
||||||
|
|
@ -1366,7 +1365,6 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
catch (System.IO.IOException) { return false; }
|
catch (System.IO.IOException) { return false; }
|
||||||
catch (ObjectDisposedException) { return false; }
|
catch (ObjectDisposedException) { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
|
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue