-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Campfire sleep not presently implemented.
- Loading branch information
1 parent
ab90228
commit 519b230
Showing
6 changed files
with
176 additions
and
3 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
42 changes: 42 additions & 0 deletions
42
src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/SleepAtCampfire/SleepAtCampfire.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,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() + ""); | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...in/java/me/shakeforprotein/treebotweakssp/Tweaks/TimescaleModifier/TimescaleModifier.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,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); | ||
|
||
} | ||
} | ||
} | ||
} |
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