From 33bbf6457f144cfc656a66625574a2992a36a460 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Mon, 4 Jul 2016 16:57:23 +0200 Subject: [PATCH] Ajouts/suppression de librairies (sources) + Ajout support basique 1.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Transfert de la librairie com.luckycatlabs.sunrisesunset vers un autre module Pandacube. - Ajout de l'utilitaire OfflineUUID développé précédemment hors projet. - Ajout de Minecraft 1.10 dans l'enum des versions de Minecraft - Ajout d'une libraire d'accès aux anciens pseudos des joueurs - L'historique de login enregistre des informations supplémentaires (pseudo actuel, version de MC) - ORM : retrait des SuppressWarnings("rawtypes") et ajout des pour retirer proprement ces warnings --- .../SunriseSunsetCalculator.java | 290 ------------- .../luckycatlabs/sunrisesunset/Zenith.java | 46 -- .../calculator/SolarEventCalculator.java | 406 ------------------ .../sunrisesunset/dto/Location.java | 93 ---- src/fr/pandacube/java/BungeeMain.java | 2 +- src/fr/pandacube/java/PandacubeUtil.java | 22 +- src/fr/pandacube/java/SpigotMain.java | 2 +- .../ConvertToSQLBungeePerms.java | 84 ---- .../java/external_tools/OfflineUUID.java | 35 ++ .../pandacube/java/util/MinecraftVersion.java | 3 +- .../java/util/PlayerNameHistoryLookup.java | 121 ++++++ .../java/util/db/LoginHistoryElement.java | 53 ++- .../java/util/db/LoginHistoryTable.java | 8 +- src/fr/pandacube/java/util/db/ORM.java | 25 +- 14 files changed, 242 insertions(+), 948 deletions(-) delete mode 100644 src/com/luckycatlabs/sunrisesunset/SunriseSunsetCalculator.java delete mode 100644 src/com/luckycatlabs/sunrisesunset/Zenith.java delete mode 100644 src/com/luckycatlabs/sunrisesunset/calculator/SolarEventCalculator.java delete mode 100644 src/com/luckycatlabs/sunrisesunset/dto/Location.java delete mode 100644 src/fr/pandacube/java/external_tools/ConvertToSQLBungeePerms.java create mode 100644 src/fr/pandacube/java/external_tools/OfflineUUID.java create mode 100644 src/fr/pandacube/java/util/PlayerNameHistoryLookup.java diff --git a/src/com/luckycatlabs/sunrisesunset/SunriseSunsetCalculator.java b/src/com/luckycatlabs/sunrisesunset/SunriseSunsetCalculator.java deleted file mode 100644 index e14b0d9..0000000 --- a/src/com/luckycatlabs/sunrisesunset/SunriseSunsetCalculator.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright 2008-2009 Mike Reedell / LuckyCatLabs. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.luckycatlabs.sunrisesunset; - -import java.util.Calendar; -import java.util.TimeZone; - -import com.luckycatlabs.sunrisesunset.calculator.SolarEventCalculator; -import com.luckycatlabs.sunrisesunset.dto.Location; - -/** - * Public interface for getting the various types of sunrise/sunset. - */ -public class SunriseSunsetCalculator { - - private Location location; - - private SolarEventCalculator calculator; - - /** - * Constructs a new SunriseSunsetCalculator with the given Location - * - * @param location - * Location object containing the Latitude/Longitude of the location to compute - * the sunrise/sunset for. - * @param timeZoneIdentifier - * String identifier for the timezone to compute the sunrise/sunset times in. In the form - * "America/New_York". Please see the zi directory under the JDK installation for supported - * time zones. - */ - public SunriseSunsetCalculator(Location location, String timeZoneIdentifier) { - this.location = location; - this.calculator = new SolarEventCalculator(location, timeZoneIdentifier); - } - - /** - * Constructs a new SunriseSunsetCalculator with the given Location - * - * @param location - * Location object containing the Latitude/Longitude of the location to compute - * the sunrise/sunset for. - * @param timeZone - * timezone to compute the sunrise/sunset times in. - */ - public SunriseSunsetCalculator(Location location, TimeZone timeZone) { - this.location = location; - this.calculator = new SolarEventCalculator(location, timeZone); - } - - /** - * Returns the astronomical (108deg) sunrise for the given date. - * - * @param date - * Calendar object containing the date to compute the astronomical sunrise for. - * @return the astronomical sunrise time in HH:MM (24-hour clock) form. - */ - public String getAstronomicalSunriseForDate(Calendar date) { - return calculator.computeSunriseTime(Zenith.ASTRONOMICAL, date); - } - - /** - * Returns the astronomical (108deg) sunrise for the given date. - * - * @param date - * Calendar object containing the date to compute the astronomical sunrise for. - * @return the astronomical sunrise time as a Calendar - */ - public Calendar getAstronomicalSunriseCalendarForDate(Calendar date) { - return calculator.computeSunriseCalendar(Zenith.ASTRONOMICAL, date); - } - - /** - * Returns the astronomical (108deg) sunset for the given date. - * - * @param date - * Calendar object containing the date to compute the astronomical sunset for. - * @return the astronomical sunset time in HH:MM (24-hour clock) form. - */ - public String getAstronomicalSunsetForDate(Calendar date) { - return calculator.computeSunsetTime(Zenith.ASTRONOMICAL, date); - } - - /** - * Returns the astronomical (108deg) sunset for the given date. - * - * @param date - * Calendar object containing the date to compute the astronomical sunset for. - * @return the astronomical sunset time as a Calendar - */ - public Calendar getAstronomicalSunsetCalendarForDate(Calendar date) { - return calculator.computeSunsetCalendar(Zenith.ASTRONOMICAL, date); - } - - /** - * Returns the nautical (102deg) sunrise for the given date. - * - * @param date - * Calendar object containing the date to compute the nautical sunrise for. - * @return the nautical sunrise time in HH:MM (24-hour clock) form. - */ - public String getNauticalSunriseForDate(Calendar date) { - return calculator.computeSunriseTime(Zenith.NAUTICAL, date); - } - - /** - * Returns the nautical (102deg) sunrise for the given date. - * - * @param date - * Calendar object containing the date to compute the nautical sunrise for. - * @return the nautical sunrise time as a Calendar - */ - public Calendar getNauticalSunriseCalendarForDate(Calendar date) { - return calculator.computeSunriseCalendar(Zenith.NAUTICAL, date); - } - - /** - * Returns the nautical (102deg) sunset for the given date. - * - * @param date - * Calendar object containing the date to compute the nautical sunset for. - * @return the nautical sunset time in HH:MM (24-hour clock) form. - */ - public String getNauticalSunsetForDate(Calendar date) { - return calculator.computeSunsetTime(Zenith.NAUTICAL, date); - } - - /** - * Returns the nautical (102deg) sunset for the given date. - * - * @param date - * Calendar object containing the date to compute the nautical sunset for. - * @return the nautical sunset time as a Calendar - */ - public Calendar getNauticalSunsetCalendarForDate(Calendar date) { - return calculator.computeSunsetCalendar(Zenith.NAUTICAL, date); - } - - /** - * Returns the civil sunrise (twilight, 96deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the civil sunrise for. - * @return the civil sunrise time in HH:MM (24-hour clock) form. - */ - public String getCivilSunriseForDate(Calendar date) { - return calculator.computeSunriseTime(Zenith.CIVIL, date); - } - - /** - * Returns the civil sunrise (twilight, 96deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the civil sunrise for. - * @return the civil sunrise time as a Calendar - */ - public Calendar getCivilSunriseCalendarForDate(Calendar date) { - return calculator.computeSunriseCalendar(Zenith.CIVIL, date); - } - - /** - * Returns the civil sunset (twilight, 96deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the civil sunset for. - * @return the civil sunset time in HH:MM (24-hour clock) form. - */ - public String getCivilSunsetForDate(Calendar date) { - return calculator.computeSunsetTime(Zenith.CIVIL, date); - } - - /** - * Returns the civil sunset (twilight, 96deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the civil sunset for. - * @return the civil sunset time as a Calendar - */ - public Calendar getCivilSunsetCalendarForDate(Calendar date) { - return calculator.computeSunsetCalendar(Zenith.CIVIL, date); - } - - /** - * Returns the official sunrise (90deg 50', 90.8333deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the official sunrise for. - * @return the official sunrise time in HH:MM (24-hour clock) form. - */ - public String getOfficialSunriseForDate(Calendar date) { - return calculator.computeSunriseTime(Zenith.OFFICIAL, date); - } - - /** - * Returns the official sunrise (90deg 50', 90.8333deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the official sunrise for. - * @return the official sunrise time as a Calendar - */ - public Calendar getOfficialSunriseCalendarForDate(Calendar date) { - return calculator.computeSunriseCalendar(Zenith.OFFICIAL, date); - } - - /** - * Returns the official sunrise (90deg 50', 90.8333deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the official sunset for. - * @return the official sunset time in HH:MM (24-hour clock) form. - */ - public String getOfficialSunsetForDate(Calendar date) { - return calculator.computeSunsetTime(Zenith.OFFICIAL, date); - } - - /** - * Returns the official sunrise (90deg 50', 90.8333deg) for the given date. - * - * @param date - * Calendar object containing the date to compute the official sunset for. - * @return the official sunset time as a Calendar - */ - public Calendar getOfficialSunsetCalendarForDate(Calendar date) { - return calculator.computeSunsetCalendar(Zenith.OFFICIAL, date); - } - - /** - * Computes the sunrise for an arbitrary declination. - * - * @param latitude - * @param longitude - * Coordinates for the location to compute the sunrise/sunset for. - * @param timeZone - * timezone to compute the sunrise/sunset times in. - * @param date - * Calendar object containing the date to compute the official sunset for. - * @param degrees - * Angle under the horizon for which to compute sunrise. For example, "civil sunrise" - * corresponds to 6 degrees. - * @return the requested sunset time as a Calendar object. - */ - - public static Calendar getSunrise(double latitude, double longitude, TimeZone timeZone, Calendar date, double degrees) { - SolarEventCalculator solarEventCalculator = new SolarEventCalculator(new Location(latitude, longitude), timeZone); - return solarEventCalculator.computeSunriseCalendar(new Zenith(90 - degrees), date); - } - - /** - * Computes the sunset for an arbitrary declination. - * - * @param latitude - * @param longitude - * Coordinates for the location to compute the sunrise/sunset for. - * @param timeZone - * timezone to compute the sunrise/sunset times in. - * @param date - * Calendar object containing the date to compute the official sunset for. - * @param degrees - * Angle under the horizon for which to compute sunrise. For example, "civil sunset" - * corresponds to 6 degrees. - * @return the requested sunset time as a Calendar object. - */ - - public static Calendar getSunset(double latitude, double longitude, TimeZone timeZone, Calendar date, double degrees) { - SolarEventCalculator solarEventCalculator = new SolarEventCalculator(new Location(latitude, longitude), timeZone); - return solarEventCalculator.computeSunsetCalendar(new Zenith(90 - degrees), date); - } - - /** - * Returns the location where the sunrise/sunset is calculated for. - * - * @return Location object representing the location of the computed sunrise/sunset. - */ - public Location getLocation() { - return location; - } -} diff --git a/src/com/luckycatlabs/sunrisesunset/Zenith.java b/src/com/luckycatlabs/sunrisesunset/Zenith.java deleted file mode 100644 index 7157d38..0000000 --- a/src/com/luckycatlabs/sunrisesunset/Zenith.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2008-2009 Mike Reedell / LuckyCatLabs. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.luckycatlabs.sunrisesunset; - -import java.math.BigDecimal; - -/** - * Defines the solar declination used in computing the sunrise/sunset. - */ -public class Zenith { - /** Astronomical sunrise/set is when the sun is 18 degrees below the horizon. */ - public static final Zenith ASTRONOMICAL = new Zenith(108); - - /** Nautical sunrise/set is when the sun is 12 degrees below the horizon. */ - public static final Zenith NAUTICAL = new Zenith(102); - - /** Civil sunrise/set (dawn/dusk) is when the sun is 6 degrees below the horizon. */ - public static final Zenith CIVIL = new Zenith(96); - - /** Official sunrise/set is when the sun is 50' below the horizon. */ - public static final Zenith OFFICIAL = new Zenith(90.8333); - - private final BigDecimal degrees; - - public Zenith(double degrees) { - this.degrees = BigDecimal.valueOf(degrees); - } - - public BigDecimal degrees() { - return degrees; - } -} diff --git a/src/com/luckycatlabs/sunrisesunset/calculator/SolarEventCalculator.java b/src/com/luckycatlabs/sunrisesunset/calculator/SolarEventCalculator.java deleted file mode 100644 index 323fc7a..0000000 --- a/src/com/luckycatlabs/sunrisesunset/calculator/SolarEventCalculator.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright 2008-2009 Mike Reedell / LuckyCatLabs. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.luckycatlabs.sunrisesunset.calculator; - -import java.math.BigDecimal; -import java.math.MathContext; -import java.math.RoundingMode; -import java.util.Calendar; -import java.util.TimeZone; - -import com.luckycatlabs.sunrisesunset.Zenith; -import com.luckycatlabs.sunrisesunset.dto.Location; - -/** - * Parent class of the Sunrise and Sunset calculator classes. - */ -public class SolarEventCalculator { - final private Location location; - final private TimeZone timeZone; - - /** - * Constructs a new SolarEventCalculator using the given parameters. - * - * @param location - * Location of the place where the solar event should be calculated from. - * @param timeZoneIdentifier - * time zone identifier of the timezone of the location parameter. For example, - * "America/New_York". - */ - public SolarEventCalculator(Location location, String timeZoneIdentifier) { - this.location = location; - this.timeZone = TimeZone.getTimeZone(timeZoneIdentifier); - } - - /** - * Constructs a new SolarEventCalculator using the given parameters. - * - * @param location - * Location of the place where the solar event should be calculated from. - * @param timeZone - * timezone of the location parameter. - */ - public SolarEventCalculator(Location location, TimeZone timeZone) { - this.location = location; - this.timeZone = timeZone; - } - - /** - * Computes the sunrise time for the given zenith at the given date. - * - * @param solarZenith - * Zenith enum corresponding to the type of sunrise to compute. - * @param date - * Calendar object representing the date to compute the sunrise for. - * @return the sunrise time, in HH:MM format (24-hour clock), 00:00 if the sun does not rise on the given - * date. - */ - public String computeSunriseTime(Zenith solarZenith, Calendar date) { - return getLocalTimeAsString(computeSolarEventTime(solarZenith, date, true)); - } - - /** - * Computes the sunrise time for the given zenith at the given date. - * - * @param solarZenith - * Zenith enum corresponding to the type of sunrise to compute. - * @param date - * Calendar object representing the date to compute the sunrise for. - * @return the sunrise time as a calendar or null for no sunrise - */ - public Calendar computeSunriseCalendar(Zenith solarZenith, Calendar date) { - return getLocalTimeAsCalendar(computeSolarEventTime(solarZenith, date, true), date); - } - - /** - * Computes the sunset time for the given zenith at the given date. - * - * @param solarZenith - * Zenith enum corresponding to the type of sunset to compute. - * @param date - * Calendar object representing the date to compute the sunset for. - * @return the sunset time, in HH:MM format (24-hour clock), 00:00 if the sun does not set on the given - * date. - */ - public String computeSunsetTime(Zenith solarZenith, Calendar date) { - return getLocalTimeAsString(computeSolarEventTime(solarZenith, date, false)); - } - - /** - * Computes the sunset time for the given zenith at the given date. - * - * @param solarZenith - * Zenith enum corresponding to the type of sunset to compute. - * @param date - * Calendar object representing the date to compute the sunset for. - * @return the sunset time as a Calendar or null for no sunset. - */ - public Calendar computeSunsetCalendar(Zenith solarZenith, Calendar date) { - return getLocalTimeAsCalendar(computeSolarEventTime(solarZenith, date, false), date); - } - - private BigDecimal computeSolarEventTime(Zenith solarZenith, Calendar date, boolean isSunrise) { - date.setTimeZone(this.timeZone); - BigDecimal longitudeHour = getLongitudeHour(date, isSunrise); - - BigDecimal meanAnomaly = getMeanAnomaly(longitudeHour); - BigDecimal sunTrueLong = getSunTrueLongitude(meanAnomaly); - BigDecimal cosineSunLocalHour = getCosineSunLocalHour(sunTrueLong, solarZenith); - if ((cosineSunLocalHour.doubleValue() < -1.0) || (cosineSunLocalHour.doubleValue() > 1.0)) { - return null; - } - - BigDecimal sunLocalHour = getSunLocalHour(cosineSunLocalHour, isSunrise); - BigDecimal localMeanTime = getLocalMeanTime(sunTrueLong, longitudeHour, sunLocalHour); - BigDecimal localTime = getLocalTime(localMeanTime, date); - return localTime; - } - - /** - * Computes the base longitude hour, lngHour in the algorithm. - * - * @return the longitude of the location of the solar event divided by 15 (deg/hour), in - * BigDecimal form. - */ - private BigDecimal getBaseLongitudeHour() { - return divideBy(location.getLongitude(), BigDecimal.valueOf(15)); - } - - /** - * Computes the longitude time, t in the algorithm. - * - * @return longitudinal time in BigDecimal form. - */ - private BigDecimal getLongitudeHour(Calendar date, Boolean isSunrise) { - int offset = 18; - if (isSunrise) { - offset = 6; - } - BigDecimal dividend = BigDecimal.valueOf(offset).subtract(getBaseLongitudeHour()); - BigDecimal addend = divideBy(dividend, BigDecimal.valueOf(24)); - BigDecimal longHour = getDayOfYear(date).add(addend); - return setScale(longHour); - } - - /** - * Computes the mean anomaly of the Sun, M in the algorithm. - * - * @return the suns mean anomaly, M, in BigDecimal form. - */ - private BigDecimal getMeanAnomaly(BigDecimal longitudeHour) { - BigDecimal meanAnomaly = multiplyBy(new BigDecimal("0.9856"), longitudeHour).subtract(new BigDecimal("3.289")); - return setScale(meanAnomaly); - } - - /** - * Computes the true longitude of the sun, L in the algorithm, at the given location, adjusted to fit in - * the range [0-360]. - * - * @param meanAnomaly - * the suns mean anomaly. - * @return the suns true longitude, in BigDecimal form. - */ - private BigDecimal getSunTrueLongitude(BigDecimal meanAnomaly) { - BigDecimal sinMeanAnomaly = new BigDecimal(Math.sin(convertDegreesToRadians(meanAnomaly).doubleValue())); - BigDecimal sinDoubleMeanAnomaly = new BigDecimal(Math.sin(multiplyBy(convertDegreesToRadians(meanAnomaly), BigDecimal.valueOf(2)) - .doubleValue())); - - BigDecimal firstPart = meanAnomaly.add(multiplyBy(sinMeanAnomaly, new BigDecimal("1.916"))); - BigDecimal secondPart = multiplyBy(sinDoubleMeanAnomaly, new BigDecimal("0.020")).add(new BigDecimal("282.634")); - BigDecimal trueLongitude = firstPart.add(secondPart); - - if (trueLongitude.doubleValue() > 360) { - trueLongitude = trueLongitude.subtract(BigDecimal.valueOf(360)); - } - return setScale(trueLongitude); - } - - /** - * Computes the suns right ascension, RA in the algorithm, adjusting for the quadrant of L and turning it - * into degree-hours. Will be in the range [0,360]. - * - * @param sunTrueLong - * Suns true longitude, in BigDecimal - * @return suns right ascension in degree-hours, in BigDecimal form. - */ - private BigDecimal getRightAscension(BigDecimal sunTrueLong) { - BigDecimal tanL = new BigDecimal(Math.tan(convertDegreesToRadians(sunTrueLong).doubleValue())); - - BigDecimal innerParens = multiplyBy(convertRadiansToDegrees(tanL), new BigDecimal("0.91764")); - BigDecimal rightAscension = new BigDecimal(Math.atan(convertDegreesToRadians(innerParens).doubleValue())); - rightAscension = setScale(convertRadiansToDegrees(rightAscension)); - - if (rightAscension.doubleValue() < 0) { - rightAscension = rightAscension.add(BigDecimal.valueOf(360)); - } else if (rightAscension.doubleValue() > 360) { - rightAscension = rightAscension.subtract(BigDecimal.valueOf(360)); - } - - BigDecimal ninety = BigDecimal.valueOf(90); - BigDecimal longitudeQuadrant = sunTrueLong.divide(ninety, 0, RoundingMode.FLOOR); - longitudeQuadrant = longitudeQuadrant.multiply(ninety); - - BigDecimal rightAscensionQuadrant = rightAscension.divide(ninety, 0, RoundingMode.FLOOR); - rightAscensionQuadrant = rightAscensionQuadrant.multiply(ninety); - - BigDecimal augend = longitudeQuadrant.subtract(rightAscensionQuadrant); - return divideBy(rightAscension.add(augend), BigDecimal.valueOf(15)); - } - - private BigDecimal getCosineSunLocalHour(BigDecimal sunTrueLong, Zenith zenith) { - BigDecimal sinSunDeclination = getSinOfSunDeclination(sunTrueLong); - BigDecimal cosineSunDeclination = getCosineOfSunDeclination(sinSunDeclination); - - BigDecimal zenithInRads = convertDegreesToRadians(zenith.degrees()); - BigDecimal cosineZenith = BigDecimal.valueOf(Math.cos(zenithInRads.doubleValue())); - BigDecimal sinLatitude = BigDecimal.valueOf(Math.sin(convertDegreesToRadians(location.getLatitude()).doubleValue())); - BigDecimal cosLatitude = BigDecimal.valueOf(Math.cos(convertDegreesToRadians(location.getLatitude()).doubleValue())); - - BigDecimal sinDeclinationTimesSinLat = sinSunDeclination.multiply(sinLatitude); - BigDecimal dividend = cosineZenith.subtract(sinDeclinationTimesSinLat); - BigDecimal divisor = cosineSunDeclination.multiply(cosLatitude); - - return setScale(divideBy(dividend, divisor)); - } - - private BigDecimal getSinOfSunDeclination(BigDecimal sunTrueLong) { - BigDecimal sinTrueLongitude = BigDecimal.valueOf(Math.sin(convertDegreesToRadians(sunTrueLong).doubleValue())); - BigDecimal sinOfDeclination = sinTrueLongitude.multiply(new BigDecimal("0.39782")); - return setScale(sinOfDeclination); - } - - private BigDecimal getCosineOfSunDeclination(BigDecimal sinSunDeclination) { - BigDecimal arcSinOfSinDeclination = BigDecimal.valueOf(Math.asin(sinSunDeclination.doubleValue())); - BigDecimal cosDeclination = BigDecimal.valueOf(Math.cos(arcSinOfSinDeclination.doubleValue())); - return setScale(cosDeclination); - } - - private BigDecimal getSunLocalHour(BigDecimal cosineSunLocalHour, Boolean isSunrise) { - BigDecimal arcCosineOfCosineHourAngle = getArcCosineFor(cosineSunLocalHour); - BigDecimal localHour = convertRadiansToDegrees(arcCosineOfCosineHourAngle); - if (isSunrise) { - localHour = BigDecimal.valueOf(360).subtract(localHour); - } - return divideBy(localHour, BigDecimal.valueOf(15)); - } - - private BigDecimal getLocalMeanTime(BigDecimal sunTrueLong, BigDecimal longitudeHour, BigDecimal sunLocalHour) { - BigDecimal rightAscension = this.getRightAscension(sunTrueLong); - BigDecimal innerParens = longitudeHour.multiply(new BigDecimal("0.06571")); - BigDecimal localMeanTime = sunLocalHour.add(rightAscension).subtract(innerParens); - localMeanTime = localMeanTime.subtract(new BigDecimal("6.622")); - - if (localMeanTime.doubleValue() < 0) { - localMeanTime = localMeanTime.add(BigDecimal.valueOf(24)); - } else if (localMeanTime.doubleValue() > 24) { - localMeanTime = localMeanTime.subtract(BigDecimal.valueOf(24)); - } - return setScale(localMeanTime); - } - - private BigDecimal getLocalTime(BigDecimal localMeanTime, Calendar date) { - BigDecimal utcTime = localMeanTime.subtract(getBaseLongitudeHour()); - BigDecimal utcOffSet = getUTCOffSet(date); - BigDecimal utcOffSetTime = utcTime.add(utcOffSet); - return adjustForDST(utcOffSetTime, date); - } - - private BigDecimal adjustForDST(BigDecimal localMeanTime, Calendar date) { - BigDecimal localTime = localMeanTime; - if (timeZone.inDaylightTime(date.getTime())) { - localTime = localTime.add(BigDecimal.ONE); - } - if (localTime.doubleValue() > 24.0) { - localTime = localTime.subtract(BigDecimal.valueOf(24)); - } - return localTime; - } - - /** - * Returns the local rise/set time in the form HH:MM. - * - * @param localTime - * BigDecimal representation of the local rise/set time. - * @return String representation of the local rise/set time in HH:MM format. - */ - private String getLocalTimeAsString(BigDecimal localTimeParam) { - if (localTimeParam == null) { - return "99:99"; - } - - BigDecimal localTime = localTimeParam; - if (localTime.compareTo(BigDecimal.ZERO) == -1) { - localTime = localTime.add(BigDecimal.valueOf(24.0D)); - } - String[] timeComponents = localTime.toPlainString().split("\\."); - int hour = Integer.parseInt(timeComponents[0]); - - BigDecimal minutes = new BigDecimal("0." + timeComponents[1]); - minutes = minutes.multiply(BigDecimal.valueOf(60)).setScale(0, RoundingMode.HALF_EVEN); - if (minutes.intValue() == 60) { - minutes = BigDecimal.ZERO; - hour += 1; - } - if (hour == 24) { - hour = 0; - } - - String minuteString = minutes.intValue() < 10 ? "0" + minutes.toPlainString() : minutes.toPlainString(); - String hourString = (hour < 10) ? "0" + String.valueOf(hour) : String.valueOf(hour); - return hourString + ":" + minuteString; - } - - /** - * Returns the local rise/set time in the form HH:MM. - * - * @param localTimeParam - * BigDecimal representation of the local rise/set time. - * @return Calendar representation of the local time as a calendar, or null for none. - */ - protected Calendar getLocalTimeAsCalendar(BigDecimal localTimeParam, Calendar date) { - if (localTimeParam == null) { - return null; - } - - // Create a clone of the input calendar so we get locale/timezone information. - Calendar resultTime = (Calendar) date.clone(); - - BigDecimal localTime = localTimeParam; - if (localTime.compareTo(BigDecimal.ZERO) == -1) { - localTime = localTime.add(BigDecimal.valueOf(24.0D)); - resultTime.add(Calendar.HOUR_OF_DAY, -24); - } - String[] timeComponents = localTime.toPlainString().split("\\."); - int hour = Integer.parseInt(timeComponents[0]); - - BigDecimal minutes = new BigDecimal("0." + timeComponents[1]); - minutes = minutes.multiply(BigDecimal.valueOf(60)).setScale(0, RoundingMode.HALF_EVEN); - if (minutes.intValue() == 60) { - minutes = BigDecimal.ZERO; - hour += 1; - } - if (hour == 24) { - hour = 0; - } - - // Set the local time - resultTime.set(Calendar.HOUR_OF_DAY, hour); - resultTime.set(Calendar.MINUTE, minutes.intValue()); - resultTime.set(Calendar.SECOND, 0); - resultTime.set(Calendar.MILLISECOND, 0); - resultTime.setTimeZone(date.getTimeZone()); - - return resultTime; - } - - /** ******* UTILITY METHODS (Should probably go somewhere else. ***************** */ - - private BigDecimal getDayOfYear(Calendar date) { - return new BigDecimal(date.get(Calendar.DAY_OF_YEAR)); - } - - private BigDecimal getUTCOffSet(Calendar date) { - BigDecimal offSetInMillis = new BigDecimal(date.get(Calendar.ZONE_OFFSET)); - BigDecimal offSet = offSetInMillis.divide(new BigDecimal(3600000), new MathContext(2)); - return offSet; - } - - private BigDecimal getArcCosineFor(BigDecimal radians) { - BigDecimal arcCosine = BigDecimal.valueOf(Math.acos(radians.doubleValue())); - return setScale(arcCosine); - } - - private BigDecimal convertRadiansToDegrees(BigDecimal radians) { - return multiplyBy(radians, new BigDecimal(180 / Math.PI)); - } - - private BigDecimal convertDegreesToRadians(BigDecimal degrees) { - return multiplyBy(degrees, BigDecimal.valueOf(Math.PI / 180.0)); - } - - private BigDecimal multiplyBy(BigDecimal multiplicand, BigDecimal multiplier) { - return setScale(multiplicand.multiply(multiplier)); - } - - private BigDecimal divideBy(BigDecimal dividend, BigDecimal divisor) { - return dividend.divide(divisor, 4, RoundingMode.HALF_EVEN); - } - - private BigDecimal setScale(BigDecimal number) { - return number.setScale(4, RoundingMode.HALF_EVEN); - } -} diff --git a/src/com/luckycatlabs/sunrisesunset/dto/Location.java b/src/com/luckycatlabs/sunrisesunset/dto/Location.java deleted file mode 100644 index ca268ef..0000000 --- a/src/com/luckycatlabs/sunrisesunset/dto/Location.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2009 Mike Reedell / LuckyCatLabs. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.luckycatlabs.sunrisesunset.dto; - -import java.math.BigDecimal; - -/** - * Simple VO class to store latitude/longitude information. - */ -public class Location { - private BigDecimal latitude; - private BigDecimal longitude; - - /** - * Creates a new instance of Location with the given parameters. - * - * @param latitude - * the latitude, in degrees, of this location. North latitude is positive, south negative. - * @param longitude - * the longitude, in degrees of this location. East longitude is positive, west negative. - */ - public Location(String latitude, String longitude) { - this.latitude = new BigDecimal(latitude); - this.longitude = new BigDecimal(longitude); - } - - /** - * Creates a new instance of Location with the given parameters. - * - * @param latitude - * the latitude, in degrees, of this location. North latitude is positive, south negative. - * @param longitude - * the longitude, in degrees, of this location. East longitude is positive, east negative. - */ - public Location(double latitude, double longitude) { - this.latitude = new BigDecimal(latitude); - this.longitude = new BigDecimal(longitude); - } - - /** - * @return the latitude - */ - public BigDecimal getLatitude() { - return latitude; - } - - /** - * @return the longitude - */ - public BigDecimal getLongitude() { - return longitude; - } - - /** - * Sets the coordinates of the location object. - * - * @param latitude - * the latitude, in degrees, of this location. North latitude is positive, south negative. - * @param longitude - * the longitude, in degrees, of this location. East longitude is positive, east negative. - */ - public void setLocation(String latitude, String longitude) { - this.latitude = new BigDecimal(latitude); - this.longitude = new BigDecimal(longitude); - } - - /** - * Sets the coordinates of the location object. - * - * @param latitude - * the latitude, in degrees, of this location. North latitude is positive, south negative. - * @param longitude - * the longitude, in degrees, of this location. East longitude is positive, east negative. - */ - public void setLocation(double latitude, double longitude) { - this.latitude = new BigDecimal(latitude); - this.longitude = new BigDecimal(longitude); - } -} diff --git a/src/fr/pandacube/java/BungeeMain.java b/src/fr/pandacube/java/BungeeMain.java index 42d6df1..fb30386 100644 --- a/src/fr/pandacube/java/BungeeMain.java +++ b/src/fr/pandacube/java/BungeeMain.java @@ -6,7 +6,7 @@ public class BungeeMain extends Plugin { @Override public void onLoad() { - PandacubeUtil.setServerLogger(getProxy().getLogger()); + PandacubeUtil.setMasterLogger(getProxy().getLogger()); PandacubeUtil.setPluginLogger(getLogger()); } diff --git a/src/fr/pandacube/java/PandacubeUtil.java b/src/fr/pandacube/java/PandacubeUtil.java index 1e27427..8fdaa34 100644 --- a/src/fr/pandacube/java/PandacubeUtil.java +++ b/src/fr/pandacube/java/PandacubeUtil.java @@ -1,25 +1,37 @@ package fr.pandacube.java; +import java.nio.charset.Charset; import java.util.logging.Logger; public class PandacubeUtil { + + + public static final Charset NETWORK_CHARSET = Charset.forName("UTF-8"); + + public static final int NETWORK_TCP_BUFFER_SIZE = 1024*1024; + + public static final int NETWORK_TIMEOUT = 30*1000; // 30 secondes + + + + /** * Représente le logger du serveur Spigot ou de Bungee,selon l'environnement */ - private static Logger serverLogger; + private static Logger masterLogger; /** * Représente le logger de PandacubeUtil, mais défini selon l'environnement Spigot ou Bungee. */ private static Logger pluginLogger; - public static Logger getServerLogger() { - return serverLogger; + public static Logger getMasterLogger() { + return masterLogger; } - public static void setServerLogger(Logger serverLogger) { - PandacubeUtil.serverLogger = serverLogger; + public static void setMasterLogger(Logger masterLogger) { + PandacubeUtil.masterLogger = masterLogger; } public static Logger getPluginLogger() { diff --git a/src/fr/pandacube/java/SpigotMain.java b/src/fr/pandacube/java/SpigotMain.java index 80a2206..3b9d8db 100644 --- a/src/fr/pandacube/java/SpigotMain.java +++ b/src/fr/pandacube/java/SpigotMain.java @@ -6,7 +6,7 @@ public class SpigotMain extends JavaPlugin { @Override public void onLoad() { - PandacubeUtil.setServerLogger(getServer().getLogger()); + PandacubeUtil.setMasterLogger(getServer().getLogger()); PandacubeUtil.setPluginLogger(getLogger()); } diff --git a/src/fr/pandacube/java/external_tools/ConvertToSQLBungeePerms.java b/src/fr/pandacube/java/external_tools/ConvertToSQLBungeePerms.java deleted file mode 100644 index 2b1776b..0000000 --- a/src/fr/pandacube/java/external_tools/ConvertToSQLBungeePerms.java +++ /dev/null @@ -1,84 +0,0 @@ -package fr.pandacube.java.external_tools; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class ConvertToSQLBungeePerms { - public static void main(String[] ç) throws Exception { - - List content = getFileLines(true, false, true, new File("convertToBungeePerms.txt")); - FileOutputStream output = new FileOutputStream(new File("output.sql")); - - - String currentSQLFormat = null; - - - for (String line : content) { - - if (line.startsWith("#sql:")) - currentSQLFormat = line.substring("#sql:".length()); - else - output.write(currentSQLFormat.replace("%%%perm%%%", line).concat("\n").getBytes()); - } - - output.flush(); - output.close(); - - - - - } - - - - - - - - - /** - * Retourne toutes les lignes d'un fichier donné - * @param ignoreEmpty true si on doit ignorer les lignes vides - * @param ignoreHashtagComment true si on doit ignorer les lignes commentés (commençant par un #) - * @param trimOutput true si on doit appeller la méthode String.trim() sur chaque ligne retournée - * @param f le fichier à lire - * @return la liste des lignes utiles - * @throws IOException - */ - protected static List getFileLines(boolean ignoreEmpty, boolean ignoreHashtagComment, boolean trimOutput, File f) throws IOException { - if (!f.isFile()) - return null; - - BufferedReader reader = new BufferedReader(new FileReader(f)); - - List lines = new ArrayList(); - - String line; - while ((line = reader.readLine()) != null) { - String trimmedLine = line.trim(); - - if (ignoreEmpty && trimmedLine.equals("")) - continue; - - if (ignoreHashtagComment && trimmedLine.startsWith("#")) - continue; - - if (trimOutput) - lines.add(trimmedLine); - else - lines.add(line); - } - - - reader.close(); - - return lines; - } - - -} diff --git a/src/fr/pandacube/java/external_tools/OfflineUUID.java b/src/fr/pandacube/java/external_tools/OfflineUUID.java new file mode 100644 index 0000000..e4fab12 --- /dev/null +++ b/src/fr/pandacube/java/external_tools/OfflineUUID.java @@ -0,0 +1,35 @@ +package fr.pandacube.java.external_tools; + +import java.nio.charset.Charset; +import java.util.*; + +public class OfflineUUID { + public static void main(String[] args) { + for (String arg : args) + { + System.out.println(""+arg+":"+getFromNickName(arg)); + } + if (args.length == 0) + throw new IllegalArgumentException("no argument given. Please give at least one argument."); + } + + public static UUID getFromNickName(String nickname) + { + String str = "OfflinePlayer:"+nickname; + byte[] from_str = str.getBytes(Charset.forName("UTF-8")); + return UUID.nameUUIDFromBytes(from_str); + } + + + + public static UUID[] getFromNickName(String[] nicknames) + { + if (nicknames == null) + throw new NullPointerException(); + + UUID[] uuids = new UUID[nicknames.length]; + for (int i=0; ihttps://bukkit.org/threads/player-name-history-lookup.412679/ +* @since 25-3-2016 +* @author mine-care (AKA fillpant) +* +*/ +public class PlayerNameHistoryLookup { + + /** + * The URL from Mojang API that provides the JSON String in response. + */ + private static final String LOOKUP_URL = "https://api.mojang.com/user/profiles/%s/names"; + + private static final Gson JSON_PARSER = new Gson(); + + /** + *

NOTE: Avoid running this method Synchronously with the main thread!It blocks while attempting to get a response from Mojang servers!

+ * @param player The UUID of the player to be looked up. + * @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted. + * @throws IOException {@link #getPlayerPreviousNames(String)} + */ + public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException { + return getPlayerPreviousNames(player.toString()); + } + + /** + *

NOTE: Avoid running this method Synchronously with the main thread! It blocks while attempting to get a response from Mojang servers!

+ * Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter. + * @param uuid The UUID String to lookup + * @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted. + * @throws IOException {@link #getRawJsonResponse(String)} + */ + public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException { + if (uuid == null || uuid.isEmpty()) + return null; + uuid = uuid.replace("-", ""); + String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid))); + PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class); + return names; + } + + /** + * This is a helper method used to read the response of Mojang's API webservers. + * @param u the URL to connect to + * @return a String with the data read. + * @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()} + */ + private static String getRawJsonResponse(URL u) throws IOException { + HttpURLConnection con = (HttpURLConnection) u.openConnection(); + con.setDoInput(true); + con.setConnectTimeout(2000); + con.setReadTimeout(2000); + con.connect(); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String response = in.readLine(); + in.close(); + return response; + } + + /** + * This class represents the typical response expected by Mojang servers when requesting the name history of a player. + */ + public class PreviousPlayerNameEntry { + private String name; + @SerializedName("changedToAt") + private long changeTime; + + /** + * Gets the player name of this entry. + * @return The name of the player. + */ + public String getPlayerName() { + return name; + } + + /** + * Get the time of change of the name. + *
Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling! + *
Parsing 0 to a Date will result in the date "01/01/1970".
+ * @return a timestamp in miliseconds that you can turn into a date or handle however you want :) + */ + public long getChangeTime() { + return changeTime; + } + + /** + * Check if this name is the name used to register the account (the initial/original name) + * @return a boolean, true if it is the the very first name of the player, otherwise false. + */ + public boolean isPlayersInitialName() { + return getChangeTime() == 0; + } + + @Override + public String toString() { + return "Name: " + name + " Date of change: " + new Date(changeTime).toString(); + } + } + + + + public static void main(String[] args) throws IOException { + System.out.println(Arrays.toString(getPlayerPreviousNames("a18d9b2c-e18f-4933-9e15-36452bc36857"))); + } + +} \ No newline at end of file diff --git a/src/fr/pandacube/java/util/db/LoginHistoryElement.java b/src/fr/pandacube/java/util/db/LoginHistoryElement.java index e222bd3..08a2ecb 100644 --- a/src/fr/pandacube/java/util/db/LoginHistoryElement.java +++ b/src/fr/pandacube/java/util/db/LoginHistoryElement.java @@ -8,27 +8,28 @@ public class LoginHistoryElement extends SQLElement { private long time; private String playerId; - private String ip; + private String ip = null; private ActionType actionType; private int nbOnline; + private String playerName; + private int minecraftVersion = 0; - public LoginHistoryElement(long t, UUID pId, InetAddress IP, ActionType action, int nbO) { + public LoginHistoryElement(long t, UUID pId, ActionType action, int nbO) { super("pandacube_login_history"); setTime(t); setPlayerId(pId); - setIp(IP); setActionType(action); setNbOnline(nbO); } - LoginHistoryElement(int id, long t, String pId, String IP, ActionType action, int nbO) { + LoginHistoryElement(int id, long t, String pId, String ip, ActionType action, int nbO) { super("pandacube_login_history", id); - if (IP == null || pId == null) - throw new IllegalArgumentException("pId et IP ne peuvent être null"); + if (pId == null) + throw new IllegalArgumentException("pId ne peuvent être null"); setTime(t); playerId = pId; - ip = IP; + this.ip = ip; setActionType(action); setNbOnline(nbO); } @@ -40,7 +41,9 @@ public class LoginHistoryElement extends SQLElement { playerId, ip, actionType.toString(), - Integer.toString(nbOnline) + Integer.toString(nbOnline), + playerName, + Integer.toString(minecraftVersion) }; } @@ -51,7 +54,9 @@ public class LoginHistoryElement extends SQLElement { "playerId", "ip", "actionType", - "nbOnline" + "nbOnline", + "playerName", + "minecraftVersion" }; } @@ -82,8 +87,9 @@ public class LoginHistoryElement extends SQLElement { public void setIp(InetAddress addr) { if (addr == null) - throw new IllegalArgumentException("addr ne peut être null"); - ip = addr.getHostAddress(); + ip = null; + else + ip = addr.getHostAddress(); } @@ -105,6 +111,31 @@ public class LoginHistoryElement extends SQLElement { public void setNbOnline(int nbOnline) { this.nbOnline = nbOnline; } + + public String getPlayerName() { + return playerName; + } + + public void setPlayerName(String pn) { + playerName = pn; + } + + public int getMinecraftVersion() { + return minecraftVersion; + } + + public void setMinecraftVersion(int m) { + minecraftVersion = m; + } + + + + + + + + + public enum ActionType { diff --git a/src/fr/pandacube/java/util/db/LoginHistoryTable.java b/src/fr/pandacube/java/util/db/LoginHistoryTable.java index eaa3422..a1b50a5 100644 --- a/src/fr/pandacube/java/util/db/LoginHistoryTable.java +++ b/src/fr/pandacube/java/util/db/LoginHistoryTable.java @@ -16,9 +16,11 @@ public class LoginHistoryTable extends SQLTable { return "id INT AUTO_INCREMENT PRIMARY KEY," + "time BIGINT NOT NULL," + "playerId CHAR(36) NOT NULL," - + "ip VARCHAR(128) NOT NULL," + + "ip VARCHAR(128) NULL," + "actionType ENUM('LOGIN', 'LOGOUT') NOT NULL," - + "nbOnline INT NOT NULL"; + + "nbOnline INT NOT NULL," + + "playerName VARCHAR(16) NULL," + + "minecraftVersion INT NOT NULL DEFAULT 0"; } @Override @@ -30,6 +32,8 @@ public class LoginHistoryTable extends SQLTable { sqlResult.getString("ip"), ActionType.valueOf(sqlResult.getString("actionType")), sqlResult.getInt("nbOnline")); + el.setPlayerName(sqlResult.getString("playerName")); + el.setMinecraftVersion(sqlResult.getInt("minecraftVersion")); return el; } diff --git a/src/fr/pandacube/java/util/db/ORM.java b/src/fr/pandacube/java/util/db/ORM.java index 34126b5..bbfd6bf 100644 --- a/src/fr/pandacube/java/util/db/ORM.java +++ b/src/fr/pandacube/java/util/db/ORM.java @@ -22,8 +22,7 @@ import java.util.List; */ public final class ORM { - @SuppressWarnings("rawtypes") - private static List tables = new ArrayList(); + private static List> tables = new ArrayList>(); /* package */ static DBConnection connection; @@ -39,18 +38,21 @@ public final class ORM { tables.add(new LoginHistoryTable()); tables.add(new ModoHistoryTable()); - - tables.add(new StaffTicketTable()); - tables.add(new MPMessageTable()); tables.add(new MPGroupTable()); tables.add(new MPGroupUserTable()); + tables.add(new MPMessageTable()); + + tables.add(new OnlineShopHistoryTable()); + tables.add(new PlayerTable()); tables.add(new PlayerIgnoreTable()); tables.add(new ShopStockTable()); + tables.add(new StaffTicketTable()); + } catch (SQLException e) { e.printStackTrace(); @@ -61,10 +63,9 @@ public final class ORM { - @SuppressWarnings("rawtypes") - public synchronized static T getTable(Class c) { + public synchronized static > T getTable(Class c) { if (c == null) return null; - for (SQLTable table : tables) { + for (SQLTable table : tables) { if (c.isAssignableFrom(table.getClass())) { return c.cast(table); @@ -83,4 +84,12 @@ public final class ORM { private ORM() { } // rend la classe non instanciable + + + + + + + + }