Fix Java 8 support (#489)
This commit is contained in:
@@ -2,5 +2,4 @@ HOST=127.0.0.1
|
|||||||
URL=jdbc:mysql://localhost:3306/heavenms
|
URL=jdbc:mysql://localhost:3306/heavenms
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
DB_PASS=
|
DB_PASS=
|
||||||
JAVA8=FALSE
|
|
||||||
SHUTDOWNHOOK=true
|
SHUTDOWNHOOK=true
|
||||||
@@ -51,10 +51,8 @@ public class ServerConstants {
|
|||||||
public static boolean LOCALSERVER;
|
public static boolean LOCALSERVER;
|
||||||
|
|
||||||
//Other Configuration
|
//Other Configuration
|
||||||
public static boolean JAVA_8;
|
public static final boolean JAVA_8 = getJavaVersion() >= 8;
|
||||||
public static boolean SHUTDOWNHOOK;
|
public static boolean SHUTDOWNHOOK;
|
||||||
// JAVA_8: every static function in AbstractPlayerInteraction are to be made non-static, and code comment sections uncommented after enabling this functionality.
|
|
||||||
|
|
||||||
|
|
||||||
//Server Flags
|
//Server Flags
|
||||||
public static final boolean USE_CUSTOM_KEYSET = true; //Enables auto-setup of the HeavenMS's custom keybindings when creating characters.
|
public static final boolean USE_CUSTOM_KEYSET = true; //Enables auto-setup of the HeavenMS's custom keybindings when creating characters.
|
||||||
@@ -320,8 +318,7 @@ public class ServerConstants {
|
|||||||
ServerConstants.DB_USER = p.getProperty("DB_USER");
|
ServerConstants.DB_USER = p.getProperty("DB_USER");
|
||||||
ServerConstants.DB_PASS = p.getProperty("DB_PASS");
|
ServerConstants.DB_PASS = p.getProperty("DB_PASS");
|
||||||
|
|
||||||
//java8 And Shutdownhook
|
// shutdownhook
|
||||||
ServerConstants.JAVA_8 = p.getProperty("JAVA8").equalsIgnoreCase("TRUE");
|
|
||||||
ServerConstants.SHUTDOWNHOOK = p.getProperty("SHUTDOWNHOOK").equalsIgnoreCase("true");
|
ServerConstants.SHUTDOWNHOOK = p.getProperty("SHUTDOWNHOOK").equalsIgnoreCase("true");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -330,4 +327,25 @@ public class ServerConstants {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// https://github.com/openstreetmap/josm/blob/a3a6e8a6b657cf4c5b4c64ea14d6e87be6280d65/src/org/openstreetmap/josm/tools/Utils.java#L1566-L1585
|
||||||
|
/**
|
||||||
|
* Returns the Java version as an int value.
|
||||||
|
* @return the Java version as an int value (8, 9, etc.)
|
||||||
|
* @since 12130
|
||||||
|
*/
|
||||||
|
public static int getJavaVersion() {
|
||||||
|
String version = System.getProperty("java.version");
|
||||||
|
if (version.startsWith("1.")) {
|
||||||
|
version = version.substring(2);
|
||||||
|
}
|
||||||
|
// Allow these formats:
|
||||||
|
// 1.8.0_72-ea
|
||||||
|
// 9-ea
|
||||||
|
// 9
|
||||||
|
// 9.0.1
|
||||||
|
int dotPos = version.indexOf('.');
|
||||||
|
int dashPos = version.indexOf('-');
|
||||||
|
return Integer.parseInt(version.substring(0,
|
||||||
|
dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class AbstractPlayerInteraction {
|
|||||||
return c.getPlayer().getMap();
|
return c.getPlayer().getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getHourOfDay() {
|
public int getHourOfDay() {
|
||||||
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class AbstractPlayerInteraction {
|
|||||||
return getMarketPortalId(getWarpMap(mapId));
|
return getMarketPortalId(getWarpMap(mapId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMarketPortalId(MapleMap map) {
|
private int getMarketPortalId(MapleMap map) {
|
||||||
return (map.findMarketPortal() != null) ? map.findMarketPortal().getId() : map.getRandomPlayerSpawnpoint().getId();
|
return (map.findMarketPortal() != null) ? map.findMarketPortal().getId() : map.getRandomPlayerSpawnpoint().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ public class AbstractPlayerInteraction {
|
|||||||
return canHoldAllAfterRemoving(Collections.singletonList(itemid), Collections.singletonList(quantity), Collections.singletonList(removeItemid), Collections.singletonList(removeQuantity));
|
return canHoldAllAfterRemoving(Collections.singletonList(itemid), Collections.singletonList(quantity), Collections.singletonList(removeItemid), Collections.singletonList(removeQuantity));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Integer> convertToIntegerArray(List<Double> list) {
|
private List<Integer> convertToIntegerArray(List<Double> list) {
|
||||||
List<Integer> intList = new LinkedList<>();
|
List<Integer> intList = new LinkedList<>();
|
||||||
for(Double d: list) {
|
for(Double d: list) {
|
||||||
intList.add(d.intValue());
|
intList.add(d.intValue());
|
||||||
@@ -270,7 +270,7 @@ public class AbstractPlayerInteraction {
|
|||||||
return MapleInventory.checkSpots(c.getPlayer(), addedItems, false);
|
return MapleInventory.checkSpots(c.getPlayer(), addedItems, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Pair<Item, MapleInventoryType>> prepareProofInventoryItems(List<Pair<Integer, Integer>> items) {
|
private List<Pair<Item, MapleInventoryType>> prepareProofInventoryItems(List<Pair<Integer, Integer>> items) {
|
||||||
List<Pair<Item, MapleInventoryType>> addedItems = new LinkedList<>();
|
List<Pair<Item, MapleInventoryType>> addedItems = new LinkedList<>();
|
||||||
for(Pair<Integer, Integer> p : items) {
|
for(Pair<Integer, Integer> p : items) {
|
||||||
Item it = new Item(p.getLeft(), (short) 0, p.getRight().shortValue());
|
Item it = new Item(p.getLeft(), (short) 0, p.getRight().shortValue());
|
||||||
@@ -280,7 +280,7 @@ public class AbstractPlayerInteraction {
|
|||||||
return addedItems;
|
return addedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<List<Pair<Integer, Integer>>> prepareInventoryItemList(List<Integer> itemids, List<Integer> quantity) {
|
private List<List<Pair<Integer, Integer>>> prepareInventoryItemList(List<Integer> itemids, List<Integer> quantity) {
|
||||||
int size = Math.min(itemids.size(), quantity.size());
|
int size = Math.min(itemids.size(), quantity.size());
|
||||||
|
|
||||||
List<List<Pair<Integer, Integer>>> invList = new ArrayList<>(6);
|
List<List<Pair<Integer, Integer>>> invList = new ArrayList<>(6);
|
||||||
@@ -948,7 +948,7 @@ public class AbstractPlayerInteraction {
|
|||||||
c.announce(MaplePacketCreator.modifyInventory(false, Collections.singletonList(new ModifyInventory(0, newItem))));
|
c.announce(MaplePacketCreator.modifyInventory(false, Collections.singletonList(new ModifyInventory(0, newItem))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spawnNpc(int npcId, Point pos, MapleMap map) {
|
public void spawnNpc(int npcId, Point pos, MapleMap map) {
|
||||||
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
npc.setPosition(pos);
|
npc.setPosition(pos);
|
||||||
@@ -967,11 +967,11 @@ public class AbstractPlayerInteraction {
|
|||||||
getPlayer().getMap().spawnMonster(monster);
|
getPlayer().getMap().spawnMonster(monster);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MapleMonster getMonsterLifeFactory(int mid) {
|
public MapleMonster getMonsterLifeFactory(int mid) {
|
||||||
return MapleLifeFactory.getMonster(mid);
|
return MapleLifeFactory.getMonster(mid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MobSkill getMobSkill(int skill, int level) {
|
public MobSkill getMobSkill(int skill, int level) {
|
||||||
return MobSkillFactory.getMobSkill(skill, level);
|
return MobSkillFactory.getMobSkill(skill, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1165,7 +1165,7 @@ public class AbstractPlayerInteraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFirstJobStatRequirement(int jobType) {
|
public String getFirstJobStatRequirement(int jobType) {
|
||||||
switch(jobType) {
|
switch(jobType) {
|
||||||
case 1:
|
case 1:
|
||||||
return "STR " + 35;
|
return "STR " + 35;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
package scripting.event;
|
package scripting.event;
|
||||||
|
|
||||||
|
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
import jdk.nashorn.api.scripting.ScriptUtils;
|
||||||
import tools.exceptions.EventInstanceInProgressException;
|
import tools.exceptions.EventInstanceInProgressException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -165,14 +167,14 @@ public class EventManager {
|
|||||||
startLock = startLock.dispose();
|
startLock = startLock.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Integer> convertToIntegerArray(List<Double> list) {
|
private List<Integer> convertToIntegerArray(List<Double> list) {
|
||||||
List<Integer> intList = new ArrayList<>();
|
List<Integer> intList = new ArrayList<>();
|
||||||
for(Double d: list) intList.add(d.intValue());
|
for(Double d: list) intList.add(d.intValue());
|
||||||
|
|
||||||
return intList;
|
return intList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLobbyDelay() {
|
public long getLobbyDelay() {
|
||||||
return ServerConstants.EVENT_LOBBY_DELAY;
|
return ServerConstants.EVENT_LOBBY_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +183,6 @@ public class EventManager {
|
|||||||
if (!ServerConstants.JAVA_8) {
|
if (!ServerConstants.JAVA_8) {
|
||||||
return convertToIntegerArray((List<Double>)iv.invokeFunction("setLobbyRange", (Object) null));
|
return convertToIntegerArray((List<Double>)iv.invokeFunction("setLobbyRange", (Object) null));
|
||||||
} else { // java 8 support here thanks to MedicOP
|
} else { // java 8 support here thanks to MedicOP
|
||||||
/*
|
|
||||||
ScriptObjectMirror object = (ScriptObjectMirror) iv.invokeFunction("setLobbyRange", (Object) null);
|
ScriptObjectMirror object = (ScriptObjectMirror) iv.invokeFunction("setLobbyRange", (Object) null);
|
||||||
int[] to = object.to(int[].class);
|
int[] to = object.to(int[].class);
|
||||||
List<Integer> list = new ArrayList<>();
|
List<Integer> list = new ArrayList<>();
|
||||||
@@ -189,9 +190,7 @@ public class EventManager {
|
|||||||
list.add(i);
|
list.add(i);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
*/
|
|
||||||
|
|
||||||
throw new NoSuchMethodException();
|
|
||||||
}
|
}
|
||||||
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
|
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
|
||||||
List<Integer> defaultRange = new ArrayList<>();
|
List<Integer> defaultRange = new ArrayList<>();
|
||||||
@@ -750,13 +749,12 @@ public class EventManager {
|
|||||||
if(p != null) {
|
if(p != null) {
|
||||||
List<MaplePartyCharacter> lmpc;
|
List<MaplePartyCharacter> lmpc;
|
||||||
|
|
||||||
/*if(ServerConstants.JAVA_8) {
|
if(ServerConstants.JAVA_8) {
|
||||||
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
|
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
|
||||||
} else {
|
} else {
|
||||||
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
|
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
|
|
||||||
party.setEligibleMembers(lmpc);
|
party.setEligibleMembers(lmpc);
|
||||||
return lmpc;
|
return lmpc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
private boolean itemScript;
|
private boolean itemScript;
|
||||||
private List<MaplePartyCharacter> otherParty;
|
private List<MaplePartyCharacter> otherParty;
|
||||||
|
|
||||||
private static Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
private Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
||||||
|
|
||||||
private static String getDefaultTalk(int npcid) {
|
private String getDefaultTalk(int npcid) {
|
||||||
String talk = npcDefaultTalks.get(npcid);
|
String talk = npcDefaultTalks.get(npcid);
|
||||||
if (talk == null) {
|
if (talk == null) {
|
||||||
talk = MapleLifeFactory.getNPCDefaultTalk(npcid);
|
talk = MapleLifeFactory.getNPCDefaultTalk(npcid);
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
|
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
|
private List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
|
||||||
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
|
||||||
|
|
||||||
List<ReactorDropEntry> items = new ArrayList<>();
|
List<ReactorDropEntry> items = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user