Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Started work on border transfer. Hotfix for counties.
Browse files Browse the repository at this point in the history
  • Loading branch information
noahhusby committed Aug 6, 2020
1 parent 012125d commit 1e3bb6e
Show file tree
Hide file tree
Showing 44 changed files with 34,516 additions and 94 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/gradle.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/maven.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Sledgehammer [Bungeecord]/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.noahhusby</groupId>
<artifactId>Sledgehammer</artifactId>
<version>0.1-bungeecord</version>
<version>0.2.2-bungeecord</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion Sledgehammer [Bungeecord]/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.noahhusby</groupId>
<artifactId>Sledgehammer</artifactId>
<version>0.1-bungeecord</version>
<version>0.2.2-bungeecord</version>
<repositories>
<repository>
<id>bungeecord-repo</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.noahhusby.sledgehammer;

public class Constants {
public static final String PLUGINID = "sledgehammer";
public static final String VERSION = "0.2.2";
public static final double SCALE = 7318261.522857145;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.noahhusby.sledgehammer.commands.CsTpllCommand;
import com.noahhusby.sledgehammer.commands.SledgehammerCommand;
import com.noahhusby.sledgehammer.commands.TpllCommand;
import com.noahhusby.sledgehammer.commands.WarpCommand;
import com.noahhusby.sledgehammer.datasets.OpenStreetMaps;
import com.noahhusby.sledgehammer.handlers.CommunicationHandler;
import com.noahhusby.sledgehammer.handlers.PlayerLocationHandler;
import com.noahhusby.sledgehammer.handlers.WarpHandler;
import com.noahhusby.sledgehammer.util.Warp;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
Expand All @@ -24,6 +28,7 @@

import java.io.*;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.logging.Logger;

Expand All @@ -50,17 +55,33 @@ public void onEnable() {
ProxyServer.getInstance().getPluginManager().registerCommand(this, new CsTpllCommand());
}

ProxyServer.getInstance().getPluginManager().registerCommand(this, new SledgehammerCommand());

ProxyServer.getInstance().registerChannel("sledgehammer:channel");
ProxyServer.getInstance().getPluginManager().registerListener(this, this);

OpenStreetMaps.getInstance();

getProxy().getScheduler().schedule(this, () -> {

}, 10, TimeUnit.SECONDS);
}

@EventHandler
public void onMessage(PluginMessageEvent e) {
CommunicationHandler.onIncomingMessage(e);
}

@EventHandler
public void onPlayerJoin(PostLoginEvent e) {
PlayerLocationHandler.getInstance().onPlayerJoin(e.getPlayer());
}

@EventHandler
public void onPlayerLeave(PlayerDisconnectEvent e) {
PlayerLocationHandler.getInstance().onPlayerQuit(e.getPlayer());
}


private void initConfig() {
createConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.noahhusby.sledgehammer.commands;

import com.noahhusby.sledgehammer.util.ChatHelper;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;

public class SledgehammerCommand extends Command {
public SledgehammerCommand() {
super("sledgehammer");
}

@Override
public void execute(CommandSender commandSender, String[] strings) {
ChatHelper.getInstance().infoMessage(commandSender);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.noahhusby.sledgehammer.datasets;


import com.noahhusby.sledgehammer.Constants;
import com.noahhusby.sledgehammer.Sledgehammer;
import com.noahhusby.sledgehammer.util.Location;
import com.noahhusby.sledgehammer.util.ProxyUtil;
Expand Down Expand Up @@ -50,9 +51,17 @@ public ServerInfo getServerFromLocation(double lon, double lat) {
}
break;
case "county":
if(location.county.equals(regionData[1].trim()) &&
location.state.equals(regionData[2].trim())) {
return ProxyUtil.getServerFromName(server);
if(regionData.length==4) {
if(location.county.equals(regionData[1].trim()) &&
location.state.equals(regionData[2].trim()) &&
location.country.equals(regionData[3].trim())) {
return ProxyUtil.getServerFromName(server);
}
} else {
if(location.county.equals(regionData[1].trim()) &&
location.state.equals(regionData[2].trim())) {
return ProxyUtil.getServerFromName(server);
}
}
break;
case "state":
Expand Down Expand Up @@ -82,7 +91,7 @@ private Location getLocation(double lon, double lat) {

URL url = new URL(fullRequest);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestProperty("User-Agent", "sledgehammer/1.0");
con.setRequestProperty("User-Agent", Constants.PLUGINID+"/"+Constants.VERSION);
con.setRequestProperty("Accept", "application/json");

try(BufferedReader br = new BufferedReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public static void onIncomingMessage(PluginMessageEvent e) {
if(args.length < 3) return;
if(!args[1].equals(Sledgehammer.configuration.getString("authentication-key"))) return;
switch (args[4]) {
case "WARP_LOC":
case "POS":
WarpHandler.getInstance().incomingLocationResponse(args[3], new Point(args[5].replaceAll("[^\\d-]", ""),
args[6].replaceAll("[^\\d-]", ""), args[7].replaceAll("[^\\d-]", "")));
PlayerLocationHandler.getInstance().updateLocation(args[3], new Point(args[5].replaceAll("[^\\d-]", ""),
args[6].replaceAll("[^\\d-]", ""), args[7].replaceAll("[^\\d-]", "")));
break;
}
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.noahhusby.sledgehammer.handlers;

import com.google.common.collect.Maps;
import com.noahhusby.sledgehammer.Constants;
import com.noahhusby.sledgehammer.Sledgehammer;
import com.noahhusby.sledgehammer.projection.GeographicProjection;
import com.noahhusby.sledgehammer.projection.ModifiedAirocean;
import com.noahhusby.sledgehammer.projection.ScaleProjection;
import com.noahhusby.sledgehammer.util.Point;
import com.noahhusby.sledgehammer.util.ProxyUtil;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.Map;

public class PlayerLocationHandler {
private static PlayerLocationHandler mInstance = null;

public static PlayerLocationHandler getInstance() {
if(mInstance == null) mInstance = new PlayerLocationHandler();
return mInstance;
}

Map<ProxiedPlayer, Point> playerLocations = Maps.newHashMap();
Map<ProxiedPlayer, Integer> playerRecall = Maps.newHashMap();

private PlayerLocationHandler() {}

public void onPlayerJoin(ProxiedPlayer player) {
playerLocations.remove(player);
}

public void onPlayerQuit(ProxiedPlayer player) {
playerLocations.remove(player);
}

public void updateLocation(String sender, Point point) {
if(false) {
//if(!ProxyUtil.isServerRegional(ProxyUtil.getServerFromPlayerName(sender))) return;
GeographicProjection projection = new ModifiedAirocean();
GeographicProjection uprightProj = GeographicProjection.orientProjection(projection, GeographicProjection.Orientation.upright);
ScaleProjection scaleProj = new ScaleProjection(uprightProj, Constants.SCALE, Constants.SCALE);

double proj[] = scaleProj.toGeo(Double.parseDouble(point.x), Double.parseDouble(point.z));
Sledgehammer.logger.info("Location: "+proj[0]+", "+proj[1]);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Warp getWarp(String w) {
public void requestNewWarp(String warp, CommandSender sender) {
requestedWarps.put(sender.getName(), warp);
CommunicationHandler.executeRequest(ProxyServer.getInstance().getPlayer(sender.getName()).getServer().getInfo(),
sender.getName(), "WARP_LOC");
sender.getName(), "POS");
}

public void removeWarp(String w, CommandSender sender) {
Expand Down
Loading

0 comments on commit 1e3bb6e

Please sign in to comment.