use of org.bukkit.material.Crops in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onPlayerInteract.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent e) {
RedProtect.get().logger.debug("RPGlobalListener - Is PlayerInteractEvent event! Cancelled? " + e.isCancelled());
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Block b = e.getClickedBlock();
ItemStack itemInHand = e.getItem();
Location l = null;
if (b != null) {
l = b.getLocation();
RedProtect.get().logger.debug("RPGlobalListener - Is PlayerInteractEvent event. The block is " + b.getType().name());
} else {
l = p.getLocation();
}
if (b != null && b.getState() instanceof Sign) {
Sign s = (Sign) b.getState();
if (ChatColor.stripColor(s.getLine(1)).equals(ChatColor.stripColor(RPLang.get("_redprotect.prefix")))) {
b.setType(Material.AIR);
e.setUseInteractedBlock(Result.DENY);
e.setUseItemInHand(Result.DENY);
e.setCancelled(true);
return;
}
}
Region r = RedProtect.get().rm.getTopRegion(l);
// deny item usage
List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName() + ".deny-item-usage.items");
if (e.getItem() != null && items.contains(e.getItem().getType().name())) {
if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) || (RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setUseInteractedBlock(Event.Result.DENY);
e.setUseItemInHand(Event.Result.DENY);
e.setCancelled(true);
return;
}
if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")) {
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setUseInteractedBlock(Event.Result.DENY);
e.setUseItemInHand(Event.Result.DENY);
e.setCancelled(true);
return;
}
}
if (b == null || r != null) {
return;
}
if ((b instanceof Crops || b.getType().equals(Material.PUMPKIN_STEM) || b.getType().equals(Material.MELON_STEM) || b.getType().toString().contains("CROPS") || b.getType().toString().contains("SOIL") || b.getType().toString().contains("CHORUS_") || b.getType().toString().contains("BEETROOT_") || b.getType().toString().contains("SUGAR_CANE")) && !RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".allow-crops-trample") && !p.hasPermission("redprotect.bypass.world")) {
e.setCancelled(true);
return;
}
if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
if ((!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(b.getType().name()) || !RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-blocks").contains(b.getType().name())) && !bypassBuild(p, null, 0)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
e.setCancelled(true);
return;
}
}
if (itemInHand != null) {
if (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART")) {
if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
e.setUseItemInHand(Event.Result.DENY);
e.setCancelled(true);
return;
}
}
if (itemInHand.getType().equals(Material.PAINTING) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().equals(Material.ARMOR_STAND)) {
if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.place-blocks").contains(itemInHand.getType().name()) && !bypassBuild(p, null, 0)) {
e.setUseItemInHand(Event.Result.DENY);
e.setCancelled(true);
return;
}
}
}
if (!RPConfig.getGlobalFlagBool(p.getWorld().getName() + ".interact") && !p.hasPermission("redprotect.bypass.world")) {
if (RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-interact-false.allow-blocks").contains(b.getType().name())) {
return;
}
e.setUseItemInHand(Event.Result.DENY);
e.setCancelled(true);
}
}
use of org.bukkit.material.Crops in project RedProtect by FabioZumbi12.
the class RPBlockListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
RedProtect.get().logger.debug("BlockListener - Is PlayerInteractEvent event! Cancelled? " + e.isCancelled());
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
Location l = e.getClickedBlock().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
Block b = p.getLocation().getBlock();
if (r != null && (b instanceof Crops || b.getType().equals(Material.PUMPKIN_STEM) || b.getType().equals(Material.MELON_STEM) || b.getType().toString().contains("CROPS") || b.getType().toString().contains("SOIL") || b.getType().toString().contains("CHORUS_") || b.getType().toString().contains("BEETROOT_") || b.getType().toString().contains("SUGAR_CANE")) && !r.canCrops(b) && !r.canBuild(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
return;
}
try {
for (Block block : p.getLineOfSight(null, 8)) {
if (block == null) {
continue;
}
if (r != null && block.getType().equals(Material.FIRE) && !r.canBuild(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
return;
}
}
} catch (Exception ignored) {
}
}
use of org.bukkit.material.Crops in project modules-extra by CubeEngine.
the class ListenerPlayerBlockInteract method onPlayerInteract.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
// TODO put item into itemframe
if (event.getAction() == RIGHT_CLICK_BLOCK) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
Location location = event.getClickedBlock().getLocation();
BlockState state = event.getClickedBlock().getState();
ActionPlayerBlock action;
BlockState newState = state.getBlock().getState();
if (state instanceof InventoryHolder) {
action = this.newAction(UseContainer.class, state.getWorld());
} else if (state.getData() instanceof Openable) {
action = this.newAction(UseDoor.class, state.getWorld());
if (action != null) {
state = adjustBlockForDoubleBlocks(state);
Openable openable = (Openable) state.getBlock().getState().getData();
openable.setOpen(!openable.isOpen());
newState.setData((MaterialData) openable);
}
} else if (state.getData() instanceof Lever) {
action = this.newAction(UseLever.class, state.getWorld());
if (action != null) {
Lever leverData = (Lever) state.getBlock().getState().getData();
leverData.setPowered(!leverData.isPowered());
newState.setData(leverData);
}
} else if (state.getType() == REDSTONE_COMPARATOR_ON || state.getType() == REDSTONE_COMPARATOR_OFF) {
action = this.newAction(UseComparator.class, state.getWorld());
if (action != null) {
newState.setType(state.getType() == REDSTONE_COMPARATOR_ON ? REDSTONE_COMPARATOR_OFF : REDSTONE_COMPARATOR_ON);
}
} else if (state.getData() instanceof Button) {
action = this.newAction(UseButton.class, state.getWorld());
if (action != null) {
Button button = (Button) state.getBlock().getState().getData();
button.setPowered(true);
newState.setData(button);
}
} else if (state.getData() instanceof Rails) {
if (itemInHand.getType() == MINECART || itemInHand.getType() == STORAGE_MINECART || itemInHand.getType() == POWERED_MINECART || itemInHand.getType() == HOPPER_MINECART || // BOAT is done down below
itemInHand.getType() == EXPLOSIVE_MINECART) {
VehiclePrePlaceEvent vEvent = new VehiclePrePlaceEvent(event.getClickedBlock().getRelative(UP).getLocation(), event.getPlayer());
this.module.getCore().getEventManager().fireEvent(vEvent);
}
action = null;
} else if (itemInHand.getType().equals(BOAT)) {
VehiclePrePlaceEvent vEvent = new VehiclePrePlaceEvent(event.getClickedBlock().getRelative(UP).getLocation(), event.getPlayer());
this.module.getCore().getEventManager().fireEvent(vEvent);
action = null;
} else if (state.getData() instanceof Cake) {
action = null;
if (event.getPlayer().getFoodLevel() < 20 && !(event.getPlayer().getGameMode() == CREATIVE)) {
action = this.newAction(UseCake.class, state.getWorld());
if (action != null) {
Cake cake = (Cake) state.getBlock().getState().getData();
cake.setSlicesEaten(cake.getSlicesEaten() + 1);
if (cake.getSlicesRemaining() == 0) {
action.setNewBlock(AIR);
newState = null;
} else {
newState.setData(cake);
}
}
}
} else if (state instanceof NoteBlock) {
action = this.newAction(UseNoteblock.class, state.getWorld());
if (action != null) {
try {
((NoteBlock) newState).setNote(((NoteBlock) newState).getNote().sharped());
} catch (IllegalArgumentException e) {
((NoteBlock) newState).setNote(new Note(1, Tone.F, true));
}
}
} else if (state.getData() instanceof Diode) {
action = this.newAction(UseRepeater.class, state.getWorld());
if (action != null) {
Diode diode = (Diode) state.getBlock().getState().getData();
Integer delay = diode.getDelay() + 1;
if (delay == 5) {
delay = 1;
}
diode.setDelay(delay);
newState.setData(diode);
}
} else if (state.getType() == TNT) {
action = null;
if (itemInHand.getType() == FLINT_AND_STEEL) {
action = this.newAction(UseTnt.class, state.getWorld());
if (action != null) {
action.setNewBlock(AIR);
newState = null;
}
}
} else if (state.getData() instanceof Crops || state.getType() == GRASS) {
if (itemInHand.getData() instanceof Dye && ((Dye) itemInHand.getData()).getColor() == WHITE) {
// TODO THIS IS BULLSHIT I need an event for bonemealUse...
action = this.newAction(UseBonemeal.class, state.getWorld());
if (action != null) {
// TODO adjust growth stage
// TODO do not log if fully grown
action.setNewBlock(state);
action.setLocation(state.getLocation());
action.setOldBlock(state);
action.setPlayer(event.getPlayer());
this.logAction(action);
}
}
return;
} else if (state instanceof Jukebox) {
// TODO
action = null;
} else {
action = null;
}
if (action != null) {
action.setLocation(state.getLocation());
action.setOldBlock(state);
if (newState != null) {
action.setNewBlock(newState);
}
action.setPlayer(event.getPlayer());
this.logAction(action);
}
} else if (event.getAction() == PHYSICAL) {
Block block = event.getClickedBlock();
if (block.getType() == SOIL) {
BlockTrample action = this.newAction(BlockTrample.class, block.getWorld());
if (action != null) {
BlockState stateUp = block.getRelative(UP).getState();
if (stateUp.getData() instanceof Crops) {
BlockTrample actionUp = this.newAction(BlockTrample.class, block.getWorld());
actionUp.setLocation(stateUp.getLocation());
actionUp.setOldBlock(stateUp);
actionUp.setNewBlock(AIR);
actionUp.setPlayer(event.getPlayer());
this.logAction(actionUp);
}
action.setLocation(block.getLocation());
action.setOldBlock(block.getState());
action.setNewBlock(DIRT);
action.setPlayer(event.getPlayer());
this.logAction(action);
}
} else if (block.getState().getData() instanceof PressurePlate) {
UsePlate action = this.newAction(UsePlate.class, block.getWorld());
if (action != null) {
// BlockState newState = block.getState();
// PressurePlate plate = (PressurePlate)newState.getData();
action.setLocation(block.getLocation());
action.setOldBlock(block.getState());
action.setNewBlock(block.getState());
action.setPlayer(event.getPlayer());
this.logAction(action);
}
}
}
}
Aggregations