More fixes!

This commit is contained in:
Sam 2017-05-03 22:05:10 +01:00
parent 3a1fb3cb86
commit 4a984f3c41
7 changed files with 119 additions and 35 deletions

View File

@ -8,6 +8,7 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.core.common.util.UtilPlayer;
import mineplex.gemhunters.economy.CashOutModule;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -29,22 +30,20 @@ public class QuitNPCModule extends MiniPlugin
{
private static final long LOG_OUT_TIME = TimeUnit.SECONDS.toMillis(60);
private final TextTutorialManager _tutorial;
private final CashOutModule _cashOut;
private final Map<UUID, QuitNPC> _npcs;
private final Map<UUID, String> _killedBy;
private final Set<UUID> _aboutToCashOut;
private QuitNPCModule()
{
super("Quit NPC");
_tutorial = require(TextTutorialManager.class);
_cashOut = require(CashOutModule.class);
_npcs = new HashMap<>();
_killedBy = new HashMap<>();
_aboutToCashOut = new HashSet<>();
}
public void spawnNpc(Player player)
@ -57,10 +56,9 @@ public class QuitNPCModule extends MiniPlugin
return;
}
if (_aboutToCashOut.contains(player.getUniqueId()))
if (_cashOut.isAboutToCashOut(player))
{
log(player.getName() + " was cashing out");
_aboutToCashOut.remove(player.getUniqueId());
return;
}
@ -78,14 +76,6 @@ public class QuitNPCModule extends MiniPlugin
_npcs.put(player.getUniqueId(), new QuitNPC(this, player, LOG_OUT_TIME));
}
@EventHandler
public void cashOutComplete(PlayerCashOutCompleteEvent event)
{
UUID key = event.getPlayer().getUniqueId();
_aboutToCashOut.add(key);
}
@EventHandler(priority = EventPriority.LOWEST)
public void playerQuit(PlayerQuitEvent event)
{

View File

@ -25,13 +25,11 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.*;
@ReflectivelyCreateMiniPlugin
public class CashOutModule extends MiniPlugin
@ -47,7 +45,8 @@ public class CashOutModule extends MiniPlugin
private final DonationManager _donation;
private final Map<UUID, CashOutSession> _sessions;
private final Set<UUID> _aboutToCashOut;
public CashOutModule()
{
super("Cash Out");
@ -55,6 +54,7 @@ public class CashOutModule extends MiniPlugin
_donation = require(DonationManager.class);
_sessions = new HashMap<>();
_aboutToCashOut = new HashSet<>();
}
@Override
@ -143,6 +143,8 @@ public class CashOutModule extends MiniPlugin
UtilServer.CallEvent(completeEvent);
_aboutToCashOut.add(player.getUniqueId());
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems());
session.endSession();
@ -230,6 +232,12 @@ public class CashOutModule extends MiniPlugin
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void playerQuit(PlayerQuitEvent event)
{
_aboutToCashOut.remove(event.getPlayer().getUniqueId());
}
public void attemptCashOut(Player player)
{
UUID key = player.getUniqueId();
@ -263,6 +271,11 @@ public class CashOutModule extends MiniPlugin
return getCashOutSession(player) != null;
}
public boolean isAboutToCashOut(Player player)
{
return _aboutToCashOut.contains(player.getUniqueId());
}
public CashOutSession getCashOutSession(Player player)
{
for (UUID key : _sessions.keySet())

View File

@ -18,31 +18,52 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ReflectivelyCreateMiniPlugin
public class PersistenceModule extends MiniPlugin
{
private final CoreClientManager _client;
private final CashOutModule _cashOut;
private final EconomyModule _economy;
private final QuestModule _quest;
private final InventoryModule _inventory;
private final PersistenceRepository _repository;
private final List<String> _denyJoining;
public PersistenceModule()
{
super("Persistence");
_client = require(CoreClientManager.class);
_cashOut = require(CashOutModule.class);
_quest = require(QuestModule.class);
_economy = require(EconomyModule.class);
_inventory = require(InventoryModule.class);
_repository = new PersistenceRepository();
_denyJoining = Collections.synchronizedList(new ArrayList<>());
}
@EventHandler
public void preLogin(AsyncPlayerPreLoginEvent event)
{
if (_denyJoining.contains(event.getName()))
{
event.disallow(Result.KICK_OTHER, "Please wait a few seconds before connecting again.");
}
}
@EventHandler(priority = EventPriority.LOWEST)
@ -51,6 +72,17 @@ public class PersistenceModule extends MiniPlugin
Player player = event.getPlayer();
CoreClient client = _client.Get(player);
if (_cashOut.isAboutToCashOut(player))
{
runAsync(() ->
{
_denyJoining.add(player.getName());
_repository.deletePersistence(client);
_denyJoining.remove(player.getName());
});
return;
}
int gems = _economy.Get(player);
Location location = player.getLocation();
QuestPlayerData quest = _quest.Get(player);
@ -63,7 +95,12 @@ public class PersistenceModule extends MiniPlugin
PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, slots, items, armour);
runAsync(() -> _repository.savePersistence(client, data));
runAsync(() ->
{
_denyJoining.add(player.getName());
_repository.savePersistence(client, data);
_denyJoining.remove(player.getName());
});
}
@EventHandler(priority = EventPriority.LOWEST)
@ -72,7 +109,12 @@ public class PersistenceModule extends MiniPlugin
Player player = event.getEntity();
CoreClient client = _client.Get(player);
runAsync(() -> _repository.deletePersistence(client));
runAsync(() ->
{
_denyJoining.add(player.getName());
_repository.deletePersistence(client);
_denyJoining.remove(player.getName());
});
}
@EventHandler
@ -80,7 +122,13 @@ public class PersistenceModule extends MiniPlugin
{
if (!event.isPluginRemove())
{
runAsync(() -> _client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence));
runAsync(() ->
{
String name = event.getNpc().getName();
_denyJoining.add(name);
_client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence);
_denyJoining.remove(name);
});
}
}

