Skip to content

Commit

Permalink
Merge pull request #72 from FN-FAL113/Dev/newgem-fixes
Browse files Browse the repository at this point in the history
"new gem, chores and important fixes"
  • Loading branch information
FN-FAL113 committed Apr 11, 2022
2 parents a701f9d + feb6c5c commit 5e572d8
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ne.fnfal113</groupId>
<artifactId>FNAmplifications</artifactId>
<version>3.1.7-UNOFFICIAL</version>
<version>3.1.8-UNOFFICIAL</version>
<packaging>jar</packaging>

<name>FNAmplifications</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import java.util.concurrent.ThreadLocalRandom;

public class AchillesHeelGem extends AbstractGem implements OnProjectileDamageHandler {

@Getter
Expand Down Expand Up @@ -58,8 +60,10 @@ public void onProjectileDamage(EntityDamageByEntityEvent event, Player shooter,
return;
}

if((projectile.getLocation().getY() - entity.getLocation().getY()) < 0.5){
if(ThreadLocalRandom.current().nextInt(100) < getChance() &&
(projectile.getLocation().getY() - entity.getLocation().getY()) < 0.5){
event.setDamage(event.getDamage() * 2.0);
shooter.sendMessage(Utils.colorTranslator("&6Achilles heel gem has taken effect!"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public void onDrag(InventoryClickEvent event, Player player) {

@Override
public void onDurabilityChange(PlayerItemDamageEvent event) {
int random = ThreadLocalRandom.current().nextInt(100);
if(random < getChance()){

if(ThreadLocalRandom.current().nextInt(100) < getChance()){
event.setCancelled(true);
event.getPlayer().sendMessage(Utils.colorTranslator("&6Adamantine gem has taken effect!"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void onDamage(EntityDamageByEntityEvent event){
Damageable damageable = (Damageable) meta;
damageable.setDamage(damageable.getDamage() + 4);
entityEquipment.setItemMeta(meta);
event.getDamager().sendMessage(Utils.colorTranslator("&eArmor impair gem has taken effect!"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onDrag(InventoryClickEvent event, Player player) {
public void onDamage(EntityDamageByEntityEvent event) {
if(ThreadLocalRandom.current().nextInt(100) < getChance() &&
event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE){
event.getEntity().sendMessage(Utils.colorTranslator("&6Enemy arrow deflected! arrow avert gem has taken effect."));
event.getEntity().sendMessage(Utils.colorTranslator("&6Arrow avert gem has taken effect!"));
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
Creeper creeper = player.getWorld().spawn(loc.clone(), Creeper.class);
creeper.setPowered(true); // big boomer creeper
creeper.setExplosionRadius(3);
event.getEntity().sendMessage(Utils.colorTranslator("&cAvenge gem has taken effect!"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onProjectileDamage(EntityDamageByEntityEvent event, Player shooter,

if(ThreadLocalRandom.current().nextInt(100) < getChance()){
entity.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 80, 2, true, false, false));
shooter.sendMessage(Utils.colorTranslator("&cBlind bind gem has taken effect!"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ public void onDamage(EntityDamageByEntityEvent event) {
if(!(event.getDamager() instanceof LivingEntity)){
return;
}

LivingEntity damager = (LivingEntity) event.getDamager();

if(damager.getEquipment() == null){
return;
}

if(WeaponArmorEnum.AXES.isTagged(damager.getEquipment().getItemInMainHand().getType())){
int random = ThreadLocalRandom.current().nextInt(100);
if(random < getChance()){
if(ThreadLocalRandom.current().nextInt(100) < getChance()){
event.setDamage(event.getDamage() * 0.75);
event.getDamager().sendMessage(Utils.colorTranslator("&6Deberserk gem has taken effect!"));
}
}
}
Expand Down
96 changes: 96 additions & 0 deletions src/main/java/ne/fnfal113/fnamplifications/gems/DisarmorGem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package ne.fnfal113.fnamplifications.gems;

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import lombok.Getter;
import ne.fnfal113.fnamplifications.FNAmplifications;
import ne.fnfal113.fnamplifications.gems.abstracts.AbstractGem;
import ne.fnfal113.fnamplifications.gems.handlers.OnDamageHandler;
import ne.fnfal113.fnamplifications.gems.implementation.Gem;
import ne.fnfal113.fnamplifications.utils.Utils;
import ne.fnfal113.fnamplifications.utils.WeaponArmorEnum;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import java.util.concurrent.ThreadLocalRandom;

public class DisarmorGem extends AbstractGem implements OnDamageHandler {

@Getter
private final int chance;

public DisarmorGem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe, 10);

this.chance = FNAmplifications.getInstance().getConfigManager().getValueById(this.getId() + "-percent-chance");
}

@Override
public void onDrag(InventoryClickEvent event, Player player) {
if(event.getCursor() == null){
return;
}

ItemStack currentItem = event.getCurrentItem();

SlimefunItem slimefunItem = SlimefunItem.getByItem(event.getCursor());

if(slimefunItem != null && currentItem != null) {
if (WeaponArmorEnum.AXES.isTagged(currentItem.getType()) || WeaponArmorEnum.SWORDS.isTagged(currentItem.getType())) {
new Gem(slimefunItem, currentItem, player).onDrag(event, false);
} else {
player.sendMessage(Utils.colorTranslator("&eInvalid item to socket! Gem works on swords and axes only"));
}
}
}

@Override
public void onDamage(EntityDamageByEntityEvent event) {
if(!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)){
return;
}
Player victim = (Player) event.getEntity();
Player damager = (Player) event.getDamager();

if(ThreadLocalRandom.current().nextInt(100) < getChance()) {
int slot = victim.getInventory().firstEmpty();

if (victim.getInventory().getHelmet() != null && ThreadLocalRandom.current().nextInt(100) < 50) {
ItemStack helmet = victim.getInventory().getHelmet();
victim.getInventory().setHelmet(null);

moveArmorToInventory(slot, victim, damager, helmet);
} else if(victim.getInventory().getChestplate() != null && ThreadLocalRandom.current().nextInt(100) < 50){
ItemStack chestplate = victim.getInventory().getChestplate();
victim.getInventory().setChestplate(null);

moveArmorToInventory(slot, victim, damager, chestplate);
} else if(victim.getInventory().getLeggings() != null && ThreadLocalRandom.current().nextInt(100) < 50){
ItemStack leggings = victim.getInventory().getLeggings();
victim.getInventory().setLeggings(null);

moveArmorToInventory(slot, victim, damager, leggings);
} else if(victim.getInventory().getBoots() != null && ThreadLocalRandom.current().nextInt(100) < 50){
ItemStack boots = victim.getInventory().getBoots();
victim.getInventory().setBoots(null);

moveArmorToInventory(slot, victim, damager, boots);
}
}

}

public void moveArmorToInventory(int slot, Player victim, Player damager, ItemStack armor){
if (slot != -1) {
victim.getInventory().setItem(slot, armor.clone());
} else {
victim.getWorld().dropItem(victim.getLocation(), armor.clone());
}
damager.sendMessage(Utils.colorTranslator("&6Disarmor gem has taken effect!"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void onDamage(EntityDamageByEntityEvent event){
return;
}

player.sendMessage(Utils.colorTranslator("&6Guardian gem has taken effect!"));
runnableMap.put(player.getUniqueId(),
guardianTask.runTaskTimer(FNAmplifications.getInstance(), 5L, 3L));
entityUUIDMap.put(player.getUniqueId(), guardianTask.getZombie());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void onDamage(EntityDamageByEntityEvent event){
Location newDamagerLoc = new Location(victim.getWorld(), damager.getLocation().getX() - nX,
damager.getLocation().getY(), damager.getLocation().getZ() - nZ, damager.getLocation().getYaw(), damager.getLocation().getPitch());
victim.teleport(newDamagerLoc);
victim.sendMessage(Utils.colorTranslator("&6Impostor gem has taken effect!"));
} // teleport behind the attacker
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void onDamage(EntityDamageByEntityEvent event){

if(random < getChance()){
livingEntity.setFireTicks(60);
event.getDamager().sendMessage(Utils.colorTranslator("&cInferno gem has taken effect!"));
} // set the attacked entity on fire

for(Entity entity : livingEntity.getNearbyEntities(7, 4,7)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onDamage(EntityDamageByEntityEvent event) {
int random = ThreadLocalRandom.current().nextInt(100);
if(random < getChance()){
event.setDamage(event.getDamage() * 0.75);
event.getDamager().sendMessage(Utils.colorTranslator("&6Parry gem has taken effect!"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void onProjectileDamage(EntityDamageByEntityEvent event, Player shooter,
if(ThreadLocalRandom.current().nextInt(100) < getChance()){
shooter.getWorld().spawnParticle(Particle.FLASH, entity.getLocation(), 2);
entity.teleport(shooter);
shooter.sendMessage(Utils.colorTranslator("&6Psychokinesis gem has taken effect!"));
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/ne/fnfal113/fnamplifications/gems/StoutGem.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public void onDrag(InventoryClickEvent event, Player player) {

@Override
public void onDurabilityChange(PlayerItemDamageEvent event) {
int random = ThreadLocalRandom.current().nextInt(100);
if(random < getChance()){
if(ThreadLocalRandom.current().nextInt(100) < getChance()){
event.setCancelled(true);
event.getPlayer().sendMessage(Utils.colorTranslator("&6Stout gem has taken effect!"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void onDamage(EntityDamageByEntityEvent event){

if(ThreadLocalRandom.current().nextInt(100) < getChance()){
event.setCancelled(true);
event.getEntity().sendMessage(Utils.colorTranslator("&6Thorn away gem has taken effect!"));
} // cancel any thorn damage

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void onDamage(EntityDamageByEntityEvent event){
if(ThreadLocalRandom.current().nextInt(100) < getChance()){
livingEntity.getWorld().strikeLightning(livingEntity.getLocation());
player.setNoDamageTicks(20);
player.sendMessage(Utils.colorTranslator("&6Thunderbolt gem has taken effect!"));
} // if below the chance, strike lightning at the victim and set no damage for the attacker for 1 second
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ FNAmpItems.PESTILENCE_RUNE, new ItemStack(Material.ROTTEN_FLESH), FNAmpItems.PES
.register(instance);

new AchillesHeelGem(FNAmpItems.FN_GEMS, FNAmpItems.FN_GEM_ACHILLES_HEEL, FnGemAltar.RECIPE_TYPE, new ItemStack[]{
FNAmpItems.PESTILENCE_RUNE, new ItemStack(Material.ROTTEN_FLESH), FNAmpItems.PESTILENCE_RUNE,
new ItemStack(Material.ROTTEN_FLESH), new ItemStack(Material.EMERALD), new ItemStack(Material.ROTTEN_FLESH),
FNAmpItems.LINGER_RUNE, SlimefunItems.MAGIC_SUGAR, FNAmpItems.LINGER_RUNE})
FNAmpItems.AGILITY_RUNE, new ItemStack(Material.FEATHER), FNAmpItems.AGILITY_RUNE,
new ItemStack(Material.ARROW), new ItemStack(Material.EMERALD), new ItemStack(Material.ARROW),
FNAmpItems.PESTILENCE_RUNE, null, FNAmpItems.INTELLECT_RUNE})
.register(instance);

new DisarmorGem(FNAmpItems.FN_GEMS, FNAmpItems.FN_GEM_DISARMOR, FnGemAltar.RECIPE_TYPE, new ItemStack[]{
FNAmpItems.INTELLECT_RUNE, null, FNAmpItems.PESTILENCE_RUNE,
new ItemStack(Material.BLAZE_POWDER), new ItemStack(Material.EMERALD), new ItemStack(Material.BLAZE_POWDER),
FNAmpItems.POWER_RUNE, null, FNAmpItems.INTELLECT_RUNE})
.register(instance);

new FlawlessUnbindGem(FNAmpItems.FN_GEMS, FNAmpItems.FN_GEM_FLAWLESS_UNBIND, FnGemAltar.RECIPE_TYPE, new ItemStack[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import ne.fnfal113.fnamplifications.utils.Utils;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -34,11 +35,13 @@ public void run() {

getArmorStand().teleport(asLocation.subtract(asVector.subtract(pVector).normalize()).setDirection(pLocation.getDirection()));

// if player is not online, drop the throwable immediately
if(!getPlayer().isOnline()){
dropItem(asLocation);
stopTask();
}

// drop the item if the distance between player and throwable is square root of 150 blocks away
if(distanceBetween(asLocation, pLocation) > 150){
Location dropLoc = dropItem(asLocation);
getPlayer().sendMessage(Utils.colorTranslator("&cWeapon has not been returned because you're too far!"));
Expand All @@ -57,24 +60,25 @@ public void run() {
} else {
getPlayer().getInventory().addItem(getItemStack().clone());
}

getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0F, 1.0F);
stopTask();
}
}

public Location dropItem(Location location){
public Location dropItem(Location location){ // drop the throwable weapon if player inventory is full
Item droppedItem = getPlayer().getWorld().dropItem(location, getItemStack().clone());
droppedItem.setOwner(getPlayer().getUniqueId());
droppedItem.setGlowing(true);

return droppedItem.getLocation();
}

// get the distance between two locations and return the square root of the distance
public double distanceBetween(Location asLoc, Location pLoc){
return asLoc.distance(pLoc);
}

public void stopTask(){
public void stopTask(){ // stop the task once task has been completed
getArmorStand().remove();
this.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public boolean isBelow4Weapons(Player player){
public void floatThrowItem(Player player, ItemStack itemStack, boolean returnWeapon){
ArmorStand as = spawnArmorstand(player, itemStack, false);

player.playSound(player.getLocation(), Sound.ENTITY_ILLUSIONER_PREPARE_MIRROR, 1.0F, 1.0F);

int id = Bukkit.getScheduler().runTaskTimer(FNAmplifications.getInstance(), () -> {
int x = ThreadLocalRandom.current().nextInt(3);
int xFinal = x < 1 ? -2 : 2;
Expand All @@ -79,6 +81,7 @@ public void throwWeapon(Player player, ArmorStand as, ItemStack itemStack, boole
Vector vector = player.getLocation().add(player.getLocation().getDirection().multiply(9).normalize())
.subtract(player.getLocation().toVector()).toVector();

player.playSound(player.getLocation(), Sound.ENTITY_WITCH_THROW, 1.0F, 1.0F);
Bukkit.getScheduler().runTaskLater(FNAmplifications.getInstance(), () -> {
as.teleport(player.getLocation().add(0,0.9, 0));

Expand Down
Loading

0 comments on commit 5e572d8

Please sign in to comment.