Fix being able to send opchat messages with no contents, prefer explicit delegates to Func

This commit is contained in:
UnknownShadow200 2017-06-21 16:33:26 +10:00
parent 9c8c4fc72e
commit 3c26d97c07
9 changed files with 37 additions and 27 deletions

View File

@ -76,6 +76,8 @@ namespace MCGalaxy {
string name = p == null ? "(console)" : p.name;
string format = "To " + group + " &f-{0}&f- {1}";
if (message == "") { Player.Message(p, "No message to send."); return; }
Chat.MessageWhere(format,
pl => (p == pl || pl.Rank >= perm) && Chat.NotIgnoring(p, pl),
displayName, message);

View File

@ -54,8 +54,8 @@ namespace MCGalaxy {
}
internal static Dictionary<string, Func<Player, string>> standardTokens
= new Dictionary<string, Func<Player, string>> {
internal static Dictionary<string, StringFormatter<Player>> standardTokens
= new Dictionary<string, StringFormatter<Player>> {
{ "$name", p => p.DisplayName == null ? null :
(Server.dollarNames ? "$" : "") + Colors.StripColors(p.DisplayName) },
{ "$truename", p => p.truename == null ? null :

View File

@ -133,8 +133,10 @@ namespace MCGalaxy.Commands.World {
delegate void BoolSetter(ref BlockProps props);
delegate bool BoolGetter(BlockProps props);
static void Toggle(Player p, BlockProps[] scope, ExtBlock block, string type,
BoolSetter setter, Func<BlockProps, bool> getter) {
BoolSetter setter, BoolGetter getter) {
BlockProps props = scope[block.Index];
setter(ref props);
scope[block.Index] = props;

View File

@ -20,15 +20,23 @@ using System.Collections.Generic;
namespace MCGalaxy.DB {
/// <summary> Retrieves a title for a column. </summary>
/// <remarks> Title is displayed on a line before the values of that column. </remarks>
public delegate string TopStatTitle();
/// <summary> Formats a value in a column. </summary>
public delegate string TopStatFormatter(string input);
/// <summary> Outputs ordered stats from a column in a database table. </summary>
public sealed class TopStat {
public readonly string Identifier, Table, Column, OrderBy;
public readonly Func<string> Title;
public readonly Func<string, string> Formatter;
public readonly TopStatTitle Title;
public readonly TopStatFormatter Formatter;
public TopStat(string identifier, string table, string col, Func<string> title,
Func<string, string> formatter, bool ascending = false, string orderBy = null) {
public TopStat(string identifier, string table, string col, TopStatTitle title,
TopStatFormatter formatter, bool ascending = false, string orderBy = null) {
Identifier = identifier;
Table = table;
Column = col;

View File

@ -22,6 +22,8 @@ using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing {
public delegate void PixelGetterCallback(Pixel pixel, DrawOpOutput output);
public sealed class PixelGetter : IDisposable {
Bitmap bmp;
@ -41,14 +43,12 @@ namespace MCGalaxy.Drawing {
data = bmp.LockBits(r, ImageLockMode.ReadOnly, bmp.PixelFormat);
}
public void Iterate(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
public void Iterate(DrawOpOutput output, PixelGetterCallback callback) {
if (data == null) IterateSlow(output, callback);
else IterateFast(output, callback);
}
unsafe void IterateFast(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
unsafe void IterateFast(DrawOpOutput output, PixelGetterCallback callback) {
Pixel pixel;
int width = bmp.Width, height = bmp.Height;
byte* scan0 = (byte*)data.Scan0;
@ -69,8 +69,7 @@ namespace MCGalaxy.Drawing {
}
}
void IterateSlow(DrawOpOutput output,
Action<Pixel, DrawOpOutput> callback) {
void IterateSlow(DrawOpOutput output, PixelGetterCallback callback) {
Pixel pixel;
int width = bmp.Width, height = bmp.Height;
for (int y = 0; y < height; y++)

View File

@ -23,6 +23,8 @@ namespace MCGalaxy.Generator.Foliage {
public delegate void TreeOutput(ushort x, ushort y, ushort z, byte block);
public delegate Tree TreeConstructor();
public abstract class Tree {
protected internal int height, size;
protected Random rnd;
@ -60,8 +62,8 @@ namespace MCGalaxy.Generator.Foliage {
}
public static Dictionary<string, Func<Tree>> TreeTypes =
new Dictionary<string, Func<Tree>>() {
public static Dictionary<string, TreeConstructor> TreeTypes =
new Dictionary<string, TreeConstructor>() {
{ "Fern", () => new NormalTree() }, { "Cactus", () => new CactusTree() },
{ "Notch", () => new ClassicTree() }, { "Swamp", () => new SwampTree() },
{ "Bamboo", () => new BambooTree() }, { "Palm", () => new PalmTree() },

View File

@ -18,7 +18,10 @@
using System;
using System.Collections.Generic;
namespace MCGalaxy.Generator {
namespace MCGalaxy.Generator {
public delegate ushort CalcLiquidLevel(ushort lvlHeight);
public sealed class RealisticGenParams {
public float RangeLow = 0.2f;
public float RangeHigh = 0.8f;
@ -26,7 +29,7 @@ namespace MCGalaxy.Generator {
public bool FalloffEdges = false;
public bool UseLavaLiquid = false;
public bool GenerateOverlay2 = true;
public Func<ushort, ushort> GetLiquidLevel = (height) => (ushort)(height / 2 + 2);
public CalcLiquidLevel GetLiquidLevel = (lvlHeight) => (ushort)(lvlHeight / 2 + 2);
// Decoration parameters
public float TreeDens = 0.35f;

View File

@ -26,6 +26,8 @@ namespace MCGalaxy {
public delegate void OptionSetter(Player p, Level lvl, string value);
public delegate bool OptionIntValidator(Player p, int value);
public static Dictionary<string, OptionSetter> Options = new Dictionary<string, OptionSetter>() {
{ "motd", SetMotd },
{ "RealmOwner", SetRealmOwner },
@ -153,7 +155,7 @@ namespace MCGalaxy {
}
static void SetInt(Player p, Level lvl, ref int target, string value, string name,
Func<Player, int, bool> validator = null) {
OptionIntValidator validator = null) {
if (value == "") { Player.Message(p, "You must provide an integer."); return; }
int raw = 0;
if (!CommandParser.GetInt(p, value, name, ref raw)) return;

View File

@ -25,15 +25,7 @@ namespace System.Runtime.CompilerServices {
public sealed class ExtensionAttribute : Attribute {}
}
namespace System {
public delegate TReturn Func<TReturn>();
public delegate TReturn Func<T1, TReturn>(T1 arg1);
public delegate TReturn Func<T1, T2, TReturn>(T1 arg1, T2 arg2);
public delegate TReturn Func<T1, T2, T3, TReturn>(T1 arg1, T2 arg2, T3 arg3);
public delegate void Action();
public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
}
namespace System { public delegate void Action(); }
namespace MCGalaxy.Util {