Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# Waypoints

## Dependencies

The plugin relies on the
[btc-ascii-table](https://code.google.com/archive/p/java-ascii-table/)
java library.

## Installation


### Dependency setup
After setting up the maven project make sure to install the dependencies
```bash
cd <project-dir>
mkdir lib && cd lib
curl -O https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/java-ascii-table/btc-ascii-table-1.0.jar
cd ..
mvn install:install-file -Dfile=lib/btc-ascii-table-1.0.jar -DgroupId=com.bethecoder -DartifactId=ascii-table -Dversion=1.0 -Dpackaging=jar
```
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,5 @@
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.bethecoder</groupId>
<artifactId>ascii-table</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
9 changes: 0 additions & 9 deletions src/main/java/org/scorp/waypoints/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -49,11 +47,4 @@ public static void sendTCPMessage(String serverAddress, int port,
e.printStackTrace();
}
}

public static String getDateString()
{
final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
return sdf.format(date);
}
}
51 changes: 11 additions & 40 deletions src/main/java/org/scorp/waypoints/Waypoint/WaypointManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.scorp.waypoints.Waypoint;

import com.bethecoder.ascii_table.ASCIITable;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -161,7 +160,7 @@ public static void onTimeElapsed()
}

requiresDiscordUpdate = false;
Utils.sendTCPMessage(host, port, getDiscordMessage());
Utils.sendTCPMessage(host, port, getDiscordCsv());
}

private static void readWaypoints()
Expand Down Expand Up @@ -199,45 +198,17 @@ private static void updateRequiresDiscordUpdate(boolean condition)
requiresDiscordUpdate = requiresDiscordUpdate || condition;
}

private static String getDiscordMessage()
private static String getDiscordCsv()
{
ArrayList<Waypoint> publicWaypoints = getPublicWaypoints();
if (publicWaypoints.size() == 0)
{
return "No publicly shared waypoints available.";
}

String tableName =
"Publicly shared waypoints" + "(updated: " + Utils.getDateString() +
")\n";
String[] tableHeaders = {"Owner", "Name", "world", "(x, y, z)"};
String[][] tableData = publicWaypoints.stream().sorted().map(
(waypoint) -> new String[]{waypoint.ownerName, waypoint.waypointName,
waypoint.worldName,
"(" + waypoint.x + ", " + waypoint.y + ", " + waypoint.z + ")"})
.collect(Collectors.toCollection(ArrayList::new))
.toArray(new String[0][0]);

String lastOwner, lastWorld;
lastWorld = lastOwner = "";
for (String[] entry : tableData)
{
String owner = entry[0];
String world = entry[2];
if (owner.equals(lastOwner))
{
entry[0] = "";
}
if (world.equals(lastWorld))
{
entry[2] = "";
}

lastOwner = owner;
lastWorld = world;
}
StringBuilder csv = new StringBuilder("owner,name,world,x,y,z\n");
getPublicWaypoints().stream().sorted().forEach(
(waypoint) -> csv.append(waypoint.ownerName).append(',')
.append(waypoint.waypointName).append(',')
.append(waypoint.worldName).append(',')
.append(waypoint.x).append(',')
.append(waypoint.y).append(',')
.append(waypoint.z).append('\n'));

return tableName +
ASCIITable.getInstance().getTable(tableHeaders, tableData);
return csv.toString();
}
}