本文整理汇总了Java中org.spongepowered.api.event.block.ChangeBlockEvent类的典型用法代码示例。如果您正苦于以下问题:Java ChangeBlockEvent类的具体用法?Java ChangeBlockEvent怎么用?Java ChangeBlockEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChangeBlockEvent类属于org.spongepowered.api.event.block包,在下文中一共展示了ChangeBlockEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onChangeBlockEvent
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onChangeBlockEvent(ChangeBlockEvent.Break e, @First Player player) {
if (plugin.getMainConfig().isUseSigns()) {
if (player.hasPermission("minecraftmarket.signs")) {
if (e.getTransactions().size() > 0) {
BlockSnapshot blockSnapshot = e.getTransactions().get(0).getOriginal();
Optional<Location<World>> optionalLocation = blockSnapshot.getLocation();
if (optionalLocation.isPresent()) {
if (plugin.getSignsConfig().getDonorSignFor(optionalLocation.get()) != null) {
if (plugin.getSignsConfig().removeDonorSign(optionalLocation.get())) {
player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_removed")));
plugin.getSignsTask().updateSigns();
}
}
}
}
}
}
}
示例2: onLiquidFlow
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
if (e.getLocations().isEmpty()) return;
Location<World> loc = e.getLocations().get(0);
BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
String name = "Water";
BlockType type = snapshot.getState().getType();
if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
name = "Lava";
db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
}
}
示例3: onPlayerChangeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerChangeBlock(ChangeBlockEvent.Pre event, @First Player player)
{
if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
{
return;
}
if (player.hasPermission("nations.admin.bypass.perm.build"))
{
return;
}
for (Location<World> loc : event.getLocations()) {
if (!ConfigHandler.isWhitelisted("break", loc.getBlock().getId())
&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
{
event.setCancelled(true);
try {
player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
} catch (Exception e) {}
return;
}
}
}
示例4: onPlayerPlacesBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerPlacesBlock(ChangeBlockEvent.Place event, @First Player player)
{
if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
{
return;
}
if (player.hasPermission("nations.admin.bypass.perm.build"))
{
return;
}
event
.getTransactions()
.stream()
.forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> {
if (!ConfigHandler.isWhitelisted("build", trans.getFinal().getState().getType().getId())
&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
{
trans.setValid(false);
try {
player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
} catch (Exception e) {}
}
}));
}
示例5: onPlayerBreaksBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerBreaksBlock(ChangeBlockEvent.Break event, @First Player player)
{
if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
{
return;
}
if (player.hasPermission("nations.admin.bypass.perm.build"))
{
return;
}
event
.getTransactions()
.stream()
.forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> {
if (!ConfigHandler.isWhitelisted("break", trans.getFinal().getState().getType().getId())
&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
{
trans.setValid(false);
try {
player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
} catch (Exception e) {}
}
}));
}
示例6: onFire
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order=Order.EARLY, beforeModifications = true)
public void onFire(ChangeBlockEvent event)
{
if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
{
return;
}
event
.getTransactions()
.stream()
.filter(trans -> trans.getFinal().getState().getType() == BlockTypes.FIRE)
.filter(trans -> {
Optional<Location<World>> optLoc = trans.getFinal().getLocation();
if (!optLoc.isPresent())
return false;
return !DataHandler.getFlag("fire", optLoc.get());
})
.forEach(trans -> trans.setValid(false));
}
示例7: onBreakBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event) {
java.util.Optional<Player> player = event.getCause().first(Player.class);
if (!player.isPresent()) {
return;
}
// check if the damager is a challenger
Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
if (challenger.isPresent()) {
if (player.get().getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
if (player.get().getItemInHand(HandTypes.MAIN_HAND).get().getValue(Keys.ITEM_DURABILITY).isPresent()) {
player.get().getItemInHand(HandTypes.MAIN_HAND).get().getValue(Keys.ITEM_DURABILITY).get().set(0);
}
}
}
}
示例8: onBlockBreak
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onBlockBreak(ChangeBlockEvent.Break event) {
for (Transaction<BlockSnapshot> blockSnapshotTransaction : event.getTransactions()) {
final BlockSnapshot original = blockSnapshotTransaction.getOriginal();
if (original.getState().getType() == BlockTypes.STANDING_SIGN
|| original.getState().getType() == BlockTypes.WALL_SIGN) {
if (original.getLocation().isPresent()) {
final Location3D location3D = WorldLocationConverter.of(original.getLocation().get());
// iterate all arenas of all minigames to see if sign is registered
//TODO: This is more expensive than it needs to be.
// We should maintain a global index of registered signs.
if (InfernoCore.getMinigames().values().stream()
.filter(minigame -> minigame.getArenas().stream()
.filter(arena -> arena.getLobbySignAt(location3D).isPresent()).count() > 0)
.count() > 0) {
event.setCancelled(true);
}
}
}
}
}
示例9: onChangeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onChangeBlock(ChangeBlockEvent.Place event) {
Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
if (!optPlayer.isPresent()) return;
Player player = optPlayer.get();
if (!this.players.contains(player.getUniqueId())) return;
event.setCancelled(true);
event.getTransactions().forEach(transaction -> {
player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getState().getId()));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getCreator()));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getNotifier()));
});
}
示例10: onBlockPlace
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {
BlockSnapshot snapshot = transaction.getFinal();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.block.place." + blockTypeId,
"protectionperms.block.place." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to place " + blockState.getName() + '!'));
break;
}
}
}
示例11: onBlockBreak
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {
BlockSnapshot snapshot = transaction.getOriginal();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.block.break." + blockTypeId,
"protectionperms.block.break." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to break " + blockState.getName() + '!'));
break;
}
}
}
示例12: onBlockBreak
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event) {
event.getTransactions().forEach(trans -> {
if (trans.getOriginal().getState().getType().equals(BlockTypes.CHEST)) {
Optional<Location<World>> w = trans.getOriginal().getLocation();
if (!w.isPresent()) return;
Extent tex = w.get().getExtent();
Vector3i tv3 = w.get().getBlockPosition();
for (NPCguard g : VillagerShops.npcs) {
if (g.playershopcontainer != null &&
g.playershopcontainer.getExtent().equals(tex) &&
g.playershopcontainer.getBlockPosition().equals(tv3)) {
trans.setValid(false);
}
}
}
});
}
示例13: onPreBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onPreBlockChange(final ChangeBlockEvent.Pre event, @First LocatableBlock block) {
final BlockType type = block.getBlockState().getType();
if (type.equals(BlockTypes.PISTON) || type.equals(BlockTypes.STICKY_PISTON) || type.equals(BlockTypes.PISTON_EXTENSION) || type
.equals(BlockTypes.PISTON_HEAD)) {
//noinspection OptionalGetWithoutIsPresent
final Location<World> location = block.getLocation().getBlockRelative(block.get(Keys.DIRECTION).get());
final LockManager lockManager = Latch.getLockManager();
if (lockManager.getLock(location).isPresent() || (lockManager.getLock(location.getBlockRelative(Direction.UP)).isPresent() && lockManager
.isProtectBelowBlocks(location.getBlockRelative(Direction.UP).getBlockType()))) {
event.setCancelled(true);
}
}
}
示例14: onPlaceBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onPlaceBlock(ChangeBlockEvent.Place event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().getState().getType().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
event.setCancelled(true);
}
}
}
}
示例15: onBreakBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入依赖的package包/类
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getOriginal().getState().getType().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
event.setCancelled(true);
}
}
}
}