Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JustBru00 committed May 13, 2023
0 parents commit 5e993ec
Show file tree
Hide file tree
Showing 13 changed files with 1,066 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>timingsystem.bluemap</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
encoding/src=UTF-8
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=16
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
20 changes: 20 additions & 0 deletions CODE_LICENSE_HEADER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* TimingSystemBlueMap - This plugin will display track spawn locations as poi markers on bluemap.
* Copyright (C) 2023 Justin "JustBru00" Brubaker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @author Justin Brubaker
*
*/
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### TimingSystem BlueMap
This plugin is an addon for TimingSystem.

This plugin will display track spawn locations as poi markers on bluemap.
83 changes: 83 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.frosthex</groupId>
<artifactId>timingsystem.bluemap</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>timingsystem.bluemap</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.BlueMap-Minecraft</groupId>
<artifactId>BlueMapAPI</artifactId>
<version>v2.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Makkuusen</groupId>
<artifactId>TimingSystem</artifactId>
<version>a3dc47c</version>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
</project>
123 changes: 123 additions & 0 deletions src/com/frosthex/timingsystem/bluemap/TimingSystemBlueMapPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.frosthex.timingsystem.bluemap;

import java.util.Optional;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.frosthex.timingsystem.bluemap.utils.Messager;

import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.BlueMapWorld;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.api.markers.POIMarker;
import me.makkuusen.timing.system.api.TimingSystemAPI;
import me.makkuusen.timing.system.track.Track;

/**
* TimingSystemBlueMap - This plugin will display track spawn locations as poi markers on bluemap.
* Copyright (C) 2023 Justin "JustBru00" Brubaker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @author Justin Brubaker
*
*/
public class TimingSystemBlueMapPlugin extends JavaPlugin {

private static TimingSystemBlueMapPlugin instance;

public static ConsoleCommandSender clogger = Bukkit.getServer().getConsoleSender();
public static Logger log = Bukkit.getLogger();

public static String prefix = Messager.color("&8[&bTimingSystem&fBlueMap&8] &7");

@Override
public void onDisable() {
Messager.msgConsole("&6Disabled plugin.");
instance = null;
}

@SuppressWarnings("deprecation")
@Override
public void onEnable() {
instance = this;
Messager.msgConsole("&6Starting TimingSystemBlueMap " + getDescription().getVersion() + "...");

Plugin timingSystem = Bukkit.getPluginManager().getPlugin("TimingSystem");
if (timingSystem == null) {
// TimingSystem isn't installed.
Bukkit.getPluginManager().disablePlugin(instance);
return;
} else {
// TimingSystem version check
if (!timingSystem.getDescription().getVersion().contains("1.2")) {
Messager.msgConsole("&cTimingSystemBlueMap only supports TimingSystem version 1.2 at this time. The plugin will attempt to run but you may encounter errors.");
}
}

Bukkit.getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {

@Override
public void run() {
Messager.msgConsole("&6Adding track POI markers to BlueMap...");
Optional<BlueMapAPI> possibleApi = BlueMapAPI.getInstance();
if (!possibleApi.isPresent()) {
Messager.msgConsole("&cBlueMapAPI wasn't ready. Cancelling marker addition...");
return;
}
Messager.msgConsole("&6BlueMapAPI was ready...");
BlueMapAPI api = possibleApi.get();

MarkerSet markerSet = MarkerSet.builder().label("TimingSystem Track Locations").toggleable(true).build();

for (Track track : TimingSystemAPI.getTracks()) {
double x = track.getSpawnLocation().getX();
double y = track.getSpawnLocation().getY();
double z = track.getSpawnLocation().getZ();

POIMarker marker = POIMarker.builder()
.label(track.getCommandName())
.position(x, y, z)
.maxDistance(1000)
.build();

markerSet.getMarkers().put("tt-" + track.getCommandName(), marker);

Optional<BlueMapWorld> possibleWorld = api.getWorld(track.getSpawnLocation().getWorld());
if (!possibleWorld.isPresent()) {
Messager.msgConsole("&cBlueMapWorld wasn't able to be found... Cancelling...");
return;
}
Messager.msgConsole("&6BlueMapWorld loaded... Attempting to add the marker set...");
BlueMapWorld blueWorld = possibleWorld.get();

for (BlueMapMap map : blueWorld.getMaps()) {
map.getMarkerSets().put("timingsystem-bluemap-tracks", markerSet);
}

}

}
}, 20*60);
}

public static TimingSystemBlueMapPlugin getInstance() {
return instance;
}
}
96 changes: 96 additions & 0 deletions src/com/frosthex/timingsystem/bluemap/utils/Messager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @author Justin "JustBru00" Brubaker
*
* This is class is licensed under the MPL Version 2.0.
*/
package com.frosthex.timingsystem.bluemap.utils;

import java.awt.Color;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.frosthex.timingsystem.bluemap.TimingSystemBlueMapPlugin;

public class Messager {

private static final Pattern RGB_PATTERN = Pattern.compile("(&)?&#([0-9a-fA-F]{6})");

public static String color(String uncolored) {
return ChatColor.translateAlternateColorCodes('&', convertHexColorCodes(uncolored));
}

/**
* ISSUE #150
* Converts hex color codes.
* @param uncolored
* @return
*/
public static String convertHexColorCodes(String uncolored) {
StringBuffer builder = new StringBuffer();

Matcher matcher = RGB_PATTERN.matcher(uncolored);

while(matcher.find()) {
boolean escaped = (matcher.group(1) != null);

if (!escaped) {
try {
String hexColorCode = matcher.group(2);
matcher.appendReplacement(builder, parseHexColor(hexColorCode));
continue;
} catch (NumberFormatException e) {
//Ignore
}
}
matcher.appendReplacement(builder, "&#$2");
}
matcher.appendTail(builder);

return builder.toString();
}

/**
* @throws NumberFormatException If the provided hex color code is incorrect or if the version less than 1.16.
*/
public static String parseHexColor(String hexColor) throws NumberFormatException {
if (hexColor.startsWith("#")) {
hexColor = hexColor.substring(1);
}

if (hexColor.length() != 6) {
throw new NumberFormatException("Invalid Length");
}

Color.decode("#" + hexColor);

StringBuilder assembledColorCode = new StringBuilder();

assembledColorCode.append("\u00a7x");

for (char curChar : hexColor.toCharArray()) {
assembledColorCode.append("\u00a7").append(curChar);
}

return assembledColorCode.toString();
}

public static void msgConsole(String msg) {
if (TimingSystemBlueMapPlugin.clogger != null) {
TimingSystemBlueMapPlugin.clogger.sendMessage(TimingSystemBlueMapPlugin.prefix + Messager.color(msg));
} else {
TimingSystemBlueMapPlugin.log.info(ChatColor.stripColor(Messager.color(msg)));
}
}

public static void msgPlayer(String msg, Player player) {
player.sendMessage(TimingSystemBlueMapPlugin.prefix + Messager.color(msg));
}

public static void msgSender(String msg, CommandSender sender) {
sender.sendMessage(TimingSystemBlueMapPlugin.prefix + Messager.color(msg));
}
}
Loading

0 comments on commit 5e993ec

Please sign in to comment.