Skip to content

Commit

Permalink
Removed redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
sarhatabaot committed Nov 19, 2024
1 parent 73b41fd commit a7abb7f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public boolean isGlobalEnabled() {
return globalEnabled;
}

public boolean isGlobalDisabled() {
return !globalEnabled;
}

public boolean doesNotNeedUpdate() {
return !needsUpdate;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,27 @@ public BlockBreakListener(FarmAssistReboot plugin) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (!plugin.isGlobalEnabled()) {
if (plugin.isGlobalDisabled()) {
debug("Plugin is globally disabled.");
return;
}

if (this.plugin.getDisabledPlayerList().contains(event.getPlayer().getUniqueId())) {
debug("Player %s with uuid %s has the far functionality disabled.", event.getPlayer().getName(), event.getPlayer().getUniqueId());
return;
}


if (!Crop.getCropList().contains(event.getBlock().getType())) {
debug(Debug.OnBlockBreak.CROP_LIST_NO_MATERIAL, event.getBlock().getType().name());
return;
}


if (FarmAssistConfig.USE_PERMISSIONS && !hasMaterialPermission(event)) {
final String permission = Permissions.BASE_PERMISSION + event.getBlock().getType().name();
debug(Debug.OnBlockBreak.PLAYER_NO_PERMISSION, event.getPlayer().getDisplayName(), permission);
return;
}

if (Util.isWorldEnabled(event.getPlayer().getWorld())) {
applyReplant(event);
if (!Util.isWorldEnabled(event.getPlayer().getWorld())) {
return;
}

applyReplant(event);
}

private boolean hasMaterialPermission(@NotNull BlockBreakEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.github.sarhatabaot.farmassistreboot.listeners;

import com.cryptomorin.xseries.XMaterial;
import com.github.sarhatabaot.farmassistreboot.Crop;
import com.github.sarhatabaot.farmassistreboot.FarmAssistReboot;
import com.github.sarhatabaot.farmassistreboot.Util;
import com.github.sarhatabaot.farmassistreboot.config.FarmAssistConfig;
import com.github.sarhatabaot.farmassistreboot.messages.Debug;
import com.github.sarhatabaot.farmassistreboot.messages.Permissions;
import com.google.common.collect.ImmutableList;
import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
Expand All @@ -18,10 +15,13 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.jetbrains.annotations.NotNull;

@RequiredArgsConstructor
public class BlockBreakListener implements Listener {
private final FarmAssistReboot plugin;

public BlockBreakListener(FarmAssistReboot plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (!plugin.isGlobalEnabled()) {
Expand Down

0 comments on commit a7abb7f

Please sign in to comment.