use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.
the class InstrumentTestPlugin method onUseItem.
@Listener
public void onUseItem(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
if (!enabled || !player.get(Keys.IS_SNEAKING).get()) {
return;
}
final BlockSnapshot snapshot = event.getTargetBlock();
if (snapshot.getState().getType().equals(BlockTypes.NOTEBLOCK)) {
final InstrumentProperty instrumentProperty = player.getWorld().getBlock(snapshot.getPosition().sub(0, 1, 0)).getProperty(InstrumentProperty.class).orElse(null);
if (instrumentProperty != null) {
final InstrumentType instrument = instrumentProperty.getValue();
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block with instrument: ", TextColors.GREEN, instrument.getName()));
} else {
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block that strangely did not have any instrument type."));
}
} else {
final InstrumentProperty instrumentProperty = snapshot.getProperty(InstrumentProperty.class).orElse(null);
if (instrumentProperty != null) {
final InstrumentType instrument = instrumentProperty.getValue();
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block with instrument type: ", TextColors.GREEN, instrument.getName()));
} else {
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block which had no instrument type."));
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @First Player p) {
RedProtect.get().logger.debug("blocks", "BlockListener - Is BlockPlaceEvent event! Cancelled? " + e.isCancelled());
BlockSnapshot b = e.getTransactions().get(0).getOriginal();
Location<World> bloc = b.getLocation().get();
World w = bloc.getExtent();
ItemType m = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
m = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
m = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
Boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if (r == null && RedProtect.get().cfgs.getGlobalFlagList(w.getName(), "if-build-false", "place-blocks").contains(b.getState().getType().getName())) {
return;
}
if (r != null) {
if (!r.canMinecart(p) && m.getName().contains("minecart")) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
e.setCancelled(true);
return;
}
if (b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) {
return;
}
try {
if (!r.canBuild(p) && !r.canPlace(b)) {
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
e.setCancelled(true);
} else {
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && (m.equals(ItemTypes.HOPPER) || m.getName().contains("rail"))) {
int x = bloc.getBlockX();
int y = bloc.getBlockY();
int z = bloc.getBlockZ();
BlockSnapshot ib = w.createSnapshot(x, y + 1, z);
if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) {
RPLang.sendMessage(p, "blocklistener.container.chestinside");
e.setCancelled(true);
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockGrow.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockGrow(ChangeBlockEvent.Grow e) {
RedProtect.get().logger.debug("blocks", "RPBlockListener - Is ChangeBlockEvent.Grow event");
BlockSnapshot b = e.getTransactions().get(0).getOriginal();
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if (r != null && !r.canGrow()) {
e.setCancelled(true);
RedProtect.get().logger.debug("blocks", "Cancel grow " + b.getState().getName());
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onSignPlace.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onSignPlace(ChangeSignEvent e, @First Player p) {
RedProtect.get().logger.debug("blocks", "BlockListener - Is SignChangeEvent event! Cancelled? " + e.isCancelled());
Sign s = e.getTargetTile();
List<Text> lines = e.getText().asList();
Location<World> loc = s.getLocation();
World w = p.getWorld();
BlockSnapshot b = w.createSnapshot(loc.getBlockPosition());
if (b == null) {
this.setErrorSign(e, p, RPLang.get("blocklistener.block.null"));
return;
}
Region signr = RedProtect.get().rm.getTopRegion(loc);
if (signr != null && !signr.canSign(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
e.setCancelled(true);
return;
}
Text line1 = lines.get(0);
if (lines.size() != 4) {
this.setErrorSign(e, p, RPLang.get("blocklistener.sign.wronglines"));
return;
}
if (RedProtect.get().cfgs.getBool("server-protection.sign-spy.enabled")) {
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
if (!RedProtect.get().cfgs.getBool("server-protection.sign-spy.only-console")) {
for (Player play : Sponge.getServer().getOnlinePlayers()) {
if (RedProtect.get().ph.hasGenPerm(play, "redprotect.signspy")) /* && !play.equals(p)*/
{
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
}
}
}
}
if ((RedProtect.get().cfgs.getBool("private.use") && s.getType().equals(TileEntityTypes.SIGN)) && (line1.toPlain().equalsIgnoreCase("private") || line1.toPlain().equalsIgnoreCase("[private]") || line1.toPlain().equalsIgnoreCase(RPLang.get("blocklistener.container.signline")) || line1.toPlain().equalsIgnoreCase("[" + RPLang.get("blocklistener.container.signline") + "]"))) {
Region r = RedProtect.get().rm.getTopRegion(loc);
Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
if (out || r != null) {
if (cont.isContainer(b)) {
int length = p.getName().length();
if (length > 16) {
length = 16;
}
lines.set(1, RPUtil.toText(p.getName().substring(0, length)));
e.getText().setElements(lines);
RPLang.sendMessage(p, "blocklistener.container.protected");
return;
} else {
RPLang.sendMessage(p, "blocklistener.container.notprotected");
// w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
return;
}
} else {
RPLang.sendMessage(p, "blocklistener.container.notregion");
// w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
return;
}
}
if (line1.toPlain().equalsIgnoreCase("[rp]")) {
String claimmode = RedProtect.get().cfgs.getWorldClaimType(p.getWorld().getName());
if ((!claimmode.equalsIgnoreCase("BLOCK") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasPerm(p, "redprotect.admin.create")) {
this.setErrorSign(e, p, RPLang.get("blocklistener.region.claimmode"));
return;
}
RegionBuilder rb = new EncompassRegionBuilder(e);
if (rb.ready()) {
Region r = rb.build();
lines.set(0, RPUtil.toText(RPLang.get("blocklistener.region.signcreated")));
lines.set(1, RPUtil.toText(r.getName()));
e.getText().setElements(lines);
// RPLang.sendMessage(p, RPLang.get("blocklistener.region.created").replace("{region}", r.getName()));
RedProtect.get().rm.add(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onDecay.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onDecay(ChangeBlockEvent.Decay e, @First BlockSnapshot source) {
BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Decay event is to " + source.getState().getType().getName() + " from " + bfrom.getState().getType().getName());
Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get());
if (r != null && !r.leavesDecay() && source.getState().getType().getName().contains("leaves")) {
e.setCancelled(true);
}
}
Aggregations