• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SimplyVanilla / SimplyPerms / #18

11 Mar 2024 09:36PM UTC coverage: 26.178% (-2.1%) from 28.261%
#18

push

github

web-flow
Fix velocity crash #3 (#10)

* Fixed [Velocity crash](https://gist.github.com/Netherwhal/5e37bd8a1656dbb9ac8cc88530144a65) happening when users in list are null

* Added forced stack trace to individuate error on Velocity restart

* Removed internal static list and reworked constructor

* Created UsersManager to keep track of loaded users

* Added usersManager field

* Added addUser method

* Updated some methods to use users manager

* Updated to use users manager to retrieve users

* Updated SimplePermProvider

1 of 24 new or added lines in 4 files covered. (4.17%)

1 existing line in 1 file now uncovered.

50 of 191 relevant lines covered (26.18%)

0.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/net/simplyvanilla/simplyperms/SimplyPerms.java
1
package net.simplyvanilla.simplyperms;
2

3
import com.google.inject.Inject;
4
import com.velocitypowered.api.event.Subscribe;
5
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
6
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
7
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
8
import com.velocitypowered.api.plugin.Plugin;
9
import com.velocitypowered.api.plugin.annotation.DataDirectory;
10
import com.velocitypowered.api.proxy.ProxyServer;
11
import net.simplyvanilla.simplyperms.groups.Group;
12
import net.simplyvanilla.simplyperms.groups.GroupYAMLParser;
13
import net.simplyvanilla.simplyperms.listeners.CommandListener;
14
import net.simplyvanilla.simplyperms.users.User;
15
import net.simplyvanilla.simplyperms.users.UserYAMLParser;
16
import net.simplyvanilla.simplyperms.users.UsersManager;
17
import net.simplyvanilla.simplyperms.utils.GroupUtils;
18
import it.fulminazzo.yamlparser.configuration.ConfigurationSection;
19
import it.fulminazzo.yamlparser.configuration.FileConfiguration;
20
import it.fulminazzo.yamlparser.utils.FileUtils;
21
import lombok.Getter;
22
import org.slf4j.Logger;
23

24
import java.io.File;
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.nio.file.Path;
28
import java.util.ArrayList;
29
import java.util.List;
30

31
@Plugin(
32
        id = "simplyperms",
33
        name = "SimplyPerms",
34
        version = "1.0",
35
        url = "https://github.com/SimplyVanilla/SimplyPerms",
36
        description = "A simple Velocity plugin to manage permissions on your server via config.yml.",
37
        authors = {"Simply Vanilla"}
38
)
39
@Getter
40
public class SimplyPerms {
41
    @Getter
×
42
    private static SimplyPerms plugin;
43
    private final ProxyServer proxyServer;
×
44
    private final Logger logger;
×
45
    private final File dataDirectory;
×
46

47
    private FileConfiguration configuration;
×
NEW
48
    private UsersManager usersManager;
×
49

50
    static {
51
        FileConfiguration.addParsers(new GroupYAMLParser());
×
52
        FileConfiguration.addParsers(new UserYAMLParser());
×
53
    }
×
54

55
    @Inject
56
    public SimplyPerms(final ProxyServer proxyServer, final Logger logger, final @DataDirectory Path dataDirectory) {
×
57
        plugin = this;
×
58
        this.proxyServer = proxyServer;
×
59
        this.logger = logger;
×
60
        this.dataDirectory = dataDirectory.toFile();
×
61
    }
×
62

63
    @Subscribe
64
    public void onEnable(final ProxyInitializeEvent event) {
65
        this.configuration = loadConfiguration("config.yml");
×
66

NEW
67
        this.usersManager = new UsersManager();
×
68

69
        loadGroups();
×
70
        loadUsers();
×
71

72
        this.proxyServer.getEventManager().register(this, new CommandListener(this));
×
73
    }
×
74

75
    @Subscribe
76
    public void onDisable(final ProxyShutdownEvent event) {
77
        unloadGroups();
×
78
        unloadUsers();
×
79
    }
×
80

81
    @Subscribe
82
    public void on(PermissionsSetupEvent event) {
NEW
83
        event.setProvider(new SimplePermProvider(this));
×
84
    }
×
85

86
    public List<String> getAllowedCommands() {
87
        List<String> commands = this.configuration.getStringList("allowed-commands");
×
88
        if (commands == null) commands = new ArrayList<>();
×
89
        return commands;
×
90
    }
91

92
    private FileConfiguration loadConfiguration(final String configName) {
93
        File file = new File(this.dataDirectory, configName);
×
94
        if (!file.exists())
×
95
            try {
96
                InputStream stream = SimplyPerms.class.getResourceAsStream(configName);
×
97
                if (stream == null) stream = SimplyPerms.class.getResourceAsStream("/" + configName);
×
98
                if (stream == null) throw new NullPointerException("Could not find configuration file: " + configName);
×
99
                FileUtils.writeToFile(file, stream);
×
100
                stream.close();
×
101
            } catch (IOException e) {
×
102
                throw new RuntimeException(e);
×
103
            }
×
104
        return new FileConfiguration(file);
×
105
    }
106

107
    private void loadGroups() {
108
        GroupUtils.loadGroups(this.configuration);
×
109
    }
×
110

111
    private void loadUsers() {
112
        final ConfigurationSection usersSection = this.configuration.getConfigurationSection("users");
×
113
        if (usersSection != null)
×
114
            for (final String key : usersSection.getKeys()) {
×
NEW
115
                this.usersManager.addUser(usersSection.get(key, User.class));
×
116
            }
×
117
    }
×
118

119
    private void unloadGroups() {
120
        Group.clearGroups();
×
121
    }
×
122

123
    private void unloadUsers() {
NEW
124
        this.usersManager.clearUsers();
×
125
    }
×
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc