Skip to content
Draft
1 change: 1 addition & 0 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class OMCPlugin extends JavaPlugin {
MailboxManager::new,
DiscordLinkManager::new,
ProfileManager::new,
() -> new fr.openmc.core.features.events.contents.halloween.halloween.HalloweenManager(),
() -> new ElevatorManager(),
() -> new CorpseManager(),
QuestsManager::new,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/openmc/core/OMCRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fr.openmc.core.registry.loottable.CustomLootTableRegistry;
import fr.openmc.core.registry.mobs.CustomMobRegistry;
import fr.openmc.core.registry.regions.CustomRegionRegistry;
import fr.openmc.core.registry.structures.CustomStructureRegistry;
import fr.openmc.core.registry.worldtemplates.WorldTemplateRegistry;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;

Expand All @@ -31,6 +32,7 @@ public final class OMCRegistry {
public static CustomLootTableRegistry CUSTOM_LOOT_TABLES;
public static CustomAmbientRegistry CUSTOM_AMBIENTS;
public static CustomLootboxRegistry CUSTOM_LOOTBOXES;
public static CustomStructureRegistry CUSTOM_STRUCTURES;
public static CustomRegionRegistry CUSTOM_REGIONS;
public static WorldTemplateRegistry WORLD_TEMPLATES;

Expand Down Expand Up @@ -58,6 +60,8 @@ public final class OMCRegistry {
RegistryLoadingType.AFTER_IA),
new RegistryContext(() -> CUSTOM_MOBS = new CustomMobRegistry(),
RegistryLoadingType.AFTER_IA),
new RegistryContext(() -> CUSTOM_STRUCTURES = new CustomStructureRegistry(),
RegistryLoadingType.RUNTIME),
new RegistryContext(() -> WORLD_TEMPLATES = new WorldTemplateRegistry(),
RegistryLoadingType.BOOTSTRAP, RegistryLoadingType.RUNTIME),
new RegistryContext(() -> WEEKLY_EVENTS = new WeeklyEventsRegistry(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.openmc.core.features.events.contents.halloween.commands;

import fr.openmc.core.features.events.contents.halloween.halloween.shop.menu.WitchShopMainMenu;
import fr.openmc.core.features.events.contents.halloween.managers.HalloweenManager;
import org.bukkit.entity.Player;
import revxrsal.commands.annotation.Command;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.bukkit.annotation.CommandPermission;
Expand All @@ -12,4 +14,9 @@ public class HalloweenCommands {
public void endHalloweenCommand() {
HalloweenManager.endEvent();
}

@Subcommand("test")
public void tst(Player player) {
new WitchShopMainMenu(player).open();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.openmc.core.features.events.contents.halloween.halloween;

import fr.openmc.core.registry.items.CustomItem;
import fr.openmc.core.registry.items.CustomItemMeta;
import fr.openmc.core.utils.text.messages.TranslationManager;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jspecify.annotations.NonNull;

import java.util.HashMap;
import java.util.Map;

public class CandyItem extends CustomItem {

@Getter
public int diabetesIndex;
public Material baseItem;

public static final Map<String, CandyItem> candies = new HashMap<>();

public CandyItem(String candyID , int diabetesIndex, Material baseItem) {
super(new CustomItemMeta(candyID));
this.diabetesIndex = diabetesIndex;
this.baseItem = baseItem;
candies.put(candyID, this);
}

@Override
public @NonNull ItemStack getVanilla() {
ItemStack item = new ItemStack(baseItem);
item.editMeta(meta -> meta.itemName(
TranslationManager.translation("feature." + super.getId().replace(":", ".") + ".name")
));
return item;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package fr.openmc.core.features.events.contents.halloween.halloween;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import fr.openmc.core.bootstrap.features.Feature;
import fr.openmc.core.bootstrap.features.types.HasCommands;
import fr.openmc.core.bootstrap.features.types.HasDatabase;
import fr.openmc.core.bootstrap.features.types.HasListeners;
import fr.openmc.core.bootstrap.features.types.LoadAfterItemsAdder;
import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.bootstrap.listeners.ListenerFactory;
import fr.openmc.core.features.events.contents.halloween.halloween.dimension.advancement.Advancements;
import fr.openmc.core.features.events.contents.halloween.halloween.model.HalloweenDB;
import fr.openmc.core.features.events.contents.halloween.halloween.shop.WitchShopManager;
import lombok.Getter;

import java.sql.SQLException;
import java.util.*;

public class HalloweenManager extends Feature implements LoadAfterItemsAdder, HasDatabase, HasListeners, HasCommands {

@Getter
private static HalloweenDB halloweenDB;

private static Dao<HalloweenDB, String> halloweenDao;

public static List<String> unlockedRooms;

@Override
public void init() {
halloweenDB = loadEvent();
unlockedRooms = halloweenDB.getUnlockedRooms();
WitchShopManager.init();
}

@Override
public void initDB(ConnectionSource connectionSource) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, HalloweenDB.class);
halloweenDao = DaoManager.createDao(connectionSource, HalloweenDB.class);
}

@Override
protected void save() {
saveEvent();
}

public static HalloweenDB loadEvent() {
try {
HalloweenDB halloweenDB = halloweenDao.queryForFirst();
if (halloweenDB == null)
halloweenDB = new HalloweenDB(0, List.of(Advancements.ROOM_1.name()), false);
return halloweenDB;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

private static void saveEvent() {
try {
halloweenDao.createOrUpdate(halloweenDB);
} catch (Exception e) {
OMCLogger.error("Impossible de sauvegarder les corpses pendant l'arret.", e);
}
}

public static boolean hasUnlock(Advancements advancements) {
return unlockedRooms.contains(advancements.name());
}

public static boolean unlockNewRoom(Advancements advancements) {
return unlockedRooms.add(advancements.name());
}

@Override
public Set<ListenerFactory> getListeners() {
return Set.of();
}

@Override
public Set<Object> getCommands() {
return Set.of(

);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package fr.openmc.core.features.events.contents.halloween.halloween.dimension;

import fr.openmc.core.bootstrap.integration.OMCLogger;
import org.bukkit.Bukkit;
import org.bukkit.GameRules;
import org.bukkit.World;
import org.bukkit.entity.SpawnCategory;

public class DimensionManager {

public static final String DIMENSION_NAME = "world_omc_halloween_witch_house";
public static World HALLOWEEN_WORLD;

public static void init() {
HALLOWEEN_WORLD = Bukkit.getWorld(DIMENSION_NAME);

setupDimension();
// loadRegions();
}

//TODO setup la dimension :

Check warning on line 21 in src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/dimension/DimensionManager.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/dimension/DimensionManager.java#L21

Resolve unexpected comment. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
// - monde vide + ajout de la structure de Mcross

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu veux que je te mette le systeme et que tu puisses bénéficier du VoidDimensionInjector que je t'avais donné?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai juste eu a mettre le json dans datapack et le monde vide s'est créé

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui mais je te donnerais un truc plus propre

// - ambiant custom

private static void setupDimension() {
if (!HALLOWEEN_WORLD.getName().equals(DIMENSION_NAME)) return;

// ** SPAWNING RULES **
HALLOWEEN_WORLD.setSpawnLimit(SpawnCategory.MONSTER, 10);
HALLOWEEN_WORLD.setSpawnLimit(SpawnCategory.AMBIENT, 10);
HALLOWEEN_WORLD.setSpawnLimit(SpawnCategory.ANIMAL, 6);

HALLOWEEN_WORLD.setTicksPerSpawns(SpawnCategory.MONSTER, 30);
HALLOWEEN_WORLD.setTicksPerSpawns(SpawnCategory.AMBIENT, 15);
HALLOWEEN_WORLD.setTicksPerSpawns(SpawnCategory.ANIMAL, 30);

// ** SET GAMERULE FOR THE WORLD **
HALLOWEEN_WORLD.setGameRule(GameRules.ADVANCE_TIME, false);
HALLOWEEN_WORLD.setGameRule(GameRules.SHOW_ADVANCEMENT_MESSAGES, false);
HALLOWEEN_WORLD.setGameRule(GameRules.ADVANCE_WEATHER, false);
HALLOWEEN_WORLD.setGameRule(GameRules.RAIDS, true);
HALLOWEEN_WORLD.setGameRule(GameRules.SPAWN_PATROLS, false);
HALLOWEEN_WORLD.setGameRule(GameRules.SPAWN_WANDERING_TRADERS, false);
HALLOWEEN_WORLD.setGameRule(GameRules.NATURAL_HEALTH_REGENERATION, false);
HALLOWEEN_WORLD.setGameRule(GameRules.LOCATOR_BAR, false);
HALLOWEEN_WORLD.setGameRule(GameRules.ALLOW_ENTERING_NETHER_USING_PORTALS, false);

// ** SET WORLD BORDER AND TIME **
HALLOWEEN_WORLD.getWorldBorder().setSize(500);
HALLOWEEN_WORLD.setTime(14000);

OMCLogger.infoFormatted("Dimension de la Maison de la Sorcière setup (gamerules, worldborder, time)");
}

//TODO modifier avec les region de bibi

Check warning on line 55 in src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/dimension/DimensionManager.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/dimension/DimensionManager.java#L55

Resolve unexpected comment. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
// private static void loadRegions() {
// MultiRegion multiRegion = new MultiRegion(
// HALLOWEEN_WORLD,
// new SquareRegion(0.0, 60.0, 0.0, 6.0, 70.0, 3.0, HALLOWEEN_WORLD),
// new SquareRegion(0.0, 60.0, 6.0, 3.0, 70.0, 3.0, HALLOWEEN_WORLD)
// );
//
// multiRegion.addDetection();
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.openmc.core.features.events.contents.halloween.halloween.dimension;

public class WitchHouseManager {



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.openmc.core.features.events.contents.halloween.halloween.dimension.advancement;

import lombok.Getter;

@Getter
public enum Advancements {
ROOM_1(0),
ROOM_2(1000)
;

private final int require;
Comment thread
iambibi marked this conversation as resolved.

Advancements(int require) {
this.require = require;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.openmc.core.features.events.contents.halloween.halloween.dimension.advancement;

import fr.openmc.core.registry.regions.types.Region;

public class HouseRoom {

public Region region;



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fr.openmc.core.features.events.contents.halloween.halloween.listeners;

import dev.lone.itemsadder.api.CustomStack;
import fr.openmc.core.OMCRegistry;
import fr.openmc.core.features.events.contents.halloween.halloween.CandyItem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class CandyListener implements Listener {

private final Map<UUID, Integer> diabetes = new HashMap<>();

@EventHandler
public void onCandyEat(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItem();

CustomStack stack = CustomStack.byItemStack(item);

if (stack == null) return;

if (!CandyItem.candies.containsKey(stack.getId())) return;

CandyItem candy = CandyItem.candies.get(stack.getId());

UUID uuid = player.getUniqueId();

int diabete = diabetes.computeIfAbsent(uuid, key -> 0);

diabete += candy.getDiabetesIndex();

if (diabete >= 20) {
//TODO faire un truc

Check warning on line 40 in src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/listeners/CandyListener.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/fr/openmc/core/features/events/contents/halloween/halloween/listeners/CandyListener.java#L40

Resolve unexpected comment. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
diabetes.put(uuid, 0);
} else
diabetes.put(uuid, diabete);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fr.openmc.core.features.events.contents.halloween.halloween.model;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@DatabaseTable(tableName = "halloween_season_event_data")
public class HalloweenDB {

@DatabaseField(columnName = "advancement")
private int currentAdvancement;

@DatabaseField(columnName = "unlocked_room")
private String unlockedRooms;

@DatabaseField(columnName = "is_active")
private boolean active;

private static final Gson GSON = new Gson();

public HalloweenDB() {
}

public HalloweenDB(int currentAdvancement, List<String> unlockedRooms, boolean active) {
this.currentAdvancement = currentAdvancement;
this.unlockedRooms = GSON.toJson(unlockedRooms);
this.active = active;
}

public void setUnlockedRooms(List<String> unlockedRooms) {
this.unlockedRooms = GSON.toJson(unlockedRooms);
}

public List<String> getUnlockedRooms() {
if (unlockedRooms == null || unlockedRooms.isBlank()) {
return new ArrayList<>();
}

return GSON.fromJson(
unlockedRooms,
new TypeToken<List<String>>() {}.getType()
);
}
}
Loading
Loading