Merge pull request #23 from Mineplex-LLC/clans/beta

Clans/beta
This commit is contained in:
Conrad 2016-04-08 11:07:00 -04:00
commit 67adf94341
10 changed files with 85 additions and 126 deletions

View File

@ -27,7 +27,7 @@ public class DonationRepository extends MinecraftRepository
private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);";
private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;";
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;";
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ? && gold >= ?;";
private static String SET_ACCOUNT_GOLD = "UPDATE accounts SET gold = ? WHERE id = ?;";
private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;";
@ -191,7 +191,8 @@ public class DonationRepository extends MinecraftRepository
{
public void run()
{
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0;
ColumnInt min = new ColumnInt("gold", gold < 0 ? -gold : 0);
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId), min) > 0;
callback.run(success);
}
}), "Error updating player gold amount in DonationRepository : ");
@ -199,6 +200,10 @@ public class DonationRepository extends MinecraftRepository
public void setGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold)
{
if (gold < 0)
{
throw new IllegalArgumentException("gold cannot be negative");
}
handleDatabaseCall(new DatabaseRunnable(new Runnable()
{
public void run()

View File

@ -276,7 +276,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_clanDisplay = new ClansDisplay(plugin, this);
_clanGame = new ClansGame(plugin, this);
_clanUtility = new ClansUtility(this);
_tutorial = new TutorialManager(plugin, clientManager, donationManager, chat, hologramManager, _npcManager, _taskManager);
_tutorial = new TutorialManager(plugin, clientManager, donationManager, chat, hologramManager, this, _npcManager, _taskManager);
_itemMapManager = new ItemMapManager(this, _tutorial, _worldEvent);
new TntGeneratorManager(plugin, this);
new SupplyDropManager(plugin, this);

View File

@ -1,7 +1,5 @@
package mineplex.game.clans.clans.siege;
import java.util.Stack;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
@ -23,7 +21,6 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
@ -36,11 +33,8 @@ import net.minecraft.server.v1_8_R3.Material;
public class SiegeManager extends MiniPlugin
{
private ClansManager _clansManager;
private OutpostManager _outpostManager;
public static SiegeManager Instance;
public NautHashMap<Integer, SiegeWeapon> LiveSiegeWeapons = new NautHashMap<>();
public NautHashMap<Integer, SiegeWeapon> UnsyncedSiegeWeapons = new NautHashMap<>();
@ -58,11 +52,7 @@ public class SiegeManager extends MiniPlugin
_outpostManager = new OutpostManager(clans, this);
addCommand(new CommandSiegeSupplies(_outpostManager));
Instance = this;
_repository = new SiegeWeaponRepository(clans.getPlugin());
_repository = new SiegeWeaponRepository(clans.getPlugin(), this);
_outpostManager.loadOutposts();
@ -188,8 +178,6 @@ public class SiegeManager extends MiniPlugin
private void saveSiegeWeapons()
{
final Stack<Runnable> queue = new Stack<>();
for (final SiegeWeapon weapon : LiveSiegeWeapons.values())
{
final SiegeWeaponToken token = weapon.toToken();
@ -197,28 +185,10 @@ public class SiegeManager extends MiniPlugin
if (UnsyncedSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId)))
continue;
queue.push(() -> {
runAsync(() -> {
_repository.updateWeapon(token);
});
}
runAsync(() -> {
while (!queue.isEmpty())
{
queue.pop().run();
}
_repository.getWeaponsByServer(_clansManager.getServerId(), tokens -> {
tokens.forEach(token -> {
if (!LiveSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId)) && !UnsyncedSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId)))
{
System.out.println("LiveSiegeWeapons no longer contains old weapon " + token.UniqueId + ", deleting.");
_repository.deleteWeapon(token.UniqueId);
}
});
});
});
}
@EventHandler

View File

@ -1,35 +0,0 @@
package mineplex.game.clans.clans.siege.commands;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.weapon.Cannon;
public class CommandSiegeSupplies extends CommandBase<OutpostManager>
{
public CommandSiegeSupplies(OutpostManager plugin)
{
super(plugin, Rank.MODERATOR, "siege");
}
@Override
public void Execute(Player caller, String[] args)
{
ItemStack outpost = new ItemStack(Outpost.OUTPOST_ITEM);
ItemStack cannons = new ItemStack(Cannon.CANNON_ITEM);
outpost.setAmount(64);
cannons.setAmount(64);
caller.getInventory().addItem(outpost);
caller.getInventory().addItem(cannons);
UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege."));
}
}

View File

@ -44,23 +44,27 @@ public class SiegeWeaponRepository extends MinecraftRepository
private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;";
public SiegeWeaponRepository(JavaPlugin plugin)
private SiegeManager _siegeManager;
public SiegeWeaponRepository(JavaPlugin plugin, SiegeManager siegeManager)
{
super(plugin, DBPool.getAccount());
_siegeManager = siegeManager;
}
public void deleteWeapon(final int uniqueId)
{
System.out.println("Siege Repo> Deleting weapon " + uniqueId);
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeUpdate(DELETE_WEAPON, new ColumnInt("uniqueId", uniqueId))
);
}
public void getWeaponById(final int uniqueId, final Callback<SiegeWeaponToken> callback)
{
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeQuery(GET_WEAPON_BY_ID, resultSet -> {
SiegeWeaponToken token = new SiegeWeaponToken();
@ -75,7 +79,7 @@ public class SiegeWeaponRepository extends MinecraftRepository
public void getWeaponsByServer(final int serverId, final Callback<List<SiegeWeaponToken>> callback)
{
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeQuery(GET_WEAPONS_BY_SERVER, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
@ -95,7 +99,7 @@ public class SiegeWeaponRepository extends MinecraftRepository
public void getWeaponsByClan(final ClanInfo clan, final Callback<List<SiegeWeaponToken>> callback)
{
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeQuery(GET_WEAPONS_BY_CLAN, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
@ -117,7 +121,7 @@ public class SiegeWeaponRepository extends MinecraftRepository
{
token.UniqueId = columns.getInt("uniqueId");
token.Location = UtilWorld.strToLoc(columns.getString("location"));
token.OwnerClan = SiegeManager.Instance.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.OwnerClan = _siegeManager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.WeaponType = columns.getByte("weaponType");
token.Health = columns.getShort("health");
token.Yaw = columns.getShort("yaw");
@ -131,7 +135,7 @@ public class SiegeWeaponRepository extends MinecraftRepository
{
System.out.println("Siege Repo> Updating weapon " + token.UniqueId);
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeUpdate(UPDATE_WEAPON,
new ColumnInt("health", token.Health),
new ColumnInt("yaw", token.Yaw),
@ -144,10 +148,10 @@ public class SiegeWeaponRepository extends MinecraftRepository
{
System.out.println("Siege Repo> Inserting new weapon " + token.UniqueId);
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeUpdate(INSERT_WEAPON,
new ColumnInt("uniqueId", token.UniqueId),
new ColumnInt("serverId", SiegeManager.Instance.getClansManager().getServerId()),
new ColumnInt("serverId", _siegeManager.getClansManager().getServerId()),
new ColumnVarChar("location", 30, UtilWorld.locToStr(token.Location)),
new ColumnInt("ownerClan", token.OwnerClan.getId()),
new ColumnInt("weaponType", token.WeaponType),
@ -192,7 +196,7 @@ public class SiegeWeaponRepository extends MinecraftRepository
@Override
protected void initialize()
{
SiegeManager.Instance.runAsync(() ->
_siegeManager.runAsync(() ->
executeUpdate(CREATE)
);
}

View File

@ -110,7 +110,7 @@ public class WeaponProjectile implements Listener
if (!newEvent.isCancelled())
{
new Crater(_weapon, this, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire);
new Crater(_weapon, this, _projectileEntity.getLocation(), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire);
}
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f));

View File

@ -23,6 +23,8 @@ import mineplex.core.npc.NpcManager;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.core.task.TaskManager;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.message.ClansMessageManager;
import mineplex.game.clans.tutorial.command.TutorialCommand;
import mineplex.game.clans.tutorial.gui.TutorialShop;
@ -37,7 +39,7 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement
private EnumMap<TutorialType, Tutorial> _tutorialMap;
private EnumMap<TutorialType, TutorialShop> _shopMap; // Don't need to do anything with shops currently
public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Chat chat, HologramManager hologram, NpcManager npcManager, TaskManager taskManager)
public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Chat chat, HologramManager hologram, ClansManager clansManager, NpcManager npcManager, TaskManager taskManager)
{
super("Clans Tutorial", plugin);
@ -48,7 +50,7 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement
_tutorialMap = new EnumMap<TutorialType, Tutorial>(TutorialType.class);
_shopMap = new EnumMap<TutorialType, TutorialShop>(TutorialType.class);
addTutorial(TutorialType.MAIN, new ClansMainTutorial(plugin, _clansMessageManager, hologram, npcManager, taskManager));
addTutorial(TutorialType.MAIN, new ClansMainTutorial(plugin, clansManager, _clansMessageManager, hologram, npcManager, taskManager));
chat.AddFilter(event -> {
if (inTutorial(event.getPlayer()))

View File

@ -3,19 +3,14 @@ package mineplex.game.clans.tutorial.tutorials.clans;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import com.google.common.collect.Lists;
import mineplex.core.hologram.Hologram;
import mineplex.core.common.util.*;
import mineplex.core.task.TaskManager;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent;
import mineplex.game.clans.clans.event.ClansPlayerSellItemEvent;
import mineplex.game.clans.clans.event.PreEnergyShopBuyEvent;
import mineplex.game.clans.clans.gui.events.ClansButtonClickEvent;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@ -30,17 +25,30 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.HologramManager;
import mineplex.core.npc.NpcManager;
import mineplex.core.task.TaskManager;
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.ClansCommandPreExecutedEvent;
import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent;
import mineplex.game.clans.clans.event.ClansPlayerSellItemEvent;
import mineplex.game.clans.clans.event.PreEnergyShopBuyEvent;
import mineplex.game.clans.clans.gui.events.ClansButtonClickEvent;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.message.ClansMessageManager;
import mineplex.game.clans.spawn.Spawn;
@ -57,8 +65,6 @@ import mineplex.game.clans.tutorial.tutorials.clans.objective.FieldsObjective;
import mineplex.game.clans.tutorial.tutorials.clans.objective.FinalObjective;
import mineplex.game.clans.tutorial.tutorials.clans.objective.PurchaseItemsObjective;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ShopsObjective;
import mineplex.game.clans.tutorial.tutorials.clans.repository.TutorialRepository;
//import mineplex.game.clans.tutorial.tutorials.clans.repository.TutorialRepository;
public class ClansMainTutorial extends Tutorial
{
@ -79,7 +85,7 @@ public class ClansMainTutorial extends Tutorial
);
public ClansMainTutorial(JavaPlugin plugin, ClansMessageManager message, HologramManager hologram, NpcManager npcManager, TaskManager taskManager)
public ClansMainTutorial(JavaPlugin plugin, ClansManager clansManager, ClansMessageManager message, HologramManager hologram, NpcManager npcManager, TaskManager taskManager)
{
super(plugin, message, hologram, "Clans Tutorial", "main", Material.DIAMOND_SWORD, (byte) 0);
@ -100,7 +106,7 @@ public class ClansMainTutorial extends Tutorial
// _repository = new TutorialRepository(ClansManager.getInstance().getClientManager());
addObjective(new ClanObjective(this, plugin));
addObjective(new AttackEnemyObjective(this, plugin));
addObjective(new AttackEnemyObjective(this, clansManager, plugin));
addObjective(new ShopsObjective(this, npcManager, plugin));
addObjective(new PurchaseItemsObjective(this, plugin));
addObjective(new ClassesObjective(this, plugin));

View File

@ -30,6 +30,8 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.TutorialSession;
@ -49,7 +51,7 @@ public class AttackEnemyObjective extends OrderedObjective<ClansMainTutorial>
private DefaultHashMap<String, List<Zombie>> _shooters;
public AttackEnemyObjective(ClansMainTutorial clansMainTutorial, JavaPlugin javaPlugin)
public AttackEnemyObjective(ClansMainTutorial clansMainTutorial, ClansManager clansManager, JavaPlugin javaPlugin)
{
super(clansMainTutorial, javaPlugin, "Enemy Clans Tutorial", "Attack and raid this enemy!");
@ -66,7 +68,7 @@ public class AttackEnemyObjective extends OrderedObjective<ClansMainTutorial>
40
));
addGoal(new ClanInfoGoal(this));
addGoal(new MountCannonGoal(this));
addGoal(new MountCannonGoal(this, clansManager));
addGoal(new LoadCannonGoal(this));
addGoal(new BlowUpWallGoal(this));
addGoal(new StealEnemyPotatoesGoal(this));

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.UtilInv;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.events.MountSiegeWeaponEvent;
import mineplex.game.clans.clans.siege.weapon.Cannon;
@ -21,7 +22,9 @@ import mineplex.game.clans.tutorial.tutorials.clans.objective.AttackEnemyObjecti
public class MountCannonGoal extends ObjectiveGoal<AttackEnemyObjective>
{
public MountCannonGoal(AttackEnemyObjective objective)
private ClansManager _clansManager;
public MountCannonGoal(AttackEnemyObjective objective, ClansManager clansManager)
{
super(
objective,
@ -31,12 +34,14 @@ public class MountCannonGoal extends ObjectiveGoal<AttackEnemyObjective>
+ "TNT Cannons are the best way to do destroy enemy bases!",
DyeColor.BLACK
);
_clansManager = clansManager;
}
@Override
protected void customStart(Player player)
{
getObjective().getCannons().put(player.getName(), SiegeManager.Instance.spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON), false));
getObjective().getCannons().put(player.getName(), _clansManager.getSiegeManager().spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON), false));
getObjective().getCannons().get(player.getName()).SetForcedVelocity(0.4, 2.45);
getObjective().getCannons().get(player.getName()).setInvincible(true);