diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockPlayer.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockPlayer.java deleted file mode 100644 index c04ae20a..00000000 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockPlayer.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Bedrock - * - * Copyright (c) 2017 Cube-Nation (Benedikt Hruschka, Tristan Cebulla) - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.cubenation.bedrock.bukkit.api.ebean; - -import com.avaje.ebean.validation.NotNull; -import de.cubenation.bedrock.bukkit.plugin.BedrockPlugin; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import javax.persistence.*; -import java.util.Date; -import java.util.UUID; - -/** - * Represents a BedrockPlayer instance. - * - * @author Cube-Nation - * @version 1.0 - */ -@SuppressWarnings({"unused", "DefaultFileTemplate"}) -@Entity() -@Table(name = "bedrock_players") -public class BedrockPlayer { - - public BedrockPlayer() { - } - - public BedrockPlayer(String uuid, String username, Date lastlogin) { - this.uuid = uuid; - this.username = username; - this.lastlogin = lastlogin; - } - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Integer id; - - @Column(unique = true, nullable = false) - private String uuid; - - @NotNull - private String username; - - private Date lastlogin; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public UUID getUUID() { - return UUID.fromString(this.uuid); - } - - public String getUuid() { - return this.uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getUsername() { - return this.username; - } - - public void setUsername(String username) { - this.username = username; - } - - public Date getLastlogin() { - return lastlogin; - } - - public void setLastlogin(Date lastlogin) { - this.lastlogin = lastlogin; - } - - public void setPlayer(UUID uuid) { - this.setUuid(uuid.toString()); - } - - public void setPlayer(Player player) { - this.setUuid(player.getUniqueId().toString()); - } - - public Player getPlayer() { - return Bukkit.getPlayer(UUID.fromString(this.uuid)); - } - - public void save() { - BedrockPlugin.getInstance().getDatabase().save(this); - } - - public void update() { - BedrockPlugin.getInstance().getDatabase().update(this); - } - - - /* - * Helper - */ - - public Date offlineTime() { - boolean playerIsOnline = false; - Player onlinePlayer = Bukkit.getServer().getPlayer(uuid); - if (onlinePlayer != null) { - playerIsOnline = onlinePlayer.isOnline(); - } - - if (playerIsOnline) { - return new Date(); - } else { - OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(getUUID()); - - if (offlinePlayer == null) { - return null; - } else { - Long lastSeen = offlinePlayer.getLastPlayed(); - if (lastSeen != null) { - return new Date(lastSeen); - } else { - return null; - } - } - } - } - - public boolean isEqual(Player player) { - return this.getUUID().equals(player.getUniqueId()); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - BedrockPlayer that = (BedrockPlayer) o; - - return uuid != null ? uuid.equals(that.uuid) : that.uuid == null; - - } - - @Override - public int hashCode() { - return uuid != null ? uuid.hashCode() : 0; - } - - @Override - public String toString() { - return "BedrockPlayer{" + - "id=" + id + - ", uuid='" + uuid + '\'' + - ", username='" + username + '\'' + - (lastlogin == null ? "" : ", lastlogin=" + lastlogin) + - '}'; - } -} diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockWorld.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockWorld.java deleted file mode 100644 index 9effc9ff..00000000 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/ebean/BedrockWorld.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Bedrock - * - * Copyright (c) 2017 Cube-Nation (Benedikt Hruschka, Tristan Cebulla) - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.cubenation.bedrock.bukkit.api.ebean; - -import de.cubenation.bedrock.bukkit.plugin.BedrockPlugin; -import org.bukkit.Bukkit; -import org.bukkit.World; - -import javax.persistence.*; -import java.util.UUID; - -/** - * Represents a BedrockWorld instance. - * - * @author Cube-Nation - * @version 1.0 - */ -@SuppressWarnings({"unused", "DefaultFileTemplate"}) -@Entity() -@Table(name="bedrock_worlds") -public class BedrockWorld { - - @Id - @GeneratedValue(strategy= GenerationType.AUTO) - private Integer id; - - @Column(unique=true, nullable=false) - private String uuid; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getUuid() { - return this.uuid; - } - - - public void setWorld(World world) { - this.setUuid(world.getUID().toString()); - } - - public World getWorld() { - return Bukkit.getWorld(UUID.fromString(this.uuid)); - } - - public String getWorldName() { - return this.getWorld().getName(); - } - - - public void save() { - BedrockPlugin.getInstance().getDatabase().save(this); - } - - @Override - public String toString() { - return "BedrockWorld{" + - "id=" + id + - ", uuid='" + uuid + '\'' + - '}'; - } -} diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/exception/BedrockEbeanEntityNotFoundException.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/exception/BedrockEbeanEntityNotFoundException.java index 3d39d060..f0d0e702 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/exception/BedrockEbeanEntityNotFoundException.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/exception/BedrockEbeanEntityNotFoundException.java @@ -22,7 +22,7 @@ package de.cubenation.bedrock.bukkit.api.exception; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockPlayer; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; import java.io.IOException; import java.util.ArrayList; @@ -42,11 +42,11 @@ public BedrockEbeanEntityNotFoundException(Class clazz, int id) { super(String.format("Could not find bedrock ebean entity %s for id %s", clazz.toString(), id)); } - public BedrockEbeanEntityNotFoundException(Class clazz, ArrayList ids) { + public BedrockEbeanEntityNotFoundException(Class clazz, ArrayList ids) { super(String.format("Could not find bedrock ebean entity %s for ids %s", clazz.toString(), ids)); } - public BedrockEbeanEntityNotFoundException(ArrayList uuids, Class clazz) { + public BedrockEbeanEntityNotFoundException(ArrayList uuids, Class clazz) { super(String.format("Could not find bedrock ebean entity %s for ids %s", clazz.toString(), uuids)); } } diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/helper/BedrockEbeanHelper.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/helper/BedrockEbeanHelper.java index b0c7b7f0..6cb39258 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/helper/BedrockEbeanHelper.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/api/helper/BedrockEbeanHelper.java @@ -24,18 +24,17 @@ import com.avaje.ebean.RawSql; import com.avaje.ebean.RawSqlBuilder; -import de.cubenation.bedrock.core.callback.FailureCallback; -import de.cubenation.bedrock.core.callback.SuccessCallback; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockPlayer; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockWorld; import de.cubenation.bedrock.bukkit.api.exception.BedrockEbeanEntityAlreadyExistsException; import de.cubenation.bedrock.bukkit.api.exception.BedrockEbeanEntityNotFoundException; -import de.cubenation.bedrock.core.helper.UUIDUtil; import de.cubenation.bedrock.bukkit.plugin.BedrockPlugin; +import de.cubenation.bedrock.bukkit.wrapper.BukkitPlayer; +import de.cubenation.bedrock.core.callback.FailureCallback; +import de.cubenation.bedrock.core.callback.SuccessCallback; +import de.cubenation.bedrock.core.helper.UUIDUtil; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; +import de.cubenation.bedrock.core.wrapper.BedrockPlayer; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; import java.util.*; import java.util.concurrent.Callable; @@ -43,30 +42,30 @@ /** * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ @SuppressWarnings("ALL") public class BedrockEbeanHelper { /** - * Returns a BedrockPlayer object for the given org.bukkit.entity.Player. + * Returns a BedrockOfflinePlayer object for the given org.bukkit.entity.Player. * * @param player A org.bukkit.entity.Player object. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void requestBedrockPlayer(final Player player, SuccessCallback successCallback, FailureCallback failureCallback) { + public static void requestBedrockPlayer(final BedrockPlayer player, SuccessCallback successCallback, FailureCallback failureCallback) { requestBedrockPlayer(player.getUniqueId(), successCallback, failureCallback); } /** - * Request a list of BedrockPlayer for a list of players. + * Request a list of BedrockOfflinePlayer for a list of players. * * @param players Player of the BedrockPlayers to request. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void bulkRequestBedrockPlayerForPlayers(final ArrayList players, final SuccessCallback> successCallback, FailureCallback failureCallback) { + public static void bulkRequestBedrockPlayerForPlayers(final ArrayList players, final SuccessCallback> successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -80,33 +79,33 @@ public static void bulkRequestBedrockPlayerForPlayers(final ArrayList pl return player.getUniqueId(); }).collect(Collectors.toList()); bulkRequestBedrockPlayerForUuids((ArrayList) collect, bedrockPlayers -> { - HashMap result = new HashMap<>(); - for (Map.Entry entry : bedrockPlayers.entrySet()) { - result.put(entry.getValue().getPlayer(), entry.getValue()); + HashMap result = new HashMap<>(); + for (Map.Entry entry : bedrockPlayers.entrySet()) { + result.put(BukkitPlayer.wrap(BedrockPlugin.getInstance().getServer().getPlayer(entry.getKey())), entry.getValue()); } successCallback.didFinished(result); }, failureCallback); } /** - * Returns a BedrockPlayer object for the given java.util.UUID + * Returns a BedrockOfflinePlayer object for the given java.util.UUID * * @param uuid The UUID of a player. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void requestBedrockPlayer(UUID uuid, SuccessCallback successCallback, FailureCallback failureCallback) { + public static void requestBedrockPlayer(UUID uuid, SuccessCallback successCallback, FailureCallback failureCallback) { requestBedrockPlayer(uuid.toString(), successCallback, failureCallback); } /** - * Request a list of BedrockPlayer for a list of uuids. + * Request a list of BedrockOfflinePlayer for a list of uuids. * * @param uuids UUIDs of the BedrockPlayers to request. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void bulkRequestBedrockPlayerForUuids(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { + public static void bulkRequestBedrockPlayerForUuids(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -120,8 +119,8 @@ public static void bulkRequestBedrockPlayerForUuids(final ArrayList uuids, return uuid.toString(); }).collect(Collectors.toList()); bulkRequestBedrockPlayerForUuidStrings((ArrayList) collect, bedrockPlayers -> { - HashMap result = new HashMap<>(); - for (Map.Entry entry : bedrockPlayers.entrySet()) { + HashMap result = new HashMap<>(); + for (Map.Entry entry : bedrockPlayers.entrySet()) { result.put(entry.getValue().getUUID(), entry.getValue()); } successCallback.didFinished(result); @@ -129,13 +128,13 @@ public static void bulkRequestBedrockPlayerForUuids(final ArrayList uuids, } /** - * Returns a BedrockPlayer object for the given uuid String. + * Returns a BedrockOfflinePlayer object for the given uuid String. * * @param uuid A string representing a UUID. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void requestBedrockPlayer(final String uuid, final SuccessCallback successCallback, final FailureCallback failureCallback) { + public static void requestBedrockPlayer(final String uuid, final SuccessCallback successCallback, final FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -144,8 +143,8 @@ public static void requestBedrockPlayer(final String uuid, final SuccessCallback @Override public void run() { - final BedrockPlayer player = BedrockPlugin.getInstance().getDatabase() - .find(BedrockPlayer.class) + final BedrockOfflinePlayer player = BedrockPlugin.getInstance().getDatabase() + .find(BedrockOfflinePlayer.class) .where() .eq("uuid", uuid) .findUnique(); @@ -153,7 +152,7 @@ public void run() { Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { if (player == null) { if (failureCallback != null) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockPlayer.class, uuid)); + failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockOfflinePlayer.class, uuid)); } } else { successCallback.didFinished(player); @@ -165,13 +164,13 @@ public void run() { } /** - * Request a list of BedrockPlayer for a list of uuids. + * Request a list of BedrockOfflinePlayer for a list of uuids. * * @param uuids UUIDs of the BedrockPlayers to request. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void bulkRequestBedrockPlayerForUuidStrings(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { + public static void bulkRequestBedrockPlayerForUuidStrings(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -190,14 +189,14 @@ public void run() { "WHERE uuid IN ('" + StringUtils.join(uuids, "','") + "');"; RawSql rawSql = RawSqlBuilder.parse(oql).create(); - List list = BedrockPlugin.getInstance().getDatabase().find(BedrockPlayer.class).setRawSql(rawSql).findList(); + List list = BedrockPlugin.getInstance().getDatabase().find(BedrockOfflinePlayer.class).setRawSql(rawSql).findList(); Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { if (list == null || list.isEmpty()) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(uuids, BedrockPlayer.class)); + failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(uuids, BedrockOfflinePlayer.class)); } else { - HashMap result = new HashMap<>(); - for (BedrockPlayer bedrockPlayer : list) { + HashMap result = new HashMap<>(); + for (BedrockOfflinePlayer bedrockPlayer : list) { result.put(bedrockPlayer.getUuid(), bedrockPlayer); } successCallback.didFinished(result); @@ -209,14 +208,14 @@ public void run() { } /** - * Returns a BedrockPlayer object for the given name String. + * Returns a BedrockOfflinePlayer object for the given name String. * * @param username A string representing a username. * @param exact Mach all or an exact player. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void requestBedrockPlayerForLastKnownName(final String username, final boolean exact, final SuccessCallback> successCallback, FailureCallback failureCallback) { + public static void requestBedrockPlayerForLastKnownName(final String username, final boolean exact, final SuccessCallback> successCallback, FailureCallback failureCallback) { if (successCallback == null) { failureCallback.didFailed(null); return; @@ -224,7 +223,7 @@ public static void requestBedrockPlayerForLastKnownName(final String username, f if (UUIDUtil.isUUID(username)) { requestBedrockPlayer(username, - player -> successCallback.didFinished(new ArrayList() {{add(player);}}), + player -> successCallback.didFinished(new ArrayList() {{add(player);}}), failureCallback); return; } @@ -233,7 +232,7 @@ public static void requestBedrockPlayerForLastKnownName(final String username, f @Override public void run() { - final List foundPlayers = BedrockPlugin.getInstance().getDatabase().find(BedrockPlayer.class) + final List foundPlayers = BedrockPlugin.getInstance().getDatabase().find(BedrockOfflinePlayer.class) .where() .like("username", username + (exact ? "" : "%")) .orderBy().desc("lastlogin") @@ -241,14 +240,14 @@ public void run() { Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { if (foundPlayers != null && !foundPlayers.isEmpty()) { - ArrayList bedrockPlayers = new ArrayList(); + ArrayList bedrockPlayers = new ArrayList(); bedrockPlayers.addAll(foundPlayers); successCallback.didFinished(bedrockPlayers); return null; } - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockPlayer.class, username)); + failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockOfflinePlayer.class, username)); return null; }); } @@ -256,14 +255,14 @@ public void run() { } /** - * Returns a list of BedrockPlayer for the given name Strings. + * Returns a list of BedrockOfflinePlayer for the given name Strings. * * @param usernames A list of usernames. * @param exact Mach all or an exact player. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void bulkRequestBedrockPlayerForLastKnownNames(final ArrayList usernames, final boolean exact, final SuccessCallback>> successCallback, FailureCallback failureCallback) { + public static void bulkRequestBedrockPlayerForLastKnownNames(final ArrayList usernames, final boolean exact, final SuccessCallback>> successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -286,7 +285,7 @@ public void run() { .collect(Collectors.toCollection(ArrayList::new)); // Prepare result list - HashMap> result = new HashMap>() {{ + HashMap> result = new HashMap>() {{ for (String username : usernames) { put(username, new ArrayList<>()); } @@ -300,10 +299,10 @@ public void run() { StringUtils.join(names, " OR "); RawSql rawSql = RawSqlBuilder.parse(oql).create(); - List list = BedrockPlugin.getInstance().getDatabase().find(BedrockPlayer.class).setRawSql(rawSql).findList(); + List list = BedrockPlugin.getInstance().getDatabase().find(BedrockOfflinePlayer.class).setRawSql(rawSql).findList(); for (String name : usernames) { - for (BedrockPlayer bedrockPlayer : list) { + for (BedrockOfflinePlayer bedrockPlayer : list) { if (bedrockPlayer.getUsername().toLowerCase().startsWith(name.toLowerCase())) { result.get(name).add(bedrockPlayer); } @@ -311,7 +310,7 @@ public void run() { } bulkRequestBedrockPlayerForUuidStrings(uuids, bedrockPlayers -> { - for (BedrockPlayer bedrockPlayer : bedrockPlayers.values()) { + for (BedrockOfflinePlayer bedrockPlayer : bedrockPlayers.values()) { result.get(bedrockPlayer.getUuid()).add(bedrockPlayer); } @@ -335,7 +334,7 @@ public void run() { // Just UUID check bulkRequestBedrockPlayerForUuidStrings(uuids, bedrockPlayers -> { - for (BedrockPlayer bedrockPlayer : bedrockPlayers.values()) { + for (BedrockOfflinePlayer bedrockPlayer : bedrockPlayers.values()) { result.get(bedrockPlayer.getUuid()).add(bedrockPlayer); } @@ -360,13 +359,13 @@ public void run() { } /** - * Returns a BedrockPlayer object for the given id + * Returns a BedrockOfflinePlayer object for the given id * - * @param id The id of the BedrockPlayer. + * @param id The id of the BedrockOfflinePlayer. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void requestBedrockPlayer(final int id, final SuccessCallback successCallback, FailureCallback failureCallback) { + public static void requestBedrockPlayer(final int id, final SuccessCallback successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -374,8 +373,8 @@ public static void requestBedrockPlayer(final int id, final SuccessCallback) () -> { if (player == null) { if (failureCallback != null) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockPlayer.class, id)); + failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockOfflinePlayer.class, id)); } } else { successCallback.didFinished(player); @@ -395,13 +394,13 @@ public void run() { } /** - * Request a list of BedrockPlayer for a list of ids. + * Request a list of BedrockOfflinePlayer for a list of ids. * * @param ids Ids of the BedrockPlayers to request. * @param successCallback The success callback for the result of the request. * @param failureCallback The failure callback for the result of the request. */ - public static void bulkRequestBedrockPlayerForIds(final ArrayList ids, final SuccessCallback> successCallback, FailureCallback failureCallback) { + public static void bulkRequestBedrockPlayerForIds(final ArrayList ids, final SuccessCallback> successCallback, FailureCallback failureCallback) { if (successCallback == null) { return; } @@ -420,14 +419,14 @@ public void run() { "WHERE id IN ('" + StringUtils.join(ids, "','") + "');"; RawSql rawSql = RawSqlBuilder.parse(oql).create(); - List list = BedrockPlugin.getInstance().getDatabase().find(BedrockPlayer.class).setRawSql(rawSql).findList(); + List list = BedrockPlugin.getInstance().getDatabase().find(BedrockOfflinePlayer.class).setRawSql(rawSql).findList(); Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { if (list == null || list.isEmpty()) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockPlayer.class, ids)); + failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockOfflinePlayer.class, ids)); } else { - HashMap result = new HashMap<>(); - for (BedrockPlayer bedrockPlayer : list) { + HashMap result = new HashMap<>(); + for (BedrockOfflinePlayer bedrockPlayer : list) { result.put(bedrockPlayer.getId(), bedrockPlayer); } successCallback.didFinished(result); @@ -444,248 +443,23 @@ public void run() { * * @param uuid The unique id of the player * @param playername The name of the player - * @return the new BedrockPlayer instance. + * @return the new BedrockOfflinePlayer instance. * @throws BedrockEbeanEntityAlreadyExistsException if the player already exists. */ - public static BedrockPlayer createBedrockPlayer(UUID uuid, String playername) throws BedrockEbeanEntityAlreadyExistsException { - BedrockPlayer player = BedrockPlugin.getInstance().getDatabase() - .find(BedrockPlayer.class) + public static BedrockOfflinePlayer createBedrockPlayer(UUID uuid, String playername) throws BedrockEbeanEntityAlreadyExistsException { + BedrockOfflinePlayer player = BedrockPlugin.getInstance().getDatabase() + .find(BedrockOfflinePlayer.class) .where() .eq("uuid", uuid.toString()) .findUnique(); if (player != null) { - throw new BedrockEbeanEntityAlreadyExistsException(BedrockPlayer.class, uuid.toString()); + throw new BedrockEbeanEntityAlreadyExistsException(BedrockOfflinePlayer.class, uuid.toString()); } - BedrockPlayer bedrockPlayer = new BedrockPlayer(uuid.toString(), playername, null); - bedrockPlayer.save(); + BedrockOfflinePlayer bedrockPlayer = new BedrockOfflinePlayer(uuid.toString(), playername, null, null); + bedrockPlayer.save(BedrockPlugin.getInstance().getDatabase()); return bedrockPlayer; } - - /** - * Returns a BedrockWorld for the given org.bukkit.World. - * - * @param world A org.bukkit.World object. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void requestBedrockWorld(World world, SuccessCallback successCallback, FailureCallback failureCallback) { - requestBedrockWorld(world.getUID(), successCallback, failureCallback); - } - - /** - * Returns a BedrockWorld for the given java.util.UUID - * - * @param uuid A UUID. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void requestBedrockWorld(UUID uuid, SuccessCallback successCallback, FailureCallback failureCallback) { - requestBedrockWorld(uuid.toString(), successCallback, failureCallback); - } - - /** - * Returns a BedrockWorld for the given uuid String. - * - * @param uuids A list of UUIDs. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void bulkRequestBedrockWorldForUuids(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { - if (successCallback == null) { - return; - } - - if (uuids == null || uuids.isEmpty()) { - successCallback.didFinished(new HashMap<>()); - return; - } - - List collect = uuids.stream().map(uuid -> { - return uuid.toString(); - }).collect(Collectors.toList()); - bulkRequestBedrockWorldForUuidStrings((ArrayList) collect, bedrockWorldHashMap -> { - HashMap result = new HashMap<>(); - for (Map.Entry entry : bedrockWorldHashMap.entrySet()) { - result.put(UUID.fromString(entry.getValue().getUuid()), entry.getValue()); - } - successCallback.didFinished(result); - }, failureCallback); - } - - /** - * Returns a BedrockWorld for the given uuid String. - * - * @param uuid A string representing a UUID. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void requestBedrockWorld(final String uuid, final SuccessCallback successCallback, final FailureCallback failureCallback) { - if (successCallback == null) { - return; - } - - Bukkit.getScheduler().runTaskAsynchronously(BedrockPlugin.getInstance(), () -> { - final BedrockWorld world = BedrockPlugin.getInstance().getDatabase() - .find(BedrockWorld.class) - .where() - .eq("uuid", uuid) - .findUnique(); - - Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { - if (world == null) { - if (failureCallback != null) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockWorld.class, uuid)); - } - } else { - successCallback.didFinished(world); - } - return null; - }); - - }); - - } - - /** - * Request a list of BedrockWorld for a list of uuids. - * - * @param uuids UUIDs of the BedrockWorld to request. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void bulkRequestBedrockWorldForUuidStrings(final ArrayList uuids, final SuccessCallback> successCallback, FailureCallback failureCallback) { - if (successCallback == null) { - return; - } - - if (uuids == null || uuids.isEmpty()) { - successCallback.didFinished(new HashMap<>()); - return; - } - - Bukkit.getScheduler().runTaskAsynchronously(BedrockPlugin.getInstance(), new Runnable() { - @Override - public void run() { - - String oql = "SELECT id, uuid " + - "FROM `bedrock_worlds` " + - "WHERE uuid IN ('" + StringUtils.join(uuids, "','") + "');"; - - RawSql rawSql = RawSqlBuilder.parse(oql).create(); - List list = BedrockPlugin.getInstance().getDatabase().find(BedrockWorld.class).setRawSql(rawSql).findList(); - - Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { - if (list == null || list.isEmpty()) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(uuids, BedrockPlayer.class)); - } else { - HashMap result = new HashMap<>(); - for (BedrockWorld bedrockWorld : list) { - result.put(bedrockWorld.getUuid(), bedrockWorld); - } - successCallback.didFinished(result); - } - return null; - }); - } - }); - } - - /** - * Returns a BedrockWorld for the given id. - * - * @param id The id of the world. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void requestBedrockWorld(final int id, final SuccessCallback successCallback, FailureCallback failureCallback) { - if (successCallback == null) { - return; - } - - Bukkit.getScheduler().runTaskAsynchronously(BedrockPlugin.getInstance(), () -> { - final BedrockWorld world = BedrockPlugin.getInstance().getDatabase() - .find(BedrockWorld.class) - .where() - .eq("id", id) - .findUnique(); - - Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { - if (world == null) { - if (failureCallback != null) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockWorld.class, id)); - } - } else { - successCallback.didFinished(world); - } - - return null; - }); - }); - } - - /** - * Request a list of BedrockWorld for a list of ids. - * - * @param ids Ids of the BedrockWorlds to request. - * @param successCallback The success callback for the result of the request. - * @param failureCallback The failure callback for the result of the request. - */ - public static void bulkRequestBedrockWorldForIds(final ArrayList ids, final SuccessCallback> successCallback, FailureCallback failureCallback) { - if (successCallback == null) { - return; - } - - if (ids == null || ids.isEmpty()) { - successCallback.didFinished(new HashMap<>()); - return; - } - - Bukkit.getScheduler().runTaskAsynchronously(BedrockPlugin.getInstance(), new Runnable() { - @Override - public void run() { - - String oql = "SELECT id, uuid " + - "FROM `bedrock_worlds` " + - "WHERE id IN ('" + StringUtils.join(ids, "','") + "');"; - - RawSql rawSql = RawSqlBuilder.parse(oql).create(); - List list = BedrockPlugin.getInstance().getDatabase().find(BedrockWorld.class).setRawSql(rawSql).findList(); - - Bukkit.getScheduler().callSyncMethod(BedrockPlugin.getInstance(), (Callable) () -> { - if (list == null || list.isEmpty()) { - failureCallback.didFailed(new BedrockEbeanEntityNotFoundException(BedrockPlayer.class, ids)); - } else { - HashMap result = new HashMap<>(); - for (BedrockWorld bedrockWorld : list) { - result.put(bedrockWorld.getId(), bedrockWorld); - } - successCallback.didFinished(result); - } - return null; - }); - } - }); - } - - - public static BedrockWorld createBedrockWorld(World world) { - - BedrockWorld bw = BedrockPlugin.getInstance().getDatabase() - .find(BedrockWorld.class) - .where() - .eq("uuid", world.getUID()) - .findUnique(); - - if (bw == null) { - // save to table - bw = new BedrockWorld(); - bw.setUuid(world.getUID().toString()); - bw.save(); - } - return bw; - } - -} \ No newline at end of file +} diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/BedrockPlugin.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/BedrockPlugin.java index e8cd5131..d4c5543e 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/BedrockPlugin.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/BedrockPlugin.java @@ -23,8 +23,6 @@ package de.cubenation.bedrock.bukkit.plugin; import de.cubenation.bedrock.bukkit.api.BasePlugin; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockPlayer; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockWorld; import de.cubenation.bedrock.bukkit.plugin.command.BedrockPlayerInfoCommand; import de.cubenation.bedrock.bukkit.plugin.io.BungeeTeleportInputHandler; import de.cubenation.bedrock.bukkit.plugin.io.IOVerbs; @@ -34,6 +32,7 @@ import de.cubenation.bedrock.core.annotation.ConfigurationFile; import de.cubenation.bedrock.core.config.BedrockDefaults; import de.cubenation.bedrock.core.config.locale.de_DE; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; import net.cubespace.Yamler.Config.InvalidConfigurationException; import javax.persistence.PersistenceException; @@ -76,8 +75,7 @@ public void onPostEnable() { // install database table try { - this.getDatabase().find(BedrockPlayer.class).findRowCount(); - this.getDatabase().find(BedrockWorld.class).findRowCount(); + this.getDatabase().find(BedrockOfflinePlayer.class).findRowCount(); } catch (PersistenceException e) { getLogger().log(Level.INFO, "Installing database for " + getDescription().getName() + " due to first time usage"); installDDL(); @@ -100,8 +98,7 @@ public void onPostEnable() { @Override public List> getDatabaseClasses() { return new ArrayList>() {{ - add(BedrockPlayer.class); - add(BedrockWorld.class); + add(BedrockOfflinePlayer.class); }}; } diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/command/BedrockPlayerInfoCommand.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/command/BedrockPlayerInfoCommand.java index 7f91929b..47835ef2 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/command/BedrockPlayerInfoCommand.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/command/BedrockPlayerInfoCommand.java @@ -22,7 +22,6 @@ package de.cubenation.bedrock.bukkit.plugin.command; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockPlayer; import de.cubenation.bedrock.bukkit.api.helper.BedrockEbeanHelper; import de.cubenation.bedrock.core.FoundationPlugin; import de.cubenation.bedrock.core.annotation.Argument; @@ -36,6 +35,7 @@ import de.cubenation.bedrock.core.exception.IllegalCommandArgumentException; import de.cubenation.bedrock.core.exception.InsufficientPermissionException; import de.cubenation.bedrock.core.helper.UUIDUtil; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; import de.cubenation.bedrock.core.wrapper.BedrockChatSender; import org.bukkit.command.ConsoleCommandSender; @@ -80,7 +80,7 @@ public void execute(final BedrockChatSender sender, String[] args) throws Comman } else { BedrockEbeanHelper.requestBedrockPlayerForLastKnownName(player, false, bedrockPlayers -> { sender.sendMessage("Results: (" + bedrockPlayers.size() + ")"); - for (BedrockPlayer bedrockPlayer : bedrockPlayers) { + for (BedrockOfflinePlayer bedrockPlayer : bedrockPlayers) { sender.sendMessage(bedrockPlayer.getUsername() + ": " + bedrockPlayer.getLastlogin()); } }, e -> sender.sendMessage("No player found for: " + player)); diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/MultiAccountJoinEvent.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/MultiAccountJoinEvent.java new file mode 100644 index 00000000..09c079ab --- /dev/null +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/MultiAccountJoinEvent.java @@ -0,0 +1,59 @@ +/* + * Bedrock + * + * Copyright (c) 2017 Cube-Nation (Benedikt Hruschka, Tristan Cebulla) + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package de.cubenation.bedrock.bukkit.plugin.event; + +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import java.util.List; + +/** + * @author Cube-Nation + * @version 2.0 + */ +@ToString +public class MultiAccountJoinEvent extends Event { + + @Setter + private static final HandlerList handlers = new HandlerList(); + + @Getter + private String ip; + + @Getter + private List bedrockPlayers; + + public MultiAccountJoinEvent(String ip, List bedrockPlayers) { + this.ip = ip; + this.bedrockPlayers = bedrockPlayers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangesNameEvent.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangeNameEvent.java similarity index 71% rename from BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangesNameEvent.java rename to BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangeNameEvent.java index 2af8868a..14184de9 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangesNameEvent.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/event/PlayerChangeNameEvent.java @@ -22,26 +22,33 @@ package de.cubenation.bedrock.bukkit.plugin.event; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ -public class PlayerChangesNameEvent extends Event { +@ToString +public class PlayerChangeNameEvent extends Event { + @Setter private static final HandlerList handlers = new HandlerList(); + @Getter @Setter private Player player; + @Getter @Setter private String oldName; + @Getter @Setter private String newName; - - public PlayerChangesNameEvent(Player player, String oldName, String newName) { + public PlayerChangeNameEvent(Player player, String oldName, String newName) { this.player = player; this.oldName = oldName; this.newName = newName; @@ -51,32 +58,4 @@ public PlayerChangesNameEvent(Player player, String oldName, String newName) { public HandlerList getHandlers() { return handlers; } - - public static HandlerList getHandlerList() { - return handlers; - } - - public Player getPlayer() { - return player; - } - - public void setPlayer(Player player) { - this.player = player; - } - - public String getOldName() { - return oldName; - } - - public void setOldName(String oldName) { - this.oldName = oldName; - } - - public String getNewName() { - return newName; - } - - public void setNewName(String newName) { - this.newName = newName; - } } diff --git a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/listener/EbeanListener.java b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/listener/EbeanListener.java index b7f913ae..204bc1a6 100644 --- a/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/listener/EbeanListener.java +++ b/BedrockBukkit/src/main/java/de/cubenation/bedrock/bukkit/plugin/listener/EbeanListener.java @@ -22,22 +22,25 @@ package de.cubenation.bedrock.bukkit.plugin.listener; -import de.cubenation.bedrock.bukkit.api.ebean.BedrockPlayer; -import de.cubenation.bedrock.bukkit.api.helper.BedrockEbeanHelper; import de.cubenation.bedrock.bukkit.plugin.BedrockPlugin; -import de.cubenation.bedrock.bukkit.plugin.event.PlayerChangesNameEvent; +import de.cubenation.bedrock.bukkit.plugin.event.MultiAccountJoinEvent; +import de.cubenation.bedrock.bukkit.plugin.event.PlayerChangeNameEvent; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.world.WorldInitEvent; import org.bukkit.scheduler.BukkitRunnable; import java.util.Date; +import java.util.List; +import java.util.logging.Level; +import java.util.stream.Collectors; /** * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ @SuppressWarnings({"unused", "DefaultFileTemplate"}) public class EbeanListener implements Listener { @@ -50,52 +53,60 @@ public void onPlayerJoinEvent(final PlayerJoinEvent event) { @Override public void run() { + BedrockPlugin plugin = BedrockPlugin.getInstance(); + String uuid = event.getPlayer().getUniqueId().toString(); - BedrockPlayer bp = BedrockPlugin.getInstance().getDatabase() - .find(BedrockPlayer.class) + BedrockOfflinePlayer bp = BedrockPlugin.getInstance().getDatabase() + .find(BedrockOfflinePlayer.class) .where() .eq("uuid", uuid) .findUnique(); + String ip = event.getPlayer().getAddress().getAddress().getHostAddress(); if (bp == null) { - bp = new BedrockPlayer(uuid, event.getPlayer().getName(), new Date()); - bp.save(); + bp = new BedrockOfflinePlayer(uuid, event.getPlayer().getName(), ip, new Date()); + bp.save(plugin.getDatabase()); } else { // check if username changed if (!bp.getUsername().equals(event.getPlayer().getName())) { - BedrockPlugin.getInstance().getLogger().info("BedrockPlayer: " + bp.getUsername() + " " + - "changed name to " + event.getPlayer().getName()); - - /** - PlayerChangesNameEvent playerChangesNameEvent = new PlayerChangesNameEvent( + plugin.log(Level.INFO, String.format("BedrockPlayer: %s changed name to %s", + bp.getUsername(), event.getPlayer().getName())); + // fire name change event + PlayerChangeNameEvent changeNameEvent = new PlayerChangeNameEvent( event.getPlayer(), bp.getUsername(), event.getPlayer().getName()); - BedrockPlugin.getInstance().getServer().getPluginManager().callEvent(playerChangesNameEvent); - */ + Bukkit.getPluginManager().callEvent(changeNameEvent); + // update username bp.setUsername(event.getPlayer().getName()); } - // update timestamp - bp.setLastlogin(new Date()); - bp.update(); - } - } - }.runTaskAsynchronously(BedrockPlugin.getInstance()); - } + List bedrockPlayers = plugin.getDatabase().find(BedrockOfflinePlayer.class).where() + .like("ip", ip) + .findList(); - @EventHandler(priority = EventPriority.MONITOR) - public void onWorldInit(final WorldInitEvent event) { - // run this as async task - new BukkitRunnable() { + if (bedrockPlayers != null) { + // Remove self + bedrockPlayers = bedrockPlayers.stream() + .filter(player -> !player.getUuid().equals(event.getPlayer().getUniqueId().toString())) + .collect(Collectors.toList()); - @Override - public void run() { - BedrockEbeanHelper.createBedrockWorld(event.getWorld()); + if (bedrockPlayers.size() > 0) { + MultiAccountJoinEvent joinEvent = new MultiAccountJoinEvent(ip, bedrockPlayers); + Bukkit.getPluginManager().callEvent(joinEvent); + } + } + + // update ip + bp.setIp(ip); + + // update timestamp + bp.setLastlogin(new Date()); + bp.update(plugin.getDatabase()); + } } }.runTaskAsynchronously(BedrockPlugin.getInstance()); } - -} \ No newline at end of file +} diff --git a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/BedrockPlugin.java b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/BedrockPlugin.java index 7a35c8ce..0b62bf16 100644 --- a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/BedrockPlugin.java +++ b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/BedrockPlugin.java @@ -25,10 +25,9 @@ import de.cubenation.bedrock.bungee.api.BasePlugin; import de.cubenation.bedrock.bungee.plugin.io.IOVerbs; import de.cubenation.bedrock.bungee.plugin.listener.PlayerListener; -import de.cubenation.bedrock.core.annotation.CommandHandler; import de.cubenation.bedrock.core.annotation.ConfigurationFile; import de.cubenation.bedrock.core.config.locale.de_DE; -import de.cubenation.bedrock.core.model.BedrockPlayer; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; import javax.persistence.PersistenceException; import java.util.ArrayList; @@ -58,7 +57,7 @@ public void onPreEnable() throws Exception { public void onPostEnable() throws Exception { // install database table try { - this.getDatabase().find(BedrockPlayer.class).findRowCount(); + this.getDatabase().find(BedrockOfflinePlayer.class).findRowCount(); } catch (PersistenceException e) { getLogger().log(Level.INFO, "Installing database for " + getDescription().getName() + " due to first time usage"); installDDL(); @@ -72,7 +71,7 @@ public void onPostEnable() throws Exception { @Override public List> getDatabaseClasses() { return new ArrayList>() {{ - add(BedrockPlayer.class); + add(BedrockOfflinePlayer.class); }}; } diff --git a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/MultiAccountJoinEvent.java b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/MultiAccountJoinEvent.java index c952220d..b88e9b83 100644 --- a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/MultiAccountJoinEvent.java +++ b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/MultiAccountJoinEvent.java @@ -1,32 +1,28 @@ package de.cubenation.bedrock.bungee.plugin.event; -import de.cubenation.bedrock.core.model.BedrockPlayer; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; +import lombok.Getter; +import lombok.ToString; import net.md_5.bungee.api.plugin.Event; import java.util.List; -import java.util.UUID; /** * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ +@ToString public class MultiAccountJoinEvent extends Event { + @Getter private String ip; - private List bedrockPlayers; + @Getter + private List bedrockPlayers; - public MultiAccountJoinEvent(String ip, List bedrockPlayers) { + public MultiAccountJoinEvent(String ip, List bedrockPlayers) { this.ip = ip; this.bedrockPlayers = bedrockPlayers; } - - public String getIp() { - return ip; - } - - public List getBedrockPlayers() { - return bedrockPlayers; - } } diff --git a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/PlayerChangeNameEvent.java b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/PlayerChangeNameEvent.java index 89ffe525..3ecd3b9e 100644 --- a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/PlayerChangeNameEvent.java +++ b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/event/PlayerChangeNameEvent.java @@ -1,19 +1,26 @@ package de.cubenation.bedrock.bungee.plugin.event; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; import net.md_5.bungee.api.plugin.Event; import java.util.UUID; /** * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ +@ToString public class PlayerChangeNameEvent extends Event { + @Getter @Setter private UUID uuid; + @Getter @Setter private String oldName; + @Getter @Setter private String newName; public PlayerChangeNameEvent(UUID uuid, String oldName, String newName) { @@ -21,28 +28,4 @@ public PlayerChangeNameEvent(UUID uuid, String oldName, String newName) { this.oldName = oldName; this.newName = newName; } - - public UUID getUuid() { - return uuid; - } - - public void setUuid(UUID uuid) { - this.uuid = uuid; - } - - public String getOldName() { - return oldName; - } - - public void setOldName(String oldName) { - this.oldName = oldName; - } - - public String getNewName() { - return newName; - } - - public void setNewName(String newName) { - this.newName = newName; - } } diff --git a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/listener/PlayerListener.java b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/listener/PlayerListener.java index 19373cd4..dd1d889d 100644 --- a/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/listener/PlayerListener.java +++ b/BedrockBungee/src/main/java/de/cubenation/bedrock/bungee/plugin/listener/PlayerListener.java @@ -4,8 +4,7 @@ import de.cubenation.bedrock.bungee.plugin.BedrockPlugin; import de.cubenation.bedrock.bungee.plugin.event.MultiAccountJoinEvent; import de.cubenation.bedrock.bungee.plugin.event.PlayerChangeNameEvent; -import de.cubenation.bedrock.core.FoundationPlugin; -import de.cubenation.bedrock.core.model.BedrockPlayer; +import de.cubenation.bedrock.core.model.BedrockOfflinePlayer; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; @@ -30,15 +29,15 @@ public void onPostLogin(PostLoginEvent event) { plugin.getProxy().getScheduler().runAsync(plugin, () -> { String uuid = event.getPlayer().getUniqueId().toString(); - BedrockPlayer bp = BedrockPlugin.getInstance().getDatabase() - .find(BedrockPlayer.class) + BedrockOfflinePlayer bp = BedrockPlugin.getInstance().getDatabase() + .find(BedrockOfflinePlayer.class) .where() .eq("uuid", uuid) .findUnique(); String ip = event.getPlayer().getAddress().getAddress().getHostAddress(); if (bp == null) { - bp = new BedrockPlayer(uuid, event.getPlayer().getName(), ip, new Date()); + bp = new BedrockOfflinePlayer(uuid, event.getPlayer().getName(), ip, new Date()); bp.save(plugin.getDatabase()); } else { // check if username changed @@ -56,7 +55,7 @@ public void onPostLogin(PostLoginEvent event) { bp.setUsername(event.getPlayer().getName()); } - List bedrockPlayers = plugin.getDatabase().find(BedrockPlayer.class).where() + List bedrockPlayers = plugin.getDatabase().find(BedrockOfflinePlayer.class).where() .like("ip", ip) .findList(); diff --git a/BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockPlayer.java b/BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockOfflinePlayer.java similarity index 58% rename from BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockPlayer.java rename to BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockOfflinePlayer.java index 0f22753f..5f83577e 100644 --- a/BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockPlayer.java +++ b/BedrockCore/src/main/java/de/cubenation/bedrock/core/model/BedrockOfflinePlayer.java @@ -2,32 +2,27 @@ import com.avaje.ebean.EbeanServer; import com.avaje.ebean.validation.NotNull; +import de.cubenation.bedrock.core.wrapper.BedrockPlayer; +import lombok.*; import javax.persistence.*; import java.util.Date; +import java.util.Objects; import java.util.UUID; /** * Represents a BedrockPlayer instance. * * @author Cube-Nation - * @version 1.0 + * @version 2.0 */ @SuppressWarnings({"unused", "DefaultFileTemplate"}) +@ToString @NoArgsConstructor @AllArgsConstructor @Entity() @Table(name = "bedrock_players") -public class BedrockPlayer { - - public BedrockPlayer() { - } - - public BedrockPlayer(String uuid, String username, String ip, Date lastlogin) { - this.uuid = uuid; - this.username = username; - this.ip = ip; - this.lastlogin = lastlogin; - } +public class BedrockOfflinePlayer { + @Getter @Setter @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @@ -35,26 +30,34 @@ public BedrockPlayer(String uuid, String username, String ip, Date lastlogin) { @Column(unique = true, nullable = false) private String uuid; + @Getter @Setter @NotNull private String username; + @Getter @Setter @Column(length = 45) private String ip; + @Getter @Setter private Date lastlogin; - public Integer getId() { - return id; - } - public void setId(Integer id) { - this.id = id; + public BedrockOfflinePlayer(String uuid, String username, String ip, Date lastlogin) { + this.uuid = uuid; + this.username = username; + this.ip = ip; + this.lastlogin = lastlogin; } + public UUID getUUID() { return UUID.fromString(this.uuid); } + public void setUUID(UUID uuid) { + this.setUuid(uuid.toString()); + } + public String getUuid() { return this.uuid; } @@ -63,41 +66,31 @@ public void setUuid(String uuid) { this.uuid = uuid; } - public String getUsername() { - return this.username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getIp() { - return ip; + public void save(EbeanServer database) { + database.save(this); } - public void setIp(String ip) { - this.ip = ip; + public void update(EbeanServer database) { + database.update(this); } - public Date getLastlogin() { - return lastlogin; - } - public void setLastlogin(Date lastlogin) { - this.lastlogin = lastlogin; + public boolean isEqual(BedrockPlayer player) { + return this.getUUID().equals(player.getUniqueId()); } - public void setPlayer(UUID uuid) { - this.setUuid(uuid.toString()); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - public void save(EbeanServer database) { - database.save(this); + BedrockOfflinePlayer that = (BedrockOfflinePlayer) o; + return Objects.equals(uuid, that.uuid); } - public void update(EbeanServer database) { - database.update(this); + @Override + public int hashCode() { + return uuid != null ? uuid.hashCode() : 0; } - }