public override void UseItem(Level world, Player player, Vector3 blockCoordinates, BlockFace face) { var blockatpos = world.GetBlock(blockCoordinates); if (!(blockatpos is BlockAir)) { BitArray b = new BitArray(new byte[] {blockatpos.Metadata}); ConsoleFunctions.WriteLine("\n\n"); ConsoleFunctions.WriteInfoLine("------------------------------------"); ConsoleFunctions.WriteInfoLine("Block: " + blockatpos); ConsoleFunctions.WriteInfoLine("------------------------------------"); for (int i = 0; i < b.Count; i++) { ConsoleFunctions.WriteInfoLine("Bit " + i + ": " + b[i]); } ConsoleFunctions.WriteInfoLine("------------------------------------\n\n"); player.SendChat("Info tool used, Metadata written to chat!", ChatColor.Gold); } }
public void MyInfo(Player player, bool console = false) { player.SendChat("====Start Debug Info====", ChatColor.Yellow); player.SendChat("Operator Status: " + player.IsOperator, ChatColor.Yellow); player.SendChat("Username: "******"UUID: " + player.Uuid, ChatColor.Yellow); player.SendChat("Gamemode: " + player.Gamemode, ChatColor.Yellow); player.SendChat("====End of Debug Info====", ChatColor.Yellow); if (console) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("====Start Debug Info===="); Console.WriteLine("Operator Status: " + player.IsOperator); Console.WriteLine("Username: "******"UUID: " + player.Uuid); Console.WriteLine("Gamemode: " + player.Gamemode); Console.WriteLine("====End of Debug Info===="); Console.ResetColor(); } }
public void HandleCommand(string message, Player player) { try { var commandText = message.Split(' ')[0]; message = message.Replace(commandText, "").Trim(); commandText = commandText.Replace("/", "").Replace(".", ""); var arguments = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); foreach (var handlerEntry in _pluginCommands) { var commandAttribute = handlerEntry.Value; if (!commandText.Equals(commandAttribute.Command, StringComparison.InvariantCultureIgnoreCase)) continue; var method = handlerEntry.Key; if (method == null) return; var authorizationAttributes = method.GetCustomAttributes<PermissionAttribute>(true); foreach (var authorizationAttribute in authorizationAttributes) { if (!PermissionManager.HasPermission(player, authorizationAttribute.Permission)) { player.SendChat("You are not permitted to use this command!", ChatColor.Red); return; } } if (ExecuteCommand(method, player, arguments, commandAttribute)) return; } } catch (Exception ex) { ConsoleFunctions.WriteWarningLine(ex.ToString()); } player.SendChat("Unknown command.", ChatColor.Red); }
private bool ExecuteCommand(MethodInfo method, Player player, string[] args, CommandAttribute commandAttribute) { var parameters = method.GetParameters(); var addLenght = 0; int requiredParameters = 0; if (parameters.Length > 0 && parameters[0].ParameterType == typeof (Player)) { addLenght = 1; requiredParameters = -1; } bool hasRequiredParameters = true; bool hasStringArray = false; foreach (var param in parameters) { if (!param.IsOptional) requiredParameters++; if (param.ParameterType == typeof (string[])) hasStringArray = true; } if (args.Length < requiredParameters && !hasStringArray) hasRequiredParameters = false; if (!hasRequiredParameters || args.Length > (parameters.Length - addLenght) && !hasStringArray) { player.SendChat("Invalid command usage!", ChatColor.Red); player.SendChat(commandAttribute.Usage, ChatColor.Red); return true; } var objectArgs = new object[parameters.Length]; bool stringarrayfound = false; int stringarrayposition = 0; List<string> stringarrayvalues = new List<string>(); int length = args.Length + addLenght; for (var k = 0; k < length; k++) { var parameter = parameters[k]; var i = k - addLenght; if (k == 0 && addLenght == 1) { if (parameter.ParameterType == typeof (Player)) { objectArgs[k] = player; continue; } ConsoleFunctions.WriteWarningLine("Command method " + method.Name + " missing Player as first argument."); return false; } if (parameter.ParameterType == typeof (string[])) { stringarrayfound = true; stringarrayposition = k; stringarrayvalues.Add(args[i]); objectArgs[stringarrayposition] = stringarrayvalues.ToArray(); break; } if (parameter.ParameterType == typeof (string)) { objectArgs[k] = args[i]; continue; } if (parameter.ParameterType == typeof (byte)) { byte value; if (!byte.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof (short)) { short value; if (!short.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof (int)) { int value; if (!int.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof (bool)) { bool value; if (!bool.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof (float)) { float value; if (!float.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof (double)) { double value; if (!double.TryParse(args[i], out value)) return false; objectArgs[k] = value; continue; } if (parameter.ParameterType == typeof(Player)) { Player value = Globals.LevelManager.GetAllPlayers().FirstOrDefault(p => p.Username.ToLower().Equals(args[i].ToLower())); if (value == null) { player.SendChat(String.Format("Player \"{0}\" is not found!", args[i]), ChatColor.Red); return true; } objectArgs[k] = value; continue; } return false; } if (stringarrayfound) { for (int k = stringarrayposition + 1; k <= args.Length; k++) { var i = k - addLenght; stringarrayvalues.Add(args[i]); objectArgs[stringarrayposition] = stringarrayvalues.ToArray(); } } var pluginInstance = _plugins.FirstOrDefault(plugin => plugin.GetType() == method.DeclaringType); if (pluginInstance == null) { ConsoleFunctions.WriteDebugLine("Plugin instance is null!"); return false; } if (method.IsStatic) { method.Invoke(null, objectArgs); } else { if (method.DeclaringType == null) return false; method.Invoke(pluginInstance, objectArgs); } return true; }
public int CalculateTps(Player player = null) { var average = _lastCalc; var d = 1000 - _lastCalc; d = d/50; var exact = d; var color = "a"; if (exact <= 10) color = "c"; if (exact <= 15 && exact > 10) color = "e"; if (player != null) { player.SendChat("TPS: §" + color + exact); player.SendChat("Miliseconds in Tick: " + average + "ms"); } return (int) exact; }
public void OptionTest(Player player, string test, string test2 = "") { player.SendChat(String.Format("Test={0}, Test2={1}", test, test2)); }
public static void SendChatMessage(Player player, string message, ChatColor color) { player.SendChat(message, color); }
public static void SendChatMessage(Player player, string message) { player.SendChat(message); }