<commit_before>package plugin

import java.util.concurrent.ThreadLocalRandom

import io.luna.game.model.mobile.attr.AttributeValue
import io.luna.game.model.mobile.{MobileEntity, Npc, Player, PlayerRights}
import io.luna.game.model.{Position, World}
import io.luna.game.task.Task
import io.luna.net.msg.out.{SendInfoMessage, SendWidgetTextMessage}

/** A trait containing methods and implicit classes that are implicitly provided to all `Plugin` implementations. This is done
  * in order to make plugins as short and easy-to-write as possible. Non-`Plugin` implementation Scala classes/traits/objects
  * '''do not''' have to extend this trait, but still should when necessary in order to keep code concise and clean.
  *
  * @author lare96 <http://github.org/lare96>
  */
trait PluginImplicits {
  implicit class PlayerImplicits(player: Player) {
    def address = player.getSession.getHostAddress
    def sendMessage(message: String) = player.queue(new SendInfoMessage(message))
    def sendWidgetText(text: String, widget: Int) = player.queue(new SendWidgetTextMessage(text, widget))
  }

  implicit class MobileEntityImplicits(mob: MobileEntity) {
    def attr[T](key: String): T = {
      val attr: AttributeValue[T] = mob.getAttributes.get(key)
      attr.get
    }
    def attr[T](key: String, value: T) = {
      val attr: AttributeValue[T] = mob.getAttributes.get(key)
      attr.set(value)
    }
  }

  implicit class WorldImplicits(world: World) {
    def addNpc(id: Int, position: Position) = world.getNpcs.add(new Npc(world.getContext, id, position))
    def run(instant: Boolean = false, delay: Int, action: Task => Unit) = {
      world.schedule(new Task(instant, delay) {
        override protected def execute() = action(this)
      })
    }
  }

  def ?[T](condition: Boolean)(primary: T, secondary: T) = if (condition) primary else secondary
  def ?:[T](primary: T)(secondary: T) = ?(primary != null)(primary, secondary)

  def rightsPlayer = PlayerRights.PLAYER
  def rightsMod = PlayerRights.MODERATOR
  def rightsAdmin = PlayerRights.ADMINISTRATOR
  def rightsDev = PlayerRights.DEVELOPER
<commit_msg>addNpc implicit returns the added Npc<commit_after>package plugin

import java.util.concurrent.ThreadLocalRandom

import io.luna.game.model.mobile.attr.AttributeValue
import io.luna.game.model.mobile.{MobileEntity, Npc, Player, PlayerRights}
import io.luna.game.model.{Position, World}
import io.luna.game.task.Task
import io.luna.net.msg.out.{SendInfoMessage, SendWidgetTextMessage}

/** A trait containing methods and implicit classes that are implicitly provided to all `Plugin` implementations. This is done
  * in order to make plugins as short and easy-to-write as possible. Non-`Plugin` implementation Scala classes/traits/objects
  * '''do not''' have to extend this trait, but still should when necessary in order to keep code concise and clean.
  *
  * @author lare96 <http://github.org/lare96>
  */
trait PluginImplicits {
  implicit class PlayerImplicits(player: Player) {
    def address = player.getSession.getHostAddress
    def sendMessage(message: String) = player.queue(new SendInfoMessage(message))
    def sendWidgetText(text: String, widget: Int) = player.queue(new SendWidgetTextMessage(text, widget))
  }

  implicit class MobileEntityImplicits(mob: MobileEntity) {
    def attr[T](key: String): T = {
      val attr: AttributeValue[T] = mob.getAttributes.get(key)
      attr.get
    }
    def attr[T](key: String, value: T) = {
      val attr: AttributeValue[T] = mob.getAttributes.get(key)
      attr.set(value)
    }
  }

  implicit class WorldImplicits(world: World) {
    def addNpc(id: Int, position: Position) = {
      val npc = new Npc(world.getContext, id, position)
      world.getNpcs.add(npc)
      npc
    }
    def run(instant: Boolean = false, delay: Int, action: Task => Unit) = {
      world.schedule(new Task(instant, delay) {
        override protected def execute() = action(this)
      })
    }
  }

  def ?[T](condition: Boolean)(primary: T, secondary: T) = if (condition) primary else secondary
  def ?:[T](primary: T)(secondary: T) = ?(primary != null)(primary, secondary)

  def rightsPlayer = PlayerRights.PLAYER
  def rightsMod = PlayerRights.MODERATOR
  def rightsAdmin = PlayerRights.ADMINISTRATOR
  def rightsDev = PlayerRights.DEVELOPER

{'fraction_non_alphanumeric': 0.11098239110287303, 'fraction_numerical': 0.0018535681186283596, 'mean_word_length': 4.120996441281139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4638504', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1315, 'n_words': 369}