本文整理汇总了Java中org.spongepowered.api.event.entity.DestructEntityEvent.Death方法的典型用法代码示例。如果您正苦于以下问题:Java DestructEntityEvent.Death方法的具体用法?Java DestructEntityEvent.Death怎么用?Java DestructEntityEvent.Death使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.entity.DestructEntityEvent
的用法示例。
在下文中一共展示了DestructEntityEvent.Death方法的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: 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());
}
}
}
示例5: 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();
}
}
示例6: 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);
}
}
}
示例7: 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());
}
}
示例8: 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();
}
示例9: 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();
}
}
示例10: 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);
}
示例11: playerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.POST)
public void playerDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Player player)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
String key = "death";
Optional<DamageSource> dmgSrcOpt = event.getCause().first(DamageSource.class);
if (dmgSrcOpt.isPresent()) {
key += ":" + dmgSrcOpt.get().getType().getId();
}
processEvent(event, player, key);
}
示例12: onPlayerDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST)
public void onPlayerDeath(DestructEntityEvent.Death event, @Root DamageSource damageSource) {
GPTimings.PLAYER_DEATH_EVENT.startTimingIfSync();
if (!(event.getTargetEntity() instanceof Player) || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) {
GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync();
return;
}
// FEATURE: prevent death message spam by implementing a "cooldown period" for death messages
Player player = (Player) event.getTargetEntity();
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), event.getTargetEntity().getUniqueId());
long now = Calendar.getInstance().getTimeInMillis();
if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled && (now - playerData.lastDeathTimeStamp) < GriefPreventionPlugin.getGlobalConfig().getConfig().spam.deathMessageCooldown * 1000) {
event.setMessage(Text.of());
}
playerData.lastDeathTimeStamp = now;
// these are related to locking dropped items on death to prevent theft
World world = event.getTargetEntity().getWorld();
if (world != null) {
GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(world.getProperties());
GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
if ((claim.pvpRulesApply() && activeConfig.getConfig().pvp.protectItemsOnDeathPvp) ||
(!claim.isPvpEnabled() && activeConfig.getConfig().general.protectItemsOnDeathNonPvp)) {
playerData.dropsAreUnlocked = false;
playerData.receivedDropUnlockAdvertisement = false;
}
}
GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync();
}
示例13: onEntityDeath
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDeath(DestructEntityEvent.Death deathEntityEvent) {
Living targetEntity = deathEntityEvent.getTargetEntity();
if (!deathEntityEvent.isMessageCancelled()) {
//clear entity properties
if (targetEntity.getType() == EntityTypes.PLAYER) {
Player targetPlayer = (Player) targetEntity;
Scoreboard playerScoreboard = targetPlayer.getScoreboard();
String playerName = targetPlayer.getName();
playerScoreboard.getTeam(playerName).ifPresent(Team::unregister);
} else if (targetEntity.supports(Keys.DISPLAY_NAME)) {
targetEntity.remove(Keys.DISPLAY_NAME);
}
//clean message
Text oldMessage = deathEntityEvent.getMessage();
Builder newMessageBuilder = Text.builder(oldMessage, "");
for (Text child : oldMessage.getChildren()) {
if (child instanceof LiteralText) {
String content = ((LiteralText) child).getContent();
String newContent = content.replace(String.valueOf(settings.getConfig().getDisplayChar()), "");
newMessageBuilder.append(Text.builder(child, newContent).build());
continue;
}
newMessageBuilder.append(child);
}
deathEntityEvent.setMessage(newMessageBuilder.build());
}
}
示例14: onPlayerDie
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDie(DestructEntityEvent.Death e){
if (!(e.getTargetEntity() instanceof Player)){
return;
}
RedProtect.get().logger.debug("player","RPLayerListener: Is DestructEntityEvent.Death");
Player p = (Player) e.getTargetEntity();
if (RedProtect.get().tpWait.contains(p.getName())){
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
}
示例15: onKill
import org.spongepowered.api.event.entity.DestructEntityEvent; //导入方法依赖的package包/类
@Listener
public void onKill(DestructEntityEvent.Death event) {
Optional<Player> first = event.getCause().first(Player.class);
if (first.isPresent()) {
Player player = first.get();
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (!character.isStub()) {
IEffectContainer container = character.getEffect(LifeAfterKillEffect.name);
if (container != null) {
float l = (float) container.getStackedValue();
entityService.healEntity(character, l, null);
}
}
}
}