use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreakByEntity.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
Entity causer;
if (event.getRemover() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getRemover();
}
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
if (causer instanceof Player) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
if (action != null) {
((PaintingBreak) action).art = ((Painting) hanging).getArt();
}
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.setPlayer((Player) causer);
this.logAction(action);
}
} else {
// TODO
}
}
use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.
the class ListenerHanging method onItemRemove.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemRemove(EntityDamageByEntityEvent event) {
Entity frame = event.getEntity();
if (frame instanceof ItemFrame) {
Entity causer;
if (event.getDamager() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getDamager();
}
if (causer instanceof Player) {
ItemFrameItemRemove action = this.newAction(ItemFrameItemRemove.class, frame.getWorld());
if (action != null) {
action.setLocation(frame.getLocation());
action.setHanging(frame);
action.setPlayer((Player) causer);
action.item = ((ItemFrame) frame).getItem();
this.logAction(action);
}
} else {
// TODO
}
}
}
use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.
the class ListenerContainerItem method onInventoryClick.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
// TODO major refactoring needed
if (event.getSlot() == -999) {
return;
}
if (event.getWhoClicked() instanceof Player) {
Player player = (Player) event.getWhoClicked();
if (!this.inventoryChanges.containsKey(player.getUniqueId())) {
return;
}
Inventory inventory = event.getInventory();
InventoryHolder holder = inventory.getHolder();
org.spongepowered.api.item.inventory.ItemStack inventoryItem = event.getCurrentItem();
ItemStack cursorItem = event.getCursor();
if ((inventoryItem == null || inventoryItem.getType() == AIR) && (cursorItem == null || cursorItem.getType() == AIR)) {
// nothing to log
return;
}
if (// click in top inventory
event.getRawSlot() < event.getView().getTopInventory().getSize()) {
if (// top & shift -> remove items
event.isShiftClick()) {
if (inventoryItem == null || inventoryItem.getType() == AIR) {
return;
}
int missingSpace = getMissingSpace(event.getView().getTopInventory(), inventoryItem);
int amountTake = inventoryitem.getQuantity() - missingSpace;
if (amountTake > 0) {
this.prepareForLogging(player, new ItemData(inventoryItem), -amountTake);
}
} else {
if (// remove items
cursorItem == null || cursorItem.getType() == AIR) {
int remove = event.isLeftClick() ? inventoryitem.getQuantity() : (inventoryitem.getQuantity() + 1) / 2;
this.prepareForLogging(player, new ItemData(inventoryItem), -remove);
} else if (// put items
inventoryItem == null || inventoryItem.getType() == AIR) {
int put = event.isLeftClick() ? cursoritem.getQuantity() : 1;
if (// handle BrewingStands separatly
holder instanceof BrewingStand) {
if (event.getRawSlot() == 3) {
if (// can be put
!BukkitUtils.canBePlacedInBrewingstand(cursorItem)) {
return;
}
} else if (cursorItem.getType() == POTION || // bottle slot
cursorItem.getType() == GLASS_BOTTLE) {
put = 1;
} else {
return;
}
}
this.prepareForLogging(player, new ItemData(cursorItem), put);
} else {
if (inventoryItem.isSimilar(cursorItem)) {
int put = event.isLeftClick() ? inventoryitem.getQuantity() : 1;
if (// if stack to big
put > inventoryItem.getMaxStackSize() - inventoryitem.getQuantity()) {
put = inventoryItem.getMaxStackSize() - // set to missing to fill
inventoryitem.getQuantity();
}
if (put == 0) {
return;
}
this.prepareForLogging(player, new ItemData(inventoryItem), put);
} else {
if (// handle BrewingStands separatly
holder instanceof BrewingStand) {
if (event.getRawSlot() == 3) {
if (// can be put
!BukkitUtils.canBePlacedInBrewingstand(cursorItem)) {
return;
}
} else if (cursorItem.getType() == POTION || // bottle slot
cursorItem.getType() == GLASS_BOTTLE) {
if (cursoritem.getQuantity() > 1) {
// nothing happens when more than 1
return;
}
// else swap items
} else {
return;
}
}
this.prepareForLogging(player, new ItemData(cursorItem), cursoritem.getQuantity());
this.prepareForLogging(player, new ItemData(inventoryItem), -inventoryitem.getQuantity());
}
}
}
} else if (// click in bottom inventory AND shift -> put | ELSE no container change
event.isShiftClick()) {
if (inventoryItem == null || inventoryItem.getType() == AIR) {
return;
}
if (holder instanceof BrewingStand) {
BrewerInventory brewerInventory = (BrewerInventory) event.getView().getTopInventory();
if (BukkitUtils.canBePlacedInBrewingstand(inventoryItem)) {
if (// could fit into inventory
inventoryItem.isSimilar(brewerInventory.getIngredient())) {
ItemStack brewerItem = brewerInventory.getIngredient();
int amountPutIn = inventoryitem.getQuantity();
if (breweritem.getQuantity() + inventoryitem.getQuantity() > inventoryItem.getMaxStackSize()) {
amountPutIn = inventoryItem.getMaxStackSize() - breweritem.getQuantity();
if (amountPutIn <= 0) {
return;
}
}
this.prepareForLogging(player, new ItemData(inventoryItem), amountPutIn);
}
} else if (inventoryItem.getType() == POTION) {
for (int i = 0; i <= 2; ++i) {
ItemStack item = brewerInventory.getItem(i);
if (// space for a potion?
item == null) {
this.prepareForLogging(player, new ItemData(inventoryItem), inventoryitem.getQuantity());
return;
}
// else no space found
}
} else if (inventoryItem.getType() == GLASS_BOTTLE) {
int bottlesFound = 0;
int bottleSlots = 0;
for (int i = 0; i <= 2; ++i) {
ItemStack item = brewerInventory.getItem(i);
if (// space for the stack ?
item == null) {
this.prepareForLogging(player, new ItemData(inventoryItem), inventoryitem.getQuantity());
return;
} else if (item.getType() == GLASS_BOTTLE) {
bottleSlots++;
bottlesFound += item.getQuantity();
}
}
if (bottleSlots > 0) {
int space = GLASS_BOTTLE.getMaxStackSize() * bottleSlots - bottlesFound;
if (space <= 0) {
return;
}
int putInto = inventoryitem.getQuantity();
if (putInto > space) {
putInto = space;
}
this.prepareForLogging(player, new ItemData(inventoryItem), putInto);
}
}
} else if (holder instanceof Furnace) {
FurnaceInventory furnaceInventory = (FurnaceInventory) event.getView().getTopInventory();
int putInto = 0;
if (BukkitUtils.isSmeltable(inventoryItem)) {
ItemStack item = furnaceInventory.getSmelting();
if (item == null) {
putInto = inventoryitem.getQuantity();
} else if (inventoryItem.isSimilar(item)) {
int space = inventoryItem.getMaxStackSize() - item.getQuantity();
if (space <= 0) {
return;
}
putInto = inventoryitem.getQuantity();
if (putInto > space) {
putInto = space;
}
}
} else if (inventoryItem.getItem().getDefaultProperty(BurningFuelProperty.class).isPresent()) {
ItemStack item = furnaceInventory.getFuel();
if (item == null) {
putInto = inventoryitem.getQuantity();
} else if (inventoryItem.isSimilar(item)) {
int space = inventoryItem.getMaxStackSize() - item.getQuantity();
if (space <= 0) {
return;
}
putInto = inventoryitem.getQuantity();
if (putInto > space) {
putInto = space;
}
}
}
if (putInto == 0) {
return;
}
this.prepareForLogging(player, new ItemData(inventoryItem), putInto);
} else {
event.getView().getTopInventory().getContents();
int missingSpace = getMissingSpace(event.getView().getTopInventory(), inventoryItem);
int amountPut = inventoryitem.getQuantity() - missingSpace;
if (amountPut > 0) {
this.prepareForLogging(player, new ItemData(inventoryItem), amountPut);
}
}
}
}
}
use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.
the class ListenerPlayerEntity method onPlayerInteractEntityEvent.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
if (!(event.getRightClicked() instanceof LivingEntity)) {
return;
}
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
ActionPlayerEntity action;
if (player.getItemInHand().getType() == COAL && entity instanceof PoweredMinecart) {
action = this.newAction(UseFurnaceMinecart.class, entity.getWorld());
} else if (player.getItemInHand().getType() == INK_SACK && entity instanceof Sheep || entity instanceof Wolf) {
action = this.newAction(EntityDye.class, entity.getWorld());
if (action != null) {
((EntityDye) action).setColor(((Dye) player.getItemInHand().getData()).getColor());
}
} else if (player.getItemInHand().getType().equals(BOWL) && entity instanceof MushroomCow) {
action = this.newAction(EntityFillSoup.class, entity.getWorld());
} else {
return;
}
if (action != null) {
action.setEntity(entity);
action.setPlayer(player);
action.setLocation(entity.getLocation());
this.logAction(action);
}
}
use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.
the class ListenerVehicle method onVehicleDestroy.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent event) {
Entity causer;
if (event.getAttacker() != null) {
if (event.getAttacker() instanceof Player) {
causer = event.getAttacker();
} else if (event.getAttacker() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getAttacker()).getShooter();
if (shooter instanceof Player) {
causer = (Player) shooter;
} else if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getAttacker();
}
} else if (event.getVehicle().getPassenger() instanceof Player) {
causer = event.getVehicle().getPassenger();
} else {
// TODO why?
return;
}
if (causer instanceof Player) {
VehicleBreak action = this.newAction(VehicleBreak.class, event.getVehicle().getWorld());
if (action != null) {
action.setLocation(event.getVehicle().getLocation());
action.setVehicle(event.getVehicle());
action.setPlayer((Player) causer);
this.logAction(action);
}
} else {
// TODO EntityVehicleBreak
}
}
Aggregations