Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.1-R12 - Improvements for Update Messages -w-
- Loading branch information
Showing
11 changed files
with
129 additions
and
106 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
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
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
102 changes: 102 additions & 0 deletions
102
src/main/java/me/croabeast/sircore/utilities/DoUpdate.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,102 @@ | ||
package me.croabeast.sircore.utilities; | ||
|
||
import com.google.common.collect.*; | ||
import me.croabeast.sircore.*; | ||
import me.croabeast.sircore.objects.*; | ||
import org.bukkit.entity.*; | ||
|
||
import java.util.*; | ||
|
||
public class DoUpdate { | ||
|
||
private final Application main; | ||
private final Records records; | ||
private final TextUtils text; | ||
|
||
public DoUpdate(Application main) { | ||
this.main = main; | ||
this.records = main.getRecords(); | ||
this.text = main.getTextUtils(); | ||
} | ||
|
||
private void updateLogger(Player player, String... lines) { | ||
List<String> list = Lists.newArrayList(lines); | ||
|
||
if (player != null) { | ||
if (list.get(0).equals("RR")) list.remove(0); | ||
list.forEach(s -> | ||
records.playerRecord(player, " " + s) | ||
); | ||
} | ||
else { | ||
if (list.get(0).equals("RR")) { | ||
list.remove(0); | ||
list.forEach(records::rawRecord); | ||
} | ||
else list.forEach(records::doRecord); | ||
} | ||
} | ||
|
||
private void runUpdater(Player player) { | ||
Updater.init(main, 96378).updateCheck().whenComplete((result, e) -> { | ||
String latest = result.getNewestVersion(); | ||
|
||
updateLogger(player, "RR", ""); | ||
switch (result.getReason()) { | ||
case NEW_UPDATE: | ||
updateLogger(player, | ||
"&4NEW UPDATE!", | ||
"&cYou don't have the latest version of S.I.R. installed.", | ||
"&cRemember, older versions won't receive any support.", | ||
"&7New Version: &a" + latest + | ||
"&7 - Your Version: &e" + main.PLUGIN_VERSION, | ||
"&7Link:&b https://www.spigotmc.org/resources/96378/" | ||
); | ||
break; | ||
|
||
case UP_TO_DATE: | ||
updateLogger(player, | ||
"&eYou have the latest version of S.I.R. &7(" + latest + ")", | ||
"&7I would appreciate if you keep updating &c<3" | ||
); | ||
break; | ||
|
||
case UNRELEASED_VERSION: | ||
updateLogger(player, | ||
"&4DEVELOPMENT BUILD:", | ||
"&cYou have a newer version of S.I.R. installed.", | ||
"&cErrors might occur in this build.", | ||
"Spigot Version: &a" + result.getSpigotVersion() | ||
+ "&7 - Your Version: &e" + main.PLUGIN_VERSION | ||
); | ||
break; | ||
|
||
default: | ||
updateLogger(player, | ||
"&4WARNING!", | ||
"&cCould not check for a new version of S.I.R.", | ||
"&7Please check your connection and restart the server.", | ||
"&7Possible reason: &e" + result.getReason() | ||
); | ||
break; | ||
} | ||
|
||
updateLogger(player, "RR", ""); | ||
}); | ||
} | ||
|
||
public void initUpdater(Player player) { | ||
if (player == null) { | ||
if (!text.getOption(4, "on-start")) | ||
return; | ||
runUpdater(null); | ||
} | ||
else { | ||
boolean perm = main.getEventUtils(). | ||
hasPerm(player, "sir.admin.updater"); | ||
if (!text.getOption(4, "send-op") || !perm) | ||
return; | ||
runUpdater(player); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
######################## | ||
# SIR by CroaBeast # | ||
# Depressed since 2004 # | ||
######################## | ||
# Want to use unicode characters? Check this site: https://coolsymbol.com | ||
|