mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Prefer MakeSelection to using blockchange
This commit is contained in:
parent
2c1698d7b6
commit
a44b630464
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
public override CommandPerm[] ExtraPerms {
|
public override CommandPerm[] ExtraPerms {
|
||||||
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can use admin commands for tntwars") }; }
|
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can use admin commands for tntwars") }; }
|
||||||
}
|
}
|
||||||
bool DeleteZone = false, CheckZone = false, NoTntZone = false;
|
bool NoTntZone = false;
|
||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
string[] text = new string[] { "", "", "", "", "" };
|
string[] text = new string[] { "", "", "", "", "" };
|
||||||
@ -946,20 +946,13 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
void HandleZone(Player p, TntWarsGame it, bool noTntZone, string[] text) {
|
void HandleZone(Player p, TntWarsGame it, bool noTntZone, string[] text) {
|
||||||
NoTntZone = noTntZone;
|
NoTntZone = noTntZone;
|
||||||
string msg = noTntZone ? "no TNT" : "no blocks deleted on explosions";
|
string msg = noTntZone ? "no TNT" : "no blocks deleted on explosions";
|
||||||
DeleteZone = false;
|
|
||||||
CheckZone = false;
|
|
||||||
Vec3U16 cpos = default(Vec3U16);
|
|
||||||
p.blockchangeObject = cpos;
|
|
||||||
|
|
||||||
switch (text[3]) {
|
switch (text[3]) {
|
||||||
case "add":
|
case "add":
|
||||||
case "a":
|
case "a":
|
||||||
case "new":
|
case "new":
|
||||||
DeleteZone = false;
|
|
||||||
CheckZone = false;
|
|
||||||
Player.Message(p, "TNT Wars: Place 2 blocks to create the zone for {0}!", msg);
|
Player.Message(p, "TNT Wars: Place 2 blocks to create the zone for {0}!", msg);
|
||||||
//p.ClearBlockchange();
|
p.MakeSelection(2, null, AddZoneCallback);
|
||||||
p.Blockchange += PlacedMark1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
@ -972,20 +965,15 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
Player.Message(p, "TNT Wars: Deleted all zones for {0}!", msg);
|
Player.Message(p, "TNT Wars: Deleted all zones for {0}!", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteZone = true;
|
|
||||||
CheckZone = false;
|
|
||||||
Player.Message(p, "TNT Wars: Place a block to delete the zone for {0}!", msg);
|
Player.Message(p, "TNT Wars: Place a block to delete the zone for {0}!", msg);
|
||||||
p.ClearBlockchange();
|
p.MakeSelection(1, null, DeleteZoneCallback);
|
||||||
p.Blockchange += PlacedMark1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "check":
|
case "check":
|
||||||
case "c":
|
case "c":
|
||||||
DeleteZone = false;
|
|
||||||
CheckZone = true;
|
|
||||||
Player.Message(p, "TNT Wars: Place a block to check for no {0}!", msg);
|
Player.Message(p, "TNT Wars: Place a block to check for no {0}!", msg);
|
||||||
p.ClearBlockchange();
|
p.MakeSelection(1, null, CheckZoneCallback);
|
||||||
p.Blockchange += PlacedMark1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1157,63 +1145,62 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacedMark1(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
bool DeleteZoneCallback(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
RevertAndClearState(p, x, y, z);
|
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||||
Vec3U16 bp = (Vec3U16)p.blockchangeObject;
|
|
||||||
bp.X = x; bp.Y = y; bp.Z = z;
|
|
||||||
p.blockchangeObject = bp;
|
|
||||||
|
|
||||||
if (!DeleteZone && !CheckZone) {
|
|
||||||
Player.Message(p, "TNT Wars: Place another block to mark the other corner of the zone!");
|
|
||||||
p.Blockchange += PlacedMark2;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
||||||
if (DeleteZone) {
|
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||||
} else if (it.InZone(x, y, z, NoTntZone)) {
|
} else if (it.InZone(x, y, z, NoTntZone)) {
|
||||||
it.DeleteZone(x, y, z, NoTntZone, p);
|
it.DeleteZone(x, y, z, NoTntZone, p);
|
||||||
}
|
}
|
||||||
} else if (CheckZone && NoTntZone) {
|
return false;
|
||||||
if (it == null) {
|
}
|
||||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
|
||||||
} else if (it.InZone(x, y, z, true)) {
|
bool CheckZoneCallback(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
|
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||||
|
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
||||||
|
|
||||||
|
if (it == null) {
|
||||||
|
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||||
|
} else if (NoTntZone) {
|
||||||
|
if (it.InZone(x, y, z, NoTntZone)) {
|
||||||
Player.Message(p, "TNT Wars: You are currently in a no TNT zone!");
|
Player.Message(p, "TNT Wars: You are currently in a no TNT zone!");
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, "TNT Wars: You are not currently in a no TNT zone!");
|
Player.Message(p, "TNT Wars: You are not currently in a no TNT zone!");
|
||||||
}
|
}
|
||||||
} else if (CheckZone && !NoTntZone) {
|
} else {
|
||||||
if (it == null) {
|
if (it.InZone(x, y, z, NoTntZone)) {
|
||||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
|
||||||
} else if (it.InZone(x, y, z, true)) {
|
|
||||||
Player.Message(p, "TNT Wars: You are currently in a no TNT block explosion zone (explosions won't destroy blocks)!");
|
Player.Message(p, "TNT Wars: You are currently in a no TNT block explosion zone (explosions won't destroy blocks)!");
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, "TNT Wars: You are currently in a TNT block explosion zone (explosions will destroy blocks)!");
|
Player.Message(p, "TNT Wars: You are currently in a TNT block explosion zone (explosions will destroy blocks)!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
bool AddZoneCallback(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
RevertAndClearState(p, x, y, z);
|
Vec3U16 p1 = (Vec3U16)marks[0], p2 = (Vec3U16)marks[1];
|
||||||
Vec3U16 cpos = (Vec3U16)p.blockchangeObject;
|
|
||||||
TntWarsGame.Zone Zn = new TntWarsGame.Zone();
|
TntWarsGame.Zone Zn = new TntWarsGame.Zone();
|
||||||
|
|
||||||
Zn.smallX = Math.Min(cpos.X, x);
|
Zn.smallX = Math.Min(p1.X, p2.X);
|
||||||
Zn.smallY = Math.Min(cpos.Y, y);
|
Zn.smallY = Math.Min(p1.Y, p2.Y);
|
||||||
Zn.smallZ = Math.Min(cpos.Z, z);
|
Zn.smallZ = Math.Min(p1.Z, p2.Z);
|
||||||
Zn.bigX = Math.Max(cpos.X, x);
|
Zn.bigX = Math.Max(p1.X, p2.X);
|
||||||
Zn.bigY = Math.Max(cpos.Y, y);
|
Zn.bigY = Math.Max(p1.Y, p2.Y);
|
||||||
Zn.bigZ = Math.Max(cpos.Z, z);
|
Zn.bigZ = Math.Max(p1.Z, p2.Z);
|
||||||
|
|
||||||
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!"); return;
|
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||||
|
} else if (NoTntZone) {
|
||||||
|
it.NoTNTplacableZones.Add(Zn);
|
||||||
|
} else {
|
||||||
|
it.NoBlockDeathZones.Add(Zn);
|
||||||
}
|
}
|
||||||
if (NoTntZone) it.NoTNTplacableZones.Add(Zn);
|
|
||||||
else it.NoBlockDeathZones.Add(Zn);
|
|
||||||
Player.Message(p, "Added zone");
|
Player.Message(p, "Added zone");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected struct CatchPos { public ushort x, y, z; public EndType ending; }
|
protected struct CatchPos { public EndType ending; }
|
||||||
protected enum EndType { Invalid, Normal, Destroy, Teleport, Explode, Laser };
|
protected enum EndType { Invalid, Normal, Destroy, Teleport, Explode, Laser };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using MCGalaxy.DB;
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
using MCGalaxy.Maths;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Info {
|
namespace MCGalaxy.Commands.Info {
|
||||||
public sealed class CmdAbout : Command {
|
public sealed class CmdAbout : Command {
|
||||||
@ -36,16 +37,13 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||||
Player.Message(p, "Break/build a block to display information.");
|
Player.Message(p, "Break/build a block to display information.");
|
||||||
p.ClearBlockchange();
|
p.MakeSelection(1, null, PlacedMark);
|
||||||
p.Blockchange += PlacedBlock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacedBlock(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
if (!p.staticCommands) p.ClearBlockchange();
|
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||||
block = p.level.GetExtBlock(x, y, z);
|
block = p.level.GetExtBlock(x, y, z);
|
||||||
if (block.IsInvalid) return;
|
|
||||||
p.RevertBlock(x, y, z);
|
p.RevertBlock(x, y, z);
|
||||||
|
|
||||||
Dictionary<int, string> names = new Dictionary<int, string>();
|
Dictionary<int, string> names = new Dictionary<int, string>();
|
||||||
|
|
||||||
Player.Message(p, "Retrieving block change records..");
|
Player.Message(p, "Retrieving block change records..");
|
||||||
@ -57,7 +55,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
entry => OutputEntry(p, ref foundAny, names, entry));
|
entry => OutputEntry(p, ref foundAny, names, entry));
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, "&cUnable to accquire read lock on BlockDB after 30 seconds, aborting.");
|
Player.Message(p, "&cUnable to accquire read lock on BlockDB after 30 seconds, aborting.");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +68,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
BlockDBChange.OutputMessageBlock(p, block, x, y, z);
|
BlockDBChange.OutputMessageBlock(p, block, x, y, z);
|
||||||
BlockDBChange.OutputPortal(p, block, x, y, z);
|
BlockDBChange.OutputPortal(p, block, x, y, z);
|
||||||
Server.DoGC();
|
Server.DoGC();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ListFromDatabase(Player p, ref bool foundAny, Dictionary<int, string> names,
|
static void ListFromDatabase(Player p, ref bool foundAny, Dictionary<int, string> names,
|
||||||
|
@ -30,7 +30,6 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||||
p.ClearBlockchange();
|
|
||||||
p.MakeSelection(2, null, DoCentre);
|
p.MakeSelection(2, null, DoCentre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,18 +147,17 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
Player.Message(p, format, cState.UsedBlocks);
|
Player.Message(p, format, cState.UsedBlocks);
|
||||||
if (cArgs.offsetIndex != -1) {
|
if (cArgs.offsetIndex != -1) {
|
||||||
Player.Message(p, "Place a block to determine where to paste from");
|
Player.Message(p, "Place a block to determine where to paste from");
|
||||||
p.Blockchange += BlockchangeOffset;
|
p.MakeSelection(1, null, PlacedOffsetMark);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockchangeOffset(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
bool PlacedOffsetMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
RevertAndClearState(p, x, y, z);
|
CopyState copy = p.CopyBuffer;
|
||||||
CopyState state = p.CopyBuffer;
|
copy.Offset.X = copy.OriginX - marks[0].X;
|
||||||
|
copy.Offset.Y = copy.OriginY - marks[0].Y;
|
||||||
state.Offset.X = state.OriginX - x;
|
copy.Offset.Z = copy.OriginZ - marks[0].Z;
|
||||||
state.Offset.Y = state.OriginY - y;
|
return false;
|
||||||
state.Offset.Z = state.OriginZ - z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CopyArgs { public int type, offsetIndex; }
|
struct CopyArgs { public int type, offsetIndex; }
|
||||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using MCGalaxy.Blocks;
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.Blocks.Extended;
|
using MCGalaxy.Blocks.Extended;
|
||||||
|
using MCGalaxy.Maths;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
using MCGalaxy.Util;
|
using MCGalaxy.Util;
|
||||||
|
|
||||||
@ -59,10 +60,8 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
if (!CheckCommand(p, cmd)) return;
|
if (!CheckCommand(p, cmd)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.blockchangeObject = data;
|
|
||||||
Player.Message(p, "Place where you wish the message block to go.");
|
Player.Message(p, "Place where you wish the message block to go.");
|
||||||
p.ClearBlockchange();
|
p.MakeSelection(1, data, PlacedMark);
|
||||||
p.Blockchange += PlacedMark;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtBlock GetBlock(Player p, string name, ref bool allMessage) {
|
ExtBlock GetBlock(Player p, string name, ref bool allMessage) {
|
||||||
@ -110,9 +109,9 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
return message.CaselessEq(cmd) || message.CaselessStarts(cmd + " ");
|
return message.CaselessEq(cmd) || message.CaselessStarts(cmd + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacedMark(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
p.ClearBlockchange();
|
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||||
MBData data = (MBData)p.blockchangeObject;
|
MBData data = (MBData)state;
|
||||||
|
|
||||||
ExtBlock old = p.level.GetExtBlock(x, y, z);
|
ExtBlock old = p.level.GetExtBlock(x, y, z);
|
||||||
if (p.level.CheckAffectPermissions(p, x, y, z, old, data.Block)) {
|
if (p.level.CheckAffectPermissions(p, x, y, z, old, data.Block)) {
|
||||||
@ -122,9 +121,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
} else {
|
} else {
|
||||||
Player.Message(p, "Failed to create a message block.");
|
Player.Message(p, "Failed to create a message block.");
|
||||||
}
|
}
|
||||||
p.RevertBlock(x, y, z);
|
return true;
|
||||||
|
|
||||||
if (p.staticCommands) p.Blockchange += PlacedMark;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDatabase(Player p, MBData data, ushort x, ushort y, ushort z) {
|
void UpdateDatabase(Player p, MBData data, ushort x, ushort y, ushort z) {
|
||||||
|
@ -145,6 +145,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Called when the player has finished providing all the marks for a selection. </summary>
|
/// <summary> Called when the player has finished providing all the marks for a selection. </summary>
|
||||||
|
/// <returns> Whether to repeat this selection, if /static mode is enabled. </returns>
|
||||||
public delegate bool SelectionHandler(Player p, Vec3S32[] marks, object state, ExtBlock block);
|
public delegate bool SelectionHandler(Player p, Vec3S32[] marks, object state, ExtBlock block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user