本文整理汇总了Java中org.spongepowered.api.event.entity.InteractEntityEvent.Primary方法的典型用法代码示例。如果您正苦于以下问题:Java InteractEntityEvent.Primary方法的具体用法?Java InteractEntityEvent.Primary怎么用?Java InteractEntityEvent.Primary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.entity.InteractEntityEvent
的用法示例。
在下文中一共展示了InteractEntityEvent.Primary方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInteractEntity
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractEntity(InteractEntityEvent.Primary 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);
player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getType().getId()));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getCreator()));
player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getNotifier()));
}
示例2: onInteractEntityPrimaryMain
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的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!"));
}
}
}
示例3: onEntityDamageByEntityEvent
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageByEntityEvent(InteractEntityEvent.Primary e, @First Player p) {
Entity e1 = e.getTargetEntity();
RedProtect.get().logger.debug("player","RPLayerListener: Is EntityDamageByEntityEvent event. Victim: "+e.getTargetEntity().getType().getName());
Location<World> l = e1.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null || p == null){
return;
}
if (e1 instanceof Player && r.flagExists("pvp") && !r.canPVP(p)){
RPLang.sendMessage(p, "entitylistener.region.cantpvp");
e.setCancelled(true);
}
}
示例4: onEntityInteract
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @First Player player, @Getter("getTargetEntity") Player targetPlayer) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
org.spongepowered.api.item.inventory.ItemStack itemStack = optItemStack.get();
if (this.equals(itemStack.getItem()) && isAttuned(itemStack)) {
if (playerAlreadyHasInvite(itemStack, targetPlayer)) {
player.sendMessage(
Text.of(TextColors.RED, targetPlayer.getName() + " already has an invite.")
);
} else {
org.spongepowered.api.item.inventory.ItemStack newStack = createForMaster(itemStack, player);
tf(targetPlayer).inventory.addItemStackToInventory(tf(newStack));
targetPlayer.sendMessage(
Text.of(TextColors.GOLD, player.getName() + " has invited you to " + getZone(itemStack).get() + ".")
);
player.sendMessage(
Text.of(TextColors.GOLD, targetPlayer.getName() + " has been given invite.")
);
}
event.setCancelled(true);
}
}
示例5: onLeftClickEntity
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onLeftClickEntity(InteractEntityEvent.Primary evt, @Root Player player) {
PlayerLeftClicksEntityScriptEvent event = (PlayerLeftClicksEntityScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
event.entity = new EntityTag(evt.getTargetEntity());
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
示例6: onInteractEntityPrimary
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onInteractEntityPrimary(InteractEntityEvent.Primary event, @Root Player player) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.entity.interact." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary interact with " + entityType.getName() + "s!"));
}
}
示例7: onEntityInteract
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityInteract(InteractEntityEvent event, @First Player player) {
HandType hand = Utils.getEventHand(event);
CustomWorld world = WorldManager.toCustomWorld(event.getTargetEntity().getWorld());
EntityTracker tracker = world.getEntityTracker(event.getTargetEntity());
if (tracker == null) {
return;
}
if (event instanceof InteractEntityEvent.Primary) {
tracker.onEntityHit(event.getTargetEntity(), player, hand);
} else if (event instanceof InteractEntityEvent.Secondary) {
tracker.onEntityActivated(event.getTargetEntity(), player, hand);
}
}
示例8: onPlayerInteractEntity
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Player player) {
if (!GPFlags.INTERACT_ENTITY_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
final Entity targetEntity = event.getTargetEntity();
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.startTimingIfSync();
Location<World> location = targetEntity.getLocation();
GPClaim claim = this.dataStore.getClaimAt(location);
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
if (playerData.lastInteractItemBlockResult == Tristate.TRUE || playerData.lastInteractItemEntityResult == Tristate.TRUE) {
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
return;
}
Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_ENTITY_PRIMARY, player, targetEntity, player, TrustType.ACCESSOR, true);
if (result == Tristate.FALSE) {
final Text message = GriefPreventionPlugin.instance.messageData.claimProtectedEntity
.apply(ImmutableMap.of(
"owner", claim.getOwnerName())).build();
GriefPreventionPlugin.sendMessage(player, message);
event.setCancelled(true);
GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
return;
}
}
示例9: onAttack
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.BEFORE_POST)
public void onAttack(InteractEntityEvent.Primary event) {
if (event.isCancelled())
return;
if (!Utils.isLivingEntity(event.getTargetEntity()))
return;
Optional<Player> first = event.getCause().first(Player.class);
IActiveCharacter character = null;
if (first.isPresent()) {
character = characterService.getCharacter(first.get().getUniqueId());
if (character.isStub())
return;
Hotbar query = first.get().getInventory().query(Hotbar.class);
inventoryService.onLeftClick(character, query.getSelectedSlotIndex());
}
IEntity entity = entityService.get(event.getTargetEntity());
if (entity.getType() == IEntityType.CHARACTER) {
IActiveCharacter target = characterService.getCharacter(event.getTargetEntity().getUniqueId());
if (target.isStub() && !PluginConfig.ALLOW_COMBAT_FOR_CHARACTERLESS_PLAYERS) {
event.setCancelled(true);
return;
}
if (first.isPresent()) {
if (character.getParty() == target.getParty() && !character.getParty().isFriendlyfire()) {
event.setCancelled(true);
}
}
}
}
示例10: onLMBClick
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
@Include({
InteractBlockEvent.Primary.class,
InteractEntityEvent.Primary.class,
InteractItemEvent.Primary.class
})
public void onLMBClick(InteractEvent e, @Root Player player) {
IActiveCharacter character = characterService.getCharacter(player);
e.setCancelled(characterService.processUserAction(character, UserActionType.L));
}
示例11: onEntityInteract
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
Entity targetEntity = event.getTargetEntity();
if (!(targetEntity instanceof Player)) {
return;
}
Player targetPlayer = (Player) targetEntity;
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
List<UUID> pacts = pactMap.get(player.getUniqueId());
if (pacts.contains(targetPlayer.getUniqueId())) {
pacts.remove(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
} else {
pacts.add(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
}
event.setCancelled(true);
}
示例12: onEntityAttack
import org.spongepowered.api.event.entity.InteractEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityAttack(InteractEntityEvent.Primary event)
{
Entity target = event.getTargetEntity();
if (target instanceof Living)
{
return;
}
Cause causes = event.getCause();
Optional<Player> playerCause = causes.first(Player.class);
if (target instanceof Boat || target instanceof Minecart) // Is Vehicle?
{
if (handleVehicle(target, playerCause.orElse(null)))
{
event.setCancelled(true);
}
}
else if (target instanceof Hanging) // Is Hanging?
{
if (handleHanging(target, playerCause.orElse(null)))
{
event.setCancelled(true);
}
}
else // TODO other ?
{
}
}