Skip to content

Commit

Permalink
Fixed: Исправлено ломание сохранений
Browse files Browse the repository at this point in the history
- Добавлена команда dimensions_list
- Событие остановки сервера перенесено в ServerStopEvent
  • Loading branch information
Reider745 committed May 11, 2024
1 parent a965f2e commit 8893dfa
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ max-packet-sending: 200
+ inner_core_network — выводит список подключенных к протоколу игроков на сервере
+ state — выводит стейты блока по рантайм идентификатору
+ profilecallback [enabled] [showParameters] — отладка и профайлинг калбеков
+ dimensions_list - выводит список измерений

> Все команды предназначены для операторов и не могут быть вызваны игроками.
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/reider745/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public static void afterload(Server server) {
public static void start(Server server) {
innerCoreServer.start();
}

public static void stop(Server server) throws Exception {
try {
innerCoreServer.left();
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) throws Throwable {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/reider745/commands/CommandsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public static void init() {
map.register(tag, new GenChunksCommands());
map.register(tag, new CallbackProfilingCommand());
map.register(tag, new GetAllPlayersIdCommand());
map.register(tag, new DimensionsList());
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/reider745/commands/DimensionsList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.reider745.commands;

import cn.nukkit.Server;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import com.reider745.world.FakeDimensions;

public class DimensionsList extends Command {
public DimensionsList() {
super("dimensions_list", "get list dimensions");
}

@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] args) {
if (!commandSender.isOp())
return false;

StringBuilder builder = new StringBuilder();

builder.append("====Dimensions====");
Server.getInstance().getLevels().forEach((levelId, level) ->
builder.append("\nid: ")
.append(FakeDimensions.getFakeIdForLevel(level))
.append(", name: ")
.append(level.getName()));

commandSender.sendMessage(builder.toString());
return true;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/reider745/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cn.nukkit.event.player.*;
import cn.nukkit.event.redstone.RedstoneUpdateEvent;
import cn.nukkit.event.server.ServerCommandEvent;
import cn.nukkit.event.server.ServerStopEvent;
import cn.nukkit.form.response.FormResponse;
import cn.nukkit.form.response.FormResponseModal;
import cn.nukkit.form.response.FormResponseSimple;
Expand All @@ -34,6 +35,8 @@
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.Vector3;
import cn.nukkit.network.protocol.UpdateBlockPacket;
import com.reider745.InnerCoreServer;
import com.reider745.Main;
import com.reider745.world.BiomesMethods;
import com.reider745.world.FakeDimensions;
import oshi.hardware.NetworkIF;
Expand Down Expand Up @@ -522,6 +525,15 @@ public void onPlayerFormResponded(PlayerFormRespondedEvent event) {
}
}

@EventHandler
public void stopServer(ServerStopEvent event){
try {
Main.innerCoreServer.left();
} catch (Exception e) {
e.printStackTrace();
}
}

// TODO: onPathNavigationDone

// TODO: onBlockSpawnResources
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/reider745/hooks/ServerHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ public static void checkTickUpdates(Server server, int tick) {

}

@Inject
public static void forceShutdown(Server server, String reason) throws Exception {
Main.LoadingStages.stop(server);
}

@Inject(type = TypeHook.AFTER)
public static void reload(Server server) {
InnerCoreServer.singleton.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import java.util.*;

public class ItemContainer implements WorkbenchField {
public class ItemContainer implements WorkbenchField, ObjectSaverRegistry.IHashSaver {
private static final Object playerInventoryLock = new Object();

public static void loadClass() {
Expand Down Expand Up @@ -161,6 +161,17 @@ public void onRemove(ConnectedClient client) {

return packet;
});
private int id;

@Override
public int getId() {
return id;
}

@Override
public void setId(int id) {
this.id = id;
}


public interface Transaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<ConnectedClient> getInitializingClients() {
}

public List<ConnectedClient> getConnectedClients() {
return connectedClients;
return new ArrayList<>(connectedClients);
}

public ConnectedClient getConnectedClientForPlayer(long player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Created by zheka on 14.02.2018.
*/

public class NativeItemInstanceExtra {
public class NativeItemInstanceExtra implements ObjectSaverRegistry.IHashSaver {
private static final int saverId;

static {
Expand Down Expand Up @@ -590,4 +590,16 @@ public static NativeItemInstanceExtra fromJson(JSONObject json) {
}
return extra;
}

private int id;

@Override
public int getId() {
return id;
}

@Override
public void setId(int id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

@Deprecated(since = "Zote")
public class Container implements WorkbenchField, UiAbstractContainer {
public class Container implements WorkbenchField, UiAbstractContainer, ObjectSaverRegistry.IHashSaver {
public static final boolean isContainer = true;

private static final int saverId;
Expand Down Expand Up @@ -208,6 +208,18 @@ public void close() {
}
}

private int id;

@Override
public int getId() {
return id;
}

@Override
public void setId(int id) {
this.id = id;
}

public interface OnCloseListener {
void onClose(Container c, IWindow win);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.zhekasmirnov.innercore.api.runtime.saver;

import com.zhekasmirnov.horizon.runtime.logger.Logger;
import com.zhekasmirnov.innercore.api.NativeItemInstanceExtra;
import com.zhekasmirnov.innercore.api.mod.ScriptableObjectHelper;
import com.zhekasmirnov.innercore.api.mod.ui.container.Container;
import com.zhekasmirnov.innercore.api.runtime.saver.world.WorldDataSaver;
import org.json.JSONObject;
import org.mozilla.javascript.*;

import java.util.HashMap;
import java.util.Map;

/**
* Created by zheka on 19.08.2017.
Expand All @@ -14,11 +18,12 @@
public class ObjectSaverRegistry {
public static final String PROPERTY_IGNORE_SAVE = "_json_ignore";
public static final String PROPERTY_SAVER_ID = "_json_saver_id";
public static final String PROPERTY_SAVER_ENABLE = "_json_saver_enable";

private static final ScriptableObject scope;

private static HashMap<Integer, ObjectSaver> saverMap = new HashMap<>();
private static HashMap<Integer, ObjectSaver> saverByObjectHash = new HashMap<>();
//private static HashMap<Integer, ObjectSaver> saverByObjectHash = new HashMap<>();
private static HashMap<Integer, String> saverNameById = new HashMap<>();

static {
Expand All @@ -28,7 +33,10 @@ public class ObjectSaverRegistry {
NativeItemInstanceExtra.initSaverId();
}


public interface IHashSaver {
int getId();
void setId(int id);
}

public static int registerSaver(String name, ObjectSaver saver) {
int saverId = name.hashCode();
Expand Down Expand Up @@ -57,7 +65,16 @@ static Object unwrapIfNeeded(Object object) {
}

public static ObjectSaver getSaverFor(Object object) {
ObjectSaver saver = saverByObjectHash.get(object.hashCode());
ObjectSaver saver = null;
if(object instanceof ScriptableObject scriptable){
int id = ScriptableObjectHelper.getIntProperty(scriptable, PROPERTY_SAVER_ENABLE, -1);
if(id != -1)
saver = saverMap.get(id);
}else if(object instanceof IHashSaver hashSaver){
saver = saverMap.get(hashSaver.getId());
}else if(object instanceof JSONObject json && json.has(PROPERTY_SAVER_ENABLE)){
saver = saverMap.get(json.getInt(PROPERTY_SAVER_ENABLE));
}
if (saver != null) {
return saver;
}
Expand Down Expand Up @@ -151,7 +168,15 @@ public static void registerObject(Object object, int saverId) {
throw new IllegalArgumentException("no saver found for id " + saverId + " use only registerObjectSaver return values");
}
object = unwrapIfNeeded(object);
saverByObjectHash.put(object.hashCode(), saverMap.get(saverId));
if (object instanceof ScriptableObject scriptable){
scriptable.put(PROPERTY_SAVER_ENABLE, scriptable, saverId);
}else if(object instanceof JSONObject json){
json.put(PROPERTY_SAVER_ENABLE, saverId);
}else if(object instanceof IHashSaver hashSaver){
hashSaver.setId(saverId);
}else {
Logger.warning("Error registerObject "+object.getClass().getName()+", serverId: "+saverId);
}
}

public static void setObjectIgnored(ScriptableObject object, boolean ignore) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/innercore/coreengine/core-engine.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,12 @@ var TileEntity = {
return null;
},
destroyTileEntity: function(tileEntity, fromDestroyBlock, isDropAllowed) {
if (tileEntity.destroy(fromDestroyBlock || false, isDropAllowed || false)) {
return false;
try{
if (tileEntity.destroy(fromDestroyBlock || false, isDropAllowed || false)) {
return false;
}
}catch(e){
print("Error destroy tile "+e);
}
tileEntity.update = function() {}; // make sure tile entity will not tick anymore, because it is already cleaned up
if (tileEntity.networkEntity) {
Expand Down

0 comments on commit 8893dfa

Please sign in to comment.