Fix all the issues with chests

This commit is contained in:
Sam 2018-01-08 01:06:15 +00:00 committed by Alexander Meech
parent 54a605de5b
commit e5a5b87abc
11 changed files with 386 additions and 1125 deletions

View File

@ -185,17 +185,17 @@ public abstract class BattleRoyale extends Game
.addItem(buildFromGun(GunStats.DEAGLE))
.addItem(buildFromGun(GunStats.P250))
.addItem(buildFromGun(GunStats.P2000))
.addItem(buildFromGun(GunStats.P90), 0.5)
.addItem(buildFromGun(GunStats.PPBIZON), 0.5)
.addItem(buildFromGun(GunStats.GALIL), 0.2)
.addItem(buildFromGun(GunStats.FAMAS), 0.2)
.addItem(buildFromGun(GunStats.AK47), 0.2)
.addItem(buildFromGun(GunStats.M4A4), 0.2)
.addItem(buildFromGun(GunStats.SG553), 0.2)
.addItem(buildFromGun(GunStats.AUG), 0.2)
.addItem(buildFromGun(GunStats.SSG08), 0.2)
.addItem(buildFromGun(GunStats.NOVA), 0.2)
.addItem(buildFromGun(GunStats.XM1014), 0.2)
.addItem(buildFromGun(GunStats.P90), 50)
.addItem(buildFromGun(GunStats.PPBIZON), 50)
.addItem(buildFromGun(GunStats.GALIL), 20)
.addItem(buildFromGun(GunStats.FAMAS), 20)
.addItem(buildFromGun(GunStats.AK47), 20)
.addItem(buildFromGun(GunStats.M4A4), 20)
.addItem(buildFromGun(GunStats.SG553), 20)
.addItem(buildFromGun(GunStats.AUG), 20)
.addItem(buildFromGun(GunStats.SSG08), 20)
.addItem(buildFromGun(GunStats.NOVA), 20)
.addItem(buildFromGun(GunStats.XM1014), 20)
.setProbability(0.5)
,
@ -204,8 +204,8 @@ public abstract class BattleRoyale extends Game
.addItem(buildGrenade(Material.CARROT_ITEM, "Flash Bang"))
.addItem(buildGrenade(Material.APPLE, "High Explosive"))
.addItem(buildGrenade(Material.POTATO_ITEM, "Smoke"))
.addItem(buildGrenade(Material.PORK, "Incendiary"), 0.5)
.addItem(buildGrenade(Material.GRILLED_PORK, "Molotov"), 0.5)
.addItem(buildGrenade(Material.PORK, "Incendiary"), 50)
.addItem(buildGrenade(Material.GRILLED_PORK, "Molotov"), 50)
.setProbability(0.2)
,
@ -264,18 +264,18 @@ public abstract class BattleRoyale extends Game
// Food
new ChestLootPool()
.addItem(new ItemStack(Material.MELON), 1, 3)
.addItem(new ItemStack(Material.BREAD), 1, 2, 0.6)
.addItem(new ItemStack(Material.COOKED_FISH), 0.5)
.addItem(new ItemStack(Material.COOKED_BEEF), 0.5)
.addItem(new ItemStack(Material.COOKED_CHICKEN), 0.5)
.addItem(new ItemStack(Material.COOKED_MUTTON), 0.5)
.addItem(new ItemStack(Material.COOKIE), 0.5)
.addItem(new ItemStack(Material.BREAD), 1, 2, 50)
.addItem(new ItemStack(Material.COOKED_FISH), 50)
.addItem(new ItemStack(Material.COOKED_BEEF), 50)
.addItem(new ItemStack(Material.COOKED_CHICKEN), 50)
.addItem(new ItemStack(Material.COOKED_MUTTON), 50)
.addItem(new ItemStack(Material.COOKIE), 50)
,
// Misc
new ChestLootPool()
.addItem(SMALL_BACKPACK, 0.5)
.addItem(LARGE_BACKPACK, 0.2)
.addItem(SMALL_BACKPACK, 50)
.addItem(LARGE_BACKPACK, 20)
.setProbability(0.2)
)
.registerChestType("Supply Drop", new ArrayList<>(0),
@ -310,8 +310,8 @@ public abstract class BattleRoyale extends Game
.addItem(buildGrenade(Material.CARROT_ITEM, "Flash Bang"))
.addItem(buildGrenade(Material.APPLE, "High Explosive"))
.addItem(buildGrenade(Material.POTATO_ITEM, "Smoke"))
.addItem(buildGrenade(Material.PORK, "Incendiary"), 0.5)
.addItem(buildGrenade(Material.GRILLED_PORK, "Molotov"), 0.5)
.addItem(buildGrenade(Material.PORK, "Incendiary"), 50)
.addItem(buildGrenade(Material.GRILLED_PORK, "Molotov"), 50)
.setAmountsPerChest(1, 2)
,

View File

@ -7,10 +7,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam;
@ -115,30 +114,30 @@ public class TeamSkywars extends Skywars
{
Scoreboard.write(C.cWhite + alive.size() + " Alive");
}
if (IsLive())
{
Scoreboard.writeNewLine();
Scoreboard.write(C.cYellow + C.Bold + "Time");
Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT));
Scoreboard.writeNewLine();
Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn");
Scoreboard.write(this.getTnTGen().getScoreboardInfo());
Scoreboard.writeNewLine();
if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime()))
{
Scoreboard.write(C.cRed + C.Bold + "Map Crumble");
Scoreboard.write("Active");
}
else
{
Scoreboard.write(C.cGreen + C.Bold + "Map Crumble");
Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT));
}
}
// if (IsLive())
// {
// Scoreboard.writeNewLine();
// Scoreboard.write(C.cYellow + C.Bold + "Time");
// Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT));
//
// Scoreboard.writeNewLine();
// Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn");
// Scoreboard.write(this.getTnTGen().getScoreboardInfo());
//
// Scoreboard.writeNewLine();
//
// if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime()))
// {
// Scoreboard.write(C.cRed + C.Bold + "Map Crumble");
// Scoreboard.write("Active");
// }
// else
// {
// Scoreboard.write(C.cGreen + C.Bold + "Map Crumble");
// Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT));
// }
// }
Scoreboard.draw();
}

