Ayuto

Getting GameRules

Nov 18th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. # =============================================================================
  2. # >> IMPORTS
  3. # =============================================================================
  4. # Source.Python Imports
  5. #   Memory
  6. from memory import make_object
  7. #   Entities
  8. from entities.entity import BaseEntity
  9. from entities.factories import factory_dictionary
  10.  
  11.  
  12. # =============================================================================
  13. # >> FUNCTIONS
  14. # =============================================================================
  15. def find_gamerules_proxy_name():
  16.     """Tries to find the gamerules proxy name (e. g. ``cs_gamerules``).
  17.  
  18.    :raise ValueError:
  19.        Raised if the gamerules proxy name wasn't found.
  20.    :rtype: str
  21.    """
  22.     for classname in factory_dictionary:
  23.         if 'gamerules' not in classname:
  24.             continue
  25.  
  26.         return classname
  27.  
  28.     raise ValueError('Unable to find gamerules proxy name.')
  29.  
  30. def find_gamerules():
  31.     """Tries to find the gamerules instance.
  32.  
  33.    :rtype: Pointer
  34.    :raise ValueError:
  35.        Raised if the gamerules instance wasn't found.
  36.    """
  37.     proxy = BaseEntity.find_or_create(find_gamerules_proxy_name())
  38.     cls = proxy.server_class
  39.     while cls:
  40.         for prop in cls.table:
  41.             if 'gamerules_data' not in prop.name:
  42.                 continue
  43.  
  44.             return prop.data_table_proxy_function(None, None, None, None, 0)
  45.  
  46.         cls = cls.next
  47.  
  48.     raise ValueError('Unable to find gamerules.')
Advertisement
Add Comment
Please, Sign In to add comment