@Inject(
      method = "onUpdate",
      at =
          @At(
              value = "INVOKE",
              target = "Lnet/minecraft/entity/effect/EntityLightningBolt;setDead()V"))
  public void onSetDead(CallbackInfo ci) {
    if (this.isDead) {
      return;
    }
    World world = (World) this.worldObj;
    LightningEvent.Strike strike =
        SpongeEventFactory.createLightningEventStrike(
            this.cause, this.struckEntities, this.struckEntitySnapshots, world, this.struckBlocks);
    Sponge.getEventManager().post(strike);

    if (!strike.isCancelled()) {
      for (Transaction<BlockSnapshot> bt : strike.getTransactions()) {
        if (bt.isValid()) {
          BlockSnapshot bs = bt.getFinal();
          world.setBlock(bs.getPosition(), bs.getState());
        }
      }
      for (Entity e : strike.getEntities()) {
        ((net.minecraft.entity.Entity) e).onStruckByLightning((EntityLightningBolt) (Object) this);
      }
      SpongeImpl.postEvent(SpongeEventFactory.createLightningEventPost(this.cause));
    }
  }
Ejemplo n.º 2
0
 public void cancel() {
   cancelled = true;
   tasks
       .values()
       .forEach(
           task -> {
             Sponge.getEventManager().unregisterListeners(task);
           });
 }
Ejemplo n.º 3
0
 final boolean unregister() {
   if (this.registered) {
     this.registered = false;
     Sponge.getEventManager().unregisterListeners(this);
     return true;
   } else {
     return false;
   }
 }
Ejemplo n.º 4
0
 final boolean register(Class<S> event) {
   if (this.registered) {
     return false;
   } else {
     this.registered = true;
     Sponge.getEventManager()
         .registerListener(
             Pore.getPlugin(), event, EventPriorityConverter.of(this.priority), this);
     return true;
   }
 }
Ejemplo n.º 5
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);
      }
    }
  }
Ejemplo n.º 6
0
 public CreatingJob(UUID uuid) {
   this.uuid = uuid;
   // Add tasks
   addTasks(
       new NameTask(this),
       new MaxLevelTask(this),
       new ColorTask(this),
       new BlockDataTask(this),
       new BreakTask(this),
       new PlaceTask(this),
       new KillTask(this),
       new SilkTouchTask(this),
       new WorldGenTask(this),
       new FinalTask(this));
   // Send cancel message
   for (Player player : Sponge.getServer().getOnlinePlayers()) {
     if (player.getUniqueId().equals(uuid))
       player.sendMessage(messages.getMessage("creation.cancel"));
   }
   // Register listener
   Sponge.getEventManager().registerListeners(JobsLite.getInstance(), this);
   // Start task
   nextTask();
 }
Ejemplo n.º 7
0
  @Listener
  public void onServerInit(GameInitializationEvent event) {
    getLogger().info("CommandSigns loading...");

    HashMap<List<String>, CommandSpec> subcommands = new HashMap<List<String>, CommandSpec>();

    subcommands.put(
        Arrays.asList("setcommandsign"),
        CommandSpec.builder()
            .description(Text.of("Creates CommandSigns"))
            .permission("commandsigns.setcommandsign")
            .arguments(
                GenericArguments.seq(
                    GenericArguments.onlyOne(GenericArguments.bool(Text.of("one time"))),
                    GenericArguments.onlyOne(
                        GenericArguments.remainingJoinedStrings(Text.of("command")))))
            .executor(new SetCommandSignExecutor())
            .build());

    subcommands.put(
        Arrays.asList("addcommand"),
        CommandSpec.builder()
            .description(Text.of("Adds Command to CommandSign"))
            .permission("commandsigns.addcommand")
            .arguments(
                GenericArguments.onlyOne(
                    GenericArguments.remainingJoinedStrings(Text.of("command"))))
            .executor(new AddCommandExecutor())
            .build());

    subcommands.put(
        Arrays.asList("removecommand"),
        CommandSpec.builder()
            .description(Text.of("Removes Command on CommandSign"))
            .permission("commandsigns.removecommand")
            .arguments(
                GenericArguments.onlyOne(GenericArguments.integer(Text.of("command number"))))
            .executor(new RemoveCommandExecutor())
            .build());

    subcommands.put(
        Arrays.asList("listcommands"),
        CommandSpec.builder()
            .description(Text.of("List Commands on CommandSign"))
            .permission("commandsigns.listcommands")
            .executor(new ListCommandsExecutor())
            .build());

    CommandSpec commandSignsCommandSpec =
        CommandSpec.builder()
            .description(Text.of("CommandSigns Command"))
            .permission("commandsigns.command")
            .executor(new CommandSignsExecutor())
            .children(subcommands)
            .build();

    Sponge.getCommandManager()
        .register(this, commandSignsCommandSpec, "cs", "commandsign", "commandsigns");

    // One-Time
    Sponge.getDataManager()
        .register(IsOneTimeData.class, ImmutableIsOneTimeData.class, new IsOneTimeDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeIsOneTimeData.class,
            ImmutableSpongeIsOneTimeData.class,
            new IsOneTimeDataBuilder());

    // IsCommandSign
    Sponge.getDataManager()
        .register(
            IsCommandSignData.class,
            ImmutableIsCommandSignData.class,
            new IsCommandSignDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeIsCommandSignData.class,
            ImmutableSpongeIsCommandSignData.class,
            new IsCommandSignDataBuilder());

    // Commands
    Sponge.getDataManager()
        .register(CommandsData.class, ImmutableCommandsData.class, new CommandsDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeCommandsData.class, ImmutableSpongeCommandsData.class, new CommandsDataBuilder());

    // Users
    Sponge.getDataManager()
        .register(UsersData.class, ImmutableUsersData.class, new UsersDataBuilder());
    Sponge.getDataManager()
        .register(SpongeUsersData.class, ImmutableSpongeUsersData.class, new UsersDataBuilder());

    Sponge.getEventManager().registerListeners(this, new HitBlockListener());
    Sponge.getEventManager().registerListeners(this, new InteractBlockListener());

    getLogger().info("-----------------------------");
    getLogger().info("CommandSigns was made by HassanS6000!");
    getLogger().info("Please post all errors on the Sponge Thread or on GitHub!");
    getLogger().info("Have fun, and enjoy! :D");
    getLogger().info("-----------------------------");
    getLogger().info("CommandSigns loaded!");
  }
