Fix Java 8 support (#489)

This commit is contained in:
kolakcc
2019-07-17 01:25:18 +02:00
committed by Ronan Lana
parent 2df59b293b
commit 68fae41251
6 changed files with 43 additions and 28 deletions

View File

@@ -96,7 +96,7 @@ public class AbstractPlayerInteraction {
return c.getPlayer().getMap();
}
public static int getHourOfDay() {
public int getHourOfDay() {
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
}
@@ -104,7 +104,7 @@ public class AbstractPlayerInteraction {
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();
}
@@ -236,7 +236,7 @@ public class AbstractPlayerInteraction {
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<>();
for(Double d: list) {
intList.add(d.intValue());
@@ -270,7 +270,7 @@ public class AbstractPlayerInteraction {
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<>();
for(Pair<Integer, Integer> p : items) {
Item it = new Item(p.getLeft(), (short) 0, p.getRight().shortValue());
@@ -280,7 +280,7 @@ public class AbstractPlayerInteraction {
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());
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))));
}
public static void spawnNpc(int npcId, Point pos, MapleMap map) {
public void spawnNpc(int npcId, Point pos, MapleMap map) {
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
if (npc != null) {
npc.setPosition(pos);
@@ -967,11 +967,11 @@ public class AbstractPlayerInteraction {
getPlayer().getMap().spawnMonster(monster);
}
public static MapleMonster getMonsterLifeFactory(int mid) {
public MapleMonster getMonsterLifeFactory(int 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);
}
@@ -1165,7 +1165,7 @@ public class AbstractPlayerInteraction {
}
}
public static String getFirstJobStatRequirement(int jobType) {
public String getFirstJobStatRequirement(int jobType) {
switch(jobType) {
case 1:
return "STR " + 35;

View File

@@ -21,6 +21,8 @@
*/
package scripting.event;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.api.scripting.ScriptUtils;
import tools.exceptions.EventInstanceInProgressException;
import java.util.Collection;
import java.util.HashMap;
@@ -165,14 +167,14 @@ public class EventManager {
startLock = startLock.dispose();
}
private static List<Integer> convertToIntegerArray(List<Double> list) {
private List<Integer> convertToIntegerArray(List<Double> list) {
List<Integer> intList = new ArrayList<>();
for(Double d: list) intList.add(d.intValue());
return intList;
}
public static long getLobbyDelay() {
public long getLobbyDelay() {
return ServerConstants.EVENT_LOBBY_DELAY;
}
@@ -181,7 +183,6 @@ public class EventManager {
if (!ServerConstants.JAVA_8) {
return convertToIntegerArray((List<Double>)iv.invokeFunction("setLobbyRange", (Object) null));
} else { // java 8 support here thanks to MedicOP
/*
ScriptObjectMirror object = (ScriptObjectMirror) iv.invokeFunction("setLobbyRange", (Object) null);
int[] to = object.to(int[].class);
List<Integer> list = new ArrayList<>();
@@ -189,9 +190,7 @@ public class EventManager {
list.add(i);
}
return list;
*/
throw new NoSuchMethodException();
}
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
List<Integer> defaultRange = new ArrayList<>();
@@ -750,13 +749,12 @@ public class EventManager {
if(p != null) {
List<MaplePartyCharacter> lmpc;
/*if(ServerConstants.JAVA_8) {
if(ServerConstants.JAVA_8) {
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
} else {
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
}*/
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
}
party.setEligibleMembers(lmpc);
return lmpc;
}

View File

@@ -97,9 +97,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
private boolean itemScript;
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);
if (talk == null) {
talk = MapleLifeFactory.getNPCDefaultTalk(npcid);

View File

@@ -186,7 +186,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
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();
List<ReactorDropEntry> items = new ArrayList<>();