~ better holograms

+ click events for holograms
This commit is contained in:
Johannes Theiner 2017-04-07 22:44:24 +02:00
parent ad9d1f9235
commit c5ad06d15d
7 changed files with 237 additions and 97 deletions

View File

@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module com.demonwav.mcdev.MinecraftModuleTypes="PAPER_MODULE_TYPE" org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
@ -11,6 +20,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.slikey:EffectLib:5.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.11-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
@ -28,11 +38,35 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.11-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:craftbukkit:1.11-R0.1-SNAPSHOT" level="project" />
<orderEntry type="module" module-name="Commons" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.2.2" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.4.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.16" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" name="Maven: io.vertx:vertx-core:3.4.1" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler-proxy:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-socks:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-http:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-http2:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.8.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: io.vertx:vertx-redis-client:3.4.1" level="project" />
<orderEntry type="library" name="Maven: io.vertx:vertx-mysql-postgresql-client:3.4.1" level="project" />
<orderEntry type="library" name="Maven: io.vertx:vertx-sql-common:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.scala-lang:scala-library:2.12.1" level="project" />
<orderEntry type="library" name="Maven: com.github.mauricio:postgresql-async_2.12:0.2.21" level="project" />
<orderEntry type="library" name="Maven: com.github.mauricio:db-async-common_2.12:0.2.21" level="project" />
<orderEntry type="library" name="Maven: org.joda:joda-convert:1.8.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: com.github.mauricio:mysql-async_2.12:0.2.21" level="project" />
<orderEntry type="library" name="Maven: io.vertx:vertx-mongo-client:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-async:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
@ -43,7 +77,7 @@
<orderEntry type="library" name="Maven: com.github.TheHolyWaffle:TeamSpeak-3-Java-API:v1.0.13" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" />
<orderEntry type="library" name="Maven: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.slikey:EffectLib:5.2" level="project" />
<orderEntry type="library" name="Maven: co.aikar:taskchain-bukkit:3.4.3" level="project" />

View File

