Skip to content

Commit

Permalink
Improved DuelSelectArenaMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Mar 31, 2024
1 parent bb17805 commit df4fd58
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import me.lrxh.practice.profile.KillEffects;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.ProfileListener;
import me.lrxh.practice.profile.Themes;
import me.lrxh.practice.profile.hotbar.Hotbar;
import me.lrxh.practice.queue.QueueListener;
import me.lrxh.practice.queue.QueueThread;
Expand Down Expand Up @@ -221,8 +222,11 @@ private void loadCommandCompletions() {

private void registerPermissions() {
PluginManager pluginManager = getServer().getPluginManager();
for (KillEffects killEffects : KillEffects.values()) {
pluginManager.addPermission(new Permission("practice.killeffect." + killEffects.getDisplayName(), PermissionDefault.OP));
for (KillEffects killEffect : KillEffects.values()) {
pluginManager.addPermission(new Permission("practice.killeffect." + killEffect.getDisplayName(), PermissionDefault.OP));
}
for (Themes theme : Themes.values()) {
pluginManager.addPermission(new Permission("practice.theme." + theme.getName(), PermissionDefault.OP));
}
Arrays.asList(
"practice.admin.arena",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public void execute(Player sender, String targetName) {
return;
}

if (sender.getUniqueId().equals(target.getUniqueId())) {
sender.sendMessage(CC.RED + "You cannot duel yourself.");
return;
}
// if (sender.getUniqueId().equals(target.getUniqueId())) {
// sender.sendMessage(CC.RED + "You cannot duel yourself.");
// return;
// }

Profile senderProfile = Profile.getByUuid(sender.getUniqueId());
Profile targetProfile = Profile.getByUuid(target.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.lrxh.practice.arena.Arena;
import me.lrxh.practice.arena.ArenaType;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.util.InventoryUtil;
import me.lrxh.practice.util.ItemBuilder;
import me.lrxh.practice.util.menu.Button;
import me.lrxh.practice.util.menu.Menu;
Expand All @@ -18,6 +19,7 @@
import java.util.Map;

public class DuelSelectArenaMenu extends Menu {
Map<Integer, Button> buttons = new HashMap<>();

@Override
public String getTitle(Player player) {
Expand All @@ -26,7 +28,7 @@ public String getTitle(Player player) {

@Override
public int getSize() {
return Practice.getInstance().getMenusConfig().getInteger("DUEL.ARENA-SELECTOR.SIZE");
return InventoryUtil.getMenuSize(buttons.size(), true);
}

@Override
Expand All @@ -38,7 +40,6 @@ public Filters getFilter() {
public Map<Integer, Button> getButtons(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());

Map<Integer, Button> buttons = new HashMap<>();
int i = 10;

for (Arena arena : Arena.getArenas()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Map<Integer, Button> getButtons(Player player) {
buttons.put(i++, new SelectKitButton(queue));
}
}
// buttons.put(4, new SelectQueueButton(ranked));
//buttons.put(4, new SelectQueueButton(ranked));
return buttons;
}

Expand Down Expand Up @@ -97,6 +97,7 @@ public ItemStack getButtonItem(Player player) {
configLore.forEach(line -> {
line = line.replaceAll("<playing>", String.valueOf(Match.getInFightsCount(queue)));
line = line.replaceAll("<queueing>", String.valueOf(queue.getQueuing()));
line = line.replaceAll("<kit>", queue.getKit().getName());
line = replaceLeaderboardPlaceholders(line, queue);
if (!line.contains("<description>") || !queue.getKit().getDescription().equalsIgnoreCase("none")) {
line = line.replaceAll("<description>", queue.getKit().getDescription());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/setting/SettingsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void clicked(Player player, ClickType clickType) {
break;
}
case THEME: {
if (!player.hasPermission("practice.options.theme.selector")) {
if (!player.hasPermission("practice.theme." + profile.getOptions().theme().getName())) {
player.sendMessage(CC.translate("&cYou don't have permission to use the theme selector"));
break;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/lrxh/practice/util/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public static String serializeInventory(ItemStack[] source) {
return builder.toString();
}

public static int getMenuSize(int numberOfItems, boolean filling) {
int slotsPerRow = 9;
int rows = (int) Math.ceil((double) numberOfItems / slotsPerRow);
rows = Math.max(rows, 1);
if(filling){
return rows * slotsPerRow + 18;
}else{
return rows * slotsPerRow;
}
}

public static ItemStack[] deserializeInventory(String source) {
List<ItemStack> items = new ArrayList<>();
String[] split = source.split(";");
Expand Down

0 comments on commit df4fd58

Please sign in to comment.