Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a few small issues #61

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import plugily.projects.minigamesbox.api.stats.IStatisticType;
import plugily.projects.minigamesbox.api.user.data.UserDatabase;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
* @author Lagggpixel
Expand All @@ -26,6 +28,10 @@ public interface IUserManager {

void updateLevelStat(IUser user, IPluginArena arena);

void storeUserQuitDuringGame(Player player, IPluginArena arena);

HashMap<UUID, IPluginArena> getUsersQuitDuringGame();

void saveAllStatistic(IUser user);

void loadStatistics(IUser user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void hidePlayersOutsideTheGame(Player player, PluginArena arena) {
VersionUtils.hidePlayer(plugin, players, player);
}
}

public static CompletableFuture<Void> preparePlayerForGame(
IPluginArena arena, Player player, Location location, boolean spectator) {
return VersionUtils.teleport(player, location).thenAccept(bo -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public void onCraft(PlugilyPlayerInteractEvent event) {
return;
}
if(event.getPlayer().getTargetBlock(null, 7).getType() == XMaterial.CRAFTING_TABLE.parseMaterial()) {
event.setCancelled(true);
if(event.getAction().isRightClick()) {
event.setCancelled(true);
}
}
if(event.getClickedBlock() == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import plugily.projects.minigamesbox.api.arena.IPluginArena;
import plugily.projects.minigamesbox.classic.PluginMain;
import plugily.projects.minigamesbox.classic.handlers.items.SpecialItem;
import plugily.projects.minigamesbox.classic.utils.serialization.InventorySerializer;
Expand All @@ -45,6 +46,11 @@ public JoinEvent(PluginMain plugin) {

@EventHandler
public void onJoin(PlayerJoinEvent event) {
IPluginArena arena = plugin.getUserManager().getUsersQuitDuringGame().get(event.getPlayer().getUniqueId());
if(arena != null) {
VersionUtils.teleport(event.getPlayer(), arena.getEndLocation());
plugin.getUserManager().getUsersQuitDuringGame().remove(event.getPlayer().getUniqueId());
}
plugin.getUserManager().loadStatistics(plugin.getUserManager().getUser(event.getPlayer()));
//load player inventory in case of server crash, file is deleted once loaded so if file was already
//deleted player won't receive his backup, in case of crash he will get it back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package plugily.projects.minigamesbox.classic.events;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -58,6 +59,7 @@ private void onQuit(Player player) {
IPluginArena arena = plugin.getArenaRegistry().getArena(player);
if (arena != null) {
plugin.getArenaManager().leaveAttempt(player, arena);
plugin.getUserManager().storeUserQuitDuringGame(player, arena);
}
IUser user = plugin.getUserManager().getUser(player);
plugin.getUserManager().saveAllStatistic(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class UserManager implements IUserManager {

private final UserDatabase database;
private final HashMap<UUID, User> users = new HashMap<>();
private final HashMap<UUID, IPluginArena> usersQuitDuringGame = new HashMap<>();
private final PluginMain plugin;

public UserManager(PluginMain plugin) {
Expand Down Expand Up @@ -129,6 +130,16 @@ public void updateLevelStat(IUser user, IPluginArena arena) {
}
}

@Override
public void storeUserQuitDuringGame(Player player, IPluginArena arena) {
usersQuitDuringGame.put(player.getUniqueId(), arena);
}

@Override
public HashMap<UUID, IPluginArena> getUsersQuitDuringGame() {
return usersQuitDuringGame;
}

@Override
public void saveAllStatistic(IUser user) {
database.saveAllStatistic(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package plugily.projects.minigamesbox.classic.utils.helper;

import com.cryptomorin.xseries.XMaterial;
import com.mojang.authlib.GameProfile;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.mojang.authlib.properties.Property;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
Expand Down Expand Up @@ -65,16 +67,16 @@ public static ItemStack getSkull(String url) {

SkullMeta headMeta = (SkullMeta) head.getItemMeta();

GameProfile profile;
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_20)) {
profile = new GameProfile(UUID.randomUUID(), "Plugily");
PlayerProfile profile;
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_21)) {
profile = Bukkit.getServer().createProfile(UUID.randomUUID(), "Plugily");
} else {
profile = new GameProfile(UUID.randomUUID(), null);
profile = Bukkit.getServer().createProfile(UUID.randomUUID(), null);
}
profile.getProperties().put("textures", new Property("textures", url));
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_15)) {
profile.setProperty(new ProfileProperty("textures", url));
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_21)) {
try {
Method mtd = headMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
Method mtd = headMeta.getClass().getDeclaredMethod("setPlayerProfile", PlayerProfile.class);
mtd.setAccessible(true);
mtd.invoke(headMeta, profile);
} catch(Exception ignored) {
Expand Down