Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
plugins {
id "org.sonarqube" version "2.6"
id 'java'
id 'idea'
}

apply plugin: 'java'
apply plugin: 'idea'
archivesBaseName = 'minicat'
version = '1.0-SNAPSHOT'

base {
archivesName = 'minicat'
}

repositories {
mavenCentral()
//mavenLocal() Enable to compile with BielAPI preinstalled on mavenlocal
/* maven{
//Repository url is ok, but server seems to be (temporarily, 02/01/17) serving wrong content
//url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}*/
mavenLocal()
maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
url = uri('https://repo.papermc.io/repository/maven-public/')
}
maven {
url = "https://oss.sonatype.org/content/repositories/snapshots/"
url = uri('https://jitpack.io')
}
}

jar {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}

def defaultEncoding = 'UTF-8'
compileJava{
options.encoding = defaultEncoding
Expand All @@ -33,18 +34,21 @@ compileTestJava{
options.encoding = defaultEncoding
}
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile 'org.apache.commons:commons-io:1.3.2'
//Enable if you have BielAPI installed on maven local
//compile 'BielAPI:BielAPI:0.0.8-SNAPSHOT'
compile fileTree(dir: 'lib', include: '*.jar')
//Enable to use automatic download, when avaliable
//compile 'org.spigotmc:spigot-api:1.10-R0.1-SNAPSHOT'
// compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'

compileOnly "org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT"
// compileOnly "org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT"
testCompileOnly "org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT"
implementation 'com.google.guava:guava:33.6.0-jre'
implementation 'commons-io:commons-io:2.21.0'
implementation 'commons-lang:commons-lang:2.6'
implementation 'com.mysql:mysql-connector-j:9.6.0'
compileOnly 'BielAPI:BielAPI:0.0.10-SNAPSHOT'
compileOnly fileTree(dir: 'lib', include: '*.jar', exclude: [
'BielAPI-*.jar',
'NametagEdit*.jar',
'spigot-*.jar'
])
compileOnly 'io.papermc.paper:paper-api:26.2.build.92-stable'
compileOnly('com.github.decentsoftware-eu.decentholograms:plugin:2.10.1') {
transitive = false
}
testCompileOnly 'io.papermc.paper:paper-api:26.2.build.92-stable'

}

Expand All @@ -55,4 +59,4 @@ task deploy(type: Copy){
}
into 'F:\\Servers MC\\Lobby - 1.9\\plugins'
}
deploy.dependsOn assemble
deploy.dependsOn assemble
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
Empty file modified gradlew
100644 → 100755
Empty file.
27 changes: 12 additions & 15 deletions src/main/java/com/biel/lobby/Com.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
import java.util.UUID;
import java.util.stream.Stream;

import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.api.VisibilityManager;
import com.nametagedit.plugin.NametagEdit;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

import com.biel.lobby.utilities.CBUtils;
import com.biel.lobby.utilities.ColorConverter;
import com.biel.lobby.utilities.HologramFacade;
import com.biel.lobby.utilities.Options;
import com.biel.lobby.utilities.PaperMessages;
import com.biel.lobby.utilities.PlayerTagState;
import com.biel.lobby.utilities.ScoreBoardUpdater;
import com.biel.lobby.utilities.Utils;
import com.biel.lobby.utilities.data.DataAPI;
import com.biel.lobby.utilities.data.PlayerData;
import com.connorlinfoot.titleapi.TitleAPI;

