Replace all Runnables with lambda .

This commit is contained in:
KrewsOrg 2020-04-23 18:08:37 +01:00
parent 4b278a2109
commit df2641f215
18 changed files with 98 additions and 179 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "morningstar-default-database"]
path = morningstar-default-database
url = https://git.krews.org/morningstar/morningstar-default-database

View File

@ -75,22 +75,15 @@ public class ButlerBot extends Bot {
tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0));
tasks.add(new Runnable() {
@Override
public void run() {
b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()));
}
});
tasks.add(() -> b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername())));
List<Runnable> failedReached = new ArrayList();
failedReached.add(new Runnable() {
public void run() {
failedReached.add(() -> {
if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) {
for (Runnable t : tasks) {
t.run();
}
}
}
});
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));

View File

@ -59,9 +59,7 @@ public class MassGiftCommand extends Command {
keys.put("message", Emulator.getTexts().getValue("generic.gift.received.anonymous"));
ServerMessage giftNotificiationMessage = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose();
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue();
@ -77,7 +75,6 @@ public class MassGiftCommand extends Command {
habbo.getClient().sendResponse(new InventoryRefreshComposer());
habbo.getClient().sendResponse(giftNotificiationMessage);
}
}
});

View File

@ -44,12 +44,9 @@ public class InteractionEffectGiver extends InteractionDefault {
this.setExtradata("1");
room.updateItem(this);
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
InteractionEffectGiver.this.setExtradata("0");
room.updateItem(instance);
}
}, 500);
}
}

View File

@ -42,12 +42,9 @@ public class InteractionHanditem extends InteractionDefault {
this.setExtradata("1");
room.updateItem(this);
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
InteractionHanditem.this.setExtradata("0");
room.updateItem(instance);
}
}, 500);
}
}

View File

@ -20,13 +20,10 @@ public class InteractionHanditemTile extends InteractionHanditem {
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
InteractionHanditemTile instance = this;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
if (roomUnit.getCurrentLocation().x == instance.getX() && roomUnit.getCurrentLocation().y == instance.getY()) {
instance.handle(room, roomUnit);
}
}
}, 3000);
}
}

View File

@ -56,24 +56,14 @@ public class InteractionPressurePlate extends HabboItem {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
updateState(room);
}
}, 100);
Emulator.getThreading().run(() -> updateState(room), 100);
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects);
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
updateState(room);
}
}, 100);
Emulator.getThreading().run(() -> updateState(room), 100);
}
@Override

View File

@ -48,12 +48,9 @@ public class InteractionTileEffectProvider extends InteractionCustomValues {
room.updateItem(this);
final InteractionTileEffectProvider proxy = this;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
proxy.values.put("state", "0");
room.updateItem(proxy);
}
}, 500);
room.giveEffect(roomUnit, effectId, -1);

View File

@ -52,12 +52,9 @@ public class InteractionTrap extends InteractionDefault {
roomUnit.setCanWalk(false);
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
room.giveEffect(roomUnit, 0, -1);
roomUnit.setCanWalk(true);
}
}, delay);
}
}

View File

@ -150,9 +150,7 @@ public class InteractionPetBreedingNest extends HabboItem {
HabboItem box = this;
Pet petOne = this.petOne;
Pet petTwo = this.petTwo;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient());
//habbo.getClient().sendResponse(new PetPackageNameValidationComposer(box.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, ""));
@ -168,7 +166,6 @@ public class InteractionPetBreedingNest extends HabboItem {
String achievement = boxType.substring(0, 1).toUpperCase() + boxType.substring(1) + "Breeder";
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement(achievement));
}
}
}, 2000);
}

View File

@ -45,14 +45,11 @@ public class InteractionPetToy extends InteractionDefault {
pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, "0");
pet.packetUpdate = true;
HabboItem item = this;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
pet.addHappyness(25);
item.setExtradata("0");
room.updateItem(item);
new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run();
}
}, 2500 + (Emulator.getRandom().nextInt(20) * 500));
this.setExtradata("1");
room.updateItemState(this);

View File

@ -72,12 +72,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
boolean hasHabbos = false;
for (Habbo habbo : room.getHabbosAt(targetTile)) {
hasHabbos = true;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{entry.getKey()});
}
});
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{entry.getKey()}));
}
if (!hasHabbos) {

View File

@ -58,12 +58,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
if (target != null) {
if (RoomLayout.tilesAdjecent(target.getRoomUnit().getCurrentLocation(), room.getLayout().getTile(item.getX(), item.getY())) && (target.getRoomUnit().getX() == item.getX() || target.getRoomUnit().getY() == item.getY())) {
final Habbo finalTarget = target;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
WiredHandler.handle(WiredTriggerType.COLLISION, finalTarget.getRoomUnit(), room, new Object[]{item});
}
}, 500);
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, finalTarget.getRoomUnit(), room, new Object[]{item}), 500);
continue;
}

View File

