5 files changed
+192
-2
No files matched your search
+45
@@ -0,0 +1,45 @@
|
||||
package com.programmerdan.minecraft.simpleadminhacks.configs;
|
||||
|
||||
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHackConfig;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class SaplingConfig extends SimpleHackConfig {
|
||||
|
||||
private Map<Material, Double> chanceMap;
|
||||
private boolean allowFortune;
|
||||
|
||||
public SaplingConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
|
||||
super(plugin, base);
|
||||
}
|
||||
|
||||
public SaplingConfig(SimpleAdminHacks plugin, ConfigurationSection base, boolean wireup) {
|
||||
super(plugin, base, wireup);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void wireup(ConfigurationSection config) {
|
||||
this.allowFortune = config.getBoolean("allow_fortune", false);
|
||||
this.chanceMap = new HashMap<>();
|
||||
for (String replace : config.getConfigurationSection("blocks").getKeys(false)) {
|
||||
Material leaves = Material.matchMaterial(replace.toUpperCase());
|
||||
//Incase this breaks, default to no extra drops
|
||||
Double chance = config.getConfigurationSection("blocks").getDouble(replace, 0.0);
|
||||
if (leaves != null && chance != null) {
|
||||
chanceMap.put(leaves, chance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Material, Double> getChanceMap() {
|
||||
return Collections.unmodifiableMap(this.chanceMap);
|
||||
}
|
||||
|
||||
public boolean isAllowFortune() {
|
||||
return this.allowFortune;
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.programmerdan.minecraft.simpleadminhacks.hacks;
|
||||
|
||||
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.configs.SaplingConfig;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHack;
|
||||
import java.util.Random;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SaplingHack extends SimpleHack<SaplingConfig> implements Listener {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
public SaplingHack(SimpleAdminHacks plugin, SaplingConfig config) {
|
||||
super(plugin, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
this.plugin.registerListener(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Block brokenBlock = event.getBlock();
|
||||
if (!checkIfLeafBlock(brokenBlock)) {
|
||||
return;
|
||||
}
|
||||
if (!this.config.isAllowFortune()) {
|
||||
if (checkIfItemHasFortune(event.getPlayer().getItemInUse())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!this.config.getChanceMap().containsKey(brokenBlock.getType())) {
|
||||
return;
|
||||
}
|
||||
double nextDouble = random.nextDouble();
|
||||
if (nextDouble <= this.config.getChanceMap().get(brokenBlock.getType())) {
|
||||
brokenBlock.getWorld().dropItemNaturally(brokenBlock.getLocation(), new ItemStack(getSaplingMaterial(brokenBlock.getType()), 1));
|
||||
logger.info("Dropped extra " + getSaplingMaterial(brokenBlock.getType()) + " from being broken at " + brokenBlock.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeafDecay(LeavesDecayEvent event) {
|
||||
Block decayedBlock = event.getBlock();
|
||||
if (!checkIfLeafBlock(decayedBlock)) {
|
||||
return;
|
||||
}
|
||||
double nextDouble = random.nextDouble();
|
||||
if (nextDouble <= this.config.getChanceMap().get(decayedBlock.getType())) {
|
||||
decayedBlock.getWorld().dropItemNaturally(decayedBlock.getLocation(), new ItemStack(getSaplingMaterial(decayedBlock.getType()), 1));
|
||||
logger.info("Dropped extra " + getSaplingMaterial(decayedBlock.getType()) + " from being broken at " + decayedBlock.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfLeafBlock(Block block) {
|
||||
return switch (block.getType()) {
|
||||
case OAK_LEAVES, BIRCH_LEAVES, SPRUCE_LEAVES, JUNGLE_LEAVES, ACACIA_LEAVES, DARK_OAK_LEAVES -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean checkIfItemHasFortune(ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
return itemStack.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS);
|
||||
}
|
||||
|
||||
private Material getSaplingMaterial(Material material) {
|
||||
return switch (material) {
|
||||
case OAK_LEAVES -> Material.OAK_SAPLING;
|
||||
case BIRCH_LEAVES -> Material.BIRCH_SAPLING;
|
||||
case SPRUCE_LEAVES -> Material.SPRUCE_SAPLING;
|
||||
case JUNGLE_LEAVES -> Material.JUNGLE_SAPLING;
|
||||
case ACACIA_LEAVES -> Material.ACACIA_SAPLING;
|
||||
case DARK_OAK_LEAVES -> Material.DARK_OAK_SAPLING;
|
||||
//We set this to air so nothing will drop if it comes to erroring
|
||||
default -> Material.AIR;
|
||||
};
|
||||
}
|
||||
|
||||
public static SaplingConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
|
||||
return new SaplingConfig(plugin, config);
|
||||
}
|
||||
}
|
||||
+43
-1
@@ -12,8 +12,11 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -63,7 +66,7 @@ public class ArmourBound extends BasicHack {
|
||||
return;
|
||||
}
|
||||
UUID boundUUID = UUID.fromString(itemContainer.get(this.key, PersistentDataType.STRING));
|
||||
if (!boundUUID.equals(player.getUniqueId())) {
|
||||
if (!boundUUID.equals(player.getUniqueId()) && !player.hasMetadata("NPC")) {
|
||||
player.closeInventory();
|
||||
ItemStack toDrop = newItem.clone();
|
||||
newItem.setAmount(0);
|
||||
@@ -72,6 +75,45 @@ public class ArmourBound extends BasicHack {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemCraft(PrepareItemCraftEvent event) {
|
||||
if (event.getRecipe() == null) {
|
||||
return;
|
||||
}
|
||||
CraftingInventory inventory = event.getInventory();
|
||||
ItemStack[] matrix = inventory.getMatrix();
|
||||
ItemStack boundItem = null;
|
||||
PersistentDataContainer container = null;
|
||||
ItemMeta meta = null;
|
||||
for (ItemStack item : matrix) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if (!whitelist.contains(item.getType().toString())) {
|
||||
continue;
|
||||
}
|
||||
meta = item.getItemMeta();
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
container = meta.getPersistentDataContainer();
|
||||
if (!container.has(this.key, PersistentDataType.STRING)) {
|
||||
continue;
|
||||
}
|
||||
boundItem = item;
|
||||
break;
|
||||
}
|
||||
if (boundItem == null) {
|
||||
return;
|
||||
}
|
||||
inventory.setResult(null);
|
||||
for (HumanEntity viewer : inventory.getViewers()) {
|
||||
if (viewer instanceof final Player playerViewer) {
|
||||
playerViewer.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EquipmentSlot getRealSlot(PlayerArmorChangeEvent.SlotType slotType) {
|
||||
switch (slotType) {
|
||||
case HEAD:
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ public final class OldEnchanting extends BasicHack {
|
||||
// Setup enchantment randomiser
|
||||
Field randomiser = null;
|
||||
try {
|
||||
randomiser = FieldUtils.getDeclaredField(EnchantmentMenu.class, "h", true);
|
||||
randomiser = FieldUtils.getDeclaredField(EnchantmentMenu.class, "p", true);
|
||||
}
|
||||
catch (final Throwable throwable) {
|
||||
this.logger.log(Level.WARNING, "An exception was thrown while trying to reflect the enchanting " +
|
||||
|
||||
@@ -465,6 +465,14 @@ hacks:
|
||||
# in seconds
|
||||
delay: 180
|
||||
message: "&4%player% is raiding a chest at %x% %y% %z%."
|
||||
#Used to roll a dice on whether to drop an additional sapling on block break or leaf decay
|
||||
SaplingHack:
|
||||
enabled: true
|
||||
#Should we still roll the dice for people when using a fortune enchanted tool?
|
||||
allow_fortune: true
|
||||
blocks:
|
||||
JUNGLE_LEAVES: 0.5
|
||||
DARK_OAK_LEAVES: 0.5
|
||||
SanityHack:
|
||||
enabled: true
|
||||
trackPlace: true
|
||||
|
||||
Reference in new issue
Block a user