mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 08:29:35 +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()) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class VersionHelper {
|
||||
URL url = new URL("https://api.polymart.org/v1/getResourceInfoSimple/?resource_id=2625&key=version");
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(60000);
|
||||
conn.setReadTimeout(30000);
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
String newest = new BufferedReader(new InputStreamReader(inputStream)).readLine();
|
||||
String current = plugin.getPluginVersion();
|
||||
|
||||
@@ -28,7 +28,7 @@ mojang_brigadier_version=1.0.18
|
||||
bstats_version=3.0.2
|
||||
geantyref_version=1.3.15
|
||||
caffeine_version=3.1.8
|
||||
rtag_version=6290733498
|
||||
rtag_version=1.5.6
|
||||
exp4j_version=0.4.8
|
||||
placeholder_api_version=2.11.6
|
||||
anti_grief_version=0.12
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customcrops.bukkit;
|
||||
|
||||
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.core.ConfigManager;
|
||||
import net.momirealms.customcrops.api.core.SimpleRegistryAccess;
|
||||
@@ -86,7 +87,7 @@ public class BukkitCustomCropsPluginImpl extends BukkitCustomCropsPlugin {
|
||||
this.logger = new JavaPluginLogger(getBoostrap().getLogger());
|
||||
this.classPathAppender = new ReflectionClassPathAppender(this);
|
||||
this.dependencyManager = new DependencyManagerImpl(this);
|
||||
this.registryAccess = new SimpleRegistryAccess(this);
|
||||
this.registryAccess = SimpleRegistryAccess.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,29 +177,40 @@ public class BukkitCustomCropsPluginImpl extends BukkitCustomCropsPlugin {
|
||||
boolean downloadFromPolymart = polymart.equals("1");
|
||||
boolean downloadFromBBB = buildByBit.equals("true");
|
||||
|
||||
this.getScheduler().sync().runLater(() -> {
|
||||
getPluginLogger().info("CustomCrops Registry has been frozen");
|
||||
((SimpleRegistryAccess) registryAccess).freeze();
|
||||
this.reload();
|
||||
if (ConfigManager.metrics()) new Metrics((JavaPlugin) getBoostrap(), 16593);
|
||||
if (ConfigManager.checkUpdate()) {
|
||||
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
||||
String link;
|
||||
if (downloadFromPolymart) {
|
||||
link = "https://polymart.org/resource/2625/";
|
||||
} else if (downloadFromBBB) {
|
||||
link = "https://builtbybit.com/resources/36363/";
|
||||
} else {
|
||||
link = "https://github.com/Xiao-MoMi/Custom-Crops/";
|
||||
}
|
||||
if (!result) {
|
||||
this.getPluginLogger().info("You are using the latest version.");
|
||||
} else {
|
||||
this.getPluginLogger().warn("Update is available: " + link);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 1, null);
|
||||
((SimpleRegistryAccess) registryAccess).freeze();
|
||||
this.reload();
|
||||
if (ConfigManager.metrics()) new Metrics((JavaPlugin) getBoostrap(), 16593);
|
||||
if (ConfigManager.checkUpdate()) {
|
||||
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
||||
String link;
|
||||
if (downloadFromPolymart) {
|
||||
link = "https://polymart.org/resource/2625/";
|
||||
} else if (downloadFromBBB) {
|
||||
link = "https://builtbybit.com/resources/36363/";
|
||||
} else {
|
||||
link = "https://github.com/Xiao-MoMi/Custom-Crops/";
|
||||
}
|
||||
if (!result) {
|
||||
this.getPluginLogger().info("You are using the latest version.");
|
||||
} else {
|
||||
this.getPluginLogger().warn("Update is available: " + link);
|
||||
}
|
||||
});
|
||||
}
|
||||
// delayed init task
|
||||
if (VersionHelper.isFolia()) {
|
||||
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
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customcrops.bukkit.item;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.momirealms.antigrieflib.AntiGriefLib;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.core.*;
|
||||
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.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -68,6 +70,7 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
private final HashMap<String, ItemProvider> itemProviders = new HashMap<>();
|
||||
private ItemProvider[] itemDetectArray = new ItemProvider[0];
|
||||
private final BukkitItemFactory factory;
|
||||
private AntiGriefLib antiGriefLib;
|
||||
|
||||
public BukkitItemManager(BukkitCustomCropsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -82,6 +85,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
this.factory = BukkitItemFactory.create(plugin);
|
||||
}
|
||||
|
||||
public void setAntiGriefLib(AntiGriefLib antiGriefLib) {
|
||||
this.antiGriefLib = antiGriefLib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.resetItemDetectionOrder();
|
||||
@@ -398,6 +405,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (antiGriefLib != null && !antiGriefLib.canInteract(player, block.getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String itemID = id(itemInHand);
|
||||
CustomCropsWorld<?> world = optionalWorld.get();
|
||||
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;
|
||||
}
|
||||
|
||||
if (antiGriefLib != null && !antiGriefLib.canInteract(player, location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String itemID = id(itemInHand);
|
||||
CustomCropsWorld<?> world = optionalWorld.get();
|
||||
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;
|
||||
}
|
||||
|
||||
if (antiGriefLib != null && !antiGriefLib.canBreak(player, location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String itemID = id(itemInHand);
|
||||
CustomCropsWorld<?> world = optionalWorld.get();
|
||||
WrappedBreakEvent wrapped = new WrappedBreakEvent(player, null, world, location, brokenID, itemInHand, itemID, BreakReason.BREAK, event);
|
||||
@@ -503,6 +522,10 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (antiGriefLib != null && !antiGriefLib.canPlace(player, location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomCropsWorld<?> world = optionalWorld.get();
|
||||
Pos3 pos3 = Pos3.from(location);
|
||||
Optional<CustomCropsBlockState> optionalState = world.getBlockState(pos3);
|
||||
|
||||
@@ -16,28 +16,4 @@ softdepend:
|
||||
- RealisticSeasons
|
||||
- AdvancedSeasons
|
||||
- SlimeWorldManager
|
||||
- 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
|
||||
- MythicMobs
|
||||
Reference in New Issue
Block a user