Skip to content

Commit

Permalink
Many Changes -112 Commits (#756)
Browse files Browse the repository at this point in the history
Changes:
- Fix mistakes in the default config.
- Added `/ce bottle` command.
- Added `/ce give` command.
- Fix item names being set to "" when there is no name set.
- Allow for " " to be set as a name on items.
- Add back drop toggle to veinMiner and blast.
- Make `/ce remove` only suggest enchants that are on the item.
- Make some methods pass a copy instead of the pointer to avoid overlap between handling.
- Fix players in spectator mode with wings not being able to fly.
- Fix telepathy not being able to work on stairs.
- Fix random enchantment level.
- Better isInt() check.
- TempFix factions errors caused by forks.
- Add an option to pick if TransmogScroll should add spaces between sections.
- Added config option to change the sound played for each enchant being added to an item.
- Fixed GKitz timer not displaying time in the correct format.
- Make ally mobs no longer target each other.
- Make the max for random enchants inclusive.
- Make random enchant levels not apply enchants that roll a 0.
- Fix Aura enchants not working.
- #774 
  - Added Per-Item Max Enchant
  - Slot Crystal
- #775
  - Make ally mobs not attack mcmmo party members.
  - Adds a cap on the number of times Aura enchantments can activate to reduce server load.
- #776 
  - Change it from individual checks over to using a single method.
- Changed Enchants over to each having their own timer.
  - Each enchant can only be used by each player once per second.
  - New permissions `crazyenchantments.%s.deny`
- Removed enchant timer for now.
- Started to change all armor enchantment checks to new methods.
- Removed silk spawner support. (if they handle it properly, enchants should still work with it)
- Properly create a block drop item event for every block break.
- #748 done by @Mowstyl 

Internal:
- Mass cleanup.
- Better methods.
- Less clutter.
- Better performance.

Bug fixes:
- All found along the way.

Misc
- Can't remember when, but `crazyenchantments.blast.use` was removed.

---------

Signed-off-by: TrueDarkLord <truedarklord.email@gmail.com>
Co-authored-by: Hernán Indíbil de la Cruz Calvo <indikalesken@hotmail.com>
  • Loading branch information
TrueDarkLord and Mowstyl committed Jan 28, 2024
1 parent 35fa984 commit d4ae91f
Show file tree
Hide file tree
Showing 79 changed files with 2,642 additions and 2,986 deletions.
9 changes: 4 additions & 5 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repositories {
val mcVersion = rootProject.properties["minecraftVersion"] as String

dependencies {
implementation("de.tr7zw", "item-nbt-api", "2.12.0")
implementation("de.tr7zw", "item-nbt-api", "2.12.2")

implementation("org.bstats", "bstats-bukkit", "3.0.2")

Expand Down Expand Up @@ -80,10 +80,6 @@ dependencies {
exclude("org.bukkit", "bukkit")
}

compileOnly("de.dustplanet", "silkspawners", "7.5.0") {
exclude("*", "*")
}

compileOnly("me.clip", "placeholderapi", "2.11.4")

compileOnly("com.github.oraxen", "oraxen", "1.160.0") {
Expand All @@ -92,7 +88,10 @@ dependencies {

compileOnly(fileTree("libs").include("*.jar"))

compileOnly("com.gmail.nossr50.mcMMO", "mcMMO", "2.1.226")

paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:$mcVersion-R0.1-SNAPSHOT")

}

val isBeta: Boolean get() = rootProject.extra["isBeta"]?.toString()?.toBoolean() ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.badbones69.crazyenchantments.paper.api.FileManager;
import com.badbones69.crazyenchantments.paper.api.FileManager.Files;
import com.badbones69.crazyenchantments.paper.api.PluginSupport.SupportedPlugins;
import com.badbones69.crazyenchantments.paper.api.support.misc.spawners.SilkSpawnerSupport;
import com.badbones69.crazyenchantments.paper.commands.BlackSmithCommand;
import com.badbones69.crazyenchantments.paper.commands.CECommand;
import com.badbones69.crazyenchantments.paper.commands.CETab;
Expand Down Expand Up @@ -61,6 +59,7 @@ public class CrazyEnchantments extends JavaPlugin implements Listener {

@Override
public void onEnable() {

plugin = this;

starter = new Starter();
Expand Down Expand Up @@ -140,8 +139,6 @@ private void enable() {
pluginManager.registerEvents(gKitzController = new GKitzController(), this);
}

if (SupportedPlugins.SILK_SPAWNERS.isCachedPluginLoaded()) pluginManager.registerEvents(new SilkSpawnerSupport(), this);

registerCommand(getCommand("crazyenchantments"), new CETab(), new CECommand());

registerCommand(getCommand("tinkerer"), null, new TinkerCommand());
Expand All @@ -152,7 +149,7 @@ private void enable() {

private void disable() {
bossBarController.removeAllBossBars();
armorEnchantments.stop();
if (armorEnchantments != null) armorEnchantments.stop();

if (starter.getAllyManager() != null) starter.getAllyManager().forceRemoveAllies();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
import com.badbones69.crazyenchantments.paper.utilities.misc.EventUtils;
import com.badbones69.crazyenchantments.paper.utilities.misc.NumberUtils;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.entity.item.ItemEntity;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftItem;
import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;

import java.util.*;

public class Methods {
Expand Down Expand Up @@ -87,6 +95,7 @@ public boolean hasPermission(Player player, String perm, boolean toggle) {
}
}

@NotNull
public ItemStack getItemInHand(Player player) {
return player.getInventory().getItemInMainHand();
}
Expand Down Expand Up @@ -190,8 +199,27 @@ public Integer percentPick(int max, int min) {
}
}

/**
*
* @param player The {@link Player} who's inventory should be checked.
* @return Returns if the player's inventory is full while letting them know.
*/
public boolean isInventoryFull(Player player) {
return player.getInventory().firstEmpty() == -1;
if (player.getInventory().firstEmpty() != -1) return false;
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
return true;
}

/**
*
* @param player The {@link Player} to give items to.
* @param item The {@link ItemStack} to give to the player.
*/
public void addItemToInventory(Player player, ItemStack item) {
player.getInventory().addItem(item).values().forEach(x -> player.getWorld().dropItem(player.getLocation(), x));
}
public void addItemToInventory(Player player, List<Item> itemList) {
itemList.forEach(x -> addItemToInventory(player, x.getItemStack()));
}

public List<LivingEntity> getNearbyLivingEntities(double radius, Entity entity) {
Expand Down Expand Up @@ -230,58 +258,20 @@ public void fireWork(Location loc, ArrayList<Color> colors) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, firework::detonate, 2);
}

public String stripString(String string) {
return string != null ? string.replace("-", "").replace("_", "").replace(" ", "") : "";
}

public Enchantment getEnchantment(String enchantmentName) {
try {
// HashMap<String, String> enchantments = getEnchantments();
enchantmentName = stripString(enchantmentName);
enchantmentName = enchantmentName.replaceAll("-|_| ", "");

for (Enchantment enchantment : Enchantment.values()) {
// MC 1.13+ has the correct names.
if (stripString(enchantment.getKey().getKey()).equalsIgnoreCase(enchantmentName)) return enchantment;
if (enchantment.getKey().getKey().replaceAll("-|_| ", "").equalsIgnoreCase(enchantmentName)) return enchantment;
}
} catch (Exception ignore) {}

return null;
}

public HashMap<String, String> getEnchantments() {
HashMap<String, String> enchantments = new HashMap<>();
enchantments.put("ARROW_DAMAGE", "Power");
enchantments.put("ARROW_FIRE", "Flame");
enchantments.put("ARROW_INFINITE", "Infinity");
enchantments.put("ARROW_KNOCKBACK", "Punch");
enchantments.put("DAMAGE_ALL", "Sharpness");
enchantments.put("DAMAGE_ARTHROPODS", "Bane_Of_Arthropods");
enchantments.put("DAMAGE_UNDEAD", "Smite");
enchantments.put("DEPTH_STRIDER", "Depth_Strider");
enchantments.put("DIG_SPEED", "Efficiency");
enchantments.put("DURABILITY", "Unbreaking");
enchantments.put("FIRE_ASPECT", "Fire_Aspect");
enchantments.put("KNOCKBACK", "KnockBack");
enchantments.put("LOOT_BONUS_BLOCKS", "Fortune");
enchantments.put("LOOT_BONUS_MOBS", "Looting");
enchantments.put("LUCK", "Luck_Of_The_Sea");
enchantments.put("LURE", "Lure");
enchantments.put("OXYGEN", "Respiration");
enchantments.put("PROTECTION_ENVIRONMENTAL", "Protection");
enchantments.put("PROTECTION_EXPLOSIONS", "Blast_Protection");
enchantments.put("PROTECTION_FALL", "Feather_Falling");
enchantments.put("PROTECTION_FIRE", "Fire_Protection");
enchantments.put("PROTECTION_PROJECTILE", "Projectile_Protection");
enchantments.put("SILK_TOUCH", "Silk_Touch");
enchantments.put("THORNS", "Thorns");
enchantments.put("WATER_WORKER", "Aqua_Affinity");
enchantments.put("BINDING_CURSE", "Curse_Of_Binding");
enchantments.put("MENDING", "Mending");
enchantments.put("FROST_WALKER", "Frost_Walker");
enchantments.put("VANISHING_CURSE", "Curse_Of_Vanishing");
return enchantments;
}

public int getMaxDurability(ItemStack item) {
if (!PluginSupport.SupportedPlugins.ORAXEN.isPluginLoaded()) return item.getType().getMaxDurability();

Expand Down Expand Up @@ -350,7 +340,7 @@ public void removeDurability(ItemStack item, Player player) {
}

public void explode(Entity player) {
spawnParticles(player, player.getWorld(), player.getLocation());
spawnExplodeParticles(player, player.getWorld(), player.getLocation());

for (Entity entity : getNearbyEntities(3D, player)) {
if (pluginSupport.allowCombat(entity.getLocation())) {
Expand All @@ -377,7 +367,7 @@ public void explode(Entity player) {
}
}

private void spawnParticles(Entity player, World world, Location location) {
private void spawnExplodeParticles(Entity player, World world, Location location) {
if (player.getLocation().getWorld() != null) {
player.getLocation().getWorld().spawnParticle(Particle.FLAME, player.getLocation(), 200);
player.getLocation().getWorld().spawnParticle(Particle.CLOUD, player.getLocation(), 30, .4F, .5F, .4F);
Expand All @@ -388,7 +378,7 @@ private void spawnParticles(Entity player, World world, Location location) {
}

public void explode(Entity player, Entity arrow) {
spawnParticles(arrow, player.getWorld(), player.getLocation());
spawnExplodeParticles(arrow, player.getWorld(), player.getLocation());

for (Entity entity : getNearbyEntities(3D, arrow)) {
if (pluginSupport.allowCombat(entity.getLocation())) {
Expand Down Expand Up @@ -419,28 +409,6 @@ public void explode(Entity player, Entity arrow) {
}
}

public void checkPotions(Map<PotionEffectType, Integer> effects, Player player) {
for (Map.Entry<PotionEffectType, Integer> type : effects.entrySet()) {
Integer value = type.getValue();
PotionEffectType key = type.getKey();

player.removePotionEffect(key);
if (value < 0) continue;
PotionEffect potionEffect = new PotionEffect(key, getInfinity(), value);
player.addPotionEffect(potionEffect);
}
}

public int getInfinity() {

int versionInt = Integer.parseInt(plugin.getServer().getVersion().split("MC:")[1]
.replace(")", "")
.replace(".", "")
.replace(" ", ""));

return versionInt >= 1194 || versionInt == 120 ? -1 : Integer.MAX_VALUE;
}

public HashSet<Block> getEnchantBlocks(Location loc, Location loc2) {
HashSet<Block> blockList = new HashSet<>();
int topBlockX = (Math.max(loc.getBlockX(), loc2.getBlockX()));
Expand Down Expand Up @@ -472,7 +440,7 @@ public void entityEvent(Player damager, LivingEntity entity, EntityDamageByEntit
EventUtils.removeIgnoredUUID(damager.getUniqueId());
}

public void checkEntity(LivingEntity en) {
public void lightning(LivingEntity en) {
Location loc = en.getLocation();
if (loc.getWorld() != null) loc.getWorld().strikeLightning(loc);
int lightningSoundRange = Files.CONFIG.getFile().getInt("Settings.EnchantmentOptions.Lightning-Sound-Range", 160);
Expand Down Expand Up @@ -517,4 +485,54 @@ public ItemBuilder getRandomPaneColor() {
"BLACK_STAINED_GLASS_PANE");
return new ItemBuilder().setMaterial(colors.get(random.nextInt(colors.size())));
}

/**
* @see #playerBreakBlock(Player, Block, ItemStack, boolean)
*/
public boolean playerBreakBlock(Player player, Block block, ItemStack tool) {
return playerBreakBlock(player, block, tool, true);
}

/**
* Imitates all the events called when a player breaks a block.
* Only calls #BlockDropItemEvent if the event isn't cancelled,
* and there are drops.
* @param player The player that will "break" the block.
* @param block The block that was broken.
* @param tool ItemStack used to break the block.
* @return If the event was cancelled.
*/
public boolean playerBreakBlock(Player player, Block block, ItemStack tool, boolean hasDrops) {
BlockBreakEvent blockBreak = new BlockBreakEvent(block, player);
Collection<ItemStack> dropItems = tool != null ? block.getDrops(tool, player) : block.getDrops();
if (dropItems.isEmpty()) blockBreak.setDropItems(false);

EventUtils.addIgnoredEvent(blockBreak);
plugin.getServer().getPluginManager().callEvent(blockBreak);
EventUtils.removeIgnoredEvent(blockBreak);

if (blockBreak.isCancelled()) return true;

if (blockBreak.isDropItems() && hasDrops) blockDropItems(player, block, dropItems);

block.setType(Material.AIR);
return false;
}

/**
* Imitates the blockDropItemEvent usage.
* @param player The player that broke the block.
* @param block The block that was broken.
* @param items The items that will be dropped from the broken block.
*/
public void blockDropItems(Player player, Block block, Collection<ItemStack> items) {
List<Item> dropItems = new ArrayList<>();
items.forEach(item -> dropItems.add(block.getWorld().dropItemNaturally(block.getLocation(), item)));

BlockDropItemEvent event = new BlockDropItemEvent(block, block.getState(), player, dropItems);
plugin.getServer().getPluginManager().callEvent(event);

if (event.isCancelled()) dropItems.forEach(Entity::remove);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import com.badbones69.crazyenchantments.paper.api.support.misc.OraxenSupport;
import com.badbones69.crazyenchantments.paper.controllers.EnchantmentControl;
import com.badbones69.crazyenchantments.paper.controllers.settings.EnchantmentBookSettings;
import com.badbones69.crazyenchantments.paper.controllers.settings.EnchantmentSettings;
import com.badbones69.crazyenchantments.paper.controllers.settings.ProtectionCrystalSettings;
import com.badbones69.crazyenchantments.paper.listeners.ScramblerListener;
import com.badbones69.crazyenchantments.paper.listeners.ScrollListener;
import com.badbones69.crazyenchantments.paper.listeners.SlotCrystalListener;
import com.badbones69.crazyenchantments.paper.utilities.BowUtils;

public class Starter {
Expand All @@ -37,7 +37,6 @@ public class Starter {

// Settings.
private ProtectionCrystalSettings protectionCrystalSettings;
private EnchantmentSettings enchantmentSettings;
private EnchantmentBookSettings enchantmentBookSettings;

// Plugin Utils.
Expand Down Expand Up @@ -67,6 +66,8 @@ public class Starter {
// Listeners.
private ScramblerListener scramblerListener;
private ScrollListener scrollListener;
private SlotCrystalListener slotCrystalListener;


public void run() {
this.fileManager = new FileManager();
Expand Down Expand Up @@ -111,13 +112,12 @@ public void run() {
// Listeners.
this.plugin.pluginManager.registerEvents(this.scramblerListener = new ScramblerListener(), this.plugin);
this.plugin.pluginManager.registerEvents(this.scrollListener = new ScrollListener(), this.plugin);
this.plugin.pluginManager.registerEvents(this.slotCrystalListener = new SlotCrystalListener(), this.plugin);

this.skullCreator = new SkullCreator();

this.crazyManager = new CrazyManager();

this.enchantmentSettings = new EnchantmentSettings();

// Plugin Utils.
this.bowUtils = new BowUtils();

Expand Down Expand Up @@ -149,10 +149,6 @@ public ProtectionCrystalSettings getProtectionCrystalSettings() {
return this.protectionCrystalSettings;
}

public EnchantmentSettings getEnchantmentSettings() {
return this.enchantmentSettings;
}

public EnchantmentBookSettings getEnchantmentBookSettings() {
return this.enchantmentBookSettings;
}
Expand Down Expand Up @@ -229,6 +225,10 @@ public ScrollListener getScrollListener() {
return this.scrollListener;
}

public SlotCrystalListener getSlotCrystalListener() {
return this.slotCrystalListener;
}

// Plugin Utils.
public BowUtils getBowUtils() {
return this.bowUtils;
Expand Down
Loading

0 comments on commit d4ae91f

Please sign in to comment.