-
-
Notifications
You must be signed in to change notification settings - Fork 944
Expand file tree
/
Copy pathMiningManager.java
More file actions
363 lines (304 loc) · 13.6 KB
/
MiningManager.java
File metadata and controls
363 lines (304 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.api.ItemSpawnReason;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.random.Probability;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static com.gmail.nossr50.util.ItemUtils.isPickaxe;
public class MiningManager extends SkillManager {
public static final String BUDDING_AMETHYST = "budding_amethyst";
public static final Collection<Material> BLAST_MINING_BLACKLIST = Set.of(Material.SPAWNER);
public MiningManager(@NotNull McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, PrimarySkillType.MINING);
}
public boolean canUseDemolitionsExpertise() {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DEMOLITIONS_EXPERTISE))
return false;
return getSkillLevel() >= BlastMining.getDemolitionExpertUnlockLevel() && Permissions.demolitionsExpertise(getPlayer());
}
public boolean canDetonate() {
Player player = getPlayer();
return canUseBlastMining() && player.isSneaking()
&& (isPickaxe(getPlayer().getInventory().getItemInMainHand()) || player.getInventory().getItemInMainHand().getType() == mcMMO.p.getGeneralConfig().getDetonatorItem())
&& Permissions.remoteDetonation(player);
}
public boolean canUseBlastMining() {
//Not checking permissions?
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BLAST_MINING);
}
public boolean canUseBiggerBombs() {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BIGGER_BOMBS))
return false;
return getSkillLevel() >= BlastMining.getBiggerBombsUnlockLevel() && Permissions.biggerBombs(getPlayer());
}
public boolean canDoubleDrop() {
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS);
}
public boolean canMotherLode() {
return Permissions.canUseSubSkill(getPlayer(), SubSkillType.MINING_MOTHER_LODE);
}
/**
* Process double drops & XP gain for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public void miningBlockCheck(BlockState blockState) {
Player player = getPlayer();
applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE);
if (!Permissions.isSubSkillEnabled(player, SubSkillType.MINING_DOUBLE_DROPS)) {
return;
}
if (mmoPlayer.getAbilityMode(mcMMO.p.getSkillTools().getSuperAbility(skill))) {
SkillUtils.handleDurabilityChange(getPlayer(), getPlayer().getInventory().getItemInMainHand(), mcMMO.p.getGeneralConfig().getAbilityToolDamage());
}
if (!mcMMO.p.getGeneralConfig().getDoubleDropsEnabled(PrimarySkillType.MINING, blockState.getType()) || !canDoubleDrop())
return;
boolean silkTouch = player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH);
if (silkTouch && !mcMMO.p.getAdvancedConfig().getDoubleDropSilkTouchEnabled())
return;
//Mining mastery allows for a chance of triple drops
if (canMotherLode()) {
//Triple Drops failed so do a normal double drops check
if (!processTripleDrops(blockState)) {
processDoubleDrops(blockState);
}
} else {
//If the user has no mastery, proceed with normal double drop routine
processDoubleDrops(blockState);
}
}
private boolean processTripleDrops(@NotNull BlockState blockState) {
//TODO: Make this readable
if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_MOTHER_LODE, mmoPlayer)) {
BlockUtils.markDropsAsBonus(blockState, 2);
return true;
} else {
return false;
}
}
private void processDoubleDrops(@NotNull BlockState blockState) {
//TODO: Make this readable
if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_DOUBLE_DROPS, mmoPlayer)) {
boolean useTriple = mmoPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && mcMMO.p.getAdvancedConfig().getAllowMiningTripleDrops();
BlockUtils.markDropsAsBonus(blockState, useTriple);
}
}
/**
* Detonate TNT for Blast Mining
*/
public void remoteDetonation() {
Player player = getPlayer();
Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
//Blast mining cooldown check needs to be first so the player can be messaged
if (!blastMiningCooldownOver()
|| targetBlock.getType() != Material.TNT
|| !EventUtils.simulateBlockBreak(targetBlock, player)) {
return;
}
TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class);
//SkillUtils.sendSkillMessage(player, SuperAbilityType.BLAST_MINING.getAbilityPlayer(player));
NotificationManager.sendPlayerInformation(player, NotificationType.SUPER_ABILITY, "Mining.Blast.Boom");
//player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
tnt.setMetadata(MetadataConstants.METADATA_KEY_TRACKED_TNT, mmoPlayer.getPlayerMetadata());
tnt.setFuseTicks(0);
if (mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 16, 4)) {
tnt.setSource(player);
}
targetBlock.setType(Material.AIR);
mmoPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis());
mmoPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false);
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(mmoPlayer.getPlayer(), new AbilityCooldownTask(mmoPlayer, SuperAbilityType.BLAST_MINING), (long) SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
}
/**
* Handler for explosion drops and XP gain.
*
* @param yield The % of blocks to drop
* @param event The {@link EntityExplodeEvent}
*/
public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {
if (yield == 0)
return;
var increasedYieldFromBonuses = yield + (yield * getOreBonus());
// Strip out only stuff that gives mining XP
List<BlockState> ores = new ArrayList<>();
List<BlockState> notOres = new ArrayList<>();
for (Block targetBlock : event.blockList()) {
BlockState blockState = targetBlock.getState();
if(mcMMO.getUserBlockTracker().isIneligible(targetBlock))
continue;
if (ExperienceConfig.getInstance().getXp(PrimarySkillType.MINING, targetBlock) != 0) {
if (BlockUtils.isOre(blockState) && !(targetBlock instanceof Container)) {
ores.add(blockState);
}
} else {
notOres.add(blockState);
}
}
int xp = 0;
int dropMultiplier = getDropMultiplier();
for(BlockState blockState : notOres) {
if (isDropIllegal(blockState.getType()))
continue;
if (Probability.ofPercent(50).evaluate()) {
ItemUtils.spawnItem(getPlayer(),
Misc.getBlockCenter(blockState),
new ItemStack(blockState.getType()),
ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES); // Initial block that would have been dropped
}
}
for (BlockState blockState : ores) {
// currentOreYield only used for drop calculations for ores
float currentOreYield = increasedYieldFromBonuses;
if (isDropIllegal(blockState.getType())) {
continue;
}
// Always give XP for every ore destroyed
xp += Mining.getBlockXp(blockState);
while(currentOreYield > 0) {
if (Probability.ofValue(currentOreYield).evaluate()) {
Collection<ItemStack> oreDrops = isPickaxe(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
? blockState.getBlock().getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
: List.of(new ItemStack(blockState.getType()));
ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(blockState),
oreDrops, BLAST_MINING_BLACKLIST, ItemSpawnReason.BLAST_MINING_ORES);
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
for (int i = 1; i < dropMultiplier; i++) {
ItemUtils.spawnItems(getPlayer(),
Misc.getBlockCenter(blockState),
oreDrops,
BLAST_MINING_BLACKLIST,
ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP);
}
}
}
currentOreYield = Math.max(currentOreYield - 1, 0);
}
}
// Replace the event blocklist with the newYield list
event.setYield(0F);
applyXpGain(xp, XPGainReason.PVE);
}
/**
* Checks if it would be illegal (in vanilla) to obtain the block
* Certain things should never drop ( such as budding_amethyst )
*
* @param material target material
* @return true if it's not legal to obtain the block through normal gameplay
*/
public boolean isDropIllegal(@NotNull Material material) {
return material.getKey().getKey().equalsIgnoreCase(BUDDING_AMETHYST);
}
/**
* Increases the blast radius of the explosion.
*
* @param radius to modify
* @return modified radius
*/
public float biggerBombs(float radius) {
return (float) (radius + getBlastRadiusModifier());
}
public double processDemolitionsExpertise(double damage) {
return damage * ((100.0D - getBlastDamageModifier()) / 100.0D);
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public int getBlastMiningTier() {
return RankUtils.getRank(getPlayer(), SubSkillType.MINING_BLAST_MINING);
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public float getOreBonus() {
return (float) (mcMMO.p.getAdvancedConfig().getOreBonus(getBlastMiningTier()) / 100F);
}
@Deprecated(since = "2.2.017", forRemoval = true)
public static double getOreBonus(int rank) {
return mcMMO.p.getAdvancedConfig().getOreBonus(rank);
}
public static double getDebrisReduction(int rank) {
return mcMMO.p.getAdvancedConfig().getDebrisReduction(rank);
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getDebrisReduction() {
return getDebrisReduction(getBlastMiningTier());
}
public static int getDropMultiplier(int rank) {
return mcMMO.p.getAdvancedConfig().getDropMultiplier(rank);
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public int getDropMultiplier() {
if (!mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
return 0;
}
return switch (getBlastMiningTier()) {
case 8, 7 -> 3;
case 6, 5, 4, 3 -> 2;
case 2, 1 -> 1;
default -> 0;
};
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getBlastRadiusModifier() {
return BlastMining.getBlastRadiusModifier(getBlastMiningTier());
}
/**
* Gets the Blast Mining tier
*
* @return the Blast Mining tier
*/
public double getBlastDamageModifier() {
return BlastMining.getBlastDamageDecrease(getBlastMiningTier());
}
private boolean blastMiningCooldownOver() {
int timeRemaining = mmoPlayer.calculateTimeRemaining(SuperAbilityType.BLAST_MINING);
if (timeRemaining > 0) {
//getPlayer().sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.ABILITY_COOLDOWN, "Skills.TooTired", String.valueOf(timeRemaining));
return false;
}
return true;
}
}