Skip to content

Commit

Permalink
feat: фикс брони
Browse files Browse the repository at this point in the history
- фикс брони
- исправлено получение локализации
  • Loading branch information
Reider745 committed Dec 19, 2023
1 parent 4a1a042 commit 799df2d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/reider745/InnerCoreServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public static String getGameLanguage() {

final StringBuilder icLang = new StringBuilder();
for(int i = 0;i < lang.length()-1;i++)
icLang.append(lang.indexOf(i));

icLang.append(lang.charAt(i));
return icLang.toString();
}

Expand Down Expand Up @@ -294,7 +293,7 @@ public void afterload() {
InnerCoreServer.server.getPluginManager().registerEvents(new EventListener(), InnerCoreServer.plugin);

CustomBlock.init();
CustomItem.init();
CustomItem.postInit();
NativeWorkbench.init();
NativeFurnaceRegistry.init();
CommandsHelper.init();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/reider745/api/CustomManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public CustomManager(int id, Class clazz, String type){
}

public <T>T get(String key, T def){
T value = (T) parameters.get(key);
if(value == null)
if(!parameters.containsKey(key))
return def;
return value;
return (T) parameters.get(key);
}

public Class<?> getClazz() {
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 @@ -14,5 +14,6 @@ public static void init(){
map.register(fallbackPrefix, new StateCommand());
map.register(fallbackPrefix, new InnerCoreNetworkCommand());
map.register(fallbackPrefix, new GenChunksCommands());
map.register(fallbackPrefix, new PlayerInfoCommand());
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/reider745/commands/PlayerInfoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.reider745.commands;

import cn.nukkit.Player;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import com.reider745.hooks.PlayerHooks;
import com.zhekasmirnov.apparatus.multiplayer.server.ConnectedClient;

public class PlayerInfoCommand extends Command {
public PlayerInfoCommand() {
super("player_info", "debug inner core network player");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
new CommandParameter("player", CommandParamType.STRING, false),
});
}

@Override
public boolean execute(CommandSender commandSender, String s, String[] args) {
if(!commandSender.isOp() || args.length < 1) return false;

Player player = commandSender.getServer().getPlayer(args[0]);
if(player != null){
ConnectedClient client = PlayerHooks.getForPlayer(player);
if(client == null) return false;

commandSender.sendMessage("=====" + args[0] + "=====\n" + "ConnectedClient protocol: " + client.getChannelInterface().getChannel().getProtocolId());
return true;
}

return false;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/reider745/hooks/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public static Item fromString(String str) {
return Item.get(id, meta.orElse(0));
}

@Inject
public static void initCreativeItems(){
CustomItem.init();
}

@Inject(signature = "()Ljava/lang/Short;", type = TypeHook.BEFORE)
public static void getFuelTime(HookController controller) {
short fuel = NativeFurnaceRegistry.getBurnTime(controller.getSelf());
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/reider745/item/CustomItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class CustomItem {

public static void init(){
items.forEach((key, value) -> Item.list[key] = value.getClazz());
}

public static void postInit(){
foods.forEach((key, value) -> Food.registerFood(new FoodNormal(value, 4), InnerCoreServer.plugin).addRelative(key));
CustomBlock.blocks.forEach((id, manager) -> Item.list[id] = manager.getClazz());
}
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/reider745/item/CustomItemClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ public CustomItemClass(int id, Integer meta, int count, CustomManager manager) {
super(id, meta, count, manager.get(PropertiesNames.NAME, "InnerCore item"));

parameters = manager;
initItem();
}

public void initItem(){
this.name = parameters.get(PropertiesNames.NAME, "InnerCore item");
this.max_damage = parameters.get(PropertiesNames.MAX_DAMAGE);
this.max_stack = parameters.get(PropertiesNames.MAX_STACK);
this.use_no_target = Callback.count("ItemUseNoTarget") > 0;
this.slot = parameters.get(PropertiesNames.Armors.SLOT, -1);
this.defense = parameters.get(PropertiesNames.Armors.DEFENSE, 0);
this.knockbackResist = parameters.get(PropertiesNames.Armors.KNOCKBACK_RESIST, 0);
this.knockbackResist = parameters.get(PropertiesNames.Armors.KNOCKBACK_RESIST, 0f);
this.ARMOR_DAMAGEABLE = parameters.get(PropertiesNames.ARMOR_DAMAGEABLE, false);

CompoundTag tag = getOrCreateNamedTag();

tag.putInt("Damage", max_damage);

CompoundTag components = tag.getCompound("components");
if(components == null){
components = new CompoundTag();
Expand Down Expand Up @@ -73,6 +74,11 @@ public boolean isHelmet() {
return slot == 0;
}

@Override
public boolean canBePutInHelmetSlot() {
return this.isHelmet();
}

@Override
public boolean isChestplate() {
return slot == 1;
Expand Down Expand Up @@ -130,9 +136,7 @@ public boolean onClickAir(Player player, Vector3 directionVector) {
@Override
public Item clone() {
CustomItemClass item = (CustomItemClass) super.clone();
item.parameters = parameters;
item.name = name;
item.meta = meta;
item.initItem();
return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,6 @@ public int getFromSlot(String name, int id, int count, int data, NativeItemInsta
return 0;
}



public void sendChanges() {
if (isServer) {
if (!dirtySlotSet.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,7 @@ public void dropPoliciesAndClear() {
}

public void send(String name, Object data) {
forEach(client -> {
try{
client.send(name, data);
}catch (Exception e){
final long playerUid = client.getPlayerUid();
ICLog.e("Network", "error send "+playerUid, e);

final Player player = EntityMethod.getPlayerToLong(playerUid);
if(player != null)
player.kick();
else
ICLog.i("Network", "error kick player");
}

});
forEach(client -> client.send(name, data));
}

public<T> void send(String name, T data, Class<T> type) {
Expand Down

0 comments on commit 799df2d

Please sign in to comment.