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

6
.gitignore vendored
View File

@ -12,4 +12,8 @@
/Filetool/nbproject/private/
/Filetool/build/
/PlanPluginBridge/target/
/MakroS/nbproject/private/
/MakroS/nbproject/private/
*.xml
Plan/Plan.iml
Plan/.sonar/.sonar_lock
Plan/.sonar/report-task.txt

View File

@ -191,7 +191,7 @@ public class Plan extends BukkitPlugin<Plan> {
}
Benchmark.start("ServerInfo Registration");
serverInfoManager = new ServerInfoManager(this);
serverInfoManager = new ServerInfoManager(this);
Benchmark.stop("Enable", "ServerInfo Registration");
setupFilter(); // TODO Move to RegisterCommand Constructor
@ -229,7 +229,7 @@ public class Plan extends BukkitPlugin<Plan> {
}
}
private final void initColorScheme() {
private void initColorScheme() {
try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.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;
}
/**
* Used to get the object storing server info
*
* @return ServerInfoManager
* @see ServerInfoManager
*/
public ServerInfoManager getServerInfoManager() {
return serverInfoManager;
}
public ProcessingQueue getProcessingQueue() {
return processingQueue;
}

View File

@ -124,7 +124,7 @@ public class InspectCommand extends SubCommand {
}
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
String url = HtmlUtils.getInspectUrlWithProtocol(playerName);
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.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.projectiles.ProjectileSource;
/**
* Event Listener for EntityDeathEvents.
@ -87,6 +88,20 @@ public class PlanDeathEventListener implements Listener {
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);
}
for (GMTimes gmTimes : worldTimes.values()) {
gmTimes.setLastStateChange(changeTime);
}
currentWorld = worldName;
currentGamemode = gameMode;
}
@ -86,10 +88,7 @@ public class WorldTimes {
*/
public long getWorldPlaytime(String world) {
GMTimes gmTimes = worldTimes.get(world);
if (gmTimes != null) {
return gmTimes.getTotal();
}
return 0;
return gmTimes != null ? gmTimes.getTotal() : 0;
}
public long getTotal() {
@ -109,11 +108,7 @@ public class WorldTimes {
* @return GMTimes object with play times of each GameMode.
*/
public GMTimes getGMTimes(String world) {
GMTimes gmTimes = worldTimes.get(world);
if (gmTimes != null) {
return gmTimes;
}
return new GMTimes();
return worldTimes.getOrDefault(world, new GMTimes());
}
@Override

View File

@ -308,11 +308,19 @@ public class WebServer {
}
Map<String, String> variables = readVariables(response);
//TODO ADD CHECK IF SERVER KEY VALID
String key = variables.get("key");
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);
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) {
String[] variables = response.split("&");

View File

@ -35,7 +35,7 @@ public class InspectWebAPI implements WebAPI {
return PageCacheHandler.loadPage(error, () -> new BadRequestResponse(error));
}
Plan.getInstance().getInspectCache().cache(uuid);
plan.getInspectCache().cache(uuid);
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
* 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
* @return The biggest Integer
@ -166,7 +166,7 @@ public class MathUtils {
/**
* 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
* @return The biggest Integer

View File

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