tnt generator changes

This commit is contained in:
Ben 2016-03-10 22:09:45 +00:00
parent c2f6217d9f
commit 20ade492a8
15 changed files with 117 additions and 292 deletions

View File

@ -413,4 +413,28 @@ public class UtilInv
return newItem;
}
public static boolean HasSpace(Player player, Material material, int amount)
{
int slotsFree = 0;
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{
if (player.getInventory().getItem(slot) == null)
{
slotsFree++;
if (slotsFree >= amount / 64)
{
return true;
}
}
else if (player.getInventory().getItem(slot).getType().equals(material) && amount <= (64 - player.getInventory().getItem(slot).getAmount()))
{
return true;
}
}
return false;
}
}

View File

@ -23,15 +23,15 @@ import mineplex.core.shop.item.IButton;
public abstract class ShopPageBase<PluginType extends MiniPlugin, ShopType extends ShopBase<PluginType>> extends CraftInventoryCustom implements Listener
{
private PluginType _plugin;
private CoreClientManager _clientManager;
private DonationManager _donationManager;
private ShopType _shop;
private Player _player;
private CoreClient _client;
private CurrencyType _currencyType;
private NautHashMap<Integer, IButton> _buttonMap;
private boolean _showCurrency = false;
protected PluginType _plugin;
protected CoreClientManager _clientManager;
protected DonationManager _donationManager;
protected ShopType _shop;
protected Player _player;
protected CoreClient _client;
protected CurrencyType _currencyType;
protected NautHashMap<Integer, IButton> _buttonMap;
protected boolean _showCurrency = false;
private int _currencySlot = 4;

View File

@ -201,7 +201,7 @@ public class ClanRepository extends MinecraftRepository
clan.Deaths = resultSet.getInt(9);
clan.WarWins = resultSet.getInt(10);
clan.WarLosses = resultSet.getInt(11);
clan.Generator = resultSet.getString(12);
clan.GeneratorBuyer = resultSet.getString(12);
clan.GeneratorStock = resultSet.getInt(13);
clan.DateCreated = resultSet.getTimestamp(14);
clan.LastOnline = resultSet.getTimestamp(15);
@ -294,7 +294,7 @@ public class ClanRepository extends MinecraftRepository
token.WarWins = resultSet.getInt(10);
token.WarLosses = resultSet.getInt(11);
token.Generator = resultSet.getString(12);
token.GeneratorBuyer = resultSet.getString(12);
token.GeneratorStock = resultSet.getInt(13);
token.DateCreated = resultSet.getTimestamp(14);
token.LastOnline = resultSet.getTimestamp(15);

View File

@ -18,7 +18,7 @@ public class ClanToken
public int WarWins;
public int WarLosses;
public int EloRating;
public String Generator;
public String GeneratorBuyer;
public int GeneratorStock;
public Timestamp DateCreated;
public Timestamp LastOnline;

View File

@ -121,23 +121,6 @@ public class ClanInfo
_bedStatus = BedStatus.DOESNT_EXIST;
}
try
{
if (token.Generator != null && token.Generator.length() > 0)
{
Block block = UtilWorld.strToBlock(token.Generator);
if (block != null)
{
_generator = new TntGenerator(block);
_generator.setStock(token.GeneratorStock);
}
}
}
catch (Exception e)
{
}
_energy = token.Energy;
_admin = token.Admin;
@ -171,6 +154,39 @@ public class ClanInfo
ClanWarData warData = warToken.WarData;
_warOut.put(warData.getClanB(), warData);
}
try
{
if (token.GeneratorBuyer != null && token.GeneratorBuyer.length() > 0)
{
if (token.GeneratorBuyer.contains(","))
{
// Convert to new generator format;
for (ClanMemberToken memberToken : token.Members)
{
ClanRole role = ClanRole.valueOf(memberToken.ClanRole);
if (role.equals(ClanRole.LEADER))
{
token.GeneratorBuyer = memberToken.PlayerUUID.toString();
break;
}
}
System.out.println("Clans> Converted " + _name + "'s generator to the new format.");
}
_generator = new TntGenerator(token.GeneratorBuyer);
_generator.setStock(token.GeneratorStock);
Clans.getClanDataAccess().updateGenerator(this, null);
}
}
catch (Exception e)
{
}
}
public int getClaims()

