mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.5.24
This commit is contained in:
@@ -380,7 +380,11 @@ public class ConfigReader {
|
|||||||
YamlConfiguration config = getConfig("season.yml");
|
YamlConfiguration config = getConfig("season.yml");
|
||||||
|
|
||||||
enable = config.getBoolean("season.enable",false);
|
enable = config.getBoolean("season.enable",false);
|
||||||
|
|
||||||
if (enable){
|
if (enable){
|
||||||
|
if (Config.growMode == 4){
|
||||||
|
AdventureManager.consoleMessage("<red>[CustomCrops] Warining: It's not advised to enable season in mode 4</red>");
|
||||||
|
}
|
||||||
greenhouse = config.getBoolean("season.greenhouse.enable",false);
|
greenhouse = config.getBoolean("season.greenhouse.enable",false);
|
||||||
if (greenhouse) {
|
if (greenhouse) {
|
||||||
range = config.getInt("season.greenhouse.range",7);
|
range = config.getInt("season.greenhouse.range",7);
|
||||||
|
|||||||
@@ -104,9 +104,6 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
HoloUtil.cache.keySet().forEach(location -> HoloUtil.cache.get(location).remove());
|
|
||||||
|
|
||||||
if (this.cropManager != null){
|
if (this.cropManager != null){
|
||||||
this.cropManager.cleanData();
|
this.cropManager.cleanData();
|
||||||
this.cropManager.updateData();
|
this.cropManager.updateData();
|
||||||
|
|||||||
@@ -427,6 +427,7 @@ public class CropManager {
|
|||||||
CustomBlock.remove(potLocation);
|
CustomBlock.remove(potLocation);
|
||||||
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
|
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
|
||||||
}, random);
|
}, random);
|
||||||
|
return ConfigReader.Config.growMode == 4;
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
//若无下一阶段,无巨大化,未启用季节,则移除无用数据
|
//若无下一阶段,无巨大化,未启用季节,则移除无用数据
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ public class InteractEntity implements Listener {
|
|||||||
if (ConfigReader.Message.hasSprinklerInfo){
|
if (ConfigReader.Message.hasSprinklerInfo){
|
||||||
String string = ConfigReader.Message.sprinklerLeft + ConfigReader.Message.sprinklerFull.repeat(currentWater) +
|
String string = ConfigReader.Message.sprinklerLeft + ConfigReader.Message.sprinklerFull.repeat(currentWater) +
|
||||||
ConfigReader.Message.sprinklerEmpty.repeat(maxWater - currentWater) + ConfigReader.Message.sprinklerRight;
|
ConfigReader.Message.sprinklerEmpty.repeat(maxWater - currentWater) + ConfigReader.Message.sprinklerRight;
|
||||||
if(HoloUtil.cache.get(location.add(0, ConfigReader.Message.sprinklerOffset,0)) == null) {
|
if(!HoloUtil.cache.contains(location.add(0, ConfigReader.Message.sprinklerOffset,0))) {
|
||||||
HoloUtil.showHolo(string.replace("{max_water}", String.valueOf(maxWater)).replace("{water}", String.valueOf(currentWater)), player, location, ConfigReader.Message.sprinklerTime);
|
HoloUtil.showHolo(string.replace("{max_water}", String.valueOf(maxWater)).replace("{water}", String.valueOf(currentWater)), player, location, ConfigReader.Message.sprinklerTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ public class RightClick implements Listener {
|
|||||||
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
||||||
String name = config.getName();
|
String name = config.getName();
|
||||||
int max_times = config.getTimes();
|
int max_times = config.getTimes();
|
||||||
if(HoloUtil.cache.get(location.add(0.5, ConfigReader.Message.cropOffset, 0.5)) == null) {
|
if(!HoloUtil.cache.contains(location.add(0.5, ConfigReader.Message.cropOffset, 0.5))) {
|
||||||
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location, ConfigReader.Message.cropTime);
|
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location, ConfigReader.Message.cropTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,7 +324,7 @@ public class RightClick implements Listener {
|
|||||||
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
||||||
String name = config.getName();
|
String name = config.getName();
|
||||||
int max_times = config.getTimes();
|
int max_times = config.getTimes();
|
||||||
if(HoloUtil.cache.get(location.add(0.5,ConfigReader.Message.cropOffset,0.5)) == null){
|
if(!HoloUtil.cache.contains(location.add(0.5,ConfigReader.Message.cropOffset,0.5))){
|
||||||
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location, ConfigReader.Message.cropTime);
|
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location, ConfigReader.Message.cropTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,17 +28,17 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class HoloUtil {
|
public class HoloUtil {
|
||||||
|
|
||||||
public static HashMap<Location, Entity> cache = new HashMap<>();
|
public static HashSet<Location> cache = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对指定玩家展示在指定位置的盔甲架
|
* 对指定玩家展示在指定位置的盔甲架
|
||||||
* @param text 文本
|
* @param text 文本
|
||||||
@@ -48,30 +48,35 @@ public class HoloUtil {
|
|||||||
*/
|
*/
|
||||||
public static void showHolo(String text, Player player, Location location, int duration){
|
public static void showHolo(String text, Player player, Location location, int duration){
|
||||||
|
|
||||||
ArmorStand entity = location.getWorld().spawn(location, ArmorStand.class, a -> {
|
PacketContainer packet1 = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||||
a.setInvisible(true);
|
|
||||||
a.setCollidable(false);
|
int id = new Random().nextInt(1000000000);
|
||||||
a.setInvulnerable(true);
|
packet1.getModifier().write(0, id);
|
||||||
a.setVisible(false);
|
packet1.getModifier().write(1, UUID.randomUUID());
|
||||||
a.setCustomNameVisible(false);
|
packet1.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND);
|
||||||
a.setSmall(true);
|
packet1.getDoubles().write(0, location.getX());
|
||||||
a.setGravity(false);
|
packet1.getDoubles().write(1, location.getY());
|
||||||
});
|
packet1.getDoubles().write(2, location.getZ());
|
||||||
cache.put(location, entity);
|
|
||||||
|
PacketContainer packet2 = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
|
|
||||||
Component component = MiniMessage.miniMessage().deserialize(text);
|
Component component = MiniMessage.miniMessage().deserialize(text);
|
||||||
|
|
||||||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher();
|
||||||
wrappedDataWatcher.setEntity(entity);
|
WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class);
|
||||||
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Boolean.class);
|
WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class);
|
||||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(component)).getHandle()));
|
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(component)).getHandle()));
|
||||||
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer), true);
|
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true);
|
||||||
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(5, serializer1), true);
|
||||||
packetContainer.getIntegers().write(0, entity.getEntityId());
|
byte mask1 = 0x20;
|
||||||
packetContainer.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
byte mask2 = 0x01;
|
||||||
|
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), mask1);
|
||||||
|
wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), mask2);
|
||||||
|
packet2.getModifier().write(0,id);
|
||||||
|
packet2.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
|
||||||
|
cache.add(location);
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet1);
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet2);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
AdventureManager.consoleMessage("<red>[CustomCrops] 无法为玩家 "+ player.getName()+" 展示悬浮信息!</red>");
|
AdventureManager.consoleMessage("<red>[CustomCrops] 无法为玩家 "+ player.getName()+" 展示悬浮信息!</red>");
|
||||||
@@ -79,8 +84,20 @@ public class HoloUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(CustomCrops.instance, ()->{
|
Bukkit.getScheduler().runTaskLater(CustomCrops.instance, ()->{
|
||||||
entity.remove();
|
removeHolo(player, id);
|
||||||
cache.remove(location);
|
cache.remove(location);
|
||||||
}, duration * 20L);
|
}, duration * 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeHolo(Player player, int entityId){
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||||
|
packet.getIntLists().write(0, List.of(entityId));
|
||||||
|
try {
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
AdventureManager.consoleMessage("<red>[CustomCrops] 无法为玩家 "+ player.getName()+" 移除悬浮信息!</red>");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ config:
|
|||||||
#Mode 3:
|
#Mode 3:
|
||||||
# Mode 1 + Mode 2
|
# Mode 1 + Mode 2
|
||||||
#Mode 4:
|
#Mode 4:
|
||||||
# No support in this mode!
|
# No support in this mode! Please disable season in this mode!
|
||||||
# All the crops will grow (May cause lag)
|
# All the crops will grow (May cause lag)
|
||||||
grow-mode: 3
|
grow-mode: 3
|
||||||
#The time to start growing(ticks)
|
#The time to start growing(ticks)
|
||||||
|
|||||||
Reference in New Issue
Block a user