Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.eternalcode.core.feature.freeze;

import com.eternalcode.commons.time.DurationTickUtil;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.util.DurationUtil;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.Duration;

@Command(name = "freeze")
@Permission("eternalcore.freeze")
public class FreezeCommand {

private final NoticeService noticeService;

@Inject
public FreezeCommand(NoticeService noticeService) {
this.noticeService = noticeService;
}
@Execute
public void freezeSelf(@Context Player player, @Arg Duration duration) {
this.freezePlayer(player, duration);
this.noticeService.create()
.notice(translation -> translation.freeze().frozenSelf())
.placeholder("{DURATION}", DurationUtil.format(duration, true))
.player(player.getUniqueId())
.send();
}

@Execute
@Permission("eternalcore.freeze.other")
public void freezeOther(@Context CommandSender sender, @Arg Player target, @Arg Duration duration) {
this.freezePlayer(target, duration);

this.noticeService.create()
.notice(translation -> translation.freeze().frozenOther())
.placeholder("{PLAYER}", target.getName())
.placeholder("{DURATION}", DurationUtil.format(duration, true))
.sender(sender)
.send();

this.noticeService.create()
.notice(translation -> translation.freeze().frozenByOther())
.placeholder("{PLAYER}", sender.getName())
.placeholder("{DURATION}", DurationUtil.format(duration, true))
.player(target.getUniqueId())
.send();
}

private void freezePlayer(Player player, Duration duration) {
int ticks = DurationTickUtil.durationToTicks(duration);
player.setFreezeTicks(ticks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.eternalcode.core.feature.freeze;

import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@Command(name = "unfreeze")
@Permission("eternalcore.unfreeze")
public class UnfreezeCommand {

private final NoticeService noticeService;

@Inject
public UnfreezeCommand(NoticeService noticeService) {
this.noticeService = noticeService;
}

@Execute
public void unfreezeSelf(@Context Player player) {
if (!player.isFrozen()) {
this.noticeService.create()
.notice(translation -> translation.freeze().selfNotFrozen())
.placeholder("{PLAYER}", player.getName())
.player(player.getUniqueId())
.send();
return;
}

player.setFreezeTicks(0);

this.noticeService.create()
.notice(translation -> translation.freeze().unfrozenSelf())
.player(player.getUniqueId())
.send();
}

@Execute
@Permission("eternalcore.unfreeze.other")
public void unfreezeOther(@Context CommandSender sender, @Arg Player target) {
if (!target.isFrozen()) {
this.noticeService.create()
.notice(translation -> translation.freeze().otherNotFrozen())
.placeholder("{PLAYER}", target.getName())
.sender(sender)
.send();
return;
}

target.setFreezeTicks(0);

this.noticeService.create()
.notice(translation -> translation.freeze().unfrozenOther())
.placeholder("{PLAYER}", target.getName())
.sender(sender)
.send();

this.noticeService.create()
.notice(translation -> translation.freeze().unfrozenByOther())
.placeholder("{PLAYER}", sender.getName())
.player(target.getUniqueId())
.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eternalcode.core.feature.freeze.messages;

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
public class ENFreezeMessages extends OkaeriConfig implements FreezeMessages {

public Notice frozenSelf = Notice.chat("<green>► <white>You have frozen yourself for <green>{DURATION}</green>!</white>");

public Notice unfrozenSelf = Notice.chat("<green>► <white>You have unfrozen yourself!</white>");

public Notice frozenOther = Notice.chat("<green>► <white>You have frozen player <green>{PLAYER}</green> for <green>{DURATION}</green>!</white>");

public Notice unfrozenOther = Notice.chat("<green>► <white>You have unfrozen player <green>{PLAYER}</green>!</white>");

public Notice frozenByOther = Notice.chat("<green>► <white>You have been frozen by player <green>{PLAYER}</green> for <green>{DURATION}</green>!</white>");

public Notice unfrozenByOther = Notice.chat("<green>► <white>You have been unfrozen by player <green>{PLAYER}</green>!</white>");

public Notice selfNotFrozen = Notice.chat("<red>► <dark_red>You are not frozen!</dark_red>");

public Notice otherNotFrozen = Notice.chat("<red>► <dark_red>Player <red>{PLAYER}</red> is not frozen!</dark_red>");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.eternalcode.core.feature.freeze.messages;

import com.eternalcode.multification.notice.Notice;

public interface FreezeMessages {

Notice frozenSelf();
Notice unfrozenSelf();
Notice frozenOther();
Notice unfrozenOther();
Notice frozenByOther();
Notice unfrozenByOther();
Notice selfNotFrozen();
Notice otherNotFrozen();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eternalcode.core.feature.freeze.messages;

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
public class PLFreezeMessages extends OkaeriConfig implements FreezeMessages {

public Notice frozenSelf = Notice.chat("<green>► <white>Zamroziłeś się na czas <green>{DURATION}</green>!</white>");

public Notice unfrozenSelf = Notice.chat("<green>► <white>Odmroziłeś się!</white>");

public Notice frozenOther = Notice.chat("<green>► <white>Zamroziłeś gracza <green>{PLAYER}</green> na czas <green>{DURATION}</green>!</white>");

public Notice unfrozenOther = Notice.chat("<green>► <white>Odmroziłeś gracza <green>{PLAYER}</green>!</white>");

public Notice frozenByOther = Notice.chat("<green>► <white>Zostałeś zamrożony przez gracza <green>{PLAYER}</green> na czas <green>{DURATION}</green>!</white>");

public Notice unfrozenByOther = Notice.chat("<green>► <white>Zostałeś odmrożony przez gracza <green>{PLAYER}</green>!</white>");

public Notice selfNotFrozen = Notice.chat("<red>► <dark_red>Nie jesteś zamrożony!</dark_red>");

public Notice otherNotFrozen = Notice.chat("<red>► <dark_red>Gracz <red>{PLAYER}</red> nie jest zamrożony!</dark_red>");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.core.translation;

import com.eternalcode.core.feature.freeze.messages.FreezeMessages;
import com.eternalcode.core.feature.playtime.messages.PlaytimeMessages;
import com.eternalcode.core.feature.clear.messages.ClearMessages;
import com.eternalcode.core.feature.container.messages.ContainerMessages;
Expand Down Expand Up @@ -243,4 +244,6 @@ interface ItemSection {
MotdMessages motd();
// playtime section
PlaytimeMessages playtime();
// freeze section
FreezeMessages freeze();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.core.translation.implementation;

import com.eternalcode.core.feature.freeze.messages.ENFreezeMessages;
import com.eternalcode.core.feature.playtime.messages.ENPlaytimeMessages;
import com.eternalcode.core.feature.clear.messages.ENClearMessages;
import com.eternalcode.core.feature.container.messages.ENContainerMessages;
Expand Down Expand Up @@ -550,4 +551,7 @@ public static class ENItemSection extends OkaeriConfig implements ItemSection {

@Comment({" ", "# This section is responsible for information about players' game time."})
public ENPlaytimeMessages playtime = new ENPlaytimeMessages();

@Comment({" ", "# This section is responsible for the messages of the freeze feature."})
public ENFreezeMessages freeze = new ENFreezeMessages();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.core.translation.implementation;

import com.eternalcode.core.feature.freeze.messages.PLFreezeMessages;
import com.eternalcode.core.feature.near.messages.PLNearMessages;
import com.eternalcode.core.feature.playtime.messages.PLPlaytimeMessages;
import com.eternalcode.core.feature.clear.messages.PLClearMessages;
Expand Down Expand Up @@ -577,4 +578,7 @@ public static class PLItemSection extends OkaeriConfig implements ItemSection {

@Comment({" ", "# Ta sekcja odpowiada za wiadomości o czasie gry graczy."})
public PLPlaytimeMessages playtime = new PLPlaytimeMessages();

@Comment({" ", "# Ta sekcja odpowiada za wiadomości dotyczące zamrażania graczy"})
public PLFreezeMessages freeze = new PLFreezeMessages();
}