View File

@ -724,17 +724,17 @@ public class ClansDataAccessLayer
public void updateGenerator(final ClanInfo clanInfo, final Callback<Boolean> callback)
{
TntGenerator generator = clanInfo.getGenerator();
final String location;
final String creator;
final int generatorStock;
if (generator != null)
{
location = UtilWorld.blockToStr(generator.getBlock());
creator = generator.getCreator().toString();
generatorStock = generator.getStock();
}
else
{
location = "";
creator = "";
generatorStock = 0;
}
@ -743,7 +743,7 @@ public class ClansDataAccessLayer
@Override
public void run()
{
final boolean ran = _repository.updateClanGenerator(clanInfo.getId(), location, generatorStock);
final boolean ran = _repository.updateClanGenerator(clanInfo.getId(), creator, generatorStock);
runSync(new Runnable()
{
@Override
@ -751,9 +751,14 @@ public class ClansDataAccessLayer
{
if (callback != null)
{
callback.run(ran);
} else {
if(!ran) System.out.println("Tnt Gen didn't save!");
callback.run(Boolean.valueOf(ran));
}
else
{
if (!ran)
{
System.out.println("Tnt Gen didn't save!");
}
}
}
});

View File

@ -1074,7 +1074,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public void onJoin(PlayerLoginEvent event)
{
Rank rank = _clientManager.Get(event.getPlayer()).GetRank();
if (!event.getPlayer().isWhitelisted() && !rank.has(Rank.LEGEND))
if (!event.getPlayer().isOp() && !event.getPlayer().isWhitelisted() && !rank.has(Rank.LEGEND))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Clans is currently in Legend+ only Alpha!");
// event.setKickMessage("This server is whitelisted!");

View File

@ -99,7 +99,7 @@ public class ClanWhoPage extends ClanPageBase
if (_lookupClan.equals(clanInfo))
{
String clanHome = _lookupClan.getHome() == null ? "None" : UtilWorld.locToStrClean(_lookupClan.getHome());
String generator = _lookupClan.getGenerator() == null ? "None" : UtilWorld.blockToStrClean(_lookupClan.getGenerator().getBlock());
String generator = _lookupClan.getGenerator() == null ? "None" : "Yes";
lore.add(C.Reset + C.cYellow + "Clan Home " + C.cWhite + clanHome);
lore.add(C.Reset + C.cYellow + "TNT Generator " + C.cWhite + generator);

View File

@ -29,6 +29,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.ColorFader;
import mineplex.core.common.util.EnclosedObject;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.LoopIterator;
import mineplex.core.common.util.RGBData;
import mineplex.core.common.util.UtilAction;
@ -66,7 +67,7 @@ import net.minecraft.server.v1_8_R3.AxisAlignedBB;
public class Outpost implements Listener
{
protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes
public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build();
public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.BEACON, 1).setRawTitle(C.cBlue + "Outpost").build();
public static final long PREP_TIME = 2 * 60 * 1000;
@ -575,7 +576,7 @@ public class Outpost implements Listener
_blocks.values().stream().forEach(block -> {
Material mat = Material.getMaterial(block.getId());
if (UtilItem.isTranslucent(mat))
if (UtilItem.isTranslucent(mat) || UtilMath.random.nextBoolean())
{
block.restore();
return;

View File

@ -40,7 +40,7 @@ import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
public class Cannon extends SiegeWeapon
{
public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build();
public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.SPONGE, 1).setData((byte) 1).setRawTitle(C.cBlue + "Cannon").build();
private int _firepower = 1;

View File

@ -1,16 +1,18 @@
package mineplex.game.clans.clans.tntGenerator;
import java.util.UUID;
import org.bukkit.block.Block;
public class TntGenerator
{
private Block _block;
private UUID _creator;
private int _ticks;
private int _stock;
public TntGenerator(Block block)
public TntGenerator(String data)
{
_block = block;
_creator = UUID.fromString(data);
}
public int getTicks()
@ -38,8 +40,8 @@ public class TntGenerator
_stock = stock;
}
public Block getBlock()
public UUID getCreator()
{
return _block;
return _creator;
}
}

View File

@ -1,40 +1,18 @@
package mineplex.game.clans.clans.tntGenerator;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_8_R3.TileEntityBrewingStand;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClanDeleteEvent;
public class TntGeneratorManager extends MiniPlugin
{
public static final Material GENERATOR_MATERIAL = Material.BREWING_STAND;
public static final Material GENERATOR_DROP_MATERIAL = Material.BREWING_STAND_ITEM;
public static final int SECONDS_PER_TNT = 60 * 60 * 10; // 10 Hours
public static final int SECONDS_PER_TNT = 1000 * 30;//60 * 60 * 10; // 10 Hours
public static final int MAX_GENERATOR_STOCK = 3;
private ClansManager _clansManager;
@ -57,26 +35,6 @@ public class TntGeneratorManager extends MiniPlugin
TntGenerator generator = clanInfo.getGenerator();
if (generator != null)
{
// Check that generator still exists
if (generator.getBlock().getType() != GENERATOR_MATERIAL)
{
clanInfo.setGenerator(null);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
continue;
}
// Check that generator is still in clan territory
ClanInfo owner = _clansManager.getClanUtility().getOwner(generator.getBlock().getLocation());
if (!clanInfo.equals(owner))
{
_clansManager.messageClan(clanInfo, F.main("Clans", "Your " + F.elem("TNT Generator") + " has been destroyed due to the land no longer being claimed"));
destroyGenerator(generator);
clanInfo.setGenerator(null);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
continue;
}
if (generator.getStock() >= MAX_GENERATOR_STOCK)
{
generator.setTicks(0);
@ -85,10 +43,9 @@ public class TntGeneratorManager extends MiniPlugin
{
if (generator.getTicks() >= SECONDS_PER_TNT)
{
_clansManager.messageClan(clanInfo, F.main("Clans", "Your " + F.elem("TNT Generator") + " has a new TNT available"));
_clansManager.messageClan(clanInfo, F.main("Clans", "Your " + F.elem("TNT Generator") + " in the " + F.elem("PvP Shop") + " has a new TNT available"));
generator.setStock(generator.getStock() + 1);
generator.setTicks(0);
updateBrewingStand(generator);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
}
@ -97,202 +54,4 @@ public class TntGeneratorManager extends MiniPlugin
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlace(BlockPlaceEvent event)
{
if (event.getBlockPlaced().getType() == GENERATOR_MATERIAL)
{
ClanInfo clan = _clansManager.getClan(event.getPlayer());
if (clan == null)
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You must be in a clan to place a " + F.elem("TNT Generator")));
event.setCancelled(true);
return;
}
// Confirm they are placing in their own land
ClanInfo owner = _clansManager.getClanUtility().getOwner(event.getBlock().getLocation());
if (!clan.equals(owner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You must place the " + F.elem("TNT Generator") + " on your own land"));
event.setCancelled(true);
return;
}
TntGenerator oldGenerator = clan.getGenerator();
if (oldGenerator != null)
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Your clan already has a " + F.elem("TNT Generator")));
event.setCancelled(true);
return;
}
// event.getBlockPlaced().setType(GENERATOR_MATERIAL);
TntGenerator generator = new TntGenerator(event.getBlock());
clan.setGenerator(generator);
_clansManager.getClanDataAccess().updateGenerator(clan, null);
_clansManager.messageClan(clan, F.main("Clans", F.name(event.getPlayer().getName()) + " placed a " + F.elem("TNT Generator") + " at " + F.elem(UtilWorld.blockToStrClean(event.getBlock()))));
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBreak(BlockBreakEvent event)
{
if (event.getBlock() != null && event.getBlock().getType() == GENERATOR_MATERIAL)
{
ClanInfo clan = getGenerator(event.getBlock());
if (clan != null)
{
destroyGenerator(clan.getGenerator());
clan.setGenerator(null);
_clansManager.getClanDataAccess().updateGenerator(clan, null);
_clansManager.messageClan(clan, F.main("Clans", "Your " + F.elem("TNT Generator") + " has been destroyed by " + F.elem(event.getPlayer().getName())));
}
clearStand(event.getBlock());
event.getBlock().setTypeId(0);
event.setCancelled(true);
}
}
@EventHandler
public void onInteract(final PlayerInteractEvent event)
{
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && event.getClickedBlock().getType() == GENERATOR_MATERIAL)
{
ClanInfo clan = getGenerator(event.getClickedBlock());
if (clan != null)
{
interact(clan, event.getPlayer());
}else { //fix tnt gen issues
//Can only place one of these in a clan location. so it must be a generator
ClanInfo owner = _clansManager.getClanUtility().getOwner(event.getClickedBlock().getLocation());
if(owner == null) return; //Wilderness
TntGenerator generator = owner.getGenerator();
System.out.println("Unable to find generator");
//Create generator if not exist
if(generator == null || !generator.getBlock().equals(event.getClickedBlock())) {
generator = new TntGenerator(event.getClickedBlock());
generator.setStock(2);
clan.setGenerator(generator);
_clansManager.getClanDataAccess().updateGenerator(clan, null);
}
interact(owner, event.getPlayer());
}
event.setCancelled(true);
}
}
private void interact(ClanInfo clan, Player player) {
final TntGenerator generator = clan.getGenerator();
final int stock = generator.getStock();
if (stock > 0)
{
generator.setStock(stock - 1);
_clansManager.getClanDataAccess().updateGenerator(clan, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
updateBrewingStand(generator);
dropItem(generator.getBlock(), new ItemStack(Material.TNT));
}
else
{
// failed
generator.setStock(stock);
}
}
});
}
else
{
int secondLeft = SECONDS_PER_TNT - generator.getTicks();
int msLeft = secondLeft * 1000;
UtilTextMiddle.display("", C.cRed + "Next TNT in " + C.cGold + UtilTime.convertString(msLeft, 1, UtilTime.TimeUnit.FIT), player);
}
}
@EventHandler
public void onDelete(ClanDeleteEvent event)
{
ClanInfo clan = event.getClanInfo();
if (clan != null && clan.getGenerator() != null)
{
clearStand(clan.getGenerator().getBlock());
clan.getGenerator().getBlock().setTypeId(0);
}
}
private void dropItem(Block dropLocation, ItemStack item)
{
dropLocation.getWorld().dropItemNaturally(dropLocation.getLocation().add(0.5, 0.5, 0.5), item);
}
public ClanInfo getGenerator(Block block)
{
for (ClanInfo clanInfo : _clansManager.getClanMap().values())
{
TntGenerator generator = clanInfo.getGenerator();
if (generator != null && block.equals(generator.getBlock()))
return clanInfo;
}
return null;
}
private void destroyGenerator(TntGenerator generator)
{
for (int i = 0; i < generator.getStock(); i++)
{
dropItem(generator.getBlock(), new ItemStack(Material.TNT));
}
generator.setStock(0);
dropItem(generator.getBlock(), new ItemStack(GENERATOR_DROP_MATERIAL));
clearStand(generator.getBlock());
generator.getBlock().setTypeId(0);
}
private void clearStand(Block block)
{
TileEntityBrewingStand tileEntity = (TileEntityBrewingStand)((CraftWorld)block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity != null)
{
for (int i = 0; i < 4; i++)
{
tileEntity.setItem(i, null);
}
}
}
private void updateBrewingStand(TntGenerator generator)
{
Block block = generator.getBlock();
if (block != null && block.getType() == Material.BREWING_STAND)
{
TileEntityBrewingStand tileEntity = (TileEntityBrewingStand)((CraftWorld)block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ());
for (int i = 0; i < 3; i++)
{
ItemStack item = new ItemStack(Material.TNT);
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
int itemSlot = i;
tileEntity.setItem(i, (generator.getStock() > i) ? nmsItem : null);
}
tileEntity.update();
}
}
}

View File

@ -40,6 +40,12 @@ public class EventTerrainFinder
{
EnclosedObject<Location> loc = new EnclosedObject<>();
if (_clansManager.getClanUtility().getClanByClanName("Borderlands") == null)
{
System.out.println("[WORLD EVENT] FATAL ERROR: CLAN BORDERLANDS NOT FOUND.");
break;
}
_clansManager.getClanUtility().getClanByClanName("Borderlands").getClaimSet().stream().filter(claim -> Math.random() > .5).filter(claim -> Math.random() > .5).filter(claim -> Math.random() > .3).filter(claim -> Math.random() > .7).limit(1).forEach(claim -> {
Chunk chunk = UtilWorld.strToChunk(claim);

View File

@ -3,6 +3,8 @@ package mineplex.game.clans.shop;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
public enum ClansShopItem
{
// PvP Shop
@ -75,7 +77,9 @@ public enum ClansShopItem
NETHER_BRICK(50, 10, Material.NETHER_BRICK, 1),
QUARTZ_BLOCK(75, 15, Material.QUARTZ_BLOCK, 1),
CLAY(30, 6, Material.CLAY, 1),
GOLD_TOKEN(50000, 50000, Material.GOLD_RECORD, 1, (byte) 0, "Gold Token");
GOLD_TOKEN(50000, 50000, Material.GOLD_RECORD, 1, (byte) 0, "Gold Token"),
OUTPOST(100000, 0, Material.BEACON, 1, (byte) 0, C.cBlue + "Outpost"),
CANNON(50000, 0, Material.SPONGE, 1, (byte) 1, C.cBlue + "Cannon");
private int _buyPrice;
private int _sellPrice;

View File

@ -1,10 +1,13 @@
package mineplex.game.clans.shop.pvp;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.shop.ClansShopPage;
import mineplex.game.clans.shop.ClansShopItem;
import mineplex.game.clans.shop.ClansShopPage;
import mineplex.game.clans.shop.pvp.tnt.TNTGenShop;
public class PvpPage extends ClansShopPage<PvpShop>
{
@ -54,9 +57,14 @@ public class PvpPage extends ClansShopPage<PvpShop>
addShopItem(33, ClansShopItem.BOW, "Standard Bow");
addShopItem(34, ClansShopItem.ARROW, (byte) 0, "Arrows", 16);
addShopItem(52 - 9, ClansShopItem.CANNON, "Cannon");
addShopItem(53 - 9, ClansShopItem.OUTPOST, "Outpost");
addShopItem(51, ClansShopItem.ENCHANTMENT_TABLE, "Class Shop");
addShopItem(52, ClansShopItem.TNT, "TNT");
addShopItem(53, ClansShopItem.TNT_GENERATOR, "TNT Generator");
addButton(53, new ItemBuilder(ClansShopItem.TNT_GENERATOR.getMaterial()).setTitle(C.cAqua + "Manage TNT Generator").build(), (player, click) ->
new TNTGenShop(_plugin, _clientManager, _donationManager).attemptShopOpen(player)
);
}
}