Merge pull request #42 in MIN/mineplex from clans_custom_gear to clans-beta

* commit 'c20d2c9516a04927b45686f301e0ea75050549e6':
  Fix bug with economy gold additions/reductions not properly working and causing shops to fail. Fix bug with region resetting command and streamline the claiming of server-based faction chunks for Spawn, Shops, Fields and Borderlands.
  Left-over commit from last update to add new /region-reset command.
  Add new /region-reset command to reset and re-claim all admin-based regions such as Spawn, Shops, Borderlands, and Fields.
  Increase spawn safe-zone radius by one chunk and shift east shop location one chunk over to fit with the map.
  Fix bug where NPCs were unable to spawn into safe zones. Remove Shield Smash skill from Clans.
This commit is contained in:
Ty Sayers 2015-08-26 19:38:58 -05:00
commit 6442ec4c2a
11 changed files with 221 additions and 51 deletions

View File

@ -193,39 +193,12 @@ public class DonationRepository extends RepositoryBase
{
public void run()
{
try (
Connection connection = getConnection();
CallableStatement statement = connection.prepareCall("{call accountGoldChange(?, ?, ?)}");
)
{
statement.setInt(1, accountId);
statement.setInt(2, gold);
statement.registerOutParameter(3, Types.BOOLEAN);
Boolean hasResults = statement.execute();
if (hasResults)
{
ResultSet resultSet = statement.getResultSet();
while (resultSet.next())
{
callback.run(resultSet.getBoolean(1));
}
}
}
catch (SQLException exception)
{
exception.printStackTrace();
}
catch (Exception exception)
{
exception.printStackTrace();
}
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0;
callback.run(success);
}
}), "Error updating player gold amount in DonationRepository : ");
}
@Override
protected void initialize()
{

View File

@ -7,6 +7,7 @@ import mineplex.core.common.util.UtilPlayer;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -18,7 +19,7 @@ public class Farming extends MiniPlugin
}
@EventHandler
public void BlockBreak(BlockPlaceEvent event)
public void BlockBreak(BlockBreakEvent event)
{
if (event.isCancelled())
return;

View File

@ -551,8 +551,7 @@ public class ClanInfo
public int getEnergyPurchasable()
{
int diff = getEnergyMax() - getEnergy();
return diff > 0 ? diff : 0;
return Math.max(getEnergyMax() - getEnergy(), 0);
}
public List<Player> getOnlinePlayers()

View File

@ -388,6 +388,45 @@ public class ClansDataAccessLayer
_manager.log("Added Neutral between [" + cA.getName() + "] and [" + cB.getName() + "] by [" + player + "].");
}
public boolean claimAll(final String name, final String player, final boolean safe, final String... chunks)
{
if (!_manager.getClanMap().containsKey(name))
return false;
final ClanInfo clan = _manager.getClanMap().get(name);
//Unclaim
for (String chunk : chunks)
{
if (_manager.getClaimMap().containsKey(chunk))
{
unclaim(chunk, player, false);
}
//Memory
ClanTerritory claim = new ClanTerritory();
claim.Owner = name;
claim.Safe = safe;
clan.getClaimSet().add(chunk);
_manager.getClaimMap().put(chunk, claim);
}
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addTerritoryClaims(clan.getId(), safe, chunks);
//Log
_manager.log("Successfully added [" + chunks.length + "] Claims for [" + name + "] by [" + player + "].");
}
});
return true;
}
@SuppressWarnings("deprecation")
public boolean claim(String name, final String chunk, String player, final boolean safe)
{
@ -436,7 +475,7 @@ public class ClansDataAccessLayer
}
//Log
_manager.log("Added Claim for [" + name + "] at [" + chunk + "] by [" + player + "].");
//_manager.log("Added Claim for [" + name + "] at [" + chunk + "] by [" + player + "].");
return true;
}

View File

