Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
buiawpkgew1 committed Feb 26, 2022
2 parents dd61822 + 9936858 commit 1ef3a44
Show file tree
Hide file tree
Showing 35 changed files with 1,071 additions and 1,310 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>2.9.9</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>FNAmplifications</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.guizhanss.guizhanlib.updater.GuizhanBuildsUpdater;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import ne.fnfal113.fnamplifications.Items.FNAmpItemSetup;
Expand Down Expand Up @@ -64,6 +65,11 @@ public void onEnable() {
}
}

@Override
public void onDisable(){
Bukkit.getScheduler().cancelTasks(FNAmplifications.getInstance());
}

@Nonnull
@Override
public JavaPlugin getJavaPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onDrag(InventoryClickEvent event, Player player){
ItemMeta meta = currentItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if(checkGemAmount(container, currentItem) < 3) {
if(checkGemAmount(container, currentItem) < 4) {
Gem gem = new Gem(slimefunItem, currentItem, player);
if(!gem.isSameGem(currentItem)){
player.setItemOnCursor(new ItemStack(Material.AIR));
Expand All @@ -63,7 +63,7 @@ public void onDrag(InventoryClickEvent event, Player player){
}
event.setCancelled(true);
} else {
player.sendMessage(Utils.colorTranslator("&eOnly 3 gems per item is allowed!"));
player.sendMessage(Utils.colorTranslator("&eOnly 4 gems per item is allowed!"));
player.playSound(player.getLocation(), Sound.UI_TOAST_OUT, 1.0F, 1.0F);
event.setCancelled(true);
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/ne/fnfal113/fnamplifications/Gems/AxeThrowieGem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ne.fnfal113.fnamplifications.FNAmplifications;
import ne.fnfal113.fnamplifications.Gems.Implementation.Gem;
import ne.fnfal113.fnamplifications.Gems.Interface.GemImpl;
import ne.fnfal113.fnamplifications.Gems.Implementation.ThrowWeaponTask;
import ne.fnfal113.fnamplifications.Gems.Implementation.ThrowableWeapon;
import ne.fnfal113.fnamplifications.Gems.Implementation.WeaponArmorEnum;
import ne.fnfal113.fnamplifications.Items.FNAmpItems;
import ne.fnfal113.fnamplifications.Multiblock.FnGemAltar;
Expand All @@ -22,11 +22,12 @@
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

@SuppressWarnings("ConstantConditions")
public class AxeThrowieGem extends SlimefunItem implements GemImpl {

private static final SlimefunAddon plugin = FNAmplifications.getInstance();

private final ThrowWeaponTask throwWeaponTask = new ThrowWeaponTask();
private final ThrowableWeapon throwableWeapon = new ThrowableWeapon();

public AxeThrowieGem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
Expand All @@ -46,7 +47,7 @@ public void onDrag(InventoryClickEvent event, Player player){
ItemMeta meta = currentItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if(checkGemAmount(container, currentItem) < 3) {
if(checkGemAmount(container, currentItem) < 4) {
Gem gem = new Gem(slimefunItem, currentItem, player);
if(!gem.isSameGem(currentItem)){
player.setItemOnCursor(new ItemStack(Material.AIR));
Expand All @@ -55,7 +56,7 @@ public void onDrag(InventoryClickEvent event, Player player){
player.sendMessage(Utils.colorTranslator("&6Your item has " + gem.getSfItemName() + " &6socketed already!"));
}
} else {
player.sendMessage(Utils.colorTranslator("&eOnly 3 gems per item is allowed!"));
player.sendMessage(Utils.colorTranslator("&eOnly 4 gems per item is allowed!"));
player.playSound(player.getLocation(), Sound.UI_TOAST_OUT, 1.0F, 1.0F);
}
event.setCancelled(true);
Expand All @@ -73,8 +74,11 @@ public int checkGemAmount(PersistentDataContainer pdc, ItemStack itemStack){
public void onRightClick(Player player){
ItemStack itemStack = player.getInventory().getItemInMainHand();

throwWeaponTask.throwWeapon(player, throwWeaponTask.spawnArmorstand(player, itemStack.clone(), false), itemStack.clone(),
true, false, false);
PersistentDataContainer pdc = itemStack.getItemMeta().getPersistentDataContainer();
NamespacedKey key = new NamespacedKey(FNAmplifications.getInstance(), "return_weapon");

throwableWeapon.throwWeapon(player, throwableWeapon.spawnArmorstand(player, itemStack.clone(), false), itemStack.clone(),
true, false, false, Boolean.parseBoolean(pdc.getOrDefault(key, PersistentDataType.STRING, "false")));

itemStack.setAmount(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onDrag(InventoryClickEvent event, Player player){
ItemMeta meta = currentItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if(checkGemAmount(container, currentItem) < 3) {
if(checkGemAmount(container, currentItem) < 4) {
Gem gem = new Gem(slimefunItem, currentItem, player);
if(!gem.isSameGem(currentItem)){
player.setItemOnCursor(new ItemStack(Material.AIR));
Expand All @@ -64,7 +64,7 @@ public void onDrag(InventoryClickEvent event, Player player){
player.sendMessage(Utils.colorTranslator("&6Your item has " + gem.getSfItemName() + " &6socketed already!"));
}
} else {
player.sendMessage(Utils.colorTranslator("&eOnly 3 gems per item is allowed!"));
player.sendMessage(Utils.colorTranslator("&eOnly 4 gems per item is allowed!"));
player.playSound(player.getLocation(), Sound.UI_TOAST_OUT, 1.0F, 1.0F);
}
event.setCancelled(true);
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/ne/fnfal113/fnamplifications/Gems/DamnationGem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ne.fnfal113.fnamplifications.FNAmplifications;
import ne.fnfal113.fnamplifications.Gems.Implementation.Gem;
import ne.fnfal113.fnamplifications.Gems.Interface.GemImpl;
import ne.fnfal113.fnamplifications.Gems.Implementation.ThrowWeaponTask;
import ne.fnfal113.fnamplifications.Gems.Implementation.ThrowableWeapon;
import ne.fnfal113.fnamplifications.Gems.Implementation.WeaponArmorEnum;
import ne.fnfal113.fnamplifications.Items.FNAmpItems;
import ne.fnfal113.fnamplifications.Multiblock.FnGemAltar;
Expand All @@ -22,11 +22,12 @@
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

@SuppressWarnings("ConstantConditions")
public class DamnationGem extends SlimefunItem implements GemImpl {

private static final SlimefunAddon plugin = FNAmplifications.getInstance();

private final ThrowWeaponTask throwWeaponTask = new ThrowWeaponTask();
private final ThrowableWeapon throwableWeapon = new ThrowableWeapon();

public DamnationGem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
Expand All @@ -47,7 +48,7 @@ public void onDrag(InventoryClickEvent event, Player player){
ItemMeta meta = currentItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if(checkGemAmount(container, currentItem) < 3) {
if(checkGemAmount(container, currentItem) < 4) {
Gem gem = new Gem(slimefunItem, currentItem, player);
if(!gem.isSameGem(currentItem)){
player.setItemOnCursor(new ItemStack(Material.AIR));
Expand All @@ -56,7 +57,7 @@ public void onDrag(InventoryClickEvent event, Player player){
player.sendMessage(Utils.colorTranslator("&6Your item has " + gem.getSfItemName() + " &6socketed already!"));
}
} else {
player.sendMessage(Utils.colorTranslator("&eOnly 3 gems per item is allowed!"));
player.sendMessage(Utils.colorTranslator("&eOnly 4 gems per item is allowed!"));
player.playSound(player.getLocation(), Sound.UI_TOAST_OUT, 1.0F, 1.0F);
}
event.setCancelled(true);
Expand All @@ -74,8 +75,11 @@ public int checkGemAmount(PersistentDataContainer pdc, ItemStack itemStack){
public void onRightClick(Player player){
ItemStack itemStack = player.getInventory().getItemInMainHand();

if(throwWeaponTask.isBelow4Weapons(player)) {
throwWeaponTask.floatThrowItem(player, itemStack.clone());
if(throwableWeapon.isBelow4Weapons(player)) {
PersistentDataContainer pdc = itemStack.getItemMeta().getPersistentDataContainer();
NamespacedKey key = new NamespacedKey(FNAmplifications.getInstance(), "return_weapon");

throwableWeapon.floatThrowItem(player, itemStack.clone(), Boolean.parseBoolean(pdc.getOrDefault(key, PersistentDataType.STRING, "false")));

itemStack.setAmount(0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ne/fnfal113/fnamplifications/Gems/HastyGem.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void onDrag(InventoryClickEvent event, Player player){
ItemMeta meta = currentItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if(checkGemAmount(container, currentItem) < 3) {
if(checkGemAmount(container, currentItem) < 4) {
Gem gem = new Gem(slimefunItem, currentItem, player);
if(!gem.isSameGem(currentItem)){
player.setItemOnCursor(new ItemStack(Material.AIR));
Expand All @@ -69,7 +69,7 @@ public void onDrag(InventoryClickEvent event, Player player){
}
event.setCancelled(true);
} else {
player.sendMessage(Utils.colorTranslator("&eOnly 3 gems per item is allowed!"));
player.sendMessage(Utils.colorTranslator("&eOnly 4 gems per item is allowed!"));
player.playSound(player.getLocation(), Sound.UI_TOAST_OUT, 1.0F, 1.0F);
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Locale;

@SuppressWarnings("ConstantConditions")
public class Gem {

private final SlimefunItem slimefunItem;
Expand All @@ -36,7 +37,7 @@ public Gem(SlimefunItem sfItem, ItemStack itemToSocket, Player p){
this.sfItemName = sfItem.getItemName();
this.gemID = sfItem.getId();
this.player = p;
this.key1 = new NamespacedKey(FNAmplifications.getInstance(), sfItem.getId());
this.key1 = new NamespacedKey(FNAmplifications.getInstance(), sfItem.getId().toLowerCase());
this.key2 = new NamespacedKey(FNAmplifications.getInstance(), itemToSocket.getType().toString().toLowerCase() + "_socket_amount");

}
Expand Down Expand Up @@ -127,4 +128,12 @@ public boolean isSameGem(ItemStack itemStack){
return container.has(getStorageKey1(), PersistentDataType.STRING);
}

public void retaliateWeapon(){
ItemMeta meta = getSocketedItemStack().getItemMeta();
PersistentDataContainer pdc = meta.getPersistentDataContainer();

pdc.set(new NamespacedKey(FNAmplifications.getInstance(), "return_weapon"), PersistentDataType.STRING, "true");
getSocketedItemStack().setItemMeta(meta);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package ne.fnfal113.fnamplifications.Gems.Implementation;

import lombok.Getter;
import ne.fnfal113.fnamplifications.Utils.Utils;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

public class ReturnWeaponTask extends BukkitRunnable {

@Getter
private final ItemStack itemStack;
@Getter
private final ArmorStand armorStand;
@Getter
private final Player player;

public ReturnWeaponTask(ItemStack itemStack, ArmorStand armorStand, Player player){
this.itemStack = itemStack;
this.armorStand = armorStand;
this.player = player;
}

@Override
public void run() {
Location asLocation = getArmorStand().getLocation();
Vector asVector = asLocation.toVector();
Location pLocation = getPlayer().getLocation();
Vector pVector = pLocation.toVector();

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

if(!getPlayer().isOnline()){
dropItem(asLocation);

stopTask();
}

if(distanceBetween(asLocation, pLocation) > 150){
Location dropLoc = dropItem(asLocation);
getPlayer().sendMessage(Utils.colorTranslator("&cWeapon has not been returned because you're too far!"));
getPlayer().sendMessage(Utils.colorTranslator("&cit was dropped at: &e" +
"x: " + (int) dropLoc.getX() + ", " +
"y: " + (int) dropLoc.getY() + ", " +
"z: " + (int) dropLoc.getZ()));

stopTask();
}

if(distanceBetween(asLocation, pLocation) < 0.5){
if(getPlayer().getInventory().firstEmpty() == -1){
getPlayer().sendMessage(Utils.colorTranslator("&eInventory full! dropped the item instead"));
dropItem(pLocation);
} else {
getPlayer().getInventory().addItem(getItemStack().clone());
}

stopTask();
}
}

public Location dropItem(Location location){
Item droppedItem = getPlayer().getWorld().dropItem(location, getItemStack().clone());
droppedItem.setOwner(getPlayer().getUniqueId());
droppedItem.setGlowing(true);

return droppedItem.getLocation();
}

public double distanceBetween(Location asLoc, Location pLoc){
return asLoc.distance(pLoc);
}

public void stopTask(){
getArmorStand().remove();
this.cancel();
}
}
Loading

0 comments on commit 1ef3a44

Please sign in to comment.