ground markers plugin: Clean up legacy code
This includes various code quality improvements such as stronger access control, enforcing newlines at EOF, naming magic numbers and strings, and utilizing higher efficiency methods and class constructors.
This commit is contained in:
committed by
Tomas Slusny
parent
39bbf2f259
commit
285926924b
@@ -23,7 +23,6 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.plugins.groundmarkers;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
@@ -64,4 +64,4 @@ public class GroundMarkerInputListener implements KeyListener
|
||||
plugin.setHotKeyPressed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
|
||||
public class GroundMarkerOverlay extends Overlay
|
||||
{
|
||||
private static final int MAX_DRAW_DISTANCE = 32;
|
||||
|
||||
private final Client client;
|
||||
private final GroundMarkerConfig config;
|
||||
private final GroundMarkerPlugin plugin;
|
||||
@@ -78,7 +80,7 @@ public class GroundMarkerOverlay extends Overlay
|
||||
{
|
||||
WorldPoint playerLocation = client.getLocalPlayer().getWorldLocation();
|
||||
|
||||
if (point.distanceTo(playerLocation) >= 32)
|
||||
if (point.distanceTo(playerLocation) >= MAX_DRAW_DISTANCE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -97,4 +99,4 @@ public class GroundMarkerOverlay extends Overlay
|
||||
|
||||
OverlayUtil.renderPolygon(graphics, poly, config.markerColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,8 +69,9 @@ public class GroundMarkerPlugin extends Plugin
|
||||
private static final String CONFIG_GROUP = "groundMarker";
|
||||
private static final String MARK = "Mark tile";
|
||||
private static final String WALK_HERE = "Walk here";
|
||||
private static final String REGION_PREFIX = "region_";
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
@@ -101,24 +102,26 @@ public class GroundMarkerPlugin extends Plugin
|
||||
{
|
||||
if (points == null || points.isEmpty())
|
||||
{
|
||||
configManager.unsetConfiguration(CONFIG_GROUP, "region_" + regionId);
|
||||
configManager.unsetConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId);
|
||||
return;
|
||||
}
|
||||
|
||||
String json = gson.toJson(points);
|
||||
configManager.setConfiguration(CONFIG_GROUP, "region_" + regionId, json);
|
||||
String json = GSON.toJson(points);
|
||||
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
|
||||
}
|
||||
|
||||
private Collection<GroundMarkerPoint> getPoints(int regionId)
|
||||
{
|
||||
String json = configManager.getConfiguration(CONFIG_GROUP, "region_" + regionId);
|
||||
String json = configManager.getConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId);
|
||||
if (Strings.isNullOrEmpty(json))
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return gson.fromJson(json, new TypeToken<List<GroundMarkerPoint>>()
|
||||
{
|
||||
}.getType());
|
||||
return GSON.fromJson(json, new GroundMarkerListTypeToken().getType());
|
||||
}
|
||||
|
||||
private static class GroundMarkerListTypeToken extends TypeToken<List<GroundMarkerPoint>>
|
||||
{
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -238,8 +241,7 @@ public class GroundMarkerPlugin extends Plugin
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
|
||||
protected void markTile(LocalPoint localPoint)
|
||||
private void markTile(LocalPoint localPoint)
|
||||
{
|
||||
if (localPoint == null)
|
||||
{
|
||||
@@ -266,4 +268,4 @@ public class GroundMarkerPlugin extends Plugin
|
||||
|
||||
loadPoints();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,15 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.plugins.groundmarkers;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class GroundMarkerPoint
|
||||
class GroundMarkerPoint
|
||||
{
|
||||
private int regionId;
|
||||
private int regionX;
|
||||
private int regionY;
|
||||
private int z;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user