AutoUpdater enhancments

This commit is contained in:
BuildTools 2018-05-09 13:55:32 +02:00
parent bd080c4ee4
commit eeab24d7b8
10 changed files with 158 additions and 104 deletions

View File

@ -1,5 +1,5 @@
name: WorldSystem name: WorldSystem
version: 2.0.3 version: 2.0.3.1
author: Butzlabben author: Butzlabben
main: de.butzlabben.world.WorldSystem main: de.butzlabben.world.WorldSystem

View File

@ -43,6 +43,11 @@ public class AutoUpdater implements Listener {
private AutoUpdater(JavaPlugin plugin) { private AutoUpdater(JavaPlugin plugin) {
confirmNeed = PluginConfig.confirmNeed(); confirmNeed = PluginConfig.confirmNeed();
UpdateInformations ui = UpdateInformations.getInformations(); UpdateInformations ui = UpdateInformations.getInformations();
if (ui == null) {
Bukkit.getConsoleSender().sendMessage(
PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server");
return;
}
String v = plugin.getDescription().getVersion(); String v = plugin.getDescription().getVersion();
if (!ui.getVersion().equals(plugin.getDescription().getVersion())) { if (!ui.getVersion().equals(plugin.getDescription().getVersion())) {
Bukkit.getConsoleSender().sendMessage( Bukkit.getConsoleSender().sendMessage(
@ -72,14 +77,17 @@ public class AutoUpdater implements Listener {
au = new AutoUpdate(ui, jar); au = new AutoUpdate(ui, jar);
if (!confirmNeed) { if (!confirmNeed) {
Runtime.getRuntime().addShutdownHook(new Thread(au)); Runtime.getRuntime().addShutdownHook(new Thread(au));
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes"); Bukkit.getConsoleSender()
.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
confirmed = true; confirmed = true;
} else { } else {
Bukkit.getPluginManager().registerEvents(this, plugin); Bukkit.getPluginManager().registerEvents(this, plugin);
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
p.sendMessage(PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); p.sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
} }
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); Bukkit.getConsoleSender().sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
} }
} }
} }
@ -87,7 +95,8 @@ public class AutoUpdater implements Listener {
@EventHandler @EventHandler
public void on(PlayerJoinEvent e) { public void on(PlayerJoinEvent e) {
if (e.getPlayer().hasPermission("ws.confirm")) { if (e.getPlayer().hasPermission("ws.confirm")) {
e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); e.getPlayer().sendMessage(
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
} }
} }

View File

@ -50,7 +50,6 @@ public class UpdateInformations {
in.close(); in.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
return sb.toString(); return sb.toString();

View File

@ -1,14 +1,22 @@
package de.butzlabben.event; package de.butzlabben.event;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class WorldCreateEvent extends WorldEvent { public class WorldCreateEvent extends WorldEvent {
private final Player owner; private final Player owner;
private Environment env;
private WorldType type;
private long seed;
public WorldCreateEvent(Player owner) { public WorldCreateEvent(Player owner, Environment env, WorldType type, long seed) {
this.owner = owner; this.owner = owner;
this.env = env;
this.type = type;
this.setSeed(seed);
} }
public Player getOwner() { public Player getOwner() {
@ -25,4 +33,28 @@ public class WorldCreateEvent extends WorldEvent {
public final HandlerList getHandlers() { public final HandlerList getHandlers() {
return handlers; return handlers;
} }
public WorldType getType() {
return type;
}
public void setType(WorldType type) {
this.type = type;
}
public Environment getEnv() {
return env;
}
public void setEnvironment(Environment env) {
this.env = env;
}
public long getSeed() {
return seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
} }

View File

@ -11,6 +11,7 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -59,18 +60,20 @@ public class WorldConfig {
id = Integer.parseInt(worldname.split("-")[0].substring(2)); id = Integer.parseInt(worldname.split("-")[0].substring(2));
} }
public void create() { public static void create(Player p) {
File file = new File(PluginConfig.getWorlddir() + getWorldName() + "/worldconfig.yml"); DependenceConfig dc = new DependenceConfig(p);
String worldname = dc.getWorldname();
File file = new File(PluginConfig.getWorlddir() + worldname + "/worldconfig.yml");
try { try {
file.createNewFile(); file.createNewFile();
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
System.err.println("Error while creating worldconfig for " + owner.toString()); System.err.println("Error while creating worldconfig for " + p.getUniqueId().toString());
} }
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.set("Informations.ID", id); cfg.set("Informations.ID", dc.getID());
cfg.set("Informations.Owner.PlayerUUID", owner.toString()); cfg.set("Informations.Owner.PlayerUUID", p.getUniqueId().toString());
cfg.set("Informations.Owner.Actualname", Bukkit.getOfflinePlayer(owner).getName()); cfg.set("Informations.Owner.Actualname", p.getName());
cfg.set("Settings.TNTDamage", false); cfg.set("Settings.TNTDamage", false);
cfg.set("Settings.Fire", false); cfg.set("Settings.Fire", false);
cfg.set("Members", null); cfg.set("Members", null);
@ -78,7 +81,7 @@ public class WorldConfig {
cfg.save(file); cfg.save(file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("Error while saving worldconfig for " + owner.toString()); System.err.println("Error while saving worldconfig for " + p.getUniqueId().toString());
} }
} }
@ -454,6 +457,12 @@ public class WorldConfig {
this.fire = fire; this.fire = fire;
} }
/**
* Allow or Disallow Fire Damage on this world
* @param player
* @param tnt if tnt is enabled
* @return if the player has the permissions to change the value
*/
public boolean setFire(UUID player, boolean fire) { public boolean setFire(UUID player, boolean fire) {
if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false) if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false)
return false; return false;

View File

@ -2,16 +2,10 @@ package de.butzlabben.world.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
//import java.util.List;
//import java.util.UUID;
//
//import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -40,20 +34,16 @@ public class WorldConfig2 {
} }
} }
public static UUID[] getMembersFiltered(String worldname) { public static HashMap<UUID, String> getMembersWithNames(String worldname) {
File file = getWorldFile(worldname); File file = getWorldFile(worldname);
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
if (cfg.getConfigurationSection("Members") == null) if (cfg.getConfigurationSection("Members") == null)
return null; return null;
Set<String> players = cfg.getConfigurationSection("Members").getKeys(false); HashMap<UUID, String> map = new HashMap<>();
Set<UUID> set = players.stream().map(new Function<String, UUID>() { for (String s : cfg.getConfigurationSection("Members").getKeys(false)) {
@Override map.put(UUID.fromString(s), cfg.getString("Members." + s + ".Actualname"));
public UUID apply(String t) {
return UUID.fromString(t);
} }
}).filter(uuid -> Bukkit.getOfflinePlayer(uuid) != null && Bukkit.getOfflinePlayer(uuid).getName() != null) return map;
.collect(Collectors.toSet());
return set.toArray(new UUID[] {});
} }
public static UUID[] getMembers(String worldname) { public static UUID[] getMembers(String worldname) {

View File

@ -1,6 +1,7 @@
package de.butzlabben.world.gui; package de.butzlabben.world.gui;
import java.util.Arrays; import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,10 +29,10 @@ public class PlayersGUIManager {
String worldname = p.getWorld().getName(); String worldname = p.getWorld().getName();
SystemWorld sw = SystemWorld.getSystemWorld(worldname); SystemWorld sw = SystemWorld.getSystemWorld(worldname);
if (sw != null) { if (sw != null) {
UUID[] members = WorldConfig2.getMembersFiltered(worldname); HashMap<UUID, String> members = WorldConfig2.getMembersWithNames(worldname);
if (members == null || members.length == 0) if (members == null || members.size() == 0)
return null; return null;
int pages = Math.round(members.length / headsPerInv) < 1 ? 1 : Math.round(members.length / headsPerInv); int pages = Math.round(members.size() / headsPerInv) < 1 ? 1 : Math.round(members.size() / headsPerInv);
if (page > pages) if (page > pages)
return null; return null;
return getPage(p, page, pages); return getPage(p, page, pages);
@ -43,15 +44,20 @@ public class PlayersGUIManager {
String worldname = p.getWorld().getName(); String worldname = p.getWorld().getName();
SystemWorld sw = SystemWorld.getSystemWorld(worldname); SystemWorld sw = SystemWorld.getSystemWorld(worldname);
if (sw != null) { if (sw != null) {
UUID[] members = WorldConfig2.getMembersFiltered(worldname); HashMap<UUID, String> members = WorldConfig2.getMembersWithNames(worldname);
if (members == null || members.length == 0) if (members == null || members.size() == 0)
return null; return null;
UUID[] uuids = new UUID[headsPerInv + 1];
int startPos = pages == 1 ? 0 : headsPerInv * (page - 1); int startPos = pages == 1 ? 0 : headsPerInv * (page - 1);
int length = pages == 1 ? members.length : headsPerInv; int length = pages == 1 ? members.size() : headsPerInv;
uuids = Arrays.copyOfRange(members, startPos, startPos + length); ArrayList<UUID> list = new ArrayList<>(members.keySet());
HashMap<UUID, String> uuids = new HashMap<>();
for (int i = startPos; i < startPos + length; i++) {
uuids.put(list.get(i), members.get(list.get(i)));
}
int pageBefore = page == 1 ? pages : page - 1; int pageBefore = page == 1 ? pages : page - 1;
int nextPage = pages == page ? 1 : page + 1; int nextPage = pages == page ? 1 : page + 1;

View File

@ -4,9 +4,7 @@ import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -28,7 +26,7 @@ public class PlayersPageGUI extends OrcInventory {
private final static String path = "options.players."; private final static String path = "options.players.";
private static HashMap<UUID, Pair<Integer, Integer>> pages = new HashMap<>(); private static HashMap<UUID, Pair<Integer, Integer>> pages = new HashMap<>();
public PlayersPageGUI(int page, UUID ex, UUID[] players, int next, int before) { public PlayersPageGUI(int page, UUID ex, HashMap<UUID, String> players, int next, int before) {
super("Players added to this world", GuiConfig.getRows("options.players"), false); super("Players added to this world", GuiConfig.getRows("options.players"), false);
pages.put(ex, Pair.of(next, before)); pages.put(ex, Pair.of(next, before));
@ -80,24 +78,24 @@ public class PlayersPageGUI extends OrcInventory {
// Spieler reinladen // Spieler reinladen
int i = 0; int i = 0;
for (UUID uuid : players) { for (UUID uuid : players.keySet()) {
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); String name = players.get(uuid);
if (op != null && op.getName() != null) {
ItemStack is = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); ItemStack is = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta sm = (SkullMeta) is.getItemMeta(); SkullMeta sm = (SkullMeta) is.getItemMeta();
sm.setOwner(op.getName()); sm.setOwner(name);
sm.setDisplayName(GuiConfig.getDisplay(cfg, PlayersPageGUI.path + "playerhead").replaceAll("%player", op.getName())); sm.setDisplayName(
GuiConfig.getDisplay(cfg, PlayersPageGUI.path + "playerhead").replaceAll("%player", name));
is.setItemMeta(sm); is.setItemMeta(sm);
OrcItem item = new OrcItem(is); OrcItem item = new OrcItem(is);
item.setOnClick((p, inv, orcitem) -> { item.setOnClick((p, inv, orcitem) -> {
p.closeInventory(); p.closeInventory();
PlayerOptionsGUI.data.put(ex, op.getName()); PlayerOptionsGUI.data.put(ex, name);
pages.remove(p.getUniqueId()); pages.remove(p.getUniqueId());
p.openInventory(PlayerOptionsGUI.instance.getInventory(p)); p.openInventory(PlayerOptionsGUI.instance.getInventory(p));
}); });
addItem(i, item); addItem(i, item);
i++; i++;
}
} }
} }

View File

@ -3,15 +3,15 @@ package de.butzlabben.world.wrapper;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import de.butzlabben.event.WorldCreateEvent; import de.butzlabben.event.WorldCreateEvent;
@ -42,7 +42,8 @@ public class SystemWorld {
* *
* @param worldname * @param worldname
* as in minecraft * as in minecraft
* @return a systemworld instance if it is a systemworld or null if is not a systemworld * @return a systemworld instance if it is a systemworld or null if is not a
* systemworld
* @exception NullPointerException * @exception NullPointerException
* worldname == null * worldname == null
*/ */
@ -59,8 +60,8 @@ public class SystemWorld {
} }
/** /**
* @param w a * @param w
* world in bukkit, no matter if systemworld or not Trys to * a world in bukkit, no matter if systemworld or not Trys to
* unload a systemworld later, with the given delay in the config * unload a systemworld later, with the given delay in the config
*/ */
public static void tryUnloadLater(World w) { public static void tryUnloadLater(World w) {
@ -118,8 +119,8 @@ public class SystemWorld {
/** /**
* Trys to unload this world later, with the given delay in the config * Trys to unload this world later, with the given delay in the config
* *
* @param w the * @param w
* associated world * the associated world
* @exception NullPointerException * @exception NullPointerException
* w == null * w == null
*/ */
@ -164,9 +165,12 @@ public class SystemWorld {
/** /**
* Trys to load this world, and messages the player about the process * Trys to load this world, and messages the player about the process
* *
* @param p the player to teleport on the world * @param p
* @exception NullPointerException if p is null * the player to teleport on the world
* @exception IllegalArgumentException if player is not online * @exception NullPointerException
* if p is null
* @exception IllegalArgumentException
* if player is not online
*/ */
public void load(Player p) { public void load(Player p) {
Preconditions.checkNotNull(p, "player must not be null"); Preconditions.checkNotNull(p, "player must not be null");
@ -225,14 +229,19 @@ public class SystemWorld {
} }
/** /**
* Trys to create a new systemworld with all entries etc. * Trys to create a new systemworld with all entries etc. finally loads the
* finally loads the world * world
* @param p Player to create the world for *
* @param p
* Player to create the world for
* @return whether it succesfull or not * @return whether it succesfull or not
*/ */
public static boolean create(Player p) { public static boolean create(Player p) {
DependenceConfig dc = new DependenceConfig(p); DependenceConfig dc = new DependenceConfig(p);
WorldCreateEvent event = new WorldCreateEvent(p); long seed = PluginConfig.getSeed();
Environment env = PluginConfig.getEnvironment();
WorldType type = PluginConfig.getWorldType();
WorldCreateEvent event = new WorldCreateEvent(p, env, type, seed);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) if (event.isCancelled())
return false; return false;
@ -284,20 +293,18 @@ public class SystemWorld {
} }
} }
WorldCreator wc = new WorldCreator(worldname); WorldCreator wc = new WorldCreator(worldname);
System.out.println(PluginConfig.getEnvironment().name()); wc.environment(event.getEnv());
wc.environment(PluginConfig.getEnvironment()); wc.type(event.getType());
System.out.println(PluginConfig.getWorldType().name()); if (event.getSeed() != 0)
wc.type(PluginConfig.getWorldType()); wc.seed(event.getSeed());
long seed = PluginConfig.getSeed();
if(seed != 0)
wc.seed(seed);
World worldinserver = Bukkit.createWorld(wc); World worldinserver = Bukkit.createWorld(wc);
Bukkit.getServer().getWorlds().add(worldinserver); Bukkit.getServer().getWorlds().add(worldinserver);
} }
return true; return true;
} }
/** /**
* @return if the world is loaded * @return if the world is loaded
*/ */
@ -323,9 +330,13 @@ public class SystemWorld {
/** /**
* Teleports the player to the world with the given settings in the config * Teleports the player to the world with the given settings in the config
* @param p player to teleport *
* @exception NullPointerException if player is null * @param p
* @exception IllegalArgumentException if player is not online * player to teleport
* @exception NullPointerException
* if player is null
* @exception IllegalArgumentException
* if player is not online
*/ */
public void teleportToWorldSpawn(Player p) { public void teleportToWorldSpawn(Player p) {
Preconditions.checkNotNull(p, "player must not be null"); Preconditions.checkNotNull(p, "player must not be null");

View File

@ -1,5 +1,5 @@
name: WorldSystem name: WorldSystem
version: 2.0.3 version: 2.0.3.1
author: Butzlabben author: Butzlabben
main: de.butzlabben.world.WorldSystem main: de.butzlabben.world.WorldSystem