Skip to content

Commit

Permalink
feat: Implement tick freezer
Browse files Browse the repository at this point in the history
chore: Update api-version to 1.21.3
  • Loading branch information
H2Owater425 committed Dec 30, 2024
1 parent 000b5ce commit 5cfdad7
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 54 deletions.
8 changes: 8 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions .idea/modules/Normalcore.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions .idea/modules/kr.dhmo.Normalcore.main.iml

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ repositories {
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
}

def targetJavaVersion = 17
def targetJavaVersion = 21
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/kr/dhmo/normalcore/Normalcore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import kr.dhmo.normalcore.listeners.PlayerDeathListener;
import kr.dhmo.normalcore.listeners.PlayerGamemodeChangeListener;
import kr.dhmo.normalcore.listeners.PlayerJoinListener;
import kr.dhmo.normalcore.listeners.PlayerQuitListener;
import kr.dhmo.normalcore.managers.ConfigurationManager;
import kr.dhmo.normalcore.managers.PlayersManager;
import kr.dhmo.normalcore.utilities.FormatUtility;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.ServerTickManager;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
Expand All @@ -27,28 +29,35 @@
import java.util.logging.Logger;

public final class Normalcore extends JavaPlugin {
final public static String ERROR_COLOR = "§c";
final public static String errorColor = "§c";
final private static ServerTickManager serverTickManager = Bukkit.getServerTickManager();
private static Normalcore instance;

public static void setServerTickFrozen(boolean isFreeze) {
Normalcore.serverTickManager.setFrozen(isFreeze);
}

public static void respawn(@NotNull Player player) {
new BukkitRunnable() {
public void run() {
final UUID playerUniqueId = player.getUniqueId();
final int respawnPenaltyTime = ConfigurationManager.getRespawnPenaltyTime() * 20;
Location location = player.getBedSpawnLocation();
Location location = player.getRespawnLocation();

if(location == null) {
location = Bukkit.getWorlds().get(0).getSpawnLocation();
location = Bukkit.getWorlds().getFirst().getSpawnLocation();
}

PlayersManager.setLastDeathAt(playerUniqueId, 0);

player.spigot().respawn();
player.setGameMode(GameMode.SURVIVAL);
player.teleport(location);


player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1200, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, respawnPenaltyTime, 0, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, respawnPenaltyTime, 2, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.MINING_FATIGUE, respawnPenaltyTime, 0, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, respawnPenaltyTime, 2, false, false));
player.sendMessage("You have " + FormatUtility.pluralize(PlayersManager.getLife(playerUniqueId), "life") + " left");
}
}.runTask(Normalcore.instance);
Expand Down Expand Up @@ -101,6 +110,7 @@ public void onEnable() {
Normalcore.pluginManager.registerEvents(new PlayerDeathListener(), this);
Normalcore.pluginManager.registerEvents(new PlayerGamemodeChangeListener(), this);
Normalcore.pluginManager.registerEvents(new PlayerJoinListener(), this);
Normalcore.pluginManager.registerEvents(new PlayerQuitListener(), this);

new BukkitRunnable() {
@Override
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/kr/dhmo/normalcore/commands/ConfigurationCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[0] must be save or reload");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[0] must be save or reload");

return false;
}
Expand All @@ -70,13 +70,13 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
yield true;
}
default -> {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[1] must be one of respawnWaitingTime, respawnPenaltyTime, lifePrice");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[1] must be one of respawnWaitingTime, respawnPenaltyTime, lifePrice");

yield false;
}
};
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[0] must be get");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[0] must be get");

return false;
}
Expand All @@ -99,7 +99,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
throw new NumberFormatException();
}
} catch(Exception exception) {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[2] must be positive long or zero");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[2] must be positive long or zero");

return false;
}
Expand All @@ -118,7 +118,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
throw new NumberFormatException();
}
} catch(Exception exception) {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[2] must be positive integer or zero");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[2] must be positive integer or zero");

return false;
}
Expand All @@ -137,33 +137,33 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
throw new NumberFormatException();
}
} catch(Exception exception) {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[2] must be positive integer or zero");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[2] must be positive integer or zero");

return false;
}
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[1] must be one of respawnWaitingTime, respawnPenaltyTime, lifePrice");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[1] must be one of respawnWaitingTime, respawnPenaltyTime, lifePrice");