View File

@ -29,6 +29,7 @@ public class PersistenceRepository extends RepositoryBase
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;
private static final ItemStack AIR = new ItemStack(Material.AIR);
static
{
@ -129,7 +130,7 @@ public class PersistenceRepository extends RepositoryBase
{
if (itemStack == null || itemStack.getType() == Material.MAP || itemStack.getType() == Material.STAINED_GLASS_PANE)
{
continue;
itemStack = AIR;
}
itemsMap.add(itemStack.serialize());
@ -192,6 +193,7 @@ public class PersistenceRepository extends RepositoryBase
int accountId = client.getAccountId();
executeUpdate(DELETE_DATA, new ColumnInt("accountId", accountId));
_exists.remove(Integer.valueOf(accountId));
}
public boolean exists(CoreClient client)

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
@ -129,7 +130,7 @@ public class SafezoneModule extends MiniPlugin
_currentSafezone.remove(player.getUniqueId());
}
@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void entityDamage(EntityDamageEvent event)
{
if (!(event.getEntity() instanceof Player))
@ -139,10 +140,15 @@ public class SafezoneModule extends MiniPlugin
Player player = (Player) event.getEntity();
if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT && Recharge.Instance.usable(player, "Cash Out"))
if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT)
{
event.setCancelled(true);
}
if (!Recharge.Instance.usable(player, "Cash Out"))
{
event.setCancelled(false);
}
}
@EventHandler

View File

@ -74,6 +74,7 @@ public class SpawnModule extends MiniPlugin
{
_spawn = _worldData.getCustomLocation("PLAYER_SPAWN").get(0);
_center = new Location(_worldData.World, 0, 64, 0);
_worldData.World.setSpawnLocation(_spawn.getBlockX(), _spawn.getBlockY(), _spawn.getBlockZ());
}
if (_npcsSpawned)

View File

@ -1,5 +1,8 @@
package mineplex.gemhunters.tutorial;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -11,8 +14,10 @@ import mineplex.core.texttutorial.tutorial.Tutorial;
import mineplex.gemhunters.economy.EconomyModule;
import mineplex.gemhunters.spawn.SpawnModule;
import mineplex.gemhunters.world.WorldDataModule;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class GemHuntersTutorial extends Tutorial
public class GemHuntersTutorial extends Tutorial implements Listener
{
private final SpawnModule _spawn;
@ -51,7 +56,7 @@ public class GemHuntersTutorial extends Tutorial
}));
addPhase(new Phase(getLocation(1), "PVP", new String[] {
"Players start with " + C.cGreen + EconomyModule.GEM_START_COST + C.cWhite + " Gems and must survive in the city.",
"Killing another player will gift you " + C.cYellow + "50%" + C.cWhite + "of their total gems.",
"Killing another player will gift you " + C.cYellow + "50%" + C.cWhite + " of their total gems.",
}));
addPhase(new Phase(getLocation(2), "Safezones", new String[] {
"In Safe Zones you cannot take damage and can purchase items like",
@ -59,8 +64,8 @@ public class GemHuntersTutorial extends Tutorial
}));
addPhase(new Phase(getLocation(3), "Items", new String[] {
"Collect items from chests and powerup.",
"You can find anything from Weaponrs to Cosmetics.",
"If you find somethiing you want to keep you can",
"You can find anything from Weapons to Cosmetics.",
"If you find something you want to keep you can",
C.cGreen + "Cash Out" + C.cWhite + " at any time by right clicking the " + C.cGreen + "Emerald" + C.cWhite + " in your inventory.",
}));
addPhase(new Phase(getLocation(4), "Cashing Out", new String[] {
@ -71,13 +76,15 @@ public class GemHuntersTutorial extends Tutorial
addPhase(new Phase(getLocation(5), "Good luck", new String[] {
"Stay safe! Anarchy rules in the world of " + C.cGreen + "Gem Hunters" + C.cWhite + "!"
}));
UtilServer.RegisterEvents(this);
}
@Override
public void startTutorial(Player player)
{
super.startTutorial(player);
player.setAllowFlight(true);
player.setFlying(true);
}
@ -100,4 +107,21 @@ public class GemHuntersTutorial extends Tutorial
return new Location(_worldData.World, locations[0] + 0.5, locations[1] + 0.5, locations[2] + 0.5, locations[3], locations[4]);
}
@EventHandler
public void updateFlight(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER)
{
return;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (isInTutorial(player) && !player.isFlying())
{
player.setFlying(true);
}
}
}
}