1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Option to pay for block broken above original one.

Sugarcane, kelp and bamboo
This commit is contained in:
Zrips 2021-07-16 16:08:05 +03:00
parent a110342157
commit 404dcb8f1a
4 changed files with 71 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -159,7 +160,12 @@ public final class Jobs extends JavaPlugin {
public static BufferedPaymentThread paymentThread;
private static DatabaseSaveThread saveTask;
public static final Map<UUID, FastPayment> FASTPAYMENT = new HashMap<>();
private static final int MAX_ENTRIES = 5;
public static final LinkedHashMap<UUID, FastPayment> FASTPAYMENT = new LinkedHashMap<UUID, FastPayment>(MAX_ENTRIES + 1, .75F, false) {
protected boolean removeEldestEntry(Map.Entry<UUID, FastPayment> eldest) {
return size() > MAX_ENTRIES;
}
};
protected static VersionChecker versionCheckManager;
protected static SelectionManager smanager;
@ -1086,8 +1092,6 @@ public final class Jobs extends JavaPlugin {
}
} else {
FASTPAYMENT.clear();
List<Job> expiredJobs = new ArrayList<>();
for (JobProgression prog : progression) {
if (prog.getJob().isWorldBlackListed(block) || prog.getJob().isWorldBlackListed(block, ent)

View File

@ -100,7 +100,7 @@ public class GeneralConfigManager {
hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel,
BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse,
DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled,
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities,
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false,
payForEachVTradeItem, allowEnchantingBoostedItems;
public ItemStack guiBackButton, guiNextButton;
@ -472,6 +472,9 @@ public class GeneralConfigManager {
"This option is only related to: sugar_cane, cactus, kelp, bamboo");
preventCropResizePayment = c.get("prevent-crop-resize-payment", false);*/
c.addComment("pay-for-above", "When enabled we will try to pay player for blocks above broken ones. This only applies to sugarcane, bamboo and kelp");
payForAbove = c.get("pay-for-above", false);
c.addComment("pay-for-stacked-entities", "Allows to pay for stacked entities for each one. Requires StackMob or WildStacker.");
payForStackedEntities = c.get("pay-for-stacked-entities", false);
@ -832,7 +835,7 @@ public class GeneralConfigManager {
MythicMobsEnabled = c.get("ExploitProtections.MythicMobs.enabled", true);
c.addComment("ExploitProtections.Spawner.PreventSlimeSplit", "Prevent slime splitting when they are from spawner",
"Protects agains exploiting as new splited slimes is treated as naturally spawned and not from spawner");
"Protects against exploiting as new splitted slimes is treated as naturally spawned and not from spawner");
PreventSlimeSplit = c.get("ExploitProtections.Spawner.PreventSlimeSplit", true);
c.addComment("ExploitProtections.Spawner.PreventMagmaCubeSplit", "Prevent magmacube splitting when they are from spawner");
PreventMagmaCubeSplit = c.get("ExploitProtections.Spawner.PreventMagmaCubeSplit", true);

View File

@ -36,4 +36,8 @@ public class FastPayment {
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
}

View File

@ -18,6 +18,8 @@
package com.gamingmesh.jobs.listeners;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -28,6 +30,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BrewingStand;
import org.bukkit.block.Furnace;
import org.bukkit.block.data.Ageable;
@ -47,6 +50,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
@ -119,6 +123,7 @@ import com.google.common.cache.CacheBuilder;
import net.Zrips.CMILib.CMILib;
import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMILocation;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
@ -450,6 +455,7 @@ public final class JobsPaymentListener implements Listener {
}*/
Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), bInfo, block);
breakCache.put(CMILocation.toString(block.getLocation(), ":", true, true), player.getUniqueId());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -1761,4 +1767,53 @@ public final class JobsPaymentListener implements Listener {
return true;
}
private static final int MAX_ENTRIES = 50;
LinkedHashMap<String, UUID> breakCache = new LinkedHashMap<String, UUID>(MAX_ENTRIES + 1, .75F, false) {
protected boolean removeEldestEntry(Map.Entry<String, UUID> eldest) {
return size() > MAX_ENTRIES;
}
};
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEvent(BlockPhysicsEvent event) {
if (!Jobs.getGCManager().payForAbove)
return;
if (event.getBlock().getType().equals(Material.AIR))
return;
final Block block = event.getBlock();
CMIMaterial mat = CMIMaterial.get(block);
if (!mat.equals(CMIMaterial.SUGAR_CANE) && !mat.equals(CMIMaterial.BAMBOO) && !mat.equals(CMIMaterial.KELP_PLANT))
return;
if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld()))
return;
if (event.getSourceBlock().equals(event.getBlock()))
return;
if (event.getBlock().getLocation().getBlockY() <= event.getSourceBlock().getLocation().getBlockY())
return;
Location loc = event.getSourceBlock().getLocation().clone();
UUID uuid = breakCache.get(CMILocation.toString(loc, ":", true, true));
if (uuid == null)
return;
BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK);
FastPayment fp = Jobs.FASTPAYMENT.get(uuid);
if (fp == null)
return;
if (!fp.getInfo().getType().equals(ActionType.BREAK) || !fp.getInfo().getNameWithSub().equals(bInfo.getNameWithSub()))
return;
if (fp.getTime() > System.currentTimeMillis() - 50L && (fp.getInfo().getName().equalsIgnoreCase(bInfo.getName()) ||
fp.getInfo().getNameWithSub().equalsIgnoreCase(bInfo.getNameWithSub()))) {
Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob());
breakCache.put(CMILocation.toString(block.getLocation(), ":", true, true), uuid);
fp.setTime(System.currentTimeMillis() + 45);
}
}
}