Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Update to v1.2.2 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Mitchell authored Sep 25, 2023
2 parents 50db190 + 235747f commit f4299a0
Show file tree
Hide file tree
Showing 52 changed files with 2,313 additions and 699 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.vscode/
.gradle/
build/
bin/
bin/
.DS_Store
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Featuring things from Projectile Trails, Particle Rings, Custom Structures, Pets

## 📓 Changelog

🔧 v1.2.2 - September 24, 2023
- Gradle & CI Updates
- Heavy Optimization & GUI Creation Changes
- Added Custom Structures Loader in config.yml
- Fix StructureReader Bugs
- Improve Unit Testing
- Other Minor Additions & Bug Fixes

📰 v1.2.1 - August 26, 2023
- Gradle Updates
- **Armor Stand Holograms**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import java.util.function.BiConsumer;
Expand Down Expand Up @@ -126,6 +128,34 @@ public static void polygon(Location l, Object o, int points, double radius) {
}
}

public static void line(Location l, Object o, int length, long stepDelay) {
Vector dir = l.getDirection();
double width = 0.1;

int count = 0;
for (double i = 0; i < length * (1 / width); i += width) {
final double fi = i;

BukkitRunnable r = new BukkitRunnable() {
@Override
public void run() {
dir.multiply(fi);
l.add(dir);
spawn(l, o);
l.subtract(dir);
dir.normalize();
}
};

if (stepDelay == 0 || i == 0)
r.run();
else
r.runTaskLater(StarConfig.getPlugin(), stepDelay * count);

count++;
}
}


private final BiConsumer<Location, Object> particle;
private final ParticleSize size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.util.ChatPaginator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static me.gamercoder215.starcosmetics.util.Constants.w;
import static me.gamercoder215.starcosmetics.util.inventory.StarInventoryUtil.itemBuilder;
import static me.gamercoder215.starcosmetics.wrapper.Wrapper.get;
import static me.gamercoder215.starcosmetics.wrapper.Wrapper.getWithArgs;
import static me.gamercoder215.starcosmetics.wrapper.nbt.NBTWrapper.builder;
import static me.gamercoder215.starcosmetics.wrapper.nbt.NBTWrapper.of;

@SuppressWarnings("unchecked")
Expand All @@ -49,10 +50,10 @@ public static StarInventory genGUI(int size, String name) {
return genGUI("", size, name);
}

