I think the goal here is pretty simple, I need to cancel an OnBlockChanging event.
I have tried to set the variable "cancel" to true, but it doesn't seem to cancel the block being placed.
Here's my code, if it is helpful:
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingMCGalaxy;usingMCGalaxy.Events.ServerEvents;usingMCGalaxy.Events.PlayerEvents;usingMCGalaxy.Blocks.Extended;usingBlockID=System.UInt16;usingSystem.Reflection;usingMCGalaxy.Tasks;namespacePluginAllersSurvival{publicclassAllersSurvival:Plugin{public override string name { get {return"AllersSurvival";}}public override string MCGalaxy_Version{ get {return"1.9.4.9";}}public override string welcome { get {return"Thanks for using my plugin, Aller's Survival!";}}public override string creator { get {return"AllergenX";}}publicstaticDictionary<string,int> blockCounts =newDictionary<string,int>();// Called when this plugin is being loaded (e.g. on server startup)public override voidLoad(bool startup){OnBlockChangingEvent.Register(OnBlockChanging,Priority.High);Player[] players =PlayerInfo.Online.Items;
foreach (Player p in players){
blockCounts[p.DisplayName]=0;}}// Called when this plugin is being unloaded (e.g. on server shutdown)public override voidUnload(bool shutdown){OnBlockChangingEvent.Unregister(OnBlockChanging);}publicstaticvoidOnBlockChanging(Player p, ushort x, ushort y, ushort z,BlockID block,bool placing, ref bool cancel){if(p.Level.Config.MOTD.Contains("+survival")){if(placing ==false){
blockCounts[p.DisplayName]= blockCounts[p.DisplayName]+1;
p.Message("You have "+Convert.ToString(blockCounts[p.DisplayName])+" blocks.");}else{if(placing ==true){if(blockCounts[p.DisplayName]>=1){
blockCounts[p.DisplayName]= blockCounts[p.DisplayName]-1;
p.Message("You have "+Convert.ToString(blockCounts[p.DisplayName])+" blocks.");}elseif(blockCounts[p.DisplayName]<=0){
p.Message("You are out of blocks.");
cancel =true;
p.Message(Convert.ToString(cancel));}}}}}// Displays help for or information about this pluginpublic override voidHelp(Player p){
p.Message("Super simple and awesome survival plugin.");}}}
Yes, it messages me "You are out of blocks." and yes, it messages me "True".
I think the goal here is pretty simple, I need to cancel an OnBlockChanging event.
I have tried to set the variable "cancel" to true, but it doesn't seem to cancel the block being placed.
Here's my code, if it is helpful:
Yes, it messages me "You are out of blocks." and yes, it messages me "True".
Share this post
Link to post