use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.
the class GraveListGui method updateIcons.
private void updateIcons() {
var config = ConfigManager.getConfig();
for (int x = 0; x < this.size; x++) {
this.clearSlot(x);
}
for (GraveInfo graveInfo : GraveManager.INSTANCE.getByUuid(this.targetUUID)) {
if (this.getFirstEmptySlot() == -1) {
return;
}
Map<String, Text> placeholders = graveInfo.getPlaceholders();
List<Text> parsed = new ArrayList<>();
for (Text text : graveInfo.isProtected() ? ConfigManager.getConfig().guiProtectedText : ConfigManager.getConfig().guiText) {
MutableText out = (MutableText) PlaceholderAPI.parsePredefinedText(text, PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN, placeholders);
if (out.getStyle().getColor() == null) {
out.setStyle(out.getStyle().withColor(Formatting.WHITE));
}
parsed.add(out);
}
var list = graveInfo.isProtected() ? config.guiProtectedItem : config.guiItem;
this.addSlot(GuiElementBuilder.from(list[Math.abs(graveInfo.hashCode() % list.length)]).setName((MutableText) parsed.remove(0)).setLore(parsed).setCallback((index, type, action) -> {
if (Permissions.check(this.player, "universal_graves.teleport", 3)) {
this.close();
ServerWorld world = this.player.getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, graveInfo.getWorld()));
if (world != null) {
var pos = graveInfo.getPosition();
this.player.teleport(world, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, this.player.getYaw(), this.player.getPitch());
}
}
}));
}
}
use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.
the class GraveInfo method getPlaceholders.
public Map<String, Text> getPlaceholders() {
Config config = ConfigManager.getConfig();
long currentTime = System.currentTimeMillis() / 1000;
long protectionTime = config.configData.protectionTime > -1 ? config.configData.protectionTime - currentTime + this.creationTime : Long.MAX_VALUE;
long breakTime = config.configData.breakingTime > -1 ? config.configData.breakingTime - currentTime + this.creationTime : Long.MAX_VALUE;
Map<String, Text> values = new HashMap<>();
values.put("player", new LiteralText(this.gameProfile != null ? this.gameProfile.getName() : "<No player!>"));
values.put("protection_time", new LiteralText("" + (config.configData.protectionTime > -1 ? config.getFormattedTime(protectionTime) : "∞")));
values.put("break_time", new LiteralText("" + (config.configData.breakingTime > -1 ? config.getFormattedTime(breakTime) : "∞")));
values.put("xp", new LiteralText("" + this.xp));
values.put("item_count", new LiteralText("" + this.itemCount));
values.put("position", new LiteralText("" + this.position.toShortString()));
values.put("world", new LiteralText(GraveUtils.toWorldName(this.world)));
values.put("death_cause", this.deathCause);
return values;
}
use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.
the class GraveInfo method shouldBreak.
public boolean shouldBreak() {
Config config = ConfigManager.getConfig();
if (config.configData.breakingTime > -1) {
long currentTime = System.currentTimeMillis() / 1000;
long breakTime = config.configData.breakingTime - currentTime + this.creationTime;
return breakTime <= 0;
} else {
return false;
}
}
use of eu.pb4.armorstandeditor.config.Config in project ArmorStandEditor by Patbox.
the class Events method registerEvents.
public static void registerEvents() {
if (FabricLoader.getInstance().isModLoaded("disguiselib")) {
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (entity instanceof EntityDisguise && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
EntityDisguise disguise = (EntityDisguise) entity;
if (disguise.isDisguised() && disguise.getDisguiseType() == EntityType.ARMOR_STAND && Permissions.check(player, "armorstandeditor.useDisguised", 2)) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) disguise.getDisguiseEntity(), 1, entity);
return ActionResult.SUCCESS;
} else if (entity instanceof ArmorStandEntity) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, 1, null);
return ActionResult.SUCCESS;
}
}
return ActionResult.PASS;
});
UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (entity instanceof EntityDisguise && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
EntityDisguise disguise = (EntityDisguise) entity;
if (disguise.isDisguised() && disguise.getDisguiseType() == EntityType.ARMOR_STAND) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) disguise.getDisguiseEntity(), -1, entity);
return ActionResult.SUCCESS;
} else if (entity instanceof ArmorStandEntity) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, -1, null);
return ActionResult.SUCCESS;
}
}
return ActionResult.PASS;
});
} else {
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (entity instanceof ArmorStandEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, 1, null);
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
});
UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (entity instanceof ArmorStandEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
Events.modifyArmorStand((ServerPlayerEntity) player, (ArmorStandEntity) entity, -1, null);
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
});
}
UseItemCallback.EVENT.register((PlayerEntity player, World world, Hand hand) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (player instanceof ServerPlayerEntity && itemStack.getItem() == config.armorStandTool && Permissions.check(player, "armorstandeditor.use", config.configData.toggleAllPermissionOnByDefault) && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
EditorGuis.openGui((ServerPlayerEntity) player);
return TypedActionResult.success(player.getMainHandStack());
}
return TypedActionResult.pass(player.getMainHandStack());
});
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
Config config = ConfigManager.getConfig();
ItemStack itemStack = player.getMainHandStack();
if (entity instanceof ItemFrameEntity && player instanceof ServerPlayerEntity && Permissions.check(player, "armorstandeditor.useItemFrame", config.configData.toggleAllPermissionOnByDefault) && itemStack.getItem() == config.armorStandTool && (!config.configData.requireIsArmorStandEditorTag || itemStack.getOrCreateTag().getBoolean("isArmorStandEditor"))) {
EditorGuis.openItemFrameEditor((ServerPlayerEntity) player, (ItemFrameEntity) entity);
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
});
}
use of eu.pb4.armorstandeditor.config.Config in project UniversalGraves by Patbox.
the class GraveInfo method isProtected.
public boolean isProtected() {
Config config = ConfigManager.getConfig();
if (config.configData.protectionTime > -1 && config.configData.isProtected) {
long currentTime = System.currentTimeMillis() / 1000;
long protectionTime = config.configData.protectionTime - currentTime + this.creationTime;
return protectionTime > 0;
} else {
return config.configData.isProtected;
}
}
Aggregations