Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
Get rid of interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yannicklamprecht committed Jan 12, 2019
1 parent 58e7310 commit 35aafed
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 90 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.ysl3000.bukkit.test

import com.github.ysl3000.bukkit.pathfinding.PathfinderGoalAPI
import com.github.ysl3000.bukkit.pathfinding.entity.Insentient
import com.github.ysl3000.bukkit.pathfinding.goals.PathfinderGoalGimmiCookie
import com.github.ysl3000.bukkit.pathfinding.goals.PathfinderGoalMoveToLocation
import com.github.ysl3000.bukkit.pathfinding.goals.TalkToStrangers
Expand All @@ -25,16 +26,16 @@ class PathfinderTestPlugin : JavaPlugin(), Listener {

private var pathfinderManager: PathfinderManager? = null

private val commandMap = HashMap<String, ICommand>()
private val commandMap = HashMap<String, (p: Player, args: List<String>) -> Boolean>()

override fun onEnable() {

this.pathfinderManager = PathfinderGoalAPI.getAPI()

commandMap["chat"] = Chat(pathfinderManager!!)
commandMap["cookie"] = DeliverCookie(pathfinderManager!!)
commandMap["move"] = MoveToLocation(pathfinderManager!!)
commandMap["print"] = PrintGoal(pathfinderManager!!)
commandMap["chat"] = this::chatCommand
commandMap["cookie"] = this::deliverCookieCommand
commandMap["move"] = this::moveToLocationCommand
commandMap["print"] = this::printGoalCommand

Bukkit.getServer().pluginManager.registerEvents(this, this)
}
Expand All @@ -60,108 +61,100 @@ class PathfinderTestPlugin : JavaPlugin(), Listener {
}

val finalParam = param
Bukkit.getScheduler().runTask(this) {

iCommand?.execute(player, finalParam)

}
Bukkit.getScheduler().runTask(this, {
iCommand?.invoke(player, finalParam)
} as Runnable)
}
}

private inner class Chat internal constructor(private val pathfinderManager: PathfinderManager) : ICommand {


override fun execute(p: Player, args: List<String>): Boolean {

val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager.getPathfindeGoalEntity(creature)

pathfinderGoalEntity.clearPathfinderGoals()
pathfinderGoalEntity.clearTargetPathfinderGoals()
pathfinderGoalEntity.addPathfinderGoal(0,
TalkToStrangers(pathfinderGoalEntity, args, TimeUnit.SECONDS.toMillis(20)))
return true
private fun clear(insentient: Insentient?) {
insentient?.let {
insentient.clearPathfinderGoals()
insentient.clearTargetPathfinderGoals()
}
}

private inner class DeliverCookie internal constructor(private val pathfinderManager: PathfinderManager) : ICommand {
private fun chatCommand(p: Player, args: List<String>): Boolean {
val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager?.getPathfindeGoalEntity(creature)
clear(pathfinderGoalEntity)
pathfinderGoalEntity?.let { insentient: Insentient ->
{

override fun execute(p: Player, args: List<String>): Boolean {
insentient.addPathfinderGoal(0,
TalkToStrangers(insentient, args, TimeUnit.SECONDS.toMillis(20)))
}
}

val creature = p.world
.spawn<Zombie>(Location(p.world, 235.0, 70.0, 246.0), Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager.getPathfindeGoalEntity(creature)
return true
}

pathfinderGoalEntity.clearPathfinderGoals()
pathfinderGoalEntity.clearTargetPathfinderGoals()
pathfinderGoalEntity
.addPathfinderGoal(0, PathfinderGoalGimmiCookie(pathfinderGoalEntity, creature))
private fun deliverCookieCommand(p: Player, args: List<String>): Boolean {

return true
}
val creature = p.world
.spawn<Zombie>(Location(p.world, 235.0, 70.0, 246.0), Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager?.getPathfindeGoalEntity(creature)
clear(pathfinderGoalEntity)
pathfinderGoalEntity?.addPathfinderGoal(0, PathfinderGoalGimmiCookie(pathfinderGoalEntity, creature))
return true
}

private inner class MoveToLocation internal constructor(private val pathfinderManager: PathfinderManager) : ICommand {

override fun execute(p: Player, args: List<String>): Boolean {
private fun moveToLocationCommand(p: Player, args: List<String>): Boolean {

val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager.getPathfindeGoalEntity(creature)
pathfinderGoalEntity.clearPathfinderGoals()
pathfinderGoalEntity.clearTargetPathfinderGoals()
pathfinderGoalEntity.addPathfinderGoal(0,
PathfinderGoalMoveToLocation(
pathfinderGoalEntity, Location(p.world, 235.0, 70.0, 246.0),
2.0, 0.0)
)
val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)
val pathfinderGoalEntity = this.pathfinderManager?.getPathfindeGoalEntity(creature)

return true
}
clear(pathfinderGoalEntity)
pathfinderGoalEntity?.addPathfinderGoal(0,
PathfinderGoalMoveToLocation(
pathfinderGoalEntity, Location(p.world, 235.0, 70.0, 246.0),
2.0, 0.0))
return true
}

private inner class PrintGoal(private val pathfinderManager: PathfinderManager) : ICommand {

override fun execute(p: Player, args: List<String>): Boolean {
val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)
private fun printGoalCommand(p: Player, args: List<String>): Boolean {
val creature = p.world.spawn<Zombie>(p.location, Zombie::class.java)

val pathfinderGoalEntity = this.pathfinderManager.getPathfindeGoalEntity(creature)
pathfinderGoalEntity.clearPathfinderGoals()
pathfinderGoalEntity.clearTargetPathfinderGoals()
pathfinderGoalEntity.addPathfinderGoal(0,
PathfinderGoalPrint()
)
val pathfinderGoalEntity = this.pathfinderManager?.getPathfindeGoalEntity(creature)
clear(pathfinderGoalEntity)
pathfinderGoalEntity?.addPathfinderGoal(0,
PathfinderGoalPrint()
)

return true
}
return true
}

private inner class PathfinderGoalPrint : PathfinderGoal {
private inner class PathfinderGoalPrint : PathfinderGoal {

private var shE = true
private var shT = true
private var shE = true
private var shT = true

override fun shouldExecute(): Boolean {
println("called should execute")
shE = shE.not()
return shE
}
override fun shouldExecute(): Boolean {
println("called should execute")
shE = shE.not()
return shE
}

override fun shouldTerminate(): Boolean {
println("Called should terminate")
shT = shE.not()
return shT
}
override fun shouldTerminate(): Boolean {
println("Called should terminate")
shT = shE.not()
return shT
}

override fun init() {
println("Called Init")
}
override fun init() {
println("Called Init")
}

override fun execute() {
println("Called execute")
}
override fun execute() {
println("Called execute")
}

override fun reset() {
println("Called reset")
}
override fun reset() {
println("Called reset")
}
}

}

0 comments on commit 35aafed

Please sign in to comment.