Skip to content

Commit

Permalink
Adds Time control clock.
Browse files Browse the repository at this point in the history
Campfire sleep not presently implemented.
  • Loading branch information
ShakeforProtein committed Sep 28, 2021
1 parent ab90228 commit 519b230
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>TreeboTweaksSP</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>
<packaging>jar</packaging>

<name>TreeboTweaksSP</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import me.shakeforprotein.treebotweakssp.Tweaks.NerfMobDropsWhenNotKilledByPlayer.NerfDrops;
import me.shakeforprotein.treebotweakssp.Tweaks.NetherWater.AllowWaterInNether;
import me.shakeforprotein.treebotweakssp.Tweaks.PlayerKeepItemsIfKilledByPlayer.PlayerKeepItems;
import me.shakeforprotein.treebotweakssp.Tweaks.SleepAtCampfire.SleepAtCampfire;
import me.shakeforprotein.treebotweakssp.Tweaks.StoneToMonsterStone.Listeners.CreatureSpawnListener;
import me.shakeforprotein.treebotweakssp.Tweaks.StoneToMonsterStone.Listeners.PlayerInteractListener;
import me.shakeforprotein.treebotweakssp.Tweaks.TimedPvpBlockBreak.Listeners.LastPvpListener;
import me.shakeforprotein.treebotweakssp.Tweaks.TimescaleModifier.TimescaleModifier;
import me.shakeforprotein.treebotweakssp.Tweaks.TreeTwerking.Listeners.TwerkingListener;
import me.shakeforprotein.treebotweakssp.Tweaks.WorldGuardFlags.WorldGuardFlagExtentions;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -196,6 +198,10 @@ public void run() {
if(getConfig().getBoolean("Tweaks.BlockPortalsInWorldGuardRegions")){
Bukkit.getPluginManager().registerEvents(new BlockPortalsInWorldGuardRegions(this), this);
}
if(getConfig().getBoolean("Tweaks.SleepAtCampfire")){
//Bukkit.getPluginManager().registerEvents(new SleepAtCampfire(this),this);
}
Bukkit.getPluginManager().registerEvents(new TimescaleModifier(this), this);
}

