mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Fix-up of the Mail system
Fixed several crashes and bugs. Tested by sending mail and trading with multiple real accounts and a server. closes #176
This commit is contained in:
1 parent
07afdf63b1
commit
36da6efa91
27 files changed
+470
-258
No files matched your search
@@ -25,8 +25,8 @@ import forestry.api.mail.IPostOffice;
|
||||
import forestry.api.mail.IPostRegistry;
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import forestry.plugins.PluginMail;
|
||||
@@ -34,8 +34,8 @@ import forestry.plugins.PluginMail;
|
||||
public class PostRegistry implements IPostRegistry {
|
||||
|
||||
public static PostOffice cachedPostOffice;
|
||||
public static HashMap<MailAddress, POBox> cachedPOBoxes = new HashMap<MailAddress, POBox>();
|
||||
public static HashMap<MailAddress, ITradeStation> cachedTradeStations = new HashMap<MailAddress, ITradeStation>();
|
||||
public static HashMap<IMailAddress, POBox> cachedPOBoxes = new HashMap<IMailAddress, POBox>();
|
||||
public static HashMap<IMailAddress, ITradeStation> cachedTradeStations = new HashMap<IMailAddress, ITradeStation>();
|
||||
|
||||
/**
|
||||
* @param world the Minecraft world the PO box will be in
|
||||
@@ -43,11 +43,11 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the passed address is valid for PO Boxes.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidPOBox(World world, MailAddress address) {
|
||||
public boolean isValidPOBox(World world, IMailAddress address) {
|
||||
return address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
public static POBox getPOBox(World world, MailAddress address) {
|
||||
public static POBox getPOBox(World world, IMailAddress address) {
|
||||
|
||||
if (cachedPOBoxes.containsKey(address))
|
||||
return cachedPOBoxes.get(address);
|
||||
@@ -58,7 +58,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
return pobox;
|
||||
}
|
||||
|
||||
public static POBox getOrCreatePOBox(World world, MailAddress address) {
|
||||
public static POBox getOrCreatePOBox(World world, IMailAddress address) {
|
||||
POBox pobox = getPOBox(world, address);
|
||||
|
||||
if (pobox == null) {
|
||||
@@ -78,7 +78,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the passed address can be an address for a trade station
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeAddress(World world, MailAddress address) {
|
||||
public boolean isValidTradeAddress(World world, IMailAddress address) {
|
||||
return !address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the trade address has not yet been used before.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailableTradeAddress(World world, MailAddress address) {
|
||||
public boolean isAvailableTradeAddress(World world, IMailAddress address) {
|
||||
return getTradeStation(world, address) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getTradeStation(World world, MailAddress address) {
|
||||
public TradeStation getTradeStation(World world, IMailAddress address) {
|
||||
if (cachedTradeStations.containsKey(address))
|
||||
return (TradeStation)cachedTradeStations.get(address);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, MailAddress address) {
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, IMailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
|
||||
if (trade == null) {
|
||||
@@ -125,7 +125,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTradeStation(World world, MailAddress address) {
|
||||
public void deleteTradeStation(World world, IMailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
if (trade == null)
|
||||
return;
|
||||
@@ -157,6 +157,16 @@ public class PostRegistry implements IPostRegistry {
|
||||
return office;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(GameProfile gameProfile) {
|
||||
return new MailAddress(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(String traderName) {
|
||||
return new MailAddress(traderName);
|
||||
}
|
||||
|
||||
/* CARRIER */
|
||||
private final HashMap<String, IPostalCarrier> carriers = new HashMap<String, IPostalCarrier>();
|
||||
|
||||
@@ -177,7 +187,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
/* LETTERS */
|
||||
@Override
|
||||
public ILetter createLetter(MailAddress sender, MailAddress recipient) {
|
||||
public ILetter createLetter(IMailAddress sender, IMailAddress recipient) {
|
||||
return new Letter(sender, recipient);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user