本文整理汇总了Java中org.spongepowered.api.event.entity.DestructEntityEvent类的典型用法代码示例。如果您正苦于以下问题:Java DestructEntityEvent类的具体用法?Java DestructEntityEvent怎么用?Java DestructEntityEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DestructEntityEvent类属于org.spongepowered.api.event.entity包,在下文中一共展示了DestructEntityEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event)
{
if(event.getTargetEntity() instanceof Player)
{
Player player = (Player)event.getTargetEntity();
PowerService.decreasePower(player.getUniqueId());
player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Your power has been decreased by ", TextColors.GOLD, String.valueOf(MainLogic.getPowerDecrement()) + "\n",
TextColors.GRAY, "Current power: ", String.valueOf(PowerService.getPlayerPower(player.getUniqueId())) + "/" + String.valueOf(PowerService.getPlayerMaxPower(player.getUniqueId()))));
PlayerService.setPlayerChunkPosition(player.getUniqueId(), null);
return;
}
else return;
}
示例2: onPlayerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event) {
DiscordBridge mod = DiscordBridge.getInstance();
GlobalConfig config = mod.getConfig();
DiscordAPI client = mod.getBotClient();
if (!(event.getTargetEntity() instanceof Player) || event.isMessageCancelled() || StringUtils.isBlank(event.getMessage().toPlain())) return;
Player player = (Player) event.getTargetEntity();
if (client != null) {
for (ChannelConfig channelConfig : config.channels) {
if (StringUtils.isNotBlank(channelConfig.discordId) && channelConfig.discord != null) {
String template = ConfigUtil.get(channelConfig.discord.deathTemplate, null);
if (StringUtils.isNotBlank(template)) {
Channel channel = client.getChannelById(channelConfig.discordId);
ChannelUtil.sendMessage(channel, template.replace("%s", event.getMessage().toPlain()));
}
}
}
}
}
示例3: onEntityDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onEntityDeath(DestructEntityEvent.Death event) {
if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) {
return;
}
GPTimings.ENTITY_DEATH_EVENT.startTimingIfSync();
final Living entity = event.getTargetEntity();
if (!(entity instanceof Player) || !event.getCause().first(EntityDamageSource.class).isPresent()) {
GPTimings.ENTITY_DEATH_EVENT.stopTimingIfSync();
return;
}
// don't do the rest in worlds where claims are not enabled
if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(entity.getWorld().getProperties())) {
GPTimings.ENTITY_DEATH_EVENT.stopTimingIfSync();
return;
}
GPTimings.ENTITY_DEATH_EVENT.stopTimingIfSync();
}
示例4: handleDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
private void handleDeath() {
// Can happen when a dead player joins, just
// mark the player as dead since the events
// have already been thrown.
if (getWorld() == null) {
setDead(true);
}
if (isDead()) {
return;
}
setDead(true);
final CauseStack causeStack = CauseStack.current();
// Post the entity destruction event
final DestructEntityEvent event = SpongeEventFactory.createDestructEntityEventDeath(causeStack.getCurrentCause(),
MessageChannel.TO_NONE, Optional.empty(), new MessageEvent.MessageFormatter(), this, false);
postDestructEvent(event);
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
// Add the destruct event to the cause, this can be used
// to track the cause of the entity death.
frame.pushCause(event);
// Post the harvest event
handleDeath(causeStack);
}
}
示例5: remove
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
public void remove(RemoveState removeState) {
checkNotNull(removeState, "removeState");
if (this.removeState == removeState) {
return;
}
this.removeState = removeState;
if (removeState == RemoveState.DESTROYED) {
setVehicle(null);
clearPassengers();
// Call the normal destroy entity event,
// don't do it if the entity is dead.
if (!isDead()) {
setDead(true);
final CauseStack causeStack = CauseStack.current();
// TODO: Message channel?
final DestructEntityEvent event = SpongeEventFactory.createDestructEntityEvent(causeStack.getCurrentCause(),
MessageChannel.TO_NONE, Optional.empty(), new MessageEvent.MessageFormatter(), this, false);
postDestructEvent(event);
}
}
}
示例6: onEntityDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onEntityDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Zombie zombie) {
Optional<PatientXInstance> optInst = manager.getApplicableZone(zombie);
if (!optInst.isPresent()) {
return;
}
if (((EntityZombie) zombie).isChild()) {
if (Probability.getChance(10)) {
Task.builder().execute(() -> {
new ItemDropper(zombie.getLocation()).dropStacks(
Lists.newArrayList(newItemStack(ItemTypes.GOLD_INGOT, Probability.getRandom(16))),
SpawnTypes.DROPPED_ITEM
);
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
}
示例7: onPlayerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Player player) {
if (!isApplicable(player)) {
return;
}
PlayerStateService service = Sponge.getServiceManager().provideUnchecked(PlayerStateService.class);
try {
service.storeInventory(player);
service.releaseInventory(player);
player.getInventory().clear();
} catch (InventoryStorageStateException e) {
e.printStackTrace();
}
}
示例8: onEntityDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onEntityDeath(DestructEntityEvent.Death destructEntityEvent, @First EntityDamageSource damageSource) {
Living targetEntity = destructEntityEvent.getTargetEntity();
if (targetEntity instanceof Player) {
Player targetPlayer = (Player) targetEntity;
increaseDeaths(targetPlayer);
}
Entity killerEntity = damageSource.getSource();
if (killerEntity instanceof Player) {
Player killerPlayer = (Player) killerEntity;
if (targetEntity instanceof Player) {
increasePlayerKills(killerPlayer);
} else {
increaseMobKills(killerPlayer);
}
}
}
示例9: onPaintingBreakEvent
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener(order = Order.EARLY)
public void onPaintingBreakEvent(DestructEntityEvent event)
{
if (!(event.getTargetEntity() instanceof Painting))
{
return;
}
Painting painting = (Painting)event.getTargetEntity();
Iterator<Entry<UUID, Painting>> paintingIterator = this.paintingChange.entrySet().iterator();
while(paintingIterator.hasNext())
{
Entry<UUID, Painting> entry = paintingIterator.next();
if(entry.getValue().equals(painting))
{
Optional<Player> player = Sponge.getServer().getPlayer(entry.getKey());
if (player.isPresent())
{
i18n.send(player.get(), NEGATIVE, "The painting broke");
}
paintingIterator.remove();
}
}
}
示例10: onEntityDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onEntityDeath(DestructEntityEvent event, @First EntityDamageSource source) // Cleanup Locks in case Entity dies
{
Entity target = event.getTargetEntity();
Lock lock = this.manager.getLockForEntityUID(target.getUniqueId());
if (lock == null) return;
Player player;
if (source.getSource() instanceof Player)
{
player = ((Player)source.getSource());
}
else if (source instanceof IndirectEntityDamageSource && ((IndirectEntityDamageSource)source).getIndirectSource() instanceof Player)
{
player = ((Player)((IndirectEntityDamageSource)source).getIndirectSource());
}
else
{
return;
}
lock.handleEntityDeletion(player); // Delete Lock and notify user that destroyed Lock
}
示例11: onDesctruct
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onDesctruct(DestructEntityEvent event)
{
/* TODO if (event.getCause().get("CombinedItem", Object.class).isPresent())
{
// Ignore CombinedItem
return;
}
TODO if (event.getCause().get("PickedUp", Object.class).isPresent())
{
// Ignore Pickup
return;
}
*/
if (!isActive(event.getTargetEntity().getWorld()))
{
return;
}
report(observe(event));
}
示例12: onDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onDeath(DestructEntityEvent.Death e) {
if (!(e.getTargetEntity() instanceof Player))
return;
Player p = (Player) e.getTargetEntity();
if (isOnPipe(p.getUniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
sendPacket(p, e.getMessage().toPlain());
}
}
示例13: onEntityDies
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onEntityDies(DestructEntityEvent.Death evt) {
EntityDiesScriptEvent event = (EntityDiesScriptEvent) clone();
event.internal = evt;
event.entity = new EntityTag(evt.getTargetEntity());
event.message = new FormattedTextTag(evt.getMessage());
event.run();
}
示例14: onPlayerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event) {
if (event.getTargetEntity() instanceof Player) {
EPlayer player = this.plugin.getEServer().getEPlayer((Player) event.getTargetEntity());
player.setBack();
}
}
示例15: commandSuicide
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入依赖的package包/类
private CompletableFuture<Boolean> commandSuicide(final EPlayer player) {
// Event cancel
if(!player.setHealth(0)) {
EEMessages.SUICIDE_CANCEL.sender()
.replace("{player}", player.getName())
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
final MessageEvent.MessageFormatter formatter = new MessageEvent.MessageFormatter();
MessageChannel originalChannel;
MessageChannel channel;
boolean messageCancelled = false;
originalChannel = player.getMessageChannel();
channel = player.getMessageChannel();
messageCancelled = !EEMessages.SUICIDE_DEATH_MESSAGE.getMessage().getChat().isPresent();
formatter.getBody().add(new MessageEvent.DefaultBodyApplier(EEMessages.SUICIDE_DEATH_MESSAGE.getFormat().toText(player.getReplaces())));
List<NamedCause> causes = new ArrayList<NamedCause>();
causes.add(NamedCause.of("Command", "kill"));
causes.add(NamedCause.owner(player));
Cause cause = Cause.of(causes);
DestructEntityEvent.Death event = SpongeEventFactory.createDestructEntityEventDeath(cause, originalChannel, Optional.of(channel), formatter, player, messageCancelled);
this.plugin.getGame().getEventManager().post(event);
if (!event.isMessageCancelled() && !event.getMessage().isEmpty()) {
event.getChannel().ifPresent(eventChannel -> eventChannel.send(player, event.getMessage()));
} else {
EEMessages.SUICIDE_PLAYER.sender()
.replace("{player}", player.getName())
.sendTo(player);
}
return CompletableFuture.completedFuture(true);
}