use of com.minecolonies.coremod.network.messages.client.OpenSuggestionWindowMessage in project minecolonies by Minecolonies.
the class EventHandler method onPlayerInteract.
/**
* Event when a player right clicks a block, or right clicks with an item. Event gets cancelled when player has no permission. Event gets cancelled when the player has no
* permission to place a hut, and tried it.
*
* @param event {@link PlayerInteractEvent.RightClickBlock}
*/
@SubscribeEvent
public static void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
final PlayerEntity player = event.getPlayer();
final World world = event.getWorld();
BlockPos bedBlockPos = event.getPos();
// and uses that return value, but I didn't want to call it twice
if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
}
return;
} else if ("pmardle".equalsIgnoreCase(event.getPlayer().getName().getString()) && Block.byItem(event.getItemStack().getItem()) instanceof SilverfishBlock) {
LanguageHandler.sendPlayerMessage(event.getPlayer(), "Stop that you twat!!!");
event.setCanceled(true);
}
if (world.getBlockState(event.getPos()).getBlock().isBed(world.getBlockState(event.getPos()), world, event.getPos(), player)) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, bedBlockPos);
// Checks to see if player tries to sleep in a bed belonging to a Citizen, ancels the event, and Notifies Player that bed is occuppied
if (colony != null && world.getBlockState(event.getPos()).hasProperty(BedBlock.PART)) {
final List<ICitizenData> citizenList = colony.getCitizenManager().getCitizens();
final BlockState potentialBed = world.getBlockState(event.getPos());
if (potentialBed.getBlock() instanceof BedBlock && potentialBed.getValue(BedBlock.PART) == BedPart.FOOT) {
bedBlockPos = bedBlockPos.relative(world.getBlockState(event.getPos()).getValue(BedBlock.FACING));
}
for (final ICitizenData citizen : citizenList) {
if (citizen.getBedPos().equals(bedBlockPos) && citizen.isAsleep()) {
event.setCanceled(true);
LanguageHandler.sendPlayerMessage(player, "block.minecraft.bed.occupied");
}
}
}
}
handleEventCancellation(event, player);
if (!event.isCanceled() && event.getEntity() instanceof PlayerEntity && event.getItemStack().getItem() instanceof BlockItem) {
final Block block = ((BlockItem) event.getItemStack().getItem()).getBlock().getBlock();
if (block instanceof AbstractBlockHut && !(block instanceof IRSComponentBlock)) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
return;
}
if (MineColonies.getConfig().getServer().suggestBuildToolPlacement.get() && !(player.isCreative() && player.isShiftKeyDown())) {
final ItemStack stack = event.getItemStack();
if (!stack.isEmpty() && !world.isClientSide) {
Network.getNetwork().sendToPlayer(new OpenSuggestionWindowMessage(block.defaultBlockState().setValue(AbstractBlockHut.FACING, event.getPlayer().getDirection()), event.getPos().relative(event.getFace()), stack), (ServerPlayerEntity) player);
}
event.setCanceled(true);
}
return;
}
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.buildTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
final IColonyView view = IColonyManager.getInstance().getClosestColonyView(event.getWorld(), event.getPos().relative(event.getFace()));
if (view != null && Settings.instance.getStyle().isEmpty()) {
Settings.instance.setStyle(view.getStyle());
}
MineColonies.proxy.openBuildToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.shapeTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
MineColonies.proxy.openShapeToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
}
use of com.minecolonies.coremod.network.messages.client.OpenSuggestionWindowMessage in project minecolonies by ldtteam.
the class EventHandler method onPlayerInteract.
/**
* Event when a player right clicks a block, or right clicks with an item. Event gets cancelled when player has no permission. Event gets cancelled when the player has no
* permission to place a hut, and tried it.
*
* @param event {@link PlayerInteractEvent.RightClickBlock}
*/
@SubscribeEvent
public static void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
final PlayerEntity player = event.getPlayer();
final World world = event.getWorld();
BlockPos bedBlockPos = event.getPos();
// and uses that return value, but I didn't want to call it twice
if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
}
return;
} else if ("pmardle".equalsIgnoreCase(event.getPlayer().getName().getString()) && Block.byItem(event.getItemStack().getItem()) instanceof SilverfishBlock) {
LanguageHandler.sendPlayerMessage(event.getPlayer(), "Stop that you twat!!!");
event.setCanceled(true);
}
if (world.getBlockState(event.getPos()).getBlock().isBed(world.getBlockState(event.getPos()), world, event.getPos(), player)) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, bedBlockPos);
// Checks to see if player tries to sleep in a bed belonging to a Citizen, ancels the event, and Notifies Player that bed is occuppied
if (colony != null && world.getBlockState(event.getPos()).hasProperty(BedBlock.PART)) {
final List<ICitizenData> citizenList = colony.getCitizenManager().getCitizens();
final BlockState potentialBed = world.getBlockState(event.getPos());
if (potentialBed.getBlock() instanceof BedBlock && potentialBed.getValue(BedBlock.PART) == BedPart.FOOT) {
bedBlockPos = bedBlockPos.relative(world.getBlockState(event.getPos()).getValue(BedBlock.FACING));
}
for (final ICitizenData citizen : citizenList) {
if (citizen.getBedPos().equals(bedBlockPos) && citizen.isAsleep()) {
event.setCanceled(true);
LanguageHandler.sendPlayerMessage(player, "block.minecraft.bed.occupied");
}
}
}
}
handleEventCancellation(event, player);
if (!event.isCanceled() && event.getEntity() instanceof PlayerEntity && event.getItemStack().getItem() instanceof BlockItem) {
final Block block = ((BlockItem) event.getItemStack().getItem()).getBlock().getBlock();
if (block instanceof AbstractBlockHut && !(block instanceof IRSComponentBlock)) {
final IColony colony = IColonyManager.getInstance().getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
return;
}
if (MineColonies.getConfig().getServer().suggestBuildToolPlacement.get() && !(player.isCreative() && player.isShiftKeyDown())) {
final ItemStack stack = event.getItemStack();
if (!stack.isEmpty() && !world.isClientSide) {
Network.getNetwork().sendToPlayer(new OpenSuggestionWindowMessage(block.defaultBlockState().setValue(AbstractBlockHut.FACING, event.getPlayer().getDirection()), event.getPos().relative(event.getFace()), stack), (ServerPlayerEntity) player);
}
event.setCanceled(true);
}
return;
}
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.buildTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
final IColonyView view = IColonyManager.getInstance().getClosestColonyView(event.getWorld(), event.getPos().relative(event.getFace()));
if (view != null && Settings.instance.getStyle().isEmpty()) {
Settings.instance.setStyle(view.getStyle());
}
MineColonies.proxy.openBuildToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
if (!event.isCanceled() && event.getItemStack().getItem() == ModItems.shapeTool.get()) {
if (event.getWorld().isClientSide()) {
if (event.getUseBlock() == Event.Result.DEFAULT && event.getFace() != null) {
MineColonies.proxy.openShapeToolWindow(event.getPos().relative(event.getFace()));
}
}
event.setCanceled(true);
}
}
Aggregations