cleanup: replace anonymous inner class with lambda
This commit is contained in:
@@ -807,12 +807,7 @@ public class MapleClient {
|
||||
|
||||
public final void disconnect(final boolean shutdown, final boolean cashshop) {
|
||||
if (canDisconnect()) {
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
disconnectInternal(shutdown, cashshop);
|
||||
}
|
||||
});
|
||||
ThreadManager.getInstance().newTask(() -> disconnectInternal(shutdown, cashshop));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,13 +65,7 @@ public class GotoCommand extends Command {
|
||||
public static String GOTO_AREAS_INFO = "";
|
||||
|
||||
private static void sortGotoEntries(List<Entry<String, Integer>> listEntries) {
|
||||
Collections.sort(listEntries, new Comparator<Entry<String, Integer>>() {
|
||||
@Override
|
||||
public int compare(Entry<String, Integer> e1, Entry<String, Integer> e2)
|
||||
{
|
||||
return e1.getValue().compareTo(e2.getValue());
|
||||
}
|
||||
});
|
||||
Collections.sort(listEntries, (e1, e2) -> e1.getValue().compareTo(e2.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,34 +38,31 @@ public class IdCommand extends Command {
|
||||
}
|
||||
final String queryItem = joinStringArr(Arrays.copyOfRange(params, 1, params.length), " ");
|
||||
player.yellowMessage("Querying for entry... May take some time... Please try to refine your search.");
|
||||
Runnable queryRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
populateIdMap(params[0].toLowerCase());
|
||||
Runnable queryRunnable = () -> {
|
||||
try {
|
||||
populateIdMap(params[0].toLowerCase());
|
||||
|
||||
Map<String, String> resultList = fetchResults(itemMap.get(params[0]), queryItem);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (resultList.size() > 0) {
|
||||
int count = 0;
|
||||
for (Map.Entry<String, String> entry: resultList.entrySet()) {
|
||||
sb.append(String.format("Id for %s is: #b%s#k", entry.getKey(), entry.getValue()) + "\r\n");
|
||||
if (++count > 100) {
|
||||
break;
|
||||
}
|
||||
Map<String, String> resultList = fetchResults(itemMap.get(params[0]), queryItem);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (resultList.size() > 0) {
|
||||
int count = 0;
|
||||
for (Map.Entry<String, String> entry: resultList.entrySet()) {
|
||||
sb.append(String.format("Id for %s is: #b%s#k", entry.getKey(), entry.getValue()) + "\r\n");
|
||||
if (++count > 100) {
|
||||
break;
|
||||
}
|
||||
sb.append(String.format("Results found: #r%d#k | Returned: #b%d#k/100 | Refine search query to improve time.", resultList.size(), count) + "\r\n");
|
||||
|
||||
player.getAbstractPlayerInteraction().npcTalk(9010000, sb.toString());
|
||||
} else {
|
||||
player.yellowMessage(String.format("Id not found for item: %s, of type: %s.", queryItem, params[0]));
|
||||
}
|
||||
} catch (IdTypeNotSupportedException e) {
|
||||
player.yellowMessage("Your query type is not supported.");
|
||||
} catch (IOException e) {
|
||||
player.yellowMessage("Error reading file, please contact your administrator.");
|
||||
sb.append(String.format("Results found: #r%d#k | Returned: #b%d#k/100 | Refine search query to improve time.", resultList.size(), count) + "\r\n");
|
||||
|
||||
player.getAbstractPlayerInteraction().npcTalk(9010000, sb.toString());
|
||||
} else {
|
||||
player.yellowMessage(String.format("Id not found for item: %s, of type: %s.", queryItem, params[0]));
|
||||
}
|
||||
} catch (IdTypeNotSupportedException e) {
|
||||
player.yellowMessage("Your query type is not supported.");
|
||||
} catch (IOException e) {
|
||||
player.yellowMessage("Error reading file, please contact your administrator.");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -75,12 +75,7 @@ public class BanCommand extends Command {
|
||||
target.yellowMessage("Reason: " + reason);
|
||||
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
|
||||
final MapleCharacter rip = target;
|
||||
TimerManager.getInstance().schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
rip.getClient().disconnect(false, false);
|
||||
}
|
||||
}, 5000); //5 Seconds
|
||||
TimerManager.getInstance().schedule(() -> rip.getClient().disconnect(false, false), 5000); //5 Seconds
|
||||
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[RIP]: " + ign + " has been banned."));
|
||||
} else if (MapleCharacter.ban(ign, reason, false)) {
|
||||
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
|
||||
|
||||
@@ -45,23 +45,20 @@ public class ServerAddChannelCommand extends Command {
|
||||
|
||||
final int worldid = Integer.parseInt(params[0]);
|
||||
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int chid = Server.getInstance().addChannel(worldid);
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(chid >= 0) {
|
||||
player.dropMessage(5, "NEW Channel " + chid + " successfully deployed on world " + worldid + ".");
|
||||
ThreadManager.getInstance().newTask(() -> {
|
||||
int chid = Server.getInstance().addChannel(worldid);
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(chid >= 0) {
|
||||
player.dropMessage(5, "NEW Channel " + chid + " successfully deployed on world " + worldid + ".");
|
||||
} else {
|
||||
if(chid == -3) {
|
||||
player.dropMessage(5, "Invalid worldid detected. Channel creation aborted.");
|
||||
} else if(chid == -2) {
|
||||
player.dropMessage(5, "Reached channel limit on worldid " + worldid + ". Channel creation aborted.");
|
||||
} else if(chid == -1) {
|
||||
player.dropMessage(5, "Error detected when loading the 'world.ini' file. Channel creation aborted.");
|
||||
} else {
|
||||
if(chid == -3) {
|
||||
player.dropMessage(5, "Invalid worldid detected. Channel creation aborted.");
|
||||
} else if(chid == -2) {
|
||||
player.dropMessage(5, "Reached channel limit on worldid " + worldid + ". Channel creation aborted.");
|
||||
} else if(chid == -1) {
|
||||
player.dropMessage(5, "Error detected when loading the 'world.ini' file. Channel creation aborted.");
|
||||
} else {
|
||||
player.dropMessage(5, "NEW Channel failed to be deployed. Check if the needed port is already in use or other limitations are taking place.");
|
||||
}
|
||||
player.dropMessage(5, "NEW Channel failed to be deployed. Check if the needed port is already in use or other limitations are taking place.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,20 +38,17 @@ public class ServerAddWorldCommand extends Command {
|
||||
public void execute(MapleClient c, String[] params) {
|
||||
final MapleCharacter player = c.getPlayer();
|
||||
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int wid = Server.getInstance().addWorld();
|
||||
ThreadManager.getInstance().newTask(() -> {
|
||||
int wid = Server.getInstance().addWorld();
|
||||
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(wid >= 0) {
|
||||
player.dropMessage(5, "NEW World " + wid + " successfully deployed.");
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(wid >= 0) {
|
||||
player.dropMessage(5, "NEW World " + wid + " successfully deployed.");
|
||||
} else {
|
||||
if(wid == -2) {
|
||||
player.dropMessage(5, "Error detected when loading the 'world.ini' file. World creation aborted.");
|
||||
} else {
|
||||
if(wid == -2) {
|
||||
player.dropMessage(5, "Error detected when loading the 'world.ini' file. World creation aborted.");
|
||||
} else {
|
||||
player.dropMessage(5, "NEW World failed to be deployed. Check if needed ports are already in use or maximum world count has been reached.");
|
||||
}
|
||||
player.dropMessage(5, "NEW World failed to be deployed. Check if needed ports are already in use or maximum world count has been reached.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,17 +44,14 @@ public class ServerRemoveChannelCommand extends Command {
|
||||
}
|
||||
|
||||
final int worldId = Integer.parseInt(params[0]);
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(Server.getInstance().removeChannel(worldId)) {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Successfully removed a channel on World " + worldId + ". Current channel count: " + Server.getInstance().getWorld(worldId).getChannelsSize() + ".");
|
||||
}
|
||||
} else {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Failed to remove last Channel on world " + worldId + ". Check if either that world exists or there are people currently playing there.");
|
||||
}
|
||||
ThreadManager.getInstance().newTask(() -> {
|
||||
if(Server.getInstance().removeChannel(worldId)) {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Successfully removed a channel on World " + worldId + ". Current channel count: " + Server.getInstance().getWorld(worldId).getChannelsSize() + ".");
|
||||
}
|
||||
} else {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Failed to remove last Channel on world " + worldId + ". Check if either that world exists or there are people currently playing there.");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,20 +44,17 @@ public class ServerRemoveWorldCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(Server.getInstance().removeWorld()) {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Successfully removed a world. Current world count: " + Server.getInstance().getWorldsSize() + ".");
|
||||
}
|
||||
} else {
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(rwid < 0) {
|
||||
player.dropMessage(5, "No registered worlds to remove.");
|
||||
} else {
|
||||
player.dropMessage(5, "Failed to remove world " + rwid + ". Check if there are people currently playing there.");
|
||||
}
|
||||
ThreadManager.getInstance().newTask(() -> {
|
||||
if(Server.getInstance().removeWorld()) {
|
||||
if(player.isLoggedinWorld()) {
|
||||
player.dropMessage(5, "Successfully removed a world. Current world count: " + Server.getInstance().getWorldsSize() + ".");
|
||||
}
|
||||
} else {
|
||||
if(player.isLoggedinWorld()) {
|
||||
if(rwid < 0) {
|
||||
player.dropMessage(5, "No registered worlds to remove.");
|
||||
} else {
|
||||
player.dropMessage(5, "Failed to remove world " + rwid + ". Check if there are people currently playing there.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,28 +21,20 @@
|
||||
*/
|
||||
package client.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
|
||||
import tools.Pair;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import constants.inventory.ItemConstants;
|
||||
import server.MapleItemInformationProvider;
|
||||
import client.inventory.manipulator.MapleInventoryManipulator;
|
||||
import tools.FilePrinter;
|
||||
import constants.inventory.ItemConstants;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import server.MapleItemInformationProvider;
|
||||
import server.ThreadManager;
|
||||
import tools.FilePrinter;
|
||||
import tools.Pair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -196,12 +188,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
if (ret.size() > 1) {
|
||||
Collections.sort(ret, new Comparator<Item>() {
|
||||
@Override
|
||||
public int compare(Item i1, Item i2) {
|
||||
return i1.getPosition() - i2.getPosition();
|
||||
}
|
||||
});
|
||||
Collections.sort(ret, (i1, i2) -> i1.getPosition() - i2.getPosition());
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -216,12 +203,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
if (ret.size() > 1) {
|
||||
Collections.sort(ret, new Comparator<Item>() {
|
||||
@Override
|
||||
public int compare(Item i1, Item i2) {
|
||||
return i1.getPosition() - i2.getPosition();
|
||||
}
|
||||
});
|
||||
Collections.sort(ret, (i1, i2) -> i1.getPosition() - i2.getPosition());
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -334,12 +316,8 @@ public class MapleInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
if (ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
ThreadManager.getInstance().newTask(new Runnable() { // deadlocks with coupons rates found thanks to GabrielSin & Masterrulax
|
||||
@Override
|
||||
public void run() {
|
||||
owner.updateCouponRates();
|
||||
}
|
||||
});
|
||||
// deadlocks with coupons rates found thanks to GabrielSin & Masterrulax
|
||||
ThreadManager.getInstance().newTask(() -> owner.updateCouponRates());
|
||||
}
|
||||
|
||||
return slotId;
|
||||
@@ -354,12 +332,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
if (ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
owner.updateCouponRates();
|
||||
}
|
||||
});
|
||||
ThreadManager.getInstance().newTask(() -> owner.updateCouponRates());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,12 +346,7 @@ public class MapleInventory implements Iterable<Item> {
|
||||
}
|
||||
|
||||
if (item != null && ItemConstants.isRateCoupon(item.getItemId())) {
|
||||
ThreadManager.getInstance().newTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
owner.updateCouponRates();
|
||||
}
|
||||
});
|
||||
ThreadManager.getInstance().newTask(() -> owner.updateCouponRates());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
package client.newyear;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import net.server.Server;
|
||||
import server.TimerManager;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -28,10 +32,6 @@ import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import net.server.Server;
|
||||
import server.TimerManager;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -244,23 +244,20 @@ public class NewYearCardRecord {
|
||||
public void startNewYearCardTask() {
|
||||
if(sendTask != null) return;
|
||||
|
||||
sendTask = TimerManager.getInstance().register(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Server server = Server.getInstance();
|
||||
|
||||
int world = server.getCharacterWorld(receiverId);
|
||||
if(world == -1) {
|
||||
sendTask.cancel(false);
|
||||
sendTask = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MapleCharacter target = server.getWorld(world).getPlayerStorage().getCharacterById(receiverId);
|
||||
if(target != null && target.isLoggedinWorld()) {
|
||||
target.announce(MaplePacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0));
|
||||
}
|
||||
sendTask = TimerManager.getInstance().register(() -> {
|
||||
Server server = Server.getInstance();
|
||||
|
||||
int world = server.getCharacterWorld(receiverId);
|
||||
if(world == -1) {
|
||||
sendTask.cancel(false);
|
||||
sendTask = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MapleCharacter target = server.getWorld(world).getPlayerStorage().getCharacterById(receiverId);
|
||||
if(target != null && target.isLoggedinWorld()) {
|
||||
target.announce(MaplePacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0));
|
||||
}
|
||||
}, 1000 * 60 * 60); //1 Hour
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user