mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Improve /place, and only allow valid enum members for ConfigEnum attribute
This commit is contained in:
parent
ee7b5ff436
commit
f53570e9c3
@ -14,7 +14,7 @@
|
|||||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
or implied. See the Licenses for the specific language governing
|
or implied. See the Licenses for the specific language governing
|
||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Building {
|
namespace MCGalaxy.Commands.Building {
|
||||||
@ -29,30 +29,25 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
ExtBlock block = p.GetHeldBlock();
|
ExtBlock block = p.GetHeldBlock();
|
||||||
int x = p.Pos.BlockX, y = (p.Pos.Y - 32) / 32, z = p.Pos.BlockZ;
|
int x = p.Pos.BlockX, y = (p.Pos.Y - 32) / 32, z = p.Pos.BlockZ;
|
||||||
|
|
||||||
try {
|
string[] parts = message.SplitSpaces();
|
||||||
string[] parts = message.SplitSpaces();
|
switch (parts.Length) {
|
||||||
switch (parts.Length) {
|
case 1:
|
||||||
case 1:
|
if (message == "") break;
|
||||||
if (message == "") break;
|
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||||
|
break;
|
||||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
case 3:
|
||||||
break;
|
if (!CommandParser.GetInt(p, parts[0], "X", ref x)) return;
|
||||||
case 3:
|
if (!CommandParser.GetInt(p, parts[1], "Y", ref y)) return;
|
||||||
x = int.Parse(parts[0]);
|
if (!CommandParser.GetInt(p, parts[2], "Z", ref z)) return;
|
||||||
y = int.Parse(parts[1]);
|
break;
|
||||||
z = int.Parse(parts[2]);
|
case 4:
|
||||||
break;
|
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||||
case 4:
|
if (!CommandParser.GetInt(p, parts[1], "X", ref x)) return;
|
||||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
if (!CommandParser.GetInt(p, parts[2], "Y", ref y)) return;
|
||||||
|
if (!CommandParser.GetInt(p, parts[3], "Z", ref z)) return;
|
||||||
x = int.Parse(parts[1]);
|
break;
|
||||||
y = int.Parse(parts[2]);
|
default:
|
||||||
z = int.Parse(parts[3]);
|
Help(p); return;
|
||||||
break;
|
|
||||||
default: Player.Message(p, "Invalid number of parameters"); return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
Player.Message(p, "Invalid parameters"); return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||||
@ -73,8 +68,10 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/place [block] <x y z>");
|
Player.Message(p, "%T/place <block>");
|
||||||
Player.Message(p, "%HPlaces block at your feet or optionally at <x y z>");
|
Player.Message(p, "%HPlaces block at your feet.");
|
||||||
|
Player.Message(p, "%T/place <block> [x y z]");
|
||||||
|
Player.Message(p, "%HPlaces block at [x y z]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,7 @@ namespace MCGalaxy.Config {
|
|||||||
object result;
|
object result;
|
||||||
try {
|
try {
|
||||||
result = Enum.Parse(EnumType, value, true);
|
result = Enum.Parse(EnumType, value, true);
|
||||||
|
if (!Enum.IsDefined(EnumType, result)) throw new ArgumentException("value not member of enumeration");
|
||||||
} catch {
|
} catch {
|
||||||
Logger.Log(LogType.Warning, "Config key \"{0}\" is not a valid enum member, using default of {1}", Name, DefaultValue);
|
Logger.Log(LogType.Warning, "Config key \"{0}\" is not a valid enum member, using default of {1}", Name, DefaultValue);
|
||||||
return DefaultValue;
|
return DefaultValue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user