mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Created Xray, Arborist, Fixed ArmorListener, Fixed Display Error.
This commit is contained in:
parent
a20c3d8b1f
commit
726654f5b8
@ -50,6 +50,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Abrasion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Aerial;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Aquatic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arachnid;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arborist;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arcanic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Atmospheric;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Backstab;
|
||||
@ -225,6 +226,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Dynamite;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Xray;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@ -467,6 +469,8 @@ public class EcoEnchants {
|
||||
public static final EcoEnchant DYNAMITE = new Dynamite();
|
||||
public static final EcoEnchant CHARGE = new Charge();
|
||||
public static final EcoEnchant ASCEND = new Ascend();
|
||||
public static final EcoEnchant ARBORIST = new Arborist();
|
||||
public static final EcoEnchant XRAY = new Xray();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s.
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.util.drops.DropQueue;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Arborist extends EcoEnchant {
|
||||
public Arborist() {
|
||||
super(
|
||||
"arborist", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Tag.LEAVES.isTagged(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
|
||||
Material toDrop;
|
||||
|
||||
List<Material> materials = new ArrayList<>();
|
||||
|
||||
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items")) {
|
||||
Material material = Material.getMaterial(materialName.toUpperCase());
|
||||
if (material != null) {
|
||||
materials.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
toDrop = materials.get(new Random().nextInt(materials.size()));
|
||||
|
||||
if (toDrop == null) {
|
||||
toDrop = block.getType();
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(toDrop, 1);
|
||||
|
||||
new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addItem(item)
|
||||
.push();
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class Dynamite extends Spell {
|
||||
|
||||
@Override
|
||||
public void onUse(@NotNull final Player player,
|
||||
@NotNull final int level,
|
||||
final int level,
|
||||
@NotNull final PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
|
@ -0,0 +1,99 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.spell;
|
||||
|
||||
import com.willfp.eco.util.TeamUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Shulker;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Xray extends Spell {
|
||||
public Xray() {
|
||||
super("xray");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Block> toReveal = new HashSet<>();
|
||||
|
||||
int size = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "blocks-per-level") * level;
|
||||
|
||||
int ticks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks");
|
||||
|
||||
List<Material> materials = new ArrayList<>();
|
||||
|
||||
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks")) {
|
||||
Material material = Material.getMaterial(materialName.toUpperCase());
|
||||
if (material != null) {
|
||||
materials.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = -size; x <= size; x++) {
|
||||
for (int y = -size; y <= size; y++) {
|
||||
for (int z = -size; z <= size; z++) {
|
||||
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(x, y, z));
|
||||
|
||||
if (!materials.contains(block1.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean hidden = true;
|
||||
|
||||
for (BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}) {
|
||||
if (block1.getRelative(face).getType() == Material.AIR) {
|
||||
hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hidden) {
|
||||
continue;
|
||||
}
|
||||
|
||||
toReveal.add(block1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toReveal.forEach(block1 -> {
|
||||
Shulker shulker = (Shulker) block1.getWorld().spawnEntity(block1.getLocation(), EntityType.SHULKER);
|
||||
shulker.setInvulnerable(true);
|
||||
shulker.setSilent(true);
|
||||
shulker.setAI(false);
|
||||
shulker.setGravity(false);
|
||||
shulker.setGlowing(true);
|
||||
shulker.setInvisible(true);
|
||||
|
||||
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "color-glow")) {
|
||||
Team team = TeamUtils.getMaterialColorTeam(block1.getType());
|
||||
team.addEntry(shulker.getUniqueId().toString());
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().runLater(shulker::remove, ticks);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#
|
||||
# Arborist EcoEnchant
|
||||
#
|
||||
|
||||
name: "Arborist"
|
||||
description: Get more sticks, apples, and saplings from leaves.
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: rare
|
||||
|
||||
general-config:
|
||||
targets:
|
||||
- axe
|
||||
- shears
|
||||
grindstoneable: true
|
||||
disabled-in-worlds: []
|
||||
conflicts:
|
||||
- silk_touch
|
||||
maximum-level: 4
|
||||
|
||||
config:
|
||||
items:
|
||||
- stick
|
||||
- apple
|
||||
- acacia_sapling
|
||||
- birch_sapling
|
||||
- dark_oak_sapling
|
||||
- jungle_sapling
|
||||
- oak_sapling
|
||||
- spruce_sapling
|
||||
chance-per-level: 0.03 # Chance to drop item.
|
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Xray EcoEnchant
|
||||
#
|
||||
|
||||
name: "Xray"
|
||||
description: Show all nearby ores.
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: legendary
|
||||
|
||||
general-config:
|
||||
targets:
|
||||
- pickaxe
|
||||
grindstoneable: true
|
||||
disabled-in-worlds: []
|
||||
conflicts: []
|
||||
maximum-level: 3
|
||||
|
||||
config:
|
||||
activation-sound: ENTITY_ENDERMAN_TELEPORT
|
||||
cooldown: 60 # In seconds
|
||||
blocks:
|
||||
- coal_ore
|
||||
- iron_ore
|
||||
- gold_ore
|
||||
- redstone_ore
|
||||
- lapis_ore
|
||||
- ancient_debris
|
||||
- diamond_ore
|
||||
blocks-per-level: 3 # Blocks on all sides to scan per level
|
||||
ticks: 20
|
||||
color-glow: true # Color ore glow based on ore type.
|
88
eco-util/src/main/java/com/willfp/eco/util/TeamUtils.java
Normal file
88
eco-util/src/main/java/com/willfp/eco/util/TeamUtils.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class TeamUtils {
|
||||
/**
|
||||
* Ore ChatColors.
|
||||
*/
|
||||
private static final BiMap<Material, ChatColor> MATERIAL_COLORS = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* All chat color teams.
|
||||
*/
|
||||
private static final BiMap<ChatColor, Team> CHAT_COLOR_TEAMS = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* The server scoreboard.
|
||||
*/
|
||||
private static final Scoreboard SCOREBOARD = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
|
||||
/**
|
||||
* Get team from {@link ChatColor}.
|
||||
* <p>
|
||||
* For {@link org.bukkit.potion.PotionEffectType#GLOWING}.
|
||||
*
|
||||
* @param color The color to find the team for.
|
||||
* @return The team.
|
||||
*/
|
||||
public Team fromChatColor(@NotNull final ChatColor color) {
|
||||
if (CHAT_COLOR_TEAMS.containsKey(color)) {
|
||||
return CHAT_COLOR_TEAMS.get(color);
|
||||
}
|
||||
|
||||
Team team;
|
||||
|
||||
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EE-" + color.name())) {
|
||||
team = SCOREBOARD.registerNewTeam("EE-" + color.name());
|
||||
} else {
|
||||
team = SCOREBOARD.getTeam("EE-" + color.name());
|
||||
}
|
||||
assert team != null;
|
||||
team.setColor(color);
|
||||
CHAT_COLOR_TEAMS.forcePut(color, team);
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get team from material.
|
||||
* <p>
|
||||
* For {@link org.bukkit.potion.PotionEffectType#GLOWING}.
|
||||
*
|
||||
* @param material The material to find the team from.
|
||||
* @return The team.
|
||||
*/
|
||||
public Team getMaterialColorTeam(@NotNull final Material material) {
|
||||
return fromChatColor(MATERIAL_COLORS.getOrDefault(material, ChatColor.WHITE));
|
||||
}
|
||||
|
||||
static {
|
||||
for (ChatColor value : ChatColor.values()) {
|
||||
fromChatColor(value);
|
||||
}
|
||||
|
||||
MATERIAL_COLORS.forcePut(Material.COAL_ORE, ChatColor.BLACK);
|
||||
MATERIAL_COLORS.forcePut(Material.IRON_ORE, ChatColor.GRAY);
|
||||
MATERIAL_COLORS.forcePut(Material.GOLD_ORE, ChatColor.YELLOW);
|
||||
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.injection.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
@ -177,7 +178,7 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
@Override
|
||||
@NotNull
|
||||
public String getString(@NotNull final String path) {
|
||||
return Objects.requireNonNull(config.getString(path, ""));
|
||||
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,37 +128,36 @@ public class ArmorListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerInteractEvent(@NotNull final PlayerInteractEvent event) {
|
||||
if (event.useItemInHand().equals(Result.DENY)) {
|
||||
public void playerInteractEvent(@NotNull final PlayerInteractEvent e) {
|
||||
if (e.useItemInHand().equals(Result.DENY)) {
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == Action.PHYSICAL) {
|
||||
if (e.getAction() == Action.PHYSICAL) {
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = event.getPlayer();
|
||||
ArmorType newArmorType = ArmorType.matchType(event.getItem());
|
||||
if (
|
||||
newArmorType != null
|
||||
&& newArmorType.equals(ArmorType.HELMET)
|
||||
&& isAirOrNull(event.getPlayer().getInventory().getHelmet())
|
||||
|| newArmorType.equals(ArmorType.CHESTPLATE)
|
||||
&& isAirOrNull(event.getPlayer().getInventory().getChestplate())
|
||||
|| newArmorType.equals(ArmorType.LEGGINGS)
|
||||
&& isAirOrNull(event.getPlayer().getInventory().getLeggings())
|
||||
|| newArmorType.equals(ArmorType.BOOTS)
|
||||
&& isAirOrNull(event.getPlayer().getInventory().getBoots())) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(
|
||||
event.getPlayer(),
|
||||
ArmorEquipEvent.EquipMethod.HOTBAR,
|
||||
ArmorType.matchType(event.getItem()),
|
||||
null,
|
||||
event.getItem()
|
||||
);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
player.updateInventory();
|
||||
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = e.getPlayer();
|
||||
if (!e.useInteractedBlock().equals(Result.DENY)) {
|
||||
if (e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK && !player.isSneaking()) {
|
||||
Material mat = e.getClickedBlock().getType();
|
||||
}
|
||||
}
|
||||
ArmorType newArmorType = ArmorType.matchType(e.getItem());
|
||||
if (newArmorType != null) {
|
||||
if (newArmorType.equals(ArmorType.HELMET)
|
||||
&& isAirOrNull(e.getPlayer().getInventory().getHelmet())
|
||||
|| newArmorType.equals(ArmorType.CHESTPLATE)
|
||||
&& isAirOrNull(e.getPlayer().getInventory().getChestplate())
|
||||
|| newArmorType.equals(ArmorType.LEGGINGS)
|
||||
&& isAirOrNull(e.getPlayer().getInventory().getLeggings())
|
||||
|| newArmorType.equals(ArmorType.BOOTS)
|
||||
&& isAirOrNull(e.getPlayer().getInventory().getBoots())) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), ArmorEquipEvent.EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
e.setCancelled(true);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user