Clean up code & Upgrade syntax to new Java
This commit is contained in:
@@ -174,8 +174,8 @@ public class Ring implements Comparable<Ring> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Ring) {
|
||||
return ((Ring) o).getRingId() == getRingId();
|
||||
if (o instanceof Ring ring) {
|
||||
return ring.getRingId() == getRingId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ import server.ThreadManager;
|
||||
import tools.exceptions.IdTypeNotSupportedException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -75,12 +76,13 @@ public class IdCommand extends Command {
|
||||
throw new IdTypeNotSupportedException();
|
||||
}
|
||||
itemMap.put(type, new HashMap<>());
|
||||
BufferedReader reader = new BufferedReader(new FileReader(handbookDirectory.get(type)));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] row = line.split(" - ", 2);
|
||||
if (row.length == 2) {
|
||||
itemMap.get(type).put(row[1].toLowerCase(), row[0]);
|
||||
try (BufferedReader reader = Files.newBufferedReader(Paths.get(handbookDirectory.get(type)))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] row = line.split(" - ", 2);
|
||||
if (row.length == 2) {
|
||||
itemMap.get(type).put(row[1].toLowerCase(), row[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,15 @@ public class WhereaMiCommand extends Command {
|
||||
HashSet<Monster> mobs = new HashSet<>();
|
||||
|
||||
for (MapObject mmo : player.getMap().getMapObjects()) {
|
||||
if (mmo instanceof NPC) {
|
||||
NPC npc = (NPC) mmo;
|
||||
if (mmo instanceof NPC npc) {
|
||||
npcs.add(npc);
|
||||
} else if (mmo instanceof Character) {
|
||||
Character mc = (Character) mmo;
|
||||
} else if (mmo instanceof Character mc) {
|
||||
chars.add(mc);
|
||||
} else if (mmo instanceof Monster) {
|
||||
Monster mob = (Monster) mmo;
|
||||
} else if (mmo instanceof Monster mob) {
|
||||
if (mob.isAlive()) {
|
||||
mobs.add(mob);
|
||||
}
|
||||
} else if (mmo instanceof PlayerNPC) {
|
||||
PlayerNPC npc = (PlayerNPC) mmo;
|
||||
} else if (mmo instanceof PlayerNPC npc) {
|
||||
playernpcs.add(npc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tools.HexTool;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PeCommand extends Command {
|
||||
@@ -51,11 +52,9 @@ public class PeCommand extends Command {
|
||||
public void execute(Client c, String[] params) {
|
||||
Character player = c.getPlayer();
|
||||
String packet = "";
|
||||
try {
|
||||
InputStreamReader is = new FileReader("pe.txt");
|
||||
try (BufferedReader br = Files.newBufferedReader(Paths.get("pe.txt"))) {
|
||||
Properties packetProps = new Properties();
|
||||
packetProps.load(is);
|
||||
is.close();
|
||||
packetProps.load(br);
|
||||
packet = packetProps.getProperty("pe");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -4,8 +4,9 @@ import com.esotericsoftware.yamlbeans.YamlReader;
|
||||
import constants.string.CharsetConstants;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -18,7 +19,7 @@ public class YamlConfig {
|
||||
|
||||
private static YamlConfig loadConfig() {
|
||||
try {
|
||||
YamlReader reader = new YamlReader(new FileReader(CONFIG_FILE_NAME, CharsetConstants.CHARSET));
|
||||
YamlReader reader = new YamlReader(Files.newBufferedReader(Paths.get(CONFIG_FILE_NAME), CharsetConstants.CHARSET));
|
||||
YamlConfig config = reader.read(YamlConfig.class);
|
||||
reader.close();
|
||||
return config;
|
||||
|
||||
@@ -269,8 +269,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
||||
cs.removeFromInventory(item);
|
||||
c.sendPacket(PacketCreator.takeFromCashInventory(item));
|
||||
|
||||
if (item instanceof Equip) {
|
||||
Equip equip = (Equip) item;
|
||||
if (item instanceof Equip equip) {
|
||||
if (equip.getRingId() >= 0) {
|
||||
Ring ring = Ring.loadFromDb(equip.getRingId());
|
||||
chr.addPlayerRing(ring);
|
||||
@@ -323,8 +322,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
||||
return;
|
||||
}*/ //Gotta let them faggots marry too, hence why this is commented out <3
|
||||
|
||||
if (itemRing.toItem() instanceof Equip) {
|
||||
Equip eqp = (Equip) itemRing.toItem();
|
||||
if (itemRing.toItem() instanceof Equip eqp) {
|
||||
Pair<Integer, Integer> rings = Ring.createRing(itemRing.getItemId(), chr, partner);
|
||||
eqp.setRingId(rings.getLeft());
|
||||
cs.addToInventory(eqp);
|
||||
@@ -387,8 +385,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
||||
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0xBE));
|
||||
} else {
|
||||
// Need to check to make sure its actually an equip and the right SN...
|
||||
if (itemRing.toItem() instanceof Equip) {
|
||||
Equip eqp = (Equip) itemRing.toItem();
|
||||
if (itemRing.toItem() instanceof Equip eqp) {
|
||||
Pair<Integer, Integer> rings = Ring.createRing(itemRing.getItemId(), chr, partner);
|
||||
eqp.setRingId(rings.getLeft());
|
||||
cs.addToInventory(eqp);
|
||||
|
||||
@@ -36,8 +36,7 @@ public final class CharInfoRequestHandler extends AbstractPacketHandler {
|
||||
int cid = p.readInt();
|
||||
MapObject target = c.getPlayer().getMap().getMapObject(cid);
|
||||
if (target != null) {
|
||||
if (target instanceof Character) {
|
||||
Character player = (Character) target;
|
||||
if (target instanceof Character player) {
|
||||
|
||||
if (c.getPlayer().getId() != player.getId()) {
|
||||
player.exportExcludedItems(c);
|
||||
|
||||
@@ -45,8 +45,7 @@ public final class DoorHandler extends AbstractPacketHandler {
|
||||
}
|
||||
|
||||
for (MapObject obj : chr.getMap().getMapObjects()) {
|
||||
if (obj instanceof DoorObject) {
|
||||
DoorObject door = (DoorObject) obj;
|
||||
if (obj instanceof DoorObject door) {
|
||||
if (door.getOwnerId() == ownerid) {
|
||||
door.warp(chr);
|
||||
return;
|
||||
|
||||
@@ -47,8 +47,7 @@ public final class HiredMerchantRequest extends AbstractPacketHandler {
|
||||
|
||||
try {
|
||||
for (MapObject mmo : chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapObjectType.HIRED_MERCHANT, MapObjectType.PLAYER))) {
|
||||
if (mmo instanceof Character) {
|
||||
Character mc = (Character) mmo;
|
||||
if (mmo instanceof Character mc) {
|
||||
|
||||
PlayerShop shop = mc.getPlayerShop();
|
||||
if (shop != null && shop.isOwner(mc)) {
|
||||
|
||||
@@ -87,8 +87,7 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (obj instanceof PlayerNPC) {
|
||||
PlayerNPC pnpc = (PlayerNPC) obj;
|
||||
} else if (obj instanceof PlayerNPC pnpc) {
|
||||
NPCScriptManager nsm = NPCScriptManager.getInstance();
|
||||
|
||||
if (pnpc.getScriptId() < NpcId.CUSTOM_DEV && !nsm.isNpcScriptAvailable(c, "" + pnpc.getScriptId())) {
|
||||
|
||||
@@ -291,11 +291,10 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
|
||||
MapObject ob = chr.getMap().getMapObject(oid);
|
||||
if (ob instanceof PlayerShop shop) {
|
||||
shop.visitShop(chr);
|
||||
} else if (ob instanceof MiniGame) {
|
||||
} else if (ob instanceof MiniGame game) {
|
||||
p.skip(1);
|
||||
String pw = p.available() > 1 ? p.readString() : "";
|
||||
|
||||
MiniGame game = (MiniGame) ob;
|
||||
if (game.checkPassword(pw)) {
|
||||
if (game.hasFreeSlot() && !game.isVisitor(chr)) {
|
||||
game.addVisitor(chr);
|
||||
@@ -849,8 +848,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
|
||||
private static boolean canPlaceStore(Character chr) {
|
||||
try {
|
||||
for (MapObject mmo : chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapObjectType.HIRED_MERCHANT, MapObjectType.PLAYER))) {
|
||||
if (mmo instanceof Character) {
|
||||
Character mc = (Character) mmo;
|
||||
if (mmo instanceof Character mc) {
|
||||
if (mc.getId() == chr.getId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -604,11 +604,10 @@ public class Guild {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof GuildCharacter)) {
|
||||
return false;
|
||||
if (other instanceof GuildCharacter o) {
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
}
|
||||
GuildCharacter o = (GuildCharacter) other;
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -150,11 +150,10 @@ public class GuildCharacter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof GuildCharacter)) {
|
||||
return false;
|
||||
if (other instanceof GuildCharacter o) {
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
}
|
||||
GuildCharacter o = (GuildCharacter) other;
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1033,8 +1033,7 @@ public class ItemInformationProvider {
|
||||
public Item scrollEquipWithId(Item equip, int scrollId, boolean usingWhiteScroll, int vegaItemId, boolean isGM) {
|
||||
boolean assertGM = (isGM && YamlConfig.config.server.USE_PERFECT_GM_SCROLL);
|
||||
|
||||
if (equip instanceof Equip) {
|
||||
Equip nEquip = (Equip) equip;
|
||||
if (equip instanceof Equip nEquip) {
|
||||
Map<String, Integer> stats = this.getEquipStats(scrollId);
|
||||
|
||||
if (((nEquip.getUpgradeSlots() > 0 || ItemConstants.isCleanSlate(scrollId))) || assertGM) {
|
||||
|
||||
@@ -112,8 +112,7 @@ public class MapFactory {
|
||||
|
||||
private static void loadLifeRaw(MapleMap map, int id, String type, int cy, int f, int fh, int rx0, int rx1, int x, int y, int hide, int mobTime, int team) {
|
||||
AbstractLoadedLife myLife = loadLife(id, type, cy, f, fh, rx0, rx1, x, y, hide);
|
||||
if (myLife instanceof Monster) {
|
||||
Monster monster = (Monster) myLife;
|
||||
if (myLife instanceof Monster monster) {
|
||||
|
||||
if (mobTime == -1) { //does not respawn, force spawn once
|
||||
map.spawnMonster(monster);
|
||||
|
||||
@@ -1650,8 +1650,7 @@ public class MapleMap {
|
||||
objectRLock.lock();
|
||||
try {
|
||||
for (Object ob : list) {
|
||||
if (ob instanceof MapObject) {
|
||||
MapObject mmo = (MapObject) ob;
|
||||
if (ob instanceof MapObject mmo) {
|
||||
|
||||
if (mapobjects.containsValue(mmo) && mmo.getType() == MapObjectType.REACTOR) {
|
||||
listObjects.add(mmo);
|
||||
|
||||
@@ -53,11 +53,10 @@ public class ArrayMap<K, V> extends AbstractMap<K, V> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Map.Entry<?, ?>)) {
|
||||
return false;
|
||||
if (o instanceof Map.Entry<?, ?> e) {
|
||||
return (key == null ? e.getKey() == null : key.equals(e.getKey())) && (value == null ? e.getValue() == null : value.equals(e.getValue()));
|
||||
}
|
||||
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
|
||||
return (key == null ? e.getKey() == null : key.equals(e.getKey())) && (value == null ? e.getValue() == null : value.equals(e.getValue()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user