Lots of great fixes

This commit is contained in:
Sam 2017-05-02 23:17:06 +01:00
parent 82ebd28400
commit 6d8c65ed08
11 changed files with 115 additions and 68 deletions

View File

@ -66,7 +66,7 @@ public class CashOutModule extends MiniPlugin
@EventHandler
public void teleportIn(PlayerTeleportIntoMapEvent event)
{
if (event.isCancelled())
if (event.isCancelled() || event.getPlayer().getInventory().contains(CASH_OUT_ITEM))
{
return;
}
@ -120,7 +120,7 @@ public class CashOutModule extends MiniPlugin
while (iterator.hasNext())
{
UUID key = iterator.next();
Player player = UtilPlayer.searchExact(key);
final Player player = UtilPlayer.searchExact(key);
CashOutSession session = _sessions.get(key);
double current = session.getCurrent();
ArmorStand stand = session.getArmourStand();
@ -140,14 +140,30 @@ public class CashOutModule extends MiniPlugin
if (session.getCurrent() <= 0)
{
PlayerCashOutCompleteEvent completeEvent = new PlayerCashOutCompleteEvent(player);
UtilServer.CallEvent(completeEvent);
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems());
session.endSession();
iterator.remove();
Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.FORCE_TRANSFER);
if (UtilServer.isTestServer())
{
kickPlayer(player);
}
else
{
Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.FORCE_TRANSFER);
runSyncLater(() ->
{
if (player.isOnline())
{
kickPlayer(player);
}
}, 20);
}
}
}
}
@ -260,4 +276,9 @@ public class CashOutModule extends MiniPlugin
return null;
}
private void kickPlayer(Player player)
{
player.kickPlayer(C.cGreen + "Imagine you are being sent to the lobby.");
}
}

View File

@ -46,14 +46,14 @@ public class EconomyModule extends MiniClientPlugin<Integer>
public void teleportIn(PlayerTeleportIntoMapEvent event)
{
Player player = event.getPlayer();
addToStore(event.getPlayer(), null, GEM_START_COST);
Donor donor = _donation.Get(event.getPlayer());
if (donor.getBalance(GlobalCurrency.GEM) >= GEM_START_COST)
{
_donation.purchaseUnknownSalesPackage(player, "Gem Hunters Access", GlobalCurrency.GEM, GEM_START_COST, false, null);
}
addToStore(event.getPlayer(), null, GEM_START_COST);
}
@EventHandler

View File

@ -4,13 +4,17 @@ import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.gemhunters.death.quitnpc.QuitNPC;
import mineplex.gemhunters.death.quitnpc.QuitNPCModule;
import mineplex.gemhunters.economy.EconomyModule;
import mineplex.gemhunters.loot.InventoryModule;
import mineplex.gemhunters.map.ItemMapModule;
import mineplex.gemhunters.persistence.PersistenceData;
import mineplex.gemhunters.persistence.PersistenceModule;
import mineplex.gemhunters.persistence.PersistenceRepository;
import mineplex.gemhunters.quest.QuestModule;
import mineplex.gemhunters.spawn.SpawnModule;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
@ -26,6 +30,8 @@ public class JoinModule extends MiniPlugin
private final QuestModule _quest;
private final PersistenceModule _persistence;
private final QuitNPCModule _npc;
private final InventoryModule _inventory;
private final SpawnModule _spawn;
private JoinModule()
{
@ -36,6 +42,8 @@ public class JoinModule extends MiniPlugin
_quest = require(QuestModule.class);
_persistence = require(PersistenceModule.class);
_npc = require(QuitNPCModule.class);
_inventory = require(InventoryModule.class);
_spawn = require(SpawnModule.class);
}
@EventHandler
@ -45,33 +53,35 @@ public class JoinModule extends MiniPlugin
CoreClient client = _client.Get(player);
PersistenceRepository repository = _persistence.getRepository();
Consumer<PersistenceData> response = data ->
{
_economy.setStore(player, data.getGems());
_quest.setPlayerData(player, data.getQuestData());
player.teleport(data.getLocation());
player.setHealth(data.getHealth());
player.setMaxHealth(data.getMaxHealth());
player.setFoodLevel(data.getHunger());
player.getInventory().clear();
player.getInventory().addItem(data.getItems());
player.getInventory().setArmorContents(data.getArmour());
};
runSync(() -> {
_economy.setStore(player, data.getGems());
_quest.setPlayerData(player, data.getQuestData());
player.teleport(data.getLocation());
player.setHealth(data.getHealth());
player.setMaxHealth(data.getMaxHealth());
player.setFoodLevel(data.getHunger());
player.getInventory().addItem(data.getItems());
player.getInventory().setArmorContents(data.getArmour());
_inventory.unlockSlots(player, data.getSlots(), false);
});
player.getInventory().clear();
if (_npc.hasNPC(player))
{
QuitNPC npc = _npc.getNPC(player);
npc.despawn(true);
}
_inventory.resetSlots(player);
runAsync(() ->
{
repository.getPersistenceData(response, client);
if (_npc.hasNPC(player))
if (!repository.exists(client))
{
QuitNPC npc = _npc.getNPC(player);
npc.despawn(true);
}
if (repository.exists(client))
{
_spawn.teleportToSpawn(player);
}
});
}

