9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-25 09:59:20 +00:00
This commit is contained in:
Xiao-MoMi
2023-01-20 02:47:07 +08:00
parent 25e28963e6
commit 4278da59ec
7 changed files with 74 additions and 2 deletions

View File

@@ -361,6 +361,13 @@ public class MainConfig {
hookMessage("BentoBox");
}
}
if (config.getBoolean("integration.IridiumSkyblock",false)){
if (Bukkit.getPluginManager().getPlugin("IridiumSkyblock") == null) Log.warn("Failed to initialize IridiumSkyblock!");
else {
antiGriefs.add(new IridiumSkyblockHook());
hookMessage("IridiumSkyblock");
}
}
if (config.getBoolean("integration.AureliumSkills")) {
if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!");

View File

@@ -0,0 +1,34 @@
package net.momirealms.customcrops.integrations.protection;
import com.iridium.iridiumskyblock.PermissionType;
import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import net.momirealms.customcrops.integrations.AntiGrief;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.Optional;
public class IridiumSkyblockHook implements AntiGrief {
private final IridiumSkyblockAPI api;
public IridiumSkyblockHook() {
this.api = IridiumSkyblockAPI.getInstance();
}
@Override
public boolean canBreak(Location location, Player player) {
Optional<Island> island = api.getIslandViaLocation(location);
User user = api.getUser(player);
return island.map(value -> api.getIslandPermission(value, user, PermissionType.BLOCK_BREAK)).orElse(true);
}
@Override
public boolean canPlace(Location location, Player player) {
Optional<Island> island = api.getIslandViaLocation(location);
User user = api.getUser(player);
return island.map(value -> api.getIslandPermission(value, user, PermissionType.BLOCK_PLACE)).orElse(true);
}
}

View File

@@ -287,6 +287,13 @@ public class CropManager extends Function {
});
}
public void dry(Location potLoc) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.removeBlock(potLoc);
customInterface.placeNoteBlock(potLoc, BasicItemConfig.dryPot);
});
}
public void makePotWet(Location potLoc) {
String potID = customInterface.getBlockID(potLoc);
if (potID == null) return;
@@ -485,6 +492,13 @@ public class CropManager extends Function {
if (potID == null) return true;
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
if (certainGrow && !hasWater(potLoc)) {
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
dry(potLoc);
certainGrow = false;
}
}
if (MainConfig.dryMakesCropDead && !certainGrow && Math.random() < MainConfig.dryDeadChance) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);
@@ -506,6 +520,13 @@ public class CropManager extends Function {
return false;
}
private boolean hasWater(Location potLoc) {
World world = potLoc.getWorld();
CustomWorld customWorld = customWorlds.get(world);
if (customWorld == null) return false;
return customWorld.isPotWet(potLoc);
}
public boolean itemFrameGrowJudge(Location location, GrowingCrop growingCrop) {
Crop crop = CropConfig.CROPS.get(growingCrop.getType());
@@ -550,6 +571,13 @@ public class CropManager extends Function {
if (potID == null) return true;
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
if (certainGrow && !hasWater(potLoc)) {
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
dry(potLoc);
certainGrow = false;
}
}
if (MainConfig.dryMakesCropDead && !certainGrow && Math.random() < MainConfig.dryDeadChance) {
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
return true;

View File

@@ -598,6 +598,7 @@ public class CustomWorld {
watered.remove(MiscUtils.getSimpleLocation(potLoc));
}
public void setPlayerWatered(Location potLoc) {
setPotWet(potLoc);
playerWatered.add(MiscUtils.getSimpleLocation(potLoc));
}