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
version: 2.0.3
version: 2.0.3.1
author: Butzlabben
main: de.butzlabben.world.WorldSystem

View File

@ -43,6 +43,11 @@ public class AutoUpdater implements Listener {
private AutoUpdater(JavaPlugin plugin) {
confirmNeed = PluginConfig.confirmNeed();
UpdateInformations ui = UpdateInformations.getInformations();
if (ui == null) {
Bukkit.getConsoleSender().sendMessage(
PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server");
return;
}
String v = plugin.getDescription().getVersion();
if (!ui.getVersion().equals(plugin.getDescription().getVersion())) {
Bukkit.getConsoleSender().sendMessage(
@ -72,14 +77,17 @@ public class AutoUpdater implements Listener {
au = new AutoUpdate(ui, jar);
if (!confirmNeed) {
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;
} else {
Bukkit.getPluginManager().registerEvents(this, plugin);
for(Player p : Bukkit.getOnlinePlayers()) {
p.sendMessage(PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
for (Player p : Bukkit.getOnlinePlayers()) {
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
public void on(PlayerJoinEvent e) {
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();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();

View File

@ -1,28 +1,60 @@
package de.butzlabben.event;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class WorldCreateEvent extends WorldEvent {
private final Player owner;
public WorldCreateEvent(Player owner) {
private Environment env;
private WorldType type;
private long seed;
public WorldCreateEvent(Player owner, Environment env, WorldType type, long seed) {
this.owner = owner;
this.env = env;
this.type = type;
this.setSeed(seed);
}
public Player getOwner() {
return owner;
}
public final static HandlerList handlers = new HandlerList();
public final static HandlerList getHandlerList() {
return handlers;
}
@Override
public final HandlerList getHandlers() {
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.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.google.common.collect.Sets;
@ -59,18 +60,20 @@ public class WorldConfig {
id = Integer.parseInt(worldname.split("-")[0].substring(2));
}
public void create() {
File file = new File(PluginConfig.getWorlddir() + getWorldName() + "/worldconfig.yml");
public static void create(Player p) {
DependenceConfig dc = new DependenceConfig(p);
String worldname = dc.getWorldname();
File file = new File(PluginConfig.getWorlddir() + worldname + "/worldconfig.yml");
try {
file.createNewFile();
} catch (IOException e1) {
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);
cfg.set("Informations.ID", id);
cfg.set("Informations.Owner.PlayerUUID", owner.toString());
cfg.set("Informations.Owner.Actualname", Bukkit.getOfflinePlayer(owner).getName());
cfg.set("Informations.ID", dc.getID());
cfg.set("Informations.Owner.PlayerUUID", p.getUniqueId().toString());
cfg.set("Informations.Owner.Actualname", p.getName());
cfg.set("Settings.TNTDamage", false);
cfg.set("Settings.Fire", false);
cfg.set("Members", null);
@ -78,7 +81,7 @@ public class WorldConfig {
cfg.save(file);
} catch (IOException e) {
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;
}
/**
* 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) {
if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false)
return false;

View File

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

View File

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

View File

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

View File

@ -3,15 +3,15 @@ package de.butzlabben.world.wrapper;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.Player;
import com.google.common.base.Preconditions;
import de.butzlabben.event.WorldCreateEvent;
@ -34,7 +34,7 @@ public class SystemWorld {
private World w;
private String worldname;
private boolean unloading = false;
private static HashMap<String, SystemWorld> cached = new HashMap<>();
/**
@ -42,16 +42,17 @@ public class SystemWorld {
*
* @param worldname
* 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
* worldname == null
*/
public static SystemWorld getSystemWorld(String worldname) {
Preconditions.checkNotNull(worldname, "worldname must not be null");
if(cached.containsKey(worldname))
if (cached.containsKey(worldname))
return cached.get(worldname);
SystemWorld sw = new SystemWorld(worldname);
if(sw != null && sw.exists()) {
if (sw != null && sw.exists()) {
cached.put(worldname, sw);
return sw;
}
@ -59,8 +60,8 @@ public class SystemWorld {
}
/**
* @param w a
* world in bukkit, no matter if systemworld or not Trys to
* @param w
* a world in bukkit, no matter if systemworld or not Trys to
* unload a systemworld later, with the given delay in the config
*/
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
*
* @param w the
* associated world
* @param w
* the associated world
* @exception NullPointerException
* w == null
*/
@ -164,9 +165,12 @@ public class SystemWorld {
/**
* Trys to load this world, and messages the player about the process
*
* @param p the player to teleport on the world
* @exception NullPointerException if p is null
* @exception IllegalArgumentException if player is not online
* @param p
* the player to teleport on the world
* @exception NullPointerException
* if p is null
* @exception IllegalArgumentException
* if player is not online
*/
public void load(Player p) {
Preconditions.checkNotNull(p, "player must not be null");
@ -208,7 +212,7 @@ public class SystemWorld {
worldname = myName.toString();
}
// Teleport the Player
World worldinserver = Bukkit.createWorld(new WorldCreator(worldname));
Bukkit.getServer().getWorlds().add(worldinserver);
w = worldinserver;
@ -225,14 +229,19 @@ public class SystemWorld {
}
/**
* Trys to create a new systemworld with all entries etc.
* finally loads the world
* @param p Player to create the world for
* @return whether it succesfull or not
* Trys to create a new systemworld with all entries etc. finally loads the
* world
*
* @param p
* Player to create the world for
* @return whether it succesfull or not
*/
public static boolean create(Player 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);
if (event.isCancelled())
return false;
@ -284,22 +293,20 @@ public class SystemWorld {
}
}
WorldCreator wc = new WorldCreator(worldname);
System.out.println(PluginConfig.getEnvironment().name());
wc.environment(PluginConfig.getEnvironment());
System.out.println(PluginConfig.getWorldType().name());
wc.type(PluginConfig.getWorldType());
long seed = PluginConfig.getSeed();
if(seed != 0)
wc.seed(seed);
wc.environment(event.getEnv());
wc.type(event.getType());
if (event.getSeed() != 0)
wc.seed(event.getSeed());
World worldinserver = Bukkit.createWorld(wc);
Bukkit.getServer().getWorlds().add(worldinserver);
}
return true;
}
/**
*@return if the world is loaded
* @return if the world is loaded
*/
public boolean isLoaded() {
File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml");
@ -323,9 +330,13 @@ public class SystemWorld {
/**
* Teleports the player to the world with the given settings in the config
* @param p player to teleport
* @exception NullPointerException if player is null
* @exception IllegalArgumentException if player is not online
*
* @param p
* player to teleport
* @exception NullPointerException
* if player is null
* @exception IllegalArgumentException
* if player is not online
*/
public void teleportToWorldSpawn(Player p) {
Preconditions.checkNotNull(p, "player must not be null");

View File

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