mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 23:17:59 +02:00
Made DamageType a DataContainer
This commit is contained in:
parent
cb52a9d119
commit
7b93881e59
@ -1,18 +1,21 @@
|
|||||||
package net.minestom.server.data;
|
package net.minestom.server.data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represent an element which can have a {@link Data} attached to it
|
||||||
|
*/
|
||||||
public interface DataContainer {
|
public interface DataContainer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data of this container
|
* Get the {@link Data} of this container
|
||||||
*
|
*
|
||||||
* @return the data of this container, can be null
|
* @return the {@link Data} of this container, can be null
|
||||||
*/
|
*/
|
||||||
Data getData();
|
Data getData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the data object of this container
|
* Set the {@link Data} of this container
|
||||||
*
|
*
|
||||||
* @param data the data of this container
|
* @param data the {@link Data} of this container, null to remove it
|
||||||
*/
|
*/
|
||||||
void setData(Data data);
|
void setData(Data data);
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package net.minestom.server.entity.damage;
|
|||||||
|
|
||||||
import net.minestom.server.chat.ColoredText;
|
import net.minestom.server.chat.ColoredText;
|
||||||
import net.minestom.server.chat.RichMessage;
|
import net.minestom.server.chat.RichMessage;
|
||||||
|
import net.minestom.server.data.Data;
|
||||||
|
import net.minestom.server.data.DataContainer;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.LivingEntity;
|
import net.minestom.server.entity.LivingEntity;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@ -10,7 +12,7 @@ import net.minestom.server.sound.Sound;
|
|||||||
/**
|
/**
|
||||||
* Represents a type of damage
|
* Represents a type of damage
|
||||||
*/
|
*/
|
||||||
public class DamageType {
|
public class DamageType implements DataContainer {
|
||||||
|
|
||||||
public static final DamageType VOID = new DamageType("attack.outOfWorld");
|
public static final DamageType VOID = new DamageType("attack.outOfWorld");
|
||||||
public static final DamageType GRAVITY = new DamageType("attack.fall");
|
public static final DamageType GRAVITY = new DamageType("attack.fall");
|
||||||
@ -21,6 +23,7 @@ public class DamageType {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final String identifier;
|
private final String identifier;
|
||||||
|
private Data data;
|
||||||
|
|
||||||
public DamageType(String identifier) {
|
public DamageType(String identifier) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
@ -35,7 +38,7 @@ public class DamageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RichMessage buildChatMessage(Player killed) {
|
public RichMessage buildChatMessage(Player killed) {
|
||||||
RichMessage richMessage = RichMessage.of(ColoredText.ofFormat("{@death." + identifier + ","+killed.getUsername()+"}"));
|
RichMessage richMessage = RichMessage.of(ColoredText.ofFormat("{@death." + identifier + "," + killed.getUsername() + "}"));
|
||||||
return richMessage;
|
return richMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,4 +74,14 @@ public class DamageType {
|
|||||||
protected Sound getPlayerSound(Player player) {
|
protected Sound getPlayerSound(Player player) {
|
||||||
return Sound.ENTITY_PLAYER_HURT;
|
return Sound.ENTITY_PLAYER_HURT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Data getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setData(Data data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user