Add Decompiled Java source code

This commit is contained in:
Len 2026-08-01 04:23:13 -05:00
parent 5233b2f046
commit 588023b20e
4 changed files with 340 additions and 0 deletions

View File

@ -0,0 +1,75 @@
package com.alttd;
import java.io.File;
import java.io.IOException;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
public class FileManager {
public static SkipNight plugin;
public FileManager(SkipNight plugin) {
FileManager.plugin = plugin;
}
public static void createFile() {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
if (!file.exists()) {
try {
file.createNewFile();
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
configFile.set("World_Name", "world");
configFile.set("Percentage", 0.51D);
configFile.set("Player.Sleep.Night", "&7* %player is sleeping. %count more required.");
configFile.set("Player.Sleep.Storm", "&7* %player is sleeping. %count more required.");
configFile.set("Player.Sleep.AlreadySleptNight", "&7Your vote to skip the night has already counted. %count more required.");
configFile.set("Player.Sleep.AlreadySleptStorm", "&7Your vote to skip the storm has already counted. %count more required.");
configFile.set("Server.Skip.Night", "&7Majority vote. Skipping night.");
configFile.set("Server.Skip.Storm", "&7Majority vote. Skipping storm.");
configFile.save(file);
} catch (IOException var2) {
var2.printStackTrace();
}
}
}
public static void saveFile() {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
YamlConfiguration configFile = YamlConfiguration.loadConfiguration(file);
try {
configFile.save(file);
} catch (IOException var3) {
var3.printStackTrace();
}
}
public static String getCMessages(String string, Player player, Integer count) {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
String getString = configFile.getString(string);
return ChatColor.translateAlternateColorCodes('&', getString).replace("%count", Integer.toString(count)).replace("%player", player.getName());
}
public static String getNMessages(String string) {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
return ChatColor.translateAlternateColorCodes('&', configFile.getString(string));
}
public static Double getPercentage(String string) {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
return configFile.getDouble(string);
}
public static String getWorld(String worldName) {
File file = new File("plugins/SkipNight" + File.separator + "config.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
return configFile.getString(worldName);
}
}

View File

@ -0,0 +1,248 @@
package com.alttd;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public class SkipNight extends JavaPlugin implements Listener {
ArrayList<String> alreadySleptNight = new ArrayList();
ArrayList<String> alreadySleptStorm = new ArrayList();
boolean checkNightTimer = false;
boolean checkStormTimer = false;
boolean skipNight = false;
boolean skipStorm = false;
boolean lockPlayer = false;
int animationSpeed = 150;
public void onEnable() {
Bukkit.getServer().getPluginManager().registerEvents(this, this);
File file = new File("plugins/SkipNight");
if (!file.exists()) {
file.mkdirs();
FileManager.createFile();
}
}
@EventHandler
public void onPlayerbed(PlayerBedEnterEvent e) {
Player player = e.getPlayer();
if (e.getBedEnterResult().equals(BedEnterResult.OK)) {
double playersNeededStorm;
double roundPlayers;
Player players;
Iterator var8;
if (Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getTime() >= 13000L) {
playersNeededStorm = (double)this.getOnlinePlayers() * FileManager.getPercentage("Percentage") - (double)this.alreadySleptNight.size();
roundPlayers = Math.ceil(playersNeededStorm);
if (!this.alreadySleptStorm.isEmpty()) {
this.alreadySleptStorm.clear();
this.checkNightTimer = false;
}
if (!this.checkNightTimer) {
this.checkNightTimer = true;
this.startServerTimeCheck();
}
if (this.alreadySleptNight.contains(player.getName())) {
player.sendMessage(FileManager.getCMessages("Player.Sleep.AlreadySleptNight", player, (int)roundPlayers + 1));
return;
}
if (roundPlayers >= 1.0D) {
this.alreadySleptNight.add(player.getName());
if (!this.skipNight) {
var8 = Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getPlayers().iterator();
while(var8.hasNext()) {
players = (Player)var8.next();
players.sendMessage(FileManager.getCMessages("Player.Sleep.Night", player, (int)roundPlayers));
}
}
}
if (roundPlayers <= 0.0D && !this.skipNight) {
this.skipNight = true;
this.checkNightTimer = false;
this.startDayAnimation();
var8 = Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getPlayers().iterator();
while(var8.hasNext()) {
players = (Player)var8.next();
players.sendMessage(FileManager.getCMessages("Server.Skip.Night", player, (int)roundPlayers));
}
}
} else if (Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).isThundering()) {
playersNeededStorm = (double)this.getOnlinePlayers() * FileManager.getPercentage("Percentage") - (double)this.alreadySleptStorm.size();
roundPlayers = Math.ceil(playersNeededStorm);
if (!this.checkStormTimer) {
this.checkStormTimer = true;
this.startServerStormCheck();
}
if (this.alreadySleptStorm.contains(player.getName())) {
player.sendMessage(FileManager.getCMessages("Player.Sleep.AlreadySleptStorm", player, (int)roundPlayers + 1));
return;
}
if (roundPlayers >= 1.0D) {
this.alreadySleptStorm.add(player.getName());
if (!this.skipStorm) {
var8 = Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getPlayers().iterator();
while(var8.hasNext()) {
players = (Player)var8.next();
players.sendMessage(FileManager.getCMessages("Player.Sleep.Storm", player, (int)roundPlayers));
}
}
}
if (roundPlayers <= 0.0D && !this.skipStorm) {
this.skipStorm = true;
this.checkStormTimer = false;
this.startStormDelay();
var8 = Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getPlayers().iterator();
while(var8.hasNext()) {
players = (Player)var8.next();
players.sendMessage(FileManager.getCMessages("Server.Skip.Storm", player, (int)roundPlayers));
}
}
}
}
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent e) {
Player player = e.getPlayer();
if (this.alreadySleptNight.contains(player.getName())) {
this.alreadySleptNight.remove(player.getName());
}
if (this.alreadySleptStorm.contains(player.getName())) {
this.alreadySleptStorm.remove(player.getName());
}
}
public int getOnlinePlayers() {
int numberOfPlayers = 0;
for(int i = 0; i < Bukkit.getServer().getOnlinePlayers().size(); numberOfPlayers = i++) {
}
return numberOfPlayers;
}
public void startServerTimeCheck() {
(new BukkitRunnable() {
int count = 15;
public void run() {
if (SkipNight.this.checkNightTimer) {
if (this.count >= 1) {
--this.count;
}
if (this.count == 0) {
if (Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getTime() >= 0L && Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getTime() <= 13000L) {
SkipNight.this.alreadySleptNight.clear();
SkipNight.this.checkNightTimer = false;
SkipNight.this.skipNight = false;
this.cancel();
} else {
this.count = 15;
}
}
} else {
this.cancel();
}
}
}).runTaskTimer(this, 0L, 20L);
}
public void startServerStormCheck() {
(new BukkitRunnable() {
int count = 15;
public void run() {
if (SkipNight.this.checkStormTimer) {
if (this.count >= 1) {
--this.count;
}
if (this.count == 0) {
if (Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).isThundering()) {
this.count = 15;
} else {
SkipNight.this.alreadySleptStorm.clear();
SkipNight.this.checkStormTimer = false;
SkipNight.this.skipStorm = false;
this.cancel();
}
}
} else {
this.cancel();
}
}
}).runTaskTimer(this, 0L, 20L);
}
public void startStormDelay() {
(new BukkitRunnable() {
int count = 3;
public void run() {
if (this.count >= 1) {
--this.count;
}
if (this.count == 0) {
SkipNight.this.skipStorm = false;
SkipNight.this.alreadySleptStorm.clear();
SkipNight.this.clearStorms();
this.cancel();
}
}
}).runTaskTimer(this, 0L, 20L);
}
public void startDayAnimation() {
(new BukkitRunnable() {
public void run() {
long currentTime = Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).getTime();
long newTime = currentTime + (long)SkipNight.this.animationSpeed;
if (newTime >= 23450L) {
Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).setTime(23450L);
SkipNight.this.skipNight = false;
SkipNight.this.alreadySleptNight.clear();
SkipNight.this.clearStorms();
this.cancel();
}
Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).setTime(currentTime + (long)SkipNight.this.animationSpeed);
}
}).runTaskTimer(this, 1L, 1L);
}
public void clearStorms() {
if (Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).isThundering()) {
Bukkit.getServer().getWorld(FileManager.getWorld("World_Name")).setStorm(false);
}
}
}

14
src/main/resources/config.yml Executable file
View File

@ -0,0 +1,14 @@
World_Name: 'world'
Percentage: 0.3
Player:
Sleep:
Night: ''
Storm: ''
AlreadySleptNight: ''
AlreadtSleptStorm: ''
Server:
Skip:
Night ''
Storm: ''

3
src/main/resources/plugin.yml Executable file
View File

@ -0,0 +1,3 @@
name: SkipNight
main: com.alttd.SkipNight
version: 0.7