Skip to content

Commit

Permalink
fix: Migrate player before create player table
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Mar 7, 2024
1 parent a4c4918 commit f35bd05
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/PlotPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ public void onEnable() {
}
}

this.playerManager = new PlayerManager(this);
if (PlayersMigrator.shouldMigrate(this)) {
PlayersMigrator.migratePlayers(this);
}

this.playerManager = new PlayerManager(this);
server.getScheduler().scheduleDelayedTask(this, this::loadPlayerNames, 1);

server.getPluginManager().registerEvents(new PlotListener(this), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package ms.kevi.plotplugin.listener;

import cn.nukkit.Player;
import cn.nukkit.block.BlockAir;
import cn.nukkit.block.BlockState;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerChatEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.registry.Registries;
import lombok.RequiredArgsConstructor;
import ms.kevi.plotplugin.PlotPlugin;
import ms.kevi.plotplugin.lang.TranslationKey;
Expand Down Expand Up @@ -75,56 +76,87 @@ public void onChat(PlayerChatEvent event) {
} catch (NumberFormatException e) {
break;
}

registration.getLevelSettings().setRoadBiome(biome);
}
case FIRST_LAYER -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setFirstLayerBlockId(blockState.getIdentifier());
registration.getLevelSettings().setFirstLayerBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setFirstLayerBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case MIDDLE_LAYER -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setMiddleLayerBlockId(blockState.getIdentifier());
registration.getLevelSettings().setMiddleLayerBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setMiddleLayerBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case LAST_LAYER -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setLastLayerBlockId(blockState.getIdentifier());
registration.getLevelSettings().setLastLayerBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setLastLayerBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case ROAD -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setRoadBlockId(blockState.getIdentifier());
registration.getLevelSettings().setRoadBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setRoadBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case ROAD_FILLING -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setRoadFillingBlockId(blockState.getIdentifier());
registration.getLevelSettings().setRoadFillingBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setRoadFillingBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case WALL_UNOWNED -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setWallPlotBlockId(blockState.getIdentifier());
registration.getLevelSettings().setWallPlotBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setWallPlotBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case WALL_CLAIMED -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setClaimPlotBlockId(blockState.getIdentifier());
registration.getLevelSettings().setClaimPlotBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setClaimPlotBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case WALL_FILLING -> {
if (!event.getMessage().contains(":")) break;
final BlockState blockState = Item.get(event.getMessage()).getBlock().getBlockState();
registration.getLevelSettings().setWallFillingBlockId(blockState.getIdentifier());
registration.getLevelSettings().setWallFillingBlockMeta(blockState.specialValue());
try {
final BlockState blockState = Registries.BLOCKSTATE.get(Integer.parseInt(event.getMessage()));
if (blockState == BlockAir.STATE) {
break;
}
registration.getLevelSettings().setWallFillingBlockHash(blockState.blockStateHash());
} catch (NumberFormatException ignore) {
}
}
case PLOT_SIZE -> {
final int number;
Expand Down Expand Up @@ -187,43 +219,35 @@ public void onChat(PlayerChatEvent event) {
registration.getLevelSettings().getRoadBiome()));
case FIRST_LAYER -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_FIRST_LAYER,
registration.getLevelSettings().getFirstLayerBlockId() + ":" +
registration.getLevelSettings().getFirstLayerBlockMeta()
registration.getLevelSettings().getFirstLayerState()
));
case MIDDLE_LAYER -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_MIDDLE_LAYER,
registration.getLevelSettings().getMiddleLayerBlockId() + ":" +
registration.getLevelSettings().getMiddleLayerBlockMeta()
registration.getLevelSettings().getMiddleLayerState()
));
case LAST_LAYER -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_LAST_LAYER,
registration.getLevelSettings().getLastLayerBlockId() + ":" +
registration.getLevelSettings().getLastLayerBlockMeta()
registration.getLevelSettings().getLastLayerState()
));
case ROAD -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_ROAD,
registration.getLevelSettings().getRoadBlockId() + ":" +
registration.getLevelSettings().getRoadBlockMeta()
registration.getLevelSettings().getRoadState()
));
case ROAD_FILLING -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_ROAD_FILLING,
registration.getLevelSettings().getRoadFillingBlockId() + ":" +
registration.getLevelSettings().getRoadFillingBlockMeta()
registration.getLevelSettings().getRoadFillingState()
));
case WALL_UNOWNED -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_WALL_UNOWNED,
registration.getLevelSettings().getWallPlotBlockId() + ":" +
registration.getLevelSettings().getWallPlotBlockMeta()
registration.getLevelSettings().getWallPlotState()
));
case WALL_CLAIMED -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_WALL_CLAIMED,
registration.getLevelSettings().getClaimPlotBlockId() + ":" +
registration.getLevelSettings().getClaimPlotBlockMeta()
registration.getLevelSettings().getClaimPlotState()
));
case WALL_FILLING -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_WALL_FILLING,
registration.getLevelSettings().getWallFillingBlockId() + ":" +
registration.getLevelSettings().getWallFillingBlockMeta()
registration.getLevelSettings().getWallFillingState()
));
case PLOT_SIZE -> player.sendMessage(this.plugin.getLanguage().translate(player,
TranslationKey.GENERATE_PLOT_SIZE,
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/ms/kevi/plotplugin/manager/PlotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import cn.nukkit.math.BlockVector3;
import cn.nukkit.math.SimpleAxisAlignedBB;
import cn.nukkit.math.Vector3;
import cn.nukkit.registry.Registries;
import cn.nukkit.utils.Config;
import cn.nukkit.utils.ConfigSection;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand Down Expand Up @@ -436,9 +435,9 @@ public void unlinkPlotFromAll(Plot centerPlot) {
}

private void finishPlotUnlinkFromNeighbors(Plot centerPlot) {
final BlockState claimBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getClaimPlotBlockId()).getBlockState(this.levelSettings.getClaimPlotBlockMeta());
final BlockState wallBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getWallPlotBlockId()).getBlockState(this.levelSettings.getWallPlotBlockMeta());
final BlockState wallFillingBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getWallFillingBlockId()).getBlockState(this.levelSettings.getWallFillingBlockMeta());
final BlockState claimBlock = this.levelSettings.getClaimPlotState();
final BlockState wallBlock = this.levelSettings.getWallPlotState();
final BlockState wallFillingBlock = this.levelSettings.getWallFillingState();

final Set<Plot> plots = new HashSet<>(Collections.singleton(centerPlot));
{
Expand All @@ -463,9 +462,9 @@ private void finishPlotUnlinkFromNeighbors(Plot centerPlot) {
}

private void finishPlotUnlinkFromAll(Set<Plot> plots) {
final BlockState claimBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getClaimPlotBlockId()).getBlockState(this.levelSettings.getClaimPlotBlockMeta());
final BlockState wallBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getWallPlotBlockId()).getBlockState(this.levelSettings.getWallPlotBlockMeta());
final BlockState wallFillingBlock = Registries.BLOCK.getBlockProperties(this.levelSettings.getWallFillingBlockId()).getBlockState(this.levelSettings.getWallFillingBlockMeta());
final BlockState claimBlock = this.levelSettings.getClaimPlotState();
final BlockState wallBlock = this.levelSettings.getWallPlotState();
final BlockState wallFillingBlock = this.levelSettings.getWallFillingState();

for (Plot plot : plots) {
for (int iDir = 0; iDir < 4; iDir++)
Expand Down
55 changes: 19 additions & 36 deletions src/main/java/ms/kevi/plotplugin/util/PlotLevelSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package ms.kevi.plotplugin.util;

import cn.nukkit.block.Block;
import cn.nukkit.block.BlockState;
import cn.nukkit.block.*;
import cn.nukkit.block.property.CommonBlockProperties;
import cn.nukkit.block.property.enums.MinecraftVerticalHalf;
import cn.nukkit.level.Level;
import cn.nukkit.level.biome.BiomeID;
import cn.nukkit.registry.Registries;
Expand All @@ -35,70 +36,52 @@
@Getter
@Setter
public class PlotLevelSettings {

private int dimension = Level.DIMENSION_OVERWORLD;

private int plotBiome = BiomeID.PLAINS;
private int roadBiome = BiomeID.PLAINS;

private int groundHeight = 64;
private int plotSize = 35;
private int roadSize = 7;

private String firstLayerBlockId = Block.BEDROCK;
private short firstLayerBlockMeta = 0;

private String middleLayerBlockId = Block.DIRT;
private short middleLayerBlockMeta = 0;

private String lastLayerBlockId = Block.GRASS;
private short lastLayerBlockMeta = 0;

private String wallFillingBlockId = Block.STONE;
private short wallFillingBlockMeta = 0;

private String wallPlotBlockId = Block.STONE_BLOCK_SLAB;
private short wallPlotBlockMeta = 0;

private String claimPlotBlockId = Block.STONE_BLOCK_SLAB;
private short claimPlotBlockMeta = 1;

private String roadBlockId = Block.OAK_PLANKS;
private short roadBlockMeta = 0;

private String roadFillingBlockId = Block.DIRT;
private short roadFillingBlockMeta = 0;
private int firstLayerBlockHash = BlockBedrock.PROPERTIES.getDefaultState().blockStateHash();
private int middleLayerBlockHash = BlockDirt.PROPERTIES.getDefaultState().blockStateHash();
private int lastLayerBlockHash = BlockGrass.PROPERTIES.getDefaultState().blockStateHash();
private int wallFillingBlockHash = BlockStone.PROPERTIES.getDefaultState().blockStateHash();
private int wallPlotBlockHash = BlockStoneBlockSlab.PROPERTIES.getBlockState(CommonBlockProperties.MINECRAFT_VERTICAL_HALF.createValue(MinecraftVerticalHalf.BOTTOM)).blockStateHash();
private int claimPlotBlockHash = BlockStoneBlockSlab2.PROPERTIES.getBlockState(CommonBlockProperties.MINECRAFT_VERTICAL_HALF.createValue(MinecraftVerticalHalf.BOTTOM)).blockStateHash();
private int roadBlockHash = BlockOakPlanks.PROPERTIES.getDefaultState().blockStateHash();
private int roadFillingBlockHash = BlockDirt.PROPERTIES.getDefaultState().blockStateHash();

public BlockState getFirstLayerState() {
return Registries.BLOCK.getBlockProperties(firstLayerBlockId).getBlockState(this.firstLayerBlockMeta);
return Registries.BLOCKSTATE.get(firstLayerBlockHash);
}

public BlockState getMiddleLayerState() {
return Registries.BLOCK.getBlockProperties(middleLayerBlockId).getBlockState(this.middleLayerBlockMeta);
return Registries.BLOCKSTATE.get(middleLayerBlockHash);
}

public BlockState getLastLayerState() {
return Registries.BLOCK.getBlockProperties(lastLayerBlockId).getBlockState(this.lastLayerBlockMeta);
return Registries.BLOCKSTATE.get(lastLayerBlockHash);
}

public BlockState getWallFillingState() {
return Registries.BLOCK.getBlockProperties(wallFillingBlockId).getBlockState(this.wallFillingBlockMeta);
return Registries.BLOCKSTATE.get(wallFillingBlockHash);
}

public BlockState getWallPlotState() {
return Registries.BLOCK.getBlockProperties(wallPlotBlockId).getBlockState(this.wallPlotBlockMeta);
return Registries.BLOCKSTATE.get(wallPlotBlockHash);
}

public BlockState getClaimPlotState() {
return Registries.BLOCK.getBlockProperties(claimPlotBlockId).getBlockState(this.claimPlotBlockMeta);
return Registries.BLOCKSTATE.get(claimPlotBlockHash);
}

public BlockState getRoadState() {
return Registries.BLOCK.getBlockProperties(roadBlockId).getBlockState(this.roadBlockMeta);
return Registries.BLOCKSTATE.get(roadBlockHash);
}

public BlockState getRoadFillingState() {
return Registries.BLOCK.getBlockProperties(roadFillingBlockId).getBlockState(this.roadFillingBlockMeta);
return Registries.BLOCKSTATE.get(roadFillingBlockHash);
}

public int getTotalSize() {
Expand Down

0 comments on commit f35bd05

Please sign in to comment.