Skip to content

Commit

Permalink
GH-11 Change the way the menu filler is created
Browse files Browse the repository at this point in the history
  • Loading branch information
zrdzn committed Apr 28, 2022
1 parent e25650a commit e360b38
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group "io.github.zrdzn.minecraft"
version "1.2.0"
version "1.2.1"
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import io.github.zrdzn.minecraft.spigot.EnchantmentMatcher;
import io.github.zrdzn.minecraft.spigot.SpigotAdapter;
import io.github.zrdzn.minecraft.spigot.V1_12SpigotAdapter;
import io.github.zrdzn.minecraft.spigot.V1_13EnchantmentMatcher;
import io.github.zrdzn.minecraft.spigot.V1_13SpigotAdapter;
import io.github.zrdzn.minecraft.spigot.V1_8EnchantmentMatcher;
import io.github.zrdzn.minecraft.spigot.V1_8SpigotAdapter;
import org.bukkit.ChatColor;
import org.bukkit.configuration.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
*/
package io.github.zrdzn.minecraft.lovelydrop.menu;

import org.bukkit.inventory.ItemStack;

import java.util.List;
import java.util.Map.Entry;

public class Menu {

private final String title;
private final int rows;
private final MenuFiller filler;
private final ItemStack filler;
private final Entry<String, String> dropSwitch;
private final Entry<String, String> inventoryDropSwitch;
private final Entry<String, String> amountFormat;
private final List<MenuItem> items;

public Menu(String title, int rows, MenuFiller filler, Entry<String, String> dropSwitch,
public Menu(String title, int rows, ItemStack filler, Entry<String, String> dropSwitch,
Entry<String, String> inventoryDropSwitch, Entry<String, String> amountFormat, List<MenuItem> items) {
this.title = title;
this.rows = rows;
Expand All @@ -47,8 +49,8 @@ public int getRows() {
return this.rows;
}

public MenuFiller getFiller() {
return this.filler;
public ItemStack getFiller() {
return this.filler.clone();
}

public Entry<String, String> getDropSwitch() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.AbstractMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.logging.Logger;

public class MenuParser {
Expand Down Expand Up @@ -53,7 +54,7 @@ public Menu parse(ConfigurationSection section) throws InvalidConfigurationExcep
throw new InvalidConfigurationException("Key 'rows' cannot be 0 and lower");
}

MenuFiller filler = null;
ItemStack filler = null;

boolean fillerEnabled = section.getBoolean("filler.enabled", false);
if (fillerEnabled) {
Expand All @@ -67,9 +68,15 @@ public Menu parse(ConfigurationSection section) throws InvalidConfigurationExcep
throw new InvalidConfigurationException("Material with key 'filler.type' does not exist.");
}

String fillerName = LovelyDropPlugin.color(section.getString("filler.displayname", "none"));
String fillerName = LovelyDropPlugin.color(section.getString("filler.displayname", " "));

filler = new MenuFiller(fillerType, fillerName);
filler = new ItemStack(fillerType);

ItemMeta fillerMeta = filler.getItemMeta();

fillerMeta.setDisplayName(fillerName.equals("none") ? " " : fillerName);

filler.setItemMeta(fillerMeta);
}

String dropSwitchEnabled = LovelyDropPlugin.color(section.getString("drop-switch.enabled", "&aon"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -195,19 +194,9 @@ public boolean open(Player player) {
});

// Fill the rest inventory with the specified item if enabled.
MenuFiller filler = this.menu.getFiller();
ItemStack filler = this.menu.getFiller();
if (filler != null) {
ItemStack fillerItem = new ItemStack(filler.getType());
ItemMeta fillerMeta = fillerItem.getItemMeta();
if (filler.getDisplayName().equalsIgnoreCase("none")) {
fillerMeta.setDisplayName(" ");
} else {
fillerMeta.setDisplayName(filler.getDisplayName());
}

fillerItem.setItemMeta(fillerMeta);

menu.getFiller().fill(ItemBuilder.from(fillerItem).asGuiItem());
menu.getFiller().fill(ItemBuilder.from(filler).asGuiItem());
}

menu.open(player);
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: LovelyDrop
version: 1.2.0
version: 1.2.1
main: io.github.zrdzn.minecraft.lovelydrop.LovelyDropPlugin
api-version: 1.13
author: zrdzn
Expand Down

0 comments on commit e360b38

Please sign in to comment.