Circular Reference Alternative

Discussion in 'Plugin Development' started by OMGitzFROST, Oct 3, 2019.

Thread Status:
Not open for further replies.
  1. Offline


    Currently, I am trying to create two Task Operators. A SettingOperator class and a MessageOperator class. Below I provided a background as to what I am trying to achieve with both classes.

    Purpose of my SettingOperator - Creates player preferences such as a normal desktop application and stores them to a file in the data folder. These preferences can be updated via player commands, configuration files, etc.

    Purpose of my MessageOperator - Handles logging localized messages and configures the plugins current locale (as long as it is currently supported by the plugin otherwise defaults to English).

    Currently, I am initializing both operators as such on the onEnable() Method
    onEnable() Method (open)
    private static PluginName instance;
    private SettingOperator setting;
    private MessageOperator message;
    public void onEnable() {
        instance = this;
        setting = new SettingOperator(this);
        message = new MessageOperator(this);
    @Contract (pure = true)
    public static AdminConsole getInstance() {
        return instance;
    public static SettingOperator getSettingOP() {
        return setting;
    public static MessageOperator getMessageOP() {
        return message;

    Then I am trying to call the references to both classes because both use each other interchangeably.
    Operator Classes (open)
    *** These Classes Are Into Separate Files, but for the sake of easy readability, I put them in one spoiler ***
    public class SettingOperator {
        private final MessageOperator message = PluginName.getMessageOP();
    public class MessageOperator {
        private final SettingOperator message = PluginName.getSettingOP();

    Is there a better way of doing this, because I tend to catch an overflow exception and does not tell me what kind of problem it is causing? Any help is appreciated and would love some constructive criticism.
    Last edited: Oct 3, 2019
  2. Offline

    timtower Administrator Administrator Moderator

    @OMGitzFROST Give them a constructor to the plugin. Then add a getter.
    No static at all.
  3. Offline


    You could try setting those fields in the onEnable instead of within those classes. That way, you have control over when those variables are set.
Thread Status:
Not open for further replies.

Share This Page