public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } ListTag list = ListTag.For(entry.GetArgument(queue, 0)); string message = "Kicked by the server."; if (entry.Arguments.Count >= 2) { message = "Kicked by the server: " + entry.GetArgument(queue, 1); } for (int i = 0; i < list.ListEntries.Count; i++) { PlayerEntity pl = TheServer.GetPlayerFor(list.ListEntries[i].ToString()); if (pl == null) { entry.Bad(queue, "Unknown player " + TagParser.Escape(list.ListEntries[i].ToString())); } else { pl.Kick(message); } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { TemplateObject cb = entry.GetArgumentObject(queue, 0); if (cb.ToString() == "\0CALLBACK") { return; } if (entry.InnerCommandBlock == null) { queue.HandleError(entry, "Invalid or missing command block!"); return; } ListTag mode = ListTag.For(cb); List <ItemStack> items = new List <ItemStack>(); for (int i = 1; i < entry.Arguments.Count; i++) { ItemTag required = ItemTag.For(TheServer, entry.GetArgumentObject(queue, i)); if (required == null) { queue.HandleError(entry, "Invalid required item!"); return; } items.Add(required.Internal); } TheServer.Recipes.AddRecipe(RecipeRegistry.ModeFor(mode), entry.InnerCommandBlock, entry.BlockStart, items.ToArray()); queue.CurrentEntry.Index = entry.BlockEnd + 2; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Added recipe!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 2) { ShowUsage(queue, entry); return; } ListTag players = ListTag.For(entry.GetArgumentObject(queue, 0)); ListTag items = ListTag.For(entry.GetArgumentObject(queue, 1)); List <ItemStack> itemlist = new List <ItemStack>(); for (int i = 0; i < items.ListEntries.Count; i++) { ItemTag item = ItemTag.For(TheServer, items.ListEntries[i]); if (item == null) { queue.HandleError(entry, "Invalid item!"); return; } itemlist.Add(item.Internal); } List <PlayerEntity> playerlist = new List <PlayerEntity>(); for (int i = 0; i < players.ListEntries.Count; i++) { PlayerTag player = PlayerTag.For(TheServer, players.ListEntries[i]); if (player == null) { queue.HandleError(entry, "Invalid player: " + TagParser.Escape(items.ListEntries[i].ToString())); return; } playerlist.Add(player.Internal); } foreach (PlayerEntity player in playerlist) { foreach (ItemStack item in itemlist) { player.Items.GiveItem(item); } } if (entry.ShouldShowGood(queue)) { entry.Good(queue, itemlist.Count + " item(s) given to " + playerlist.Count + " player(s)!"); } }
public static RecipeResultTag For(Server tserver, TagData data, TemplateObject input) { if (input is RecipeResultTag) { return((RecipeResultTag)input); } ListTag list = ListTag.For(input); RecipeTag recipe = RecipeTag.For(tserver, data, list.ListEntries[0]); List <ItemStack> used = new List <ItemStack>(); for (int i = 1; i < list.ListEntries.Count; i++) { used.Add(ItemTag.For(tserver, list.ListEntries[i]).Internal); } return(new RecipeResultTag(new RecipeResult() { Recipe = recipe.Internal, UsedInput = used })); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { ListTag players = ListTag.For(entry.GetArgument(queue, 0)); TemplateObject tcolor = entry.GetArgumentObject(queue, 1); ColorTag color = ColorTag.For(tcolor); if (color == null) { queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString())); return; } string tchatter = entry.GetArgument(queue, 2); PlayerTag chatter = PlayerTag.For(tchatter); if (chatter == null) { queue.HandleError(entry, "Invalid chatting player: " + TagParser.Escape(tchatter)); return; } string message = entry.GetArgument(queue, 3); foreach (TemplateObject tplayer in players.ListEntries) { PlayerTag player = PlayerTag.For(tplayer.ToString()); if (player == null) { queue.HandleError(entry, "Invalid player: " + TagParser.Escape(tplayer.ToString())); continue; } ChatManager.manager.channel.send("tellChat", player.Internal.playerID.steamID, ESteamPacket.UPDATE_UNRELIABLE_BUFFER, chatter.Internal.playerID.steamID, (byte)0 /* TODO: Configurable mode? */, color.Internal, message); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully sent a message."); } } }
public override TemplateObject Handle(TagData data) { data.Shrink(); if (data.Remaining == 0) { return(new TextTag(ToString())); } switch (data[0]) { // <--[tagbase] // @Name ServerTag.online_players // @Group Entities // @ReturnType ListTag // @Returns a list of all online players. // @Example .online_players could return "Fortifier|mcmonkey". // --> case "online_players": { ListTag players = new ListTag(); foreach (PlayerEntity p in TheServer.Players) { players.ListEntries.Add(new PlayerTag(p)); } return(players.Handle(data.Shrink())); } // <--[tagbase] // @Name ServerTag.loaded_worlds // @Group World // @ReturnType ListTag // @Returns a list of all loaded worlds. // @Example .loaded_worlds could return "default|bob". // --> case "loaded_worlds": { ListTag worlds = new ListTag(); foreach (World w in TheServer.LoadedWorlds) { worlds.ListEntries.Add(new WorldTag(w)); } return(worlds.Handle(data.Shrink())); } // <--[tagbase] // @Name ServerTag.loaded_recipes // @Group Items // @ReturnType ListTag // @Returns a list of all loaded recipes. // --> case "loaded_recipes": { ListTag recipes = new ListTag(); foreach (ItemRecipe r in TheServer.Recipes.Recipes) { recipes.ListEntries.Add(new RecipeTag(r)); } return(recipes.Handle(data.Shrink())); } // <--[tagbase] // @Name ServerTag.can_craft_from[<ListTag>] // @Group Items // @ReturnType ListTag // @Returns a list of all loaded recipes that can be crafted from the given input. // @Example .can_craft_from[blocks/grass_forest] could return "1&pipeblocks/grass_forest|". // --> case "can_craft_from": { // TODO: Handle errors neatly! List <ItemStack> items = new List <ItemStack>(); ListTag list = ListTag.For(data.GetModifierObject(0)); foreach (TemplateObject obj in list.ListEntries) { items.Add(ItemTag.For(TheServer, obj).Internal); } ListTag recipes = new ListTag(); foreach (RecipeResult r in TheServer.Recipes.CanCraftFrom(items.ToArray())) { recipes.ListEntries.Add(new RecipeResultTag(r)); } return(recipes.Handle(data.Shrink())); } // <--[tagbase] // @Name ServerTag.match_player[<TextTag>] // @Group Entities // @ReturnType PlayerTag // @Returns the player whose name best matches the input. // @Example .match_player[Fort] out of a group of "Fortifier", "Fort", and "Forty" would return "Fort". // @Example .match_player[monk] out of a group of "mcmonkey", "morph", and "Fort" would return "mcmonkey". // --> case "match_player": { string pname = data.GetModifier(0); PlayerEntity player = TheServer.GetPlayerFor(pname); if (player == null) { data.Error("Invalid player '" + TagParser.Escape(pname) + "'!"); return(new NullTag()); } return(new PlayerTag(player).Handle(data.Shrink())); } default: return(new TextTag(ToString()).Handle(data)); } }
public override TemplateObject Handle(TagData data) { if (data.Remaining == 0) { return(this); } switch (data[0]) { // <--[tag] // @Name ColorTag.red // @Group General Information // @ReturnType NumberTag // @Returns the red value of this color. // @Example "0.1,0.2,0.3,1" .red returns "0.1". // --> case "red": return(new NumberTag(Internal.r).Handle(data.Shrink())); // <--[tag] // @Name ColorTag.green // @Group General Information // @ReturnType NumberTag // @Returns the green value of this color. // @Example "0.1,0.2,0.3,1" .green returns "0.2". // --> case "green": return(new NumberTag(Internal.g).Handle(data.Shrink())); // <--[tag] // @Name ColorTag.blue // @Group General Information // @ReturnType NumberTag // @Returns the blue value of this color. // @Example "0.1,0.2,0.3,1" .red returns "0.3". // --> case "blue": return(new NumberTag(Internal.b).Handle(data.Shrink())); // <--[tag] // @Name ColorTag.alpha // @Group General Information // @ReturnType NumberTag // @Returns the alpha value of this color. // @Example "0.1,0.2,0.3,1" .red returns "1". // --> case "alpha": return(new NumberTag(Internal.a).Handle(data.Shrink())); // <--[tag] // @Name ColorTag.mix[<ColorTag>|...] // @Group Mathematics // @ReturnType ColorTag // @Returns the result of mixing the specified color(s) with this one. // @Example "blue" .mix[red] returns "0.5,0,0.5,1" // --> case "mix": { ListTag list = ListTag.For(data.GetModifierObject(0)); Color mixedColor = Internal; foreach (TemplateObject tcolor in list.ListEntries) { ColorTag color = ColorTag.For(tcolor); if (color == null) { SysConsole.Output(OutputType.ERROR, "Invalid color: " + TagParser.Escape(tcolor.ToString())); continue; } mixedColor += color.Internal; } return(new ColorTag(mixedColor / list.ListEntries.Count).Handle(data.Shrink())); } default: return(new TextTag(ToString()).Handle(data)); } }
/// <summary>Constructs the argument with input text.</summary> /// <param name="_text">The input text.</param> /// <param name="wasquoted">Whether the argument was quoted at input time.</param> /// <param name="perfect">Whether the argument must parse back "perfectly" (meaning, it will ToString to the exact original input).</param> /// <param name="_engine">The backing script engine.</param> public TextArgumentBit(string _text, bool wasquoted, bool perfect, ScriptEngine _engine) { Engine = _engine; if (wasquoted) { InputValue = new TextTag(_text); ResType = TextTag.TYPE; return; } else if (_text == "true") { InputValue = BooleanTag.TRUE; ResType = BooleanTag.TYPE; return; } else if (_text == "false") { InputValue = BooleanTag.FALSE; ResType = BooleanTag.TYPE; return; } else if (_text == "&{NULL}") { InputValue = NullTag.NULL_VALUE; ResType = NullTag.TYPE; return; } else if (long.TryParse(_text, out long ti) && ti.ToString() == _text) { InputValue = new IntegerTag(ti); ResType = IntegerTag.TYPE; return; } else if (double.TryParse(_text, out double tn) && (!perfect || tn.ToString() == _text)) { InputValue = new NumberTag(tn); ResType = NumberTag.TYPE; return; } else if (_text.Contains('|')) { if (_text.Contains(':')) { MapTag map = MapTag.For(_text); if (map.ToString() == _text) { InputValue = map; ResType = MapTag.TYPE; return; } } ListTag list = ListTag.For(_text); if (list.ToString() == _text) { InputValue = list; ResType = ListTag.TYPE; return; } } InputValue = new TextTag(_text); ResType = TextTag.TYPE; }