@ -68,6 +68,7 @@ public class ClansGame extends MiniPlugin
return;
for (Player cur : UtilServer.getPlayers())
{
if (Clans.getClanUtility().isSafe(cur.getLocation()))
{
long lastDamager = Clans.getCombatManager().Get(cur).GetLastCombat();
@ -80,6 +81,7 @@ public class ClansGame extends MiniPlugin
Clans.getCondition().Factory().Custom("Unsafe", cur, cur, ConditionType.CUSTOM, 1, 0, false, Material.FIRE, (byte)0, true);
}
}
}
}
@EventHandler

View File

@ -47,6 +47,7 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.commands.MapCommand;
import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.commands.ServerTimeCommand;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager;
@ -189,6 +190,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
SkillFactory skillManager = new SkillFactory(plugin, damageManager, this, _combatManager, _condition, _projectileManager, disguiseManager, blockRestore, fire, new Movement(plugin), teleport, energy, webServerAddress);
skillManager.RemoveSkill("Dwarf Toss", "Block Toss");
skillManager.removeSkill("Whirlwind Axe");
skillManager.removeSkill("Shield Smash");
_classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress);
StatsManager statsManager = new StatsManager(plugin, _clientManager);
@ -219,12 +221,18 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
public void addCommands()
{
addCommand(new ClansCommand(this));
addCommand(new RegionsCommand(this));
addCommand(new ClansChatCommand(this));
addCommand(new ClansAllyChatCommand(this));
addCommand(new ServerTimeCommand(this));
addCommand(new ClanManagementCommand(this));
addCommand(new MapCommand(this));
}
public ClansRegions getClanRegions()
{
return _clanRegions;
}
public ItemMapManager getItemMapManager()
{

View File

@ -0,0 +1,30 @@
package mineplex.game.clans.clans.commands;
import org.bukkit.entity.Player;
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.ClansManager;
import mineplex.game.clans.clans.regions.ClansRegions;
public class RegionsCommand extends CommandBase<ClansManager>
{
private ClansManager _manager;
public RegionsCommand(ClansManager plugin)
{
super(plugin, Rank.ADMIN, "region-reset");
_manager = plugin;
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main("Regions", "Resetting clans regions!"));
_manager.getClanRegions().resetRegions();
}
}

View File