View File

@ -1,142 +0,0 @@
package nautilus.game.arcade.game.games.skywars.data;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.skywars.Skywars;
import nautilus.game.arcade.game.games.skywars.events.TNTPickupEvent;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class TNTGenerator
{
private Skywars Host;
private Location _loc;
private long _time;
private long _timeDelay = 25000;
private Item _ent;
public TNTGenerator(Skywars host, Location loc)
{
Host = host;
_time = System.currentTimeMillis();
_loc = loc;
_loc.getBlock().getRelative(BlockFace.DOWN)
.setType(Material.IRON_BLOCK);
}
public void update()
{
if (_ent != null)
{
if (!_ent.isValid())
{
_ent.remove();
_ent = null;
}
return;
}
if (!UtilTime.elapsed(_time, _timeDelay))
return;
// Spawn
_ent = _loc.getWorld().dropItem(_loc.clone().add(0, 1, 0),
new ItemStack(Material.TNT));
_ent.setVelocity(new Vector(0, 1, 0));
// Block
_loc.getBlock().getRelative(BlockFace.DOWN)
.setType(Material.REDSTONE_BLOCK);
// Firework
UtilFirework.playFirework(_loc.clone().add(0, 1, 0), FireworkEffect
.builder().flicker(false).withColor(Color.RED).with(Type.BURST)
.trail(true).build());
}
public boolean pickup(Player player, Item item)
{
if (_ent == null)
return false;
if (!_ent.equals(item))
return false;
if (!Host.IsAlive(player))
return true;
if (Host.Manager.isSpectator(player))
return true;
GameTeam team = Host.GetTeam(player);
if (team == null)
return true;
// Remove
_ent.remove();
_ent = null;
_time = System.currentTimeMillis();
_loc.getBlock().getRelative(BlockFace.DOWN)
.setType(Material.IRON_BLOCK);
// Inform
UtilPlayer.message(
player,
F.main("Game", "You collected " + C.cYellow
+ "Super Throwing TNT"));
// Firework
UtilFirework.playFirework(_loc.clone().add(0, 1, 0),
FireworkEffect.builder().flicker(false).withColor(Color.YELLOW)
.with(Type.BALL_LARGE).trail(true).build());
player.getInventory().addItem(
ItemStackFactory.Instance.CreateStack(
Material.TNT,
(byte) 0,
2,
F.item(C.cYellow + C.Bold + "Left Click - Far "
+ C.cWhite + " / " + C.cYellow + C.Bold
+ " Right Click - Drop")));
player.playSound(player.getLocation(), Sound.ENDERDRAGON_HIT, 3F, 1F);
Bukkit.getPluginManager().callEvent(new TNTPickupEvent(player));
return true;
}
public String getScoreboardInfo()
{
if (_ent != null)
return "Lootable";
else
return UtilTime.MakeStr(_timeDelay - (System.currentTimeMillis() - _time), 0);
}
public boolean active()
{
return _ent != null;
}
}

