本文整理汇总了Java中org.spongepowered.api.event.filter.cause.Root类的典型用法代码示例。如果您正苦于以下问题:Java Root类的具体用法?Java Root怎么用?Java Root使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Root类属于org.spongepowered.api.event.filter.cause包,在下文中一共展示了Root类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerJoin
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event, @Root Player player) {
Date now = new Date(java.util.Date.from(Instant.now()).getTime());
UserData userData = dataStore.getOrCreateUserData(player);
int index[] = new int[1];
dataStore.getPlayerRegions(player.getUniqueId()).forEach(region -> {
if (region.getType() == LoadedRegion.ChunkType.PERSONAL)
region.forceChunks();
index[0]++;
});
logger.info(String.format("Loaded %s chunks for %s", index[0], player.getName()));
// Update the userData in case it's an existing userData
dataStore.getOrCreateUserData(player).setLastSeen(now).update();
database.saveUserData(userData);
}
示例2: onPlayerLeave
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onPlayerLeave(ClientConnectionEvent.Disconnect event, @Root Player player) {
Date now = new Date(java.util.Date.from(Instant.now()).getTime());
UserData userData = dataStore.getOrCreateUserData(player);
int index[] = new int[1];
index[0] = 0;
dataStore.getPlayerRegions(player.getUniqueId()).forEach(region -> {
if (region.getType() == LoadedRegion.ChunkType.PERSONAL) {
region.unForceChunks();
index[0]++;
}
});
logger.info(String.format("Unloaded %s chunks for %s", index[0], player.getName()));
// Update the userData in case it's an existing userData
dataStore.getOrCreateUserData(player).setLastSeen(now).update();
database.saveUserData(userData);
}
示例3: onPlayerJoin
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event, @Root Player player) {
if (!player.hasPermission("iplog.bypasslogging")) {
final Storage storage = IPLog.getPlugin().getStorage();
final InetAddress ip = player.getConnection().getAddress().getAddress();
final UUID uuid = player.getUniqueId();
final LocalDateTime time = LocalDateTime.now();
if (storage.isPresent(ip, uuid)) {
storage.updateConnection(ip, uuid, time);
} else {
storage.addConnection(ip, uuid, time);
}
}
}
示例4: onMoveEntity
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onMoveEntity(MoveEntityEvent event, @Root @Has(ViewerData.class) Player player) {
Optional<String> camId = player.get(VigilateKeys.CAMERA);
if(camId.isPresent() && Vigilate.getInstance().getCameras().containsKey(camId.get())) {
Camera camera = Vigilate.getInstance().getCameras().get(camId.get());
if (!camera.getLocation().equals(event.getToTransform().getLocation())) {
camera.endViewCamera(player);
}
return;
}
if(!event.getFromTransform().getLocation().equals(event.getToTransform().getLocation())) {
Camera.resetPlayer(player);
event.setCancelled(true);
}
}
示例5: onRightClickBlock
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onRightClickBlock(InteractBlockEvent.Secondary evt, @Root Player player) {
PlayerRightClicksBlockScriptEvent event = (PlayerRightClicksBlockScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
if (evt.getTargetBlock().getLocation().isPresent()) {
event.location = new LocationTag(evt.getTargetBlock().getLocation().get());
event.precise_location = new LocationTag(evt.getInteractionPoint().get().add(evt.getTargetBlock().getPosition().toDouble()));
event.precise_location.getInternal().world = event.location.getInternal().world;
event.intersection_point = new LocationTag(evt.getInteractionPoint().get());
event.impact_normal = new LocationTag(evt.getTargetSide().asOffset());
}
else {
BlockRayHit<World> brh = BlockRay.from(player).distanceLimit(Utilities.getHandReach(player)).build().end().get();
event.location = new LocationTag(brh.getLocation());
event.precise_location = new LocationTag(brh.getPosition());
event.precise_location.getInternal().world = event.location.getInternal().world;
event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
event.impact_normal = new LocationTag(0, 0, 0);
}
event.hInternal = evt.getHandType();
event.hand = new TextTag(Utilities.getIdWithoutDefaultPrefix(evt.getHandType().getId()));
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
示例6: onEntityDamage
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
if(dmgSource.getSource() instanceof Player) {
Player player = (Player)dmgSource.getSource();
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.entity.damage." + entityId + ".deal")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
}
}
}
示例7: onItemDrop
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
ItemType itemType = item.getItemType();
String itemId = itemType.getId();
if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
return false;
}
}
return true;
});
}
示例8: onItemForge
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onItemForge(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
/*if (inventory.getArchetype() == InventoryArchetypes.ANVIL) {
Inventory forgingInputs = inventory.query(InputSlot.class);
PermHandler ph = PermHandler.getInstance();
forgingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
if (!ph.checkPerm(player, "protectionperms.item.forge." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to forge " + itemId + '!'));
}
}));
}*/
}
示例9: onItemEnchant
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onItemEnchant(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
/*if (inventory.getArchetype() == InventoryArchetypes.ENCHANTING_TABLE) {
Inventory enchantingInputs = inventory.query(InputSlot.class);
enchantingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
itemStack.getValue(Keys.ITEM_ENCHANTMENTS).ifPresent(itemEnchantments -> itemEnchantments.forEach(enchantment -> {
String enchantmentId = enchantment.getEnchantment().getId();
if (!player.hasPermission("protectionperms.item.enchant." + itemId + ".with." + enchantmentId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to enchant " + itemId + " with " + enchantmentId + '!'));
}
}));
}));
}*/
}
示例10: onInteractBlockPrimaryMain
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary",
"protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
}
}
}
示例11: onInteractBlockSecondaryMain
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
BlockState blockState = event.getTargetBlock().getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
"protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
}
}
}
示例12: onInteractEntitySecondaryMain
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例13: onInteractEntityPrimaryMain
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例14: onItemSmelt
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的package包/类
@Listener
public void onItemSmelt(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
/*if (inventory.getArchetype() == InventoryArchetypes.BREWING_STAND) {
Inventory brewingInputs = inventory.query(InputSlot.class);
brewingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
PermHandler ph = PermHandler.getInstance();
if (slot instanceof FuelSlot) {
if (!ph.checkPerm(player, "protectionperms.item.fuel." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemId + " as fuel!"));
}
} else {
if (!ph.checkPerm(player, "protectionperms.item.brew." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to brew " + itemId + '!'));
}
}
}));
}*/
}
示例15: onBlockPlace
import org.spongepowered.api.event.filter.cause.Root; //导入依赖的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;
}
}
}