Skip to content

Commit

Permalink
v0.0.7 - Option for a day where UHC (no natural regeneration), is act…
Browse files Browse the repository at this point in the history
…ive. Is enabled by default, for own server
  • Loading branch information
Fido2603 committed May 26, 2019
1 parent 9d1ff46 commit 7e08718
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 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.6</version>
<version>0.0.7</version>
<name>Semi-Hardcore</name>
<repositories>
<!-- Spigot Repo for Spigot and Bukkit -->
Expand Down
59 changes: 58 additions & 1 deletion src/main/java/dk/fido2603/semihardcore/SemiHardcore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import dk.fido2603.semihardcore.listeners.PlayerListener;
import net.milkbowl.vault.economy.Economy;

import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
Expand All @@ -15,6 +18,9 @@ public class SemiHardcore extends JavaPlugin
{
public static boolean pluginEnabled = false;
public boolean vaultEnabled = false;
public boolean uhcDayEnabled = true;
public Integer uhcDay = 2;
public boolean isUHCDay = false;
public static Server server = null;
public boolean debug = false;
private String timeToBanString = "24h";
Expand All @@ -28,6 +34,7 @@ public class SemiHardcore extends JavaPlugin
private Commands commands = null;

private static SemiHardcore plugin;
private ConsoleCommandSender console;

public static PermissionsManager getPermissionsManager()
{
Expand All @@ -43,6 +50,14 @@ public static Economy getEconomy()
{
return economy;
}

public void sendInfoAll(String message) {
String translatedMessage = ChatColor.translateAlternateColorCodes('&', message);
for (Player player : plugin.getServer().getOnlinePlayers())
{
player.sendMessage(translatedMessage);
}
}

public void sendInfo(Player player, String message)
{
Expand All @@ -60,6 +75,16 @@ public void onDisable()
{
saveSettings();
reloadSettings();

if (this.uhcDayEnabled) {
logDebug("Checking to turn off UHC");

if (isUHCDay) {
getServer().dispatchCommand(console, "gamerule naturalRegeneration true");
isUHCDay = false;
log("Turned off UHC!");
}
}

pluginEnabled = false;
}
Expand All @@ -72,6 +97,7 @@ public void onEnable()
server = getServer();
config = getConfig();

this.console = server.getConsoleSender();
this.commands = new Commands(this);

pluginEnabled = true;
Expand All @@ -97,7 +123,7 @@ public void onEnable()
}
else
{
plugin.log("Vault not found.");
log("Vault not found.");
}
}
else
Expand All @@ -109,6 +135,33 @@ public void onEnable()

loadSettings();
saveSettings();

if (this.uhcDayEnabled) {
logDebug("UHC Day is enabled... checking");
logDebug("Current day of week: " + TimeConverter.getDayOfWeek() + ". UHC Day: " + uhcDay);

// now let's check every half minute, if it's UHC day
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
{
public void run()
{
if (TimeConverter.getDayOfWeek() == uhcDay && !isUHCDay) {
log("It's time for UHC day, switching the gamerule");
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!");
}
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!");
}
}
}, 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
}

permissionsManager.load();
playerManager.load();
Expand Down Expand Up @@ -141,6 +194,8 @@ 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.timeToBan = TimeConverter.parseStringToMillis(timeToBanString);

Expand All @@ -152,6 +207,8 @@ 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);

saveConfig();
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dk/fido2603/semihardcore/TimeConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dk.fido2603.semihardcore;

import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class TimeConverter
Expand Down Expand Up @@ -87,4 +89,11 @@ public static String parseMillisToUFString(long millis) {
return String.format("%d %s", banMinutes, m);
}

public static Integer getDayOfWeek() {
Calendar calendar = Calendar.getInstance();
Date currentTime = new Date();
calendar.setTime(currentTime);
return calendar.get(Calendar.DAY_OF_WEEK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onPlayerJoin(PlayerJoinEvent event)
{
return;
}
if (!event.getPlayer().isOp() || (!SemiHardcore.getPermissionsManager().hasPermission(event.getPlayer(), "semihardcore.exempt"))) {
if (!event.getPlayer().isOp() && (!SemiHardcore.getPermissionsManager().hasPermission(event.getPlayer(), "semihardcore.exempt"))) {
plugin.logDebug("No op or exempt, checking player");
SemiHardcore.getPlayerManager().newPlayerCheck(event.getPlayer());
return;
Expand All @@ -36,7 +36,7 @@ public void onPlayerJoin(PlayerJoinEvent event)
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event)
{
if (!event.getEntity().isOp() || (!SemiHardcore.getPermissionsManager().hasPermission(event.getEntity(), "semihardcore.exempt"))) {
if (!event.getEntity().isOp() && (!SemiHardcore.getPermissionsManager().hasPermission(event.getEntity(), "semihardcore.exempt"))) {
plugin.logDebug("No op or exempt, banning player");
SemiHardcore.getPlayerManager().banPlayer(event.getEntity(), event.getEntity().getUniqueId());
return;
Expand Down

0 comments on commit 7e08718

Please sign in to comment.