Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Unrelated code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
literalplus committed Jan 22, 2018
1 parent 077be30 commit ecf6cad
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CommandBlockerPlugin extends JavaPlugin implements Listener {

//Create plugin version from manifest (see cbu-bootstrap/pom.xml -> maven-jar-plugin,buildnumber-maven-plugin for details)
//Don't need to read this every time since we don't need the individual properties anyway --> performance
public static String PLUGIN_VERSION_STRING = PluginVersion.ofClass(CommandBlockerPlugin.class).toString();
public static final String PLUGIN_VERSION_STRING = PluginVersion.ofClass(CommandBlockerPlugin.class).toString();

private ConfigAdapter configAdapter;
private SpigotAliasResolver aliasResolver = new SpigotAliasResolver(this);
Expand Down Expand Up @@ -103,7 +103,7 @@ public void run() {
}

private ConfigAdapter createConfig() {
if(getServer().getPluginManager().getPlugin("Yamler") != null) {
if (getServer().getPluginManager().getPlugin("Yamler") != null) {
return new CBUConfig(new File(getDataFolder(), "config.yml"));
} else {
getLogger().warning("It is recommended that you install Yamler, because that allows the config to be a lot " +
Expand All @@ -121,8 +121,8 @@ private ConfigAdapter createConfig() {
* @return Whether {@code sender} can execute {@code command}, not taking aliases into account.
*/
private boolean canExecute(final CommandSender sender, final String command) {
if (configAdapter.isBlocked(command)){
if (!sender.hasPermission(getConfigAdapter().getBypassPermission())){
if (configAdapter.isBlocked(command)) {
if (!sender.hasPermission(getConfigAdapter().getBypassPermission())) {
sendErrorMessageIfEnabled(sender, command);
return false;
} else {
Expand All @@ -142,7 +142,7 @@ public void sendTabErrorMessageIfEnabled(final CommandSender target) {
}

private void sendBypassMessageIfEnabled(final CommandSender target, final String command) {
if(getConfigAdapter().isNotifyBypass()) {
if (getConfigAdapter().isNotifyBypass()) {
target.sendMessage(
unescapeCommandMessage(getConfigAdapter().getBypassMessage(), target, command)
);
Expand Down Expand Up @@ -174,14 +174,17 @@ private String unescapeCommandMessage(final String message, final CommandSender
* @param chatMessage The message written, including the slash.
*/
public void handleEvent(Cancellable evt, CommandSender sender, String chatMessage) {
if (chatMessage.startsWith("/") && !canExecute(sender, CommandHelper.getRawCommand(chatMessage))) {
boolean executionCancelled = chatMessage.startsWith("/") &&
!canExecute(sender, CommandHelper.getRawCommand(chatMessage));
if (executionCancelled) {
evt.setCancelled(true);
}
}

/**
* Returns the current config adapter used by the plugin.
* <b>Warning:</b> The adapter might be replaced at any time, so make sure to always get the latest one!
*
* @return the plugin's current config adapter
*/
public ConfigAdapter getConfigAdapter() {
Expand All @@ -195,8 +198,9 @@ public ConfigAdapter getConfigAdapter() {
* If the current config file is invalid, an exception is thrown and the adapter is not replaced.
* Note that this method doesn't work with {@link SpigotCBUConfig} since Bukkit's configuration API doesn't allow
* handling of syntax errors.
*
* @throws InvalidConfigException Propagated from {@link CBUConfig#initialize()} - If you get this, you can
* safely assume that thew adapter has not been replaced.
* safely assume that thew adapter has not been replaced.
*/
public void replaceConfigAdapter() throws InvalidConfigException {
ConfigAdapter newAdapter = createConfig();
Expand Down

0 comments on commit ecf6cad

Please sign in to comment.