mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-21 16:09:21 +00:00
1.7-7
This commit is contained in:
@@ -136,8 +136,6 @@ public class MainConfig {
|
||||
enableParticles = !config.getBoolean("optimization.disable-water-particles", false);
|
||||
enableAnimations = !config.getBoolean("optimization.disable-sprinkler-animation", false);
|
||||
|
||||
realisticSeasonHook = config.getBoolean("integration.RealisticSeasons");
|
||||
|
||||
try {
|
||||
boneMealSuccess = Particle.valueOf(config.getString("mechanics.success-particle", "VILLAGER_HAPPY"));
|
||||
}
|
||||
@@ -238,6 +236,11 @@ public class MainConfig {
|
||||
if (Bukkit.getPluginManager().getPlugin("JobsReborn") == null) Log.warn("Failed to initialize JobsReborn!");
|
||||
else {skillXP = new JobsRebornHook();}
|
||||
}
|
||||
realisticSeasonHook = false;
|
||||
if (config.getBoolean("integration.RealisticSeasons")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("RealisticSeasons") == null) Log.warn("Failed to initialize RealisticSeasons!");
|
||||
else {realisticSeasonHook = true;}
|
||||
}
|
||||
}
|
||||
|
||||
public static World[] getWorldsArray() {
|
||||
|
||||
@@ -38,6 +38,7 @@ import net.momirealms.customcrops.integrations.season.RealisticSeasonsHook;
|
||||
import net.momirealms.customcrops.integrations.season.SeasonInterface;
|
||||
import net.momirealms.customcrops.managers.listener.ItemSpawnListener;
|
||||
import net.momirealms.customcrops.managers.listener.WorldListener;
|
||||
import net.momirealms.customcrops.managers.timer.CrowTask;
|
||||
import net.momirealms.customcrops.managers.timer.TimerTask;
|
||||
import net.momirealms.customcrops.objects.OtherLoot;
|
||||
import net.momirealms.customcrops.objects.QualityLoot;
|
||||
@@ -53,6 +54,7 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -194,6 +196,12 @@ public class CropManager extends Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasScarecrow(Location location) {
|
||||
CustomWorld customWorld = customWorlds.get(location.getWorld());
|
||||
if (customWorld == null) return true;
|
||||
return customWorld.hasScarecrow(location);
|
||||
}
|
||||
|
||||
public CustomInterface getCustomInterface() {
|
||||
return customInterface;
|
||||
}
|
||||
@@ -324,6 +332,36 @@ public class CropManager extends Function {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean crowJudge(Location location, ItemFrame itemFrame) {
|
||||
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
|
||||
for (Player player : location.getNearbyPlayers(48)) {
|
||||
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
|
||||
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
|
||||
customInterface.removeFurniture(itemFrame);
|
||||
}, 125);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean crowJudge(Location location) {
|
||||
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
for (Player player : location.getNearbyPlayers(48)) {
|
||||
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
|
||||
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
|
||||
}
|
||||
});
|
||||
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
}, 125);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArmorStandUtil getArmorStandUtil() {
|
||||
return armorStandUtil;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface {
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
String temp = StringUtils.chop(id);
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||
addStage(itemFrame, temp + (nextStage+1));
|
||||
@@ -87,6 +88,7 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
|
||||
@@ -67,6 +67,7 @@ public class ItemsAdderWireCropImpl implements CropModeInterface{
|
||||
String temp = StringUtils.chop(blockID);
|
||||
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||
addStage(location, temp + (nextStage+1));
|
||||
@@ -77,6 +78,7 @@ public class ItemsAdderWireCropImpl implements CropModeInterface{
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenHook;
|
||||
import net.momirealms.customcrops.managers.timer.CrowTask;
|
||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Gigantic;
|
||||
@@ -34,6 +35,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class OraxenFrameCropImpl implements CropModeInterface {
|
||||
@@ -80,6 +82,7 @@ public class OraxenFrameCropImpl implements CropModeInterface {
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
String temp = StringUtils.chop(id);
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||
addStage(itemFrame, temp + (nextStage+1));
|
||||
@@ -90,6 +93,7 @@ public class OraxenFrameCropImpl implements CropModeInterface {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true;
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
|
||||
@@ -66,6 +66,7 @@ public class OraxenWireCropImpl implements CropModeInterface{
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
String temp = StringUtils.chop(blockID);
|
||||
if (customInterface.doesExist(temp + nextStage)) {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) {
|
||||
if (customInterface.doesExist(temp + (nextStage+1))) {
|
||||
addStage(location, temp + (nextStage+1));
|
||||
@@ -76,6 +77,7 @@ public class OraxenWireCropImpl implements CropModeInterface{
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true;
|
||||
GiganticCrop giganticCrop = crop.getGiganticCrop();
|
||||
if (giganticCrop != null) {
|
||||
double chance = giganticCrop.getChance();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.momirealms.customcrops.managers.timer;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.utils.ArmorStandUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Random;
|
||||
|
||||
public class CrowTask extends BukkitRunnable {
|
||||
|
||||
private int timer;
|
||||
private final int entityID;
|
||||
private final ArmorStandUtil armorStandUtil;
|
||||
private final Vector vectorDown;
|
||||
private final Vector vectorUp;
|
||||
private final Location from;
|
||||
private final Player player;
|
||||
private float yaw;
|
||||
|
||||
|
||||
public CrowTask(Player player, Location crop, ArmorStandUtil armorStandUtil) {
|
||||
this.timer = 0;
|
||||
this.player = player;
|
||||
this.armorStandUtil = armorStandUtil;
|
||||
this.entityID = new Random().nextInt(10000000);
|
||||
yaw = new Random().nextInt(361) - 180;
|
||||
this.from = crop.clone().add(10 * Math.sin((Math.PI * yaw)/180), 10, - 10 * Math.cos((Math.PI * yaw)/180));
|
||||
Location relative = crop.clone().subtract(from);
|
||||
this.vectorDown = new Vector(relative.getX() / 100, -0.1, relative.getZ() / 100);
|
||||
this.vectorUp = new Vector(relative.getX() / 100, 0.1, relative.getZ() / 100);
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getSpawnPacket(entityID, from));
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getMetaPacket(entityID));
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timer++;
|
||||
if (timer < 100) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getTeleportPacket(entityID, from.add(vectorDown), yaw));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
}
|
||||
else if (timer == 100){
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowLand)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
}
|
||||
else if (timer == 150) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
}
|
||||
else if (timer > 150) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getTeleportPacket(entityID, from.add(vectorUp), yaw));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
}
|
||||
if (timer > 300) {
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getDestroyPacket(entityID));
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
//release
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
@@ -42,17 +41,15 @@ import java.util.UUID;
|
||||
public class ArmorStandUtil {
|
||||
|
||||
private final CropManager cropManager;
|
||||
private static final Vector[] vectors =
|
||||
{new Vector(10,10,10), new Vector(0,10,-15)
|
||||
, new Vector(10,10,-10), new Vector(15,10,0)
|
||||
, new Vector(-15,10,0), new Vector(-10,10,10)
|
||||
, new Vector(0,10,15), new Vector(-10,10,-10)};
|
||||
private static final float[] yaws = {135f, 180f, -135f, -90f, -45f, 0f, 45f, 90f};
|
||||
|
||||
public ArmorStandUtil(CropManager cropManager) {
|
||||
this.cropManager = cropManager;
|
||||
}
|
||||
|
||||
public CropManager getCropManager() {
|
||||
return cropManager;
|
||||
}
|
||||
|
||||
public void playWaterAnimation(Player player, Location location) {
|
||||
int id = new Random().nextInt(1000000000);
|
||||
try {
|
||||
@@ -72,19 +69,7 @@ public class ArmorStandUtil {
|
||||
}, MainConfig.timeToWork/2);
|
||||
}
|
||||
|
||||
public void playCrowAnimation(Player player, Location location) {
|
||||
int id = new Random().nextInt(1000000000);
|
||||
Location startLoc = location.clone().add(vectors[new Random().nextInt(vectors.length - 1)]);
|
||||
try {
|
||||
CustomCrops.protocolManager.sendServerPacket(player, getSpawnPacket(id, startLoc));
|
||||
CustomCrops.protocolManager.sendServerPacket(player, getMetaPacket(id));
|
||||
CustomCrops.protocolManager.sendServerPacket(player, getEquipPacket(id, cropManager.getCustomInterface().getItemStack(BasicItemConfig.crowLand)));
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private WrappedDataWatcher createDataWatcher() {
|
||||
public WrappedDataWatcher createDataWatcher() {
|
||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
@@ -94,13 +79,13 @@ public class ArmorStandUtil {
|
||||
return wrappedDataWatcher;
|
||||
}
|
||||
|
||||
private PacketContainer getDestroyPacket(int id) {
|
||||
public PacketContainer getDestroyPacket(int id) {
|
||||
PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getIntLists().write(0, List.of(id));
|
||||
return destroyPacket;
|
||||
}
|
||||
|
||||
private PacketContainer getSpawnPacket(int id, Location location) {
|
||||
public PacketContainer getSpawnPacket(int id, Location location) {
|
||||
PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
entityPacket.getModifier().write(0, id);
|
||||
entityPacket.getModifier().write(1, UUID.randomUUID());
|
||||
@@ -111,14 +96,14 @@ public class ArmorStandUtil {
|
||||
return entityPacket;
|
||||
}
|
||||
|
||||
private PacketContainer getMetaPacket(int id) {
|
||||
public PacketContainer getMetaPacket(int id) {
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
metaPacket.getIntegers().write(0, id);
|
||||
metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher().getWatchableObjects());
|
||||
return metaPacket;
|
||||
}
|
||||
|
||||
private PacketContainer getEquipPacket(int id, ItemStack itemStack) {
|
||||
public PacketContainer getEquipPacket(int id, ItemStack itemStack) {
|
||||
PacketContainer equipPacket = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
equipPacket.getIntegers().write(0, id);
|
||||
List<Pair<EnumWrappers.ItemSlot, ItemStack>> pairs = new ArrayList<>();
|
||||
@@ -127,19 +112,19 @@ public class ArmorStandUtil {
|
||||
return equipPacket;
|
||||
}
|
||||
|
||||
private PacketContainer getTeleportPacket(int id, Location location) {
|
||||
public PacketContainer getTeleportPacket(int id, Location location, float yaw) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
packet.getIntegers().write(0, id);
|
||||
packet.getDoubles().write(0, location.getX());
|
||||
packet.getDoubles().write(1, location.getY());
|
||||
packet.getDoubles().write(2, location.getZ());
|
||||
packet.getBytes().write(0, (byte) (yaw * (128.0 / 180)));
|
||||
return packet;
|
||||
}
|
||||
|
||||
private PacketContainer getRotationPacket(int id, float yaw) {
|
||||
public PacketContainer getRotationPacket(int id, float yaw) {
|
||||
PacketContainer rotationPacket = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
rotationPacket.getIntegers().write(0, id);
|
||||
rotationPacket.getBytes().write(0, (byte) yaw);
|
||||
return rotationPacket;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ mechanics:
|
||||
range: 5
|
||||
crow:
|
||||
enable: true
|
||||
chance: 0.001
|
||||
chance: 0.005
|
||||
default-quality-ratio: 17/2/1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user