mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 00:19:24 +00:00
implement antigrief
This commit is contained in:
@@ -102,7 +102,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onInteractBlock(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
@@ -121,7 +121,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onInteractEntity(PlayerInteractAtEntityEvent event) {
|
||||
EntityType type = event.getRightClicked().getType();
|
||||
if (entities.contains(type)) {
|
||||
@@ -135,7 +135,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPlaceBlock(BlockPlaceEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if (blocks.contains(block.getType())) {
|
||||
@@ -151,7 +151,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onBreakBlock(BlockBreakEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if (blocks.contains(block.getType())) {
|
||||
@@ -215,7 +215,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onTrampling(EntityChangeBlockEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if (block.getType() == Material.FARMLAND && event.getTo() == Material.DIRT) {
|
||||
@@ -227,13 +227,13 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onMoistureChange(MoistureChangeEvent event) {
|
||||
if (ConfigManager.disableMoistureMechanic())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
||||
if (world.isEmpty()){
|
||||
@@ -248,7 +248,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
||||
if (world.isEmpty()){
|
||||
@@ -294,7 +294,7 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onDispenser(BlockDispenseEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if (!(block.getBlockData() instanceof org.bukkit.block.data.type.Dispenser directional)) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package net.momirealms.customcrops.api.core;
|
||||
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.core.block.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerType;
|
||||
@@ -25,11 +24,18 @@ import net.momirealms.customcrops.common.util.Key;
|
||||
|
||||
public class SimpleRegistryAccess implements RegistryAccess {
|
||||
|
||||
private BukkitCustomCropsPlugin plugin;
|
||||
private boolean frozen;
|
||||
private static SimpleRegistryAccess instance;
|
||||
|
||||
public SimpleRegistryAccess(BukkitCustomCropsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
private SimpleRegistryAccess() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static SimpleRegistryAccess getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new SimpleRegistryAccess();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
|
||||
@@ -326,13 +326,19 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
||||
return;
|
||||
}
|
||||
|
||||
int pointToAdd = 1;
|
||||
for (GrowCondition growCondition : config.growConditions()) {
|
||||
if (growCondition.isMet(context)) {
|
||||
pointToAdd = growCondition.pointToAdd();
|
||||
break;
|
||||
int pointToAdd = 0;
|
||||
GrowCondition[] growConditions = config.growConditions();
|
||||
if (growConditions.length == 0) {
|
||||
pointToAdd = 1;
|
||||
} else {
|
||||
for (GrowCondition growCondition : config.growConditions()) {
|
||||
if (growCondition.isMet(context)) {
|
||||
pointToAdd = growCondition.pointToAdd();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pointToAdd == 0) return;
|
||||
|
||||
Optional<CustomCropsBlockState> optionalState = world.getBlockState(location.add(0,-1,0));
|
||||
if (optionalState.isPresent()) {
|
||||
|
||||
Reference in New Issue
Block a user