Skip to content

Commit

Permalink
Adds DisplayInfo
Browse files Browse the repository at this point in the history
Fixes WalletOwnerManager
  • Loading branch information
anjoismysign committed Mar 31, 2024
1 parent 0d1d0ea commit b2411cf
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ci-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.11</version>
<version>1.698.12</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.11</version>
<version>1.698.12</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.11</version>
<version>1.698.12</version>
<packaging>pom</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ public boolean getBoolean(String key) {
}

public double getDouble(String key) {
return (double) getValue(key);
try {
return (double) getValue(key);
} catch (ClassCastException e) {
return Double.valueOf((Float) getValue(key));
}
}

public long getLong(String key) {
return (long) getValue(key);
try {
return (long) getValue(key);
} catch (ClassCastException e) {
return Long.valueOf((Integer) getValue(key));
}
}

public float getFloat(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,35 @@ public void onPrejoin(AsyncPlayerPreLoginEvent e) {
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
UUID uuid = player.getUniqueId();
CompletableFuture<BlobCrudable> future = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
if (player == null || !player.isOnline()) {
future.completeExceptionally(new NullPointerException("Player is null"));
return;
}
BlobCrudable crudable = crudManager.read(uuid.toString());
future.complete(crudable);
});
future.thenAccept(crudable -> {
if (player == null || !player.isOnline())
return;
T applied = generator.apply(crudable);
BlobCrudable serialized = applied.serializeAllAttributes();
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(),
() -> crudManager.update(serialized));
walletOwners.put(uuid, applied);
if (joinEvent == null)
return;
Bukkit.getPluginManager().callEvent(joinEvent.apply(applied));
autoSave.put(uuid, new BukkitRunnable() {
@Override
public void run() {
if (player == null || !player.isOnline()) {
cancel();
return;
BlobCrudable crudable = crudManager.read(uuid.toString());
Bukkit.getScheduler().runTask(plugin, () -> {
if (player == null || !player.isOnline())
return;
T applied = generator.apply(crudable);
BlobCrudable serialized = applied.serializeAllAttributes();
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(),
() -> crudManager.update(serialized));
walletOwners.put(uuid, applied);
if (joinEvent == null)
return;
Bukkit.getPluginManager().callEvent(joinEvent.apply(applied));
autoSave.put(uuid, new BukkitRunnable() {
@Override
public void run() {
if (player == null || !player.isOnline()) {
cancel();
return;
}
BlobCrudable serialized = applied.serializeAllAttributes();
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(),
() -> crudManager.update(serialized));
}
BlobCrudable serialized = applied.serializeAllAttributes();
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(),
() -> crudManager.update(serialized));
}
}.runTaskTimer(getPlugin(), 20 * 60 * 5,
20 * 60 * 5));
}.runTaskTimer(getPlugin(), 20 * 60 * 5,
20 * 60 * 5));
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Display;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Objects;

/**
* Holds all data that DisplayEntities hold except
Expand Down Expand Up @@ -37,6 +39,22 @@ public record DisplayData(Display.Brightness brightness,
null, false,
1, 0, 1);

/**
* Gets a DisplayData instance from the given Display.
*
* @param display the Display to get the DisplayData from
* @return the DisplayData from the given Display
*/
public static DisplayData of(@NotNull Display display) {
Objects.requireNonNull(display, "'display' cannot be null");
return new DisplayData(display.getBrightness(), display.getBillboard(),
display.getShadowRadius(), display.getShadowStrength(),
display.getViewRange(), display.getDisplayWidth(), display.getDisplayHeight(),
display.getGlowColorOverride(), true,
display.getInterpolationDuration(), display.getInterpolationDelay(),
display.getTeleportDuration());
}

/**
* Will apply the DisplayData to the given Display.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package us.mytheria.bloblib.entities.display;

import org.bukkit.entity.Display;
import org.bukkit.util.Transformation;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.util.Objects;

public record DisplayInfo(@NotNull DisplayData getDisplayData,
@NotNull Transformation getTransformation) {

/**
* Gets a DisplayInfo instance from the given Display.
*
* @param display the Display to get the DisplayInfo from
* @return the DisplayInfo from the given Display
*/
public static DisplayInfo of(@NotNull Display display) {
Objects.requireNonNull(display, "'display' cannot be null");
Transformation transformation = display.getTransformation();
Vector3f translation = transformation.getTranslation();
Quaternionf leftRotation = transformation.getLeftRotation();
Vector3f scale = transformation.getScale();
Quaternionf rightRotation = transformation.getRightRotation();
return new DisplayInfo(DisplayData.of(display),
new Transformation(
new Vector3f(translation.x, translation.y, translation.z),
new Quaternionf(leftRotation.x, leftRotation.y, leftRotation.z, leftRotation.w),
new Vector3f(scale.x, scale.y, scale.z),
new Quaternionf(rightRotation.x, rightRotation.y, rightRotation.z, rightRotation.w)));
}

/**
* Applies the DisplayInfo to the given Display.
*
* @param display the Display to apply the DisplayInfo to
*/
public void apply(@NotNull Display display) {
getDisplayData.apply(display);
display.setTransformation(getTransformation());
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Listeners:
TinyListeners:
Display-Unriding: true
Display-Unriding: false
Locale:
Console: en_us
Default-To:
Expand Down

0 comments on commit b2411cf

Please sign in to comment.