-
Notifications
You must be signed in to change notification settings - Fork 35
Evènement d'Halloween #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Evènement d'Halloween #1489
Changes from all commits
830b400
0deb10d
d101e83
caef5ab
3d5f3ce
0c363e3
635ca6d
06f3e1c
38bf0e4
c019585
c855ad9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
|
||
| // - monde vide + ajout de la structure de Mcross | ||
| // - 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
|
||
| // 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; | ||
|
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
|
||
| 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() | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
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é?
There was a problem hiding this comment.
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éé
There was a problem hiding this comment.
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