View File

@ -1,36 +0,0 @@
package nautilus.game.arcade.game.games.skywars.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class PlayerOpenChestEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _who;
public PlayerOpenChestEvent(Player who)
{
this._who = who;
}
public static HandlerList getHandlerList()
{
return handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
public Player getPlayer() {
return _who;
}
}

View File

@ -1,23 +1,5 @@
package nautilus.game.arcade.game.games.skywars.modes;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilMath;
import mineplex.core.loot.ChestLoot;
import mineplex.core.loot.RandomItem;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.games.AbsorptionFix;
@ -30,191 +12,12 @@ import nautilus.game.arcade.game.games.skywars.TeamSkywars;
*/
public class OverpoweredSkywars extends TeamSkywars
{
private ChestLoot _playerArmor = new ChestLoot();
private ChestLoot _playerFood = new ChestLoot();
private ChestLoot _playerTool = new ChestLoot();
private ChestLoot _playerProjectile = new ChestLoot();
private ChestLoot _playerBlock = new ChestLoot();
private ChestLoot _middleArmor = new ChestLoot();
private ChestLoot _middleFood = new ChestLoot();
private ChestLoot _middleTool = new ChestLoot();
private ChestLoot _middleProjectile = new ChestLoot();
private ChestLoot _middleBlock = new ChestLoot();
public OverpoweredSkywars(ArcadeManager manager)
{
super(manager, GameType.Brawl);
new AbsorptionFix(this);
setupOPPlayerLoot();
}
@Override
public void fillChest(Player looter, Block block)
{
getLooted().add(block.getLocation());
Chest chest = (Chest) block.getState();
chest.getBlockInventory().clear();
//Prevents same inventory spot being used twice
HashSet<Integer> used = new HashSet<Integer>();
//Player Island
if (getSpawnChests().contains(block))
{
//Armor
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
{
ItemStack item = _playerArmor.getLoot();
chest.getBlockInventory().setItem(getIndex(used), item);
}
//Food
for (int i=0 ; i<1 + UtilMath.r(3) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _playerFood.getLoot());
//Tool
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _playerTool.getLoot());
//Projectile
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _playerProjectile.getLoot());
//Block
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _playerBlock.getLoot());
}
//Other
else if (getMiddleChests().contains(block))
{
//Armor
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
{
ItemStack item = _middleArmor.getLoot();
item.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1 + UtilMath.r(3));
chest.getBlockInventory().setItem(getIndex(used), item);
}
//Food
for (int i=0 ; i<1 + UtilMath.r(3) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleFood.getLoot());
//Tool
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleTool.getLoot());
//Projectile
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleProjectile.getLoot());
//Block
for (int i=0 ; i<1 + UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleBlock.getLoot());
}
else
{
//Armor
for (int i=0 ; i<UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleArmor.getLoot());
//Food
for (int i=0 ; i<UtilMath.r(3) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleFood.getLoot());
//Tool
for (int i=0 ; i<UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleTool.getLoot());
//Projectile
for (int i=0 ; i<UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleProjectile.getLoot());
//Block
for (int i=0 ; i<UtilMath.r(2) ; i++)
chest.getBlockInventory().setItem(getIndex(used), _middleBlock.getLoot());
}
}
public void setupOPPlayerLoot()
{
//Armor
_playerArmor.addLoot(new RandomItem(Material.DIAMOND_HELMET, 20));
_playerArmor.addLoot(new RandomItem(Material.DIAMOND_CHESTPLATE, 32));
_playerArmor.addLoot(new RandomItem(Material.DIAMOND_LEGGINGS, 28));
_playerArmor.addLoot(new RandomItem(Material.DIAMOND_BOOTS, 16));
//Food
_playerFood.addLoot(new RandomItem(Material.BAKED_POTATO, 1, 1, 4));
_playerFood.addLoot(new RandomItem(Material.COOKED_BEEF, 1, 1, 2));
_playerFood.addLoot(new RandomItem(Material.COOKED_CHICKEN, 1, 1, 2));
//Tools
_playerTool.addLoot(new RandomItem(Material.DIAMOND_SWORD, 2));
_playerTool.addLoot(new RandomItem(Material.FISHING_ROD, 2));
_playerTool.addLoot(new RandomItem(Material.DIAMOND_PICKAXE, 3));
_playerTool.addLoot(new RandomItem(Material.IRON_AXE, 1));
//Projectile
_playerProjectile.addLoot(new RandomItem(Material.ARROW, 18, 2, 8));
_playerProjectile.addLoot(new RandomItem(Material.SNOW_BALL, 60, 2, 5));
_playerProjectile.addLoot(new RandomItem(Material.EGG, 60, 2, 5));
_playerProjectile.addLoot(new RandomItem(Material.ENDER_PEARL, 20, 2, 5));
_playerProjectile.addLoot(new RandomItem(Material.LAVA_BUCKET, 20, 1, 1));
//Block
_playerBlock.addLoot(new RandomItem(Material.COBBLESTONE, 30, 8, 16));
_playerBlock.addLoot(new RandomItem(Material.WOOD, 30, 8, 16));
}
@Override
public void setupMiddleLoot()
{
_middleArmor.addLoot(new RandomItem(Material.DIAMOND_HELMET, 5));
_middleArmor.addLoot(new RandomItem(Material.DIAMOND_CHESTPLATE, 8));
_middleArmor.addLoot(new RandomItem(Material.DIAMOND_LEGGINGS, 7));
_middleArmor.addLoot(new RandomItem(Material.DIAMOND_BOOTS, 4));
//Food
_middleFood.addLoot(new RandomItem(Material.COOKED_BEEF, 1, 1, 3));
_middleFood.addLoot(new RandomItem(Material.COOKED_CHICKEN, 1, 1, 3));
_middleFood.addLoot(new RandomItem(Material.MUSHROOM_SOUP, 1));
_middleFood.addLoot(new RandomItem(Material.GRILLED_PORK, 1, 1, 3));
//Tools
_middleTool.addLoot(new RandomItem(Material.DIAMOND_SWORD, 1));
_middleTool.addLoot(new RandomItem(Material.FISHING_ROD, 1));
//Projectile
_middleTool.addLoot(new RandomItem(Material.BOW, 1));
_middleProjectile.addLoot(new RandomItem(Material.ARROW, 2, 4, 12));
_middleProjectile.addLoot(new RandomItem(Material.ENDER_PEARL, 1, 1, 2));
//Block
_middleBlock.addLoot(new RandomItem(Material.BRICK, 30, 12, 24));
_middleBlock.addLoot(new RandomItem(Material.GLASS, 30, 12, 24));
_middleBlock.addLoot(new RandomItem(Material.SOUL_SAND, 30, 12, 24));
}
private int getIndex(HashSet<Integer> used)
{
int i = UtilMath.r(27);
while (used.contains(i))
{
i = UtilMath.r(27);
}
used.add(i);
return i;
}
@Override