View File

@ -52,12 +52,6 @@ public class InventoryModule extends MiniPlugin
resetSlots(event.getPlayer());
}
@EventHandler
public void playerJoin(PlayerJoinEvent event)
{
resetSlots(event.getPlayer());
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
@ -110,6 +104,13 @@ public class InventoryModule extends MiniPlugin
public void unlockSlots(Player player, int slots)
{
unlockSlots(player, slots, true);
}
public void unlockSlots(Player player, int slots, boolean inform)
{
_slotsUnlocked.putIfAbsent(player.getUniqueId(), 0);
Inventory inv = player.getInventory();
UUID key = player.getUniqueId();
@ -122,11 +123,14 @@ public class InventoryModule extends MiniPlugin
inv.setItem(i, null);
}
player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!"));
if (inform)
{
player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!"));
}
_slotsUnlocked.put(key, _slotsUnlocked.get(key) + slots);
}
private void resetSlots(Player player)
public void resetSlots(Player player)
{
Inventory inv = player.getInventory();
@ -137,4 +141,9 @@ public class InventoryModule extends MiniPlugin
inv.setItem(i, LOCKED);
}
}
public int getSlots(Player player)
{
return _slotsUnlocked.get(player.getUniqueId());
}
}

View File

@ -613,20 +613,20 @@ public class LootModule extends MiniPlugin
{
return;
}
_shownPlayers.clear();
for (Player player : Bukkit.getOnlinePlayers())
{
UUID key = player.getUniqueId();
for (LootItemReward itemReward : _itemRewards)
{
if (itemReward.getPlayer() == null)
{
continue;
}
if (itemReward.getPlayer().equals(player))
{
_shownPlayers.add(key);
@ -641,7 +641,7 @@ public class LootModule extends MiniPlugin
{
event.getPlayer().getInventory().addItem(SPAWN_ITEMS);
}
@EventHandler
public void cashOutComplete(PlayerCashOutCompleteEvent event)
{

View File

@ -29,6 +29,7 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack;
@ -662,12 +663,21 @@ public class ItemMapModule extends MiniPlugin
showZoom(player, info);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void playerJoin(PlayerJoinEvent event)
{
handleGive(event.getPlayer());
}
@EventHandler
public void teleportIn(PlayerCustomRespawnEvent event)
public void respawn(PlayerCustomRespawnEvent event)
{
handleGive(event.getPlayer());
}
public void handleGive(Player player)
{
MapInfo info = new MapInfo(_mapId);
Player player = event.getPlayer();
Location loc = player.getLocation();
int zoom = getZoom(1);

View File

@ -13,10 +13,11 @@ public class PersistenceData
private final int _health;
private final int _maxHealth;
private final int _hunger;
private final int _slots;
private final ItemStack[] _items;
private final ItemStack[] _armour;
public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, ItemStack[] items, ItemStack[] armour)
public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, int slots, ItemStack[] items, ItemStack[] armour)
{
_gems = gems;
_location = location;
@ -25,6 +26,7 @@ public class PersistenceData
_maxHealth = maxHealth;
_hunger = hunger;
_items = items;
_slots = slots;
_armour = armour;
}
@ -58,6 +60,11 @@ public class PersistenceData
return _hunger;
}
public int getSlots()
{
return _slots;
}
public ItemStack[] getItems()
{
return _items;

View File

@ -7,6 +7,7 @@ import mineplex.core.account.CoreClientManager;
import mineplex.gemhunters.death.event.QuitNPCDespawnEvent;
import mineplex.gemhunters.economy.CashOutModule;
import mineplex.gemhunters.economy.EconomyModule;
import mineplex.gemhunters.loot.InventoryModule;
import mineplex.gemhunters.quest.QuestModule;
import mineplex.gemhunters.quest.QuestPlayerData;
import net.minecraft.server.v1_8_R3.EntityItemFrame;
@ -28,6 +29,7 @@ public class PersistenceModule extends MiniPlugin
private final CoreClientManager _client;
private final EconomyModule _economy;
private final QuestModule _quest;
private final InventoryModule _inventory;
private final PersistenceRepository _repository;
@ -38,6 +40,7 @@ public class PersistenceModule extends MiniPlugin
_client = require(CoreClientManager.class);
_quest = require(QuestModule.class);
_economy = require(EconomyModule.class);
_inventory = require(InventoryModule.class);
_repository = new PersistenceRepository();
}
@ -54,10 +57,11 @@ public class PersistenceModule extends MiniPlugin
int health = (int) player.getHealth();
int maxHealth = (int) player.getMaxHealth();
int hunger = player.getFoodLevel();
int slots = _inventory.getSlots(player);
ItemStack[] items = player.getInventory().getContents();
ItemStack[] armour = player.getInventory().getArmorContents();
PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, items, armour);
PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, slots, items, armour);
runAsync(() -> _repository.savePersistence(client, data));
}