return false;
}
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[1] must be set");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[1] must be set");

return false;
}
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments.length must between 0 and 3");
commandSender.sendMessage(Normalcore.errorColor + "Arguments.length must between 0 and 3");

return false;
}
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "CommandSender must be op");
commandSender.sendMessage(Normalcore.errorColor + "CommandSender must be op");

return false;
}
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/kr/dhmo/normalcore/commands/LifeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

return true;
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "CommandSender must be player");
commandSender.sendMessage(Normalcore.errorColor + "CommandSender must be player");

return false;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

return true;
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "You must have " + FormatUtility.pluralize(remainingLifePrice, "more enchanted golden apple"));
commandSender.sendMessage(Normalcore.errorColor + "You must have " + FormatUtility.pluralize(remainingLifePrice, "more enchanted golden apple"));

return false;
}
Expand All @@ -98,20 +98,20 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

return true;
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "You must have at least 1 life");
commandSender.sendMessage(Normalcore.errorColor + "You must have at least 1 life");

return false;
}
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[0] must be deposit or withdraw");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[0] must be deposit or withdraw");

return false;
}
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "CommandSender must be player");
commandSender.sendMessage(Normalcore.errorColor + "CommandSender must be player");

return false;
}
Expand All @@ -132,12 +132,12 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

return true;
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Argument[1] must be valid player");
commandSender.sendMessage(Normalcore.errorColor + "Argument[1] must be valid player");

return false;
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Argument[1] must be self");
commandSender.sendMessage(Normalcore.errorColor + "Argument[1] must be self");

return false;
}
Expand Down Expand Up @@ -178,29 +178,29 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

return true;
} else {
player.sendMessage(Normalcore.ERROR_COLOR + "Argument[1] must be valid player");
player.sendMessage(Normalcore.errorColor + "Argument[1] must be valid player");

return false;
}
} else {
player.sendMessage(Normalcore.ERROR_COLOR + "Argument[1] must not be yourself");
player.sendMessage(Normalcore.errorColor + "Argument[1] must not be yourself");

return false;
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "You must have at least 1 life");
commandSender.sendMessage(Normalcore.errorColor + "You must have at least 1 life");

return false;
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "CommandSender must be player");
commandSender.sendMessage(Normalcore.errorColor + "CommandSender must be player");

return false;
}
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[0] must be get or remit");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[0] must be get or remit");

return false;
}
Expand All @@ -227,24 +227,24 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
throw new NumberFormatException();
}
} catch(Exception exception) {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments[2] must be positive integer or zero");
commandSender.sendMessage(Normalcore.errorColor + "Arguments[2] must be positive integer or zero");

return false;
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Argument[1] must be valid player");
commandSender.sendMessage(Normalcore.errorColor + "Argument[1] must be valid player");

return false;
}
} else {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "CommandSender must be op");
commandSender.sendMessage(Normalcore.errorColor + "CommandSender must be op");

return false;
}
}

default: {
commandSender.sendMessage(Normalcore.ERROR_COLOR + "Arguments.length must between 0 and 3");
commandSender.sendMessage(Normalcore.errorColor + "Arguments.length must between 0 and 3");

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import kr.dhmo.normalcore.Normalcore;
import kr.dhmo.normalcore.managers.PlayersManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -10,9 +11,11 @@

import java.util.UUID;

public class PlayerJoinListener implements Listener {
final public class PlayerJoinListener implements Listener {
@EventHandler
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
Normalcore.setServerTickFrozen(false);

final Player player = event.getPlayer();
final UUID playerUniqueId = player.getUniqueId();

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/kr/dhmo/normalcore/listeners/PlayerQuitListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.dhmo.normalcore.listeners;

import kr.dhmo.normalcore.Normalcore;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

final public class PlayerQuitListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if(Bukkit.getOnlinePlayers().isEmpty()) {
Normalcore.setServerTickFrozen(true);
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Normalcore
version: '0.0.1-SNAPSHOT'
main: kr.dhmo.normalcore.Normalcore
api-version: '1.20'
api-version: '1.21'
author: H2Owater425
description: Normalcore
load: STARTUP
Expand Down

0 comments on commit 5cfdad7

Please sign in to comment.