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.1 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Mitchell authored Aug 26, 2023
2 parents 757ecb8 + 6a649f6 commit 945325d
Show file tree
Hide file tree
Showing 67 changed files with 2,314 additions and 57 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ Featuring things from Projectile Trails, Particle Rings, Custom Structures, Pets
- **Pets** - Spawn a best friend to play along with!
- **Sound Effects** - Create sound effects for your players to use, on any triggered event.
- **Gadgets** - Fun, harmless toys for you and your players to use!
- **Holograms** - Messages shown above your head!

---

## 📓 Changelog

📰 v1.2.1 - August 26, 2023
- Gradle Updates
- **Armor Stand Holograms**
- Custom Messages available Above your Head
- Change Color & Bold Texture
- Minor Bug Fixes
- API Improvements & Fixes

🔫 v1.2.0 - July 14, 2023
- Gradle Updates
- **Introduction of Gadgets**
Expand Down Expand Up @@ -87,10 +96,12 @@ First Release of StarCosmetics

## 🔮 Future Features

#### v1.2.0
- [ ] Custom Player Soundtracks
#### v1.2.2
- [ ] Custom Structures using StarCosmetics Structure Files (.scs)

#### v1.3.0
- [ ] More Animations

---

## 💻 StarCosmetics API
Expand Down Expand Up @@ -166,6 +177,8 @@ Download the plugin on our Spigot Page, and drop it in to your Spigot/Paper "plu

## 📷 Screenshots

<img src="https://media.discordapp.net/attachments/894254760075603980/1145101159367987281/2023-08-26_15.51.54.png" title="StarCosmetics v1.2.1 Holograms" alt="StarCosmetics Holograms">

<img src="https://media.discordapp.net/attachments/894254760075603980/1129526351444070561/2023-07-14_16.33.56.png" title="StarCosmetics v1.2.0 Gadgets GUI" alt="StarCosmetics GUI">

<img src="https://media.discordapp.net/attachments/894254760075603980/1089413119933161523/2023-03-25_23.57.33.png" title="Stripped Bamboo Hat" alt="Stripped Bamboo Hat">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,75 @@
package me.gamercoder215.starcosmetics.api.player;

import me.gamercoder215.starcosmetics.api.StarConfig;
import me.gamercoder215.starcosmetics.api.cosmetics.pet.Pet;
import me.gamercoder215.starcosmetics.api.cosmetics.pet.PetType;
import me.gamercoder215.starcosmetics.wrapper.Wrapper;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static me.gamercoder215.starcosmetics.wrapper.Wrapper.STAR_PLAYER_CACHE;

