Skip to content

Commit

Permalink
v0.0.8 - Option for sound on UHC day toggles, and more customization …
Browse files Browse the repository at this point in the history
…in the config for messages!
  • Loading branch information
Fido2603 committed Jun 3, 2019
1 parent 56352db commit 6b08553
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dk.fido2603</groupId>
<artifactId>semihardcore</artifactId>
<version>0.0.7</version>
<version>0.0.8</version>
<name>Semi-Hardcore</name>
<repositories>
<!-- Spigot Repo for Spigot and Bukkit -->
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/dk/fido2603/semihardcore/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public void newPlayerCheck(PlayerJoinEvent event)
// Delay the kick, to make sure the player is gone...
SemiHardcore.server.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
player.kickPlayer("You still have time left on your death cooldown: " + TimeConverter.parseMillisToUFString(plugin.timeToBan-timeDiff(playerId)) + "!");
String kickMessage = plugin.messageKickPlayerTimeLeft.replace("{timeLeft}", TimeConverter.parseMillisToUFString(plugin.timeToBan-timeDiff(playerId)));
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', kickMessage));
}
}, 20L);
plugin.logDebug("Tried to keep player, " + player.getName() +", away from joining, as they are banned!");
Expand Down Expand Up @@ -200,13 +201,15 @@ public boolean banPlayer(Player player, UUID playerId)
// Delay the kick, to not have the console make a "Removing entity while ticking!" Exception
SemiHardcore.server.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
player.kickPlayer("You have been set on a cooldown for: " + plugin.timeToBanStringUF + "!");
String kickMessage = plugin.messageKickPlayerOnBan.replace("{banTime}",plugin.timeToBanStringUF);
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', kickMessage));
}
}, 1L);

this.semihardcoreConfig.set(playerId.toString() + ".Name", player.getName());

plugin.sendInfoAll("&c" + player.getName() + " has been banned for &4" + plugin.timeToBanStringUF + "&c!");
String banMessage = plugin.messageBanPlayer.replace("{playerName}", player.getName()).replace("{timeBanned}", plugin.timeToBanStringUF);
plugin.sendInfoAll(banMessage);

saveTimed();

Expand Down
67 changes: 58 additions & 9 deletions src/main/java/dk/fido2603/semihardcore/SemiHardcore.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ public class SemiHardcore extends JavaPlugin
{
public static boolean pluginEnabled = false;
public boolean vaultEnabled = false;
public boolean uhcDayEnabled = true;

public boolean uhcDayEnabled = false;
public Integer uhcDay = 2;
public boolean isUHCDay = false;

public boolean playSoundEnabled = true;
private String uhcStartSound = "entity.wither.spawn";
private String uhcEndSound = "entity.ender_dragon.growl";

public String messageLoginUHCDay = "&4-> &6It is currently UHC day! Take care, there is no natural regen!&4 <-";
public String messageBanPlayer = "&c{playerName} has been banned for &4{timeBanned}&c!";
public String messageKickPlayerOnBan = "&4You have been set on a cooldown for: &c{banTime}&4!";
public String messageKickPlayerTimeLeft = "&cYou still have time left on your death cooldown: &4{timeLeft}&c!";
private String messageStartUHCDay = "&4-> &6It is now UHC day! Take care, no more natural regen! &4<-";
private String messageEndUHCDay = "&4-> &6It is no longer UHC day! &4<-";

public static Server server = null;
public boolean debug = false;
private String timeToBanString = "24h";
Expand Down Expand Up @@ -61,13 +74,21 @@ public void sendInfoAll(String message) {

public void sendInfo(Player player, String message)
{
String translatedMessage = ChatColor.translateAlternateColorCodes('&', message);
if (player == null)
{
log(message);
log(translatedMessage);
}
else
{
player.sendMessage(message);
player.sendMessage(translatedMessage);
}
}

public void playSoundAll(String sound) {
for (Player player : plugin.getServer().getOnlinePlayers())
{
player.playSound(player.getLocation(), sound, 1.0F, 1.0F);
}
}

Expand Down Expand Up @@ -150,14 +171,20 @@ public void run()
logDebug("Day: " + TimeConverter.getDayOfWeek() + " - UHCDay: " + plugin.uhcDay.toString());
getServer().dispatchCommand(console, "gamerule naturalRegeneration false");
isUHCDay = true;
sendInfoAll("&6It is now UHC day! Take care, no more natural regen!");
sendInfoAll(plugin.messageStartUHCDay);
if (plugin.playSoundEnabled) {
plugin.playSoundAll(plugin.uhcStartSound);
}
}
else if (!(TimeConverter.getDayOfWeek() == uhcDay) && isUHCDay) {
log("It's not UHC day anymore, switching the gamerule...");
logDebug("Day: " + TimeConverter.getDayOfWeek() + " - UHCDay: " + plugin.uhcDay.toString());
getServer().dispatchCommand(console, "gamerule naturalRegeneration true");
isUHCDay = false;
sendInfoAll("&6It is no longer UHC day!");
sendInfoAll(plugin.messageEndUHCDay);
if (plugin.playSoundEnabled) {
plugin.playSoundAll(plugin.uhcEndSound);
}
}
}
}, 20L, 600L); // 1200 is the ideal number of ticks for a minute, so we'll check each half minute - waiting about a second for the first check though, to get the things started
Expand Down Expand Up @@ -194,8 +221,19 @@ public void loadSettings()

