mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Cleanup
This commit is contained in:
parent
ca1954ff80
commit
18c52a5e23
@ -115,15 +115,14 @@ public class mcMMO extends JavaPlugin {
|
|||||||
|
|
||||||
if (Config.getInstance().getStatsTrackingEnabled()) {
|
if (Config.getInstance().getStatsTrackingEnabled()) {
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Failed to submit stats.");
|
System.out.println("Failed to submit stats.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get profile of the player.
|
* Get profile of the player.
|
||||||
* </br>
|
* </br>
|
||||||
@ -164,23 +163,20 @@ public class mcMMO extends JavaPlugin {
|
|||||||
* Things to be run when the plugin is disabled.
|
* Things to be run when the plugin is disabled.
|
||||||
*/
|
*/
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
//Make sure to save player information if the server shuts down
|
//Make sure to save player information if the server shuts down
|
||||||
for (PlayerProfile x : Users.getProfiles().values()) {
|
for (PlayerProfile x : Users.getProfiles().values()) {
|
||||||
x.save();
|
x.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.getServer().getScheduler().cancelTasks(this); //This removes our tasks
|
this.getServer().getScheduler().cancelTasks(this); //This removes our tasks
|
||||||
|
|
||||||
//Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
|
//Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
|
||||||
|
try {
|
||||||
try { //Try the backup
|
ZipLibrary.mcMMObackup();
|
||||||
ZipLibrary.mcMMObackup();
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
p.getLogger().severe(e.toString());
|
||||||
p.getLogger().severe(e.toString());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("mcMMO was disabled."); //How informative!
|
System.out.println("mcMMO was disabled."); //How informative!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +184,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
* Register the commands.
|
* Register the commands.
|
||||||
*/
|
*/
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
|
|
||||||
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
|
//Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
|
||||||
//Skills commands
|
//Skills commands
|
||||||
aliasMap.put(LocaleLoader.getString("Acrobatics.SkillName").toLowerCase(), "acrobatics");
|
aliasMap.put(LocaleLoader.getString("Acrobatics.SkillName").toLowerCase(), "acrobatics");
|
||||||
|
@ -15,7 +15,7 @@ import com.gmail.nossr50.util.Combat;
|
|||||||
|
|
||||||
public class BleedTimer implements Runnable {
|
public class BleedTimer implements Runnable {
|
||||||
private final static int MAX_BLEED_TICKS = 10;
|
private final static int MAX_BLEED_TICKS = 10;
|
||||||
|
|
||||||
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();
|
private static Map<LivingEntity, Integer> bleedList = new HashMap<LivingEntity, Integer>();
|
||||||
private static Map<LivingEntity, Integer> bleedAddList = new HashMap<LivingEntity, Integer>();
|
private static Map<LivingEntity, Integer> bleedAddList = new HashMap<LivingEntity, Integer>();
|
||||||
private static List<LivingEntity> bleedRemoveList = new ArrayList<LivingEntity>();
|
private static List<LivingEntity> bleedRemoveList = new ArrayList<LivingEntity>();
|
||||||
@ -121,6 +121,7 @@ public class BleedTimer implements Runnable {
|
|||||||
* Add a LivingEntity to the bleedList if it is not in it.
|
* Add a LivingEntity to the bleedList if it is not in it.
|
||||||
*
|
*
|
||||||
* @param entity LivingEntity to add
|
* @param entity LivingEntity to add
|
||||||
|
* @param ticks Number of bleeding ticks
|
||||||
*/
|
*/
|
||||||
public static void add(LivingEntity entity, int ticks) {
|
public static void add(LivingEntity entity, int ticks) {
|
||||||
int newTicks = ticks;
|
int newTicks = ticks;
|
||||||
@ -128,7 +129,7 @@ public class BleedTimer implements Runnable {
|
|||||||
if (lock) {
|
if (lock) {
|
||||||
if (bleedAddList.containsKey(entity)) {
|
if (bleedAddList.containsKey(entity)) {
|
||||||
newTicks += bleedAddList.get(entity);
|
newTicks += bleedAddList.get(entity);
|
||||||
|
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
if (newTicks > MAX_BLEED_TICKS) {
|
||||||
newTicks = MAX_BLEED_TICKS;
|
newTicks = MAX_BLEED_TICKS;
|
||||||
}
|
}
|
||||||
@ -146,7 +147,7 @@ public class BleedTimer implements Runnable {
|
|||||||
else {
|
else {
|
||||||
if (bleedList.containsKey(entity)) {
|
if (bleedList.containsKey(entity)) {
|
||||||
newTicks += bleedList.get(entity);
|
newTicks += bleedList.get(entity);
|
||||||
|
|
||||||
if (newTicks > MAX_BLEED_TICKS) {
|
if (newTicks > MAX_BLEED_TICKS) {
|
||||||
newTicks = MAX_BLEED_TICKS;
|
newTicks = MAX_BLEED_TICKS;
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,7 @@ public class BlastMining {
|
|||||||
/**
|
/**
|
||||||
* Detonate TNT for Blast Mining
|
* Detonate TNT for Blast Mining
|
||||||
*
|
*
|
||||||
|
* @param event The PlayerInteractEvent
|
||||||
* @param player Player detonating the TNT
|
* @param player Player detonating the TNT
|
||||||
* @param plugin mcMMO plugin instance
|
* @param plugin mcMMO plugin instance
|
||||||
*/
|
*/
|
||||||
|
@ -310,11 +310,11 @@ public class Combat {
|
|||||||
if (!(entity instanceof LivingEntity)) {
|
if (!(entity instanceof LivingEntity)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfTargets <= 0) {
|
if (numberOfTargets <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case WOLF:
|
case WOLF:
|
||||||
AnimalTamer tamer = ((Wolf) entity).getOwner();
|
AnimalTamer tamer = ((Wolf) entity).getOwner();
|
||||||
@ -324,50 +324,49 @@ public class Combat {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
Player defender = (Player) entity;
|
Player defender = (Player) entity;
|
||||||
|
|
||||||
if (!target.getWorld().getPVP()) {
|
if (!target.getWorld().getPVP()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defender.getName().equals(attacker.getName())) {
|
if (defender.getName().equals(attacker.getName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Party.getInstance().inSameParty(attacker, defender)) {
|
if (Party.getInstance().inSameParty(attacker, defender)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerProfile playerProfile = Users.getProfile((Player) entity);
|
PlayerProfile playerProfile = Users.getProfile((Player) entity);
|
||||||
|
|
||||||
if (playerProfile.getGodMode()) {
|
if (playerProfile.getGodMode()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SWORDS:
|
case SWORDS:
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BleedTimer.add((LivingEntity) entity, 5);
|
BleedTimer.add((LivingEntity) entity, 5);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case AXES:
|
case AXES:
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dealDamage((LivingEntity) entity, damageAmount, attacker);
|
dealDamage((LivingEntity) entity, damageAmount, attacker);
|
||||||
numberOfTargets--;
|
numberOfTargets--;
|
||||||
}
|
}
|
||||||
|
@ -15,57 +15,55 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
public class ZipLibrary {
|
public class ZipLibrary {
|
||||||
|
|
||||||
private static String BackupDirectory = mcMMO.mainDirectory + "backup";
|
private static String BackupDirectory = mcMMO.mainDirectory + "backup";
|
||||||
private static File BackupDir = new File(BackupDirectory);
|
private static File BackupDir = new File(BackupDirectory);
|
||||||
private static File FlatFileDirectory = new File(mcMMO.flatFileDirectory);
|
private static File FlatFileDirectory = new File(mcMMO.flatFileDirectory);
|
||||||
private static File UsersFile = new File(mcMMO.usersFile);
|
private static File UsersFile = new File(mcMMO.usersFile);
|
||||||
private static File ConfigFile = new File(mcMMO.mainDirectory + "config.yml");
|
private static File ConfigFile = new File(mcMMO.mainDirectory + "config.yml");
|
||||||
private static File Leaderboards = new File(mcMMO.leaderboardDirectory);
|
private static File Leaderboards = new File(mcMMO.leaderboardDirectory);
|
||||||
|
|
||||||
|
public static void mcMMObackup() throws IOException {
|
||||||
public static void mcMMObackup() throws IOException {
|
if (BackupDir.mkdir()) {
|
||||||
try {
|
try {
|
||||||
if (BackupDir.mkdir()) { mcMMO.p.getLogger().info("Created Backup Directory."); }
|
mcMMO.p.getLogger().info("Created Backup Directory.");
|
||||||
} catch (Exception h) {
|
} catch (Exception e) {
|
||||||
mcMMO.p.getLogger().severe(h.toString());
|
mcMMO.p.getLogger().severe(e.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//Generate the proper date for the backup filename
|
|
||||||
Date date = new Date();
|
//Generate the proper date for the backup filename
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
Date date = new Date();
|
||||||
File fileZip = new File(BackupDirectory + File.separator + dateFormat.format(date) + ".zip");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||||
|
File fileZip = new File(BackupDirectory + File.separator + dateFormat.format(date) + ".zip");
|
||||||
|
|
||||||
//Create the Source List, and add directories/etc to the file.
|
//Create the Source List, and add directories/etc to the file.
|
||||||
List<File> sources = new ArrayList<File>();
|
List<File> sources = new ArrayList<File>();
|
||||||
sources.add(FlatFileDirectory);
|
sources.add(FlatFileDirectory);
|
||||||
sources.add(UsersFile);
|
sources.add(UsersFile);
|
||||||
sources.add(ConfigFile);
|
sources.add(ConfigFile);
|
||||||
sources.add(Leaderboards);
|
sources.add(Leaderboards);
|
||||||
|
|
||||||
|
//Actually do something
|
||||||
//Actually do something
|
System.out.println("Backing up your mcMMO Configuration... ");
|
||||||
System.out.println("Backing up your mcMMO Configuration... ");
|
|
||||||
|
packZip(fileZip, sources);
|
||||||
packZip(fileZip, sources);
|
}
|
||||||
|
|
||||||
}
|
private static void packZip(File output, List<File> sources) throws IOException
|
||||||
|
|
||||||
private static void packZip(File output, List<File> sources) throws IOException
|
|
||||||
{
|
{
|
||||||
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output));
|
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output));
|
||||||
zipOut.setLevel(Deflater.DEFAULT_COMPRESSION);
|
zipOut.setLevel(Deflater.DEFAULT_COMPRESSION);
|
||||||
|
|
||||||
for (File source : sources) {
|
for (File source : sources) {
|
||||||
|
|
||||||
if (source.isDirectory()) {
|
if (source.isDirectory()) {
|
||||||
zipDir(zipOut, "", source);
|
zipDir(zipOut, "", source);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
zipFile(zipOut, "", source);
|
zipFile(zipOut, "", source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zipOut.flush();
|
zipOut.flush();
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
System.out.println("Backup Completed.");
|
System.out.println("Backup Completed.");
|
||||||
@ -74,7 +72,8 @@ public class ZipLibrary {
|
|||||||
private static String buildPath(String path, String file) {
|
private static String buildPath(String path, String file) {
|
||||||
if (path == null || path.isEmpty()) {
|
if (path == null || path.isEmpty()) {
|
||||||
return file;
|
return file;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return path + "/" + file;
|
return path + "/" + file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,11 +90,11 @@ public class ZipLibrary {
|
|||||||
for (File source : files) {
|
for (File source : files) {
|
||||||
if (source.isDirectory()) {
|
if (source.isDirectory()) {
|
||||||
zipDir(zos, path, source);
|
zipDir(zos, path, source);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
zipFile(zos, path, source);
|
zipFile(zos, path, source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void zipFile(ZipOutputStream zos, String path, File file) throws IOException {
|
private static void zipFile(ZipOutputStream zos, String path, File file) throws IOException {
|
||||||
@ -103,13 +102,13 @@ public class ZipLibrary {
|
|||||||
System.out.println("Cannot read " + file.getCanonicalPath() + "(File Permissions?)");
|
System.out.println("Cannot read " + file.getCanonicalPath() + "(File Permissions?)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zos.putNextEntry(new ZipEntry(buildPath(path, file.getName())));
|
zos.putNextEntry(new ZipEntry(buildPath(path, file.getName())));
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
|
||||||
byte[] buffer = new byte[4092];
|
byte[] buffer = new byte[4092];
|
||||||
int byteCount = 0;
|
int byteCount = 0;
|
||||||
|
|
||||||
while ((byteCount = fis.read(buffer)) != -1) {
|
while ((byteCount = fis.read(buffer)) != -1) {
|
||||||
zos.write(buffer, 0, byteCount);
|
zos.write(buffer, 0, byteCount);
|
||||||
}
|
}
|
||||||
@ -117,6 +116,4 @@ public class ZipLibrary {
|
|||||||
fis.close();
|
fis.close();
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user