@Nullable
@NotNull
public static StarInventory genGUI(String key, int size, String name) {
if (size < 9 || size > 54) return null;
if (size % 9 > 0) return null;
if (size < 9 || size > 54) throw new IllegalStateException("Invalid inventory size: " + size);
if (size % 9 > 0) throw new IllegalStateException("Invalid inventory size: " + size);

StarInventory inv = w.createInventory(key, size, name);
ItemStack bg = ItemBuilder.GUI_BACKGROUND;
Expand Down Expand Up @@ -103,7 +104,7 @@ public static Map<Integer, List<ItemStack>> generateRows(@NotNull Collection<Ite
.filter(m -> w.isItem(m.getType()))
.collect(Collectors.toList());

if (list.size() == 0) return map;
if (list.isEmpty()) return map;

int size = list.size();

Expand Down Expand Up @@ -181,34 +182,28 @@ public static StarInventory createSelectionInventory(@NotNull Player p) {

for (SoundEventSelection s : sp.getSoundSelections()) inv.addItem(StarInventoryUtil.toItemStack(s));

ItemStack add = StarInventoryUtil.getHead("plus");
ItemMeta aMeta = add.getItemMeta();
aMeta.setDisplayName(ChatColor.GREEN + get("constants.cosmetics.add_selection"));
add.setItemMeta(aMeta);

NBTWrapper nbt = of(add);
nbt.setID("add:soundevent");
add = nbt.getItem();

if (size < selLimit) inv.addItem(add);
if (size < selLimit) inv.addItem(builder(StarInventoryUtil.getHead("plus"),
meta -> meta.setDisplayName(ChatColor.GREEN + get("constants.cosmetics.add_selection")),
nbt -> nbt.setID("add:soundevent")
));

for (int j = 0; j < BOTTOM_HALF_SLOTS.length; j++) {
if (selLimit > j) continue;
inv.setItem(BOTTOM_HALF_SLOTS[j], ItemBuilder.GUI_BACKGROUND);
}

if (selLimit < 35) {
ItemStack limit = new ItemStack(Material.NETHER_STAR);
ItemMeta lMeta = limit.getItemMeta();
lMeta.setDisplayName(ChatColor.GOLD + get("constants.cosmetics.selection_limit"));

CompletionCriteria nextCriteria = CompletionCriteria.fromSelectionLimit(selLimit + 1);
ItemStack limit = itemBuilder(Material.NETHER_STAR,
meta -> {
meta.setDisplayName(ChatColor.GOLD + get("constants.cosmetics.selection_limit"));
meta.setLore(Arrays.asList(
ChatColor.YELLOW + nextCriteria.getDisplayMessage(),
ChatColor.GOLD + getWithArgs("constants.completed", String.format("%,.2f", nextCriteria.getProgressPercentage(p)) + "%")
));
}
);

lMeta.setLore(Arrays.asList(
ChatColor.YELLOW + nextCriteria.getDisplayMessage(),
ChatColor.GOLD + getWithArgs("constants.completed", String.format("%,.2f", nextCriteria.getProgressPercentage(p)) + "%")
));
limit.setItemMeta(lMeta);
inv.setItem(18, limit);
}

Expand Down Expand Up @@ -286,50 +281,42 @@ public static ItemStack generateSetting(@NotNull Player p, @NotNull PlayerSettin

if (Boolean.class.isAssignableFrom(setting.getType())) {
boolean on = sp.getSetting((PlayerSetting<Boolean>) setting);

item = on ? StarMaterial.LIME_TERRACOTTA.findStack() : StarMaterial.RED_TERRACOTTA.findStack();
ItemMeta meta = item.getItemMeta();

meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + (on ? ChatColor.GREEN + get("constants.on") : ChatColor.RED + get("constants.off")));
if (on) {
meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
item.setItemMeta(meta);

NBTWrapper nbt = of(item);
nbt.setID("toggle:setting:boolean");
nbt.set("setting", setting.getId());
item = nbt.getItem();
item = builder(on ? StarMaterial.LIME_TERRACOTTA.findStack() : StarMaterial.RED_TERRACOTTA.findStack(),
meta -> {
meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + (on ? ChatColor.GREEN + get("constants.on") : ChatColor.RED + get("constants.off")));
if (on) {
meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
},
nbt -> {
nbt.setID("toggle:setting:boolean");
nbt.set("setting", setting.getId());
}
);
} else if (Enum.class.isAssignableFrom(setting.getType())) {
Enum<?> value = sp.getSetting((PlayerSetting<Enum<?>>) setting);

item = StarMaterial.LIGHT_BLUE_TERRACOTTA.findStack();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + ChatColor.AQUA + value.name());
item.setItemMeta(meta);

NBTWrapper nbt = of(item);
nbt.setID("toggle:setting:enum");
nbt.set("setting", setting.getId());
item = nbt.getItem();
item = builder(StarMaterial.LIGHT_BLUE_TERRACOTTA.findStack(),
meta -> meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + ChatColor.AQUA + value.name()),
nbt -> {
nbt.setID("toggle:setting:enum");
nbt.set("setting", setting.getId());
}
);
} else {
Object value = sp.getSetting(setting);

item = StarMaterial.LIGHT_BLUE_TERRACOTTA.findStack();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + ChatColor.YELLOW + value);
item.setItemMeta(meta);

NBTWrapper nbt = of(item);
nbt.setID("toggle:setting");
nbt.set("setting", setting.getId());
item = nbt.getItem();
item = builder(StarMaterial.LIGHT_BLUE_TERRACOTTA.findStack(),
meta -> meta.setDisplayName(ChatColor.YELLOW + setting.getDisplayName() + ": " + ChatColor.YELLOW + value),
nbt -> {
nbt.setID("toggle:setting");
nbt.set("setting", setting.getId());
}
);
}

ItemMeta meta = item.getItemMeta();
String desc = setting.getDescription() == null ? null : StarConfig.getConfig().get(setting.getDescription());
if (desc != null && !desc.equalsIgnoreCase("Unknown Value")) {
ItemMeta meta = item.getItemMeta();
List<String> lore = new ArrayList<>();

lore.add(" ");
Expand All @@ -338,10 +325,9 @@ public static ItemStack generateSetting(@NotNull Player p, @NotNull PlayerSettin
).map(s -> ChatColor.GRAY + s).collect(Collectors.toList()));

meta.setLore(lore);
item.setItemMeta(meta);
}

item.setItemMeta(meta);

return item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -117,10 +118,12 @@ public enum StarMaterial {
SNOWBALL("snow_ball"),
;

private final Material defaultV;
@VisibleForTesting
final Material defaultV;
private final short data;
private final boolean dataOnlyLegacy;
private final List<String> names = new ArrayList<>();
@VisibleForTesting
final List<String> names = new ArrayList<>();

StarMaterial(Material defaultV, int data, boolean dataOnlyLegacy, String... allnames) {
this.names.add(name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -26,7 +27,8 @@ public enum StarSound {
ITEM_TRIDENT_RIPTIDE_1,
;

private final List<String> sounds = new ArrayList<>();
@VisibleForTesting
final List<String> sounds = new ArrayList<>();

StarSound(String... sounds) {
// Ensure names are uppercase
Expand Down
Loading

0 comments on commit f4299a0

Please sign in to comment.