コード例 #1
0
 @Redirect(
     method = "interact",
     at =
         @At(
             value = "INVOKE",
             target = "Ljava/util/Random;nextInt(I)I",
             ordinal = 0,
             remap = false))
 public int onTame(Random rand, int bound, EntityPlayer player) {
   int random = rand.nextInt(bound);
   if (random == 0
       && !SpongeImpl.postEvent(
           SpongeEventFactory.createTameEntityEvent(
               Cause.of(
                   NamedCause.source(player),
                   NamedCause.of(
                       TameEntityEvent.USED_ITEM,
                       ((org.spongepowered.api.item.inventory.ItemStack) this.currentItemStack)
                           .createSnapshot())),
               this))) {
     this.currentItemStack = null;
     return random;
   }
   this.currentItemStack = null;
   return 1;
 }
コード例 #2
0
ファイル: MixinWorld.java プロジェクト: phroa/SpongeCommon
 /**
  * @author gabizou - February 7th, 2016
  *     <p>This will short circuit all other patches such that we control the entities being loaded
  *     by chunkloading and can throw our bulk entity event. This will bypass Forge's hook for
  *     individual entity events, but the SpongeModEventManager will still successfully throw the
  *     appropriate event and cancel the entities otherwise contained.
  * @param entities The entities being loaded
  * @param callbackInfo The callback info
  */
 @Final
 @Inject(method = "loadEntities", at = @At("HEAD"), cancellable = true)
 private void spongeLoadEntities(
     Collection<net.minecraft.entity.Entity> entities, CallbackInfo callbackInfo) {
   if (entities.isEmpty()) {
     // just return, no entities to load!
     callbackInfo.cancel();
     return;
   }
   List<Entity> entityList = new ArrayList<>();
   ImmutableList.Builder<EntitySnapshot> snapshotBuilder = ImmutableList.builder();
   for (net.minecraft.entity.Entity entity : entities) {
     entityList.add((Entity) entity);
     snapshotBuilder.add(((Entity) entity).createSnapshot());
   }
   SpawnCause cause = SpawnCause.builder().type(InternalSpawnTypes.CHUNK_LOAD).build();
   List<NamedCause> causes = new ArrayList<>();
   causes.add(NamedCause.source(cause));
   causes.add(NamedCause.of("World", this));
   SpawnEntityEvent.ChunkLoad chunkLoad =
       SpongeEventFactory.createSpawnEntityEventChunkLoad(
           Cause.of(causes), entityList, snapshotBuilder.build(), this);
   SpongeImpl.postEvent(chunkLoad);
   if (!chunkLoad.isCancelled()) {
     for (Entity successful : chunkLoad.getEntities()) {
       this.loadedEntityList.add((net.minecraft.entity.Entity) successful);
       this.onEntityAdded((net.minecraft.entity.Entity) successful);
     }
   }
   callbackInfo.cancel();
 }
コード例 #3
0
 @Inject(
     method = "dropItem",
     at =
         @At(
             value = "FIELD",
             opcode = Opcodes.GETFIELD,
             target = "Lnet/minecraft/entity/player/EntityPlayer;posY:D"),
     cancellable = true)
 private void onDropTop(
     ItemStack itemStack,
     boolean a,
     boolean b,
     CallbackInfoReturnable<EntityItem> callbackInfoReturnable) {
   final double height = this.posY - 0.3D + (double) this.getEyeHeight();
   Transform<org.spongepowered.api.world.World> transform =
       new Transform<>(this.getWorld(), new Vector3d(this.posX, height, this.posZ));
   SpawnCause cause =
       EntitySpawnCause.builder().entity(this).type(SpawnTypes.DROPPED_ITEM).build();
   ConstructEntityEvent.Pre event =
       SpongeEventFactory.createConstructEntityEventPre(
           Cause.of(NamedCause.source(cause)), EntityTypes.ITEM, transform);
   SpongeImpl.postEvent(event);
   if (event.isCancelled()) {
     callbackInfoReturnable.setReturnValue(null);
   }
 }
コード例 #4
0
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    if (src instanceof Player) {
      Player player = (Player) src;
      String playerTeamName = ConfigManager.getTeam(player.getUniqueId());

      if (playerTeamName != null
          && !ConfigManager.getMembers(playerTeamName).contains(player.getUniqueId().toString())) {
        BigDecimal money =
            ConfigManager.getClaimCost()
                .multiply(new BigDecimal(ConfigManager.getClaims(playerTeamName)));
        Polis.economyService
            .getOrCreateAccount(playerTeamName)
            .get()
            .deposit(
                Polis.economyService.getDefaultCurrency(),
                money,
                Cause.of(NamedCause.source(player)));
        ConfigManager.depositToTownBank(money, playerTeamName);
        ConfigManager.removeClaims(playerTeamName);
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.GOLD,
                "Successfully removed all claims!"));
      } else if (playerTeamName != null) {
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Ask your leader to remove all claims!"));
      } else {
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "You're not part of a town!"));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /polis unclaimall!"));
    }

    return CommandResult.success();
  }
