PR for 4.0.0 (Fuzzlemann) (5) (#267)

* Add check for the server key

* Fix Kill Detection when the player is killed by an Arrow

* Change some WorldTimes methods

* Fixes #260
Fixes JavaDoc at MathUtils

* Fix Error

* Fix Error
This commit is contained in:
Fuzzlemann 2017-08-21 20:29:40 +02:00 committed by Rsl1122
parent c74340f6f1
commit 9790b6cb73
9 changed files with 62 additions and 19 deletions

4
.gitignore vendored
View File

@ -13,3 +13,7 @@
/Filetool/build/ /Filetool/build/
/PlanPluginBridge/target/ /PlanPluginBridge/target/
/MakroS/nbproject/private/ /MakroS/nbproject/private/
*.xml
Plan/Plan.iml
Plan/.sonar/.sonar_lock
Plan/.sonar/report-task.txt

View File

@ -229,7 +229,7 @@ public class Plan extends BukkitPlugin<Plan> {
} }
} }
private final void initColorScheme() { private void initColorScheme() {
try { try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1)); ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1));
ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1)); ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1));
@ -458,6 +458,16 @@ public class Plan extends BukkitPlugin<Plan> {
return serverVariableHolder; return serverVariableHolder;
} }
/**
* Used to get the object storing server info
*
* @return ServerInfoManager
* @see ServerInfoManager
*/
public ServerInfoManager getServerInfoManager() {
return serverInfoManager;
}
public ProcessingQueue getProcessingQueue() { public ProcessingQueue getProcessingQueue() {
return processingQueue; return processingQueue;
} }

View File

@ -124,7 +124,7 @@ public class InspectCommand extends SubCommand {
} }
private void sendInspectMsg(ISender sender, String playerName, UUID uuid) { private void sendInspectMsg(ISender sender, String playerName, UUID uuid) {
sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT) + playerName); sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT) + " " + playerName);
// Link // Link
String url = HtmlUtils.getInspectUrlWithProtocol(playerName); String url = HtmlUtils.getInspectUrlWithProtocol(playerName);
String message = Locale.get(Msg.CMD_INFO_LINK).toString(); String message = Locale.get(Msg.CMD_INFO_LINK).toString();

View File

@ -13,6 +13,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.projectiles.ProjectileSource;
/** /**
* Event Listener for EntityDeathEvents. * Event Listener for EntityDeathEvents.
@ -87,6 +88,20 @@ public class PlanDeathEventListener implements Listener {
plugin.addToProcessQueue(new KillInfo(owner.getUniqueId(), time, dead, "Wolf")); plugin.addToProcessQueue(new KillInfo(owner.getUniqueId(), time, dead, "Wolf"));
} }
if (killerEntity instanceof Arrow) {
Arrow arrow = (Arrow) killerEntity;
ProjectileSource source = arrow.getShooter();
if (!(source instanceof Player)) {
return;
}
Player player = (Player) source;
plugin.addToProcessQueue(new KillInfo(player.getUniqueId(), time, dead, "Bow"));
}
} }
} }

View File

@ -71,9 +71,11 @@ public class WorldTimes {
} }
currentGMTimes.changeState(currentGamemode, changeTime); currentGMTimes.changeState(currentGamemode, changeTime);
} }
for (GMTimes gmTimes : worldTimes.values()) { for (GMTimes gmTimes : worldTimes.values()) {
gmTimes.setLastStateChange(changeTime); gmTimes.setLastStateChange(changeTime);
} }
currentWorld = worldName; currentWorld = worldName;
currentGamemode = gameMode; currentGamemode = gameMode;
} }
@ -86,10 +88,7 @@ public class WorldTimes {
*/ */
public long getWorldPlaytime(String world) { public long getWorldPlaytime(String world) {
GMTimes gmTimes = worldTimes.get(world); GMTimes gmTimes = worldTimes.get(world);
if (gmTimes != null) { return gmTimes != null ? gmTimes.getTotal() : 0;
return gmTimes.getTotal();
}
return 0;
} }
public long getTotal() { public long getTotal() {
@ -109,11 +108,7 @@ public class WorldTimes {
* @return GMTimes object with play times of each GameMode. * @return GMTimes object with play times of each GameMode.
*/ */
public GMTimes getGMTimes(String world) { public GMTimes getGMTimes(String world) {
GMTimes gmTimes = worldTimes.get(world); return worldTimes.getOrDefault(world, new GMTimes());
if (gmTimes != null) {
return gmTimes;
}
return new GMTimes();
} }
@Override @Override

View File

@ -308,11 +308,19 @@ public class WebServer {
} }
Map<String, String> variables = readVariables(response); Map<String, String> variables = readVariables(response);
String key = variables.get("key");
//TODO ADD CHECK IF SERVER KEY VALID
Plan plan = Plan.getInstance(); Plan plan = Plan.getInstance();
if (!checkKey(plan, key)) {
String error = "Server Key not given or invalid";
return PageCacheHandler.loadPage(error, () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
});
}
WebAPI api = WebAPIManager.getAPI(method); WebAPI api = WebAPIManager.getAPI(method);
if (api == null) { if (api == null) {
@ -328,6 +336,18 @@ public class WebServer {
} }
} }
private boolean checkKey(Plan plan, String key) {
UUID uuid = plan.getServerInfoManager().getServerUUID();
UUID keyUUID;
try {
keyUUID = UUID.fromString(key);
} catch (IllegalArgumentException e) {
return false;
}
return uuid.equals(keyUUID);
}
private Map<String, String> readVariables(String response) { private Map<String, String> readVariables(String response) {
String[] variables = response.split("&"); String[] variables = response.split("&");

View File

@ -35,7 +35,7 @@ public class InspectWebAPI implements WebAPI {
return PageCacheHandler.loadPage(error, () -> new BadRequestResponse(error)); return PageCacheHandler.loadPage(error, () -> new BadRequestResponse(error));
} }
Plan.getInstance().getInspectCache().cache(uuid); plan.getInspectCache().cache(uuid);
return PageCacheHandler.loadPage("success", SuccessResponse::new); return PageCacheHandler.loadPage("success", SuccessResponse::new);
} }

View File

@ -152,7 +152,7 @@ public class MathUtils {
/** /**
* Gets the biggest Integer in a Collection with Integer as Entry * Gets the biggest Integer in a Collection with Integer as Entry
* If the Collection is empty, it will return 0. * If the Collection is empty, it will return 1.
* *
* @param values The Collection with Integer as the Entry * @param values The Collection with Integer as the Entry
* @return The biggest Integer * @return The biggest Integer
@ -166,7 +166,7 @@ public class MathUtils {
/** /**
* Gets the biggest Long in a Collection with Long as Entry * Gets the biggest Long in a Collection with Long as Entry
* If the Collection is empty, it will return 0. * If the Collection is empty, it will return 1.
* *
* @param values The Collection with Long as the Entry * @param values The Collection with Long as the Entry
* @return The biggest Integer * @return The biggest Integer

View File

@ -28,5 +28,4 @@ public class PermissionsTest {
public void testGetPermission() { public void testGetPermission() {
assertEquals("plan.inspect.other", Permissions.INSPECT_OTHER.getPerm()); assertEquals("plan.inspect.other", Permissions.INSPECT_OTHER.getPerm());
} }
} }