diff --git a/core/pom.xml b/core/pom.xml
index 633a5ed..d95426f 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -245,7 +245,7 @@
com.github.LoneDev6
api-itemsadder
- 3.0.0
+ 3.2.5
provided
@@ -259,4 +259,4 @@
-
\ No newline at end of file
+
diff --git a/core/src/main/java/com/github/sachin/tweakin/Tweakin.java b/core/src/main/java/com/github/sachin/tweakin/Tweakin.java
index bd6307c..046bfa9 100644
--- a/core/src/main/java/com/github/sachin/tweakin/Tweakin.java
+++ b/core/src/main/java/com/github/sachin/tweakin/Tweakin.java
@@ -57,15 +57,16 @@ public final class Tweakin extends JavaPlugin {
private List permissions;
private List placedPlayers = new ArrayList<>();
-
@Override
public void onLoad() {
plugin = this;
- isWorldGuardEnabled = Bukkit.getPluginManager().getPlugin("WorldGuard") != null;
- if(isWorldGuardEnabled){
+
+ if(Bukkit.getPluginManager().getPlugin("WorldGuard") != null){
wgFlagManager = new WGFlagManager(this);
plugin.getLogger().info("Found WorldGuard, initializing flags support");
- wgFlagManager.registerFlags();
+ if (wgFlagManager.registerFlags()) {
+ isWorldGuardEnabled = true;
+ }
}
}
@@ -250,12 +251,12 @@ public void addPlacedPlayer(Player player){
}
public boolean isPost1_17(){
- return Arrays.asList("v1_17_R1","v1_18_R1","v1_18_R2","v1_19_R1").contains(version);
+ return Arrays.asList("v1_17_R1","v1_18_R1","v1_18_R2","v1_19_R1","v1_19_R2","v1_19_R3").contains(version);
}
- public boolean is1_18() {return Arrays.asList("v1_18_R1","v1_18_R2","v1_19_R1").contains(version);}
+ public boolean is1_18() {return Arrays.asList("v1_18_R1","v1_18_R2","v1_19_R1","v1_19_R2","v1_19_R3").contains(version);}
- public boolean isPost1_19() {return Arrays.asList("v1_19_R1").contains(version);}
+ public boolean isPost1_19() {return Arrays.asList("v1_19_R1","v1_19_R2","v1_19_R3").contains(version);}
public List getPlacedPlayers() {
return placedPlayers;
diff --git a/core/src/main/java/com/github/sachin/tweakin/WGFlagManager.java b/core/src/main/java/com/github/sachin/tweakin/WGFlagManager.java
index 2e51876..89e8c5f 100644
--- a/core/src/main/java/com/github/sachin/tweakin/WGFlagManager.java
+++ b/core/src/main/java/com/github/sachin/tweakin/WGFlagManager.java
@@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.logging.Level;
public class WGFlagManager {
@@ -35,11 +36,16 @@ public FlagRegistry getRegistry() {
}
- public void registerFlags(){
-
- registeredFlags.put(TConstants.BSE_FLAG, new BSEFlag(plugin));
- registeredFlags.put(TConstants.SIF_FLAG, new SIFFlag(plugin));
- registeredFlags.put(TConstants.SBK_FLAG, new SBKFlag(plugin));
+ public boolean registerFlags(){
+ try {
+ registeredFlags.put(TConstants.BSE_FLAG, new BSEFlag(plugin));
+ registeredFlags.put(TConstants.SIF_FLAG, new SIFFlag(plugin));
+ registeredFlags.put(TConstants.SBK_FLAG, new SBKFlag(plugin));
+ } catch (Throwable t) {
+ plugin.getLogger().log(Level.WARNING, "Unable to initialize flags support:", t);
+ return false;
+ }
+ return true;
}
public BaseFlag getFlag(String name){
return registeredFlags.get(name);
diff --git a/core/src/main/java/com/github/sachin/tweakin/modules/shulkerboxpreview/ShulkerBoxPreview.java b/core/src/main/java/com/github/sachin/tweakin/modules/shulkerboxpreview/ShulkerBoxPreview.java
index 087c502..d8950a6 100644
--- a/core/src/main/java/com/github/sachin/tweakin/modules/shulkerboxpreview/ShulkerBoxPreview.java
+++ b/core/src/main/java/com/github/sachin/tweakin/modules/shulkerboxpreview/ShulkerBoxPreview.java
@@ -41,7 +41,10 @@ public void shulkerGuiClickEvent(InventoryClickEvent e){
ShulkerGui gui = (ShulkerGui) e.getView().getTopInventory().getHolder();
gui.update(false);
- if((e.getClick() == ClickType.NUMBER_KEY && gui.getSlot() == e.getHotbarButton()) || getConfig().getBoolean("preview-only") || (e.getCurrentItem() != null && e.getCurrentItem().getType().name().endsWith("SHULKER_BOX"))){
+ if(((e.getClick() == ClickType.NUMBER_KEY && gui.getSlot() == e.getHotbarButton())
+ || (e.getClick() == ClickType.SWAP_OFFHAND && gui.getSlot() == 40))
+ || getConfig().getBoolean("preview-only")
+ || (e.getCurrentItem() != null && e.getCurrentItem().getType().name().endsWith("SHULKER_BOX"))){
e.setCancelled(true);
}
}
diff --git a/core/src/main/java/com/github/sachin/tweakin/nbtapi/NBTAPI.java b/core/src/main/java/com/github/sachin/tweakin/nbtapi/NBTAPI.java
index cbee0f6..7976ba2 100644
--- a/core/src/main/java/com/github/sachin/tweakin/nbtapi/NBTAPI.java
+++ b/core/src/main/java/com/github/sachin/tweakin/nbtapi/NBTAPI.java
@@ -17,10 +17,7 @@ public NBTAPI(){
public boolean loadVersions(@Nonnull JavaPlugin plugin,String version,String mcVersion){
String newVersion = version;
- if(mcVersion.equals("1.19")){
- newVersion = "v1_19_R1";
- }
- else if(mcVersion.equals("1.19.1") || mcVersion.equals("1.19.2")){
+ if (mcVersion.equals("1.19.1") || mcVersion.equals("1.19.2")) {
newVersion = "v1_19_R11";
}
try {
diff --git a/dist/pom.xml b/dist/pom.xml
index 363bd26..b9230d1 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -136,5 +136,11 @@
3.8.6
compile
+
+ com.github.sachin
+ nms1_19_3
+ 3.8.6
+ compile
+
\ No newline at end of file
diff --git a/nms1_19_3/pom.xml b/nms1_19_3/pom.xml
new file mode 100644
index 0000000..db20f54
--- /dev/null
+++ b/nms1_19_3/pom.xml
@@ -0,0 +1,97 @@
+
+
+
+ Tweakin
+ com.github.sachin
+ 3.8.6
+
+ 4.0.0
+
+ nms1_19_3
+ jar
+
+ 11
+ 11
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ eclipse
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+ org.codehaus.plexus
+ plexus-compiler-eclipse
+ 2.8.8
+
+
+
+
+ net.md-5
+ specialsource-maven-plugin
+ 1.2.2
+
+
+ package
+
+ remap
+
+ remap-obf
+
+ org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:txt:maps-mojang
+ true
+ org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-mojang
+
+ true
+ remapped-obf
+
+
+
+ package
+
+ remap
+
+ remap-spigot
+
+
+ ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
+
+ org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:csrg:maps-spigot
+ org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-obf
+
+
+
+
+
+
+
+
+
+
+
+ org.spigotmc
+ spigot
+ 1.19.3-R0.1-SNAPSHOT
+ provided
+ remapped-mojang
+
+
+
+ com.github.sachin
+ core
+ 3.8.6
+ compile
+
+
+
\ No newline at end of file
diff --git a/nms1_19_3/src/main/java/com/github/sachin/tweakin/nms/v1_19_R2/NMSHandler.java b/nms1_19_3/src/main/java/com/github/sachin/tweakin/nms/v1_19_R2/NMSHandler.java
new file mode 100644
index 0000000..24599a6
--- /dev/null
+++ b/nms1_19_3/src/main/java/com/github/sachin/tweakin/nms/v1_19_R2/NMSHandler.java
@@ -0,0 +1,327 @@
+package com.github.sachin.tweakin.nms.v1_19_R2;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import com.github.sachin.tweakin.Tweakin;
+import com.github.sachin.tweakin.modules.betterflee.AnimalFleeTweak;
+import com.github.sachin.tweakin.nbtapi.nms.NMSHelper;
+import com.github.sachin.tweakin.utils.PaperUtils;
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.properties.Property;
+
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.world.entity.PlayerRideable;
+import net.minecraft.world.entity.PlayerRideableJumping;
+import net.minecraft.world.entity.ai.control.JumpControl;
+import net.minecraft.world.entity.ai.goal.PanicGoal;
+import net.minecraft.world.entity.animal.Cow;
+import net.minecraft.world.entity.animal.Pig;
+import net.minecraft.world.entity.animal.horse.AbstractHorse;
+import net.minecraft.world.entity.animal.horse.Horse;
+import net.minecraft.world.entity.vehicle.Boat;
+import net.minecraft.world.item.*;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.LiquidBlockContainer;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.material.Fluids;
+import net.minecraft.world.level.saveddata.maps.MapDecoration;
+import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
+import net.minecraft.world.level.storage.loot.functions.ExplorationMapFunction;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
+import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
+import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
+import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
+import org.bukkit.entity.*;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.persistence.PersistentDataType;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.PathfinderMob;
+import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
+import net.minecraft.world.entity.ai.goal.TemptGoal;
+import net.minecraft.world.entity.animal.Animal;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.item.crafting.Ingredient;
+import net.minecraft.world.phys.BlockHitResult;
+import net.minecraft.world.phys.Vec3;
+
+public class NMSHandler extends NMSHelper {
+
+
+ private net.minecraft.world.item.ItemStack nmsItem;
+ private CompoundTag compound;
+
+ public NMSHandler(){}
+
+ public NMSHandler(ItemStack item){
+ if(item==null) return;
+
+ this.nmsItem = CraftItemStack.asNMSCopy(item);
+ this.compound = nmsItem.getOrCreateTag();
+ }
+
+ @Override
+ public NMSHelper newItem(ItemStack item) {
+ return new NMSHandler(item);
+ }
+
+ @Override
+ public void setString(String key, String value) {
+ compound.putString(key,value);
+ }
+
+ @Override
+ public void setBoolean(String key, boolean value) {
+ compound.putBoolean(key,value);
+ }
+
+ @Override
+ public void setInt(String key, int value) {
+ compound.putInt(key,value);
+ }
+
+ @Override
+ public void setLong(String key, long value) {
+ compound.putLong(key,value);
+ }
+
+ @Override
+ public void setDouble(String key, double value) {
+ compound.putDouble(key,value);
+ }
+
+ @Override
+ public String getString(String key) {
+ return compound.getString(key);
+ }
+
+ @Override
+ public boolean getBoolean(String key) {
+ return compound.getBoolean(key);
+ }
+
+ @Override
+ public int getInt(String key) {
+ return compound.getInt(key);
+ }
+
+ @Override
+ public long getLong(String key) {
+ return compound.getLong(key);
+ }
+
+ @Override
+ public double getDouble(String key) {
+ return compound.getDouble(key);
+ }
+
+ @Override
+ public boolean hasKey(String key) {
+ return compound.contains(key);
+ }
+
+ @Override
+ public org.bukkit.inventory.ItemStack getItem() {
+ nmsItem.save(compound);
+ return CraftItemStack.asBukkitCopy(nmsItem);
+ }
+
+ @Override
+ public void removeKey(String key) {
+ compound.remove(key);
+ }
+
+ @Override
+ public void placeWater(Block block) {
+ Location loc = block.getLocation();
+ BlockPos blockPos = new BlockPos(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
+ ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
+ BlockState iBlockData = level.getBlockState(blockPos);
+ net.minecraft.world.level.block.Block nmsBlock = iBlockData.getBlock();
+ if(nmsBlock instanceof LiquidBlockContainer){
+ ((LiquidBlockContainer)nmsBlock).placeLiquid(level,blockPos,iBlockData, Fluids.WATER.getSource(false));
+ }
+ }
+
+ @Override
+ public void attack(Player player, Entity target) {
+
+ ((CraftPlayer)player).getHandle().attack(((CraftEntity)target).getHandle());
+ ((CraftPlayer)player).getHandle().resetAttackStrengthTicker();
+ }
+
+ @Override
+ public boolean placeItem(Player player, Location location, ItemStack item, BlockFace hitFace, String tweakName, boolean playSound) {
+ net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
+ BlockPos pos = new BlockPos(location.getX(), location.getY(), location.getZ());
+ ServerPlayer nmsPlayer = ((CraftPlayer)player).getHandle();
+ UseOnContext context = new UseOnContext(nmsPlayer, InteractionHand.MAIN_HAND, new BlockHitResult(new Vec3(0.5F, 1F, 0.5F), Direction.UP, pos, false));
+ InteractionResult res = nmsItem.useOn(context,InteractionHand.MAIN_HAND);
+
+ if(res==InteractionResult.CONSUME){
+ player.swingMainHand();
+ BlockPos placedPos = context.getClickedPos().relative(context.getClickedFace());
+ Block placedBlock = player.getWorld().getBlockAt(placedPos.getX(),placedPos.getY(),placedPos.getZ());
+ if (placedBlock.getType()==Material.BARRIER){
+ placedBlock.setType(Material.AIR);
+ }
+ if(playSound){
+ player.getWorld().playSound(location, location.getBlock().getBlockData().getSoundGroup().getPlaceSound(), 1F, 1F);
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+
+ @Override
+ public void spawnVillager(Villager villager,boolean update) {
+ net.minecraft.world.entity.npc.Villager vil = (net.minecraft.world.entity.npc.Villager) ((CraftEntity)villager).getHandle();
+ TemptGoal goal = new TemptGoal(vil, 0.6, Ingredient.of(Items.EMERALD_BLOCK), false);
+ if(update){
+ vil.goalSelector.removeGoal(goal);
+ }
+ vil.goalSelector.addGoal(2,goal);
+
+ }
+
+ @Override
+ public void avoidPlayer(Entity entity, Player player, ConfigurationSection config) {
+ Animal animal = (Animal) ((CraftEntity)entity).getHandle();
+ List list = animal.getLevel().getEntitiesOfClass(Animal.class,animal.getBoundingBox().inflate(5));
+ animal.goalSelector.removeGoal(new PanicGoal(animal, 2.0));
+ if(!list.isEmpty()){
+ for (Animal en : list) {
+ Entity bEn = en.getBukkitEntity();
+
+ if(bEn.getType() == entity.getType()){
+ if(bEn.getPersistentDataContainer().has(AnimalFleeTweak.key, PersistentDataType.INTEGER) && config.getBoolean("ignore-breeded")) continue;
+ FleePathFinder goal = new FleePathFinder(en, ServerPlayer.class, config.getInt("max-radius"), config.getDouble("walk-speed"), config.getDouble("sprint-speed"), (pl) -> pl.getUUID() == player.getUniqueId(), config.getInt("cooldown"));
+ en.goalSelector.removeGoal(goal);
+ en.goalSelector.addGoal(1, goal);
+ }
+ }
+ }
+ }
+
+ @Override
+ public ItemStack createMap(Location dist,byte zoom,boolean biomePreview){
+ BlockPos loc = new BlockPos(dist.getBlockX(),dist.getBlockY(),dist.getBlockZ());
+ ServerLevel level = ((CraftWorld) dist.getWorld()).getHandle();
+ net.minecraft.world.item.ItemStack mapItem = MapItem.create(level,dist.getBlockX(),dist.getBlockZ(),zoom,true,true);
+ MapItemSavedData.addTargetDecoration(mapItem,loc,"+", MapDecoration.Type.RED_X);
+ if(biomePreview){
+ MapItem.renderBiomePreviewMap(level,mapItem);
+ }
+ return CraftItemStack.asBukkitCopy(mapItem);
+ }
+
+ @Override
+ public boolean matchAxoltlVariant(Entity entity, String color) {
+ return ((Axolotl)entity).getVariant().toString().equals(color);
+ }
+
+ @Override
+ public boolean matchFrogVariant(Entity entity, String variant) {
+ return ((Frog)entity).getVariant().toString().equals(variant);
+ }
+
+ @Override
+ public boolean isScreamingGoat(Entity entity) {
+ return ((Goat)entity).isScreaming();
+ }
+
+ @Override
+ public List getEntitiesWithinRadius(int radius, Entity center) {
+ net.minecraft.world.entity.Entity entity = ((CraftEntity)center).getHandle();
+ return entity.getLevel().getEntities(entity,entity.getBoundingBox().inflate(radius)).stream().map(net.minecraft.world.entity.Entity::getBukkitEntity).collect(Collectors.toList());
+ }
+
+ @Override
+ public void applyHeadTexture(SkullMeta meta, String b64) {
+ Field metaProfileField ;
+ Method metaSetProfileMethod;
+ try {
+ metaSetProfileMethod = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
+ metaSetProfileMethod.setAccessible(true);
+
+ metaSetProfileMethod.invoke(meta, makeProfile(b64));
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+ try {
+ metaProfileField = meta.getClass().getDeclaredField("profile");
+ metaProfileField.setAccessible(true);
+
+ metaProfileField.set(meta, makeProfile(b64));
+
+ } catch (NoSuchFieldException | IllegalAccessException ex2) {
+ ex2.printStackTrace();
+ }
+ }
+ }
+
+ public GameProfile makeProfile(String b64) {
+ UUID id = new UUID(b64.substring(b64.length() - 20).hashCode(),b64.substring(b64.length() - 10).hashCode());
+ GameProfile profile = new GameProfile(id, "someName");
+ profile.getProperties().put("textures", new Property("textures", b64));
+ return profile;
+ }
+
+
+ private static class FleePathFinder extends AvoidEntityGoal{
+
+ private int cooldown;
+
+ private final int finalCoolDown;
+
+
+ public FleePathFinder(PathfinderMob entity, Class avoider, float maxDis, double walkSpeedModifier, double sprintSpeedModifier,
+ Predicate condition, int cooldown) {
+ super(entity, avoider, maxDis, walkSpeedModifier, sprintSpeedModifier, condition);
+ this.finalCoolDown = cooldown*20;
+ this.cooldown = finalCoolDown;
+ }
+
+ @Override
+ public boolean canUse() {
+ if(cooldown==0){
+ return false;
+ }
+ else{
+ cooldown--;
+ return super.canUse();
+ }
+ }
+
+ @Override
+ public boolean canContinueToUse() {
+ if(cooldown==0){
+ this.cooldown = this.finalCoolDown;
+ }
+ if(cooldown==finalCoolDown){
+ return false;
+ }
+ return super.canContinueToUse();
+ }
+ }
+
+}
+
diff --git a/nms1_19_4/pom.xml b/nms1_19_4/pom.xml
new file mode 100644
index 0000000..8534b45
--- /dev/null
+++ b/nms1_19_4/pom.xml
@@ -0,0 +1,97 @@
+
+
+
+ Tweakin
+ com.github.sachin
+ 3.8.6
+
+ 4.0.0
+
+ nms1_19_4
+ jar
+
+ 11
+ 11
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ eclipse
+ ${java.version}
+ ${java.version}
+
+
+
+
+
+ org.codehaus.plexus
+ plexus-compiler-eclipse
+ 2.8.8
+
+
+
+
+ net.md-5
+ specialsource-maven-plugin
+ 1.2.2
+
+
+ package
+
+ remap
+
+ remap-obf
+
+ org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang
+ true
+ org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang
+
+ true
+ remapped-obf
+
+
+
+ package
+
+ remap
+
+ remap-spigot
+
+
+ ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
+
+ org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot
+ org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf
+
+
+
+
+
+
+
+
+
+
+
+ org.spigotmc
+ spigot
+ 1.19.4-R0.1-SNAPSHOT
+ provided
+ remapped-mojang
+
+
+
+ com.github.sachin
+ core
+ 3.8.6
+ compile
+
+
+
\ No newline at end of file
diff --git a/nms1_19_4/src/main/java/com/github/sachin/tweakin/nms/v1_19_R3/NMSHandler.java b/nms1_19_4/src/main/java/com/github/sachin/tweakin/nms/v1_19_R3/NMSHandler.java
new file mode 100644
index 0000000..c085cfd
--- /dev/null
+++ b/nms1_19_4/src/main/java/com/github/sachin/tweakin/nms/v1_19_R3/NMSHandler.java
@@ -0,0 +1,318 @@
+package com.github.sachin.tweakin.nms.v1_19_R3;
+
+import com.github.sachin.tweakin.modules.betterflee.AnimalFleeTweak;
+import com.github.sachin.tweakin.nbtapi.nms.NMSHelper;
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.properties.Property;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.entity.PathfinderMob;
+import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
+import net.minecraft.world.entity.ai.goal.PanicGoal;
+import net.minecraft.world.entity.ai.goal.TemptGoal;
+import net.minecraft.world.entity.animal.Animal;
+import net.minecraft.world.item.Items;
+import net.minecraft.world.item.MapItem;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.item.crafting.Ingredient;
+import net.minecraft.world.level.block.LiquidBlockContainer;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.material.Fluids;
+import net.minecraft.world.level.saveddata.maps.MapDecoration;
+import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
+import net.minecraft.world.phys.BlockHitResult;
+import net.minecraft.world.phys.Vec3;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
+import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
+import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
+import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
+import org.bukkit.entity.Axolotl;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Frog;
+import org.bukkit.entity.Goat;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Villager;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.persistence.PersistentDataType;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+public class NMSHandler extends NMSHelper {
+
+
+ private net.minecraft.world.item.ItemStack nmsItem;
+ private CompoundTag compound;
+
+ public NMSHandler(){}
+
+ public NMSHandler(ItemStack item){
+ if(item==null) return;
+
+ this.nmsItem = CraftItemStack.asNMSCopy(item);
+ this.compound = nmsItem.getOrCreateTag();
+ }
+
+ @Override
+ public NMSHelper newItem(ItemStack item) {
+ return new NMSHandler(item);
+ }
+
+ @Override
+ public void setString(String key, String value) {
+ compound.putString(key,value);
+ }
+
+ @Override
+ public void setBoolean(String key, boolean value) {
+ compound.putBoolean(key,value);
+ }
+
+ @Override
+ public void setInt(String key, int value) {
+ compound.putInt(key,value);
+ }
+
+ @Override
+ public void setLong(String key, long value) {
+ compound.putLong(key,value);
+ }
+
+ @Override
+ public void setDouble(String key, double value) {
+ compound.putDouble(key,value);
+ }
+
+ @Override
+ public String getString(String key) {
+ return compound.getString(key);
+ }
+
+ @Override
+ public boolean getBoolean(String key) {
+ return compound.getBoolean(key);
+ }
+
+ @Override
+ public int getInt(String key) {
+ return compound.getInt(key);
+ }
+
+ @Override
+ public long getLong(String key) {
+ return compound.getLong(key);
+ }
+
+ @Override
+ public double getDouble(String key) {
+ return compound.getDouble(key);
+ }
+
+ @Override
+ public boolean hasKey(String key) {
+ return compound.contains(key);
+ }
+
+ @Override
+ public org.bukkit.inventory.ItemStack getItem() {
+ nmsItem.save(compound);
+ return CraftItemStack.asBukkitCopy(nmsItem);
+ }
+
+ @Override
+ public void removeKey(String key) {
+ compound.remove(key);
+ }
+
+ @Override
+ public void placeWater(Block block) {
+ Location loc = block.getLocation();
+ BlockPos blockPos = new BlockPos(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
+ ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
+ BlockState iBlockData = level.getBlockState(blockPos);
+ net.minecraft.world.level.block.Block nmsBlock = iBlockData.getBlock();
+ if(nmsBlock instanceof LiquidBlockContainer){
+ ((LiquidBlockContainer)nmsBlock).placeLiquid(level,blockPos,iBlockData, Fluids.WATER.getSource(false));
+ }
+ }
+
+ @Override
+ public void attack(Player player, Entity target) {
+
+ ((CraftPlayer)player).getHandle().attack(((CraftEntity)target).getHandle());
+ ((CraftPlayer)player).getHandle().resetAttackStrengthTicker();
+ }
+
+ @Override
+ public boolean placeItem(Player player, Location location, ItemStack item, BlockFace hitFace, String tweakName, boolean playSound) {
+ net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
+ BlockPos pos = new BlockPos((int) location.getX(), (int) location.getY(), (int) location.getZ());
+ ServerPlayer nmsPlayer = ((CraftPlayer)player).getHandle();
+ UseOnContext context = new UseOnContext(nmsPlayer, InteractionHand.MAIN_HAND, new BlockHitResult(new Vec3(0.5F, 1F, 0.5F), Direction.UP, pos, false));
+ InteractionResult res = nmsItem.useOn(context,InteractionHand.MAIN_HAND);
+
+ if(res==InteractionResult.CONSUME){
+ player.swingMainHand();
+ BlockPos placedPos = context.getClickedPos().relative(context.getClickedFace());
+ Block placedBlock = player.getWorld().getBlockAt(placedPos.getX(),placedPos.getY(),placedPos.getZ());
+ if (placedBlock.getType()==Material.BARRIER){
+ placedBlock.setType(Material.AIR);
+ }
+ if(playSound){
+ player.getWorld().playSound(location, location.getBlock().getBlockData().getSoundGroup().getPlaceSound(), 1F, 1F);
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+
+ @Override
+ public void spawnVillager(Villager villager,boolean update) {
+ net.minecraft.world.entity.npc.Villager vil = (net.minecraft.world.entity.npc.Villager) ((CraftEntity)villager).getHandle();
+ TemptGoal goal = new TemptGoal(vil, 0.6, Ingredient.of(Items.EMERALD_BLOCK), false);
+ if(update){
+ vil.goalSelector.removeGoal(goal);
+ }
+ vil.goalSelector.addGoal(2,goal);
+
+ }
+
+ @Override
+ public void avoidPlayer(Entity entity, Player player, ConfigurationSection config) {
+ Animal animal = (Animal) ((CraftEntity)entity).getHandle();
+ List list = animal.getLevel().getEntitiesOfClass(Animal.class,animal.getBoundingBox().inflate(5));
+ animal.goalSelector.removeGoal(new PanicGoal(animal, 2.0));
+ if(!list.isEmpty()){
+ for (Animal en : list) {
+ Entity bEn = en.getBukkitEntity();
+
+ if(bEn.getType() == entity.getType()){
+ if(bEn.getPersistentDataContainer().has(AnimalFleeTweak.key, PersistentDataType.INTEGER) && config.getBoolean("ignore-breeded")) continue;
+ FleePathFinder goal = new FleePathFinder(en, ServerPlayer.class, config.getInt("max-radius"), config.getDouble("walk-speed"), config.getDouble("sprint-speed"), (pl) -> pl.getUUID() == player.getUniqueId(), config.getInt("cooldown"));
+ en.goalSelector.removeGoal(goal);
+ en.goalSelector.addGoal(1, goal);
+ }
+ }
+ }
+ }
+
+ @Override
+ public ItemStack createMap(Location dist,byte zoom,boolean biomePreview){
+ BlockPos loc = new BlockPos(dist.getBlockX(),dist.getBlockY(),dist.getBlockZ());
+ ServerLevel level = ((CraftWorld) dist.getWorld()).getHandle();
+ net.minecraft.world.item.ItemStack mapItem = MapItem.create(level,dist.getBlockX(),dist.getBlockZ(),zoom,true,true);
+ MapItemSavedData.addTargetDecoration(mapItem,loc,"+", MapDecoration.Type.RED_X);
+ if(biomePreview){
+ MapItem.renderBiomePreviewMap(level,mapItem);
+ }
+ return CraftItemStack.asBukkitCopy(mapItem);
+ }
+
+ @Override
+ public boolean matchAxoltlVariant(Entity entity, String color) {
+ return ((Axolotl)entity).getVariant().toString().equals(color);
+ }
+
+ @Override
+ public boolean matchFrogVariant(Entity entity, String variant) {
+ return ((Frog)entity).getVariant().toString().equals(variant);
+ }
+
+ @Override
+ public boolean isScreamingGoat(Entity entity) {
+ return ((Goat)entity).isScreaming();
+ }
+
+ @Override
+ public List getEntitiesWithinRadius(int radius, Entity center) {
+ net.minecraft.world.entity.Entity entity = ((CraftEntity)center).getHandle();
+ return entity.getLevel().getEntities(entity,entity.getBoundingBox().inflate(radius)).stream().map(net.minecraft.world.entity.Entity::getBukkitEntity).collect(Collectors.toList());
+ }
+
+ @Override
+ public void applyHeadTexture(SkullMeta meta, String b64) {
+ Field metaProfileField ;
+ Method metaSetProfileMethod;
+ try {
+ metaSetProfileMethod = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
+ metaSetProfileMethod.setAccessible(true);
+
+ metaSetProfileMethod.invoke(meta, makeProfile(b64));
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+ try {
+ metaProfileField = meta.getClass().getDeclaredField("profile");
+ metaProfileField.setAccessible(true);
+
+ metaProfileField.set(meta, makeProfile(b64));
+
+ } catch (NoSuchFieldException | IllegalAccessException ex2) {
+ ex2.printStackTrace();
+ }
+ }
+ }
+
+ public GameProfile makeProfile(String b64) {
+ UUID id = new UUID(b64.substring(b64.length() - 20).hashCode(),b64.substring(b64.length() - 10).hashCode());
+ GameProfile profile = new GameProfile(id, "someName");
+ profile.getProperties().put("textures", new Property("textures", b64));
+ return profile;
+ }
+
+
+ private static class FleePathFinder extends AvoidEntityGoal{
+
+ private int cooldown;
+
+ private final int finalCoolDown;
+
+
+ public FleePathFinder(PathfinderMob entity, Class avoider, float maxDis, double walkSpeedModifier, double sprintSpeedModifier,
+ Predicate condition, int cooldown) {
+ super(entity, avoider, maxDis, walkSpeedModifier, sprintSpeedModifier, condition);
+ this.finalCoolDown = cooldown*20;
+ this.cooldown = finalCoolDown;
+ }
+
+ @Override
+ public boolean canUse() {
+ if(cooldown==0){
+ return false;
+ }
+ else{
+ cooldown--;
+ return super.canUse();
+ }
+ }
+
+ @Override
+ public boolean canContinueToUse() {
+ if(cooldown==0){
+ this.cooldown = this.finalCoolDown;
+ }
+ if(cooldown==finalCoolDown){
+ return false;
+ }
+ return super.canContinueToUse();
+ }
+ }
+
+}
+
diff --git a/pom.xml b/pom.xml
index b62afa8..1b5a1cc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,6 +12,8 @@
dist
nms1_19
nms1_19_1
+ nms1_19_3
+ nms1_19_4
nms1_18_R2
nms1_17_R1