コード例 #5
0
ファイル: InventoryGuard.java プロジェクト: CubeEngine/core
 public void submitInventory(Class owner, boolean openInventory) {
   this.owner = owner;
   em.registerListener(owner, this);
   if (openInventory) {
     for (UUID user : users) {
       Optional<Player> player = Sponge.getServer().getPlayer(user);
       if (player.isPresent()) {
         this.container =
             player
                 .get()
                 .openInventory(this.inventory, Cause.of(NamedCause.source(player)))
                 .orElse(null);
         // TODO check if not opened
       }
     }
   }
 }
コード例 #6
0
  /**
   * @author gabizou - January 30th, 2016
   * @author blood - May 12th, 2016
   * @reason If capturing is enabled, captures the item and avoids spawn. If capturing is not
   *     enabled, redirects the dropped item spawning to use our world spawning since we know the
   *     cause.
   */
  @Overwrite
  public void joinEntityItemWithWorld(EntityItem itemIn) {
    if (this.worldObj.isRemote) {
      this.worldObj.spawnEntityInWorld(itemIn);
      return;
    }

    if (this.captureItemDrops) {
      this.capturedItemDrops.add(itemIn);
      return;
    }

    SpawnCause spawnCause =
        EntitySpawnCause.builder().entity(this).type(SpawnTypes.DROPPED_ITEM).build();
    ((org.spongepowered.api.world.World) this.worldObj)
        .spawnEntity((Entity) itemIn, Cause.of(NamedCause.source(spawnCause)));
  }
コード例 #7
0
 @Inject(
     method = "randomTick",
     at = @At(value = "HEAD"),
     locals = LocalCapture.CAPTURE_FAILEXCEPTION,
     cancellable = true)
 public void callRandomTickEvent(
     net.minecraft.world.World world,
     BlockPos pos,
     IBlockState state,
     Random rand,
     CallbackInfo ci) {
   BlockSnapshot blockSnapshot = ((World) world).createSnapshot(VecHelper.toVector(pos));
   final TickBlockEvent event =
       SpongeEventFactory.createTickBlockEvent(Cause.of(NamedCause.source(world)), blockSnapshot);
   SpongeImpl.postEvent(event);
   if (event.isCancelled()) {
     ci.cancel();
   }
 }
コード例 #8
0
 @Redirect(
     method = "onUpdate",
     at =
         @At(
             value = "INVOKE",
             target = "Lnet/minecraft/entity/player/EntityPlayer;isPlayerSleeping()Z"))
 public boolean onIsPlayerSleeping(EntityPlayer self) {
   if (self.isPlayerSleeping()) {
     if (!this.worldObj.isRemote) {
       SpongeImpl.postEvent(
           SpongeEventFactory.createSleepingEventTick(
               Cause.of(NamedCause.source(this)),
               this.getWorld().createSnapshot(VecHelper.toVector(this.playerLocation)),
               this));
     }
     return true;
   }
   return false;
 }
コード例 #9
0
  @Listener(order = Order.POST)
  public void onAffectSlotEvent(AffectSlotEvent event, @Root Player player) {
    for (SlotTransaction transaction : event.getTransactions()) {
      ItemStack itemStack = transaction.getFinal().createStack();

      BigDecimal amount = WalletDrop.getValue(itemStack);

      if (amount.compareTo(BigDecimal.ZERO) == 0) {
        continue;
      }

      WorldSettings settings = WorldSettings.get(player.getWorld());

      if (player.gameMode().get().equals(GameModes.CREATIVE) && !settings.isCreativeModeAllowed()) {
        event.setCancelled(true);
        return;
      }

      if (settings.isUsePermissions()) {
        if (!player.hasPermission("walletdrop.enable")) {
          return;
        }
      }

      WalletPickupEvent moneyPickupEvent =
          new WalletPickupEvent(itemStack, amount, Cause.of(NamedCause.source(player)));

      if (!Sponge.getEventManager().post(moneyPickupEvent)) {
        Sponge.getScheduler()
            .createTaskBuilder()
            .delayTicks(2)
            .execute(
                c -> {
                  player.getInventory().query(itemStack).clear();
                })
            .submit(Main.getPlugin());

        WalletDrop.depositOrWithdraw(player, moneyPickupEvent.getAmount());

        WalletDrop.sendPickupMessage(player, amount);
      }
    }
  }