Ejemplo n.º 8
0
  @Listener(order = Order.PRE)
  public void onDestructEntityEventDeathPlayer(
      DestructEntityEvent.Death event, @First EntityDamageSource damageSrc) {
    if (!(event.getTargetEntity() instanceof Player)) {
      return;
    }
    Player player = (Player) event.getTargetEntity();

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

    DeathReason reason = DeathReason.GENERIC;

    Entity src = damageSrc.getSource();

    if (src instanceof Player) {
      reason = DeathReason.PLAYER;
    } else if (src instanceof Projectile) {
      Projectile projectile = (Projectile) src;

      Optional<UUID> optionalUUID = projectile.getCreator();

      if (!optionalUUID.isPresent()) {
        return;
      }

      Optional<Player> optionalPlayer = Sponge.getServer().getPlayer(optionalUUID.get());

      if (optionalPlayer.isPresent()) {
        reason = DeathReason.PLAYER;
      } else {
        reason = DeathReason.PROJECTILE;
      }
    } else {
      DamageType cause = damageSrc.getType();
      reason = DeathReason.valueOf(cause.getName().toUpperCase());
    }

    Optional<EconomyService> optionalEconomy =
        Sponge.getServiceManager().provide(EconomyService.class);

    if (!optionalEconomy.isPresent()) {
      Main.instance().getLog().error("Economy plugin not found");
      return;
    }
    EconomyService economy = optionalEconomy.get();

    BigDecimal balance =
        economy
            .getOrCreateAccount(player.getUniqueId())
            .get()
            .getBalance(WorldSettings.get(player.getWorld()).getCurrency());

    PlayerWallet wallet = settings.getPlayerWallet();

    BigDecimal amount = wallet.getAmount(reason, balance);

    WalletDropEvent walletDropEvent = new WalletDropEvent(amount, player);

    if (walletDropEvent.getAmount().compareTo(BigDecimal.ZERO) != 0
        && (!Sponge.getEventManager().post(walletDropEvent))) {
      WalletDrop.depositOrWithdraw(
          player, walletDropEvent.getAmount().multiply(BigDecimal.valueOf(-1)));

      if (settings.isDropsEnabled()) {
        for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) {
          moneyStack.drop(walletDropEvent.getLocation());
        }
      }

      WalletDrop.sendDeathMessage(
          WorldSettings.get(player.getWorld()), player, walletDropEvent.getAmount());
    }
  }
Ejemplo n.º 9
0
  @Listener
  public void onDestructEntityEventDeath(
      DestructEntityEvent.Death event,
      @Getter("getTargetEntity") @Has(MoneyData.class) Living entity) {
    if (entity instanceof Player) {
      return;
    }

    if (entity.getType().equals(EntityTypes.ARMOR_STAND)
        || entity.getType().equals(EntityTypes.HUMAN)) {
      return;
    }

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

    if (settings.getDropsPerSecond().isAtDropLimit()) {
      return;
    }

    Optional<MobWallet> optionalWallet = settings.getMobWallet(entity);

    if (!optionalWallet.isPresent()) {
      return;
    }
    MobWallet wallet = optionalWallet.get();

    if (BigDecimal.valueOf(random.nextDouble()).compareTo(wallet.getFrequency()) >= 0) {
      return;
    }

    BigDecimal amount = wallet.getAmount(settings.getPrecision());

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

    WalletDropEvent walletDropEvent = new WalletDropEvent(amount, entity);

    if (settings.isDropsEnabled()) {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (optionalPlayer.isPresent()) {
        Player player = optionalPlayer.get();

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

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

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

        for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) {
          moneyStack.drop(walletDropEvent.getLocation());
        }
      }
    } else {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (!optionalPlayer.isPresent()) {
        return;
      }
      Player player = optionalPlayer.get();

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

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

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

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

        WalletDrop.sendPickupMessage(player, walletDropEvent.getAmount());
      }
    }
  }