Add config setting for click protection

This commit is contained in:
PikaMug 2024-10-15 03:55:44 -04:00
parent 04a2a63a37
commit 318f8e565b
4 changed files with 25 additions and 6 deletions

View File

@ -51,6 +51,8 @@ public interface ConfigSettings {
void setEffect(final String effect); void setEffect(final String effect);
String getRedoEffect(); String getRedoEffect();
void setRedoEffect(final String redoEffect); void setRedoEffect(final String redoEffect);
boolean canPreventExploit();
void setPreventExploit(final boolean preventExploit);
boolean canShowCompletedObjs(); boolean canShowCompletedObjs();
void setShowCompletedObjs(final boolean showCompletedObjs); void setShowCompletedObjs(final boolean showCompletedObjs);
boolean canShowQuestReqs(); boolean canShowQuestReqs();

View File

@ -40,6 +40,7 @@ public class BukkitConfigSettings implements ConfigSettings {
private boolean npcEffects = true; private boolean npcEffects = true;
private String effect = "note"; private String effect = "note";
private String redoEffect = "angry_villager"; private String redoEffect = "angry_villager";
private boolean preventExploit;
private boolean showCompletedObjs = true; private boolean showCompletedObjs = true;
private boolean showQuestReqs = true; private boolean showQuestReqs = true;
private boolean showQuestTitles = true; private boolean showQuestTitles = true;
@ -174,6 +175,12 @@ public class BukkitConfigSettings implements ConfigSettings {
public void setRedoEffect(final String redoEffect) { public void setRedoEffect(final String redoEffect) {
this.redoEffect = redoEffect; this.redoEffect = redoEffect;
} }
public boolean canPreventExploit() {
return preventExploit;
}
public void setPreventExploit(final boolean preventExploit) {
this.preventExploit = preventExploit;
}
public boolean canShowCompletedObjs() { public boolean canShowCompletedObjs() {
return showCompletedObjs; return showCompletedObjs;
} }
@ -264,6 +271,7 @@ public class BukkitConfigSettings implements ConfigSettings {
npcEffects = config.getBoolean("npc-effects.enabled", true); npcEffects = config.getBoolean("npc-effects.enabled", true);
effect = config.getString("npc-effects.new-quest", "note"); effect = config.getString("npc-effects.new-quest", "note");
redoEffect = config.getString("npc-effects.redo-quest", "angry_villager"); redoEffect = config.getString("npc-effects.redo-quest", "angry_villager");
preventExploit = config.getBoolean("prevent-exploit", true);
showCompletedObjs = config.getBoolean("show-completed-objectives", true); showCompletedObjs = config.getBoolean("show-completed-objectives", true);
showQuestReqs = config.getBoolean("show-requirements", true); showQuestReqs = config.getBoolean("show-requirements", true);
showQuestTitles = config.getBoolean("show-titles", true); showQuestTitles = config.getBoolean("show-titles", true);

View File

@ -66,6 +66,7 @@ public class BukkitItemListener implements Listener {
} }
if (quester.getCurrentQuests().containsKey(quest) if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
if (plugin.getConfigSettings().canPreventExploit()) {
if (craftedItem.getMaxStackSize() == 0 || (BukkitInventoryUtil.getEmptySlots(player) if (craftedItem.getMaxStackSize() == 0 || (BukkitInventoryUtil.getEmptySlots(player)
< craftedItem.getAmount() / craftedItem.getMaxStackSize())) { < craftedItem.getAmount() / craftedItem.getMaxStackSize())) {
BukkitActionBarProvider.sendActionBar(player, ChatColor.RED + BukkitLang.get(player, BukkitActionBarProvider.sendActionBar(player, ChatColor.RED + BukkitLang.get(player,
@ -73,6 +74,7 @@ public class BukkitItemListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
quester.craftItem(quest, craftedItem); quester.craftItem(quest, craftedItem);
} }
@ -178,6 +180,9 @@ public class BukkitItemListener implements Listener {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
if (!plugin.getConfigSettings().canPreventExploit()) {
return;
}
if (event.getWhoClicked() instanceof Player) { if (event.getWhoClicked() instanceof Player) {
if (event.getInventory().getType() == InventoryType.BREWING) { if (event.getInventory().getType() == InventoryType.BREWING) {
final Quester quester = plugin.getQuester(event.getWhoClicked().getUniqueId()); final Quester quester = plugin.getQuester(event.getWhoClicked().getUniqueId());
@ -193,6 +198,9 @@ public class BukkitItemListener implements Listener {
} }
public boolean isAllowedBrewingAction(final InventoryClickEvent event) { public boolean isAllowedBrewingAction(final InventoryClickEvent event) {
if (!plugin.getConfigSettings().canPreventExploit()) {
return true;
}
final int slot = event.getRawSlot(); final int slot = event.getRawSlot();
final InventoryAction action = event.getAction(); final InventoryAction action = event.getAction();
// Prevent shift-click into Brewing Stand // Prevent shift-click into Brewing Stand

View File

@ -19,6 +19,7 @@ npc-effects:
enabled: true enabled: true
new-quest: note new-quest: note
redo-quest: heart redo-quest: heart
prevent-exploit: true
show-completed-objectives: true show-completed-objectives: true
show-requirements: true show-requirements: true
show-titles: true show-titles: true