@ -1,7 +1,5 @@
package eu.univento.core;
import de.slikey.effectlib.EffectLib;
import de.slikey.effectlib.EffectManager;
import eu.univento.commons.Commons;
import eu.univento.commons.server.TPS;
import eu.univento.core.antihack.AntiHack;
@ -24,7 +22,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@ -38,15 +35,10 @@ import java.util.List;
*/
public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
@Getter
private static EffectLib effectLib = (EffectLib) Bukkit.getPluginManager().getPlugin("EffectLib");
@Getter
private static Core instance;
@Getter
private static Commons commons;
@Getter
private static EffectManager effectManager;
private ArrayList<String> registeredPlugins = new ArrayList<>();
@ -78,12 +70,6 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
return list;
}
public static void broadcast(String key) {
for (CustomPlayer players : getOnlinePlayers()) {
players.sendMessage(players.getDatabasePlayer().getLanguage().getWord(key));
}
}
/*
@Override
public void onLoad() {
@ -110,7 +96,6 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
public void onEnable() {
commons = new Commons();
registerPlugin(this);
effectManager = new EffectManager(this);
commons.getLoggingHandler().getCore().info("\n" +
"\n" +
" \n" +

View File

@ -15,6 +15,8 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
@Deprecated
public class Hologram {
private final List<EntityArmorStand> entitylist = new ArrayList<>();
@ -31,15 +33,15 @@ public class Hologram {
}
public void showPlayerTemp(final CustomPlayer p, int Time){
public void showPlayerTemp(final CustomPlayer p, int time){
showPlayer(p);
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hidePlayer(p), Time);
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hidePlayer(p), time);
}
public void showAllTemp(int Time){
public void showAllTemp(int time){
showAll();
Bukkit.getScheduler().runTaskLater(Core.getInstance(), this::hideAll, Time);
Bukkit.getScheduler().runTaskLater(Core.getInstance(), this::hideAll, time);
}
public void showPlayer(CustomPlayer p) {

View File

@ -14,18 +14,11 @@ public class BorderLeaveEvent extends PlayerEvent {
public BorderLeaveEvent(Player who) {
super(who);
}
public static HandlerList handlers;
public static HandlerList handlers = new HandlerList();
static {
handlers = new HandlerList();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.api.events;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.entity.ArmorStand;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerInteractEntityEvent;
/**
* @author joethei
* @version 0.1
*/
public class HologramClickEvent extends PlayerInteractEntityEvent{
public static HandlerList handlers = new HandlerList();
public HologramClickEvent(CustomPlayer player, ArmorStand armorStand) {
super(player, armorStand);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.api.hologram;
import eu.univento.core.Core;
import eu.univento.core.api.events.HologramClickEvent;
import eu.univento.core.api.player.CustomPlayer;
import net.minecraft.server.v1_11_R1.EntityArmorStand;
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.entity.ArmorStand;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import java.util.ArrayList;
import java.util.List;
/**
* @author joethei
* @version 1.0
*/
public class Hologram implements Listener{
private final List<EntityArmorStand> stands = new ArrayList<>();
private final String[] text;
private final Location location;
private int count;
public Hologram(String[] text, Location location) {
this.text = text;
this.location = location;
create();
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
}
public void show(CustomPlayer p) {
for(EntityArmorStand stand : stands) {
p.sendPacket(new PacketPlayOutSpawnEntityLiving(stand));
}
}
public void hide(CustomPlayer p) {
for(EntityArmorStand stand : stands) {
p.sendPacket(new PacketPlayOutEntityDestroy(stand.getId()));
}
}
public void destroy() {
for(EntityArmorStand armorStand : stands) {
armorStand.die();
}
}
private void create() {
double DISTANCE = 0.25D;
for (String text : this.text) {
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
entity.setCustomName(text);
entity.setCustomNameVisible(true);
entity.setInvisible(true);
entity.setNoGravity(true);
stands.add(entity);
this.location.subtract(0, DISTANCE, 0);
count++;
}
for (int i = 0; i < count; i++) {
this.location.add(0, DISTANCE, 0);
}
this.count = 0;
}
@EventHandler
public void onEntityInteract(PlayerInteractEntityEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
if(e.getRightClicked() instanceof EntityArmorStand) {
if(stands.contains(e.getRightClicked())) {
ArmorStand stand = (ArmorStand) e.getRightClicked();
Bukkit.getPluginManager().callEvent(new HologramClickEvent(p, stand));
}
}
}
}

View File

@ -1,6 +1,6 @@
package eu.univento.core.listeners;
import eu.univento.commons.player.Rank;
import eu.univento.commons.player.rank.Rank;
import eu.univento.commons.player.warn.WarnReason;
import eu.univento.core.Core;
import eu.univento.core.api.blocks.MiniBlock;
@ -44,7 +44,13 @@ public class Chat implements Listener {
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
assert p != null;
Messages msgs = p.getMessages();
e.setCancelled(true);
p.getDatabasePlayer().isMuted().whenComplete((aBoolean, throwable) -> {
if (aBoolean) {
p.sendMessage(msgs.PREFIX() + msgs.Core_SERVER_MUTED());
} else {
//TODO: remove this, used for debugging
if (e.getMessage().equalsIgnoreCase("bestswordever")) {
new BestSwordEver(p).addItem();
@ -59,17 +65,12 @@ public class Chat implements Listener {
new MiniBlock(p.getWorld().getSpawnLocation(), new ItemStack(Material.WOOL), 3);
}
Messages msgs = p.getMessages();
if (ServerSettings.isMute()) {
if (!p.getDatabasePlayer().isAllowed(Rank.Sound)) {
e.setCancelled(true);
p.sendMessage(msgs.PREFIX() + msgs.Core_SERVER_MUTED());
}
}
if (p.getDatabasePlayer().isMuted()) {
e.setCancelled(true);
p.sendMessage(msgs.PREFIX() + msgs.Core_SERVER_MUTED());
}
if (players.contains(p)) {
e.setCancelled(true);
p.sendMessage("§cDu musst dich bewegen bevor du chatten kannst");
@ -99,17 +100,22 @@ public class Chat implements Listener {
String message = e.getMessage();
if (e.getFormat().contains("%")) message = message.replace("%", "%%");
if (p.getDatabasePlayer().isAllowed(Rank.Partner)) {
if (p.getDatabasePlayer().isAllowed(Rank.VIP)) {
if (p.getDatabasePlayer().getSettings().isNicked() && !ServerSettings.isLobby()) {
e.setFormat(p.getDatabasePlayer().getRank().getPrefix() + p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + p.getDatabasePlayer().getRank().getSuffix() + ChatColor.translateAlternateColorCodes('&', message));
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendMessage(e.getMessage());
} else {
e.setFormat(p.getDatabasePlayer().getRank().getPrefix() + p.getDisplayName() + p.getDatabasePlayer().getRank().getSuffix() + ChatColor.translateAlternateColorCodes('&', message));
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendMessage(e.getMessage());
}
} else {
e.setFormat(p.getDatabasePlayer().getRank().getPrefix() + p.getDisplayName() + p.getDatabasePlayer().getRank().getSuffix() + message);
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendMessage(e.getMessage());
Core.getOnlinePlayers().stream().filter(player -> e.getMessage().toLowerCase().contains(player.getDisplayName().toLowerCase()) || e.getMessage().toLowerCase().contains(player.getName().toLowerCase())).forEach(player -> player.playSound(p.getEyeLocation(), Sound.BLOCK_NOTE_PLING, 100.0F, 1.0F));
}
}
});
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {