-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from mrgeneralq/kick-from-bed
Insomnia update
- Loading branch information
Showing
23 changed files
with
563 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/me/mrgeneralq/sleepmost/commands/subcommands/InsomniaSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package me.mrgeneralq.sleepmost.commands.subcommands; | ||
|
||
import me.mrgeneralq.sleepmost.enums.ConfigMessage; | ||
import me.mrgeneralq.sleepmost.interfaces.*; | ||
import me.mrgeneralq.sleepmost.messages.MessageTemplate; | ||
import me.mrgeneralq.sleepmost.models.WorldProperty; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.World; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
import java.util.List; | ||
|
||
public class InsomniaSubCommand implements ISubCommand { | ||
|
||
private final ISleepService sleepService; | ||
private final IFlagsRepository flagsRepository; | ||
private final IMessageService messageService; | ||
private final IWorldPropertyService worldPropertyService; | ||
|
||
public InsomniaSubCommand(ISleepService sleepService, IFlagsRepository flagsRepository, IMessageService messageService, IWorldPropertyService worldPropertyService) { | ||
this.sleepService = sleepService; | ||
this.flagsRepository = flagsRepository; | ||
this.messageService = messageService; | ||
this.worldPropertyService = worldPropertyService; | ||
} | ||
|
||
|
||
@Override | ||
public boolean executeCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
|
||
Player player = (Player) sender; | ||
World world = player.getWorld(); | ||
|
||
if(!sleepService.isEnabledAt(world)){ | ||
this.messageService.sendMessage(player, messageService.fromTemplate(MessageTemplate.NOT_ENABLED_FOR_WORLD)); | ||
return true; | ||
} | ||
|
||
if (!sleepService.isNight(world)) { | ||
String notNightMessage = this.messageService.fromTemplate(MessageTemplate.CMD_ONLY_DURING_NIGHT); | ||
player.sendMessage(notNightMessage); | ||
return true; | ||
} | ||
|
||
if (this.worldPropertyService.getWorldProperties(world).isInsomniaEnabled()) { | ||
String insomniaMessage = this.messageService.fromTemplate(MessageTemplate.INSOMNIA_ALREADY_ENABLED); | ||
player.sendMessage(insomniaMessage); | ||
return true; | ||
} | ||
|
||
WorldProperty property = this.worldPropertyService.getWorldProperties(world); | ||
property.setInsomniaEnabled(true); | ||
|
||
this.worldPropertyService.setWorldProperty(world, property); | ||
|
||
String insomniaMessage = this.messageService.fromTemplate(MessageTemplate.INSOMNIA_ENABLED); | ||
List<Player> sleepingPlayers = this.sleepService.getSleepers(world); | ||
|
||
for(Player p: sleepingPlayers){ | ||
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60,1)); | ||
p.teleport(p.getLocation()); | ||
String targetInsomniaMessage = this.messageService.fromTemplate(MessageTemplate.INSOMNIA_NOT_SLEEPY); | ||
p.sendMessage(targetInsomniaMessage); | ||
} | ||
|
||
player.sendMessage(insomniaMessage); | ||
return true; | ||
|
||
} | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
src/main/java/me/mrgeneralq/sleepmost/commands/subcommands/KickSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package me.mrgeneralq.sleepmost.commands.subcommands; | ||
|
||
import me.mrgeneralq.sleepmost.interfaces.IMessageService; | ||
import me.mrgeneralq.sleepmost.interfaces.ISleepService; | ||
import me.mrgeneralq.sleepmost.interfaces.ISubCommand; | ||
import me.mrgeneralq.sleepmost.messages.MessageTemplate; | ||
import me.mrgeneralq.sleepmost.statics.CommandSenderUtils; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.World; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class KickSubCommand implements ISubCommand { | ||
|
||
private final ISleepService sleepService; | ||
private final IMessageService messageService; | ||
|
||
public KickSubCommand(ISleepService sleepService, IMessageService messageService) { | ||
this.sleepService = sleepService; | ||
this.messageService = messageService; | ||
} | ||
|
||
@Override | ||
public boolean executeCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
|
||
if(!CommandSenderUtils.hasWorld(sender)){ | ||
this.messageService.sendMessage(sender, messageService.fromTemplate(MessageTemplate.NO_CONSOLE_COMMAND)); | ||
return true; | ||
} | ||
|
||
Player player = (Player) sender; | ||
|
||
World world = CommandSenderUtils.getWorldOf(sender); | ||
|
||
if(args.length < 2){ | ||
this.messageService.sendMessage(sender, messageService.fromTemplate(MessageTemplate.SPECIFY_PLAYER)); | ||
return true; | ||
} | ||
|
||
String targetPlayerName = args[1]; | ||
|
||
if(Bukkit.getPlayer(targetPlayerName) == null){ | ||
this.messageService.sendMessage(sender, messageService.fromTemplate(MessageTemplate.TARGET_NOT_ONLINE)); | ||
return true; | ||
} | ||
|
||
Player targetPlayer = Bukkit.getPlayer(targetPlayerName); | ||
|
||
if(!this.sleepService.isPlayerAsleep(targetPlayer)){ | ||
this.messageService.sendMessage(sender, messageService.fromTemplate(MessageTemplate.TARGET_NOT_SLEEPING)); | ||
return true; | ||
} | ||
|
||
targetPlayer.teleport(targetPlayer.getLocation()); | ||
this.messageService.sendMessage(sender,"Player has been kicked from the bed"); | ||
this.sleepService.setSleeping(targetPlayer, false); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.mrgeneralq.sleepmost.enums; | ||
|
||
public enum TimeCycle { | ||
DAY, | ||
NIGHT, | ||
UNKNOWN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.