Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Oct 3, 2024
1 parent 8773482 commit da0f169
Show file tree
Hide file tree
Showing 82 changed files with 257 additions and 1,094 deletions.
56 changes: 22 additions & 34 deletions src/main/java/cn/nukkit/AdventureSettings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cn.nukkit;

import cn.nukkit.network.protocol.AdventureSettingsPacket;
import cn.nukkit.network.protocol.UpdateAbilitiesPacket;
import cn.nukkit.network.protocol.UpdateAdventureSettingsPacket;
import cn.nukkit.network.protocol.types.AbilityLayer;
Expand Down Expand Up @@ -147,51 +146,40 @@ void update(boolean reset) {
* List of adventure settings
*/
public enum Type {
WORLD_IMMUTABLE(AdventureSettingsPacket.WORLD_IMMUTABLE, null, false),
NO_PVM(AdventureSettingsPacket.NO_PVM, null, false),
NO_MVP(AdventureSettingsPacket.NO_MVP, PlayerAbility.INVULNERABLE, false),
SHOW_NAME_TAGS(AdventureSettingsPacket.SHOW_NAME_TAGS, null, false),
AUTO_JUMP(AdventureSettingsPacket.AUTO_JUMP, null, true),
ALLOW_FLIGHT(AdventureSettingsPacket.ALLOW_FLIGHT, PlayerAbility.MAY_FLY, false),
NO_CLIP(AdventureSettingsPacket.NO_CLIP, PlayerAbility.NO_CLIP, false),
WORLD_BUILDER(AdventureSettingsPacket.WORLD_BUILDER, PlayerAbility.WORLD_BUILDER, false),
FLYING(AdventureSettingsPacket.FLYING, PlayerAbility.FLYING, false),
MUTED(AdventureSettingsPacket.MUTED, PlayerAbility.MUTED, false),
MINE(AdventureSettingsPacket.MINE, PlayerAbility.MINE, true),
DOORS_AND_SWITCHED(AdventureSettingsPacket.DOORS_AND_SWITCHES, PlayerAbility.DOORS_AND_SWITCHES, true),
OPEN_CONTAINERS(AdventureSettingsPacket.OPEN_CONTAINERS, PlayerAbility.OPEN_CONTAINERS, true),
ATTACK_PLAYERS(AdventureSettingsPacket.ATTACK_PLAYERS, PlayerAbility.ATTACK_PLAYERS, true),
ATTACK_MOBS(AdventureSettingsPacket.ATTACK_MOBS, PlayerAbility.ATTACK_MOBS, true),
OPERATOR(AdventureSettingsPacket.OPERATOR, PlayerAbility.OPERATOR_COMMANDS, false),
TELEPORT(AdventureSettingsPacket.TELEPORT, PlayerAbility.TELEPORT, false),
BUILD(AdventureSettingsPacket.BUILD, PlayerAbility.BUILD, true),
PRIVILEGED_BUILDER(0, PlayerAbility.PRIVILEGED_BUILDER, false),
WORLD_IMMUTABLE(null, false),
NO_PVM(null, false),
NO_MVP(PlayerAbility.INVULNERABLE, false),
SHOW_NAME_TAGS(null, false),
AUTO_JUMP(null, true),
ALLOW_FLIGHT(PlayerAbility.MAY_FLY, false),
NO_CLIP(PlayerAbility.NO_CLIP, false),
WORLD_BUILDER(PlayerAbility.WORLD_BUILDER, false),
FLYING(PlayerAbility.FLYING, false),
MUTED(PlayerAbility.MUTED, false),
MINE(PlayerAbility.MINE, true),
DOORS_AND_SWITCHED(PlayerAbility.DOORS_AND_SWITCHES, true),
OPEN_CONTAINERS(PlayerAbility.OPEN_CONTAINERS, true),
ATTACK_PLAYERS(PlayerAbility.ATTACK_PLAYERS, true),
ATTACK_MOBS(PlayerAbility.ATTACK_MOBS, true),
OPERATOR(PlayerAbility.OPERATOR_COMMANDS, false),
TELEPORT(PlayerAbility.TELEPORT, false),
BUILD(PlayerAbility.BUILD, true),
PRIVILEGED_BUILDER(PlayerAbility.PRIVILEGED_BUILDER, false),

// For backwards compatibility
@Deprecated
BUILD_AND_MINE(0, null, true),
BUILD_AND_MINE(null, true),
@Deprecated
DEFAULT_LEVEL_PERMISSIONS(AdventureSettingsPacket.DEFAULT_LEVEL_PERMISSIONS, null, false);
DEFAULT_LEVEL_PERMISSIONS(null, false);

private final int id;
private final PlayerAbility ability;
private final boolean defaultValue;

Type(int id, PlayerAbility ability, boolean defaultValue) {
this.id = id;
Type(PlayerAbility ability, boolean defaultValue) {
this.ability = ability;
this.defaultValue = defaultValue;
}

/**
* Legacy: Get adventure setting ID if available
*
* @return adventure setting ID
*/
public int getId() {
return this.id;
}

/**
* Get default value
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Nukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void main(String[] args) {
}
}

ServerKiller killer = new ServerKiller(8);
ServerKiller killer = new ServerKiller(10);
killer.start();

if (TITLE) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public void setAllowInteract(boolean value, boolean containers) {
}

/**
* Set auto jump adventure setting
* Set auto jump adventure setting (adventureSettings.set(Type.AUTO_JUMP) + adventureSettings.update())
* @param value auto jump enabled
*/
@Deprecated
Expand All @@ -550,7 +550,7 @@ public void setAutoJump(boolean value) {
}

/**
* Check wether auto jump adventure setting is enabled
* Check whether auto jump adventure setting is enabled (adventureSettings.get(Type.AUTO_JUMP))
* @return auto jump enabled
*/
@Deprecated
Expand Down Expand Up @@ -1638,7 +1638,7 @@ public boolean setGamemode(int gamemode, boolean clientSide, AdventureSettings n
}

/**
* Send adventure settings
* Send adventure settings (adventureSettings.update())
*/
@Deprecated
public void sendSettings() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ public boolean isWhitelisted(String name) {
* @return is operator
*/
public boolean isOp(String name) {
return this.operators.exists(name, true);
return name != null && this.operators.exists(name, true);
}

/**
Expand Down Expand Up @@ -2836,7 +2836,7 @@ private void loadSettings() {
this.queryPlugins = this.getConfig("settings.query-plugins", true);

this.networkCompressionThreshold = this.getConfig("network.batch-threshold", 256);
this.networkCompressionLevel = Math.max(Math.min(this.getConfig("network.compression-level", 4), 9), 0);
this.networkCompressionLevel = Math.max(Math.min(this.getConfig("network.compression-level", 5), 9), 0);
this.encryptionEnabled = this.getConfig("network.encryption", false);

this.autoTickRate = this.getConfig("level-settings.auto-tick-rate", true);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/cn/nukkit/block/BlockItemFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
public class BlockItemFrame extends BlockTransparentMeta implements Faceable {

protected final static int[] FACING = {4, 5, 3, 2, 1, 0};

private final static int FACING_BITMASK = 0b0111;
//private final static int MAP_BIT = 0b1000;
protected final static int[] FACING = {8, 9, 3, 2, 1, 0};

public BlockItemFrame() {
this(0);
Expand Down Expand Up @@ -142,22 +139,26 @@ public int getComparatorInputOverride() {
}

public BlockFace getFacing() {
switch (this.getDamage() & FACING_BITMASK) {
switch (this.getDamage()) {
case 0:
case 4:
return BlockFace.WEST;
case 1:
case 5:
return BlockFace.EAST;
case 2:
case 6:
return BlockFace.NORTH;
case 3:
case 7:
return BlockFace.SOUTH;
case 4:
case 8:
return BlockFace.UP;
case 5:
case 9:
return BlockFace.DOWN;
}

return null;
return BlockFace.UP;
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ public BaseInventory getInventory() {
return this.inventory;
}

@Deprecated
public ShulkerBoxInventory getRealInventory() {
return (ShulkerBoxInventory) this.getInventory();
}

@Override
public String getName() {
return this.hasName() ? this.namedTag.getString("CustomName") : "Shulker Box";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.network.protocol.SetDefaultGameTypePacket;
import cn.nukkit.utils.TextFormat;

/**
* Created on 2015/11/12 by xtypr.
Expand Down Expand Up @@ -47,7 +48,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
gameTypePacket.gamemode = sender.getServer().getDefaultGamemode();
Server.broadcastPacket(sender.getServer().getOnlinePlayers().values(), gameTypePacket);
} else {
sender.sendMessage("Unknown game mode");
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.gamemode.fail.invalid", args[0]));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

int gameMode = Server.getGamemodeFromString(args[0]);
if (gameMode == -1) {
sender.sendMessage("Unknown game mode");
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.gamemode.fail.invalid", args[0]));
return true;
}

Expand Down
26 changes: 17 additions & 9 deletions src/main/java/cn/nukkit/command/defaults/SummonCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.entity.Entity;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.level.Position;
import cn.nukkit.network.protocol.AddEntityPacket;
import cn.nukkit.utils.TextFormat;
Expand Down Expand Up @@ -36,16 +37,23 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

if (args.length == 0 || (args.length == 1 && !(sender instanceof Player))) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}

String mob = args[0];

// Convert Minecraft format to the format what Nukkit uses
String mob = Character.toUpperCase(args[0].charAt(0)) + args[0].substring(1);
int max = mob.length() - 1;
for (int x = 2; x < max; x++) {
if (mob.charAt(x) == '_') {
mob = mob.substring(0, x) + Character.toUpperCase(mob.charAt(x + 1)) + mob.substring(x + 2);
if (!Entity.isKnown(mob)) {
mob = Character.toUpperCase(args[0].charAt(0)) + args[0].substring(1);
StringBuilder sb = new StringBuilder(mob);
for (int x = 2; x < sb.length() - 1; x++) {
if (sb.charAt(x) == '_') {
sb.setCharAt(x + 1, Character.toUpperCase(sb.charAt(x + 1)));
sb.deleteCharAt(x);
}
}
mob = sb.toString();
}

Player playerThatSpawns;
Expand All @@ -57,16 +65,16 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

if (playerThatSpawns != null) {
Position pos = playerThatSpawns.getPosition().floor().add(0.5, 0, 0.5);
Position pos = playerThatSpawns.floor().add(0.5, 0, 0.5);
Entity ent;
if ((ent = Entity.createEntity(mob, pos)) != null) {
ent.spawnToAll();
sender.sendMessage("§6Spawned " + mob + " to " + playerThatSpawns.getName());
sender.sendMessage(new TranslationContainer("%commands.summon.success"));
} else {
sender.sendMessage(TextFormat.RED + "Unable to spawn " + mob);
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.summon.failed"));
}
} else {
sender.sendMessage(TextFormat.RED + "Unknown player " + (args.length == 2 ? args[1] : sender.getName()));
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public Item dispense(BlockDispenser block, BlockFace face, Item item) {

if (target.getId() == BlockID.AIR) {
Block down = target.down();
if (down.getId() != BlockID.OBSIDIAN || !down.level.createPortal(down, false)) {
if (down.getId() != BlockID.OBSIDIAN || !down.level.createPortal(down)) {
boolean soulFire = down.getId() == Block.SOUL_SAND || down.getId() == Block.SOUL_SOIL;
block.level.setBlock(target, Block.get(soulFire ? BlockID.SOUL_FIRE : BlockID.FIRE));
}
down.level.addSound(down, cn.nukkit.level.Sound.MOB_GHAST_FIREBALL);
item.useOn(target);
} else if (target.getId() == BlockID.TNT) {
target.onActivate(item);
Expand Down
Loading

0 comments on commit da0f169

Please sign in to comment.