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) {
|
public void onInteractBlock(PlayerInteractEvent event) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||||
return;
|
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) {
|
public void onInteractEntity(PlayerInteractAtEntityEvent event) {
|
||||||
EntityType type = event.getRightClicked().getType();
|
EntityType type = event.getRightClicked().getType();
|
||||||
if (entities.contains(type)) {
|
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) {
|
public void onPlaceBlock(BlockPlaceEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (blocks.contains(block.getType())) {
|
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) {
|
public void onBreakBlock(BlockBreakEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (blocks.contains(block.getType())) {
|
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) {
|
public void onTrampling(EntityChangeBlockEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (block.getType() == Material.FARMLAND && event.getTo() == Material.DIRT) {
|
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) {
|
public void onMoistureChange(MoistureChangeEvent event) {
|
||||||
if (ConfigManager.disableMoistureMechanic())
|
if (ConfigManager.disableMoistureMechanic())
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||||
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
||||||
if (world.isEmpty()){
|
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) {
|
public void onPistonRetract(BlockPistonRetractEvent event) {
|
||||||
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
Optional<CustomCropsWorld<?>> world = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(event.getBlock().getWorld());
|
||||||
if (world.isEmpty()){
|
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) {
|
public void onDispenser(BlockDispenseEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (!(block.getBlockData() instanceof org.bukkit.block.data.type.Dispenser directional)) {
|
if (!(block.getBlockData() instanceof org.bukkit.block.data.type.Dispenser directional)) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.api.core;
|
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.block.CustomCropsBlock;
|
||||||
import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
||||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerType;
|
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 {
|
public class SimpleRegistryAccess implements RegistryAccess {
|
||||||
|
|
||||||
private BukkitCustomCropsPlugin plugin;
|
|
||||||
private boolean frozen;
|
private boolean frozen;
|
||||||
|
private static SimpleRegistryAccess instance;
|
||||||
|
|
||||||
public SimpleRegistryAccess(BukkitCustomCropsPlugin plugin) {
|
private SimpleRegistryAccess() {
|
||||||
this.plugin = plugin;
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimpleRegistryAccess getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new SimpleRegistryAccess();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void freeze() {
|
public void freeze() {
|
||||||
|
|||||||
@@ -326,13 +326,19 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pointToAdd = 1;
|
int pointToAdd = 0;
|
||||||
for (GrowCondition growCondition : config.growConditions()) {
|
GrowCondition[] growConditions = config.growConditions();
|
||||||
if (growCondition.isMet(context)) {
|
if (growConditions.length == 0) {
|
||||||
pointToAdd = growCondition.pointToAdd();
|
pointToAdd = 1;
|
||||||
break;
|
} 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));
|
Optional<CustomCropsBlockState> optionalState = world.getBlockState(location.add(0,-1,0));
|
||||||
if (optionalState.isPresent()) {
|
if (optionalState.isPresent()) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class VersionHelper {
|
|||||||
URL url = new URL("https://api.polymart.org/v1/getResourceInfoSimple/?resource_id=2625&key=version");
|
URL url = new URL("https://api.polymart.org/v1/getResourceInfoSimple/?resource_id=2625&key=version");
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
conn.setConnectTimeout(10000);
|
conn.setConnectTimeout(10000);
|
||||||
conn.setReadTimeout(60000);
|
conn.setReadTimeout(30000);
|
||||||
InputStream inputStream = conn.getInputStream();
|
InputStream inputStream = conn.getInputStream();
|
||||||
String newest = new BufferedReader(new InputStreamReader(inputStream)).readLine();
|
String newest = new BufferedReader(new InputStreamReader(inputStream)).readLine();
|
||||||
String current = plugin.getPluginVersion();
|
String current = plugin.getPluginVersion();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ mojang_brigadier_version=1.0.18
|
|||||||
bstats_version=3.0.2
|
bstats_version=3.0.2
|
||||||
geantyref_version=1.3.15
|
geantyref_version=1.3.15
|
||||||
caffeine_version=3.1.8
|
caffeine_version=3.1.8
|
||||||
rtag_version=6290733498
|
rtag_version=1.5.6
|
||||||
exp4j_version=0.4.8
|
exp4j_version=0.4.8
|
||||||
placeholder_api_version=2.11.6
|
placeholder_api_version=2.11.6
|
||||||
anti_grief_version=0.12
|
anti_grief_version=0.12
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.bukkit;
|
package net.momirealms.customcrops.bukkit;
|
||||||
|
|
||||||
|
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||||
import net.momirealms.customcrops.api.core.ConfigManager;
|
import net.momirealms.customcrops.api.core.ConfigManager;
|
||||||
import net.momirealms.customcrops.api.core.SimpleRegistryAccess;
|
import net.momirealms.customcrops.api.core.SimpleRegistryAccess;
|
||||||
@@ -86,7 +87,7 @@ public class BukkitCustomCropsPluginImpl extends BukkitCustomCropsPlugin {
|
|||||||
this.logger = new JavaPluginLogger(getBoostrap().getLogger());
|
this.logger = new JavaPluginLogger(getBoostrap().getLogger());
|
||||||
this.classPathAppender = new ReflectionClassPathAppender(this);
|
this.classPathAppender = new ReflectionClassPathAppender(this);
|
||||||
this.dependencyManager = new DependencyManagerImpl(this);
|
this.dependencyManager = new DependencyManagerImpl(this);
|
||||||
this.registryAccess = new SimpleRegistryAccess(this);
|
this.registryAccess = SimpleRegistryAccess.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,29 +177,40 @@ public class BukkitCustomCropsPluginImpl extends BukkitCustomCropsPlugin {
|
|||||||
boolean downloadFromPolymart = polymart.equals("1");
|
boolean downloadFromPolymart = polymart.equals("1");
|
||||||
boolean downloadFromBBB = buildByBit.equals("true");
|
boolean downloadFromBBB = buildByBit.equals("true");
|
||||||
|
|
||||||
this.getScheduler().sync().runLater(() -> {
|
((SimpleRegistryAccess) registryAccess).freeze();
|
||||||
getPluginLogger().info("CustomCrops Registry has been frozen");
|
this.reload();
|
||||||
((SimpleRegistryAccess) registryAccess).freeze();
|
if (ConfigManager.metrics()) new Metrics((JavaPlugin) getBoostrap(), 16593);
|
||||||
this.reload();
|
if (ConfigManager.checkUpdate()) {
|
||||||
if (ConfigManager.metrics()) new Metrics((JavaPlugin) getBoostrap(), 16593);
|
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
||||||
if (ConfigManager.checkUpdate()) {
|
String link;
|
||||||
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
if (downloadFromPolymart) {
|
||||||
String link;
|
link = "https://polymart.org/resource/2625/";
|
||||||
if (downloadFromPolymart) {
|
} else if (downloadFromBBB) {
|
||||||
link = "https://polymart.org/resource/2625/";
|
link = "https://builtbybit.com/resources/36363/";
|
||||||
} else if (downloadFromBBB) {
|
} else {
|
||||||
link = "https://builtbybit.com/resources/36363/";
|
link = "https://github.com/Xiao-MoMi/Custom-Crops/";
|
||||||
} else {
|
}
|
||||||
link = "https://github.com/Xiao-MoMi/Custom-Crops/";
|
if (!result) {
|
||||||
}
|
this.getPluginLogger().info("You are using the latest version.");
|
||||||
if (!result) {
|
} else {
|
||||||
this.getPluginLogger().info("You are using the latest version.");
|
this.getPluginLogger().warn("Update is available: " + link);
|
||||||
} else {
|
}
|
||||||
this.getPluginLogger().warn("Update is available: " + link);
|
});
|
||||||
}
|
}
|
||||||
});
|
// delayed init task
|
||||||
}
|
if (VersionHelper.isFolia()) {
|
||||||
}, 1, null);
|
Bukkit.getGlobalRegionScheduler().run(getBoostrap(), (scheduledTask) -> {
|
||||||
|
((SimpleRegistryAccess) registryAccess).freeze();
|
||||||
|
logger.info("Registry access has been frozen");
|
||||||
|
((BukkitItemManager) itemManager).setAntiGriefLib(AntiGriefLib.builder((JavaPlugin) getBoostrap()).silentLogs(true).ignoreOP(true).build());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTask(getBoostrap(), () -> {
|
||||||
|
((SimpleRegistryAccess) registryAccess).freeze();
|
||||||
|
logger.info("Registry access has been frozen");
|
||||||
|
((BukkitItemManager) itemManager).setAntiGriefLib(AntiGriefLib.builder((JavaPlugin) getBoostrap()).silentLogs(true).ignoreOP(true).build());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package net.momirealms.customcrops.bukkit.item;
|
|||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||||
import net.momirealms.customcrops.api.core.*;
|
import net.momirealms.customcrops.api.core.*;
|
||||||
import net.momirealms.customcrops.api.core.block.BreakReason;
|
import net.momirealms.customcrops.api.core.block.BreakReason;
|
||||||
@@ -52,6 +53,7 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -68,6 +70,7 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
private final HashMap<String, ItemProvider> itemProviders = new HashMap<>();
|
private final HashMap<String, ItemProvider> itemProviders = new HashMap<>();
|
||||||
private ItemProvider[] itemDetectArray = new ItemProvider[0];
|
private ItemProvider[] itemDetectArray = new ItemProvider[0];
|
||||||
private final BukkitItemFactory factory;
|
private final BukkitItemFactory factory;
|
||||||
|
private AntiGriefLib antiGriefLib;
|
||||||
|
|
||||||
public BukkitItemManager(BukkitCustomCropsPlugin plugin) {
|
public BukkitItemManager(BukkitCustomCropsPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -82,6 +85,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
this.factory = BukkitItemFactory.create(plugin);
|
this.factory = BukkitItemFactory.create(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAntiGriefLib(AntiGriefLib antiGriefLib) {
|
||||||
|
this.antiGriefLib = antiGriefLib;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
this.resetItemDetectionOrder();
|
this.resetItemDetectionOrder();
|
||||||
@@ -398,6 +405,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (antiGriefLib != null && !antiGriefLib.canInteract(player, block.getLocation())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String itemID = id(itemInHand);
|
String itemID = id(itemInHand);
|
||||||
CustomCropsWorld<?> world = optionalWorld.get();
|
CustomCropsWorld<?> world = optionalWorld.get();
|
||||||
WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.BLOCK, player, world, block.getLocation(), blockID, itemInHand, itemID, hand, blockFace, event);
|
WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.BLOCK, player, world, block.getLocation(), blockID, itemInHand, itemID, hand, blockFace, event);
|
||||||
@@ -412,6 +423,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (antiGriefLib != null && !antiGriefLib.canInteract(player, location)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String itemID = id(itemInHand);
|
String itemID = id(itemInHand);
|
||||||
CustomCropsWorld<?> world = optionalWorld.get();
|
CustomCropsWorld<?> world = optionalWorld.get();
|
||||||
WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.FURNITURE, player, world, location, furnitureID, itemInHand, itemID, hand, null, event);
|
WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.FURNITURE, player, world, location, furnitureID, itemInHand, itemID, hand, null, event);
|
||||||
@@ -442,6 +457,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (antiGriefLib != null && !antiGriefLib.canBreak(player, location)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String itemID = id(itemInHand);
|
String itemID = id(itemInHand);
|
||||||
CustomCropsWorld<?> world = optionalWorld.get();
|
CustomCropsWorld<?> world = optionalWorld.get();
|
||||||
WrappedBreakEvent wrapped = new WrappedBreakEvent(player, null, world, location, brokenID, itemInHand, itemID, BreakReason.BREAK, event);
|
WrappedBreakEvent wrapped = new WrappedBreakEvent(player, null, world, location, brokenID, itemInHand, itemID, BreakReason.BREAK, event);
|
||||||
@@ -503,6 +522,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (antiGriefLib != null && !antiGriefLib.canPlace(player, location)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CustomCropsWorld<?> world = optionalWorld.get();
|
CustomCropsWorld<?> world = optionalWorld.get();
|
||||||
Pos3 pos3 = Pos3.from(location);
|
Pos3 pos3 = Pos3.from(location);
|
||||||
Optional<CustomCropsBlockState> optionalState = world.getBlockState(pos3);
|
Optional<CustomCropsBlockState> optionalState = world.getBlockState(pos3);
|
||||||
|
|||||||
@@ -16,28 +16,4 @@ softdepend:
|
|||||||
- RealisticSeasons
|
- RealisticSeasons
|
||||||
- AdvancedSeasons
|
- AdvancedSeasons
|
||||||
- SlimeWorldManager
|
- SlimeWorldManager
|
||||||
- MythicMobs
|
- MythicMobs
|
||||||
- HuskClaims
|
|
||||||
- HuskTowns
|
|
||||||
- Residence
|
|
||||||
- BentoBox
|
|
||||||
- FabledSkyBlock
|
|
||||||
- CrashClaim
|
|
||||||
- GriefDefender
|
|
||||||
- GriefPrevention
|
|
||||||
- BentoBox
|
|
||||||
- IridiumSkyblock
|
|
||||||
- KingdomsX
|
|
||||||
- Landlord
|
|
||||||
- Lands
|
|
||||||
- PlotSquared
|
|
||||||
- ProtectionStones
|
|
||||||
- RedProtect
|
|
||||||
- Factions
|
|
||||||
- SuperiorSkyblock2
|
|
||||||
- Towny
|
|
||||||
- UltimateClaims
|
|
||||||
- UltimateClans
|
|
||||||
- uSkyBlock
|
|
||||||
- WorldGuard
|
|
||||||
- XClaim
|
|
||||||
Reference in New Issue
Block a user