public static Vector3 PlayerSpawning(PlayerClient pc, Vector3 pos, bool camp) { Player player = Player.FindByPlayerClient(pc); SpawnEvent spawnEvent = new SpawnEvent(pos, camp); if (Hooks.OnPlayerSpawning != null && player != null) { Hooks.OnPlayerSpawning(player, spawnEvent); } return(new Vector3(spawnEvent.X, spawnEvent.Y, spawnEvent.Z)); }
public static bool PlayerConnect(NetUser user) { Player player = new Player(user.playerClient); Server.GetServer().Players.Add(player); bool connected = user.connected; if (Hooks.OnPlayerConnected != null) { Hooks.OnPlayerConnected(player); } return(connected); }
public static void PlayerDisconnect(NetUser user) { Player player = Player.FindByPlayerClient(user.playerClient); if (player != null) { Server.GetServer().Players.Remove(player); } if (Hooks.OnPlayerDisconnected != null) { Hooks.OnPlayerDisconnected(player); } }
public static bool CheckOwner(DeployableObject obj, Controllable controllable) { DoorEvent doorEvent = new DoorEvent(new Entity(obj)); if (obj.ownerID == controllable.playerClient.userID) { doorEvent.Open = true; } if (obj.GetComponent <BasicDoor>() != null && Hooks.OnDoorUse != null) { Hooks.OnDoorUse(Player.FindByPlayerClient(controllable.playerClient), doorEvent); } return(doorEvent.Open); }
public static void NPCKilled(ref DamageEvent e) { try { DeathEvent de = new DeathEvent(ref e); if (Hooks.OnNPCKilled != null) { Hooks.OnNPCKilled(de); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static float EntityDecay(object entity, float dmg) { DecayEvent decayEvent = new DecayEvent(new Entity(entity), ref dmg); if (Hooks.OnEntityDecay != null) { Hooks.OnEntityDecay(decayEvent); } if (Hooks.decayList.Contains(entity)) { Hooks.decayList.Remove(entity); } Hooks.decayList.Add(entity); return(decayEvent.DamageAmount); }
public static bool ConsoleReceived(ref ConsoleSystem.Arg a) { bool result; if (a.argUser == null && a.Class == "magmaweb" && a.Function == "handshake") { a.ReplyWith("All Good !"); result = true; } else { bool flag = a.argUser == null; if (Hooks.OnConsoleReceived != null) { Hooks.OnConsoleReceived(ref a, flag); } if (a.Class == "magma" && a.Function.ToLower() == "reload") { if (a.argUser != null && a.argUser.admin) { PluginEngine.GetPluginEngine().ReloadPlugins(Player.FindByPlayerClient(a.argUser.playerClient)); a.ReplyWith("Magma: Reloaded"); } else if (flag) { PluginEngine.GetPluginEngine().ReloadPlugins(null); a.ReplyWith("Magma: Reloaded"); } } if (a.Reply != null && a.Reply != "") { a.ReplyWith(string.Concat(new string[] { "Magma: ", a.Class, ".", a.Function, " was executed!" })); result = true; } else { result = false; } } return(result); }
public static void PlayerGatherWood(IMeleeWeaponItem rec, ResourceTarget rt, ref ItemDataBlock db, ref int amount, ref string name) { Player player = Player.FindByNetworkPlayer(rec.inventory.networkView.owner); GatherEvent gatherEvent = new GatherEvent(rt, db, amount) { Item = "Wood" }; if (Hooks.OnPlayerGathering != null) { Hooks.OnPlayerGathering(player, gatherEvent); } db = Server.GetServer().Items.Find(gatherEvent.Item); amount = gatherEvent.Quantity; name = gatherEvent.Item; }
public static void PlayerGather(Inventory rec, ResourceTarget rt, ResourceGivePair rg, ref int amount) { Player player = Player.FindByNetworkPlayer(rec.networkView.owner); GatherEvent gatherEvent = new GatherEvent(rt, rg, amount); if (Hooks.OnPlayerGathering != null) { Hooks.OnPlayerGathering(player, gatherEvent); } amount = gatherEvent.Quantity; if (!gatherEvent.Override) { amount = Mathf.Min(amount, rg.AmountLeft()); } rg._resourceItemDatablock = gatherEvent.Item; rg.ResourceItemName = gatherEvent.Item; }
public static ItemDataBlock[] ItemsLoaded(List <ItemDataBlock> items, Dictionary <string, int> stringDB, Dictionary <int, int> idDB) { ItemsBlocks itemsBlocks = new ItemsBlocks(items); if (Hooks.OnItemsLoaded != null) { Hooks.OnItemsLoaded(itemsBlocks); } int num = 0; foreach (ItemDataBlock current in itemsBlocks) { stringDB.Add(current.name, num); idDB.Add(current.uniqueID, num); num++; } Server.GetServer().Items = itemsBlocks; return(itemsBlocks.ToArray()); }
public static bool PlayerKilled(ref DamageEvent de) { bool result; try { DeathEvent deathEvent = new DeathEvent(ref de); if (Hooks.OnPlayerKilled != null) { Hooks.OnPlayerKilled(deathEvent); } result = deathEvent.DropItems; } catch (Exception ex) { Console.WriteLine(ex.ToString()); result = true; } return(result); }
public static bool BlueprintUse(IBlueprintItem item, BlueprintDataBlock bdb) { Player player = Player.FindByPlayerClient(item.controllable.playerClient); bool result; if (player != null) { BPUseEvent bPUseEvent = new BPUseEvent(bdb); if (Hooks.OnBlueprintUse != null) { Hooks.OnBlueprintUse(player, bPUseEvent); } if (!bPUseEvent.Cancel) { result = true; return(result); } } result = false; return(result); }
public void Start() { Helper.Log("Initialize Magma Plugins", true); string text = Path.Combine(Core.SavePath, "\\cfg\\Magma\\config.cfg"); if (!File.Exists(text)) { Data.PATH = Path.Combine(Core.SavePath, "plugins\\"); } else { Data.PATH = new IniParser(text).GetSetting("Settings", "Directory"); } Data.PATH = CommandLine.GetSwitch("-plugindir", Data.PATH); if (!Directory.Exists(Data.PATH)) { Directory.CreateDirectory(Data.PATH); } PluginEngine.GetPluginEngine(); Hooks.ServerStarted(); Helper.Log("Loaded " + PluginEngine.GetPluginEngine().Plugins.Count + " Plugin(s) Total.", true); }
public void LoadPlugins(Player p) { Hooks.ResetHooks(); this.ParsePlugin(); foreach (Plugin plugin in this.plugins) { try { this.interpreter.Run(plugin.Code); foreach (Statement current in JintEngine.Compile(plugin.Code, false).Statements) { if (current.GetType() == typeof(FunctionDeclarationStatement)) { FunctionDeclarationStatement functionDeclarationStatement = (FunctionDeclarationStatement)current; if (functionDeclarationStatement != null) { if (functionDeclarationStatement.Name == "On_ServerInit") { Hooks.OnServerInit += new Hooks.ServerInitDelegate(plugin.OnServerInit); } else if (functionDeclarationStatement.Name == "On_PluginInit") { Hooks.OnPluginInit += new Hooks.PluginInitHandlerDelegate(plugin.OnPluginInit); } else if (functionDeclarationStatement.Name == "On_ServerShutdown") { Hooks.OnServerShutdown += new Hooks.ServerShutdownDelegate(plugin.OnServerShutdown); } else if (functionDeclarationStatement.Name == "On_ItemsLoaded") { Hooks.OnItemsLoaded += new Hooks.ItemsDatablocksLoaded(plugin.OnItemsLoaded); } else if (functionDeclarationStatement.Name == "On_TablesLoaded") { Hooks.OnTablesLoaded += new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); } else if (functionDeclarationStatement.Name == "On_Chat") { Hooks.OnChat += new Hooks.ChatHandlerDelegate(plugin.OnChat); } else if (functionDeclarationStatement.Name == "On_Console") { Hooks.OnConsoleReceived += new Hooks.ConsoleHandlerDelegate(plugin.OnConsole); } else if (functionDeclarationStatement.Name == "On_Command") { Hooks.OnCommand += new Hooks.CommandHandlerDelegate(plugin.OnCommand); } else if (functionDeclarationStatement.Name == "On_PlayerConnected") { Hooks.OnPlayerConnected += new Hooks.ConnectionHandlerDelegate(plugin.OnPlayerConnected); } else if (functionDeclarationStatement.Name == "On_PlayerDisconnected") { Hooks.OnPlayerDisconnected += new Hooks.DisconnectionHandlerDelegate(plugin.OnPlayerDisconnected); } else if (functionDeclarationStatement.Name == "On_PlayerKilled") { Hooks.OnPlayerKilled += new Hooks.KillHandlerDelegate(plugin.OnPlayerKilled); } else if (functionDeclarationStatement.Name == "On_PlayerHurt") { Hooks.OnPlayerHurt += new Hooks.HurtHandlerDelegate(plugin.OnPlayerHurt); } else if (functionDeclarationStatement.Name == "On_PlayerSpawning") { Hooks.OnPlayerSpawning += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawn); } else if (functionDeclarationStatement.Name == "On_PlayerSpawned") { Hooks.OnPlayerSpawned += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawned); } else if (functionDeclarationStatement.Name == "On_PlayerGathering") { Hooks.OnPlayerGathering += new Hooks.PlayerGatheringHandlerDelegate(plugin.OnPlayerGathering); } else if (functionDeclarationStatement.Name == "On_EntityHurt") { Hooks.OnEntityHurt += new Hooks.EntityHurtDelegate(plugin.OnEntityHurt); } else if (functionDeclarationStatement.Name == "On_EntityDecay") { Hooks.OnEntityDecay += new Hooks.EntityDecayDelegate(plugin.OnEntityDecay); } else if (functionDeclarationStatement.Name == "On_EntityDeployed") { Hooks.OnEntityDeployed += new Hooks.EntityDeployedDelegate(plugin.OnEntityDeployed); } else if (functionDeclarationStatement.Name == "On_NPCHurt") { Hooks.OnNPCHurt += new Hooks.HurtHandlerDelegate(plugin.OnNPCHurt); } else if (functionDeclarationStatement.Name == "On_NPCKilled") { Hooks.OnNPCKilled += new Hooks.KillHandlerDelegate(plugin.OnNPCKilled); } else if (functionDeclarationStatement.Name == "On_BlueprintUse") { Hooks.OnBlueprintUse += new Hooks.BlueprintUseHandlerDelagate(plugin.OnBlueprintUse); } else if (functionDeclarationStatement.Name == "On_DoorUse") { Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin.OnDoorUse); } } } } } catch (Exception) { string arg = "Can't load plugin : " + plugin.Path.Remove(0, plugin.Path.LastIndexOf("\\") + 1); if (p != null) { p.Message(arg); } else { Server.GetServer().Broadcast(arg); } } } }