Fix players being able to claim level rewards twice if on EU and US and fix negative chests! 🎉
This commit is contained in:
parent
4f8c63d6a0
commit
e9a244b274
@ -31,6 +31,7 @@ import mineplex.core.achievement.leveling.rewards.LevelReward;
|
|||||||
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
||||||
import mineplex.core.common.currency.GlobalCurrency;
|
import mineplex.core.common.currency.GlobalCurrency;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.common.util.UtilTextMiddle;
|
import mineplex.core.common.util.UtilTextMiddle;
|
||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
@ -43,6 +44,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleWitchsCure;
|
|||||||
import mineplex.core.gadget.gadgets.taunts.EasyModeTaunt;
|
import mineplex.core.gadget.gadgets.taunts.EasyModeTaunt;
|
||||||
import mineplex.core.gadget.types.Gadget;
|
import mineplex.core.gadget.types.Gadget;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
import mineplex.core.treasure.types.TreasureType;
|
import mineplex.core.treasure.types.TreasureType;
|
||||||
import mineplex.serverdata.commands.CommandCallback;
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
@ -405,10 +407,28 @@ public class LevelingManager extends MiniDbClientPlugin<List<Integer>> implement
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void claim(Player player, int level)
|
public void claim(Player player, int level, ShopPageBase menu)
|
||||||
{
|
{
|
||||||
Get(player).add(level);
|
runAsync(() ->
|
||||||
runAsync(() -> _repository.claimReward(ClientManager.getAccountId(player), level));
|
{
|
||||||
|
boolean success = _repository.claimReward(ClientManager.getAccountId(player), level);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
runSync(() ->
|
||||||
|
{
|
||||||
|
Get(player).add(level);
|
||||||
|
List<LevelReward> rewards = getLevelRewards(level);
|
||||||
|
player.sendMessage(F.main(_plugin.getName(), "You claimed rewards for level " + F.elem(level) + ":"));
|
||||||
|
rewards.forEach(reward ->
|
||||||
|
{
|
||||||
|
reward.claim(player);
|
||||||
|
player.sendMessage(F.main(getName(), reward.getDescription()));
|
||||||
|
menu.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasClaimed(Player player, int level)
|
public boolean hasClaimed(Player player, int level)
|
||||||
|
@ -14,11 +14,11 @@ public class LevelingRepository extends RepositoryBase
|
|||||||
super(DBPool.getAccount());
|
super(DBPool.getAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void claimReward(int accountId, int level)
|
public boolean claimReward(int accountId, int level)
|
||||||
{
|
{
|
||||||
executeInsert(CLAIM_REWARD, null,
|
return executeInsert(CLAIM_REWARD, null,
|
||||||
new ColumnInt("accountId", accountId),
|
new ColumnInt("accountId", accountId),
|
||||||
new ColumnInt("level", level)
|
new ColumnInt("level", level)
|
||||||
);
|
) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package mineplex.core.achievement.leveling.ui.button;
|
package mineplex.core.achievement.leveling.ui.button;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import mineplex.core.achievement.leveling.LevelingManager;
|
import mineplex.core.achievement.leveling.LevelingManager;
|
||||||
import mineplex.core.achievement.leveling.rewards.LevelReward;
|
|
||||||
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
||||||
import mineplex.core.common.util.F;
|
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
import mineplex.core.shop.item.IButton;
|
import mineplex.core.shop.item.IButton;
|
||||||
import mineplex.core.shop.page.ShopPageBase;
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
@ -16,16 +12,14 @@ import mineplex.core.shop.page.ShopPageBase;
|
|||||||
public class LevelRewardButton implements IButton
|
public class LevelRewardButton implements IButton
|
||||||
{
|
{
|
||||||
|
|
||||||
private LevelingManager _plugin;
|
private final LevelingManager _plugin;
|
||||||
private ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
private final ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
||||||
private final List<LevelReward> _rewards;
|
|
||||||
private final int _level;
|
private final int _level;
|
||||||
|
|
||||||
public LevelRewardButton(ShopPageBase<LevelingManager, LevelRewardShop> menu, List<LevelReward> rewards, int level)
|
public LevelRewardButton(ShopPageBase<LevelingManager, LevelRewardShop> menu, int level)
|
||||||
{
|
{
|
||||||
_plugin = menu.getPlugin();
|
_plugin = menu.getPlugin();
|
||||||
_menu = menu;
|
_menu = menu;
|
||||||
_rewards = rewards;
|
|
||||||
_level = level;
|
_level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,14 +32,10 @@ public class LevelRewardButton implements IButton
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the player the reward
|
_plugin.claim(player, _level, _menu);
|
||||||
_rewards.forEach(reward -> reward.claim(player));
|
|
||||||
_plugin.claim(player, _level);
|
|
||||||
|
|
||||||
// Give some feedback
|
// Give some feedback
|
||||||
_menu.playAcceptSound(player);
|
_menu.playAcceptSound(player);
|
||||||
player.sendMessage(F.main(_plugin.getName(), "You claimed rewards for level " + F.elem(_level) + ":"));
|
|
||||||
_rewards.forEach(reward -> player.sendMessage(F.main(_plugin.getName(), reward.getDescription())));
|
|
||||||
|
|
||||||
// Rebuild the menu
|
// Rebuild the menu
|
||||||
_menu.refresh();
|
_menu.refresh();
|
||||||
|
@ -101,7 +101,7 @@ public class LevelRewardMainPage extends ShopPageBase<LevelingManager, LevelRewa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addButton(slot, _plugin.getLevelItem(_player, rewards, level), new LevelRewardButton(this, rewards, level));
|
addButton(slot, _plugin.getLevelItem(_player, rewards, level), new LevelRewardButton(this, level));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreviousLevel(int level)
|
private int getPreviousLevel(int level)
|
||||||
|
@ -56,7 +56,7 @@ public class LevelRewardViewAllPage extends ShopPageBase<LevelingManager, LevelR
|
|||||||
List<LevelReward> rewards = entry.getValue();
|
List<LevelReward> rewards = entry.getValue();
|
||||||
ItemStack itemStack = _plugin.getLevelItem(_player, rewards, level);
|
ItemStack itemStack = _plugin.getLevelItem(_player, rewards, level);
|
||||||
|
|
||||||
addButton(slot, itemStack, new LevelRewardButton(this, rewards, level));
|
addButton(slot, itemStack, new LevelRewardButton(this, level));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ public class TreasureLocation implements Listener
|
|||||||
|
|
||||||
public boolean openChest(Player player, Treasure treasure)
|
public boolean openChest(Player player, Treasure treasure)
|
||||||
{
|
{
|
||||||
if (!Recharge.Instance.use(player, "Open Chest", 1000, false, false))
|
if (!Recharge.Instance.use(player, "Open Chest", 10000, false, false))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -181,26 +181,29 @@ public class TreasureLocation implements Listener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreasureSession session = new TreasureSession(player, this, treasure);
|
||||||
|
|
||||||
|
if (session.hasFailed())
|
||||||
|
{
|
||||||
|
player.sendMessage(F.main(getManager().getName(), "Sorry, it looks like the rewards for the chest could not be generated."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
getManager().getInventoryManager().addItemToInventory(success ->
|
getManager().getInventoryManager().addItemToInventory(success ->
|
||||||
{
|
{
|
||||||
if (!success)
|
// Need to check if it's inUse again since this is called in the future
|
||||||
|
if (!success || inUse())
|
||||||
{
|
{
|
||||||
player.sendMessage(F.main(getManager().getName(), "It looks like something went wrong when processing your request. Please try again."));
|
player.sendMessage(F.main(getManager().getName(), "It looks like something went wrong when processing your request. Please try again."));
|
||||||
|
// Using the variation of addItemToInventory with a callback so our request is processed ASAP
|
||||||
|
getManager().getInventoryManager().addItemToInventory(null, player, treasure.getTreasureType().getItemName(), 1);
|
||||||
|
session.cleanup(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_session = new TreasureSession(player, this, treasure);
|
_session = session;
|
||||||
|
|
||||||
if (_session.hasFailed())
|
UtilServer.CallEvent(new TreasureStartEvent(player, _session));
|
||||||
{
|
|
||||||
getManager().getInventoryManager().addItemToInventory(player, treasure.getTreasureType().getItemName(), 1);
|
|
||||||
_session = null;
|
|
||||||
player.sendMessage(F.main(getManager().getName(), "Sorry, it looks like the rewards for the chest could not be generated."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TreasureStartEvent startEvent = new TreasureStartEvent(player, _session);
|
|
||||||
UtilServer.CallEvent(startEvent);
|
|
||||||
|
|
||||||
player.eject();
|
player.eject();
|
||||||
player.leaveVehicle();
|
player.leaveVehicle();
|
||||||
|
@ -143,7 +143,7 @@ public class TreasureManager extends MiniPlugin
|
|||||||
|
|
||||||
public void giveTreasure(Player player, Treasure treasure, int amount)
|
public void giveTreasure(Player player, Treasure treasure, int amount)
|
||||||
{
|
{
|
||||||
_inventoryManager.addItemToInventory(player, treasure.getTreasureType().getItemName(), amount);
|
_inventoryManager.addItemToInventory(null, player, treasure.getTreasureType().getItemName(), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -134,7 +135,7 @@ public class TreasureSession implements Listener
|
|||||||
|
|
||||||
if (isDone())
|
if (isDone())
|
||||||
{
|
{
|
||||||
UtilServer.runSyncLater(this::cleanup, 5 * 20);
|
UtilServer.runSyncLater(() -> cleanup(true), 5 * 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,15 +147,19 @@ public class TreasureSession implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup();
|
cleanup(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup()
|
public void cleanup(boolean cleanLocation)
|
||||||
{
|
{
|
||||||
UtilServer.Unregister(this);
|
UtilServer.Unregister(this);
|
||||||
_animation.cleanup();
|
_animation.cleanup();
|
||||||
_rewardAnimations.forEach(TreasureRewardAnimation::cleanup);
|
_rewardAnimations.forEach(TreasureRewardAnimation::cleanup);
|
||||||
_treasureLocation.cleanup();
|
|
||||||
|
if (cleanLocation)
|
||||||
|
{
|
||||||
|
_treasureLocation.cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -190,7 +195,7 @@ public class TreasureSession implements Listener
|
|||||||
{
|
{
|
||||||
for (LivingEntity entity : UtilEnt.getInRadius(_treasureLocation.getChest(), CHEST_RADIUS).keySet())
|
for (LivingEntity entity : UtilEnt.getInRadius(_treasureLocation.getChest(), CHEST_RADIUS).keySet())
|
||||||
{
|
{
|
||||||
if (entity.equals(_player) || UtilEnt.hasFlag(entity, UtilEnt.FLAG_ENTITY_COMPONENT))
|
if (entity.equals(_player) || entity instanceof ArmorStand || _animation.getEntities().contains(entity))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -230,7 +235,7 @@ public class TreasureSession implements Listener
|
|||||||
getPlayer().sendMessage(F.main(_treasureLocation.getManager().getName(), rewardData.getHeader() + " : " + rewardData.getFriendlyName()));
|
getPlayer().sendMessage(F.main(_treasureLocation.getManager().getName(), rewardData.getHeader() + " : " + rewardData.getFriendlyName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup();
|
cleanup(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer()
|
public Player getPlayer()
|
||||||
|
@ -163,6 +163,11 @@ public abstract class TreasureAnimation implements Runnable
|
|||||||
return _tick;
|
return _tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<LivingEntity> getEntities()
|
||||||
|
{
|
||||||
|
return _entities;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRunning()
|
public boolean isRunning()
|
||||||
{
|
{
|
||||||
return _running;
|
return _running;
|
||||||
|
@ -45,6 +45,7 @@ import mineplex.core.packethandler.PacketHandler;
|
|||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.hub.HubManager;
|
import mineplex.hub.HubManager;
|
||||||
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A World Manager class that handles all world related events.
|
* A World Manager class that handles all world related events.
|
||||||
@ -165,27 +166,25 @@ public class HubWorldManager extends MiniPlugin
|
|||||||
* Prevent entities taking damage
|
* Prevent entities taking damage
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void entityDamage(EntityDamageEvent event)
|
public void entityDamage(CustomDamageEvent event)
|
||||||
{
|
{
|
||||||
if (event.getCause() == DamageCause.VOID)
|
if (event.GetCause() == DamageCause.VOID)
|
||||||
{
|
{
|
||||||
if (event.getEntity() instanceof Player)
|
Entity entity = event.GetDamageeEntity();
|
||||||
|
|
||||||
|
if (entity instanceof Player)
|
||||||
{
|
{
|
||||||
event.getEntity().eject();
|
entity.eject();
|
||||||
event.getEntity().leaveVehicle();
|
entity.leaveVehicle();
|
||||||
event.getEntity().teleport(_manager.GetSpawn());
|
entity.teleport(_manager.GetSpawn());
|
||||||
}
|
}
|
||||||
else if (!UtilEnt.hasFlag(event.getEntity(), UtilEnt.FLAG_NO_REMOVE))
|
else if (!UtilEnt.hasFlag(entity, UtilEnt.FLAG_NO_REMOVE))
|
||||||
{
|
{
|
||||||
event.getEntity().remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.getCause() == DamageCause.SUFFOCATION)
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.SetCancelled("Hub World");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user