diff --git a/src/api/java/appeng/api/features/ILocatableRegistry.java b/src/api/java/appeng/api/features/ILocatableRegistry.java index 5f10c22e..6c9d6225 100644 --- a/src/api/java/appeng/api/features/ILocatableRegistry.java +++ b/src/api/java/appeng/api/features/ILocatableRegistry.java @@ -23,19 +23,31 @@ package appeng.api.features; + /** * A Registry for locatable items, works based on serial numbers. */ public interface ILocatableRegistry { - /** * Attempts to find the object with the serial specified, if it can it * returns the object. * * @param serial serial + * * @return requestedObject, or null + * + * @deprecated use {@link ILocatableRegistry#getLocatableBy(long)} */ - public abstract Object findLocatableBySerial(long serial); + @Deprecated + Object findLocatableBySerial( long serial ); + /** + * Gets the {@link ILocatable} with the registered serial, if available + * + * @param serial serial + * + * @return requestedObject, or null, if the object does not exist anymore + */ + ILocatable getLocatableBy( long serial ); } \ No newline at end of file diff --git a/src/main/java/appeng/core/features/registries/LocatableRegistry.java b/src/main/java/appeng/core/features/registries/LocatableRegistry.java index 4106a275..49998a6a 100644 --- a/src/main/java/appeng/core/features/registries/LocatableRegistry.java +++ b/src/main/java/appeng/core/features/registries/LocatableRegistry.java @@ -18,7 +18,9 @@ package appeng.core.features.registries; + import java.util.HashMap; +import java.util.Map; import net.minecraftforge.common.MinecraftForge; @@ -30,13 +32,19 @@ import appeng.api.features.ILocatable; import appeng.api.features.ILocatableRegistry; import appeng.util.Platform; -public class LocatableRegistry implements ILocatableRegistry -{ - private final HashMap set; +public final class LocatableRegistry implements ILocatableRegistry +{ + private final Map set; + + public LocatableRegistry() + { + this.set = new HashMap(); + MinecraftForge.EVENT_BUS.register( this ); + } @SubscribeEvent - public void updateLocatable(LocatableEventAnnounce e) + public void updateLocatable( LocatableEventAnnounce e ) { if ( Platform.isClient() ) return; // IGNORE! @@ -51,18 +59,18 @@ public class LocatableRegistry implements ILocatableRegistry } } - public LocatableRegistry() { - this.set = new HashMap(); - MinecraftForge.EVENT_BUS.register( this ); - } - /** * Find a locate-able object by its serial. */ @Override - public Object findLocatableBySerial(long ser) + public Object findLocatableBySerial( long ser ) { return this.set.get( ser ); } + @Override + public ILocatable getLocatableBy( long serial ) + { + return this.set.get( serial ); + } } diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index 2057cc7b..656adcc6 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -18,24 +18,25 @@ package appeng.core.features.registries; + import java.util.ArrayList; import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; +import appeng.api.AEApi; +import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermRegistry; import appeng.core.localization.PlayerMessages; import appeng.core.sync.GuiBridge; import appeng.util.Platform; -public class WirelessRegistry implements IWirelessTermRegistry +public final class WirelessRegistry implements IWirelessTermRegistry { - - final List handlers; + private final List handlers; public WirelessRegistry() { this.handlers = new ArrayList(); @@ -76,10 +77,25 @@ public class WirelessRegistry implements IWirelessTermRegistry if ( Platform.isClient() ) return; - IWirelessTermHandler handler = this.getWirelessTerminalHandler( item ); - if ( handler == null ) + if ( !this.isWirelessTerminal( item ) ) { - player.addChatMessage( new ChatComponentText( "Item is not a wireless terminal." ) ); + player.addChatMessage( PlayerMessages.DeviceNotWirelessTerminal.get() ); + return; + } + + final IWirelessTermHandler handler = this.getWirelessTerminalHandler( item ); + final String unparsedKey = handler.getEncryptionKey( item ); + if ( unparsedKey.length() == 0 ) + { + player.addChatMessage( PlayerMessages.DeviceNotLinked.get() ); + return; + } + + final long parsedKey = Long.parseLong( unparsedKey ); + final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy( parsedKey ); + if ( securityStation == null ) + { + player.addChatMessage( PlayerMessages.StationCanNotBeLocated.get() ); return; } diff --git a/src/main/java/appeng/core/localization/PlayerMessages.java b/src/main/java/appeng/core/localization/PlayerMessages.java index 12c1a6b7..c98f7285 100644 --- a/src/main/java/appeng/core/localization/PlayerMessages.java +++ b/src/main/java/appeng/core/localization/PlayerMessages.java @@ -25,7 +25,10 @@ public enum PlayerMessages { ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, - isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared; + isNowLocked, isNowUnlocked, + AmmoDepleted, + CommunicationError, OutOfRange, DeviceNotPowered, DeviceNotWirelessTerminal, DeviceNotLinked, StationCanNotBeLocated, + SettingCleared,; String getName() { diff --git a/src/main/resources/assets/appliedenergistics2/lang/en_US.lang b/src/main/resources/assets/appliedenergistics2/lang/en_US.lang index 325f2996..f3567087 100644 --- a/src/main/resources/assets/appliedenergistics2/lang/en_US.lang +++ b/src/main/resources/assets/appliedenergistics2/lang/en_US.lang @@ -66,6 +66,9 @@ chat.appliedenergistics2.OutOfRange=Wireless Out Of Range. chat.appliedenergistics2.InvalidMachine=Invalid Machine. chat.appliedenergistics2.LoadedSettings=Successfully loaded settings. chat.appliedenergistics2.DeviceNotPowered=Device is low on power. +chat.appliedenergistics2.DeviceNotWirelessTerminal=Device is not a wireless terminal. +chat.appliedenergistics2.DeviceNotLinked=Device is not linked. +chat.appliedenergistics2.StationCanNotBeLocated=Station can not be located. chat.appliedenergistics2.MachineNotPowered=Machine is not powered. chat.appliedenergistics2.CommunicationError=Error Communicating with Network. chat.appliedenergistics2.SavedSettings=Successfully saved settings.