public final class StarPlayerUtil {

private static final Map<UUID, ArmorStand> HOLOGRAMS = new HashMap<>();

public static void onDisable() {
// Remove Pets
for (Player p : Bukkit.getOnlinePlayers()) removePet(p);

// Remove Holograms
for (ArmorStand as : HOLOGRAMS.values()) as.remove();
}

public static Map<UUID, Pet> getPets() {
return StarPlayer.SPAWNED_PETS;
}

@Nullable
public static ArmorStand getHologram(Player p) {
if (!STAR_PLAYER_CACHE.containsKey(p.getUniqueId())) {
StarPlayer sp = new StarPlayer(p);
STAR_PLAYER_CACHE.put(p.getUniqueId(), sp);

if (HOLOGRAMS.containsKey(p.getUniqueId()))
HOLOGRAMS.get(p.getUniqueId()).setCustomName(sp.getSetting(PlayerSetting.HOLOGRAM_FORMAT).toString() + sp.getHologramMessage());
}

StarPlayer sp = STAR_PLAYER_CACHE.get(p.getUniqueId());
if (sp.getHologramMessage().isEmpty()) {
if (HOLOGRAMS.get(p.getUniqueId()) != null) {
HOLOGRAMS.get(p.getUniqueId()).remove();
HOLOGRAMS.remove(p.getUniqueId());
}

return null;
}

if (HOLOGRAMS.get(p.getUniqueId()) != null) return HOLOGRAMS.get(p.getUniqueId());

ArmorStand hologram = p.getWorld().spawn(p.getEyeLocation().add(0, 0.3, 0), ArmorStand.class);
hologram.setInvulnerable(true);
hologram.setGravity(false);
hologram.setVisible(false);
hologram.setMarker(true);

hologram.setCustomNameVisible(true);
hologram.setCustomName(sp.getSetting(PlayerSetting.HOLOGRAM_FORMAT).toString() + sp.getHologramMessage());
hologram.setMetadata("starcosmetics:nointeract", new FixedMetadataValue(StarConfig.getPlugin(), true));

HOLOGRAMS.put(p.getUniqueId(), hologram);
return hologram;
}

@NotNull
public static Location createPetLocation(@NotNull Player p) {
if (p == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static void chooseEvent(@NotNull Player p, Consumer<Class<? extends Event
p.openInventory(inv);
}

public static void confirm(@NotNull Player p, @NotNull Runnable confirmR, @NotNull Runnable cancelR) {
public static StarInventory confirm(@NotNull Player p, @NotNull Runnable confirmR, @NotNull Runnable cancelR) {
StarInventory inv = Generator.genGUI("confirm_inv", 27, get("menu.are_you_sure"));
inv.setCancelled();
inv.setAttribute("confirm_action", confirmR);
Expand All @@ -202,10 +202,11 @@ public static void confirm(@NotNull Player p, @NotNull Runnable confirmR, @NotNu
inv.setItem(15, cancel);

p.openInventory(inv);
return inv;
}

public static void confirm(@NotNull Player p, @NotNull Runnable confirmR) {
confirm(p, confirmR, () -> {
public static StarInventory confirm(@NotNull Player p, @NotNull Runnable confirmR) {
return confirm(p, confirmR, () -> {
p.closeInventory();
StarSound.BLOCK_NOTE_BLOCK_PLING.playFailure(p);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import me.gamercoder215.starcosmetics.api.cosmetics.BaseShape;
import me.gamercoder215.starcosmetics.api.cosmetics.Cosmetic;
import me.gamercoder215.starcosmetics.api.cosmetics.particle.ParticleShape;
import me.gamercoder215.starcosmetics.util.Constants;
import me.gamercoder215.starcosmetics.util.inventory.StarInventoryUtil;
import me.gamercoder215.starcosmetics.wrapper.Wrapper;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.NoSuchElementException;

import static me.gamercoder215.starcosmetics.wrapper.Wrapper.get;

Expand All @@ -27,9 +30,17 @@ public ParticleSelection(String name, ParticleShape parent, Object object, Compl
this.parent = parent;
}

// public ParticleSelection(Map<String, Object> customData) {
// super
// }
public ParticleSelection(Map<String, Object> customData) {
super(parseObject(customData.get("object")), CompletionCriteria.fromPermission(customData.get("permission").toString()), Rarity.valueOf(customData.get("rarity").toString().toUpperCase()));

this.name = customData.get("id").toString();
this.displayName = customData.get("name").toString();
this.parent = (ParticleShape) Constants.PARENTS.stream()
.filter(p -> p instanceof ParticleShape)
.filter(p -> p.getNamespace().equalsIgnoreCase(customData.get("shape").toString()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unknown shape '" + customData.get("shape") + "'"));
}

@Override
public String getKey() {
Expand All @@ -56,4 +67,17 @@ public Class<? extends Cosmetic> getParentClass() {
public Class<?> getInputType() {
return getInput().getClass();
}

private static Enum<?> parseObject(Object obj) {
String s = obj.toString().toUpperCase();

try {
return Particle.valueOf(s);
} catch (NoSuchElementException e) {
Material m = Material.matchMaterial(s);
if (m != null) return m;

throw new IllegalArgumentException("Unknown Object '" + obj + "'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.function.Consumer;

public final class TestWrapper implements Wrapper {
@Override
public int getCommandVersion() {
Expand Down Expand Up @@ -67,5 +69,14 @@ public String getAdvancementDescription(String s) {
@Override
public ItemStack cleanSkull(ItemStack item) { return null; }

@Override
public void addPacketInjector(Player p) {}

@Override
public void removePacketInjector(Player p) {}

@Override
public void sendSign(Player p, Consumer<String[]> lines) {}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import java.lang.reflect.Constructor;
import java.security.SecureRandom;
import java.util.*;
import java.util.function.Consumer;

import static me.gamercoder215.starcosmetics.util.Constants.w;

public interface Wrapper {

SecureRandom r = Constants.r;

String PACKET_INJECTOR_ID = "starcosmetics:packet_injector";

Map<UUID, StarPlayer> STAR_PLAYER_CACHE = new HashMap<>();

static boolean isCompatible() {
Expand Down Expand Up @@ -209,6 +212,12 @@ default void sendBlockChange(Player p, Location loc, Material m) {

default ItemStack createDecoratedPot(Material[] sherds) { throw new UnsupportedOperationException(); }

void addPacketInjector(Player p);

void removePacketInjector(Player p);

void sendSign(Player p, Consumer<String[]> lines);

// Other Utilities

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.*;

import static me.gamercoder215.starcosmetics.util.Generator.cw;
import static me.gamercoder215.starcosmetics.util.Generator.genGUI;
import static me.gamercoder215.starcosmetics.wrapper.Wrapper.*;
import static me.gamercoder215.starcosmetics.wrapper.nbt.NBTWrapper.of;

Expand All @@ -50,6 +51,7 @@ public interface CommandWrapper {
.put("starpets", Arrays.asList("starp", "sp", "spets", "pets"))
.put("starhelp", Collections.singletonList("shelp"))
.put("starcosmeticinfo", Arrays.asList("cosmeticinfo", "scinfo", "scosmeticinfo", "cinfo"))
.put("starhologram", Arrays.asList("starh", "hologram"))
.build();

Map<String, String> COMMAND_PERMISSION = ImmutableMap.<String, String>builder()
Expand All @@ -59,6 +61,7 @@ public interface CommandWrapper {
.put("starstructures", "starcosmetics.user.cosmetics")
.put("starpets", "starcosmetics.user.cosmetics")
.put("starcosmeticinfo", "starcosmetics.user.cosmetics")
.put("starhologram", "starcosmetics.user.cosmetics")
.build();

Map<String, String> COMMAND_DESCRIPTION = ImmutableMap.<String, String>builder()
Expand All @@ -70,6 +73,7 @@ public interface CommandWrapper {
.put("starpets", "Opens the StarCosmetics pets menu.")
.put("starhelp", "Displays help for StarCosmetics.")
.put("starcosmeticinfo", "Displays information about the cosmetic the player has currently equipped.")
.put("starhologram", "Opens the StarCosmetics hologram menu.")
.build();

Map<String, String> COMMAND_USAGE = ImmutableMap.<String, String>builder()
Expand All @@ -81,6 +85,7 @@ public interface CommandWrapper {
.put("starpets", "/starpets [remove|spawn]")
.put("starhelp", "/starhelp")
.put("starcosmeticinfo", "/starcosmeticinfo <cosmetic>")
.put("starhologram", "/starhologram")
.build();

// Command Methods
Expand Down Expand Up @@ -509,6 +514,39 @@ default void cosmeticInfo(Player p, Class<? extends Cosmetic> cosmetic) {
p.sendMessage(s);
}

default void hologramInfo(Player p) {
StarPlayer sp = new StarPlayer(p);
StarInventory inv = genGUI(27, get("menu.cosmetics.hologram"));
inv.setCancelled();

ItemStack message = StarMaterial.OAK_SIGN.findStack();
ItemMeta mMeta = message.getItemMeta();
if (!sp.getHologramMessage().isEmpty())
mMeta.setDisplayName(ChatColor.YELLOW + "\"" + sp.getHologramMessage() + "\"");
else
mMeta.setDisplayName(ChatColor.YELLOW + get("menu.cosmetics.hologram.none"));
message.setItemMeta(mMeta);
inv.setItem(12, message);

ItemStack setMessage = NBTWrapper.builder(Material.PAPER,
meta -> meta.setDisplayName(ChatColor.YELLOW + get("menu.cosmetics.hologram.set")),
nbt -> nbt.setID("cosmetic:hologram:set")
);
inv.setItem(14, setMessage);

ItemStack resetMessage = NBTWrapper.builder(StarMaterial.RED_WOOL.findStack(),
meta -> meta.setDisplayName(ChatColor.RED + get("menu.cosmetics.hologram.reset")),
nbt -> nbt.setID("cosmetic:hologram:reset")
);
inv.setItem(22, resetMessage);

while (inv.firstEmpty() != -1)
inv.setItem(inv.firstEmpty(), ItemBuilder.GUI_BACKGROUND);

p.openInventory(inv);
StarSound.ENTITY_ARROW_HIT_PLAYER.playSuccess(p);
}

// Utilities

static long getCosmeticCount(TrailType t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ public static CompletionCriteria fromSelectionLimit(int limit) throws IllegalArg
return CompletionCriteria.fromCrafted(260, Material.JUKEBOX);
}

/**
* Generates a CompletionCriteria with the given permission.
* @param permission Permission to check for
* @return CompletionCriteria with the given criteria
*/
@NotNull
public static CompletionCriteria fromPermission(String permission) {
return new CompletionCriteria(p -> p.hasPermission(permission), p -> p.hasPermission(permission) ? 100 : 0, "criteria.permission", permission);
}

private static String formatTime(long ticks) {
double seconds = (double) ticks / 20D;

Expand Down

This file was deleted.

Loading

0 comments on commit 945325d

Please sign in to comment.