mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
221 lines
8.9 KiB
Java
221 lines
8.9 KiB
Java
package me.ShermansWorld.AlathraWar;
|
|
|
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.Damageable;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class Helper {
|
|
public static String color(final String input) {
|
|
return ChatColor.translateAlternateColorCodes('&', input);
|
|
}
|
|
|
|
public static String chatLabel() {
|
|
return color("&6[&4AlathraWar&6]&r ");
|
|
}
|
|
|
|
/**
|
|
* Damages all gear in a players inventory
|
|
*
|
|
* @param p
|
|
* @author ShermansWorld
|
|
*/
|
|
public static void damageAllGear(Player p) {
|
|
final Inventory inv = p.getInventory();
|
|
for (int i = 0; i < inv.getSize(); ++i) {
|
|
final ItemStack is = inv.getItem(i);
|
|
if (is != null && (is.getType() == Material.NETHERITE_AXE || is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.DIAMOND_AXE || is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.IRON_AXE || is.getType() == Material.IRON_SWORD)) {
|
|
final ItemMeta meta = getItemMeta(is);
|
|
is.setItemMeta(meta);
|
|
}
|
|
}
|
|
final ItemStack[] armor = p.getInventory().getArmorContents();
|
|
for (ItemStack itemStack : armor) {
|
|
if (itemStack != null) {
|
|
if (itemStack.getType() == Material.NETHERITE_HELMET || itemStack.getType() == Material.NETHERITE_CHESTPLATE || itemStack.getType() == Material.NETHERITE_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.DIAMOND_HELMET || itemStack.getType() == Material.DIAMOND_CHESTPLATE || itemStack.getType() == Material.DIAMOND_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.IRON_HELMET || itemStack.getType() == Material.IRON_CHESTPLATE || itemStack.getType() == Material.IRON_LEGGINGS || itemStack.getType() == Material.IRON_BOOTS) {
|
|
final ItemMeta meta2 = getItemMeta2(itemStack);
|
|
itemStack.setItemMeta(meta2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
private static ItemMeta getItemMeta2(ItemStack is2) {
|
|
ItemMeta meta2 = is2.getItemMeta();
|
|
final Damageable damageable2 = (Damageable) meta2;
|
|
if (is2.getType() == Material.NETHERITE_HELMET) {
|
|
damageable2.setDamage(damageable2.getDamage() + 101);
|
|
if (damageable2.getDamage() > 400) {
|
|
damageable2.setDamage(406);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.NETHERITE_CHESTPLATE) {
|
|
damageable2.setDamage(damageable2.getDamage() + 148);
|
|
if (damageable2.getDamage() > 450) {
|
|
damageable2.setDamage(591);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.NETHERITE_LEGGINGS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 138);
|
|
if (damageable2.getDamage() > 420) {
|
|
damageable2.setDamage(554);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.NETHERITE_BOOTS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 120);
|
|
if (damageable2.getDamage() > 370) {
|
|
damageable2.setDamage(480);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.DIAMOND_HELMET) {
|
|
damageable2.setDamage(damageable2.getDamage() + 90);
|
|
if (damageable2.getDamage() > 280) {
|
|
damageable2.setDamage(362);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.DIAMOND_CHESTPLATE) {
|
|
damageable2.setDamage(damageable2.getDamage() + 132);
|
|
if (damageable2.getDamage() > 410) {
|
|
damageable2.setDamage(527);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.DIAMOND_LEGGINGS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 123);
|
|
if (damageable2.getDamage() > 380) {
|
|
damageable2.setDamage(494);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.DIAMOND_BOOTS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 107);
|
|
if (damageable2.getDamage() > 330) {
|
|
damageable2.setDamage(428);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.IRON_HELMET) {
|
|
damageable2.setDamage(damageable2.getDamage() + 41);
|
|
if (damageable2.getDamage() > 125) {
|
|
damageable2.setDamage(164);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.IRON_CHESTPLATE) {
|
|
damageable2.setDamage(damageable2.getDamage() + 60);
|
|
if (damageable2.getDamage() > 190) {
|
|
damageable2.setDamage(239);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.IRON_LEGGINGS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 56);
|
|
if (damageable2.getDamage() > 180) {
|
|
damageable2.setDamage(224);
|
|
}
|
|
}
|
|
if (is2.getType() == Material.IRON_BOOTS) {
|
|
damageable2.setDamage(damageable2.getDamage() + 48);
|
|
if (damageable2.getDamage() > 150) {
|
|
damageable2.setDamage(194);
|
|
}
|
|
}
|
|
meta2 = damageable2;
|
|
return meta2;
|
|
}
|
|
|
|
@Nullable
|
|
private static ItemMeta getItemMeta(ItemStack is) {
|
|
ItemMeta meta = is.getItemMeta();
|
|
final Damageable damageable = (Damageable) meta;
|
|
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
|
|
damageable.setDamage(damageable.getDamage() + 507);
|
|
if (damageable.getDamage() > 2000) {
|
|
damageable.setDamage(2030);
|
|
}
|
|
} else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
|
|
damageable.setDamage(damageable.getDamage() + 390);
|
|
if (damageable.getDamage() > 1500) {
|
|
damageable.setDamage(1560);
|
|
}
|
|
} else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
|
|
damageable.setDamage(damageable.getDamage() + 62);
|
|
if (damageable.getDamage() > 200) {
|
|
damageable.setDamage(249);
|
|
}
|
|
} else if (is.getType() == Material.TRIDENT) {
|
|
damageable.setDamage(damageable.getDamage() + 62);
|
|
if (damageable.getDamage() > 200) {
|
|
damageable.setDamage(249);
|
|
}
|
|
}
|
|
meta = damageable;
|
|
return meta;
|
|
}
|
|
|
|
/**
|
|
* @param worldCoord worldCoord
|
|
* @return List of connected chunks
|
|
* @author NinjaMandalorian
|
|
*/
|
|
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
|
|
ArrayList<WorldCoord> ReturnList = new ArrayList<>();
|
|
|
|
int[][] XZarray = new int[][]{
|
|
{-1, 0},
|
|
{1, 0},
|
|
{0, -1},
|
|
{0, 1}
|
|
}; // Array that contains relative orthogonal shifts from origin
|
|
for (int[] pair : XZarray) {
|
|
// Constructs new WorldCoord for comparison
|
|
WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
|
if (tCoord.getTownOrNull() != null && tCoord.getTownOrNull() == worldCoord.getTownOrNull()) {
|
|
// If in town, and in same town, adds to return list
|
|
ReturnList.add(tCoord);
|
|
}
|
|
}
|
|
return ReturnList;
|
|
}
|
|
|
|
/**
|
|
* Gets all adjacently connected townblocks
|
|
*
|
|
* @param chunkCoord - WorldCoord to check at
|
|
* @return List of WorldCoords
|
|
* @author NinjaMandalorian
|
|
*/
|
|
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord) {
|
|
// WCoordList is the returning array, SearchList is the to-search list.
|
|
ArrayList<WorldCoord> WCoordList = new ArrayList<>();
|
|
ArrayList<WorldCoord> SearchList = new ArrayList<>();
|
|
SearchList.add(chunkCoord); // Adds 1st chunk to list
|
|
|
|
// Iterates through SearchList, to create a full list of every adjacent cell.
|
|
while (!SearchList.isEmpty()) {
|
|
// Gets WorldCoord
|
|
WorldCoord toSearch = SearchList.get(0);
|
|
// Gets adjacent cells
|
|
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch);
|
|
for (WorldCoord cell : adjCells) {
|
|
// If in final list, ignore.
|
|
if (WCoordList.contains(cell)) {
|
|
// If in to-search list, ignore
|
|
} else if (SearchList.contains(cell)) {
|
|
// Otherwise, add to search-list.
|
|
} else {
|
|
SearchList.add(cell);
|
|
}
|
|
}
|
|
// Removes from search list and adds to finished list. After checking all adjacent chunks.
|
|
SearchList.remove(toSearch);
|
|
WCoordList.add(toSearch);
|
|
}
|
|
|
|
return WCoordList; // Returns list
|
|
}
|
|
}
|