Skip to content

Commit

Permalink
GH-24 Add default drop to inventory option
Browse files Browse the repository at this point in the history
  • Loading branch information
zrdzn committed Jun 14, 2022
1 parent 8de7cc9 commit 571cd32
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void onEnable() {

PluginManager pluginManager = this.getServer().getPluginManager();

pluginManager.registerEvents(new UserListener(this.userCache, this.dropItemCache), this);
pluginManager.registerEvents(new UserListener(this.userCache, this.dropItemCache,
this.menu.isDefaultDropToInventory()), this);
pluginManager.registerEvents(new DropListener(this.logger, this.messageService, spigotAdapter,
this.dropItemCache, this.userCache), this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ public class Menu {
private final Entry<String, String> inventoryDropSwitch;
private final Entry<String, String> amountFormat;
private final Entry<String, String> heightFormat;
private final boolean defaultDropToInventory;
private final List<MenuItem> items;

public Menu(String title, int rows, ItemStack filler, Entry<String, String> dropSwitch,
Entry<String, String> inventoryDropSwitch, Entry<String, String> amountFormat,
Entry<String, String> heightFormat, List<MenuItem> items) {
Entry<String, String> heightFormat, boolean defaultDropToInventory, List<MenuItem> items) {
this.title = title;
this.rows = rows;
this.filler = filler;
this.dropSwitch = dropSwitch;
this.inventoryDropSwitch = inventoryDropSwitch;
this.amountFormat = amountFormat;
this.heightFormat = heightFormat;
this.defaultDropToInventory = defaultDropToInventory;
this.items = items;
}

Expand Down Expand Up @@ -73,6 +75,10 @@ public Entry<String, String> getHeightFormat() {
return this.heightFormat;
}

public boolean isDefaultDropToInventory() {
return this.defaultDropToInventory;
}

public List<MenuItem> getItems() {
return this.items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ public Menu parse(ConfigurationSection section) throws InvalidConfigurationExcep

Entry<String, String> heightFormat = new AbstractMap.SimpleEntry<>(heightSingular, heightPlural);

boolean defaultDropToInventory = section.getBoolean("default-drop-to-inventory", true);

MenuItemParser menuItemParser = new MenuItemParser(this.logger, this.dropItemCache);

List<MenuItem> menuItems = menuItemParser.parseMany(section.getConfigurationSection("items"));

return new Menu(title, rows, filler, dropSwitch, inventorySwitch, amountFormat, heightFormat, menuItems);
return new Menu(title, rows, filler, dropSwitch, inventorySwitch, amountFormat, heightFormat, defaultDropToInventory,
menuItems);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class UserListener implements Listener {

private final UserCache userCache;
private final DropItemCache dropItemCache;
private final boolean defaultDropToInventory;

public UserListener(UserCache userCache, DropItemCache dropItemCache) {
public UserListener(UserCache userCache, DropItemCache dropItemCache, boolean defaultDropToInventory) {
this.userCache = userCache;
this.dropItemCache = dropItemCache;
this.defaultDropToInventory = defaultDropToInventory;
}

@EventHandler
Expand All @@ -39,7 +41,7 @@ public void onJoin(PlayerJoinEvent event) {

User user = new User(playerId);
this.dropItemCache.getDrops().values().forEach(items ->
items.forEach(item -> user.addInventoryDrop(item, false)));
items.forEach(item -> user.addInventoryDrop(item, this.defaultDropToInventory)));

this.userCache.addUser(playerId, user);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ menu:
plural: "&e{HEIGHT-MIN}&8-&e{HEIGHT-MAX}"


# If drop to inventory should be enabled by default or not.
default-drop-to-inventory: true


# All items that will appear in the menu. There are 3 available types of items in the menu.
# They are based on the action that they do when they are clicked. Actions:
# NONE - it will not do anything;
Expand Down

0 comments on commit 571cd32

Please sign in to comment.