Created an automatic updater for TwosideKeeper and aPlugin for the
server. Added a Discord Message status updater to keep track of Time of day, Ticks per second, and player count.
This commit is contained in:
parent
4335ee2eba
commit
12f050e24c
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
name: TwosideKeeper
|
||||
main: sig.plugin.TwosideKeeper.TwosideKeeper
|
||||
version: 3.4.7a
|
||||
version: 3.4.7bbbbb
|
||||
commands:
|
||||
money:
|
||||
description: Tells the player the amount of money they are holding.
|
||||
|
144
src/sig/plugin/TwosideKeeper/AutoUpdatePlugin.java
Normal file
144
src/sig/plugin/TwosideKeeper/AutoUpdatePlugin.java
Normal file
@ -0,0 +1,144 @@
|
||||
package sig.plugin.TwosideKeeper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.CopyOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class AutoUpdatePlugin implements Runnable {
|
||||
List<Plugin> plugins;
|
||||
boolean restarting=false;
|
||||
|
||||
public AutoUpdatePlugin() {
|
||||
plugins = new ArrayList<Plugin>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
FetchPlugins();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void FetchPlugins() throws IOException {
|
||||
for (int i=0;i<plugins.size();i++) {
|
||||
FileUtils.copyURLToFile(new URL(plugins.get(i).url), new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
||||
|
||||
//After that's done, check the hash.
|
||||
FileInputStream file = new FileInputStream(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name));
|
||||
String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(file);
|
||||
file.close();
|
||||
|
||||
if (plugins.get(i).hash==null || !md5.equalsIgnoreCase(plugins.get(i).hash)) {
|
||||
//This plugin is different! Update the hash for it. Prepare for a restart of the server!
|
||||
restarting=true;
|
||||
//Save the new plugin hash.
|
||||
plugins.get(i).hash = md5;
|
||||
SaveHash(plugins.get(i));
|
||||
Bukkit.broadcastMessage("The server has detected a new version of "+ChatColor.YELLOW+plugins.get(i).name+". The server will restart in 3 minutes!");
|
||||
//Move the file to the new location.
|
||||
FileUtils.copyFile(new File(TwosideKeeper.filesave,"updates/"+plugins.get(i).name),
|
||||
new File(TwosideKeeper.filesave,"../"+plugins.get(i).name+".jar"));
|
||||
}
|
||||
}
|
||||
if (restarting) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.broadcastMessage(ChatColor.YELLOW+"The server is restarting in 1 minute for a plugin update!");
|
||||
}
|
||||
},20*120);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.broadcastMessage(ChatColor.RED+"The server is restarting in 10 seconds!");
|
||||
}
|
||||
},20*170);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("TwosideKeeper"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.savePlayers();
|
||||
for (int i=0;i<Bukkit.getWorlds().size();i++) {
|
||||
Bukkit.getWorlds().get(i).save();
|
||||
}
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
},20*180);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPlugin(String name, String url) {
|
||||
plugins.add(new Plugin(name,url));
|
||||
}
|
||||
|
||||
public void LoadHash(Plugin pluginname) {
|
||||
//Read from the server config.
|
||||
File config = new File(TwosideKeeper.filesave,"hashes.data");
|
||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||
pluginname.hash = workable.getString(pluginname.name+"/HASH");
|
||||
}
|
||||
public void SaveHash(Plugin pluginname) {
|
||||
File config = new File(TwosideKeeper.filesave,"hashes.data");
|
||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||
workable.set(pluginname.name+"/HASH",pluginname.hash);
|
||||
try {
|
||||
workable.save(config);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void SaveAllHashes(List<Plugin> pluginlist) {
|
||||
File config = new File(TwosideKeeper.filesave,"hashes.data");
|
||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||
for (int i=0;i<pluginlist.size();i++) {
|
||||
workable.set(pluginlist.get(i).name+"/HASH",pluginlist.get(i).hash);
|
||||
}
|
||||
try {
|
||||
workable.save(config);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Plugin {
|
||||
String name;
|
||||
String hash;
|
||||
String url;
|
||||
|
||||
public Plugin(String name,String url) {
|
||||
this.name=name;
|
||||
this.url=url;
|
||||
this.hash=FetchHash(); //Try to fetch the hash.
|
||||
}
|
||||
|
||||
public Plugin(String name,String hash,String url) {
|
||||
this.name=name;
|
||||
this.url=url;
|
||||
this.hash=hash;
|
||||
}
|
||||
|
||||
public String FetchHash() {
|
||||
File config = new File(TwosideKeeper.filesave,"hashes.data");
|
||||
FileConfiguration workable = YamlConfiguration.loadConfiguration(config);
|
||||
return workable.getString(this.name+"/HASH");
|
||||
}
|
||||
}
|
@ -660,7 +660,7 @@ public class GenericFunctions {
|
||||
return "Sandstone Slab";
|
||||
}
|
||||
case 2:{
|
||||
return "(Stone)Wooden Slab";
|
||||
return "Fireproof Oak Wooden Slab";
|
||||
}
|
||||
case 3:{
|
||||
return "Cobblestone Slab";
|
||||
|
@ -435,6 +435,10 @@ public class WorldShop {
|
||||
}
|
||||
message+="\n"+ChatColor.GRAY+"Repairs Left: "+(6-repairs);
|
||||
}
|
||||
//If there is a newline at the very end, cut it out.
|
||||
if (message.endsWith("\n")) {
|
||||
message.substring(0, message.length()-1);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
21
src/sig/plugin/TwosideKeeper/Lag.java
Normal file
21
src/sig/plugin/TwosideKeeper/Lag.java
Normal file
@ -0,0 +1,21 @@
|
||||
package sig.plugin.TwosideKeeper;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class Lag
|
||||
{
|
||||
public long LAST_TICK= System.currentTimeMillis();
|
||||
public double lastTPS = 20.0;
|
||||
|
||||
public void updateTPS()
|
||||
{
|
||||
long calctime = (long) ((System.currentTimeMillis()-LAST_TICK));
|
||||
TwosideKeeper.log("Ticks were "+LAST_TICK+":::"+System.currentTimeMillis(), 5);
|
||||
LAST_TICK = System.currentTimeMillis();
|
||||
lastTPS = 20*1000/(calctime / 60d);
|
||||
}
|
||||
public double getTPS() {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
return Double.parseDouble(df.format(lastTPS));
|
||||
}
|
||||
}
|
@ -476,7 +476,7 @@ public class Recipes {
|
||||
ItemStack modded_plank = new ItemStack(Material.STEP,1);
|
||||
modded_plank.setDurability((short)2);
|
||||
ItemMeta m = modded_plank.getItemMeta();
|
||||
m.setDisplayName("Fireproof Oak Wood Slab");
|
||||
m.setDisplayName("Fireproof Oak Wooden Slab");
|
||||
modded_plank.setItemMeta(m);
|
||||
stone_construction_recipe = new ShapelessRecipe(modded_plank);
|
||||
stone_construction_recipe.addIngredient(1, Material.WOOD_STEP);
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server.Spigot;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@ -135,6 +136,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import aPlugin.DiscordMessageSender;
|
||||
import net.minecraft.server.v1_9_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_9_R1.Vector3f;
|
||||
import sig.plugin.TwosideKeeper.HelperStructures.ArtifactItem;
|
||||
import sig.plugin.TwosideKeeper.HelperStructures.ArtifactItemType;
|
||||
@ -155,6 +157,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.WorldShop;
|
||||
import sig.plugin.TwosideKeeper.HelperStructures.WorldShopSession;
|
||||
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
|
||||
import sig.plugin.TwosideKeeper.Logging.MysteriousEssenceLogger;
|
||||
import net.minecraft.server.v1_9_R1.MinecraftServer;
|
||||
|
||||
|
||||
public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
@ -196,6 +199,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
public static SpleefManager TwosideSpleefGames;
|
||||
public static WorldShopManager TwosideShops;
|
||||
public static MysteriousEssenceLogger EssenceLogger; //The logger for Essences.
|
||||
public static AutoUpdatePlugin pluginupdater;
|
||||
public static Lag tpstracker;
|
||||
|
||||
public int TeamCounter = 0;
|
||||
public List<Party> PartyList = new ArrayList<Party>();
|
||||
@ -262,6 +267,20 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
TwosideRecyclingCenter.loadConfig();
|
||||
log("Recycling Centers Loaded: "+TwosideRecyclingCenter.getNumberOfNodes(),3);
|
||||
|
||||
pluginupdater = new AutoUpdatePlugin();
|
||||
pluginupdater.AddPlugin("TwosideKeeper", "https://github.com/sigonasr2/TwosideKeeper/raw/master/TwosideKeeper.jar");
|
||||
pluginupdater.AddPlugin("aPlugin", "https://dl.dropboxusercontent.com/u/62434995/aPlugin.jar");
|
||||
|
||||
if (SERVER_TYPE==ServerType.MAIN) {
|
||||
//Try an update right away.
|
||||
try {
|
||||
pluginupdater.FetchPlugins();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//Create Spleef Games.
|
||||
TwosideSpleefGames = new SpleefManager(this);
|
||||
|
||||
@ -294,6 +313,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
playerdata = new HashMap();
|
||||
banksessions = new HashMap();
|
||||
|
||||
//tpstracker = new Lag();
|
||||
|
||||
//Let's not assume there are no players online. Load their data.
|
||||
for (int i=0;i<Bukkit.getOnlinePlayers().toArray().length;i++) {
|
||||
playerdata.put(((Player)Bukkit.getOnlinePlayers().toArray()[i]).getUniqueId(), new PlayerStructure((Player)Bukkit.getOnlinePlayers().toArray()[i],getServerTickTime()));
|
||||
@ -355,6 +376,26 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
}
|
||||
}}, 5l, 5l);
|
||||
|
||||
if (SERVER_TYPE==ServerType.MAIN) { //Only perform this on the official servers. Test servers do not require constant updating.
|
||||
//Every 5 minutes, check for a plugin update.
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
|
||||
public void run(){
|
||||
try {
|
||||
pluginupdater.FetchPlugins();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}}, 20*300, 20*300);
|
||||
}
|
||||
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
|
||||
public void run(){
|
||||
DiscordMessageSender.setPlaying(getTimeOfDay()+" "+getWeatherIcon()+" TPS: "+MinecraftServer.getServer().recentTps[0]+" ("+Bukkit.getOnlinePlayers().size()+"/"+Bukkit.getMaxPlayers()+")");
|
||||
}
|
||||
}, 300l, 300l);
|
||||
|
||||
//This is the constant timing method.
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
|
||||
public void run(){
|
||||
@ -587,7 +628,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
MalleableBaseQuest.getTimeStarted(p.getEquipment().getItemInMainHand())<=147337849) {
|
||||
p.getEquipment().setItemInMainHand(MalleableBaseQuest.setTimeStarted(p.getEquipment().getItemInMainHand(), getServerTickTime()));
|
||||
}
|
||||
GenericFunctions.addObscureHardenedItemBreaks(p.getEquipment().getItemInMainHand(), 4);
|
||||
|
||||
//p.sendMessage(tpstracker.getTPS()+"");
|
||||
//GenericFunctions.addObscureHardenedItemBreaks(p.getEquipment().getItemInMainHand(), 4);
|
||||
return true;
|
||||
} else
|
||||
if (cmd.getName().equalsIgnoreCase("money")) {
|
||||
@ -4111,25 +4154,41 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
},20);
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onServerListPing(ServerListPingEvent ev) {
|
||||
public String getWeatherIcon() {
|
||||
long time = Bukkit.getWorld("world").getTime();
|
||||
String weather = "";
|
||||
if (Bukkit.getWorld("world").hasStorm()) {weather="\u2602";} else {if (time>=10000) {weather="\u263D";} else {weather="\u2600";}}
|
||||
return weather;
|
||||
}
|
||||
|
||||
public String getTimeOfDay() {
|
||||
long time = Bukkit.getWorld("world").getTime();
|
||||
String tod = "";
|
||||
if (time>0 && time<=3000) {
|
||||
ev.setMotd("\u00A7bsig's Minecraft!\n"+weather+" \u00A7fCurrently: \u00A7eMORNING");
|
||||
tod="\u00A7eMORNING";
|
||||
} else
|
||||
if (time>3000 && time<=10000) {
|
||||
ev.setMotd("\u00A7bsig's Minecraft!\n"+weather+" \u00A7fCurrently: \u00A76AFTERNOON");
|
||||
tod="\u00A76AFTERNOON";
|
||||
} else
|
||||
if (time>10000 && time<=13000) {
|
||||
ev.setMotd("\u00A7bsig's Minecraft!\n"+weather+" \u00A7fCurrently: \u00A73EVENING");
|
||||
tod="\u00A73EVENING";
|
||||
} else
|
||||
if (time>13000 && time<23000) {
|
||||
ev.setMotd("\u00A7bsig's Minecraft!\n"+weather+" \u00A7fCurrently: \u00A79NIGHT");
|
||||
tod="\u00A79NIGHT";
|
||||
} else {
|
||||
ev.setMotd("\u00A7bsig's Minecraft!\n"+weather+" \u00A7fCurrently: \u00A7dDAWN");
|
||||
tod="\u00A7dDAWN";
|
||||
}
|
||||
return tod;
|
||||
}
|
||||
|
||||
public String getServerListPingString() {
|
||||
long time = Bukkit.getWorld("world").getTime();
|
||||
return "\u00A7bsig's Minecraft!\n"+getWeatherIcon()+" \u00A7fCurrently: "+getTimeOfDay();
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onServerListPing(ServerListPingEvent ev) {
|
||||
ev.setMotd(getServerListPingString());
|
||||
}
|
||||
|
||||
public void saveOurData(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user