コード例 #10
0
 @Redirect(
     method = "onUpdate()V",
     at =
         @At(
             value = "INVOKE",
             target =
                 "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z"))
 public boolean onAttackEntityFrom(
     net.minecraft.entity.Entity entity, DamageSource damageSource, float damage) {
   EntitySnapshot fishHookSnapshot = this.createSnapshot();
   FishingEvent.HookEntity event =
       SpongeEventFactory.createFishingEventHookEntity(
           Cause.of(NamedCause.source(this.angler)), this.createSnapshot(), this, (Entity) entity);
   if (!SpongeImpl.postEvent(event)) {
     if (this.getShooter() instanceof Entity) {
       DamageSource.causeThrownDamage(
           (net.minecraft.entity.Entity) (Object) this,
           (net.minecraft.entity.Entity) this.getShooter());
     }
     return entity.attackEntityFrom(damageSource, (float) this.getDamage());
   }
   return false;
 }
コード例 #11
0
  /**
   * @author Aaron1011 - February 6th, 2015
   * @reason This needs to handle for both cases where a fish and/or an entity is being caught.
   *     There's no real good way to do this with an injection.
   */
  @Overwrite
  public int handleHookRetraction() {
    if (this.worldObj.isRemote) {
      return 0;
    }

    // Sponge start
    byte b0 = 0;

    net.minecraft.item.ItemStack itemStack = null;
    int exp = 0;
    if (this.ticksCatchable > 0) {
      itemStack = this.getFishingResult();
      exp = this.rand.nextInt(6) + 1;
    }

    EntitySnapshot fishHookSnapshot = this.createSnapshot();

    Transaction<ItemStackSnapshot> transaction = null;
    if (itemStack != null) {
      ItemStackSnapshot original = ((ItemStack) itemStack).createSnapshot();
      ItemStackSnapshot replacement = ((ItemStack) itemStack).createSnapshot();
      transaction = new Transaction<>(original, replacement);
    } else {
      transaction = new Transaction<>(ItemStackSnapshot.NONE, ItemStackSnapshot.NONE);
    }

    FishingEvent.Stop event =
        SpongeEventFactory.createFishingEventStop(
            Cause.of(NamedCause.source(this.angler)),
            exp,
            exp,
            fishHookSnapshot,
            this,
            transaction,
            (Player) this.angler);
    if (!SpongeImpl.postEvent(event)) {
      // Sponge end
      if (this.caughtEntity != null) {
        double d0 = this.angler.posX - this.posX;
        double d2 = this.angler.posY - this.posY;
        double d4 = this.angler.posZ - this.posZ;
        double d6 = (double) MathHelper.sqrt_double(d0 * d0 + d2 * d2 + d4 * d4);
        double d8 = 0.1D;
        this.caughtEntity.motionX += d0 * d8;
        this.caughtEntity.motionY += d2 * d8 + (double) MathHelper.sqrt_double(d6) * 0.08D;
        this.caughtEntity.motionZ += d4 * d8;
        b0 = 3;
      }

      // Sponge Start
      if (!event.getItemStackTransaction().getFinal().getType().equals(ItemTypes.NONE)) {
        ItemStackSnapshot itemSnapshot = event.getItemStackTransaction().getFinal();
        EntityItem entityitem1 =
            new EntityItem(
                this.worldObj,
                this.posX,
                this.posY,
                this.posZ,
                (net.minecraft.item.ItemStack) itemSnapshot.createStack());
        double d1 = this.angler.posX - this.posX;
        double d3 = this.angler.posY - this.posY;
        double d5 = this.angler.posZ - this.posZ;
        double d7 = MathHelper.sqrt_double(d1 * d1 + d3 * d3 + d5 * d5);
        double d9 = 0.1D;
        entityitem1.motionX = d1 * d9;
        entityitem1.motionY = d3 * d9 + MathHelper.sqrt_double(d7) * 0.08D;
        entityitem1.motionZ = d5 * d9;
        this.worldObj.spawnEntityInWorld(entityitem1);
        this.angler.worldObj.spawnEntityInWorld(
            new EntityXPOrb(
                this.angler.worldObj,
                this.angler.posX,
                this.angler.posY + 0.5D,
                this.angler.posZ + 0.5D,
                event.getExperience()));
        // Sponge End
        b0 = 1;
      }

      if (this.inGround) {
        b0 = 2;
      }

      this.setDead();
      this.angler.fishEntity = null;

      // Sponge Start
      if (this.fishingRod != null) {
        this.fishingRod.damageItem(b0, this.angler);
        this.angler.swingItem();
        this.fishingRod = null;
      }
      // Sponge End
    }
    return b0;
  }