craztheking

Untitled

Aug 23rd, 2025
116
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. public class AdminSafezoneBuildMod : MonoBehaviour
  7. {
  8. private bool adminBuildMode = false;
  9. private Config config;
  10.  
  11. void Start()
  12. {
  13. LoadConfig();
  14. ChatManager.RegisterCommand(config.adminBuildCommand, OnAdminBuildCommand);
  15. GameManager.Instance.OnBlockPlaced += OnBlockAction;
  16. GameManager.Instance.OnBlockDestroyed += OnBlockAction;
  17. }
  18.  
  19. void LoadConfig()
  20. {
  21. string configPath = "Mods/AdminSafezoneBuild/Config/AdminSafezoneConfig.json";
  22. if (File.Exists(configPath))
  23. {
  24. string json = File.ReadAllText(configPath);
  25. config = JsonUtility.FromJson<Config>(json);
  26. }
  27. else
  28. {
  29. config = new Config();
  30. }
  31. }
  32.  
  33. void OnAdminBuildCommand(Player player, string command, string[] args)
  34. {
  35. if (player.PermissionLevel < config.requiredPermissionLevel)
  36. {
  37. if (config.notifyAdmin)
  38. GameManager.Instance.ChatMessageToPlayer(player, "You do not have permission to toggle Admin Build Mode.");
  39. return;
  40. }
  41.  
  42. adminBuildMode = !adminBuildMode;
  43. if (config.notifyAdmin)
  44. {
  45. string msg = adminBuildMode ? config.enableMessage : config.disableMessage;
  46. GameManager.Instance.ChatMessageToPlayer(player, msg);
  47. }
  48. }
  49.  
  50. void OnBlockAction(Player player, Vector3 blockPos, BlockValue block, bool placing)
  51. {
  52. if (!IsInSafezone(blockPos)) return;
  53.  
  54. if (player.PermissionLevel < config.requiredPermissionLevel) // block low-permission players
  55. {
  56. GameManager.Instance.ChatMessageToPlayer(player, "You cannot build or destroy blocks in safezones!");
  57. CancelBlockAction(player, blockPos, placing);
  58. }
  59. else if (!adminBuildMode) // block high-permission players if mode off
  60. {
  61. GameManager.Instance.ChatMessageToPlayer(player, "Safezone restrictions active. Toggle admin build mode to modify blocks.");
  62. CancelBlockAction(player, blockPos, placing);
  63. }
  64. // else: player can build/destroy freely
  65. }
  66.  
  67. bool IsInSafezone(Vector3 position)
  68. {
  69. // Replace with your safezone check logic
  70. return SafezoneManager.IsPositionInSafezone(position);
  71. }
  72.  
  73. void CancelBlockAction(Player player, Vector3 blockPos, bool placing)
  74. {
  75. if (placing)
  76. player.CancelBlockPlacement(blockPos);
  77. else
  78. player.CancelBlockDestruction(blockPos);
  79. }
  80.  
  81. [Serializable]
  82. public class Config
  83. {
  84. public int requiredPermissionLevel = 100;
  85. public string adminBuildCommand = "#adminbuild";
  86. public bool notifyAdmin = true;
  87. public string enableMessage = "Admin Build Mode is now ENABLED. You can build in safezones.";
  88. public string disable
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment