Skip to content

Added small fixes and final modifiers #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class AbstractCosmetic {
protected Cosmetic cosmetic;
protected Player player;

protected AbstractCosmetic(Cosmetic cosmetic, @NotNull Player player, @NotNull TSSLobbyPlugin plugin) {
protected AbstractCosmetic(final Cosmetic cosmetic, @NotNull final Player player, @NotNull final TSSLobbyPlugin plugin) {
this.plugin = plugin;

this.cosmetic = cosmetic;
Expand All @@ -27,11 +27,10 @@ protected AbstractCosmetic(Cosmetic cosmetic, @NotNull Player player, @NotNull T
}

public void equip() {
UUID playerUuid = player.getUniqueId();
Map<UUID, ArrayList<AbstractCosmetic>> playerCosmetics = plugin.getCosmeticsManager().getActiveCosmetics();
ArrayList<AbstractCosmetic> equippedCosmetics = playerCosmetics.computeIfAbsent(playerUuid, key -> new ArrayList<>());
final Map<UUID, ArrayList<AbstractCosmetic>> playerCosmetics = plugin.getCosmeticsManager().getActiveCosmetics();
ArrayList<AbstractCosmetic> equippedCosmetics = playerCosmetics.computeIfAbsent(player.getUniqueId(), key -> new ArrayList<>());

Rank playerRank = plugin.getRanksPlugin().getRankManager().getPlayerRank(player);
final Rank playerRank = plugin.getRanksPlugin().getRankManager().getPlayerRank(player);

MessageManager messageManager = plugin.getCore().getMessageManager();
if (cosmetic.getRequiredRankWeight() > playerRank.getWeight()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public enum CosmeticType {
private final BiConsumer<Player, TSSLobbyPlugin> menuConstructor;

CosmeticType(TranslatableItemStack displayItem, BiConsumer<Player, TSSLobbyPlugin> menuConstructor) {
this.menuConstructor = menuConstructor;
this.displayItem = displayItem;
this.menuConstructor = menuConstructor;
this.displayItem = displayItem;
}

public ItemStack getDisplayItem(Player player, @NotNull TSSLobbyPlugin plugin) {
return displayItem.asBukkitItemStack(player, plugin.getCore());
return displayItem.asBukkitItemStack(player, plugin.getCore());
}

public BiConsumer<Player, TSSLobbyPlugin> getMenuConstructor() {
return menuConstructor;
return menuConstructor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public <T> ArrayList<T> getPlayerCosmetics(@NotNull Player player, Class<T> targ
ArrayList<T> equippedTargetCosmetics = new ArrayList<>();
ArrayList<AbstractCosmetic> equippedCosmetics = activeCosmetics.computeIfAbsent(player.getUniqueId(), key -> new ArrayList<>());
for (AbstractCosmetic equippedCosmetic : equippedCosmetics) {
Cosmetic cosmetic = equippedCosmetic.getCosmetic();
final Cosmetic cosmetic = equippedCosmetic.getCosmetic();

if (targetCosmeticClass.isInstance(equippedCosmetic)) {
equippedTargetCosmetics.add((T) equippedCosmetic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
public class CosmeticsMenu {

public CosmeticsMenu(Player player, @NotNull TSSLobbyPlugin plugin) {
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getCore().getMessageManager().getPlayerMessage(Message.COSMETICS, player));
final Inventory inventory = Bukkit.createInventory(null, 27, plugin.getCore().getMessageManager().getPlayerMessage(Message.COSMETICS, player));

CosmeticType[] cosmeticTypes = CosmeticType.values();
final CosmeticType[] cosmeticTypes = CosmeticType.values();
for (int i = 0; i < cosmeticTypes.length; i++) {
CosmeticType cosmeticType = cosmeticTypes[i];
final CosmeticType cosmeticType = cosmeticTypes[i];

ItemStack displayItem = cosmeticType.getDisplayItem(player, plugin);
ItemMeta displayItemMeta = displayItem.getItemMeta();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public TrailMenu(Player player, @NotNull TSSLobbyPlugin plugin) {
Inventory inventory = Bukkit.createInventory(null, 27, messageManager.getPlayerMessage(Message.TRAILS, player));

ArrayList<TrailType> activeTrails = plugin.getCosmeticsManager().getPlayerCosmetics(player, TrailType.class);
Rank rank = plugin.getRanksPlugin().getRankManager().getPlayerRank(player);
final Rank rank = plugin.getRanksPlugin().getRankManager().getPlayerRank(player);

if (rank == null)
return;

TrailType[] trailTypes = TrailType.values();
for (int i = 0; i < trailTypes.length; i++) {
Expand All @@ -42,7 +45,7 @@ public TrailMenu(Player player, @NotNull TSSLobbyPlugin plugin) {
)
);

PersistentDataContainer container = displayItemMeta.getPersistentDataContainer();
final PersistentDataContainer container = displayItemMeta.getPersistentDataContainer();
container.set(new NamespacedKey(plugin, "trail_type"), PersistentDataType.STRING, trailType.name());
container.set(new NamespacedKey(plugin, "cosmetic"), PersistentDataType.STRING, "trail");
displayItem.setItemMeta(displayItemMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;

public class JoinListener implements Listener {

Expand All @@ -31,15 +32,16 @@ public JoinListener(@NotNull TSSLobbyPlugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPlayerSpawn(@NotNull PlayerSpawnLocationEvent playerSpawnLocationEvent) {
playerSpawnLocationEvent.setSpawnLocation(plugin.getLobbyLocation());
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onJoin(@NotNull PlayerJoinEvent event) {
Player player = event.getPlayer();
boolean success = player.teleport(plugin.getLobbyLocation());
if (!success) {
return;
}
final Player player = event.getPlayer();

PlayerInventory playerInventory = player.getInventory();
final PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
playerInventory.setItem(4, new TranslatableItemStack(Material.CHEST, Message.COSMETICS_ITEM_DISPLAY_NAME, Message.COSMETICS_ITEM_DESCRIPTION).asBukkitItemStack(player, plugin.getCore()));

Expand All @@ -61,7 +63,7 @@ public void onJoin(@NotNull PlayerJoinEvent event) {
return;
}

World playerWorld = player.getWorld();
final World playerWorld = player.getWorld();

Firework firework = playerWorld.spawn(
player.getLocation().clone().add(
Expand All @@ -72,8 +74,8 @@ public void onJoin(@NotNull PlayerJoinEvent event) {
Firework.class
);

FireworkMeta fireworkMeta = firework.getFireworkMeta();
FireworkType fireworkType = rank.getFireworkType();
final FireworkMeta fireworkMeta = firework.getFireworkMeta();
final FireworkType fireworkType = rank.getFireworkType();

for (FireworkEffect effect : fireworkType.getEffects()) {
fireworkMeta.addEffects(effect);
Expand All @@ -82,7 +84,7 @@ public void onJoin(@NotNull PlayerJoinEvent event) {
fireworkMeta.setPower(fireworkType.getPower());
firework.setFireworkMeta(fireworkMeta);

Particle spiralParticle = fireworkType.getSpiralParticle();
final Particle spiralParticle = fireworkType.getSpiralParticle();

if (spiralParticle == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public void onItemDrop(@NotNull PlayerDropItemEvent event) {

@EventHandler
public void onCosmeticMenuNavigate(@NotNull InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
final ItemStack clickedItem = event.getCurrentItem();
if (clickedItem == null) {
return;
}

ItemMeta itemInfo = clickedItem.getItemMeta();
final ItemMeta itemInfo = clickedItem.getItemMeta();

CosmeticType cosmeticType;
final CosmeticType cosmeticType;
try {
cosmeticType = CosmeticType.valueOf(itemInfo.getPersistentDataContainer().get(new NamespacedKey(plugin, "cosmetic_type"), PersistentDataType.STRING));
} catch (NullPointerException | IllegalArgumentException exception) {
Expand All @@ -84,27 +84,27 @@ public void onCosmeticMenuNavigate(@NotNull InventoryClickEvent event) {

@EventHandler
public void onCosmeticMenuSelect(@NotNull InventoryClickEvent event) {
ItemStack clickedItem = event.getCurrentItem();
final ItemStack clickedItem = event.getCurrentItem();
if (clickedItem == null) {
return;
}

ItemMeta itemInfo = clickedItem.getItemMeta();
final ItemMeta itemInfo = clickedItem.getItemMeta();

if (itemInfo == null) {
return;
}

PersistentDataContainer container = itemInfo.getPersistentDataContainer();
String cosmetic = container.get(new NamespacedKey(plugin, "cosmetic"), PersistentDataType.STRING);
final PersistentDataContainer container = itemInfo.getPersistentDataContainer();
final String cosmetic = container.get(new NamespacedKey(plugin, "cosmetic"), PersistentDataType.STRING);

if (cosmetic == null) {
return;
}

Player player = (Player) event.getWhoClicked();
CosmeticsManager cosmeticsManager = plugin.getCosmeticsManager();
ArrayList<AbstractCosmetic> activePlayerCosmetics = cosmeticsManager.getActiveCosmetics().get(player.getUniqueId());
final Player player = (Player) event.getWhoClicked();
final CosmeticsManager cosmeticsManager = plugin.getCosmeticsManager();
final ArrayList<AbstractCosmetic> activePlayerCosmetics = cosmeticsManager.getActiveCosmetics().get(player.getUniqueId());

switch (cosmetic) {
case "hat" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ public NPCClickListener(TSSLobbyPlugin plugin) {

@EventHandler
public void onNPCClick(@NotNull NPCClickEvent event) {
Player player = event.getPlayer();
NPC npc = event.getNpc();

String worldName = npc.getDestinationWorldName();

World world = Bukkit.getWorld(worldName);
final Player player = event.getPlayer();
final NPC npc = event.getNpc();

final String worldName = npc.getDestinationWorldName();
final World world = Bukkit.getWorld(worldName);

if (world != null) {
Bukkit.getScheduler().runTask(plugin, () ->
Expand Down