Skip to content

Commit

Permalink
Add a config option to disable commands within trade window
Browse files Browse the repository at this point in the history
It feels exploitable and most users won't need it anyway.
  • Loading branch information
WizardCM committed Nov 19, 2023
1 parent a5afefc commit 748a061
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class Config {

//-- Booleans --//
public static boolean allowCommandsTrade;
public static boolean assignPublicOnGeneric;
public static boolean assignUseDisplayNames;
public static boolean assignUseDurability;
Expand Down Expand Up @@ -176,6 +177,7 @@ public void reloadConfiguration() {

//-- Booleans --//

allowCommandsTrade = c.getBoolean("trade.allow_commands", false);
assignPublicOnGeneric = c.getBoolean("assign.public.allow_on_generic_items", false);
assignUseDisplayNames = c.getBoolean("assign.lore_and_display_names", true);
assignUseDurability = c.getBoolean("assign.durability", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.royaldev.royalcommands.Config;
import org.royaldev.royalcommands.MessageColor;
import org.royaldev.royalcommands.gui.inventory.ClickHandler;
import org.royaldev.royalcommands.gui.inventory.GUIItem;
import org.royaldev.royalcommands.gui.inventory.InventoryGUI;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.AddPartyCommand;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.DoNothing;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.GiveHelpBook;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.RemindOtherParty;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.RemoveItem;
import org.royaldev.royalcommands.rcommands.trade.clickhandlers.ToggleTradeAcceptance;
import org.royaldev.royalcommands.rcommands.trade.guiitems.AddCommandItem;
import org.royaldev.royalcommands.rcommands.trade.guiitems.DoNothingItem;
import org.royaldev.royalcommands.rcommands.trade.guiitems.HelpItem;
import org.royaldev.royalcommands.rcommands.trade.guiitems.RemindItem;
import org.royaldev.royalcommands.rcommands.trade.guiitems.ToggleAcceptanceItem;
Expand Down Expand Up @@ -128,16 +131,19 @@ private String getTradeName() {
private InventoryGUI makeInventoryGUI() {
if (this.getInventoryGUI() != null) return null;
final InventoryGUI inventoryGUI = new InventoryGUI(this.getTradeName());
inventoryGUI.addItem(
new AddPartyCommand(this, Party.TRADER),
5, 1,
new AddCommandItem(this, Party.TRADER)
);
inventoryGUI.addItem(
new AddPartyCommand(this, Party.TRADEE),
5, 2,
new AddCommandItem(this, Party.TRADEE)
);
if (Config.allowCommandsTrade) {
inventoryGUI.addItem(
new AddPartyCommand(this, Party.TRADER),
5, 1,
new AddCommandItem(this, Party.TRADER));
inventoryGUI.addItem(
new AddPartyCommand(this, Party.TRADEE),
5, 2,
new AddCommandItem(this, Party.TRADEE));
} else {
inventoryGUI.addItem(new DoNothing(), 5, 1, new DoNothingItem());
inventoryGUI.addItem(new DoNothing(), 5, 2, new DoNothingItem());
}
inventoryGUI.addItem(
this.acceptButtonUUID,
new ToggleTradeAcceptance(this),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.royaldev.royalcommands.rcommands.trade.clickhandlers;

import org.royaldev.royalcommands.gui.inventory.ClickEvent;
import org.royaldev.royalcommands.gui.inventory.ClickHandler;

public class DoNothing implements ClickHandler {

public DoNothing() {}

@Override
public boolean onClick(final ClickEvent clickEvent) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.royaldev.royalcommands.rcommands.trade.guiitems;

import org.bukkit.Material;
import org.royaldev.royalcommands.MessageColor;
import org.royaldev.royalcommands.gui.inventory.GUIItem;

public class DoNothingItem extends GUIItem {

public DoNothingItem() {
super(
Material.BARRIER,
MessageColor.RESET + "",
null
);
}
}
2 changes: 2 additions & 0 deletions modules/RoyalCommands/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ warps:
trade:
# Allow trades between players with different gamemodes?
between_gamemodes: false
# Allow specifying commands to be run when a trade is successful?
allow_commands: false
help: |
<book>
<title>Trade Help</title>
Expand Down

0 comments on commit 748a061

Please sign in to comment.