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
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
@ -29,30 +29,25 @@ namespace MCGalaxy.Commands.Building {
|
||||
ExtBlock block = p.GetHeldBlock();
|
||||
int x = p.Pos.BlockX, y = (p.Pos.Y - 32) / 32, z = p.Pos.BlockZ;
|
||||
|
||||
try {
|
||||
string[] parts = message.SplitSpaces();
|
||||
switch (parts.Length) {
|
||||
case 1:
|
||||
if (message == "") break;
|
||||
|
||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||
break;
|
||||
case 3:
|
||||
x = int.Parse(parts[0]);
|
||||
y = int.Parse(parts[1]);
|
||||
z = int.Parse(parts[2]);
|
||||
break;
|
||||
case 4:
|
||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||
|
||||
x = int.Parse(parts[1]);
|
||||
y = int.Parse(parts[2]);
|
||||
z = int.Parse(parts[3]);
|
||||
break;
|
||||
default: Player.Message(p, "Invalid number of parameters"); return;
|
||||
}
|
||||
} catch {
|
||||
Player.Message(p, "Invalid parameters"); return;
|
||||
string[] parts = message.SplitSpaces();
|
||||
switch (parts.Length) {
|
||||
case 1:
|
||||
if (message == "") break;
|
||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||
break;
|
||||
case 3:
|
||||
if (!CommandParser.GetInt(p, parts[0], "X", ref x)) return;
|
||||
if (!CommandParser.GetInt(p, parts[1], "Y", ref y)) return;
|
||||
if (!CommandParser.GetInt(p, parts[2], "Z", ref z)) return;
|
||||
break;
|
||||
case 4:
|
||||
if (!CommandParser.GetBlock(p, parts[0], out block)) return;
|
||||
if (!CommandParser.GetInt(p, parts[1], "X", ref x)) return;
|
||||
if (!CommandParser.GetInt(p, parts[2], "Y", ref y)) return;
|
||||
if (!CommandParser.GetInt(p, parts[3], "Z", ref z)) return;
|
||||
break;
|
||||
default:
|
||||
Help(p); return;
|
||||
}
|
||||
|
||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||
@ -73,8 +68,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/place [block] <x y z>");
|
||||
Player.Message(p, "%HPlaces block at your feet or optionally at <x y z>");
|
||||
Player.Message(p, "%T/place <block>");
|
||||
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;
|
||||
try {
|
||||
result = Enum.Parse(EnumType, value, true);
|
||||
if (!Enum.IsDefined(EnumType, result)) throw new ArgumentException("value not member of enumeration");
|
||||
} catch {
|
||||
Logger.Log(LogType.Warning, "Config key \"{0}\" is not a valid enum member, using default of {1}", Name, DefaultValue);
|
||||
return DefaultValue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user