mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-07-29 00:43:12 +00:00
Copy the yaw/pitch of the player when creating fixed effects
This commit is contained in:
parent
cc528e91d6
commit
46fc435a96
9 changed files with 75 additions and 19 deletions
|
@ -865,7 +865,7 @@ public final class PlayerParticlesAPI {
|
|||
if (fixedEffect == null)
|
||||
return null;
|
||||
|
||||
fixedEffect.setCoordinates(location.getX(), location.getY(), location.getZ());
|
||||
fixedEffect.setCoordinates(location);
|
||||
dataManager.saveFixedEffect(fixedEffect);
|
||||
return fixedEffect;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,9 @@ public class FixedCommandModule implements CommandModule {
|
|||
}
|
||||
|
||||
if (player != null) {
|
||||
location.setYaw(player.getLocation().getYaw());
|
||||
location.setPitch(player.getLocation().getPitch());
|
||||
|
||||
double distanceFromEffect = player.getLocation().distance(location);
|
||||
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
|
||||
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
|
||||
|
@ -292,6 +295,9 @@ public class FixedCommandModule implements CommandModule {
|
|||
}
|
||||
|
||||
if (player != null) {
|
||||
location.setYaw(player.getLocation().getYaw());
|
||||
location.setPitch(player.getLocation().getPitch());
|
||||
|
||||
double distanceFromEffect = player.getLocation().distance(location);
|
||||
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
|
||||
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
|
||||
|
@ -300,7 +306,7 @@ public class FixedCommandModule implements CommandModule {
|
|||
}
|
||||
}
|
||||
|
||||
fixedEffect.setCoordinates(location.getX(), location.getY(), location.getZ());
|
||||
fixedEffect.setCoordinates(location);
|
||||
break;
|
||||
case "effect": {
|
||||
ParticleEffect effect = inputParser.next(ParticleEffect.class);
|
||||
|
|
|
@ -163,10 +163,11 @@ public class GroupCommandModule implements CommandModule {
|
|||
// Update group and notify player
|
||||
PlayerParticlesAPI.getInstance().savePlayerParticleGroup(pplayer.getPlayer(), activeGroup);
|
||||
|
||||
if (!isPreset)
|
||||
if (!isPreset) {
|
||||
localeManager.sendMessage(pplayer, "group-load-success", StringPlaceholders.builder("amount", activeGroup.getParticles().size()).addPlaceholder("name", groupName).build());
|
||||
else
|
||||
} else {
|
||||
localeManager.sendMessage(pplayer, "group-load-preset-success", StringPlaceholders.builder("amount", activeGroup.getParticles().size()).addPlaceholder("name", groupName).build());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package dev.esophose.playerparticles.database.migrations;
|
||||
|
||||
import dev.esophose.playerparticles.database.DataMigration;
|
||||
import dev.esophose.playerparticles.database.DatabaseConnector;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class _4_Add_Fixed_Effect_Yaw_Pitch_Columns extends DataMigration {
|
||||
|
||||
public _4_Add_Fixed_Effect_Yaw_Pitch_Columns() {
|
||||
super(4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(DatabaseConnector connector, Connection connection, String tablePrefix) throws SQLException {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate("ALTER TABLE " + tablePrefix + "fixed ADD COLUMN yaw DOUBLE DEFAULT 0");
|
||||
statement.executeUpdate("ALTER TABLE " + tablePrefix + "fixed ADD COLUMN pitch DOUBLE DEFAULT 0");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ public class DataManager extends Manager {
|
|||
}
|
||||
|
||||
// Load fixed effects
|
||||
String fixedQuery = "SELECT f.id AS f_id, f.world, f.xPos, f.yPos, f.zPos, p.id AS p_id, p.effect, p.style, p.item_material, p.block_material, p.note, p.r, p.g, p.b, p.r_end, p.g_end, p.b_end, p.duration FROM " + this.getTablePrefix() + "fixed f " +
|
||||
String fixedQuery = "SELECT f.id AS f_id, f.world, f.xPos, f.yPos, f.zPos, f.yaw, f.pitch, p.id AS p_id, p.effect, p.style, p.item_material, p.block_material, p.note, p.r, p.g, p.b, p.r_end, p.g_end, p.b_end, p.duration FROM " + this.getTablePrefix() + "fixed f " +
|
||||
"JOIN " + this.getTablePrefix() + "particle p ON f.particle_uuid = p.uuid " +
|
||||
"WHERE f.owner_uuid = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(fixedQuery)) {
|
||||
|
@ -213,6 +213,8 @@ public class DataManager extends Manager {
|
|||
double xPos = result.getDouble("xPos");
|
||||
double yPos = result.getDouble("yPos");
|
||||
double zPos = result.getDouble("zPos");
|
||||
double yaw = result.getDouble("yaw");
|
||||
double pitch = result.getDouble("pitch");
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
if (world == null) {
|
||||
// World was deleted, remove the fixed effect as it is no longer valid
|
||||
|
@ -240,7 +242,7 @@ public class DataManager extends Manager {
|
|||
continue;
|
||||
}
|
||||
|
||||
fixedParticles.put(fixedEffectId, new FixedParticleEffect(playerUUID, fixedEffectId, new Location(world, xPos, yPos, zPos), particle));
|
||||
fixedParticles.put(fixedEffectId, new FixedParticleEffect(playerUUID, fixedEffectId, new Location(world, xPos, yPos, zPos, (float) yaw, (float) pitch), particle));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,7 +493,7 @@ public class DataManager extends Manager {
|
|||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String fixedEffectQuery = "INSERT INTO " + this.getTablePrefix() + "fixed (owner_uuid, id, particle_uuid, world, xPos, yPos, zPos) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
String fixedEffectQuery = "INSERT INTO " + this.getTablePrefix() + "fixed (owner_uuid, id, particle_uuid, world, xPos, yPos, zPos, yaw, pitch) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) {
|
||||
statement.setString(1, fixedEffect.getOwnerUniqueId().toString());
|
||||
statement.setInt(2, fixedEffect.getId());
|
||||
|
@ -500,6 +502,8 @@ public class DataManager extends Manager {
|
|||
statement.setDouble(5, fixedEffect.getLocation().getX());
|
||||
statement.setDouble(6, fixedEffect.getLocation().getY());
|
||||
statement.setDouble(7, fixedEffect.getLocation().getZ());
|
||||
statement.setDouble(8, fixedEffect.getLocation().getYaw());
|
||||
statement.setDouble(9, fixedEffect.getLocation().getPitch());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}));
|
||||
|
@ -513,13 +517,15 @@ public class DataManager extends Manager {
|
|||
public void updateFixedEffect(FixedParticleEffect fixedEffect) {
|
||||
this.async(() -> this.databaseConnector.connect((connection) -> {
|
||||
// Update fixed effect
|
||||
String fixedEffectQuery = "UPDATE " + this.getTablePrefix() + "fixed SET xPos = ?, yPos = ?, zPos = ? WHERE owner_uuid = ? AND id = ?";
|
||||
String fixedEffectQuery = "UPDATE " + this.getTablePrefix() + "fixed SET xPos = ?, yPos = ?, zPos = ?, yaw = ?, pitch = ? WHERE owner_uuid = ? AND id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) {
|
||||
statement.setDouble(1, fixedEffect.getLocation().getX());
|
||||
statement.setDouble(2, fixedEffect.getLocation().getY());
|
||||
statement.setDouble(3, fixedEffect.getLocation().getZ());
|
||||
statement.setString(4, fixedEffect.getOwnerUniqueId().toString());
|
||||
statement.setInt(5, fixedEffect.getId());
|
||||
statement.setDouble(4, fixedEffect.getLocation().getYaw());
|
||||
statement.setDouble(5, fixedEffect.getLocation().getPitch());
|
||||
statement.setString(6, fixedEffect.getOwnerUniqueId().toString());
|
||||
statement.setInt(7, fixedEffect.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
|
@ -588,7 +594,7 @@ public class DataManager extends Manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Asynchronizes the callback with it's own thread unless it is already not on the main thread
|
||||
* Asynchronizes the callback with its own thread unless it is already not on the main thread
|
||||
*
|
||||
* @param asyncCallback The callback to run on a separate thread
|
||||
*/
|
||||
|
|
|
@ -7,6 +7,7 @@ import dev.esophose.playerparticles.database.SQLiteConnector;
|
|||
import dev.esophose.playerparticles.database.migrations._1_InitialMigration;
|
||||
import dev.esophose.playerparticles.database.migrations._2_Add_Data_Columns;
|
||||
import dev.esophose.playerparticles.database.migrations._3_Add_Setting_Toggle_Self_Column;
|
||||
import dev.esophose.playerparticles.database.migrations._4_Add_Fixed_Effect_Yaw_Pitch_Columns;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Arrays;
|
||||
|
@ -24,7 +25,8 @@ public class DataMigrationManager extends Manager {
|
|||
this.migrations = Arrays.asList(
|
||||
new _1_InitialMigration(),
|
||||
new _2_Add_Data_Columns(),
|
||||
new _3_Add_Setting_Toggle_Self_Column()
|
||||
new _3_Add_Setting_Toggle_Self_Column(),
|
||||
new _4_Add_Fixed_Effect_Yaw_Pitch_Columns()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,15 +94,23 @@ public class GuiManager extends Manager implements Listener, Runnable {
|
|||
* Used for when the plugin unloads so players can't take items from the GUI
|
||||
*/
|
||||
public void forceCloseAllOpenGUIs() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (GuiInventory inventory : this.guiInventories) {
|
||||
if (inventory.getPPlayer().getUniqueId().equals(player.getUniqueId()) && inventory.getInventory().equals(player.getOpenInventory().getTopInventory())) {
|
||||
player.closeInventory();
|
||||
break;
|
||||
Runnable task = () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (GuiInventory inventory : this.guiInventories) {
|
||||
if (inventory.getPPlayer().getUniqueId().equals(player.getUniqueId()) && inventory.getInventory().equals(player.getOpenInventory().getTopInventory())) {
|
||||
player.closeInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.guiInventories.clear();
|
||||
};
|
||||
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
task.run();
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(this.playerParticles, task);
|
||||
}
|
||||
this.guiInventories.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,4 +90,13 @@ public class FixedParticleEffect {
|
|||
this.location.setZ(z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the coordinates of the FixedParticleEffect
|
||||
*
|
||||
* @param location The new Location
|
||||
*/
|
||||
public void setCoordinates(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ParticleStyleWings extends ConfiguredParticleStyle {
|
|||
private int spawnDelay;
|
||||
|
||||
protected ParticleStyleWings() {
|
||||
super("wings", false, true, 0);
|
||||
super("wings", true, true, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue