1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-18 05:11:32 +01:00

Fix exploit for berries and composter when sneaking

Fixes #875
This commit is contained in:
montlikadani 2020-08-08 14:47:39 +02:00
parent b4f0744391
commit 4bf49034b1
4 changed files with 50 additions and 61 deletions

View File

@ -1088,7 +1088,7 @@ public class ConfigManager {
job.setXpEquation(expEquation);
job.setPointsEquation(pointsEquation);
if (jobSection.contains("Quests")) {
if (jobSection.isConfigurationSection("Quests")) {
List<Quest> quests = new ArrayList<>();
ConfigurationSection qsection = jobSection.getConfigurationSection("Quests");

View File

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -36,7 +36,8 @@ import com.gamingmesh.jobs.container.ShopItem;
import com.gamingmesh.jobs.stuff.GiveItem;
public class ShopManager {
private List<ShopItem> list = new ArrayList<>();
private final List<ShopItem> list = new ArrayList<>();
public List<ShopItem> getShopItemList() {
return list;
@ -214,7 +215,6 @@ public class ShopManager {
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
@ -301,6 +301,7 @@ public class ShopManager {
public void load() {
list.clear();
File file = new File(Jobs.getFolder(), "shopItems.yml");
YamlConfiguration f = YamlConfiguration.loadConfiguration(file);
@ -343,11 +344,8 @@ public class ShopManager {
Sitem.setIconName(CMIChatColor.translate(NameSection.getString("Icon.Name")));
if (NameSection.isList("Icon.Lore")) {
List<String> lore = new ArrayList<>();
for (String eachLine : NameSection.getStringList("Icon.Lore")) {
lore.add(CMIChatColor.translate(eachLine));
}
Sitem.setIconLore(lore);
Sitem.setIconLore(NameSection.getStringList("Icon.Lore").stream().map(CMIChatColor::translate)
.collect(Collectors.toList()));
}
if (NameSection.isString("Icon.CustomHead.PlayerName"))
@ -393,20 +391,19 @@ public class ShopManager {
}
if (NameSection.isList("PerformCommands")) {
List<String> cmd = new ArrayList<>();
for (String eachLine : NameSection.getStringList("PerformCommands")) {
cmd.add(CMIChatColor.translate(eachLine));
}
Sitem.setCommands(cmd);
Sitem.setCommands(NameSection.getStringList("PerformCommands").stream().map(CMIChatColor::translate)
.collect(Collectors.toList()));
}
if (NameSection.isConfigurationSection("GiveItems")) {
ConfigurationSection itemsSection = NameSection.getConfigurationSection("GiveItems");
Set<String> itemKeys = itemsSection.getKeys(false);
List<JobItems> items = new ArrayList<>();
for (String oneItemName : itemKeys) {
for (String oneItemName : itemsSection.getKeys(false)) {
ConfigurationSection itemSection = itemsSection.getConfigurationSection(oneItemName);
if (itemSection == null)
continue;
String node = oneItemName.toLowerCase();
String id = null;

View File

@ -23,10 +23,12 @@ import java.util.HashMap;
import java.util.List;
public class JobConditions {
private String node;
private List<String> requiresPerm = new ArrayList<>();
private HashMap<String, Integer> requiresJobs = new HashMap<>();
private HashMap<String, Boolean> performPerm = new HashMap<>();
private final List<String> requiresPerm = new ArrayList<>();
private final HashMap<String, Integer> requiresJobs = new HashMap<>();
private final HashMap<String, Boolean> performPerm = new HashMap<>();
public JobConditions(String node, List<String> requires, List<String> perform) {
this.node = node;
@ -34,14 +36,17 @@ public class JobConditions {
for (String one : requires) {
if (one.toLowerCase().contains("j:")) {
String jobName = one.toLowerCase().replace("j:", "").split("-")[0];
int jobLevel = 0;
try {
jobLevel = Integer.valueOf(one.toLowerCase().replace("j:", "").split("-")[1]);
} catch (Exception e) {
} catch (NumberFormatException e) {
continue;
}
requiresJobs.put(jobName, jobLevel);
}
if (one.toLowerCase().contains("p:")) {
requiresPerm.add(one.replace("p:", ""));
}
@ -49,6 +54,7 @@ public class JobConditions {
for (String one : perform) {
if (!one.toLowerCase().contains("p:"))
continue;
String clean = one.toLowerCase().substring("p:".length());
if (clean.contains("-")) {
String perm = clean.split("-")[0];

View File

@ -106,10 +106,7 @@ public class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void villagerTradeInventoryClick(InventoryClickEvent event) {
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
if (event.isCancelled())
if (!plugin.isEnabled() || event.isCancelled())
return;
//disabling plugin in world
@ -127,13 +124,7 @@ public class JobsPaymentListener implements Listener {
break;
}
if (event.getInventory().getType() != InventoryType.MERCHANT)
return;
if (event.getSlot() != 2)
return;
if (!event.getSlotType().equals(SlotType.RESULT))
if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT)
return;
ItemStack resultStack = event.getClickedInventory().getItem(2);
@ -370,10 +361,10 @@ public class JobsPaymentListener implements Listener {
return;
CMIMaterial cmat = CMIMaterial.get(block);
if (cmat.equals(CMIMaterial.FURNACE) || cmat.equals(CMIMaterial.SMOKER)
|| cmat.equals(CMIMaterial.BLAST_FURNACE) && block.hasMetadata(furnaceOwnerMetadata))
if (cmat == CMIMaterial.FURNACE || cmat == CMIMaterial.SMOKER
|| cmat == CMIMaterial.BLAST_FURNACE && block.hasMetadata(furnaceOwnerMetadata))
FurnaceBrewingHandling.removeFurnace(block);
else if (cmat.equals(CMIMaterial.BREWING_STAND) || cmat.equals(CMIMaterial.LEGACY_BREWING_STAND)
else if (cmat == CMIMaterial.BREWING_STAND || cmat == CMIMaterial.LEGACY_BREWING_STAND
&& block.hasMetadata(brewingOwnerMetadata))
FurnaceBrewingHandling.removeBrewing(block);
@ -1638,10 +1629,10 @@ public class JobsPaymentListener implements Listener {
CMIMaterial cmat = CMIMaterial.get(block);
if (cmat.equals(CMIMaterial.FURNACE) || cmat.equals(CMIMaterial.SMOKER)
|| cmat.equals(CMIMaterial.BLAST_FURNACE) && block.hasMetadata(furnaceOwnerMetadata))
if (cmat == CMIMaterial.FURNACE || cmat == CMIMaterial.SMOKER
|| cmat == CMIMaterial.BLAST_FURNACE && block.hasMetadata(furnaceOwnerMetadata))
FurnaceBrewingHandling.removeFurnace(block);
else if (cmat.equals(CMIMaterial.BREWING_STAND) || cmat.equals(CMIMaterial.LEGACY_BREWING_STAND)
else if (cmat == CMIMaterial.BREWING_STAND || cmat == CMIMaterial.LEGACY_BREWING_STAND
&& block.hasMetadata(brewingOwnerMetadata))
FurnaceBrewingHandling.removeBrewing(block);
@ -1672,36 +1663,34 @@ public class JobsPaymentListener implements Listener {
Material hand = Jobs.getNms().getItemInMainHand(p).getType();
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1) && !event.useInteractedBlock().equals(org.bukkit.event.Event.Result.DENY)
&& event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (jPlayer != null) {
if (cmat.equals(CMIMaterial.COMPOSTER)) {
org.bukkit.block.data.Levelled level = (org.bukkit.block.data.Levelled) block.getBlockData();
if (level.getLevel() == level.getMaximumLevel()) {
Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.COLLECT), block);
}
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1) && event.useInteractedBlock() != org.bukkit.event.Event.Result.DENY
&& event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null && !p.isSneaking()) {
if (cmat == CMIMaterial.COMPOSTER) {
org.bukkit.block.data.Levelled level = (org.bukkit.block.data.Levelled) block.getBlockData();
if (level.getLevel() == level.getMaximumLevel()) {
Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.COLLECT), block);
}
}
if (cmat.equals(CMIMaterial.SWEET_BERRY_BUSH) && !hand.equals(CMIMaterial.BONE_MEAL.getMaterial())) {
Ageable age = (Ageable) block.getBlockData();
Jobs.action(jPlayer, new BlockCollectInfo(block, ActionType.COLLECT, age.getAge()), block);
}
if (cmat == CMIMaterial.SWEET_BERRY_BUSH && hand != CMIMaterial.BONE_MEAL.getMaterial()) {
Ageable age = (Ageable) block.getBlockData();
Jobs.action(jPlayer, new BlockCollectInfo(block, ActionType.COLLECT, age.getAge()), block);
}
}
if (Version.isCurrentEqualOrHigher(Version.v1_15_R1) && !event.useInteractedBlock().equals(org.bukkit.event.Event.Result.DENY)
if (Version.isCurrentEqualOrHigher(Version.v1_15_R1) && event.useInteractedBlock() != org.bukkit.event.Event.Result.DENY
&& event.getAction() == Action.RIGHT_CLICK_BLOCK && !p.isSneaking()) {
if (jPlayer != null && cmat.equals(CMIMaterial.BEEHIVE) || cmat.equals(CMIMaterial.BEE_NEST)) {
if (jPlayer != null && (cmat == CMIMaterial.BEEHIVE || cmat == CMIMaterial.BEE_NEST)) {
org.bukkit.block.data.type.Beehive beehive = (org.bukkit.block.data.type.Beehive) block.getBlockData();
if (beehive.getHoneyLevel() == beehive.getMaximumHoneyLevel() && (hand.equals(CMIMaterial.SHEARS.getMaterial())
|| hand.equals(CMIMaterial.GLASS_BOTTLE.getMaterial()))) {
if (beehive.getHoneyLevel() == beehive.getMaximumHoneyLevel() && (hand == CMIMaterial.SHEARS.getMaterial()
|| hand == CMIMaterial.GLASS_BOTTLE.getMaterial())) {
Jobs.action(jPlayer, new BlockCollectInfo(block, ActionType.COLLECT, beehive.getHoneyLevel()), block);
}
}
}
if (cmat.equals(CMIMaterial.FURNACE) || cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE)
|| cmat.equals(CMIMaterial.SMOKER) || cmat.equals(CMIMaterial.BLAST_FURNACE)) {
if (cmat == CMIMaterial.FURNACE || cmat == CMIMaterial.LEGACY_BURNING_FURNACE
|| cmat == CMIMaterial.SMOKER || cmat == CMIMaterial.BLAST_FURNACE) {
ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(p, block);
if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false;
@ -1727,7 +1716,7 @@ public class JobsPaymentListener implements Listener {
"[current]", jPlayer.getFurnaceCount(),
"[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed()));
}
} else if (cmat.equals(CMIMaterial.BREWING_STAND) || cmat.equals(CMIMaterial.LEGACY_BREWING_STAND)) {
} else if (cmat == CMIMaterial.BREWING_STAND || cmat == CMIMaterial.LEGACY_BREWING_STAND) {
ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(p, block);
if (done.equals(ownershipFeedback.tooMany)) {
boolean report = false;
@ -1784,10 +1773,7 @@ public class JobsPaymentListener implements Listener {
@EventHandler
public void onExplore(JobsChunkChangeEvent event) {
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
if (event.isCancelled())
if (!plugin.isEnabled() || event.isCancelled())
return;
Player player = event.getPlayer();
@ -1832,7 +1818,7 @@ public class JobsPaymentListener implements Listener {
}
public static boolean payIfCreative(Player player) {
if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative() && !player.hasPermission("jobs.paycreative"))
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative() && !player.hasPermission("jobs.paycreative"))
return false;
return true;