I am looking to implement two branches of classes in my Java program to distinguish between Human and AI-controlled Players in my game. The game is asynchronous, so players have different methods and behavior depending on which type of player they are selected as at the start of the game. All Players have shared methods, and each Player subclass has unique methods that only they can do. In addition, Human players receive prompts to make decisions while AI players make their choices automatically. There can potentially be an infinite number of Player subclasses, and each one will have a Human and AI version.
Since Java doesn't have true multiple inheritance, my current solution is to make use of an AI interface that the AI players inherit, and a Human interface that Human players inherit. Each of these interfaces has a unique makeDecision() method for each potential decision that can be made. Rewriting the code from the decision interfaces is fine, as different types of players shouldn't have the same AI.
I think the first misstep in your idea, in the context of the game, is that you aren't really modeling an AI or a Human, you are modeling a Player. You just happen to have different implementations of Player. From the game's perspective there should be no difference between a human and an AI player.
Note that this name will not be displayed in game, only in chat andplaces defined by plugins.Returns:the friendly name
- setDisplayNamevoid setDisplayName(@NullableString name)Sets the "friendly" name to display of this player. This may includecolor.Note that this name will not be displayed in game, only in chat andplaces defined by plugins.Parameters:name - The new display name.
- getPlayerListName@NotNullString getPlayerListName()Gets the name that is shown on the player list.Returns:the player list name
- setPlayerListNamevoid setPlayerListName(@NullableString name)Sets the name that is shown on the in-game player list.If the value is null, the name will be identical to getName().Parameters:name - new player list name
- getPlayerListHeader@NullableString getPlayerListHeader()Gets the currently displayed player list header for this player.Returns:player list header or null
- getPlayerListFooter@NullableString getPlayerListFooter()Gets the currently displayed player list footer for this player.Returns:player list header or null
- setPlayerListHeadervoid setPlayerListHeader(@NullableString header)Sets the currently displayed player list header for this player.Parameters:header - player list header, null for empty
- setPlayerListFootervoid setPlayerListFooter(@NullableString footer)Sets the currently displayed player list footer for this player.Parameters:footer - player list footer, null for empty
- setPlayerListHeaderFootervoid setPlayerListHeaderFooter(@NullableString header,@NullableString footer)Sets the currently displayed player list header and footer for thisplayer.Parameters:header - player list header, null for emptyfooter - player list footer, null for empty
- setCompassTargetvoid setCompassTarget(@NotNullLocation loc)Set the target of the player's compass.Parameters:loc - Location to point to
- getCompassTarget@NotNullLocation getCompassTarget()Get the previously set compass target.Returns:location of the target
- getAddress@NullableInetSocketAddress getAddress()Gets the socket address of this playerReturns:the player's address
- sendRawMessagevoid sendRawMessage(@NotNullString message)Sends this sender a message rawSpecified by:sendRawMessage in interface ConversableParameters:message - Message to be displayed
- kickPlayervoid kickPlayer(@NullableString message)Kicks player with custom kick message.Parameters:message - kick message
- ban@NullableBanEntry ban(@NullableString reason,@NullableDate expires,@NullableString source,boolean kickPlayer)Adds this user to the ProfileBanList. If a previous ban exists, this willupdate the entry.Parameters:reason - reason for the ban, null indicates implementation defaultexpires - date for the ban's expiration (unban), or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- ban@NullableBanEntry ban(@NullableString reason,@NullableInstant expires,@NullableString source,boolean kickPlayer)Adds this user to the ProfileBanList. If a previous ban exists, this willupdate the entry.Parameters:reason - reason for the ban, null indicates implementation defaultexpires - date for the ban's expiration (unban), or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- ban@NullableBanEntry ban(@NullableString reason,@NullableDuration duration,@NullableString source,boolean kickPlayer)Adds this user to the ProfileBanList. If a previous ban exists, this willupdate the entry.Parameters:reason - reason for the ban, null indicates implementation defaultduration - the duration how long the ban lasts, or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- banIp@NullableBanEntry banIp(@NullableString reason,@NullableDate expires,@NullableString source,boolean kickPlayer)Adds this user's current IP address to the IpBanList. If a previous ban exists, this willupdate the entry. If getAddress() is null this method will throw an exception.Parameters:reason - reason for the ban, null indicates implementation defaultexpires - date for the ban's expiration (unban), or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- banIp@NullableBanEntry banIp(@NullableString reason,@NullableInstant expires,@NullableString source,boolean kickPlayer)Adds this user's current IP address to the IpBanList. If a previous ban exists, this willupdate the entry. If getAddress() is null this method will throw an exception.Parameters:reason - reason for the ban, null indicates implementation defaultexpires - date for the ban's expiration (unban), or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- banIp@NullableBanEntry banIp(@NullableString reason,@NullableDuration duration,@NullableString source,boolean kickPlayer)Adds this user's current IP address to the IpBanList. If a previous ban exists, this willupdate the entry. If getAddress() is null this method will throw an exception.Parameters:reason - reason for the ban, null indicates implementation defaultduration - the duration how long the ban lasts, or null to implyforeversource - source of the ban, null indicates implementation defaultkickPlayer - if the player need to be kickReturns:the entry for the newly created ban, or the entry for the(updated) previous ban
- chatvoid chat(@NotNullString msg)Says a message (or runs a command).Parameters:msg - message to print
- performCommandboolean performCommand(@NotNullString command)Makes the player perform the given commandParameters:command - Command to performReturns:true if the command was successful, otherwise false
- isOnGround@Deprecatedboolean isOnGround()Deprecated.This value is controlled only by the client and is thereforeunreliable and vulnerable to spoofing and/or desync depending on thecontext/time which it is accessedReturns true if the entity is supported by a block.This value is a state updated by the client after each movement.Specified by:isOnGround in interface EntityReturns:True if entity is on ground.See Also:
- isOnGround()
- isSneakingboolean isSneaking()Returns if the player is in sneak modeReturns:true if player is in sneak mode
- setSneakingvoid setSneaking(boolean sneak)Sets the sneak mode the playerParameters:sneak - true if player should appear sneaking
- isSprintingboolean isSprinting()Gets whether the player is sprinting or not.Returns:true if player is sprinting.
- setSprintingvoid setSprinting(boolean sprinting)Sets whether the player is sprinting or not.Parameters:sprinting - true if the player should be sprinting
- saveDatavoid saveData()Saves the players current location, health, inventory, motion, andother information into the username.dat file, in the world/playerfolder
- loadDatavoid loadData()Loads the players current location, health, inventory, motion, andother information from the username.dat file, in the world/playerfolder.Note: This will overwrite the players current inventory, health,motion, etc, with the state from the saved dat file.
- setSleepingIgnoredvoid setSleepingIgnored(boolean isSleeping)Sets whether the player is ignored as not sleeping. If everyone iseither sleeping or has this flag set, then time will advance to thenext day. If everyone has this flag set but no one is actually in bed,then nothing will happen.Parameters:isSleeping - Whether to ignore.
- isSleepingIgnoredboolean isSleepingIgnored()Returns whether the player is sleeping ignored.Returns:Whether player is ignoring sleep.
- getBedSpawnLocation@NullableLocation getBedSpawnLocation()Gets the Location where the player will spawn at their bed, null ifthey have not slept in one or their current bed spawn is invalid.Specified by:getBedSpawnLocation in interface OfflinePlayerReturns:Bed Spawn Location if bed exists, otherwise null.
- setBedSpawnLocationvoid setBedSpawnLocation(@NullableLocation location)Sets the Location where the player will spawn at their bed.Parameters:location - where to set the respawn location
- setBedSpawnLocationvoid setBedSpawnLocation(@NullableLocation location,boolean force)Sets the Location where the player will spawn at their bed.Parameters:location - where to set the respawn locationforce - whether to forcefully set the respawn location even if avalid bed is not present
- playNote@Deprecatedvoid playNote(@NotNullLocation loc,byte instrument,byte note)Deprecated.Magic valuePlay a note for the player at a location.
This will work with cake.Parameters:loc - The location to play the noteinstrument - The instrument ID.note - The note ID. - playNotevoid playNote(@NotNullLocation loc,@NotNullInstrument instrument,@NotNullNote note)Play a note for the player at a location.
This will work with cake.This method will fail silently when called with Instrument.CUSTOM_HEAD.Parameters:loc - The location to play the noteinstrument - The instrumentnote - The note - playSoundvoid playSound(@NotNullLocation location,@NotNullSound sound,float volume,float pitch)Play a sound for a player at the location.This function will fail silently if Location or Sound are null.Parameters:location - The location to play the soundsound - The sound to playvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullLocation location,@NotNullString sound,float volume,float pitch)Play a sound for a player at the location.This function will fail silently if Location or Sound are null. Nosound will be heard by the player if their client does not have therespective sound for the value passed.Parameters:location - The location to play the soundsound - The internal sound name to playvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullLocation location,@NotNullSound sound,@NotNullSoundCategory category,float volume,float pitch)Play a sound for a player at the location.This function will fail silently if Location or Sound are null.Parameters:location - The location to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullLocation location,@NotNullString sound,@NotNullSoundCategory category,float volume,float pitch)Play a sound for a player at the location.This function will fail silently if Location or Sound are null. No soundwill be heard by the player if their client does not have the respectivesound for the value passed.Parameters:location - The location to play the soundsound - The internal sound name to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullLocation location,@NotNullSound sound,@NotNullSoundCategory category,float volume,float pitch,long seed)Play a sound for a player at the location. For sounds with multiplevariations passing the same seed will always play the same variation.This function will fail silently if Location or Sound are null.Parameters:location - The location to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the soundseed - The seed for the sound
- playSoundvoid playSound(@NotNullLocation location,@NotNullString sound,@NotNullSoundCategory category,float volume,float pitch,long seed)Play a sound for a player at the location. For sounds with multiplevariations passing the same seed will always play the same variation.This function will fail silently if Location or Sound are null. No soundwill be heard by the player if their client does not have the respectivesound for the value passed.Parameters:location - The location to play the soundsound - The internal sound name to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the soundseed - The seed for the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullSound sound,float volume,float pitch)Play a sound for a player at the location of the entity.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullString sound,float volume,float pitch)Play a sound for a player at the location of the entity.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullSound sound,@NotNullSoundCategory category,float volume,float pitch)Play a sound for a player at the location of the entity.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullString sound,@NotNullSoundCategory category,float volume,float pitch)Play a sound for a player at the location of the entity.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullSound sound,@NotNullSoundCategory category,float volume,float pitch,long seed)Play a sound for a player at the location of the entity. For sounds withmultiple variations passing the same seed will always play the same variation.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the soundseed - The seed for the sound
- playSoundvoid playSound(@NotNullEntity entity,@NotNullString sound,@NotNullSoundCategory category,float volume,float pitch,long seed)Play a sound for a player at the location of the entity. For sounds withmultiple variations passing the same seed will always play the same variation.This function will fail silently if Entity or Sound are null.Parameters:entity - The entity to play the soundsound - The sound to playcategory - The category of the soundvolume - The volume of the soundpitch - The pitch of the soundseed - The seed for the sound
- stopSoundvoid stopSound(@NotNullSound sound)Stop the specified sound from playing.Parameters:sound - the sound to stop
- stopSoundvoid stopSound(@NotNullString sound)Stop the specified sound from playing.Parameters:sound - the sound to stop
- stopSoundvoid stopSound(@NotNullSound sound,@NullableSoundCategory category)Stop the specified sound from playing.Parameters:sound - the sound to stopcategory - the category of the sound
- stopSoundvoid stopSound(@NotNullString sound,@NullableSoundCategory category)Stop the specified sound from playing.Parameters:sound - the sound to stopcategory - the category of the sound
- stopSoundvoid stopSound(@NotNullSoundCategory category)Stop the specified sound category from playing.Parameters:category - the sound category to stop
- stopAllSoundsvoid stopAllSounds()Stop all sounds from playing.
- playEffect@Deprecatedvoid playEffect(@NotNullLocation loc,@NotNullEffect effect,int data)Deprecated.Magic valuePlays an effect to just this player.Parameters:loc - the location to play the effect ateffect - the Effectdata - a data bit needed for some effects
- playEffect void playEffect(@NotNullLocation loc,@NotNullEffect effect,@NullableT data)Plays an effect to just this player.Type Parameters:T - the data based based on the type of the effectParameters:loc - the location to play the effect ateffect - the Effectdata - a data bit needed for some effects
- breakBlockboolean breakBlock(@NotNullBlock block)Force this player to break a Block using the item in their main hand.This method will respect enchantments, handle item durability (ifapplicable) and drop experience and the correct items according to thetool/item in the player's hand.Note that this method will call a BlockBreakEvent, meaning thatthis method may not be successful in breaking the block if the event wascancelled by a third party plugin. Care should be taken if running thismethod in a BlockBreakEvent listener as recursion may be possible if itis invoked on the same Block being broken in the event.Additionally, a BlockDropItemEvent is called for the itemsdropped by this method (if successful).The block must be in the same world as the player.Parameters:block - the block to breakReturns:true if the block was broken, false if the break failed
- sendBlockChange@Deprecatedvoid sendBlockChange(@NotNullLocation loc,@NotNullMaterial material,byte data)Deprecated.Magic valueSend a block change. This fakes a block change packet for a user at acertain location. This will not actually change the world in any way.Parameters:loc - The location of the changed blockmaterial - The new blockdata - The block data
- sendBlockChangevoid sendBlockChange(@NotNullLocation loc,@NotNullBlockData block)Send a block change. This fakes a block change packet for a user at acertain location. This will not actually change the world in any way.Parameters:loc - The location of the changed blockblock - The new block
- sendBlockChangesvoid sendBlockChanges(@NotNullCollection blocks)Send a multi-block change. This fakes a block change packet for a userat multiple loca