Skip to content

Commit

Permalink
chore: Cleaned up overall code, removed debug stuff etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuvlyy committed Oct 5, 2024
1 parent cf7f716 commit 75b52f4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

/**
* Debug command
*/
public class CommandCosmeticDump implements CommandExecutor
{

Expand All @@ -36,7 +39,6 @@ public boolean onCommand(

player.sendMessage(Component.text("" + ChatColor.GOLD + ChatColor.BOLD + "COSMETIC DUMP"));

player.sendMessage(Component.text("Player: " + cosmeticManager.getPlayer().getName()));
player.sendMessage(Component.text("KSFX:"));
if (cosmeticManager.getCurrentKillSfx() == null) {
player.sendMessage(Component.text("Current: null"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import java.util.List;

/**
* Debug command
*/
public class CommandGuiDump implements CommandExecutor
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package fr.hashtek.spigot.breakffa.cosmetics;

import fr.hashtek.spigot.breakffa.BreakFFA;
import fr.hashtek.spigot.breakffa.cosmetics.types.AbstractCosmetic;
import fr.hashtek.spigot.breakffa.cosmetics.types.CosmeticTypeCustomHelmet;
import fr.hashtek.spigot.breakffa.cosmetics.types.CosmeticTypeKSFX;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -65,8 +63,6 @@ public interface OwnedCosmeticsGetter<T extends Cosmetic<? extends AbstractCosme
}


private final Player player;

/* Kill SFXs */
private final List<Cosmetic<CosmeticTypeKSFX>> ownedKillSfxs;
private Cosmetic<CosmeticTypeKSFX> currentKillSfx;
Expand All @@ -78,14 +74,9 @@ public interface OwnedCosmeticsGetter<T extends Cosmetic<? extends AbstractCosme

/**
* Creates a new instance of CosmeticManager.
*
* @param main BreakFFA instance
* @param player Player linked to this Cosmetic Manager
*/
public CosmeticManager(BreakFFA main, Player player)
public CosmeticManager()
{
this.player = player;

this.ownedKillSfxs = new ArrayList<Cosmetic<CosmeticTypeKSFX>>();
this.ownedCustomHelmets = new ArrayList<Cosmetic<CosmeticTypeCustomHelmet>>();

Expand Down Expand Up @@ -122,11 +113,6 @@ private void unlockEverything()
this.currentCustomHelmet = this.ownedCustomHelmets.get(0);
}

public Player getPlayer()
{
return this.player;
}


/* Kill SFXs */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,22 @@ public HashItem getItem()
private final GuiCosmeticsCategory<T, E> parentGui;
private final Cosmetic<T> cosmetic;
private final CosmeticManager.OwnedCosmeticsGetter<Cosmetic<T>> ownedCosmeticsGetter;
private final CosmeticManager.CurrentCosmeticGetter<Cosmetic<T>> currentCosmeticGetter;
private final CosmeticManager.CurrentCosmeticSetter<Cosmetic<T>> currentCosmeticSetter;
private final CosmeticManager cosmeticManager;


public GuiCosmeticBuy(
GuiCosmeticsCategory<T, E> parentGui,
CosmeticManager cosmeticManager,
Cosmetic<T> cosmetic,
CosmeticManager.OwnedCosmeticsGetter<Cosmetic<T>> ownedCosmeticsGetter,
CosmeticManager.CurrentCosmeticGetter<Cosmetic<T>> currentCosmeticGetter,
CosmeticManager.CurrentCosmeticSetter<Cosmetic<T>> currentCosmeticSetter
)
{
super(TITLE, SIZE);

this.parentGui = parentGui;
this.cosmeticManager = cosmeticManager;
this.cosmetic = cosmetic;
this.ownedCosmeticsGetter = ownedCosmeticsGetter;
this.currentCosmeticGetter = currentCosmeticGetter;
this.currentCosmeticSetter = currentCosmeticSetter;

this.createGui(cosmetic);
Expand Down Expand Up @@ -125,6 +120,7 @@ private void createGui(Cosmetic<T> cosmetic)
)
.build(this, GUI_MANAGER);


final Mask mask = new Mask(this);

mask.setItem('o', Items.ORANGE_SEP.getItem())
Expand Down Expand Up @@ -169,24 +165,20 @@ private ClickAction returnToParentGui()
return this.returnToParentGui(null);
}

public Cosmetic<T> getCosmetic()
{
return this.cosmetic;
}

public GuiCosmeticsCategory<T, E> getParentGui()
{
return this.parentGui;
}

public CosmeticManager.OwnedCosmeticsGetter<Cosmetic<T>> getOwnedCosmeticsGetter()
public Cosmetic<T> getCosmetic()
{
return this.ownedCosmeticsGetter;
return this.cosmetic;
}

public CosmeticManager.CurrentCosmeticGetter<Cosmetic<T>> getCurrentCosmeticGetter()
public CosmeticManager.OwnedCosmeticsGetter<Cosmetic<T>> getOwnedCosmeticsGetter()
{
return this.currentCosmeticGetter;
return this.ownedCosmeticsGetter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import fr.hashtek.spigot.hashgui.page.Page;
import fr.hashtek.spigot.hashitem.HashItem;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -138,12 +137,8 @@ public void reloadGui(
CosmeticManager manager
)
{
Bukkit.broadcast(Component.text("Reloading GUI..."));
gui.clearPages();
gui.addCosmeticsItems(
gui.getCosmeticsClass(),
manager
);
gui.addCosmeticsItems(gui.getCosmeticsClass(), manager);
}

/**
Expand All @@ -159,29 +154,21 @@ private HashItem createCosmeticItem(
CosmeticManager manager
)
{
Bukkit.broadcast(Component.text("name: " + manager.getPlayer().getName()));

final Cosmetic<T> currentCosmetic = currentCosmeticGetter.getGetter(manager).get();

final HashItem item = new HashItem(cosmetic.getMaterial())
.setName(Component.text(cosmetic.getName()))
.addLore(Component.text(cosmetic.getDescription()));

if (ownedCosmeticsGetter.getOwnedGetter(manager).get().contains(cosmetic)) {
Bukkit.broadcast(Component.text("owned"));
item.addLore(Component.text("YOU GOT THIS COSMETIC!!!"));
} else {
Bukkit.broadcast(Component.text("not owned :("));
item.addLore(Component.text("price: " + cosmetic.getPrice()));
}

if (currentCosmetic != null && currentCosmetic.equals(cosmetic)) {
Bukkit.broadcast(Component.text("selected"));
item.addLore(Component.text(ChatColor.GREEN + "Selected!!!"));
item.addEnchant(Enchantment.DURABILITY, 1);

} else {
Bukkit.broadcast(Component.text("not selected :c"));
}

item.addClickHandler(
Expand All @@ -199,27 +186,21 @@ private HashItem createCosmeticItem(
final CosmeticManager playerCosmeticManager =
MAIN.getGameManager().getPlayerManager(player).getCosmeticManager();

System.out.println("Targeted cosmetic is : \"" + cosmetic.getName() + "\"");

/* If player doesn't own cosmetic, redirect it to the Buy Gui. */
if (!gui.getOwnedCosmeticsGetter().getOwnedGetter(playerCosmeticManager).get().contains(cosmetic)) {
new GuiCosmeticBuy<T, E>(
gui,
playerCosmeticManager,
cosmetic,
gui.getOwnedCosmeticsGetter(),
gui.getCurrentCosmeticGetter(),
gui.getCurrentCosmeticSetter()
).open(player);
return;
}

gui.getCurrentCosmeticSetter().getSetter(playerCosmeticManager).accept(cosmetic);

gui.reloadGui(
gui,
playerCosmeticManager
);
gui.reloadGui(gui, playerCosmeticManager);

gui.update(player);
})
Expand All @@ -244,21 +225,11 @@ private void addCosmeticItem(
{
final Page lastPage = this.getLastPage();

Bukkit.broadcast(Component.text("Adding cosmetic item " + cosmetic.getName()));

try {
lastPage.addItem(
this.createCosmeticItem(
cosmetic,
manager
)
);
lastPage.addItem(this.createCosmeticItem(cosmetic, manager));
} catch (IllegalArgumentException unused) {
this.createNewPage();
this.addCosmeticItem(
cosmetic,
manager
);
this.addCosmeticItem(cosmetic, manager);
}
}

Expand All @@ -273,8 +244,6 @@ private void addCosmeticsItems(
CosmeticManager manager
)
{
Bukkit.broadcast(Component.text("Adding cosmetics..."));

for (E enumConstant : enumClass.getEnumConstants()) {
this.addCosmeticItem(
enumConstant.getCosmetic(),
Expand All @@ -284,15 +253,6 @@ private void addCosmeticsItems(
}


/* TEMP */
@Override
public void open(Player player)
{
player.chat("/cosmeticdump");
super.open(player);
}


/**
* @apiNote Item should not be built. Just create it, we'll build it for ya ;)
* @apiNote Tip: Create a static variable that stores the item, and make this function return the variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PlayerManager(BreakFFA main, Player player)
this.player = player;
this.playerData = new PlayerData(this.main, this.player);

this.cosmeticManager = new CosmeticManager(this.main, this.player);
this.cosmeticManager = new CosmeticManager();
}


Expand Down

0 comments on commit 75b52f4

Please sign in to comment.