-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add more flexible configuration for Random Teleport. * Complete configurations with missing unsafe blocks and air blocks * Fix issues reported by @coderabbitai * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportRadiusRepresenterImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Resolve issues reported in review, create `RandomTeleportRadiusRepresenterImpl#of` methods. * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportRadiusRepresenterImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportServiceImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Add import. * Remvoe buttons, add height range * Fix comments * Add teleportation counting. * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Move description. * Rename some classes make API more usable. * Teleport players without waiting with the `/rtp <player> (admin command). * Add migrations, rename configs * Fix migration --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Rollczi <[email protected]>
- Loading branch information
1 parent
9978731
commit 18e5722
Showing
26 changed files
with
770 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.time.Duration; | ||
|
||
@Deprecated | ||
public interface DelaySettings { | ||
|
||
Duration delay(); | ||
|
17 changes: 17 additions & 0 deletions
17
...e-api/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportRadius.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.eternalcode.core.feature.randomteleport; | ||
|
||
public interface RandomTeleportRadius { | ||
int maxZ(); | ||
int minZ(); | ||
int maxX(); | ||
int minX(); | ||
|
||
static RandomTeleportRadius of(int minX, int maxX, int minZ, int maxZ) { | ||
return new SimpleRandomTeleportRadius(minX, maxX, minZ, maxZ); | ||
} | ||
|
||
static RandomTeleportRadius of(int radius) { | ||
return new SimpleRandomTeleportRadius(-radius, radius, -radius, radius); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/eternalcode/core/feature/randomteleport/SimpleRandomTeleportRadius.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.eternalcode.core.feature.randomteleport; | ||
|
||
record SimpleRandomTeleportRadius(int minX, int maxX, int minZ, int maxZ) implements RandomTeleportRadius { | ||
public SimpleRandomTeleportRadius { | ||
if (minX > maxX) { | ||
throw new IllegalArgumentException("minX cannot be greater than maxX"); | ||
} | ||
if (minZ > maxZ) { | ||
throw new IllegalArgumentException("minZ cannot be greater than maxZ"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
eternalcore-core/src/main/java/com/eternalcode/core/configuration/migration/Migration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
public interface Migration { | ||
|
||
boolean migrate(); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...-core/src/main/java/com/eternalcode/core/configuration/migration/MigrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
import com.eternalcode.core.configuration.ConfigurationManager; | ||
import com.eternalcode.core.configuration.ReloadableConfig; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.component.Controller; | ||
import com.eternalcode.core.publish.Subscribe; | ||
import com.eternalcode.core.publish.Subscriber; | ||
import com.eternalcode.core.publish.event.EternalInitializeEvent; | ||
import java.util.logging.Logger; | ||
|
||
@Controller | ||
class MigrationController implements Subscriber { | ||
|
||
private final MigrationService migrationService; | ||
private final ConfigurationManager configurationManager; | ||
private final Logger logger; | ||
|
||
@Inject | ||
MigrationController(MigrationService migrationService, ConfigurationManager configurationManager, Logger logger) { | ||
this.migrationService = migrationService; | ||
this.configurationManager = configurationManager; | ||
this.logger = logger; | ||
} | ||
|
||
@Subscribe | ||
void onMigration(EternalInitializeEvent event) { | ||
for (ReloadableConfig config : configurationManager.getConfigs()) { | ||
boolean wasMigrated = migrationService.migrate(config); | ||
|
||
if (wasMigrated) { | ||
configurationManager.save(config); | ||
logger.info("Configuration " + config.getClass().getSimpleName() + " was migrated and saved."); | ||
} | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ore-core/src/main/java/com/eternalcode/core/configuration/migration/MigrationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
import com.eternalcode.core.configuration.ReloadableConfig; | ||
import com.eternalcode.core.injector.annotations.component.Service; | ||
import com.eternalcode.core.util.ReflectUtil; | ||
import java.lang.reflect.Field; | ||
import net.dzikoysk.cdn.entity.Contextual; | ||
|
||
@Service | ||
class MigrationService { | ||
|
||
public <T extends ReloadableConfig> boolean migrate(T config) { | ||
return reflectMigrate(config); | ||
} | ||
|
||
private <T> boolean reflectMigrate(T config) { | ||
boolean isMigrated = false; | ||
|
||
for (Field declaredField : ReflectUtil.getAllSuperFields(config.getClass())) { | ||
Class<?> fieldType = declaredField.getType(); | ||
|
||
if (Migration.class.isAssignableFrom(fieldType)) { | ||
Migration migration = ReflectUtil.getFieldValue(declaredField, config); | ||
boolean wasMigrationSuccessful = migration.migrate(); | ||
isMigrated |= wasMigrationSuccessful; | ||
} | ||
|
||
if (fieldType.isAnnotationPresent(Contextual.class)) { | ||
Object fieldValue = ReflectUtil.getFieldValue(declaredField, config); | ||
isMigrated |= reflectMigrate(fieldValue); | ||
} | ||
} | ||
|
||
return isMigrated; | ||
} | ||
|
||
} |
Oops, something went wrong.