public class Com {
//HIO
Expand Down Expand Up @@ -71,22 +69,20 @@ public static void teleportPlayerToLobby(Player p){
}


private static HashMap<UUID, Hologram> playerHologramMap = new HashMap<UUID, Hologram>();
private static HashMap<UUID, HologramFacade.Handle> playerHologramMap = new HashMap<UUID, HologramFacade.Handle>();
private static void showRanking(Player player) {

Hologram hologram;
HologramFacade.Handle hologram;
if(playerHologramMap.containsKey(player.getUniqueId())) {
hologram = playerHologramMap.get(player.getUniqueId());
hologram.clearLines();
} else {
Location hologramLocation = new Location(getLobbyWorld(), -283, 72.5, 26);
hologram = HologramsAPI.createHologram(getPlugin(), hologramLocation);
hologram = HologramFacade.create(hologramLocation);
playerHologramMap.put(player.getUniqueId(), hologram);
}

VisibilityManager visibilityManager = hologram.getVisibilityManager();
visibilityManager.showTo(player);
visibilityManager.setVisibleByDefault(false);
hologram.showOnlyTo(player);

hologram.appendTextLine(ChatColor.AQUA + "MINICAT RANKING");
hologram.appendTextLine("");
Expand Down Expand Up @@ -135,10 +131,10 @@ public static void setHeadColor(Player ply, ChatColor color){
setHeadColor(ply, ColorConverter.chatToRaw(color));
}
public static void setHeadColor(Player ply, String color){
NametagEdit.getApi().setPrefix(ply, color);
PlayerTagState.setPrefix(ply, color);
}
public static void setSuffix(Player ply, String suffix){
NametagEdit.getApi().setSuffix(ply, suffix);
PlayerTagState.setSuffix(ply, suffix);
}
public static void displayRanking(Player p){
if(Com.getDataAPI().isInDatalessMode()){
Expand Down Expand Up @@ -266,12 +262,13 @@ public static void playMinicatAnimation(Player p){
f.add(ChatColor.WHITE + "" + bold + "MINICAT");
int i = 0;
for (String s : f){
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> TitleAPI.sendTitle(p,0,6,0,s,Integer.toString(Bukkit.getOnlinePlayers().size())), 4 * i + 14 + (CBUtils.getPing(p) * 20 / 1000));
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> PaperMessages.showTitle(p, 0, 6, 0, s,
Integer.toString(Bukkit.getOnlinePlayers().size())), 4 * i + 14 + (CBUtils.getPing(p) * 20 / 1000));
i++;
}
}
public static Material getSkullIconMaterial(Player p){
Material m = Material.LEGACY_SKULL_ITEM;
Material m = Material.PLAYER_HEAD;
if(Stream.of("amiguet", "pilota", "ball", "").anyMatch(s -> (p.getName().equalsIgnoreCase(s) || p.getName().contains(s))))
m = Material.SLIME_BALL;
return m;
Expand Down
107 changes: 82 additions & 25 deletions src/main/java/com/biel/lobby/GestorMapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import java.util.List;
import java.util.stream.Collectors;

import com.connorlinfoot.bountifulapi.BountifulAPI;
import com.biel.lobby.utilities.PaperMessages;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool;

import com.biel.BielAPI.Utils.IconMenu;
import com.biel.BielAPI.Utils.Pair;
Expand All @@ -26,6 +26,8 @@


public class GestorMapes implements Listener{
public enum InstanceRemovalResult { REMOVED, NOT_FOUND, HAS_PLAYERS, EDIT_MODE, UNLOAD_FAILED }
public enum InstanceJoinResult { JOINED, NOT_FOUND, UNAVAILABLE }
public lobby plugin;
ArrayList<Pair<String, Double>> auto_ratings;
ArrayList<ContenidorMapa> Mapes = new ArrayList<>();
Expand All @@ -36,7 +38,7 @@ public GestorMapes() {

//Mapes.add(new ContenidorJoc(ObsidianDefenders.class, "Obsidian defenders", Material.OBSIDIAN, DevelopmentState.NotWorking));
Mapes.add(new ContenidorJoc(Spleef.class, "Spleef", Material.SNOW, DevelopmentState.Release));
Mapes.add(new ContenidorJoc(RainbowClay.class, "Rainbow Clay", Material.LEGACY_HARD_CLAY, DevelopmentState.Beta));
Mapes.add(new ContenidorJoc(RainbowClay.class, "Rainbow Clay", Material.RED_TERRACOTTA, DevelopmentState.Beta));
Mapes.add(new ContenidorJoc(Torres.class, "Torres de defensa", Material.ARROW, DevelopmentState.Beta));
Mapes.add(new ContenidorJoc(Quakecraft.class, "Quakecraft", Material.STONE_HOE, DevelopmentState.Beta));
Mapes.add(new ContenidorJoc(Dominion.class, "Dominion", Material.DIAMOND, DevelopmentState.Beta));
Expand Down Expand Up @@ -65,7 +67,9 @@ public GestorMapes() {
Mapes.add(new ContenidorJoc(PilotaSplash.class, "Pilota Splash", Material.SLIME_BALL, DevelopmentState.Alpha));
//Mapes.add(new ContenidorJoc(TempleQuest.class, "Temple Quest", Material.QUARTZ_BLOCK, DevelopmentState.InDevelopment));
Mapes.add(new ContenidorJoc(OneInTheChamber.class, "OneInTheChamber", Material.BOW, DevelopmentState.Alpha));
Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.RED_BED, DevelopmentState.InDevelopment));
// No Mapes/BedWars template exists in either recovered server tree.
// Keep the implementation source, but do not advertise an instance that cannot be created.
// Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.RED_BED, DevelopmentState.InDevelopment));
}
public void queryAutoRatings() {
auto_ratings = Com.getDataAPI().getAutoRating();
Expand Down Expand Up @@ -107,6 +111,33 @@ public ArrayList<Mapa> getAllInstances(){
}
return all;
}
public List<Joc> getAllGameInstances(){
return getAllInstances().stream()
.filter(Joc.class::isInstance)
.map(Joc.class::cast)
.collect(Collectors.toList());
}
public InstanceRemovalResult removeGameInstance(String worldName){
for (ContenidorMapa container : Mapes){
if (!(container instanceof ContenidorJoc)) continue;
ContenidorJoc gameContainer = (ContenidorJoc) container;
for (Joc game : new ArrayList<>(gameContainer.Instàncies)){
if (game.getMapName().equalsIgnoreCase(worldName)){
return gameContainer.removeMap(game);
}
}
}
return InstanceRemovalResult.NOT_FOUND;
}
public InstanceJoinResult joinGameInstance(Player player, String worldName){
for (Joc game : getAllGameInstances()){
if (!game.getMapName().equalsIgnoreCase(worldName)) continue;
if (!game.canJoin(player)) return InstanceJoinResult.UNAVAILABLE;
game.Join(player);
return InstanceJoinResult.JOINED;
}
return InstanceJoinResult.NOT_FOUND;
}
public Mapa getMapWherePlayerIs(Player p){
if (lobby.isOnLobby(p)){return null;}
for(Mapa m : getAllInstances()){
Expand All @@ -117,6 +148,14 @@ public Mapa getMapWherePlayerIs(Player p){
//Bukkit.broadcastMessage("Jugador desaparegut");
return null;
}
public Joc createGameInstance(String gameName, Integer mapId){
for (ContenidorMapa container : Mapes){
if (container instanceof ContenidorJoc && container.ClassMapa.getSimpleName().equalsIgnoreCase(gameName)){
return ((ContenidorJoc) container).addMap(mapId);
}
}
return null;
}
public abstract class ContenidorMapa implements Listener{
public lobby plugin;

Expand Down Expand Up @@ -307,25 +346,36 @@ public void onPlayerChangedWorld(PlayerChangedWorldEvent evt) {
if (map != null) {

checkNecessary(map);
}
}
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent evt) {
Joc map = getInstànciaFromWorld(evt.getPlayer().getWorld());
if (map == null) return;
Bukkit.getScheduler().runTask(plugin, () -> checkNecessary(map));
}

void checkNecessary(Joc map){
if (map.getWorld() == null){ Bukkit.broadcastMessage("WORLD: null");return;}
if (!Instàncies.contains(map) || map.getWorld() == null) return;

if(map.getEditMode())return;

if (map.getWorld().getPlayers().size() == 0){
//map.JocFinalitzat();
map.clearExternals();
map.deleteVirtualWorld();
Instàncies.remove(map);
map.destroyEventBus();
System.gc();
//map = null;
//Bukkit.broadcastMessage("Mapa esborrat!");
removeMap(map);
}
}
InstanceRemovalResult removeMap(Joc map){
if (!Instàncies.contains(map)) return InstanceRemovalResult.NOT_FOUND;
if (map.getWorld() == null) return InstanceRemovalResult.UNLOAD_FAILED;
if (!map.getWorld().getPlayers().isEmpty()) return InstanceRemovalResult.HAS_PLAYERS;
if (map.getEditMode()) return InstanceRemovalResult.EDIT_MODE;
if (!map.deleteVirtualWorld()) return InstanceRemovalResult.UNLOAD_FAILED;
map.clearAllExternals();
Instàncies.remove(map);
map.destroyEventBus();
return InstanceRemovalResult.REMOVED;
}
public DyeColor getGameColor(Joc joc){
switch(joc.getGameState()){
case InGame:
Expand Down Expand Up @@ -388,31 +438,36 @@ public void ObrirMenu(Player ply){
if(this.getMapCount() == 0) {

String msg = ChatColor.RED + "" + ChatColor.ITALIC + "No hi ha mapes disponibles";
BountifulAPI.sendActionBar(ply, msg, 150);
PaperMessages.sendActionBar(ply, msg, 150);
ply.playSound(ply.getLocation(), Sound.ENTITY_VILLAGER_NO, 100.0F, 1.0F);
return;

}

for(Joc mapa : Instàncies){
Wool wool = new Wool(getGameColor(mapa));
ItemStack stack = wool.toItemStack();
stack.setAmount(mapa.getPlayers().size());
ItemStack stack = new ItemStack(getWoolMaterial(getGameColor(mapa)));
stack.setAmount(Math.max(1, mapa.getPlayers().size()));
String tStr = new SimpleDateFormat("mm:ss").format(new Date(mapa.tempsTranscorregut()));//Integer.toString(mapa.segonsTranscorreguts());
double gameProgressETA = mapa.getGameProgressETA();
String progressStr = ChatColor.AQUA + "Progrés: " + Math.round(gameProgressETA * 1000) / 10 + "% ETA";
menu.setOption(Instàncies.indexOf(mapa), stack, mapa.getGameName(),ChatColor.WHITE + mapa.NomWorld, ChatColor.WHITE + mapa.getGameState().name(), ChatColor.GREEN + "Jugadors: " + Integer.toString(mapa.getPlayers().size()), ChatColor.YELLOW + "Espectadors:" + mapa.getSpectators().size(), "Temps: " + tStr, progressStr);
menu.setOption(Instàncies.indexOf(mapa), stack,
ChatColor.GREEN + "ENTRAR: " + mapa.NomWorld,
ChatColor.WHITE + mapa.getGameName(),
ChatColor.WHITE + mapa.getGameState().name(),
ChatColor.GREEN + "Jugadors: " + Integer.toString(mapa.getPlayers().size()),
ChatColor.YELLOW + "Espectadors: " + mapa.getSpectators().size(),
"Temps: " + tStr, progressStr);
}
MapMode mapMode = tempInstance.getMapMode();
if (!AlgunMapaDisponible() || mapMode == MapMode.MULTIPLE){
if(mapMode == MapMode.SINGLE)menu.setOption(26, new ItemStack(Material.EMERALD, 1), ChatColor.GREEN + "Afegeix", ChatColor.WHITE + "Crea una nova instància");
if(mapMode == MapMode.SINGLE)menu.setOption(26, new ItemStack(Material.EMERALD, 1),
ChatColor.GREEN + "Afegeix", ChatColor.WHITE + "Crea una nova instància");
if(mapMode == MapMode.MULTIPLE){
ArrayList<String> multiWorldList = tempInstance.getMultiWorldList();
for (int i = 0; i < multiWorldList.size(); i++) {
String name = multiWorldList.get(i);
menu.setOption(26 - i, new ItemStack(Material.EMERALD, 1),
ChatColor.GREEN + name, ChatColor.WHITE
+ "Crear una nova instància");
ChatColor.GREEN + name, ChatColor.WHITE + "Crear una nova instància");
}
}
}
Expand Down Expand Up @@ -441,9 +496,8 @@ public void openAllGamesMenu(Player ply){
});
List<Joc> games = getGames();
for(Joc mapa : games){
Wool wool = new Wool(DyeColor.BLACK);
ItemStack stack = wool.toItemStack();
stack.setAmount(mapa.getPlayers().size());
ItemStack stack = new ItemStack(Material.BLACK_WOOL);
stack.setAmount(Math.max(1, mapa.getPlayers().size()));
String tStr = new SimpleDateFormat("mm:ss").format(new Date(mapa.tempsTranscorregut()));//Integer.toString(mapa.segonsTranscorreguts());
menu.setOption(games.indexOf(mapa), stack, mapa.getGameName(),ChatColor.WHITE + mapa.getGameName() + " (" + mapa.NomWorld + ")", ChatColor.WHITE + mapa.getGameState().name(), ChatColor.GREEN + "Jugadors: " + Integer.toString(mapa.getPlayers().size()), ChatColor.YELLOW + "Espectadors:" + mapa.getSpectators().size(), "Temps: " + tStr);
}
Expand All @@ -465,4 +519,7 @@ public void openAllGamesMenu(Player ply){
public List<Joc> getGames() {
return getAllInstances().stream().filter(m -> m instanceof Joc).map(m -> (Joc)m).collect(Collectors.toList());
}
private Material getWoolMaterial(DyeColor color) {
return Material.valueOf(color.name() + "_WOOL");
}
}
Loading
Loading