View File

@ -25,8 +25,8 @@ public class PersistenceRepository extends RepositoryBase
{
private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=?;";
private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);";
private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,items=?,armour=? WHERE accountId=?;";
private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=? WHERE accountId=?;";
private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;";
private static final Gson GSON;
@ -61,6 +61,7 @@ public class PersistenceRepository extends RepositoryBase
int z = resultSet.getInt("z");
int yaw = resultSet.getInt("yaw");
int pitch = resultSet.getInt("pitch");
int slots = resultSet.getInt("slots");
String quests = resultSet.getString("quests");
QuestPlayerData questData = GSON.fromJson(quests, QuestPlayerData.class);
@ -99,7 +100,7 @@ public class PersistenceRepository extends RepositoryBase
_exists.add(accountId);
Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch);
PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0]));
PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, slots, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0]));
response.accept(data);
}
}, new ColumnInt("accountId", accountId));
@ -118,6 +119,7 @@ public class PersistenceRepository extends RepositoryBase
int z = data.getLocation().getBlockZ();
int yaw = (int) data.getLocation().getYaw();
int pitch = (int) data.getLocation().getPitch();
int slots = data.getSlots();
ItemStack[] items = data.getItems();
ItemStack[] armour = data.getArmour();
List<Map<String, Object>> itemsMap = new ArrayList<>(items.length);
@ -156,6 +158,7 @@ public class PersistenceRepository extends RepositoryBase
new ColumnInt("yaw", yaw),
new ColumnInt("pitch", pitch),
new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())),
new ColumnInt("slots", slots),
new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)),
new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)),
new ColumnInt("accountId", accountId)
@ -175,6 +178,7 @@ public class PersistenceRepository extends RepositoryBase
new ColumnInt("yaw", yaw),
new ColumnInt("pitch", pitch),
new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())),
new ColumnInt("slots", slots),
new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)),
new ColumnVarChar("armour", 1000, GSON.toJson(armourMap))
);

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import mineplex.core.recharge.Recharge;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
@ -112,7 +113,7 @@ public class SafezoneModule extends MiniPlugin
{
_playerStatus.setStatus(player, PlayerStatusType.SAFE, true);
}
else
else if (Recharge.Instance.usable(player, "Cash Out"))
{
_playerStatus.setStatus(player, PlayerStatusType.SAFE);
}
@ -138,7 +139,7 @@ public class SafezoneModule extends MiniPlugin
Player player = (Player) event.getEntity();
if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT)
if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT && Recharge.Instance.usable(player, "Cash Out"))
{
event.setCancelled(true);
}

View File

@ -67,7 +67,7 @@ public class SpawnModule extends MiniPlugin
addCommand(new HubCommand(this));
}
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.LOWEST)
public void playerJoin(PlayerJoinEvent event)
{
if (_spawn == null || _center == null)
@ -76,25 +76,6 @@ public class SpawnModule extends MiniPlugin
_center = new Location(_worldData.World, 0, 64, 0);
}
Player player = event.getPlayer();
if (_npc.hasNPC(player))
{
QuitNPC npc = _npc.getNPC(player);
npc.despawn(true);
return;
}
player.teleport(_spawn);
// player.setFoodLevel(20);
// player.setExhaustion(0);
// player.setLevel(0);
// player.setExp(0);
// player.getInventory().clear();
// player.getInventory().setArmorContents(null);
// player.updateInventory();
if (_npcsSpawned)
{
return;