Skip to content

Commit

Permalink
Merge pull request #21 from PZDonny/develop
Browse files Browse the repository at this point in the history
2.6.0 | Animation State Machines, Improved Mythic Mobs, and QOL
  • Loading branch information
PZDonny authored Jan 17, 2025
2 parents 2e19a79 + cc9a581 commit 1406b79
Show file tree
Hide file tree
Showing 57 changed files with 3,136 additions and 854 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.donnypz</groupId>
<artifactId>displayentityutils</artifactId>
<version>2.5.7</version>
<version>2.6.0</version>
<packaging>jar</packaging>

<name>DisplayEntityUtils</name>
Expand Down
55 changes: 15 additions & 40 deletions src/main/java/net/donnypz/displayentityutils/ConfigUtils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.donnypz.displayentityutils;

import net.donnypz.displayentityutils.managers.LoadMethod;
import net.donnypz.displayentityutils.managers.LocalManager;
import net.donnypz.displayentityutils.managers.MYSQLManager;
import net.donnypz.displayentityutils.managers.MongoManager;
import net.donnypz.displayentityutils.utils.CullOption;
import net.donnypz.displayentityutils.utils.FollowType;
import net.donnypz.displayentityutils.utils.mythic.MythicDisplayManager;
import net.donnypz.displayentityutils.utils.mythic.MythicDisplayOptions;
import net.donnypz.displayentityutils.utils.controller.DisplayController;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
Expand All @@ -15,54 +13,31 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