public void runCommandSynchronouslyLater(CommandSender sender, String command, long delay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public MaintainFlightBetweenWorlds(TreeboTweaksSP main){
public void maintainFlight(PlayerChangedWorldEvent e){
if(flyingPlayers.containsKey(e.getPlayer()) && e.getPlayer().hasPermission("essentials.fly")){
Bukkit.getScheduler().runTaskLater(pl, ()->{
e.getPlayer().setAllowFlight(true);
e.getPlayer().setFlying(true);
if(!e.getPlayer().getWorld().getName().toLowerCase().contains("resource")) {
e.getPlayer().setAllowFlight(true);
e.getPlayer().setFlying(true);
}
}, 2L);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.shakeforprotein.treebotweakssp.Tweaks.SleepAtCampfire;

import me.shakeforprotein.treebotweakssp.TreeboTweaksSP;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class SleepAtCampfire implements Listener {

private TreeboTweaksSP pl;

public SleepAtCampfire(TreeboTweaksSP main){
this.pl = main;
}

@EventHandler
private void playerInteractCampfire(PlayerInteractEvent event){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().isSneaking() && event.getItem().getType() == Material.AIR && event.getPlayer().getWorld().getTime() > 12000){

Location existingBedSpawnLocation = event.getPlayer().getBedSpawnLocation();

Player player = event.getPlayer();

player.sendBlockChange(event.getPlayer().getLocation().getBlock().getLocation(), Bukkit.createBlockData(Material.RED_BED));

event.getPlayer().sleep(event.getPlayer().getLocation().getBlock().getLocation(), true);

if(existingBedSpawnLocation != null) {
if (event.getPlayer().getBedSpawnLocation() != existingBedSpawnLocation) {
event.getPlayer().setBedSpawnLocation(existingBedSpawnLocation, true);
}
}
} else {
event.getPlayer().sendMessage(event.getPlayer().getWorld().getTime() + "");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package me.shakeforprotein.treebotweakssp.Tweaks.TimescaleModifier;

import me.shakeforprotein.treebotweakssp.TreeboTweaksSP;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.List;

public class TimescaleModifier implements Listener {

private TreeboTweaksSP pl;

private List<World> worlds;
private String timeMultiplier = "NORMAL";
private int cycles = 0;
private BukkitTask timer;
private Runnable normalRunnable = () -> {
};
private Runnable doubleRunnable = () -> {
for (World world : worlds) {
world.setTime(world.getFullTime() + 1);
}
};
private Runnable quadRunnable = () -> {
for (World world : worlds) {
world.setTime(world.getFullTime() + 3);
}
};
private Runnable stupidRunnable = () -> {
for (World world : worlds) {
world.setTime(world.getFullTime() + 127);
}
};
private Runnable halfRunnable = () -> {
if (cycles == 1) {
for (World world : worlds) {
world.setTime(world.getFullTime() - 1);
}
cycles = 0;
} else {
cycles = 1;
}
};
private Runnable quarterRunnable = () -> {
if (cycles >= 3) {
for (World world : worlds) {
world.setTime(world.getFullTime() - 1);
}
cycles = 0;
} else {
cycles++;
}
};

private Runnable shortNightRunnable = () -> {
for (World world : worlds) {
Long time = world.getTime();
if (time > 18000 || time < 6000) {
world.setFullTime(world.getFullTime() + 3);
}
}
};

private HashMap<String, Runnable> speedHash = new HashMap<>();

public TimescaleModifier(TreeboTweaksSP main) {
this.pl = main;
speedHash.put("NORMAL", normalRunnable);
speedHash.put("DOUBLE", doubleRunnable);
speedHash.put("QUADRUPLE", quadRunnable);
speedHash.put("STUPID", stupidRunnable);
speedHash.put("HALF", halfRunnable);
speedHash.put("QUARTER", quarterRunnable);
speedHash.put("SHORTNIGHTS", shortNightRunnable);


Bukkit.getScheduler().runTaskLater(pl, () -> {
worlds = Bukkit.getWorlds();
timer = Bukkit.getScheduler().runTaskTimer(pl, normalRunnable, 1L, 1L);
}, 1L);
}

@EventHandler
public void multiplyTimeScale (PlayerInteractEvent event){
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (event.getPlayer().hasPermission("treebo.staff") && event.getItem().getType() == Material.CLOCK && event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasEnchants() && event.getItem().getItemMeta().hasEnchant(Enchantment.DIG_SPEED)) {
String newValue = "NORMAL";

if (timeMultiplier.equalsIgnoreCase("NORMAL")) {
newValue = "DOUBLE";
} else if (timeMultiplier.equalsIgnoreCase("DOUBLE")) {
newValue = "QUADRUPLE";
} else if (timeMultiplier.equalsIgnoreCase("QUADRUPLE")) {
newValue = "STUPID";
} else if (timeMultiplier.equalsIgnoreCase("STUPID")) {
newValue = "HALF";
} else if (timeMultiplier.equalsIgnoreCase("HALF")) {
newValue = "QUARTER";
} else if (timeMultiplier.equalsIgnoreCase("QUARTER")) {
newValue = "SHORTNIGHTS";
} else if (timeMultiplier.equalsIgnoreCase("SHORTNIGHTS")) {
newValue = "NORMAL";
}

timer.cancel();
timeMultiplier = newValue;
timer = Bukkit.getScheduler().runTaskTimer(pl, speedHash.get(newValue), 1L, 1L);

event.getPlayer().sendMessage(pl.badge + "Set Timescale to " + newValue);

}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Tweaks:
Description_MaintainFlightBetweenWorlds: Ensures flight status is toggled on during world change if it was toggled on prior to world change.
BlockPortalsInWorldGuardRegions: true
Description_BlockPortalsInWorldGuardRegions: Block portals from being created in a world guard protected region, both manually and as a result of using a portal in another dimension.
SleepAtCampfire: true

DynmapToInGameMapDetails:
World: 'Survival'
Expand Down

0 comments on commit 519b230

Please sign in to comment.