@ -717,15 +717,12 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
if (oldZ != roomUnit.getZ()) {
this.scheduledTasks.add(new Runnable() {
@Override
public void run() {
this.scheduledTasks.add(() -> {
try {
item.onWalkOn(roomUnit, Room.this, null);
} catch (Exception e) {
}
}
});
}
}
@ -1039,12 +1036,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.loaded) {
try {
Emulator.getThreading().run(
new Runnable() {
@Override
public void run() {
Room.this.cycle();
}
});
Room.this::cycle);
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
@ -1175,12 +1167,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
habbo.getRoomUnit().kickCount++;
if (habbo.getRoomUnit().kickCount >= 5) {
this.scheduledTasks.add(new Runnable() {
@Override
public void run() {
Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room);
}
});
this.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room));
continue;
}
}
@ -1471,9 +1458,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y);
if (item != null && itemsNewTile.contains(item)) {
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
if (unit.getGoal() == rollerTile) {
try {
item.onWalkOn(unit, room, null);
@ -1481,7 +1466,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
Emulator.getLogging().logErrorLine(e);
}
}
}
}, this.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY);
}
}

View File

@ -8,7 +8,6 @@ import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboManager;
import com.eu.habbo.habbohotel.users.inventory.EffectsComponent;
import com.eu.habbo.messages.NoAuthMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.MessageHandler;
@ -36,7 +35,6 @@ import com.eu.habbo.plugin.events.users.UserLoginEvent;
import gnu.trove.map.hash.THashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@NoAuthMessage
@ -178,15 +176,12 @@ public class SecureLoginEvent extends MessageHandler {
if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) {
final Habbo finalHabbo = habbo;
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
if (Emulator.getConfig().getBoolean("hotel.welcome.alert.oldstyle")) {
SecureLoginEvent.this.client.sendResponse(new MessagesForYouComposer(HabboManager.WELCOME_MESSAGE.replace("%username%", finalHabbo.getHabboInfo().getUsername()).replace("%user%", finalHabbo.getHabboInfo().getUsername()).split("<br/>")));
} else {
SecureLoginEvent.this.client.sendResponse(new GenericAlertComposer(HabboManager.WELCOME_MESSAGE.replace("%username%", finalHabbo.getHabboInfo().getUsername()).replace("%user%", finalHabbo.getHabboInfo().getUsername())));
}
}
}, Emulator.getConfig().getInt("hotel.welcome.alert.delay", 5000));
}

View File

@ -70,9 +70,7 @@ public class ReportEvent extends MessageHandler {
if (cfhTopic != null) {
if (cfhTopic.action != CfhActionType.MODS) {
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
if (issue.state == ModToolTicketState.OPEN) {
if (cfhTopic.action == CfhActionType.AUTO_IGNORE) {
ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(reported.getHabboInfo().getId());
@ -82,7 +80,6 @@ public class ReportEvent extends MessageHandler {
ReportEvent.this.client.sendResponse(new ModToolIssueHandledComposer(cfhTopic.reply).compose());
Emulator.getGameEnvironment().getModToolManager().closeTicketAsHandled(issue, null);
}
}
}, 30 * 1000);
}
}
@ -99,9 +96,7 @@ public class ReportEvent extends MessageHandler {
if (cfhTopic != null) {
if (cfhTopic.action != CfhActionType.MODS) {
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
if (issue.state == ModToolTicketState.OPEN) {
if (cfhTopic.action == CfhActionType.AUTO_IGNORE) {
ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(issue.reportedId);
@ -114,7 +109,6 @@ public class ReportEvent extends MessageHandler {
ReportEvent.this.client.sendResponse(new ModToolIssueHandledComposer(cfhTopic.reply).compose());
Emulator.getGameEnvironment().getModToolManager().closeTicketAsHandled(issue, null);
}
}
}, 30 * 1000);
}
}

View File

@ -38,15 +38,12 @@ public class ThreadPooling {
public ScheduledFuture run(Runnable run, long delay) {
try {
if (this.canAdd) {
return this.scheduledPool.schedule(new Runnable() {
@Override
public void run() {
return this.scheduledPool.schedule(() -> {
try {
run.run();
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
}
}, delay, TimeUnit.MILLISECONDS);
}
} catch (Exception e) {

View File

@ -29,12 +29,9 @@ public class HopperActionOne implements Runnable {
this.client.getHabbo().getRoomUnit().setZ(this.teleportOne.getZ());
this.client.getHabbo().getRoomUnit().setPreviousLocationZ(this.teleportOne.getZ());
Emulator.getThreading().run(new Runnable() {
@Override
public void run() {
Emulator.getThreading().run(() -> {
HopperActionOne.this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
HopperActionOne.this.room.sendComposer(new RoomUserStatusComposer(HopperActionOne.this.client.getHabbo().getRoomUnit()).compose());
}
}, 750);
Emulator.getThreading().run(new HopperActionTwo(this.teleportOne, this.room, this.client), 1250);