From b38ea75c22799a49f8a5155535504668306b51b7 Mon Sep 17 00:00:00 2001 From: Benjamin Amos Date: Sat, 12 Feb 2022 14:35:27 +0000 Subject: [PATCH 1/2] fix(gestalt): expose additional API classes to modules --- .../main/java/org/destinationsol/Const.java | 3 +++ .../java/org/destinationsol/GameOptions.java | 2 ++ .../asteroids/components/package-info.java | 18 ++++++++++++++++++ .../body/components/package-info.java | 18 ++++++++++++++++++ .../body/events/package-info.java | 18 ++++++++++++++++++ .../health/components/package-info.java | 18 ++++++++++++++++++ .../health/events/package-info.java | 18 ++++++++++++++++++ .../location/components/package-info.java | 18 ++++++++++++++++++ .../location/events/package-info.java | 18 ++++++++++++++++++ .../moneyDropping/components/package-info.java | 18 ++++++++++++++++++ .../removal/components/package-info.java | 18 ++++++++++++++++++ .../removal/events/package-info.java | 18 ++++++++++++++++++ .../rendering/RenderableElement.java | 2 ++ .../rendering/components/package-info.java | 18 ++++++++++++++++++ .../rendering/events/package-info.java | 18 ++++++++++++++++++ .../rubble/components/package-info.java | 18 ++++++++++++++++++ .../size/components/package-info.java | 18 ++++++++++++++++++ .../stasis/components/package-info.java | 18 ++++++++++++++++++ 18 files changed, 277 insertions(+) create mode 100644 engine/src/main/java/org/destinationsol/asteroids/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/body/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/body/events/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/health/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/health/events/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/location/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/location/events/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/moneyDropping/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/removal/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/removal/events/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/rendering/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/rendering/events/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/rubble/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/size/components/package-info.java create mode 100644 engine/src/main/java/org/destinationsol/stasis/components/package-info.java diff --git a/engine/src/main/java/org/destinationsol/Const.java b/engine/src/main/java/org/destinationsol/Const.java index c3ab949d1..433f35423 100644 --- a/engine/src/main/java/org/destinationsol/Const.java +++ b/engine/src/main/java/org/destinationsol/Const.java @@ -15,6 +15,9 @@ */ package org.destinationsol; +import org.terasology.gestalt.module.sandbox.API; + +@API public class Const { public static final float ATM_HEIGHT = 14f; public static final float MAX_SKY_HEIGHT_FROM_GROUND = 1.5f * ATM_HEIGHT; diff --git a/engine/src/main/java/org/destinationsol/GameOptions.java b/engine/src/main/java/org/destinationsol/GameOptions.java index d8493f5f8..3c519be87 100644 --- a/engine/src/main/java/org/destinationsol/GameOptions.java +++ b/engine/src/main/java/org/destinationsol/GameOptions.java @@ -20,9 +20,11 @@ import com.google.common.base.Enums; import org.destinationsol.menu.Resolution; import org.destinationsol.menu.ResolutionProvider; +import org.terasology.gestalt.module.sandbox.API; import static java.util.Arrays.asList; +@API public class GameOptions { public enum ControlType { KEYBOARD("Keyboard"), diff --git a/engine/src/main/java/org/destinationsol/asteroids/components/package-info.java b/engine/src/main/java/org/destinationsol/asteroids/components/package-info.java new file mode 100644 index 000000000..778e87144 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/asteroids/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.asteroids.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/body/components/package-info.java b/engine/src/main/java/org/destinationsol/body/components/package-info.java new file mode 100644 index 000000000..722b39378 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/body/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.body.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/body/events/package-info.java b/engine/src/main/java/org/destinationsol/body/events/package-info.java new file mode 100644 index 000000000..ed9247bb5 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/body/events/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.body.events; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/health/components/package-info.java b/engine/src/main/java/org/destinationsol/health/components/package-info.java new file mode 100644 index 000000000..67ef0d5ac --- /dev/null +++ b/engine/src/main/java/org/destinationsol/health/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.health.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/health/events/package-info.java b/engine/src/main/java/org/destinationsol/health/events/package-info.java new file mode 100644 index 000000000..e6d7f8f34 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/health/events/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.health.events; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/location/components/package-info.java b/engine/src/main/java/org/destinationsol/location/components/package-info.java new file mode 100644 index 000000000..edb437671 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/location/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.location.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/location/events/package-info.java b/engine/src/main/java/org/destinationsol/location/events/package-info.java new file mode 100644 index 000000000..3f32f61dc --- /dev/null +++ b/engine/src/main/java/org/destinationsol/location/events/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.location.events; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/moneyDropping/components/package-info.java b/engine/src/main/java/org/destinationsol/moneyDropping/components/package-info.java new file mode 100644 index 000000000..d36d5ebd4 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/moneyDropping/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.moneyDropping.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/removal/components/package-info.java b/engine/src/main/java/org/destinationsol/removal/components/package-info.java new file mode 100644 index 000000000..c36660e69 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/removal/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.removal.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/removal/events/package-info.java b/engine/src/main/java/org/destinationsol/removal/events/package-info.java new file mode 100644 index 000000000..59c4b0222 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/removal/events/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.removal.events; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/rendering/RenderableElement.java b/engine/src/main/java/org/destinationsol/rendering/RenderableElement.java index e0df1d201..f5320397c 100644 --- a/engine/src/main/java/org/destinationsol/rendering/RenderableElement.java +++ b/engine/src/main/java/org/destinationsol/rendering/RenderableElement.java @@ -21,10 +21,12 @@ import org.destinationsol.common.SolMath; import org.destinationsol.game.drawables.DrawableLevel; import org.destinationsol.size.components.Size; +import org.terasology.gestalt.module.sandbox.API; /** * Contains a {@link TextureAtlas.AtlasRegion} (an image), along with information about how it should be drawn. */ +@API public class RenderableElement { /** Represents the image of this element. */ diff --git a/engine/src/main/java/org/destinationsol/rendering/components/package-info.java b/engine/src/main/java/org/destinationsol/rendering/components/package-info.java new file mode 100644 index 000000000..1830db29f --- /dev/null +++ b/engine/src/main/java/org/destinationsol/rendering/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.rendering.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/rendering/events/package-info.java b/engine/src/main/java/org/destinationsol/rendering/events/package-info.java new file mode 100644 index 000000000..fb2034241 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/rendering/events/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.rendering.events; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/rubble/components/package-info.java b/engine/src/main/java/org/destinationsol/rubble/components/package-info.java new file mode 100644 index 000000000..91e205760 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/rubble/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.rubble.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/size/components/package-info.java b/engine/src/main/java/org/destinationsol/size/components/package-info.java new file mode 100644 index 000000000..230266ec1 --- /dev/null +++ b/engine/src/main/java/org/destinationsol/size/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.size.components; + +import org.terasology.gestalt.module.sandbox.API; diff --git a/engine/src/main/java/org/destinationsol/stasis/components/package-info.java b/engine/src/main/java/org/destinationsol/stasis/components/package-info.java new file mode 100644 index 000000000..287d85dad --- /dev/null +++ b/engine/src/main/java/org/destinationsol/stasis/components/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 MovingBlocks + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@API package org.destinationsol.stasis.components; + +import org.terasology.gestalt.module.sandbox.API; From 0a0d2b9e94cfaffda791fa3429cb04416e234878 Mon Sep 17 00:00:00 2001 From: Benjamin Amos Date: Sat, 12 Feb 2022 14:36:21 +0000 Subject: [PATCH 2/2] fix(gestalt): Use AccessController::doPrivileged when saving to allow module-initiated saves --- .../org/destinationsol/game/SaveManager.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/engine/src/main/java/org/destinationsol/game/SaveManager.java b/engine/src/main/java/org/destinationsol/game/SaveManager.java index 7972e6072..9e50a0078 100644 --- a/engine/src/main/java/org/destinationsol/game/SaveManager.java +++ b/engine/src/main/java/org/destinationsol/game/SaveManager.java @@ -45,6 +45,8 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -59,16 +61,19 @@ protected SaveManager() { } public static void writeShips(HullConfig hull, float money, List itemsList, Hero hero, HullConfigManager hullConfigManager) { String hullName = hullConfigManager.getName(hull); - writeMercs(hero, hullConfigManager); + AccessController.doPrivileged((PrivilegedAction) () -> { + writeMercs(hero, hullConfigManager); - String items = itemsToString(itemsList); + String items = itemsToString(itemsList); - Vector2 pos = hero.getPosition(); + Vector2 pos = hero.getPosition(); - String waypoints = waypointsToString(hero.getWaypoints()); + String waypoints = waypointsToString(hero.getWaypoints()); - IniReader.write(Const.SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items, - "x", pos.x, "y", pos.y, "waypoints", waypoints, "version", Const.VERSION); + IniReader.write(Const.SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items, + "x", pos.x, "y", pos.y, "waypoints", waypoints, "version", Const.VERSION); + return null; + }); } private static String waypointsToString(ArrayList waypoints) { @@ -246,12 +251,16 @@ public static void saveWorld(int numberOfSystems) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String stringToWrite = gson.toJson(world); - try (PrintWriter writer = new PrintWriter(fileName, "UTF-8")) { - writer.write(stringToWrite); - logger.debug("Successfully saved the world file"); - } catch (FileNotFoundException | UnsupportedEncodingException e) { - logger.error("Could not save world file", e); - } + AccessController.doPrivileged((PrivilegedAction) () -> { + try (PrintWriter writer = new PrintWriter(fileName, "UTF-8")) { + writer.write(stringToWrite); + logger.debug("Successfully saved the world file"); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + logger.error("Could not save world file", e); + } + + return null; + }); } /**