final class ConfigUtils {

private ConfigUtils(){}

static void registerMythic(){
File file = new File(DisplayEntityPlugin.getInstance().getDataFolder(), "/mythicgroups.yml");
InputStream in = DisplayEntityPlugin.getInstance().getResource("mythicgroups.yml");
if (!file.exists()){
static void registerMobControllers(){
DisplayController.unregisterConfigControllers();
File controllerFolder = LocalManager.getDisplayControllerFolder();
if (!controllerFolder.exists()){
try{
Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
controllerFolder.mkdirs();
}
catch(IOException | SecurityException e){
Bukkit.getLogger().severe("Failed to create \"mythicgroups.yml\" file for MythicMobs!");
catch(SecurityException e){
Bukkit.getLogger().severe("Failed to find \"displaycontrollers\" folder for MythicMobs!");
return;
}
return;
}
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
for (String key : config.getKeys(false)){
String groupTag = config.getString(key+".groupTag");
LoadMethod loadMethod;
try{
loadMethod = LoadMethod.valueOf(config.getString(key+".groupStorageLocation"));
}
catch(IllegalArgumentException e){
throw new IllegalArgumentException("Invalid \"groupStorageLocation\" for "+key);
}
FollowType followType;
try{
followType = FollowType.valueOf(config.getString(key+".entityFollowType"));
}
catch(IllegalArgumentException e){
throw new IllegalArgumentException("Invalid \"entityFollowType\" for "+key);
}

int deathDespawnDelay = config.getInt(key+".deathDespawnDelay");
int teleportationDuration = config.getInt(key+".teleportationDuration");
boolean pivotInteractions = config.getBoolean(key+".pivotInteractions");


MythicDisplayOptions options = new MythicDisplayOptions(groupTag, loadMethod, followType, deathDespawnDelay, pivotInteractions, teleportationDuration);
MythicDisplayManager.setAssignedGroup(key, options);
Bukkit.getConsoleSender().sendMessage(DisplayEntityPlugin.pluginPrefix
.append(Component.text("Registered Mythic Mob - (Mob:"+key+" | Group:"+groupTag+")", NamedTextColor.YELLOW)));
for (File file : controllerFolder.listFiles()){
if (!file.getName().endsWith(".yml")){
continue;
}
DisplayController.read(file);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
import net.donnypz.displayentityutils.events.PreInteractionClickEvent;
import net.donnypz.displayentityutils.listeners.autoGroup.DEULoadingListeners;
import net.donnypz.displayentityutils.listeners.bdengine.DEUEntitySpawned;
import net.donnypz.displayentityutils.listeners.mythic.DEUMythicListener;
import net.donnypz.displayentityutils.listeners.entity.DEUEntityListener;
import net.donnypz.displayentityutils.listeners.entity.DEUMythicListener;
import net.donnypz.displayentityutils.listeners.player.DEUPlayerChatListener;
import net.donnypz.displayentityutils.listeners.player.DEUPlayerConnectionListener;
import net.donnypz.displayentityutils.managers.LocalManager;
import net.donnypz.displayentityutils.managers.MYSQLManager;
import net.donnypz.displayentityutils.managers.MongoManager;
import net.donnypz.displayentityutils.utils.CullOption;
import net.donnypz.displayentityutils.utils.DisplayEntities.MachineState;
import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityGroup;
import net.donnypz.displayentityutils.utils.DisplayUtils;
import net.donnypz.displayentityutils.command.DisplayEntityPluginCommand;
import net.donnypz.displayentityutils.utils.InteractionCommand;
import net.donnypz.displayentityutils.utils.deu.ParticleDisplay;
import net.donnypz.displayentityutils.utils.controller.DisplayController;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.md_5.bungee.api.ChatColor;
Expand All @@ -30,9 +33,15 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.ApiStatus;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;

public final class DisplayEntityPlugin extends JavaPlugin implements Listener {
Expand Down Expand Up @@ -95,6 +104,7 @@ public void onEnable() {
}
Bukkit.getPluginManager().registerEvents(new DEUPlayerConnectionListener(), this);
Bukkit.getPluginManager().registerEvents(new DEUPlayerChatListener(), this);
Bukkit.getPluginManager().registerEvents(new DEUEntityListener(), this);



Expand All @@ -120,6 +130,16 @@ private void createLocalSaveFolders(){
if (!LocalManager.getAnimationDatapackFolder().exists()){
LocalManager.getAnimationDatapackFolder().mkdirs();
}
if (!LocalManager.getDisplayControllerFolder().exists()){
LocalManager.getDisplayControllerFolder().mkdirs();
String exampleController = "examplecontroller.yml";
File exampleFile = new File(LocalManager.getDisplayControllerFolder(), exampleController);
InputStream stream = DisplayEntityPlugin.getInstance().getResource(exampleController);
try {
Files.copy(stream, exampleFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
stream.close();
} catch (IOException e) {}
}
}

public static NamespacedKey getPartUUIDKey() {
Expand Down Expand Up @@ -307,26 +327,35 @@ public static String getLegacyPartTagPrefix(){
* Reload the plugin's config
*/
public void reloadPlugin(boolean isOnEnable){
createLocalSaveFolders();

if (!isOnEnable){
MongoManager.closeConnection();
MYSQLManager.closeConnection();
}
else{
saveDefaultConfig();
ConfigUtils.updateConfig();
ConfigUtils.registerMythic();
}

reloadConfig();
ConfigUtils.setConfigVariables(getConfig());
createLocalSaveFolders();
ConfigUtils.registerMobControllers();
}

/**
* Reload the registered MythicMob Groups from the "mythicgroups.yml" file
* Reload the registered {@link DisplayController}s from the "mythicgroups.yml" file
*/
public void reloadMythic(){
ConfigUtils.registerMythic();
public void reloadControllers(){
ConfigUtils.registerMobControllers();
}

@EventHandler(priority = EventPriority.LOW)
private void onStart(ServerLoadEvent e){
if (e.getType() == ServerLoadEvent.LoadType.RELOAD){
return;
}
MachineState.registerNullLoaderStates();
DisplayController.registerNullLoaderControllers();
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand All @@ -335,11 +364,7 @@ private void rClick(PlayerInteractEntityEvent e){
return;
}
if (e.getRightClicked() instanceof Interaction entity){
if (!new PreInteractionClickEvent(e.getPlayer(), entity, InteractionClickEvent.ClickType.RIGHT).callEvent()){
return;
}
List<InteractionCommand> commands = DisplayUtils.getInteractionCommandsWithData(entity);
callInteractionEvent(new InteractionClickEvent(e.getPlayer(), entity, InteractionClickEvent.ClickType.RIGHT, commands));
determineAction(entity, e.getPlayer(), InteractionClickEvent.ClickType.RIGHT);
}
}

Expand All @@ -349,53 +374,54 @@ private void lClick(EntityDamageByEntityEvent e){
return;
}
if (e.getEntity() instanceof Interaction entity){
if (!new PreInteractionClickEvent((Player) e.getDamager(), entity, InteractionClickEvent.ClickType.LEFT).callEvent()){
return;
}
List<InteractionCommand> commands = DisplayUtils.getInteractionCommandsWithData(entity);
callInteractionEvent(new InteractionClickEvent((Player) e.getDamager(), entity, InteractionClickEvent.ClickType.LEFT, commands));
determineAction(entity, (Player) e.getDamager(), InteractionClickEvent.ClickType.LEFT);
}
}

private void callInteractionEvent(InteractionClickEvent event){
Interaction i = event.getInteraction();

//Particle Displays
if (ParticleDisplay.isParticleDisplay(i)){
Player p = event.getPlayer();
if (event.getClickType() == InteractionClickEvent.ClickType.RIGHT){
if (p.isSneaking()){
if (!DisplayEntityPluginCommand.hasPermission(p, Permission.ANIM_REMOVE_PARTICLE)){
private void determineAction(Interaction interaction, Player player, InteractionClickEvent.ClickType clickType){
//Particle Displays
if (ParticleDisplay.isParticleDisplay(interaction)){
if (clickType == InteractionClickEvent.ClickType.RIGHT){
if (player.isSneaking()){
if (!DisplayEntityPluginCommand.hasPermission(player, Permission.ANIM_REMOVE_PARTICLE)){
return;
}
boolean result = ParticleDisplay.delete(i.getUniqueId());
boolean result = ParticleDisplay.delete(interaction.getUniqueId());
if (result){
p.sendMessage(pluginPrefix.append(Component.text("Successfully removed particle from frame!", NamedTextColor.YELLOW)));
player.sendMessage(pluginPrefix.append(Component.text("Successfully removed particle from frame!", NamedTextColor.YELLOW)));
}
else{
p.sendMessage(pluginPrefix.append(Component.text("This particle has already been removed by another player or other methods!", NamedTextColor.RED)));
player.sendMessage(pluginPrefix.append(Component.text("This particle has already been removed by another player or other methods!", NamedTextColor.RED)));
}
}
else{
ParticleDisplay particle = ParticleDisplay.get(i.getUniqueId());
ParticleDisplay particle = ParticleDisplay.get(interaction.getUniqueId());
if (particle == null){
p.sendMessage(Component.text("Failed to get particle", NamedTextColor.RED));
player.sendMessage(Component.text("Failed to get particle", NamedTextColor.RED));
return;
}
particle.spawn();
p.sendMessage(Component.text("Particle Spawned", NamedTextColor.GREEN));
player.sendMessage(Component.text("Particle Spawned", NamedTextColor.GREEN));
}
}
else{
ParticleDisplay.sendInfo(i.getUniqueId(), p);
ParticleDisplay.sendInfo(interaction.getUniqueId(), player);
}
return;
}

if (!new PreInteractionClickEvent(player, interaction, clickType).callEvent()){
return;
}

List<InteractionCommand> commands = DisplayUtils.getInteractionCommandsWithData(interaction);
InteractionClickEvent event = new InteractionClickEvent(player, interaction, clickType, commands);

if (!event.callEvent()){
return;
}

//Commands
Player p = event.getPlayer();
for (InteractionCommand cmd : event.getCommands()){
if (cmd.isLeftClick() && event.getClickType() == InteractionClickEvent.ClickType.LEFT){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ public void execute(Player player, String[] args) {
throw new NumberFormatException();
}
SpawnedDisplayAnimationFrame frame = new SpawnedDisplayAnimationFrame(delay, duration);
anim.addFrame(frame);
if (anim.isPartAnimation()) {
frame.setTransformation(group, anim.getPartTag());
} else {
frame.setTransformation(group);
}
boolean isUnique = anim.addFrame(frame);
if (isUnique){
player.sendMessage(DisplayEntityPlugin.pluginPrefix.append(Component.text("Successfully captured animation frame", NamedTextColor.GREEN)));
player.playSound(player, Sound.ENTITY_SHEEP_SHEAR, 1, 0.75f);
}
else{
player.sendMessage(DisplayEntityPlugin.pluginPrefix.append(Component.text("Merged frame delay and duration with previous frame!", NamedTextColor.YELLOW)));
player.sendMessage(Component.text("| Duplicate frame data", NamedTextColor.YELLOW));
player.playSound(player, Sound.ENTITY_SHEEP_SHEAR, 1, 0.5f);
}
player.sendMessage(Component.text("| Delay: "+delay, NamedTextColor.GRAY));
player.sendMessage(Component.text("| Duration: "+duration, NamedTextColor.GRAY));

player.sendMessage(DisplayEntityPlugin.pluginPrefix.append(Component.text("Successfully captured animation frame", NamedTextColor.GREEN)));
player.playSound(player, Sound.ENTITY_SHEEP_SHEAR, 1, 0.75f);
} catch (NumberFormatException e) {
player.sendMessage(Component.text("Invalid value entered for delay or duration! Enter a whole number >= 0", NamedTextColor.RED));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void execute(Player player, String[] args) {
player.sendMessage("Animation Part Tag: " + ChatColor.YELLOW + animation.getPartTag());
}
player.sendMessage("Total Frames: " + ChatColor.YELLOW + animation.getFrames().size());
player.sendMessage("Total Duration: "+ChatColor.YELLOW+animation.getDuration()+" ticks");
player.sendMessage("Respect Scale: " + ChatColor.YELLOW + animation.groupScaleRespect());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.donnypz.displayentityutils.command;

import net.donnypz.displayentityutils.DisplayEntityPlugin;
import net.donnypz.displayentityutils.managers.DisplayAnimationManager;
import net.donnypz.displayentityutils.managers.DisplayGroupManager;
import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayAnimation;
import net.donnypz.displayentityutils.utils.DisplayEntities.SpawnedDisplayEntityGroup;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -22,13 +20,8 @@ public void execute(Player player, String[] args) {
return;
}

SpawnedDisplayAnimation anim = DisplayAnimationManager.getSelectedSpawnedAnimation(player);
if (anim == null) {
AnimCMD.noAnimationSelection(player);
return;
}

group.stopAnimation(true);
player.sendMessage(DisplayEntityPlugin.pluginPrefix.append(Component.text("Stopping a animation played on group!", NamedTextColor.YELLOW)));
player.sendMessage(DisplayEntityPlugin.pluginPrefix.append(Component.text("Stopping any animation played on your selected group!", NamedTextColor.YELLOW)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static void noPartSelectionInteraction(Player player){
player.sendMessage(Component.text("/mdis parts select <part-tag>", NamedTextColor.GRAY));
}

static void suggestUpdateSelection(Player player){
player.sendMessage(Component.text("| It is recommended to update/reset your part selection after adding parts!", NamedTextColor.GRAY));
player.sendMessage(Component.text("| Quickly reset with \"/mdis parts deselect", NamedTextColor.GRAY));
}

public static boolean hasPermission(Player player, Permission permission){
if (!player.hasPermission(permission.getPermission())){
player.sendMessage(Component.text("You do not have permission to do that!", NamedTextColor.RED));
Expand Down Expand Up @@ -133,6 +138,6 @@ static void mainCommandHelp(CommandSender sender){
CMDUtils.sendCMD(sender, "/mdis listgroups <storage> [page-number]");
CMDUtils.sendCMD(sender, "/mdis listanims <storage> [page-number]");
CMDUtils.sendCMD(sender, "/mdis bdengine", " (Import models from BDEngine or convert animations)");
CMDUtils.sendCMD(sender, "/mdis reload <config | mythic>", " (To reload Local, MySQL or MongoDB config save options, the server must be restarted)");
CMDUtils.sendCMD(sender, "/mdis reload <config | controllers>", " (To reload Local, MySQL or MongoDB config save options, the server must be restarted)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case "listgroups", "listanim" -> addStorages(suggestions);
case "reload" -> {
suggestions.add("config");
suggestions.add("mythic");
suggestions.add("controllers");
}
}
}
Expand Down Expand Up @@ -130,6 +130,11 @@ else if (args.length == 3){
suggestions.add("console");
}
}
case "text" -> {
if (args[1].equalsIgnoreCase("background")){
addColors(suggestions);
}
}
}
}
else if (args.length == 4) {
Expand Down
Loading

0 comments on commit 1406b79

Please sign in to comment.