本文整理汇总了Java中org.spongepowered.api.event.Cancellable.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java Cancellable.setCancelled方法的具体用法?Java Cancellable.setCancelled怎么用?Java Cancellable.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.Cancellable
的用法示例。
在下文中一共展示了Cancellable.setCancelled方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFor
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
if (optService.isPresent()) {
PvPService service = optService.get();
if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
return;
}
}
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in build worlds!"));
event.setCancelled(true);
}
};
}
示例2: createFor
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
if (pactMap.getOrDefault(attacker.getUniqueId(), new ArrayList<>()).contains(defender.getUniqueId())) {
if (hasPactScroll(attacker) && hasPactScroll(defender)) {
event.setCancelled(true);
}
} else if (pactMap.getOrDefault(defender.getUniqueId(), new ArrayList<>()).contains(attacker.getUniqueId())) {
if (hasPactScroll(attacker) && hasPactScroll(defender)) {
event.setCancelled(true);
pactMap.get(defender.getUniqueId()).remove(attacker.getUniqueId());
defender.sendMessage(Text.of(TextColors.DARK_RED, "Your pact with ", attacker.getName(), " has been broken!"));
}
}
}
};
}
示例3: createFor
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
if (optService.isPresent()) {
PvPService service = optService.get();
if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
return;
}
}
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this area!"));
event.setCancelled(true);
}
};
}
示例4: createFor
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
if (inst.getState() != JungleRaidState.IN_PROGRESS) {
attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
event.setCancelled(true);
return;
}
if (inst.isFriendlyFire(attacker, defender)) {
attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
event.setCancelled(true);
return;
}
if (event instanceof DamageEntityEvent) {
inst.recordAttack(attacker, defender);
attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
}
}
};
}
示例5: createFor
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, SkyWarsInstance inst) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
if (inst.getState() != SkyWarsState.IN_PROGRESS) {
attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
event.setCancelled(true);
return;
}
if (inst.isFriendlyFire(attacker, defender)) {
attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
event.setCancelled(true);
return;
}
if (indirectSource instanceof Snowball && event instanceof CollideEntityEvent.Impact) {
Optional<SkyWarsPlayerData> optData = inst.getPlayerData(defender);
if (optData.isPresent()) {
SkyWarsPlayerData data = optData.get();
data.stopFlight(3000 + (1000 * Probability.getRandom(5)));
data.stopDefrost(15000);
}
} else if (!(event instanceof DamageEntityEvent)) {
return;
}
attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
}
};
}
示例6: checkLoginStatus
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
protected void checkLoginStatus(Cancellable event, Player player) {
if (settings.getGeneral().isBypassPermission() && player.hasPermission(PomData.ARTIFACT_ID + ".bypass")) {
return;
}
if (settings.getGeneral().isCommandOnlyProtection()) {
//check if the user is already registered
if (!plugin.getDatabase().getAccount(player).isPresent()
&& player.hasPermission(PomData.ARTIFACT_ID + ".registerRequired")) {
event.setCancelled(true);
}
} else if (!plugin.getDatabase().isLoggedIn(player)) {
event.setCancelled(true);
}
}
示例7: checkSetting
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public Tristate checkSetting(Cancellable event, Player player, List<Region> regionsAt, Supplier<Permission> perm, Function<RegionConfig.Settings, Tristate> func, Tristate defaultTo)
{
Permission permission = perm.get();
if (player != null && permission != null && player.hasPermission(permission.getId()))
{
event.setCancelled(false);
return Tristate.TRUE;
}
Tristate allow = UNDEFINED;
for (Region region : regionsAt)
{
allow = allow.and(func.apply(region.getSettings()));
if (allow != UNDEFINED)
{
if (allow == FALSE)
{
event.setCancelled(true);
return FALSE;
}
break;
}
}
if (allow == TRUE)
{
event.setCancelled(false);
}
if (allow == UNDEFINED)
{
return defaultTo;
}
return allow;
}
示例8: handleAccess
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public boolean handleAccess(Player user, Location soundLocation, Cancellable event)
{
Boolean keyBookUsed = this.checkForKeyBook(user, soundLocation);
if (this.isOwner(user)) return true;
if (keyBookUsed != null && !keyBookUsed)
{
event.setCancelled(true);
return false;
}
return keyBookUsed != null || this.checkForUnlocked(user) || user.hasPermission(
module.perms().ACCESS_OTHER.getId());
}
示例9: handleEntityInteract
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleEntityInteract(Cancellable event, Player user)
{
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEUTRAL, "This entity is protected by {user}", this.getOwner());
}
if (this.getLockType() == PUBLIC) return;
if (this.handleAccess(user, null, event))
{
this.notifyUsage(user);
return;
}
if (event.isCancelled())
{
return;
}
AccessListModel access = this.getAccess(user);
if (access == null && this.getLockType() == LockType.PRIVATE)
{
event.setCancelled(true); // private & no access
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic from {user} repelled your attempts to reach this entity!", this.getOwner());
}
else
{
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic repelled your attempts to reach this entity!");
}
}
this.notifyUsage(user);
}
示例10: handleBlockBreak
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleBlockBreak(Cancellable event, Player user)
{
if (this.model.getValue(TABLE_LOCKS.OWNER_ID).equals(user.getUniqueId())
|| user.hasPermission(module.perms().BREAK_OTHER.getId()))
{
this.delete(user);
return;
}
event.setCancelled(true);
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from breaking this protection!");
}
示例11: handleBlockInteract
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleBlockInteract(Cancellable event, Player user)
{
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEUTRAL, "This block is protected by {user}", this.getOwner());
}
if (this.getLockType() == PUBLIC) return;
if (this.handleAccess(user, null, event))
{
this.notifyUsage(user);
return;
}
event.setCancelled(true);
i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from interacting with this block!");
}
示例12: doSpectatorCheck
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private void doSpectatorCheck(Cancellable event, UUID player) {
Optional<Challenger> ch = CommonCore.getChallenger(player);
if (ch.isPresent() && ch.get().isSpectating()) {
event.setCancelled(true);
}
}
示例13: handleBlockDoorUse
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleBlockDoorUse(Cancellable event, Player user, Location<World> clickedDoor)
{
if (this.getLockType() == PUBLIC)
{
this.doorUse(user, clickedDoor);
event.setCancelled(true);
return; // Allow everything
}
if (this.handleAccess(user, clickedDoor, event))
{
this.doorUse(user, clickedDoor);
event.setCancelled(true);
return;
}
if (event.isCancelled()) return;
if (this.model.getValue(TABLE_LOCKS.OWNER_ID).equals(user.getUniqueId())) return; // Its the owner
switch (this.getLockType())
{
case PRIVATE: // block changes
break;
case GUARDED:
case DONATION:
case FREE:
default: // Not Allowed for doors
throw new IllegalStateException();
}
AccessListModel access = this.getAccess(user);
if (access == null || !(access.canIn() && access.canOut()) || user.hasPermission(
module.perms().ACCESS_OTHER.getId())) // No access Or not full access
{
event.setCancelled(true);
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock from {user} prevents you from using this door!", this.getOwner());
}
else
{
i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock prevents you from using this door!");
}
return;
} // else has access
this.doorUse(user, clickedDoor);
event.setCancelled(true);
}
示例14: handleInventoryOpen
import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleInventoryOpen(Cancellable event, Inventory protectedInventory, Location<World> soundLocation, Player user)
{
if (soundLocation != null && user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEUTRAL, "This inventory is protected by {user}", this.getOwner());
}
if (this.handleAccess(user, soundLocation, event) || event.isCancelled()) return;
boolean in;
boolean out;
switch (this.getLockType())
{
default: throw new IllegalStateException();
case PUBLIC: return; // Allow everything
case PRIVATE: // block changes
case GUARDED:
in = false;
out = false;
break;
case DONATION:
in = true;
out = false;
break;
case FREE:
in = false;
out = true;
}
AccessListModel access = this.getAccess(user);
if (access == null && this.getLockType() == LockType.PRIVATE && !user.hasPermission(module.perms().ACCESS_OTHER.getId()))
{
event.setCancelled(true); // private & no access
if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
{
i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock from {user} prevents you from accessing this inventory!", this.getOwner());
}
else
{
i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock prevents you from accessing this inventory!");
}
}
else // Has access access -> new InventoryGuard
{
if (access != null)
{
in = in || access.canIn();
out = out || access.canOut();
}
this.notifyUsage(user);
if ((in && out) || user.hasPermission(module.perms().ACCESS_OTHER.getId())) return; // Has full access
if (protectedInventory == null) return; // Just checking else do lock
InventoryGuardFactory igf = module.getInventoryGuardFactory();
igf.prepareInv(protectedInventory, user.getUniqueId());
if (!in)
{
igf.blockPutInAll();
}
if (!out)
{
igf.blockTakeOutAll();
}
igf.submitInventory(Locker.class, false);
this.notifyUsage(user);
updateAccess();
}
}