mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Carrot is not fruit (#27)
* Carrot is not fruit * updateBuildScript & spotlessApply
This commit is contained in:
1 parent
6973dbc80d
commit
c5c3aee2fb
1345 files changed
+92079
-90006
No files matched your search
@@ -10,148 +10,145 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
||||
public class MailAddress implements INBTTagable, IMailAddress {
|
||||
|
||||
private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), "");
|
||||
private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), "");
|
||||
|
||||
private EnumAddressee type;
|
||||
private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
private EnumAddressee type;
|
||||
private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
|
||||
public MailAddress() {
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = invalidGameProfile;
|
||||
}
|
||||
public MailAddress() {
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = invalidGameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
throw new IllegalArgumentException("gameProfile must not be null");
|
||||
}
|
||||
public MailAddress(GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
throw new IllegalArgumentException("gameProfile must not be null");
|
||||
}
|
||||
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("name must not be null");
|
||||
}
|
||||
public MailAddress(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("name must not be null");
|
||||
}
|
||||
|
||||
this.type = EnumAddressee.TRADER;
|
||||
this.gameProfile = new GameProfile(null, name);
|
||||
}
|
||||
this.type = EnumAddressee.TRADER;
|
||||
this.gameProfile = new GameProfile(null, name);
|
||||
}
|
||||
|
||||
public MailAddress(IMailAddress address) {
|
||||
this.type = address.getType();
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
String name = address.getName();
|
||||
this.gameProfile = new GameProfile(null, name);
|
||||
} else if (type == EnumAddressee.PLAYER) {
|
||||
this.gameProfile = address.getPlayerProfile();
|
||||
}
|
||||
}
|
||||
public MailAddress(IMailAddress address) {
|
||||
this.type = address.getType();
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
String name = address.getName();
|
||||
this.gameProfile = new GameProfile(null, name);
|
||||
} else if (type == EnumAddressee.PLAYER) {
|
||||
this.gameProfile = address.getPlayerProfile();
|
||||
}
|
||||
}
|
||||
|
||||
public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) {
|
||||
MailAddress address = new MailAddress();
|
||||
address.readFromNBT(nbttagcompound);
|
||||
return address;
|
||||
}
|
||||
public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) {
|
||||
MailAddress address = new MailAddress();
|
||||
address.readFromNBT(nbttagcompound);
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAddressee getType() {
|
||||
return type;
|
||||
}
|
||||
@Override
|
||||
public EnumAddressee getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return gameProfile.getName();
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return gameProfile.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
|
||||
}
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return type == EnumAddressee.PLAYER;
|
||||
}
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return type == EnumAddressee.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrader() {
|
||||
return type == EnumAddressee.TRADER;
|
||||
}
|
||||
@Override
|
||||
public boolean isTrader() {
|
||||
return type == EnumAddressee.TRADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getPlayerProfile() {
|
||||
if (!this.isPlayer()) {
|
||||
return null;
|
||||
}
|
||||
return gameProfile;
|
||||
}
|
||||
@Override
|
||||
public GameProfile getPlayerProfile() {
|
||||
if (!this.isPlayer()) {
|
||||
return null;
|
||||
}
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return gameProfile.getName().hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return gameProfile.getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof MailAddress)) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof MailAddress)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MailAddress address = (MailAddress) o;
|
||||
return PlayerUtil.isSameGameProfile(address.gameProfile, gameProfile);
|
||||
}
|
||||
MailAddress address = (MailAddress) o;
|
||||
return PlayerUtil.isSameGameProfile(address.gameProfile, gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = getName().toLowerCase(Locale.ENGLISH);
|
||||
if (isPlayer()) {
|
||||
return type + "-" + name + '-' + gameProfile.getId();
|
||||
} else {
|
||||
return type + "-" + name;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = getName().toLowerCase(Locale.ENGLISH);
|
||||
if (isPlayer()) {
|
||||
return type + "-" + name + '-' + gameProfile.getId();
|
||||
} else {
|
||||
return type + "-" + name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
type = null;
|
||||
if (nbttagcompound.hasKey("TP")) {
|
||||
String typeName = nbttagcompound.getString("TP");
|
||||
type = EnumAddressee.fromString(typeName);
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
type = null;
|
||||
if (nbttagcompound.hasKey("TP")) {
|
||||
String typeName = nbttagcompound.getString("TP");
|
||||
type = EnumAddressee.fromString(typeName);
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
type = EnumAddressee.PLAYER;
|
||||
gameProfile = invalidGameProfile;
|
||||
} else if (nbttagcompound.hasKey("profile")) {
|
||||
NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile");
|
||||
gameProfile = NBTUtil.func_152459_a(profileTag);
|
||||
}
|
||||
}
|
||||
if (type == null) {
|
||||
type = EnumAddressee.PLAYER;
|
||||
gameProfile = invalidGameProfile;
|
||||
} else if (nbttagcompound.hasKey("profile")) {
|
||||
NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile");
|
||||
gameProfile = NBTUtil.func_152459_a(profileTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setString("TP", type.toString());
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setString("TP", type.toString());
|
||||
|
||||
if (gameProfile != null) {
|
||||
NBTTagCompound profileNbt = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a(profileNbt, gameProfile);
|
||||
nbttagcompound.setTag("profile", profileNbt);
|
||||
}
|
||||
}
|
||||
if (gameProfile != null) {
|
||||
NBTTagCompound profileNbt = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a(profileNbt, gameProfile);
|
||||
nbttagcompound.setTag("profile", profileNbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user