-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkyEssentials.cs
143 lines (133 loc) · 5.55 KB
/
SkyEssentials.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
namespace SkyEssentials
{
using global::SkyEssentials.Commands;
using MiNET.Effects;
using OpenAPI;
using OpenAPI.Permission;
using OpenAPI.Player;
using OpenAPI.Plugins;
using System;
/// <summary>
/// Defines the <see cref="SkyEssentials" />.
/// </summary>
[OpenPluginInfo(Author = "Palente", Name = "SkyEssentials", Version = "0.0.3", Website = "https://github.com/Palente")]
public class SkyEssentials : OpenPlugin
{
/// <summary>
/// Defines the Api.
/// </summary>
public OpenApi Api;
/// <summary>
/// Gets the Permissions.
/// </summary>
public PermissionGroup Permissions { get; private set; }
/// <summary>
/// Defines the Version of the plugin..
/// </summary>
public readonly string Version = "0.0.2";
public Events Events { get; private set; }
/// <summary>
/// Called when the plugin is disabled.
/// </summary>
/// <param name="api">The api<see cref="OpenApi"/>.</param>
public override void Disabled(OpenApi api)
{
api.EventDispatcher.UnregisterEvents(Events);
}
/// <summary>
/// Called when the plugin is enabled
/// </summary>
/// <param name="api">The api<see cref="OpenApi"/>.</param>
public override void Enabled(OpenApi api)
{
Events = new Events(this);
api.CommandManager.LoadCommands(new OpCommand());
api.CommandManager.LoadCommands(new PluginsCommand(api));
api.CommandManager.LoadCommands(new TellCommand(this));
api.CommandManager.LoadCommands(new MeCommand(this));
api.CommandManager.LoadCommands(new ListCommand(this));
api.CommandManager.LoadCommands(new TeleportCommand(this));
api.CommandManager.LoadCommands(new SayCommand(this));
api.CommandManager.LoadCommands(new GiveCommand());
api.CommandManager.LoadCommands(new KillCommand(this));
api.CommandManager.LoadCommands(new TimeCommand(this));
api.CommandManager.LoadCommands(new EffectCommand(this));
api.CommandManager.LoadCommands(new SpawnCommand(this));
api.CommandManager.LoadCommands(new GamemodeCommand(this));
api.CommandManager.LoadCommands(new TestCommand(this));
api.EventDispatcher.RegisterEvents(Events);
Api = api;
}
/// <summary>
/// The GetPlayer.
/// </summary>
/// <param name="name">The name<see cref="string"/>.</param>
/// <returns>The <see cref="OpenPlayer?"/>.</returns>
public OpenPlayer? GetPlayer(string name)
{
var players = Api.PlayerManager.GetPlayers();
foreach (OpenPlayer player in players)
if (player.Username.ToLower() == name.ToLower())
return player;
return null;
}
/// <summary>
/// The BroadcastMessage.
/// </summary>
/// <param name="message">The message<see cref="string"/>.</param>
/// <param name="operators">The operators<see cref="bool"/>.</param>
public void BroadcastMessage(string message, bool operators = false)
{
foreach (OpenPlayer player in Api.PlayerManager.GetPlayers())
{
if (operators)
{
if (player.Permissions.HasPermission("skyessentials.admin"))
player.SendMessage(message);
}
else
player.SendMessage(message);
}
}
public static EffectType? EffectTypeFromName(string effectName)
{
effectName = effectName.ToLower();
foreach(EffectType effect in Enum.GetValues(typeof(EffectType))){
if (effect.ToString().ToLower() == effectName)
return effect;
}
return null;
}
//it took me a year to do it... just because we can not create a new instance of Effect ...
public static Effect? GetEffect(EffectType type)
{
return type switch
{
EffectType.Speed => new Speed(),
EffectType.Slowness => new Slowness(),
EffectType.Haste => new Haste(),
EffectType.MiningFatigue => new MiningFatigue(),
EffectType.Strength => new Strength(),
EffectType.InstantHealth => new InstantHealth(),
EffectType.InstantDamage => new InstantDamage(),
EffectType.JumpBoost => new JumpBoost(),
EffectType.Nausea => new Nausea(),
EffectType.Regeneration => new Regeneration(),
EffectType.Resistance => new Resistance(),
EffectType.FireResistance => new FireResistance(),
EffectType.WaterBreathing => new WaterBreathing(),
EffectType.Invisibility => new Invisibility(),
EffectType.Blindness => new Blindness(),
EffectType.NightVision => new NightVision(),
EffectType.Hunger => new Hunger(),
EffectType.Weakness => new Weakness(),
EffectType.Poison => new Poison(),
EffectType.Wither => new Wither(),
EffectType.HealthBoost => new HealthBoost(),
EffectType.Absorption => new Absorption(),
EffectType.Saturation => new Saturation(),
_ => null,
};
}
}
}