Skip to content

Commit

Permalink
[U] 1.2.0-dev11
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayCoffee committed Jun 25, 2020
1 parent b05ff10 commit a4aa66f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 20 deletions.
34 changes: 21 additions & 13 deletions src/main/java/club/claycoffee/ClayTech/ClayTech.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
//import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -294,6 +294,14 @@ public void run() {
updater = new ClayTechUpdater();
if (!getConfig().getBoolean("disable-auto-updater")) {
updater.tryUpdate();
new BukkitRunnable() {

@Override
public void run() {
updater.tryUpdate();
}

}.runTaskTimerAsynchronously(ClayTech.getInstance(), 72000, 7200);
} else {
Bukkit.getLogger().info(ChatColor.YELLOW + Lang.readGeneralText("Info_1"));
Bukkit.getLogger().info(ChatColor.YELLOW + Lang.readGeneralText("Auto-updater_disabled"));
Expand Down Expand Up @@ -540,17 +548,17 @@ private void registerResources() {
new ClayFuel();
}

// @Override
// public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
// List<String> PlanetNameList = new ArrayList<String>();
// List<Planet> PlanetList = getPlanets();
// for (Planet p : PlanetList) {
// PlanetNameList.add(p.getPlanetWorldName());
// }
// if (Utils.ExitsInList(id, PlanetNameList.toArray(new String[PlanetNameList.size()]))) {
// return PlanetList.get(PlanetNameList.indexOf(id)).getPlanetGenerator();
// }
// return Bukkit.getWorld(getOverworld()).getGenerator();
// }
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
List<String> PlanetNameList = new ArrayList<String>();
List<Planet> PlanetList = getPlanets();
for (Planet p : PlanetList) {
PlanetNameList.add(p.getPlanetWorldName());
}
if (Utils.ExitsInList(id, PlanetNameList.toArray(new String[PlanetNameList.size()]))) {
return PlanetList.get(PlanetNameList.indexOf(id)).getPlanetGenerator();
}
return Bukkit.getWorld(getOverworld()).getGenerator();
}

}
3 changes: 2 additions & 1 deletion src/main/java/club/claycoffee/ClayTech/api/Planet.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ public void register() {
}
}
ClayTech.getPlanets().add(this);

WorldCreator newWorld = new WorldCreator(this.planetName);
if (Bukkit.getWorld(this.planetName) == null) {
newWorld.environment(this.environment);
long seed = new Random().nextLong();
newWorld = newWorld.seed(seed);
newWorld = newWorld.type(WorldType.CUSTOMIZED);
newWorld = newWorld.generateStructures(false);
newWorld = newWorld.generator(this.planetWorld);
newWorld = newWorld.generator("ClayTech:"+this.planetName);
World w = newWorld.createWorld();
if (this.cold) {
// 如果冷就不会下雨
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package club.claycoffee.ClayTech.listeners;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -51,8 +55,34 @@ public void InventoryMoveItemEvent(InventoryClickEvent e) {
currentPage = new Integer(Utils.getMetadata(b, "currentPage")).intValue();
}
int index = (currentPage - 1) * 21 + (e.getSlot() - 18) - 1;
Planet target = ClayTech.getPlanets().get(index);
Planet current = PlanetUtils.getPlanet(b.getWorld());
// 排列星球
List<Planet> pl = new ArrayList<Planet>();
for(Planet p1 : ClayTech.getPlanets()) {
pl.add(p1);
}
Planet[] pl2 = pl.toArray(new Planet[pl.size()]);
List<Integer> d = new ArrayList<Integer>();
for(Planet p1 : pl2) {
d.add((Integer) PlanetUtils.getDistance(current, p1));
}
Integer[] distance = d.toArray(new Integer[d.size()]);
for (int i = 0; i < distance.length; i++) {
for (int j = 0; j < distance.length - i - 1; j++) {
if (distance[j].intValue() > distance[j + 1].intValue()) {
int temp = distance[j + 1];
distance[j + 1] = distance[j];
distance[j] = temp;

Planet temp2 = pl2[j + 1];
pl2[j + 1] = pl2[j];
pl2[j] = temp2;
}
}
}
pl = Arrays.asList(pl2);

Planet target = pl.get(index);
if (!target.getPlanetWorldName().equalsIgnoreCase(current.getPlanetWorldName())) {
if (PlanetUtils.getFuel(current, target) <= RocketUtils.getFuel(handItem)) {
if (handItem.getAmount() == 1) {
Expand Down
39 changes: 34 additions & 5 deletions src/main/java/club/claycoffee/ClayTech/utils/PlanetUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package club.claycoffee.ClayTech.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -103,13 +105,40 @@ public static int getTotalPage() {
}

public static Inventory renderLauncherMenu(Planet current, Inventory Preset, int currentPage) {
int i = 0;
int v = 0;
int c = 0;
List<Planet> pl = ClayTech.getPlanets();
for (Planet each : pl) {

// 排列星球
List<Planet> pl = new ArrayList<Planet>();
for(Planet p : ClayTech.getPlanets()) {
pl.add(p);
}
Planet[] pl2 = pl.toArray(new Planet[pl.size()]);
List<Integer> d = new ArrayList<Integer>();
for(Planet p : pl2) {
d.add((Integer) PlanetUtils.getDistance(current, p));
}
Integer[] distance = d.toArray(new Integer[d.size()]);
for (int i = 0; i < distance.length; i++) {
for (int j = 0; j < distance.length - i - 1; j++) {
if (distance[j].intValue() > distance[j + 1].intValue()) {
int temp = distance[j + 1];
distance[j + 1] = distance[j];
distance[j] = temp;

Planet temp2 = pl2[j + 1];
pl2[j + 1] = pl2[j];
pl2[j] = temp2;
}
}
}
pl = Arrays.asList(pl2);


for (Planet each : pl) {
c++;
if (c > (currentPage - 1) * 21 && c <= currentPage * 21) {
i++;
v++;
ItemStack di = each.getDisplayStack();
di = Utils.setLoreList(di, new String[] {
Lang.readMachinesText("DISTANCE_TO_PLANET").replaceAll("%ly%",
Expand All @@ -121,7 +150,7 @@ public static Inventory renderLauncherMenu(Planet current, Inventory Preset, int
Lang.readMachinesText("PLANET_GRAVITY").replaceAll("%gravity%", "1/" + each.getGravity()),
Lang.readMachinesText("PLANET_HARM_LEVEL").replaceAll("%harm_level%",
each.getHarmLevel() + "") });
Preset.setItem(planet[i - 1], di);
Preset.setItem(planet[v - 1], di);
} else if (c > currentPage * 21) {
break;
}
Expand Down

0 comments on commit a4aa66f

Please sign in to comment.