From 71e1a07e117acb9d368ffa9f80eaf9e5d49c3b19 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 24 Oct 2020 14:07:48 +0200 Subject: [PATCH 1/4] Add new Particle with onlineTime restriction --- .../lobby/inventories/ParticleInventory.java | 49 ++++++++++++++++--- .../lobby/listener/EnderPearlListener.java | 3 +- src/de/steamwar/lobby/utils/LobbyPlayer.java | 3 ++ src/de/steamwar/sql/OnlineTime.java | 38 ++++++++++++++ 4 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/de/steamwar/sql/OnlineTime.java diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 44965d2..20882c2 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -22,6 +22,7 @@ package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.lobby.utils.LobbyPlayer; +import de.steamwar.sql.OnlineTime; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.Material; @@ -29,19 +30,20 @@ import org.bukkit.Particle; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import java.util.regex.MatchResult; public class ParticleInventory { private ParticleInventory() {} + private static SWItem mysteryParticle = new SWItem(Material.STRUCTURE_VOID, "§5§l???", Arrays.asList("§5Ein mysteriöses Partikel"), false, clickType -> {}); + private static List lore = Arrays.asList("§aKlicken zum Auswählen"); + private static SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - UserGroup userGroup = SteamwarUser.get(player.getUniqueId()).getUserGroup(); - - List lore = new ArrayList<>(); - lore.add("§aKlicken zum Auswählen"); + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); SWInventory swInventory; if (userGroup == UserGroup.Member) { @@ -67,7 +69,8 @@ public class ParticleInventory { add(swInventory, Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB, 25, player, lobbyPlayer); if (userGroup == UserGroup.Member) { - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 31, player, lobbyPlayer); + add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 34, player, lobbyPlayer); + add(swInventory, 28, steamwarUser, player, lobbyPlayer); } else { add(swInventory, Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 28, player, lobbyPlayer, true, 0.2F, 0F, 0.2F, 0.01); add(swInventory, Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH, 29, player, lobbyPlayer); @@ -77,12 +80,44 @@ public class ParticleInventory { add(swInventory, Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 33, player, lobbyPlayer, true, 0F, 0.2F, 0F, 0.2); add(swInventory, Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 34, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 40, player, lobbyPlayer); + add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 43, player, lobbyPlayer); + add(swInventory, 37, steamwarUser, player, lobbyPlayer); } return swInventory; } + private static void add(SWInventory swInventory, int slot, SteamwarUser steamwarUser, Player player, LobbyPlayer lobbyPlayer) { + swInventory.setItem(slot, mysteryParticle); + swInventory.setItem(slot + 1, mysteryParticle); + swInventory.setItem(slot + 2, mysteryParticle); + swInventory.setItem(slot + 3, mysteryParticle); + swInventory.setItem(slot + 4, mysteryParticle); + + double onlineTime = OnlineTime.getOnlinetime(steamwarUser) / 60 / 60; + + if (onlineTime < 200) { + return; + } + add(swInventory, Material.DRAGON_BREATH, "§5Dragon Breath", lore, Particle.DRAGON_BREATH, slot, player, lobbyPlayer); + if (onlineTime < 400) { + return; + } + add(swInventory, Material.DOLPHIN_SPAWN_EGG, "§bDelphin", lore, Particle.DOLPHIN, slot + 1, player, lobbyPlayer); + if (onlineTime < 800) { + return; + } + add(swInventory, Material.RED_CONCRETE, "§cInstant Spell", lore, Particle.SPELL_INSTANT, slot + 2, player, lobbyPlayer); + if (onlineTime < 1600) { + return; + } + add(swInventory, Material.PURPLE_WOOL, "§5Portal", lore, Particle.PORTAL, slot + 3, player, lobbyPlayer); + if (onlineTime < 3200) { + return; + } + add(swInventory, Material.WHITE_DYE, "§fFlash", lore, Particle.FLASH, slot + 4, player, lobbyPlayer); + } + private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyPlayer lobbyPlayer, boolean customVelocity, float vx, float vy, float vz, double time) { SWItem swItem = new SWItem(material, name, lore, false, clickType -> { lobbyPlayer.setParticle(particle, customVelocity); diff --git a/src/de/steamwar/lobby/listener/EnderPearlListener.java b/src/de/steamwar/lobby/listener/EnderPearlListener.java index 7e7ec2e..2a8c9e9 100644 --- a/src/de/steamwar/lobby/listener/EnderPearlListener.java +++ b/src/de/steamwar/lobby/listener/EnderPearlListener.java @@ -24,7 +24,8 @@ import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Bukkit; import org.bukkit.Sound; -import org.bukkit.entity.*; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index cbf0e11..95cb678 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,8 +19,11 @@ package de.steamwar.lobby.utils; +import de.steamwar.sql.SQL; import org.bukkit.Particle; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.*; public class LobbyPlayer { diff --git a/src/de/steamwar/sql/OnlineTime.java b/src/de/steamwar/sql/OnlineTime.java new file mode 100644 index 0000000..8eec5c9 --- /dev/null +++ b/src/de/steamwar/sql/OnlineTime.java @@ -0,0 +1,38 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class OnlineTime { + + public static double getOnlinetime(SteamwarUser steamwarUser) { + ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", steamwarUser.getId()); + try { + set.next(); + return set.getBigDecimal("Playtime").doubleValue(); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return 0; + } + +} From d6d48edffe9d093aaff9a7f9014ea33e86fbbc56 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 24 Oct 2020 14:10:33 +0200 Subject: [PATCH 2/4] Shorten Time to get Particles --- .../steamwar/lobby/inventories/ParticleInventory.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 20882c2..b3fb85b 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -29,7 +29,6 @@ import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -96,23 +95,23 @@ public class ParticleInventory { double onlineTime = OnlineTime.getOnlinetime(steamwarUser) / 60 / 60; - if (onlineTime < 200) { + if (onlineTime < 100) { return; } add(swInventory, Material.DRAGON_BREATH, "§5Dragon Breath", lore, Particle.DRAGON_BREATH, slot, player, lobbyPlayer); - if (onlineTime < 400) { + if (onlineTime < 200) { return; } add(swInventory, Material.DOLPHIN_SPAWN_EGG, "§bDelphin", lore, Particle.DOLPHIN, slot + 1, player, lobbyPlayer); - if (onlineTime < 800) { + if (onlineTime < 300) { return; } add(swInventory, Material.RED_CONCRETE, "§cInstant Spell", lore, Particle.SPELL_INSTANT, slot + 2, player, lobbyPlayer); - if (onlineTime < 1600) { + if (onlineTime < 400) { return; } add(swInventory, Material.PURPLE_WOOL, "§5Portal", lore, Particle.PORTAL, slot + 3, player, lobbyPlayer); - if (onlineTime < 3200) { + if (onlineTime < 500) { return; } add(swInventory, Material.WHITE_DYE, "§fFlash", lore, Particle.FLASH, slot + 4, player, lobbyPlayer); From 86fdd87781a09d46623395c87e71a59c84206e59 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 24 Oct 2020 17:34:52 +0200 Subject: [PATCH 3/4] Optimize Imports --- src/de/steamwar/lobby/utils/LobbyPlayer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 95cb678..68857eb 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,12 +19,11 @@ package de.steamwar.lobby.utils; -import de.steamwar.sql.SQL; import org.bukkit.Particle; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; public class LobbyPlayer { From d815a05b60f6aeaf23c5bda2564fdf130ed8cd19 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 25 Oct 2020 08:09:50 +0100 Subject: [PATCH 4/4] Fix OnlineTime Exception --- src/de/steamwar/sql/OnlineTime.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/de/steamwar/sql/OnlineTime.java b/src/de/steamwar/sql/OnlineTime.java index 8eec5c9..35be024 100644 --- a/src/de/steamwar/sql/OnlineTime.java +++ b/src/de/steamwar/sql/OnlineTime.java @@ -25,6 +25,9 @@ import java.sql.SQLException; public class OnlineTime { public static double getOnlinetime(SteamwarUser steamwarUser) { + if (true) { + return 0; + } ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", steamwarUser.getId()); try { set.next();