Place barrier blocks within the shop npc hitboxes
This commit is contained in:
parent
c74a754a91
commit
c478c8f413
@ -5,28 +5,31 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.MapUtil;
|
||||||
import mineplex.core.common.util.UtilAlg;
|
import mineplex.core.common.util.UtilAlg;
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.core.newnpc.NPC;
|
import mineplex.core.newnpc.NPC;
|
||||||
import mineplex.core.newnpc.NewNPCManager;
|
import mineplex.core.newnpc.NewNPCManager;
|
||||||
import mineplex.core.newnpc.event.NPCInteractEvent;
|
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
@ -181,6 +184,9 @@ public class CakeShopModule extends CakeModule
|
|||||||
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory2d(location, cakeTeam.getShop())));
|
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory2d(location, cakeTeam.getShop())));
|
||||||
NPC npc = new NPC(-1, EntityType.VILLAGER, resource.getChatColor() + C.Bold + resource.getName() + " Shop", location, null, (byte) 0, null, null, null, null, "CAKE_NPC");
|
NPC npc = new NPC(-1, EntityType.VILLAGER, resource.getChatColor() + C.Bold + resource.getName() + " Shop", location, null, (byte) 0, null, null, null, null, "CAKE_NPC");
|
||||||
|
|
||||||
|
MapUtil.QuickChangeBlockAt(location, Material.BARRIER);
|
||||||
|
MapUtil.QuickChangeBlockAt(location.clone().add(0, 1, 0), Material.BARRIER);
|
||||||
|
|
||||||
_manager.addNPC(npc, false);
|
_manager.addNPC(npc, false);
|
||||||
_npcs.put(npc, resource);
|
_npcs.put(npc, resource);
|
||||||
}
|
}
|
||||||
@ -194,24 +200,33 @@ public class CakeShopModule extends CakeModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void npcInteract(NPCInteractEvent event)
|
public void npcInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if (!_game.IsLive())
|
if (!_game.IsLive())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NPC npc = event.getNpc();
|
Block block = event.getClickedBlock();
|
||||||
CakeResource resource = _npcs.get(npc);
|
|
||||||
|
|
||||||
if (resource == null)
|
if (block == null || block.getType() != Material.BARRIER)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
Location location = block.getLocation();
|
||||||
|
|
||||||
|
for (Entry<NPC, CakeResource> entry : _npcs.entrySet())
|
||||||
|
{
|
||||||
|
if (UtilMath.offset2dSquared(entry.getKey().getEntity().getLocation(), location) > 1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
CakeResource resource = entry.getValue();
|
||||||
|
|
||||||
if (UtilPlayer.isSpectator(player) || !Recharge.Instance.use(player, "Interact Shop", 500, false, false))
|
if (UtilPlayer.isSpectator(player) || !Recharge.Instance.use(player, "Interact Shop", 500, false, false))
|
||||||
{
|
{
|
||||||
@ -231,6 +246,8 @@ public class CakeShopModule extends CakeModule
|
|||||||
|
|
||||||
page.refresh();
|
page.refresh();
|
||||||
_shop.openPageForPlayer(player, page);
|
_shop.openPageForPlayer(player, page);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
Loading…
Reference in New Issue
Block a user