mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 23:43:45 -04:00
Make /possess 24.535% less copy-paste.
This commit is contained in:
parent
5babc4332f
commit
ace8cd5b71
@ -108,7 +108,7 @@ namespace MCGalaxy.Commands
|
|||||||
}
|
}
|
||||||
who = PlayerInfo.Find(message);
|
who = PlayerInfo.Find(message);
|
||||||
p.following = who.name;
|
p.following = who.name;
|
||||||
Player.SendMessage(p, "Following " + who.color + who.DisplayName + Server.DefaultColor + ". Use \"/follow\" to stop.");
|
Player.SendMessage(p, "Following " + who.color + who.DisplayName + "%S. Use \"/follow\" to stop.");
|
||||||
p.SendDespawn(who.id);
|
p.SendDespawn(who.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
namespace MCGalaxy.Commands
|
namespace MCGalaxy.Commands {
|
||||||
{
|
|
||||||
public sealed class CmdPossess : Command
|
public sealed class CmdPossess : Command {
|
||||||
{
|
|
||||||
public override string name { get { return "possess"; } }
|
public override string name { get { return "possess"; } }
|
||||||
public override string shortcut { get { return ""; } }
|
public override string shortcut { get { return ""; } }
|
||||||
public override string type { get { return CommandTypes.Moderation; } }
|
public override string type { get { return CommandTypes.Moderation; } }
|
||||||
@ -28,129 +27,69 @@ namespace MCGalaxy.Commands
|
|||||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||||
public CmdPossess() { }
|
public CmdPossess() { }
|
||||||
|
|
||||||
public override void Use(Player p, string message)
|
public override void Use(Player p, string message) {
|
||||||
{
|
if (p == null) { MessageInGameOnly(p); return; }
|
||||||
if (message.Split(' ').Length > 2) { Help(p); return; }
|
string[] args = message.Split(' ');
|
||||||
if (p == null) { Player.SendMessage(p, "Console possession? Nope.avi."); return; }
|
if (args.Length > 2) { Help(p); return; }
|
||||||
|
|
||||||
|
string skin = (args.Length == 2) ? args[1] : "";
|
||||||
|
message = args[0];
|
||||||
|
if (message == "" || message == p.possess) {
|
||||||
|
if (message == "" && p.possess == "") { Help(p); return; }
|
||||||
|
|
||||||
string skin = (message.Split(' ').Length == 2) ? message.Split(' ')[1] : "";
|
|
||||||
message = message.Split(' ')[0];
|
|
||||||
if (message == "")
|
|
||||||
{
|
|
||||||
if (p.possess == "")
|
|
||||||
{
|
|
||||||
Help(p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Player who = PlayerInfo.Find(p.possess);
|
Player who = PlayerInfo.Find(p.possess);
|
||||||
if (who == null)
|
if (who == null) {
|
||||||
{
|
|
||||||
p.possess = "";
|
p.possess = "";
|
||||||
Player.SendMessage(p, "Possession disabled.");
|
Player.SendMessage(p, "Possession disabled."); return;
|
||||||
return;
|
}
|
||||||
|
if (who == p) {
|
||||||
|
Player.SendMessage(p, "Cannot possess yourself!"); return;
|
||||||
}
|
}
|
||||||
who.following = "";
|
who.following = "";
|
||||||
who.canBuild = true;
|
who.canBuild = true;
|
||||||
p.possess = "";
|
p.possess = "";
|
||||||
if (!who.MarkPossessed())
|
if (!who.MarkPossessed()) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p.invincible = false;
|
p.invincible = false;
|
||||||
Command.all.Find("hide").Use(p, "");
|
Command.all.Find("hide").Use(p, "");
|
||||||
Player.SendMessage(p, "Stopped possessing " + who.color + who.name + Server.DefaultColor + ".");
|
Player.SendMessage(p, "Stopped possessing " + who.color + who.name + "%S.");
|
||||||
return;
|
} else {
|
||||||
}
|
Player who = PlayerInfo.FindOrShowMatches(p, message);
|
||||||
}
|
if (who == null) return;
|
||||||
else if (message == p.possess)
|
if (who.group.Permission >= p.group.Permission) {
|
||||||
{
|
Player.SendMessage(p, "Cannot possess someone of equal or greater rank."); return;
|
||||||
Player who = PlayerInfo.Find(p.possess);
|
}
|
||||||
if (who == null)
|
|
||||||
{
|
if (who.possess != "") {
|
||||||
p.possess = "";
|
Player.SendMessage(p, "That player is currently possessing someone!"); return;
|
||||||
Player.SendMessage(p, "Possession disabled.");
|
}
|
||||||
return;
|
if (who.following != "") {
|
||||||
}
|
Player.SendMessage(p, "That player is either following someone or already possessed."); return;
|
||||||
if (who == p)
|
}
|
||||||
{
|
if (p.possess != "") {
|
||||||
Player.SendMessage(p, "Cannot possess yourself!");
|
Player prev = PlayerInfo.Find(p.possess);
|
||||||
return;
|
if (prev != null) {
|
||||||
}
|
prev.following = "";
|
||||||
who.following = "";
|
prev.canBuild = true;
|
||||||
who.canBuild = true;
|
if (!prev.MarkPossessed()) return;
|
||||||
p.possess = "";
|
|
||||||
if (!who.MarkPossessed())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p.invincible = false;
|
|
||||||
Command.all.Find("hide").Use(p, "");
|
|
||||||
Player.SendMessage(p, "Stopped possessing " + who.color + who.name + Server.DefaultColor + ".");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Player who = PlayerInfo.Find(message);
|
|
||||||
if (who == null)
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, "Could not find player.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (who.group.Permission >= p.group.Permission)
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, "Cannot possess someone of equal or greater rank.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (who.possess != "")
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, "That player is currently possessing someone!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (who.following != "")
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, "That player is either following someone or already possessed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (p.possess != "")
|
|
||||||
{
|
|
||||||
Player oldwho = PlayerInfo.Find(p.possess);
|
|
||||||
if (oldwho != null)
|
|
||||||
{
|
|
||||||
oldwho.following = "";
|
|
||||||
oldwho.canBuild = true;
|
|
||||||
if (!oldwho.MarkPossessed())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//p.SendSpawn(oldwho.id, oldwho.color + oldwho.name, oldwho.pos[0], oldwho.pos[1], oldwho.pos[2], oldwho.rot[0], oldwho.rot[1]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command.all.Find("tp").Use(p, who.name);
|
Command.all.Find("tp").Use(p, who.name);
|
||||||
if (!p.hidden)
|
if (!p.hidden) Command.all.Find("hide").Use(p, "");
|
||||||
{
|
|
||||||
Command.all.Find("hide").Use(p, "");
|
|
||||||
}
|
|
||||||
p.possess = who.name;
|
p.possess = who.name;
|
||||||
who.following = p.name;
|
who.following = p.name;
|
||||||
if (!p.invincible)
|
if (!p.invincible) p.invincible = true;
|
||||||
{
|
|
||||||
p.invincible = true;
|
|
||||||
}
|
|
||||||
bool result = (skin == "#") ? who.MarkPossessed() : who.MarkPossessed(p.name);
|
bool result = (skin == "#") ? who.MarkPossessed() : who.MarkPossessed(p.name);
|
||||||
if (!result)
|
if (!result) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p.SendDespawn(who.id);
|
p.SendDespawn(who.id);
|
||||||
who.canBuild = false;
|
who.canBuild = false;
|
||||||
Player.SendMessage(p, "Successfully possessed " + who.color + who.name + Server.DefaultColor + ".");
|
Player.SendMessage(p, "Successfully possessed " + who.color + who.name + "%S.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p)
|
public override void Help(Player p) {
|
||||||
{
|
|
||||||
Player.SendMessage(p, "/possess <player> [skin as #] - DEMONIC POSSESSION HUE HUE");
|
Player.SendMessage(p, "/possess <player> [skin as #] - DEMONIC POSSESSION HUE HUE");
|
||||||
Player.SendMessage(p, "Using # after player name makes possessed keep their custom skin during possession.");
|
Player.SendMessage(p, "Using # after player name makes possessed keep their custom skin during possession.");
|
||||||
Player.SendMessage(p, "Not using it makes them lose their skin, and makes their name show as \"Player (YourName)\".");
|
Player.SendMessage(p, "Not using it makes them lose their skin, and makes their name show as \"Player (YourName)\".");
|
||||||
|
@ -144,9 +144,7 @@ namespace MCGalaxy.Commands {
|
|||||||
if (pl.level != p.level || pl.hidden || p == pl) continue;
|
if (pl.level != p.level || pl.hidden || p == pl) continue;
|
||||||
Player.SpawnEntity(pl, p, pl.id, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], "");
|
Player.SpawnEntity(pl, p, pl.id, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], "");
|
||||||
}
|
}
|
||||||
|
Player.GlobalSpawn(p, x, y, z, rotX, rotY, true);
|
||||||
if (!p.hidden) Player.GlobalSpawn(p, x, y, z, rotX, rotY, true, "");
|
|
||||||
else p.SendPos(0xFF, x, y, z, rotX, rotY);
|
|
||||||
|
|
||||||
PlayerBot[] bots = PlayerBot.Bots.Items;
|
PlayerBot[] bots = PlayerBot.Bots.Items;
|
||||||
foreach (PlayerBot b in bots)
|
foreach (PlayerBot b in bots)
|
||||||
|
@ -489,8 +489,8 @@ namespace MCGalaxy {
|
|||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
p.lastSpawnColor = p.infected ? ZombieGame.InfectCol : p.color;
|
p.lastSpawnColor = p.infected ? ZombieGame.InfectCol : p.color;
|
||||||
foreach (Player other in players) {
|
foreach (Player other in players) {
|
||||||
if (other.Loading && p != other) continue;
|
if ((other.Loading && p != other) || p.level != other.level) continue;
|
||||||
if (p.level != other.level || (p.hidden && !self)) continue;
|
if ((p.hidden || p.referee) && !self) continue;
|
||||||
|
|
||||||
if (p != other) {
|
if (p != other) {
|
||||||
SpawnEntity(p, other, p.id, x, y, z, rotx, roty, possession);
|
SpawnEntity(p, other, p.id, x, y, z, rotx, roty, possession);
|
||||||
@ -504,20 +504,16 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
internal static void SpawnEntity(Player p, Player dst, byte id, ushort x, ushort y, ushort z,
|
internal static void SpawnEntity(Player p, Player dst, byte id, ushort x, ushort y, ushort z,
|
||||||
byte rotx, byte roty, string possession = "") {
|
byte rotx, byte roty, string possession = "") {
|
||||||
if (!Server.ZombieModeOn) {
|
if (!Server.ZombieModeOn || !p.infected) {
|
||||||
dst.SendSpawn(id, p.color + p.name + possession, x, y, z, rotx, roty); return;
|
dst.SendSpawn(id, p.color + p.name + possession, x, y, z, rotx, roty); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.infected) {
|
|
||||||
if (Server.zombie.ZombieName != "" && !dst.aka)
|
if (Server.zombie.ZombieName != "" && !dst.aka)
|
||||||
dst.SendSpawn(id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
|
dst.SendSpawn(id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
|
||||||
else
|
else
|
||||||
dst.SendSpawn(id, Colors.red + p.name + possession, x, y, z, rotx, roty);
|
dst.SendSpawn(id, Colors.red + p.name + possession, x, y, z, rotx, roty);
|
||||||
if (dst.HasCpeExt(CpeExt.ChangeModel))
|
if (dst.HasCpeExt(CpeExt.ChangeModel))
|
||||||
dst.SendChangeModel(id, "zombie");
|
dst.SendChangeModel(id, "zombie");
|
||||||
} else if (!p.referee) {
|
|
||||||
dst.SendSpawn(id, p.color + p.name + possession, x, y, z, rotx, roty);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GlobalDespawn(Player p, bool self) {
|
public static void GlobalDespawn(Player p, bool self) {
|
||||||
@ -531,12 +527,11 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public bool MarkPossessed(string marker = "") {
|
public bool MarkPossessed(string marker = "") {
|
||||||
if (marker != "") {
|
if (marker != "") {
|
||||||
Player controller = PlayerInfo.Find(marker);
|
Player controller = PlayerInfo.FindExact(marker);
|
||||||
if ( controller == null ) {
|
if (controller == null) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
marker = " (" + controller.color + controller.name + color + ")";
|
marker = " (" + controller.color + controller.name + color + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalDespawn(this, true);
|
GlobalDespawn(this, true);
|
||||||
GlobalSpawn(this, pos[0], pos[1], pos[2], rot[0], rot[1], true, marker);
|
GlobalSpawn(this, pos[0], pos[1], pos[2], rot[0], rot[1], true, marker);
|
||||||
return true;
|
return true;
|
||||||
|
@ -48,7 +48,7 @@ namespace MCGalaxy {
|
|||||||
if (p.frozen) {
|
if (p.frozen) {
|
||||||
p.SendPos(0xFF, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); continue;
|
p.SendPos(0xFF, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); continue;
|
||||||
} else if (p.following != "") {
|
} else if (p.following != "") {
|
||||||
Player who = PlayerInfo.Find(p.following);
|
Player who = PlayerInfo.FindExact(p.following);
|
||||||
if (who == null || who.level != p.level) {
|
if (who == null || who.level != p.level) {
|
||||||
p.following = "";
|
p.following = "";
|
||||||
if (!p.canBuild)
|
if (!p.canBuild)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user