DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
DreamWorld.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamWorld;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import lombok.Getter;
28import lombok.Setter;
29import org.bukkit.Bukkit;
30import org.bukkit.Difficulty;
31import org.bukkit.GameMode;
32import org.bukkit.World;
33import org.bukkit.entity.Player;
34
35import java.util.UUID;
36
54public class DreamWorld {
55
59 @Getter private UUID worldUUID;
60
64 @Setter private TimeLock timeLock;
65
69 @Setter private Difficulty difficultyLock;
70
74 @Setter private GameMode gameModeLock;
75
79 @Setter private Integer heartLock;
80
84 @Setter private Integer hungerLock;
85
89 @Setter private Integer saturationLock;
90
95 public DreamWorld(UUID worldUUID){
96 this.worldUUID = worldUUID;
97 }
98
107 public World GetWorld(){
108 var world = Bukkit.getWorld(worldUUID);
109 if (world == null) DreamCore.DreamWorlds.remove(worldUUID);
110 return world;
111 }
112
120 public void TickWorld(){
121 var world = GetWorld();
122 if (world == null) return;
123 TickTimeLock(world);
124 TickDifficultyLock(world);
125 for (var player : Bukkit.getOnlinePlayers()){
126 if (!player.getWorld().getUID().equals(worldUUID)) continue;
127 TickGameModeLock(player);
128 TickHeartLock(player);
129 TickHungerLock(player);
130 TickSaturationLock(player);
131 }
132 }
133
138 private void TickTimeLock(World world){
139 if (timeLock == null) return;
140 world.setTime(timeLock.time);
141 }
142
147 private void TickDifficultyLock(World world){
148 if (difficultyLock == null) return;
149 world.setDifficulty(difficultyLock);
150 }
151
156 private void TickGameModeLock(Player player){
157 if (gameModeLock == null) return;
158 player.setGameMode(gameModeLock);
159 }
160
165 private void TickHeartLock(Player player){
166 if (heartLock == null) return;
167 player.setHealth(heartLock);
168 }
169
174 private void TickHungerLock(Player player){
175 if (hungerLock == null) return;
176 player.setFoodLevel(hungerLock);
177 }
178
183 private void TickSaturationLock(Player player){
184 if (saturationLock == null) return;
185 player.setSaturation(saturationLock);
186 }
187}
static final LinkedHashMap< UUID, DreamWorld > DreamWorlds
Per-world locks for time, difficulty, and player attributes such as gamemode, health,...
void TickWorld()
Enforces all configured locks on the world and its players.
World GetWorld()
Resolves the Bukkit World for this UUID.
DreamWorld(UUID worldUUID)
Constructs a DreamWorld wrapper for the given world UUID.
Common time-lock presets for setting world time.
Definition TimeLock.java:32