Skip to content

Commit

Permalink
**2.0.1-Build 11**
Browse files Browse the repository at this point in the history
* Fixed display offsets for older mc versions
* Fixed several performance issues
* Fixed some numeric parsing issues
* Adjustments to utilities to better target Diaplay entities

Signed-off-by: Jeremiah Osborne <[email protected]>
  • Loading branch information
XZot1K authored and Jeremiah Osborne committed Jun 26, 2024
1 parent 0f6019e commit a3b30f8
Show file tree
Hide file tree
Showing 34 changed files with 429 additions and 428 deletions.
4 changes: 2 additions & 2 deletions Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

<core.build>10</core.build>
<core.build>11</core.build>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -40,7 +40,7 @@
<configuration>
<archive>
<manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
<paperweight-mappings-namespace>spigot</paperweight-mappings-namespace>
</manifestEntries>
</archive>
</configuration>
Expand Down
4 changes: 3 additions & 1 deletion Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public void onEnable() {
setup();
} catch (ClassNotFoundException e) {e.printStackTrace();}

if (getDisplayManager() != null) {Display.ClearAllEntities();}

setPaperSpigot(false);
Method[] methods = World.class.getMethods();
if (methods.length > 0) for (int i = -1; ++i < methods.length; ) {
Expand Down Expand Up @@ -249,7 +251,7 @@ else if (isOutdated())
public void onDisable() {
getServer().getScheduler().cancelTasks(this);

if (getPluginInstance().getDisplayManager() != null) {Display.ClearAllEntities();}
if (getDisplayManager() != null) {Display.ClearAllEntities();}

if (getManager() != null) {
final int[] shopSaveCount = {0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,14 @@ public void performCurrencyTransfer(boolean canNotBypass) {
}

if (getEconomyCallType() == EconomyCallType.SELL) {
INSTANCE.getEconomyHandler().deposit(getPlayer(), getShop(), getAmount(), getEconomyCallType());

if (getShop() != null && !getShop().isAdminShop()) {
if (INSTANCE.getConfig().getBoolean("sync-owner-balance")) {
final OfflinePlayer shopOwner = INSTANCE.getServer().getOfflinePlayer(getShop().getOwnerUniqueId());
INSTANCE.getEconomyHandler().withdraw(shopOwner, getShop(), getTaxedAmount(), economyCallType);
return;
}

getShop().setStoredBalance(Math.max((getShop().getStoredBalance() - getTaxedAmount()), 0));
} else getShop().setStoredBalance(Math.max((getShop().getStoredBalance() - getTaxedAmount()), 0));
}

INSTANCE.getEconomyHandler().deposit(getPlayer(), getShop(), getAmount(), getEconomyCallType());
return;
}

Expand Down
72 changes: 29 additions & 43 deletions Core/src/main/java/xzot1k/plugins/ds/api/objects/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.md_5.bungee.api.ChatColor;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -14,77 +15,59 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Display {

public static NamespacedKey key = new NamespacedKey(DisplayShops.getPluginInstance(), "DisplayShops-Entity");
public static final ItemStack barrier = new ItemStack(Material.BARRIER);

private final Shop shop;
//private final List<TextDisplay> lines = new ArrayList<>();
private Entity textDisplay, itemDisplay, blockDisplay;
//private final List<Integer> usedLines = new ArrayList<>();

// private final int duration = 5 * 20;
// private float scale = 0.5f;
// private Matrix4f mat = new Matrix4f();

public Display(@NotNull Shop shop) {
this.shop = shop;
//update();
}

public static void ClearAllEntities() {
DisplayShops.getPluginInstance().getServer().getWorlds().forEach(world -> {
world.getEntities().forEach(entity -> {
if ((entity.getType() == EntityType.ARMOR_STAND || entity.getType() == EntityType.ITEM_FRAME) && (entity.hasMetadata("DisplayShops-Entity")
|| entity.getPersistentDataContainer().has(key))) {entity.remove();}
});
});
for (World world : DisplayShops.getPluginInstance().getServer().getWorlds()) {
for (Entity entity : world.getEntities()) {
if ((entity.getType() == EntityType.ARMOR_STAND || entity.getType() == EntityType.ITEM_FRAME || entity.getType().name().endsWith("_DISPLAY"))
&& (entity.hasMetadata("DisplayShops-Entity") || entity.getPersistentDataContainer().has(key))) {entity.remove();}
}
}

DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().values().forEach(display -> {
//if (display.getItem() != null) {display.getItem().remove();}
for (Map.Entry<UUID, Display> entry : DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet()) {
Display display = entry.getValue();
if (display.getItemHolder() != null) {display.getItemHolder().remove();}
if (display.getGlass() != null) {display.getGlass().remove();}
if (display.getTextDisplay() != null) {display.getTextDisplay().remove();}
}
}

public void Clear() {
DisplayShops.getPluginInstance().getServer().getScheduler().runTask(DisplayShops.getPluginInstance(), () -> {
if (getItemHolder() != null) {getItemHolder().remove();}
if (getGlass() != null) {getGlass().remove();}
if (getTextDisplay() != null) {getTextDisplay().remove();}
});
}

public void update(String generatedText, float itemScale, double itemOffsetX, double itemOffsetY, double itemOffsetZ) {
public void update(World world, String generatedText, float itemScale, double itemOffsetX, double itemOffsetY, double itemOffsetZ, double[] offsets) {
if (getShop() == null) return;

World world = DisplayShops.getPluginInstance().getServer().getWorld(getShop().getBaseLocation().getWorldName());
if (world == null) {return;}

if (!world.isChunkLoaded((int) (getShop().getBaseLocation().getX()) >> 4, (int) (getShop().getBaseLocation().getZ()) >> 4)) {return;}

Location baseLocation = getShop().getBaseLocation().asBukkitLocation();
if (baseLocation == null) return;

double[] offsets = null;
Appearance appearance = Appearance.getAppearance(shop.getAppearanceId());
if (appearance != null) {offsets = appearance.getOffset();}

updateItem(world, baseLocation, itemScale, itemOffsetX, itemOffsetY, itemOffsetZ, offsets);
updateGlass(world, baseLocation, offsets);
updateLines(world, baseLocation, generatedText, offsets);
}

public void rotate() {
/*if(getItemHolder() != null && getItemHolder().getItemStack() != null) {
mat = mat.scale(scale);
getItemHolder().setTransformationMatrix(mat = mat.rotateY(((float) Math.toRadians(180)) + 0.1F));
getItemHolder().setInterpolationDelay(0);
getItemHolder().setInterpolationDuration(duration);
}*/
}

public void delete() {
DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().remove(shop.getOwnerUniqueId());

if (getItemHolder() != null) {getItemHolder().remove();}
if (getGlass() != null) {getGlass().remove();}
if (getTextDisplay() != null) {getTextDisplay().remove();}
Clear();
}

private void updateItem(World world, Location baseLocation, float scale, double x, double y, double z, double[] appearanceOffsets) {
Expand Down Expand Up @@ -204,7 +187,7 @@ public void run() {
display.setInterpolationDelay(0); // no delay to the interpolation
display.setInterpolationDuration(duration); // set the duration of the interpolated rotation
}
}.runTaskTimer(DisplayShops.getPluginInstance(), 1, duration); // Schedule the task with the specified duration
}.runTaskTimer(DisplayShops.getPluginInstance(), 1, duration);
}

private void updateGlass(World world, Location baseLocation, double[] appearanceOffsets) {
Expand All @@ -229,7 +212,7 @@ private void updateGlass(World world, Location baseLocation, double[] appearance
entity.getPersistentDataContainer().set(key, PersistentDataType.STRING, "glass");
entity.setMetadata("DisplayShops-Entity", new FixedMetadataValue(DisplayShops.getPluginInstance(), ""));
});
} else {getGlass().teleport(newLocation);}
} else {getGlass().teleportAsync(newLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);}
}

public String generateText() {
Expand Down Expand Up @@ -287,11 +270,13 @@ public String generateText() {

private void updateLines(World world, Location baseLocation, String text, double[] appearanceOffsets) {
double x = (0.5 + baseLocation.getX() + (appearanceOffsets != null ? appearanceOffsets[0] : 0)),
y = (1.7 + baseLocation.getY() + (appearanceOffsets != null ? appearanceOffsets[0] : 0)),
z = (0.5 + baseLocation.getZ() + (appearanceOffsets != null ? appearanceOffsets[0] : 0));
y = (1.8 + baseLocation.getY() + (appearanceOffsets != null ? appearanceOffsets[1] : 0)),
z = (0.5 + baseLocation.getZ() + (appearanceOffsets != null ? appearanceOffsets[2] : 0));

Location location = new Location(world, x, y, z);

if (getTextDisplay() == null || !getTextDisplay().isValid() || getTextDisplay().isDead()) {
textDisplay = world.spawn(new Location(world, x, y, z), TextDisplay.class, entity -> {
textDisplay = world.spawn(location, TextDisplay.class, entity -> {
// customize the entity!
//entity.text(Component.text("Some awesome content", NamedTextColor.BLACK));
entity.setBillboard(org.bukkit.entity.Display.Billboard.VERTICAL); // pivot only around the vertical axis
Expand Down Expand Up @@ -332,6 +317,7 @@ private void updateLines(World world, Location baseLocation, String text, double
});
} else {
((TextDisplay) getTextDisplay()).text(LegacyComponentSerializer.legacySection().deserialize(text));
getTextDisplay().teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
}

// remove all unused
Expand Down
34 changes: 24 additions & 10 deletions Core/src/main/java/xzot1k/plugins/ds/core/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xzot1k.plugins.ds.DisplayShops;
Expand All @@ -33,10 +34,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;

public class Commands implements CommandExecutor {
Expand Down Expand Up @@ -285,9 +283,9 @@ private void runKill(CommandSender commandSender, String[] args) {
for (int i = -1; ++i < entities.size(); ) {
Entity entity = entities.get(i);

if (((entity instanceof ArmorStand || entity instanceof org.bukkit.entity.Item) && type.toLowerCase().contains("both"))
|| (entity instanceof ArmorStand && (type.toLowerCase().contains("armorstand") || type.toLowerCase().contains("stand")))
|| (entity instanceof org.bukkit.entity.Item && (type.toLowerCase().contains("item") || type.toLowerCase().contains("drop")))) {
if (((entity instanceof TextDisplay || entity instanceof ItemDisplay) && type.toLowerCase().contains("both"))
|| (entity instanceof TextDisplay && (type.toLowerCase().contains("armorstand") || type.toLowerCase().contains("stand")))
|| (entity instanceof ItemDisplay && (type.toLowerCase().contains("item") || type.toLowerCase().contains("drop")))) {
entity.remove();
removedCounter++;
}
Expand Down Expand Up @@ -1455,7 +1453,17 @@ private void runCleanUp(CommandSender commandSender) {
return;
}

Display.ClearAllEntities();
if (DisplayShops.getPluginInstance().getDisplayManager() != null) {
DisplayShops.getPluginInstance().getInSightTask().setPaused(true);

Display.ClearAllEntities();

for (Map.Entry<UUID, Display> entry : new ArrayList<>(DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet())) {
entry.getValue().delete();
}

DisplayShops.getPluginInstance().getInSightTask().setPaused(false);
}

final int cleanInactiveTime = getPluginInstance().getConfig().getInt("clean-inactive-duration");

Expand Down Expand Up @@ -1793,7 +1801,13 @@ private void runReload(CommandSender commandSender) {
getPluginInstance().reloadConfigs();

// clear displays
if (getPluginInstance().getDisplayManager() != null) {Display.ClearAllEntities();}
if (getPluginInstance().getDisplayManager() != null) {
Display.ClearAllEntities();

for (Map.Entry<UUID, Display> entry : new ArrayList<>(DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet())) {
entry.getValue().delete();
}
}

// reset EconomyHandler
getPluginInstance().getEconomyHandler().reset();
Expand Down
Loading

0 comments on commit a3b30f8

Please sign in to comment.