View File

@ -10,15 +10,19 @@ import org.bukkit.Material;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
@ -34,6 +38,7 @@ public class ZombieGuardianModule extends Module
new ItemStack(Material.GOLD_CHESTPLATE),
new ItemStack(Material.GOLD_HELMET)
};
private static final PotionEffect FIRE_RESISTANCE = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false);
private static final int HEALTH = 15;
private static final int MAX_OFFSET_SQUARED = 64;
@ -77,6 +82,7 @@ public class ZombieGuardianModule extends Module
zombie.setCustomNameVisible(true);
zombie.setMaxHealth(HEALTH);
zombie.setHealth(HEALTH);
zombie.addPotionEffect(FIRE_RESISTANCE);
EntityEquipment equipment = zombie.getEquipment();
equipment.setArmorContents(ARMOUR);
@ -137,4 +143,15 @@ public class ZombieGuardianModule extends Module
event.setCancelled(true);
}
}
@EventHandler
public void zombieDamage(CustomDamageEvent event)
{
if (event.GetCause() != DamageCause.ENTITY_EXPLOSION || !_zombies.containsKey(event.GetDamageeEntity()))
{
return;
}
event.SetCancelled("Zombie Blast Protection");
}
}

View File

@ -8,14 +8,12 @@ public class ChestLootItem
private ItemStack _item;
private int _lowestAmount, _highestAmount;
private double _rarity;
public ChestLootItem(ItemStack item, int lowestAmount, int highestAmount, double rarity)
public ChestLootItem(ItemStack item, int lowestAmount, int highestAmount)
{
_item = item;
_lowestAmount = lowestAmount;
_highestAmount = highestAmount;
_rarity = rarity;
}
public ItemStack getItem()
@ -29,9 +27,4 @@ public class ChestLootItem
return itemStack;
}
public double getProbability()
{
return _rarity;
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -163,14 +164,17 @@ public class ChestLootModule extends Module
if (_autoRotateChests)
{
List<BlockFace> faces = new ArrayList<>(FACES.length);
for (BlockFace face : FACES)
{
if (UtilBlock.airFoliage(block.getRelative(face)))
{
block.setData(getData(face));
break;
faces.add(face);
}
}
block.setData(getData(UtilAlg.Random(faces)));
}
ChestMetadata metadata = new ChestMetadata(block, chestType);

View File

@ -1,24 +1,31 @@
package nautilus.game.arcade.game.modules.chest;
import mineplex.core.common.util.UtilMath;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import org.bukkit.block.Chest;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.weight.WeightSet;
public class ChestLootPool
{
private List<ChestLootItem> _items;
private static final int DEFAULT_RARITY = 100;
private final WeightSet<ChestLootItem> _items;
private final WeightSet<Entry<Enchantment, Integer>> _enchantments;
private int _minimumPerChest;
private int _maximumPerChest;
private double _rarity;
private double _rarity, _enchantmentRarity;
public ChestLootPool()
{
_items = new ArrayList<>();
_items = new WeightSet<>();
_enchantments = new WeightSet<>();
_minimumPerChest = 1;
_maximumPerChest = 1;
_rarity = 1;
@ -29,19 +36,36 @@ public class ChestLootPool
return addItem(itemStack, itemStack.getAmount(), itemStack.getAmount(), 1);
}
public ChestLootPool addItem(ItemStack itemStack, double rarity)
public ChestLootPool addItem(ItemStack itemStack, int rarity)
{
return addItem(itemStack, itemStack.getAmount(), itemStack.getAmount(), rarity);
}
public ChestLootPool addItem(ItemStack itemStack, int lowestAmount, int highestAmount)
{
return addItem(itemStack, lowestAmount, highestAmount, 1);
return addItem(itemStack, lowestAmount, highestAmount, DEFAULT_RARITY);
}
public ChestLootPool addItem(ItemStack itemStack, int lowestAmount, int highestAmount, double rarity)
public ChestLootPool addItem(ItemStack itemStack, int lowestAmount, int highestAmount, int rarity)
{
_items.add(new ChestLootItem(itemStack, lowestAmount, highestAmount, rarity));
_items.add(rarity, new ChestLootItem(itemStack, lowestAmount, highestAmount));
return this;
}
public ChestLootPool addEnchantment(Enchantment enchantment, int maxLevel)
{
return addEnchantment(enchantment, maxLevel, DEFAULT_RARITY);
}
public ChestLootPool addEnchantment(Enchantment enchantment, int maxLevel, int rarity)
{
_enchantments.add(rarity, new SimpleEntry<>(enchantment, maxLevel));
return this;
}
public ChestLootPool setEnchantmentRarity(double probability)
{
_enchantmentRarity = probability;
return this;
}
@ -65,41 +89,28 @@ public class ChestLootPool
for (int i = 0; i < UtilMath.rRange(_minimumPerChest, _maximumPerChest); i++)
{
int slot = UtilMath.r(inventory.getSize());
ChestLootItem item = getRandomItem();
ChestLootItem item = _items.generateRandom();
if (item == null)
{
continue;
}
inventory.setItem(slot, item.getItem());
ItemStack itemStack = item.getItem();
if (_enchantments.elements() != null && Math.random() < _enchantmentRarity)
{
Entry<Enchantment, Integer> enchantment = _enchantments.generateRandom();
itemStack.addUnsafeEnchantment(enchantment.getKey(), UtilMath.r(enchantment.getValue()) + 1);
}
inventory.setItem(slot, itemStack);
}
chest.update();
}
private ChestLootItem getRandomItem()
{
double totalWeight = 0;
for (ChestLootItem item : _items)
{
totalWeight += item.getProbability();
}
double select = Math.random() * totalWeight;
for (ChestLootItem item : _items)
{
if ((select -= item.getProbability()) <= 0)
{
return item;
}
}
return null;
}
public double getProbability()
{
return _rarity;

View File

@ -69,7 +69,7 @@ public class GeneratorModule extends Module
{
for (Generator generator: _generators)
{
if (generator.getHolder().equals(event.getRightClicked()))
if (generator.getHolder() != null && generator.getHolder().equals(event.getRightClicked()))
{
event.setCancelled(true);
return;
@ -82,7 +82,7 @@ public class GeneratorModule extends Module
{
for (Generator generator: _generators)
{
if (generator.getHolder().equals(event.GetDamageeEntity()))
if (generator.getHolder() != null && generator.getHolder().equals(event.GetDamageeEntity()))
{
event.SetCancelled("Generator Holder");
return;