this.debug = config.getBoolean("Settings.Debug", false);
this.timeToBanString = config.getString("Settings.TimeToBan", "24h");
this.uhcDayEnabled = config.getBoolean("Settings.UHCDayEnabled", true);
this.uhcDay = config.getInt("Settings.UHCDay", 2);

this.uhcDayEnabled = config.getBoolean("Misc.UHCDayEnabled", false);
this.uhcDay = config.getInt("Misc.UHCDay", 2);
this.uhcDayEnabled = config.getBoolean("Misc.PlaySounds", true);
this.uhcStartSound = config.getString("Misc.Sound_UHCStart", "entity.ender_dragon.growl");
this.uhcEndSound = config.getString("Misc.Sound_UHCEnd", "entity.wither.spawn");

this.messageLoginUHCDay = config.getString("Messages.LoginUHCDay", "&4-> &6It is currently UHC day! Take care, there is no natural regen!&4 <-");
this.messageBanPlayer = config.getString("Messages.BanPlayer", "&c{playerName} has been banned for &4{timeBanned}&c!");
this.messageKickPlayerOnBan = config.getString("Messages.KickPlayerOnBan", "&4You have been set on a cooldown for: &c{banTime}&4!");
this.messageKickPlayerTimeLeft = config.getString("Messages.PlayerTimeLeft", "&cYou still have time left on your death cooldown: &4{timeLeft}&c!");
this.messageStartUHCDay = config.getString("Messages.StartUHCDay", "&4-> &6It is now UHC day! Take care, no more natural regen! &4<-");
this.messageEndUHCDay = config.getString("Messages.EndUHCDay", "&4-> &6It is no longer UHC day! &4<-");

this.timeToBan = TimeConverter.parseStringToMillis(timeToBanString);

Expand All @@ -207,8 +245,19 @@ public void saveSettings()
{
config.set("Settings.Debug", Boolean.valueOf(this.debug));
config.set("Settings.TimeToBan", this.timeToBanString);
config.set("Settings.UHCDayEnabled", Boolean.valueOf(this.uhcDayEnabled));
config.set("Settings.UHCDay", this.uhcDay);

config.set("Misc.UHCDayEnabled", Boolean.valueOf(this.uhcDayEnabled));
config.set("Misc.UHCDay", this.uhcDay);
config.set("Misc.PlaySounds", this.playSoundEnabled);
config.set("Misc.Sound_UHCStart", this.uhcStartSound);
config.set("Misc.Sound_UHCEnd", this.uhcEndSound);

config.set("Messages.LoginUHCDay", this.messageLoginUHCDay);
config.set("Messages.BanPlayer", this.messageBanPlayer);
config.set("Messages.KickPlayerOnBan", this.messageKickPlayerOnBan);
config.set("Messages.PlayerTimeLeft", this.messageKickPlayerTimeLeft);
config.set("Messages.StartUHCDay", this.messageStartUHCDay);
config.set("Messages.EndUHCDay", this.messageEndUHCDay);

saveConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void onPlayerJoin(PlayerJoinEvent event)
{
return;
}
if (plugin.uhcDayEnabled && plugin.isUHCDay) {
plugin.logDebug("Trying to send player the It is UHC day message!");
plugin.sendInfo(event.getPlayer(), plugin.messageLoginUHCDay);
}
if (!event.getPlayer().isOp() && (!SemiHardcore.getPermissionsManager().hasPermission(event.getPlayer(), "semihardcore.exempt"))) {
plugin.logDebug("No op or exempt, checking player");
SemiHardcore.getPlayerManager().newPlayerCheck(event);
Expand Down

0 comments on commit 6b08553

Please sign in to comment.