mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 00:49:33 +00:00
res wg 兼容
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package net.momirealms.customcrops.Integrations;
|
||||||
|
|
||||||
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
|
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||||
|
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
||||||
|
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class ResidenceIntegrations {
|
||||||
|
public static boolean checkResBuild(Location location, CustomBlockInteractEvent event){
|
||||||
|
FlagPermissions.addFlag("build");
|
||||||
|
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||||
|
if(res!=null){
|
||||||
|
ResidencePermissions perms = res.getPermissions();
|
||||||
|
String playerName = event.getPlayer().getName();
|
||||||
|
boolean hasPermission = perms.playerHas(playerName, "build", true);
|
||||||
|
if(!hasPermission){
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean checkResHarvest(Location location, CustomBlockInteractEvent event){
|
||||||
|
FlagPermissions.addFlag("harvest");
|
||||||
|
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||||
|
if(res!=null){
|
||||||
|
ResidencePermissions perms = res.getPermissions();
|
||||||
|
String playerName = event.getPlayer().getName();
|
||||||
|
boolean hasPermission = perms.playerHas(playerName, "harvest", true);
|
||||||
|
if(!hasPermission){
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.momirealms.customcrops.Integrations;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
|
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class WorldGuardIntegrations {
|
||||||
|
public static boolean checkWGBuild(Player player, Location loc, CustomBlockInteractEvent event){
|
||||||
|
|
||||||
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
|
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BUILD)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean checkWGHarvest(Player player, Location loc, CustomBlockInteractEvent event){
|
||||||
|
|
||||||
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
|
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BLOCK_BREAK)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package net.momirealms.customcrops.listener;
|
package net.momirealms.customcrops.listener;
|
||||||
|
|
||||||
|
import com.bekvon.bukkit.residence.Residence;
|
||||||
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
|
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||||
|
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
||||||
import dev.lone.itemsadder.api.CustomStack;
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.DataManager.MaxSprinklersPerChunk;
|
import net.momirealms.customcrops.DataManager.MaxSprinklersPerChunk;
|
||||||
@@ -24,16 +28,16 @@ import java.util.List;
|
|||||||
|
|
||||||
public class RightClickBlock implements Listener {
|
public class RightClickBlock implements Listener {
|
||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void rightClickBlock(PlayerInteractEvent event){
|
public void rightClickBlock(PlayerInteractEvent event){
|
||||||
if(event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasItem()){
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
|
if(!event.hasItem()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) return;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack itemStack = event.getItem();
|
ItemStack itemStack = event.getItem();
|
||||||
|
//水壶加水
|
||||||
if(itemStack.getType() == Material.WOODEN_SWORD){
|
if(itemStack.getType() == Material.WOODEN_SWORD){
|
||||||
List<Block> lineOfSight = player.getLineOfSight(null, 3);
|
List<Block> lineOfSight = player.getLineOfSight(null, 3);
|
||||||
boolean hasWater = false;
|
boolean hasWater = false;
|
||||||
@@ -47,19 +51,30 @@ public class RightClickBlock implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
if(event.getBlockFace() != BlockFace.UP) return;
|
if(event.getBlockFace() != BlockFace.UP) return;
|
||||||
|
if(CustomStack.byItemStack(event.getItem()) == null) return;
|
||||||
|
|
||||||
if(CustomStack.byItemStack(event.getItem()) == null){
|
Location location = event.getClickedBlock().getLocation();
|
||||||
|
if(config.getBoolean("config.integration.residence")){
|
||||||
|
FlagPermissions.addFlag("build");
|
||||||
|
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||||
|
if(res!=null){
|
||||||
|
ResidencePermissions perms = res.getPermissions();
|
||||||
|
String playerName = event.getPlayer().getName();
|
||||||
|
boolean hasPermission = perms.playerHas(playerName, "build", true);
|
||||||
|
if(!hasPermission){
|
||||||
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//是否过高过低
|
||||||
if(event.getClickedBlock().getY() > config.getInt("config.height.max") || event.getClickedBlock().getY() < config.getInt("config.height.min")){
|
if(event.getClickedBlock().getY() > config.getInt("config.height.max") || event.getClickedBlock().getY() < config.getInt("config.height.min")){
|
||||||
MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.not-a-good-place"),player);
|
MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.not-a-good-place"),player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = event.getClickedBlock().getLocation();
|
|
||||||
|
|
||||||
if(CustomStack.byItemStack(event.getItem()).getNamespacedID().equalsIgnoreCase(config.getString("config.sprinkler-1-item"))){
|
if(CustomStack.byItemStack(event.getItem()).getNamespacedID().equalsIgnoreCase(config.getString("config.sprinkler-1-item"))){
|
||||||
if(MaxSprinklersPerChunk.maxSprinklersPerChunk(location)){
|
if(MaxSprinklersPerChunk.maxSprinklersPerChunk(location)){
|
||||||
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.reach-limit-sprinkler").replace("{Max}", config.getString("config.max-sprinklers")),player);
|
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.reach-limit-sprinkler").replace("{Max}", config.getString("config.max-sprinklers")),player);
|
||||||
@@ -83,6 +98,7 @@ public class RightClickBlock implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void addWater(ItemStack itemStack, Player player){
|
private void addWater(ItemStack itemStack, Player player){
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
if(CustomStack.byItemStack(itemStack)!= null){
|
if(CustomStack.byItemStack(itemStack)!= null){
|
||||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||||
if(customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-1")) ||
|
if(customStack.getNamespacedID().equalsIgnoreCase(config.getString("config.watering-can-1")) ||
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
|||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.DataManager.CropManager;
|
import net.momirealms.customcrops.DataManager.CropManager;
|
||||||
import net.momirealms.customcrops.DataManager.MaxCropsPerChunk;
|
import net.momirealms.customcrops.DataManager.MaxCropsPerChunk;
|
||||||
|
import net.momirealms.customcrops.Integrations.ResidenceIntegrations;
|
||||||
|
import net.momirealms.customcrops.Integrations.WorldGuardIntegrations;
|
||||||
import net.momirealms.customcrops.MessageManager;
|
import net.momirealms.customcrops.MessageManager;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@@ -21,8 +23,6 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class RightClickCustomBlock implements Listener {
|
public class RightClickCustomBlock implements Listener {
|
||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void rightClickCustomCrop(CustomBlockInteractEvent event){
|
public void rightClickCustomCrop(CustomBlockInteractEvent event){
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||||
@@ -31,7 +31,19 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
Block clickedBlock = event.getBlockClicked();
|
Block clickedBlock = event.getBlockClicked();
|
||||||
Location clickedBlockLocation = clickedBlock.getLocation();
|
Location clickedBlockLocation = clickedBlock.getLocation();
|
||||||
CustomBlock clickedCustomBlock = CustomBlock.byAlreadyPlaced(clickedBlock);
|
CustomBlock clickedCustomBlock = CustomBlock.byAlreadyPlaced(clickedBlock);
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
|
Player player = event.getPlayer();
|
||||||
if (event.getItem() == null) {
|
if (event.getItem() == null) {
|
||||||
|
if(config.getBoolean("config.integration.residence")){
|
||||||
|
if(ResidenceIntegrations.checkResHarvest(clickedBlockLocation, event)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(config.getBoolean("config.integration.worldguard")){
|
||||||
|
if(WorldGuardIntegrations.checkWGHarvest(player,clickedBlockLocation, event)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (clickedCustomBlock.getNamespacedID().contains("stage")){
|
if (clickedCustomBlock.getNamespacedID().contains("stage")){
|
||||||
if(clickedCustomBlock.getNamespacedID().equalsIgnoreCase(config.getString("config.dead-crop"))) return;
|
if(clickedCustomBlock.getNamespacedID().equalsIgnoreCase(config.getString("config.dead-crop"))) return;
|
||||||
String namespace = clickedCustomBlock.getNamespacedID().split(":")[0];
|
String namespace = clickedCustomBlock.getNamespacedID().split(":")[0];
|
||||||
@@ -47,16 +59,31 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//res兼容
|
||||||
|
if(config.getBoolean("config.integration.residence")){
|
||||||
|
if(ResidenceIntegrations.checkResBuild(clickedBlockLocation, event)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
}
|
||||||
|
|
||||||
|
//wg兼容
|
||||||
|
if(config.getBoolean("config.integration.worldguard")){
|
||||||
|
if(WorldGuardIntegrations.checkWGBuild(player,clickedBlockLocation, event)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
|
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
//右键的作物下方是否为自定义方块
|
||||||
if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))) != null && clickedBlock.getType() == Material.TRIPWIRE) {
|
if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))) != null && clickedBlock.getType() == Material.TRIPWIRE) {
|
||||||
|
//检测右键的方块下方是否为干燥的种植盆方块
|
||||||
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))) {
|
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))) {
|
||||||
|
//如果手中的是水桶,那么转干为湿
|
||||||
if (mainHandItem.getType() == Material.WATER_BUCKET) {
|
if (mainHandItem.getType() == Material.WATER_BUCKET) {
|
||||||
|
//扣除水桶
|
||||||
if(player.getGameMode() != GameMode.CREATIVE){
|
if(player.getGameMode() != GameMode.CREATIVE){
|
||||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||||
player.getInventory().addItem(new ItemStack(Material.BUCKET));
|
player.getInventory().addItem(new ItemStack(Material.BUCKET));
|
||||||
@@ -64,23 +91,29 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
CustomBlock.remove(clickedBlockLocation.clone().subtract(0, 1, 0));
|
CustomBlock.remove(clickedBlockLocation.clone().subtract(0, 1, 0));
|
||||||
CustomBlock.place(config.getString("config.watered-pot"), clickedBlockLocation.clone().subtract(0, 1, 0));
|
CustomBlock.place(config.getString("config.watered-pot"), clickedBlockLocation.clone().subtract(0, 1, 0));
|
||||||
}else if(mainHandItem.getType() == Material.WOODEN_SWORD){
|
}else if(mainHandItem.getType() == Material.WOODEN_SWORD){
|
||||||
waterPot(mainHandItem,player,clickedBlockLocation.clone().subtract(0,1,0));
|
waterPot(mainHandItem,player,clickedBlockLocation.clone().subtract(0,1,0),config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//检测右键的方块下方是否为湿润的种植盆方块
|
||||||
else if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))).getNamespacedID().equalsIgnoreCase(config.getString("config.watered-pot"))){
|
else if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation.clone().subtract(0,1,0))).getNamespacedID().equalsIgnoreCase(config.getString("config.watered-pot"))){
|
||||||
|
//如果是骨粉
|
||||||
if (mainHandItem.getType() == Material.BONE_MEAL){
|
if (mainHandItem.getType() == Material.BONE_MEAL){
|
||||||
|
//植物是否具有stage属性
|
||||||
if (clickedCustomBlock.getNamespacedID().contains("stage")){
|
if (clickedCustomBlock.getNamespacedID().contains("stage")){
|
||||||
String[] cropNameList = clickedCustomBlock.getNamespacedID().split("_");
|
String[] cropNameList = clickedCustomBlock.getNamespacedID().split("_");
|
||||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||||
|
//植物是否存在下一个stage
|
||||||
if (CustomBlock.getInstance(cropNameList[0] + "_" +cropNameList[1] +"_" + nextStage) != null){
|
if (CustomBlock.getInstance(cropNameList[0] + "_" +cropNameList[1] +"_" + nextStage) != null){
|
||||||
if(player.getGameMode() != GameMode.CREATIVE){
|
if(player.getGameMode() != GameMode.CREATIVE){
|
||||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||||
}
|
}
|
||||||
|
//骨粉的成功率
|
||||||
if (Math.random() < config.getDouble("config.bone-meal-chance")){
|
if (Math.random() < config.getDouble("config.bone-meal-chance")){
|
||||||
CustomBlock.remove(clickedBlockLocation);
|
CustomBlock.remove(clickedBlockLocation);
|
||||||
CustomBlock.place(cropNameList[0] + "_" +cropNameList[1] +"_" + nextStage,clickedBlockLocation);
|
CustomBlock.place(cropNameList[0] + "_" +cropNameList[1] +"_" + nextStage,clickedBlockLocation);
|
||||||
Particle particleSuccess = Particle.valueOf(config.getString("config.particle.success"));
|
Particle particleSuccess = Particle.valueOf(config.getString("config.particle.success"));
|
||||||
world.spawnParticle(particleSuccess, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
|
world.spawnParticle(particleSuccess, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
|
||||||
|
//使用骨粉是否消耗水分
|
||||||
if(config.getBoolean("config.bone-meal-consume-water")){
|
if(config.getBoolean("config.bone-meal-consume-water")){
|
||||||
CustomBlock.remove(clickedBlockLocation.clone().subtract(0,1,0));
|
CustomBlock.remove(clickedBlockLocation.clone().subtract(0,1,0));
|
||||||
CustomBlock.place(config.getString("config.pot"), clickedBlockLocation.clone().subtract(0,1,0));
|
CustomBlock.place(config.getString("config.pot"), clickedBlockLocation.clone().subtract(0,1,0));
|
||||||
@@ -94,8 +127,11 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)) != null && event.getBlockFace() == BlockFace.UP){
|
} else if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)) != null && event.getBlockFace() == BlockFace.UP){
|
||||||
|
//检测右键的方块是否为干燥的种植盆方块
|
||||||
if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
if (CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
||||||
|
//如果手中的是水桶,那么转干为湿
|
||||||
if (mainHandItem.getType() == Material.WATER_BUCKET){
|
if (mainHandItem.getType() == Material.WATER_BUCKET){
|
||||||
|
//扣除水桶
|
||||||
if(player.getGameMode() != GameMode.CREATIVE){
|
if(player.getGameMode() != GameMode.CREATIVE){
|
||||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||||
player.getInventory().addItem(new ItemStack(Material.BUCKET));
|
player.getInventory().addItem(new ItemStack(Material.BUCKET));
|
||||||
@@ -103,25 +139,30 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
CustomBlock.remove(clickedBlockLocation);
|
CustomBlock.remove(clickedBlockLocation);
|
||||||
CustomBlock.place(config.getString("config.watered-pot"),clickedBlockLocation);
|
CustomBlock.place(config.getString("config.watered-pot"),clickedBlockLocation);
|
||||||
} else if (mainHandItem.getType() == Material.WOODEN_SWORD){
|
} else if (mainHandItem.getType() == Material.WOODEN_SWORD){
|
||||||
waterPot(mainHandItem, player,clickedBlockLocation);
|
waterPot(mainHandItem, player,clickedBlockLocation, config);
|
||||||
} else {
|
} else {
|
||||||
tryPlantSeed(clickedBlockLocation, mainHandItem, player);
|
tryPlantSeed(clickedBlockLocation, mainHandItem, player, config);
|
||||||
}
|
}
|
||||||
|
//检测右键的方块是否为湿润的种植盆方块
|
||||||
}else if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)).getNamespacedID().equalsIgnoreCase(config.getString("config.watered-pot"))){
|
}else if(CustomBlock.byAlreadyPlaced(world.getBlockAt(clickedBlockLocation)).getNamespacedID().equalsIgnoreCase(config.getString("config.watered-pot"))){
|
||||||
|
|
||||||
tryPlantSeed(clickedBlockLocation, mainHandItem, player);
|
tryPlantSeed(clickedBlockLocation, mainHandItem, player, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void tryPlantSeed(Location clickedBlockLocation, ItemStack mainHandItem, Player player) {
|
//尝试种植植物
|
||||||
|
private void tryPlantSeed(Location clickedBlockLocation, ItemStack mainHandItem, Player player, FileConfiguration config) {
|
||||||
|
|
||||||
if(CustomStack.byItemStack(mainHandItem) == null) return;
|
if(CustomStack.byItemStack(mainHandItem) == null) return;
|
||||||
if (CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase().endsWith("_seeds")){
|
if (CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase().endsWith("_seeds")){
|
||||||
String namespaced_id = CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase();
|
String namespaced_id = CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase();
|
||||||
String[] crop = CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase().replace("_seeds","").split(":");
|
String[] crop = CustomStack.byItemStack(mainHandItem).getNamespacedID().toLowerCase().replace("_seeds","").split(":");
|
||||||
|
//是否超高超低
|
||||||
if (clickedBlockLocation.getY() < config.getInt("config.height.min") || clickedBlockLocation.getY() > config.getInt("config.height.max")){
|
if (clickedBlockLocation.getY() < config.getInt("config.height.min") || clickedBlockLocation.getY() > config.getInt("config.height.max")){
|
||||||
MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.not-a-good-place"),player);
|
MessageManager.playerMessage(config.getString("messages.prefix") + config.getString("messages.not-a-good-place"),player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//是否启用了季节
|
||||||
Label_out:
|
Label_out:
|
||||||
if(config.getBoolean("enable-season")){
|
if(config.getBoolean("enable-season")){
|
||||||
if(config.getBoolean("config.enable-greenhouse")){
|
if(config.getBoolean("config.enable-greenhouse")){
|
||||||
@@ -146,26 +187,31 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//该种子是否存在于配置文件中
|
||||||
if(!config.contains("crops."+crop[1])){
|
if(!config.contains("crops."+crop[1])){
|
||||||
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.no-such-seed"),player);
|
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.no-such-seed"),player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//是否到达区块上限
|
||||||
if(MaxCropsPerChunk.maxCropsPerChunk(clickedBlockLocation)){
|
if(MaxCropsPerChunk.maxCropsPerChunk(clickedBlockLocation)){
|
||||||
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.reach-limit-crop").replace("{Max}", config.getString("config.max-crops")),player);
|
MessageManager.playerMessage(config.getString("messages.prefix")+config.getString("messages.reach-limit-crop").replace("{Max}", config.getString("config.max-crops")),player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//添加到缓存中
|
||||||
if(config.getBoolean("enable-season")){
|
if(config.getBoolean("enable-season")){
|
||||||
CropManager.putInstance(clickedBlockLocation.clone().add(0,1,0), config.getString("crops."+crop[1]+".season"));
|
CropManager.putInstance(clickedBlockLocation.clone().add(0,1,0), config.getString("crops."+crop[1]+".season"));
|
||||||
}else{
|
}else{
|
||||||
CropManager.putInstance(clickedBlockLocation.clone().add(0,1,0), "all");
|
CropManager.putInstance(clickedBlockLocation.clone().add(0,1,0), "all");
|
||||||
}
|
}
|
||||||
|
//减少种子数量
|
||||||
if(player.getGameMode() != GameMode.CREATIVE){
|
if(player.getGameMode() != GameMode.CREATIVE){
|
||||||
mainHandItem.setAmount(mainHandItem.getAmount() -1);
|
mainHandItem.setAmount(mainHandItem.getAmount() -1);
|
||||||
}
|
}
|
||||||
|
//放置自定义农作物
|
||||||
CustomBlock.place(namespaced_id.replace("_seeds","_stage_1"),clickedBlockLocation.clone().add(0,1,0));
|
CustomBlock.place(namespaced_id.replace("_seeds","_stage_1"),clickedBlockLocation.clone().add(0,1,0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void waterPot(ItemStack itemStack, Player player, Location location){
|
private void waterPot(ItemStack itemStack, Player player, Location location, FileConfiguration config){
|
||||||
|
|
||||||
if(CustomStack.byItemStack(itemStack) == null) return;
|
if(CustomStack.byItemStack(itemStack) == null) return;
|
||||||
|
|
||||||
@@ -189,6 +235,12 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
x = 4;
|
x = 4;
|
||||||
z = 4;
|
z = 4;
|
||||||
} else return;
|
} else return;
|
||||||
|
/*
|
||||||
|
-45 < yaw < 45 z+
|
||||||
|
-135 < yaw < -45 x+
|
||||||
|
45 < yaw < 135 x-
|
||||||
|
else z-
|
||||||
|
*/
|
||||||
player.playSound(player,Sound.BLOCK_WATER_AMBIENT,1,1);
|
player.playSound(player,Sound.BLOCK_WATER_AMBIENT,1,1);
|
||||||
float yaw = player.getLocation().getYaw();
|
float yaw = player.getLocation().getYaw();
|
||||||
if (yaw <= 45 && yaw >= -135) {
|
if (yaw <= 45 && yaw >= -135) {
|
||||||
@@ -200,7 +252,7 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
for (int i = 0; i <= x; i++) {
|
for (int i = 0; i <= x; i++) {
|
||||||
for (int j = 0; j <= z; j++) {
|
for (int j = 0; j <= z; j++) {
|
||||||
Location tempLoc = location.clone().add(i, 0, j);
|
Location tempLoc = location.clone().add(i, 0, j);
|
||||||
canWaterPot(tempLoc);
|
canWaterPot(tempLoc,config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -212,13 +264,13 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
for (int i = 0; i <= x; i++) {
|
for (int i = 0; i <= x; i++) {
|
||||||
for (int j = 0; j <= z; j++) {
|
for (int j = 0; j <= z; j++) {
|
||||||
Location tempLoc = location.clone().subtract(i, 0, j);
|
Location tempLoc = location.clone().subtract(i, 0, j);
|
||||||
canWaterPot(tempLoc);
|
canWaterPot(tempLoc,config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void canWaterPot(Location location){
|
private void canWaterPot(Location location, FileConfiguration config){
|
||||||
if(CustomBlock.byAlreadyPlaced(location.getWorld().getBlockAt(location)) != null){
|
if(CustomBlock.byAlreadyPlaced(location.getWorld().getBlockAt(location)) != null){
|
||||||
if(CustomBlock.byAlreadyPlaced(location.getWorld().getBlockAt(location)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
if(CustomBlock.byAlreadyPlaced(location.getWorld().getBlockAt(location)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
||||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance,()->{
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance,()->{
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ config:
|
|||||||
- world
|
- world
|
||||||
# 只在被加载的区块中生长和枯萎,对性能友好
|
# 只在被加载的区块中生长和枯萎,对性能友好
|
||||||
only-grow-in-loaded-chunks: true
|
only-grow-in-loaded-chunks: true
|
||||||
|
#与第三方插件兼容
|
||||||
|
integration:
|
||||||
|
#收获权限为harvest 浇水种植权限为build
|
||||||
|
residence: false
|
||||||
|
#收获flag为BLOCK_BREAK 浇水种植flag为BUILD
|
||||||
|
worldguard: false
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: '<gradient:#ccfbff:#ef96c5>[CustomCrops] </gradient>'
|
prefix: '<gradient:#ccfbff:#ef96c5>[CustomCrops] </gradient>'
|
||||||
|
|||||||
Reference in New Issue
Block a user