Skip to content

Commit

Permalink
Updated to Minecraft 1.12, and Java 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed May 18, 2017
1 parent 5d4923e commit 87c0fb3
Show file tree
Hide file tree
Showing 144 changed files with 647 additions and 992 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<version>1.12-pre2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
Expand Down Expand Up @@ -175,8 +175,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/me4502/util/GenerateConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public void generate(String[] args) {
e.printStackTrace();
}

List<String> mechs = new ArrayList<String>();

mechs.addAll(CraftBookPlugin.availableMechanics.keySet());
List<String> mechs = new ArrayList<>(CraftBookPlugin.availableMechanics.keySet());

Collections.sort(mechs);

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/me4502/util/GenerateWikiICList.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public void generate(String[] args) {
writer.println("<strong style=\"color: red\">*</strong>Requires the permission '''craftbook.ic.restricted.*''' or the respective '''craftbook.ic.mc''XXXX''''' permission.");

writer.close();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SecurityException | IOException e) {
e.printStackTrace();
}
}
Expand Down
105 changes: 49 additions & 56 deletions src/main/java/com/me4502/util/GenerateWikiICPages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Map;
import java.util.Set;

import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void generate(String[] args) {
try {

boolean upload = false;
final List<String> toUpload = new ArrayList<String>();
final List<String> toUpload = new ArrayList<>();

for(String arg : args) {

Expand Down Expand Up @@ -76,7 +75,7 @@ else if(upload)

int missingComments = 0;

final Set<String> missingDocuments = new HashSet<String>();
final Set<String> missingDocuments = new HashSet<>();

for(RegisteredICFactory ric : ICManager.inst().getICList()) {

Expand Down Expand Up @@ -208,73 +207,67 @@ else if(upload)

if(upload) {

Bukkit.getScheduler().runTaskAsynchronously(CraftBookPlugin.inst(), new Runnable() {

@Override
public void run () {
Bukkit.getLogger().info("Starting Upload");
Wiki wiki = new Wiki("wiki.sk89q.com");
wiki.setMaxLag(0);
wiki.setThrottle(5000);
wiki.setResolveRedirects(true);

try {
Bukkit.getLogger().info("Logging In");
wiki.login(username, password);
Bukkit.getLogger().info("Logged in Successfully!");

int amount = 0;
String failed = "";

for(RegisteredICFactory ric : ICManager.inst().getICList()) {
if(toUpload.contains("ALL") || toUpload.contains(ric.getId())) {

if(missingDocuments.contains(ric.getId())) {
if(failed.length() == 0)
failed = ric.getId();
else
failed = failed + "," + ric.getId();
continue; //Ignore this, bad docs.
}
Bukkit.getScheduler().runTaskAsynchronously(CraftBookPlugin.inst(), () -> {
Bukkit.getLogger().info("Starting Upload");
Wiki wiki = new Wiki("wiki.sk89q.com");
wiki.setMaxLag(0);
wiki.setThrottle(5000);
wiki.setResolveRedirects(true);

try {
Bukkit.getLogger().info("Logging In");
wiki.login(username, password);
Bukkit.getLogger().info("Logged in Successfully!");

int amount = 0;
String failed = "";

for(RegisteredICFactory ric : ICManager.inst().getICList()) {
if(toUpload.contains("ALL") || toUpload.contains(ric.getId())) {

if(missingDocuments.contains(ric.getId())) {
if(failed.length() == 0)
failed = ric.getId();
else
failed = failed + "," + ric.getId();
continue; //Ignore this, bad docs.
}

Bukkit.getLogger().info("Uploading " + ric.getId() + "...");
Bukkit.getLogger().info("Uploading " + ric.getId() + "...");

StringBuilder builder = new StringBuilder();
StringBuilder builder = new StringBuilder();

BufferedReader reader = new BufferedReader(new FileReader(new File(file, ric.getId() + ".txt")));
BufferedReader reader = new BufferedReader(new FileReader(new File(file, ric.getId() + ".txt")));

String line = null;
String line = null;

while((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
while((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}

reader.close();
reader.close();

wiki.edit("CraftBook/" + ric.getId(), builder.toString(), "Automated update of '" + ric.getId() + "' by " + username);
wiki.edit("CraftBook/" + ric.getId(), builder.toString(), "Automated update of '" + ric.getId() + "' by " + username);

Bukkit.getLogger().info("Uploaded: " + ric.getId());
Bukkit.getLogger().info("Uploaded: " + ric.getId());

amount++;
}
amount++;
}

Bukkit.getLogger().info("Finished uploading! Uploaded " + amount + " IC Pages!");
if(failed.length() > 0)
Bukkit.getLogger().warning("Failed to upload ICs: " + failed);
} catch (LoginException e) {
e.printStackTrace();
Bukkit.getLogger().warning("Failed to login to wiki!");
} catch (IOException e) {
e.printStackTrace();
}

Bukkit.getLogger().info("Finished uploading! Uploaded " + amount + " IC Pages!");
if(failed.length() > 0)
Bukkit.getLogger().warning("Failed to upload ICs: " + failed);
} catch (LoginException e) {
e.printStackTrace();
Bukkit.getLogger().warning("Failed to login to wiki!");
} catch (IOException e) {
e.printStackTrace();
}
});
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SecurityException | IOException e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
Expand Down Expand Up @@ -86,7 +85,7 @@ public void load() {
config.setComment("enabled-mechanics", "List of mechanics to enable! If they aren't in this list, the server won't load them!");
enabledMechanics = config.getStringList("enabled-mechanics", Collections.singletonList("Variables"));

List<String> disabledMechanics = new ArrayList<String>();
List<String> disabledMechanics = new ArrayList<>();

for(String mech : CraftBookPlugin.availableMechanics.keySet()) {
if(!enabledMechanics.contains(mech))
Expand Down Expand Up @@ -139,7 +138,7 @@ public void load() {
debugLogToFile = config.getBoolean("debug-mode-file-logging", false);

config.setComment("debug-flags", "Enable certain debug types when debug mode is enabled.");
debugFlags = config.getStringList("debug-flags", new ArrayList<String>());
debugFlags = config.getStringList("debug-flags", new ArrayList<>());

config.setComment("easter-eggs", "Enables random easter eggs. Can be from console messages on startup for a special occasion, to funny little effects with IC's and other mechanics (Always harmless, won't mess anything up)");
easterEggs = config.getBoolean("easter-eggs", true);
Expand All @@ -163,7 +162,7 @@ public void save() {

config.setProperty("enabled-mechanics", enabledMechanics);

List<String> disabledMechanics = new ArrayList<String>();
List<String> disabledMechanics = new ArrayList<>();

for(String mech : CraftBookPlugin.availableMechanics.keySet()) {
if(!enabledMechanics.contains(mech))
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/com/sk89q/craftbook/bukkit/CraftBookPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class CraftBookPlugin extends JavaPlugin {
public boolean useLegacyCartSystem = false;

static {
availableMechanics = new TreeMap<String, Class<? extends CraftBookMechanic>>();
availableMechanics = new TreeMap<>();

availableMechanics.put("Variables", VariableManager.class);
availableMechanics.put("CommandItems", CommandItems.class);
Expand Down Expand Up @@ -390,12 +390,8 @@ public void playerJoin(PlayerJoinEvent event) {
}

if(!foundAMech) {
Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
@Override
public void run () {
getLogger().warning(ChatColor.RED + "Warning! You have no mechanics enabled, the plugin will appear to do nothing until a feature is enabled!");
}
}, 20L, 20*60*5);
Bukkit.getScheduler().runTaskTimer(this,
() -> getLogger().warning(ChatColor.RED + "Warning! You have no mechanics enabled, the plugin will appear to do nothing until a feature is enabled!"), 20L, 20*60*5);
}
}

Expand All @@ -419,15 +415,9 @@ public void setupCraftBook() {
languageManager = new LanguageManager();
languageManager.init();

getServer().getScheduler().runTask(this, new Runnable() {

@Override
public void run () {
CompatabilityUtil.init();
}
});
getServer().getScheduler().runTask(this, CompatabilityUtil::init);

mechanics = new ArrayList<CraftBookMechanic>();
mechanics = new ArrayList<>();

logDebugMessage("Initializing Mechanisms!", "startup");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
*/
final class MechanicListenerAdapter implements Listener {

private Set<String> signClickTimer = new HashSet<String>();
private Set<String> signClickTimer = new HashSet<>();

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(final PlayerInteractEvent event) {
Expand Down Expand Up @@ -99,12 +99,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
return;
} else {
signClickTimer.add(event.getPlayer().getName());
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), new Runnable() {
@Override
public void run () {
signClickTimer.remove(event.getPlayer().getName());
}
}, CraftBookPlugin.inst().getConfiguration().signClickTimeout);
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> signClickTimer.remove(event.getPlayer().getName()), CraftBookPlugin.inst().getConfiguration().signClickTimeout);
}
}
SignClickEvent ev = new SignClickEvent(event.getPlayer(), action, event.getItem(), block, event.getBlockFace());
Expand Down Expand Up @@ -344,16 +339,12 @@ private static void handleDirectWireInput(WorldVector pt, Block sourceBlock, int
CraftBookPlugin.inst().getServer().getPluginManager().callEvent(event);

if(CraftBookPlugin.inst().useLegacyCartSystem) {
CraftBookPlugin.server().getScheduler().runTask(CraftBookPlugin.inst(), new Runnable() {

@Override
public void run() {
try {
CartMechanismBlocks cmb = CartMechanismBlocks.find(event.getBlock());
CartBlockRedstoneEvent ev = new CartBlockRedstoneEvent(event.getBlock(), event.getSource(), event.getOldCurrent(), event.getNewCurrent(), cmb, CartBlockMechanism.getCart(cmb.rail));
CraftBookPlugin.inst().getServer().getPluginManager().callEvent(ev);
} catch (InvalidMechanismException ignored) {
}
CraftBookPlugin.server().getScheduler().runTask(CraftBookPlugin.inst(), () -> {
try {
CartMechanismBlocks cmb = CartMechanismBlocks.find(event.getBlock());
CartBlockRedstoneEvent ev = new CartBlockRedstoneEvent(event.getBlock(), event.getSource(), event.getOldCurrent(), event.getNewCurrent(), cmb, CartBlockMechanism.getCart(cmb.rail));
CraftBookPlugin.inst().getServer().getPluginManager().callEvent(ev);
} catch (InvalidMechanismException ignored) {
}
});
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/com/sk89q/craftbook/bukkit/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ public boolean isOptOut() {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
return true;
} catch (InvalidConfigurationException ex) {
} catch (IOException | InvalidConfigurationException ex) {
if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
}
Expand Down Expand Up @@ -620,7 +615,7 @@ public static class Graph {
/**
* The set of plotters that are contained within this graph
*/
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
private final Set<Plotter> plotters = new LinkedHashSet<>();

private Graph(final String name) {
this.name = name;
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/sk89q/craftbook/bukkit/util/BukkitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,10 @@ public static Sign toSign(ChangedSign sign) {
}
}

private static final Map<String, LocalWorld> wlw = new HashMap<String, LocalWorld>();
private static final Map<String, LocalWorld> wlw = new HashMap<>();

public static LocalWorld getLocalWorld(World w) {

LocalWorld lw = wlw.get(w.getName());
if (lw == null) {
lw = new BukkitWorld(w);
wlw.put(w.getName(), lw);
}
return lw;
return wlw.computeIfAbsent(w.getName(), k -> new BukkitWorld(w));
}

public static Vector toVector(Block block) {
Expand Down
Loading

1 comment on commit 87c0fb3

@parlough
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always a fun update to do 🥂

Please sign in to comment.