@ -1,10 +1,15 @@
package mineplex.game.clans.clans.regions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -15,10 +20,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.packethandler.PacketPlayOutWorldBorder;
import mineplex.game.clans.clans.ClanInfo;
@ -29,7 +36,7 @@ import mineplex.game.clans.spawn.Spawn;
public class ClansRegions extends MiniPlugin
{
public final static String DEFAULT_WORLD_NAME = "world";
public final static int SPAWN_RADIUS = 0; // Radius of spawn claim area (measured in chunks)
public final static int SPAWN_RADIUS = 1; // Radius of spawn claim area (measured in chunks)
public final static int SHOP_RADIUS = 2; // Radius of shop claim area (measured in chunks)
public final static int FIELDS_RADIUS = 7; // Radius of fields claim area (measured in chunks)
public final static int BORDERLANDS_RADIUS = 50; // Radius of borderlands claim area (measured in chunks)
@ -40,7 +47,7 @@ public class ClansRegions extends MiniPlugin
public ClansRegions(JavaPlugin plugin, ClansManager manager, String worldName)
{
super("Clans Regions - " + worldName, plugin);
super("Clans Regions" + worldName, plugin);
_manager = manager;
_world = Bukkit.getWorld(worldName);
}
@ -53,17 +60,59 @@ public class ClansRegions extends MiniPlugin
public void initializeRegions()
{
Location worldCenter = new Location(_world, 0, 0, 0);
// Initialize Spawn faction and claims
Set<Location> spawns = Spawn.getInstance().getSpawnLocations();
Location[] spawnsArray = spawns.toArray(new Location[spawns.size()]);
Location[] shopsArray = {Spawn.getEastShop(), Spawn.getWestShop()};
claimArea("Spawn", SPAWN_RADIUS, 0, true, spawnsArray);
claimArea("Shops", SHOP_RADIUS, 0, true, shopsArray);
// Initialize Spawn faction and claims
claimArea("Spawn", SPAWN_RADIUS, 0, true, new Location[]{Spawn.getNorthSpawn(), Spawn.getSouthSpawn()});
claimArea("Shops", SHOP_RADIUS, 0, true, new Location[]{Spawn.getEastShop(), Spawn.getWestShop()});
// Initialize Fields and Borderlands factions and claims
claimArea("Fields", FIELDS_RADIUS, 0, false, worldCenter);
claimArea("Borderlands", BORDERLANDS_RADIUS, 32, false, worldCenter);
//debugClan("Spawn");
//debugClan("Shops");
//debugClan("Fields");
//debugClan("Borderlands");
}
public void debugClan(String clanName)
{
ClanInfo clan = _manager.getClan(clanName);
if (clan != null)
{
System.out.println("Clan " + clanName + " has " + clan.getClaimSet().size() + " claims!");
}
else
{
System.out.println("NO CLAN FOUND BY NAME " + clanName);
}
}
public void resetRegions()
{
clearClaims("Spawn");
clearClaims("Shops");
clearClaims("Fields");
clearClaims("Borderlands");
initializeRegions();
}
private void clearClaims(String name)
{
ClanInfo clan = _manager.getClan(name);
System.out.println("Clearing claims for " + name + " with clan id " + clan.getId() + "!");
if (clan != null)
{
for (String chunk : clan.getClaimSet())
{
_manager.getClaimMap().remove(chunk);
}
clan.getClaimSet().clear();
_manager.getClanDataAccess().getRepository().removeTerritoryClaims(clan.getId());
}
}
/**
@ -79,7 +128,7 @@ public class ClansRegions extends MiniPlugin
{
final ClanInfo clan = _manager.getClan(clanName);
if (clan == null)
if (clan == null )
{
_manager.getClanDataAccess().create("ClansRegions", clanName, true, new Callback<ClanInfo>()
{
@ -93,6 +142,8 @@ public class ClansRegions extends MiniPlugin
claimArea(data, location, chunkRadius, claimOffset, safe);
log(String.format("Initialized %s faction territory and creation!", clanName));
}
debugClan(clanName);
}
else
{
@ -102,12 +153,20 @@ public class ClansRegions extends MiniPlugin
}
});
}
else
{
for (Location location : locations)
{
claimArea(clan, location, chunkRadius, claimOffset, safe);
}
}
}
private void claimArea(ClanInfo clan, Location location, int chunkRadius, int claimOffset, boolean safe)
{
int chunkX = location.getChunk().getX();
int chunkZ = location.getChunk().getZ();
Set<String> chunks = new HashSet<String>();
for (int xOffset = -chunkRadius; xOffset <= chunkRadius; xOffset++)
{
@ -124,9 +183,14 @@ public class ClansRegions extends MiniPlugin
continue;
}
_manager.getClanDataAccess().claim(clan.getName(), chunkStr, "ClansRegions", safe);
chunks.add(chunkStr);
}
}
if (chunks.size() > 0)
{
_manager.getClanDataAccess().claimAll(clan.getName(), "ClansRegions", safe, chunks.toArray(new String[0]));
}
}
private void sendBorder(Player player)

View File

@ -1,7 +1,10 @@
package mineplex.game.clans.clans.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.UUID;
@ -13,6 +16,7 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.Column;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
@ -23,6 +27,7 @@ import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import org.jooq.DSLContext;
import static mineplex.database.Tables.*;
@ -43,6 +48,7 @@ public class ClanRepository extends RepositoryBase
private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;";
private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan WHERE clanId = ?;";
private static String DELETE_CLAN_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND serverId = ? AND chunk = ?;";
private static String DELETE_CLAN_ALL_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND serverId = ?;";
private static String DELETE_CLAN_TERRITORIES = "DELETE FROM clanTerritory WHERE clanId = ?;";
private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;";
private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances WHERE clanId = ? OR otherClanId = ?;";
@ -336,6 +342,48 @@ public class ClanRepository extends RepositoryBase
{
return executeUpdate(ADD_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnInt("serverId", _serverId), new ColumnVarChar("chunk", 100, chunk), new ColumnBoolean("safe", safe)) == 1;
}
public boolean addTerritoryClaims(int clanId, boolean safe, String... chunks)
{
int affectedRows = 0;
int size = chunks.length;
String query = "INSERT INTO clanTerritory (clanId, serverId, chunk, safe) VALUES";
for (int i = 0; i < size; i++)
{
query += " (?, ?, ?, ?)";
if (i < (size - 1))
query += ",";
}
query += ";";
try (Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS))
{
Column<?> clanIdCol = new ColumnInt("clanId", clanId);
Column<?> serverIdCol = new ColumnInt("serverId", _serverId);
Column<?> safeCol = new ColumnBoolean("safe", safe);
int i = 0;
for (String chunk : chunks)
{
Column<?> chunkCol = new ColumnVarChar("chunk", 100, chunk);
clanIdCol.setValue(preparedStatement, i + 1);
serverIdCol.setValue(preparedStatement, i + 2);
chunkCol.setValue(preparedStatement, i + 3);
safeCol.setValue(preparedStatement, i + 4);
i += 4;
}
affectedRows = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
return affectedRows == size;
}
public void addEnemy(int clanId, int otherClanId)
{
@ -346,6 +394,11 @@ public class ClanRepository extends RepositoryBase
{
executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnInt("serverId", _serverId), new ColumnVarChar("chunk", 100, chunk));
}
public void removeTerritoryClaims(int clanId)
{
executeUpdate(DELETE_CLAN_ALL_TERRITORY, new ColumnInt("clanId", clanId), new ColumnInt("serverId", _serverId));
}
public void updateClan(int clanId, String name, String desc, String home, boolean admin, int energy, int kills, int murder, int deaths, int warWins, int warLosses, Timestamp lastOnline)
{

View File

@ -174,17 +174,18 @@ public class GoldManager extends MiniPlugin
public void addGold(Player player, int amount)
{
if (amount >= 0)
_donationManager.RewardGoldLater("GoldManager", player, amount);
_donationManager.rewardGold(null, "GoldManager", player, amount);
}
public void deductGold(Callback<Boolean> resultCallback, Player player, int amount)
{
_donationManager.rewardGold(resultCallback, "GoldManager", player, -amount);
if (amount >= 0)
_donationManager.rewardGold(resultCallback, "GoldManager", player, -amount);
}
public void cashIn(Player player, GoldToken token)
{
int value = token.getGoldValue();
int value = token.getGoldValue();
addGold(player, value);
notify(player, String.format("You have cashed in a gold token worth %dg!", value));
}

View File

@ -30,7 +30,7 @@ import mineplex.game.clans.items.generation.WeightSet;
public class Spawn extends MiniPlugin
{
public static final int SPAWN_RADIUS = 9;
public static final int SPAWN_RADIUS = 32;
public static final int SHOP_RADIUS = 48;
private static Spawn _instance;
@ -95,7 +95,7 @@ public class Spawn extends MiniPlugin
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event)
{
if (isInSpawn(event.getLocation()))
if (event.getEntity() instanceof Monster && isInSpawn(event.getLocation()))
{
event.setCancelled(true);
}
@ -241,7 +241,7 @@ public class Spawn extends MiniPlugin
public static Location getEastShop()
{
return new Location(getSpawnWorld(), 200, 68, 0);
return new Location(getSpawnWorld(), 216, 68, 0);
}
public static Location getWestShop()