+ new command framework
+ workbench optimizations ~ refactored commands to fit the new framework
This commit is contained in:
parent
1600996f47
commit
44100f10ad
@ -1,7 +1,7 @@
|
||||
image: maven:3-jdk-8
|
||||
|
||||
build:
|
||||
script: "mvn clean install deploy --settings .gitlab/settings.xml"
|
||||
script: "mvn clean --settings .gitlab/settings.xml"
|
||||
artifacts:
|
||||
name: "Core"
|
||||
paths:
|
||||
|
23
Core.iml
23
Core.iml
@ -20,7 +20,7 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<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: com.destroystokyo.paper:paper-api:1.11.2-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" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
@ -33,13 +33,18 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.10-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-all:5.0.4" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.11-R0.1-SNAPSHOT" level="project" />
|
||||
<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="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.11.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.11.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:craftbukkit:1.11.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:taskchain-bukkit:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:taskchain-core:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.github.lordakkarin:nbt:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:5.0.0.Alpha2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-common:5.0.0.Alpha2" level="project" />
|
||||
<orderEntry type="module" module-name="Commons" />
|
||||
<orderEntry type="library" name="Maven: ai.api:libai:1.4.8" 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" />
|
||||
@ -68,6 +73,7 @@
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.vertx:vertx-rabbitmq-client:3.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.rabbitmq:amqp-client:3.6.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" 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: joda-time:joda-time:2.9.4" level="project" />
|
||||
@ -75,8 +81,9 @@
|
||||
<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: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:simple:0.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:core:0.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ejml:dense64:0.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.gitlab:java-gitlab-api:1.2.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:taskchain-bukkit:3.4.3" level="project" />
|
||||
</component>
|
||||
</module>
|
26
pom.xml
26
pom.xml
@ -64,42 +64,50 @@
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.11-R0.1-SNAPSHOT</version>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.univento</groupId>
|
||||
<artifactId>Commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>taskchain-bukkit</artifactId>
|
||||
<version>3.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.lordakkarin</groupId>
|
||||
<artifactId>nbt</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>eu.univento</groupId>
|
||||
<artifactId>Commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -2,28 +2,25 @@ package eu.univento.core;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import eu.univento.commons.server.TPS;
|
||||
import eu.univento.core.antihack.AntiHack;
|
||||
import eu.univento.core.api.Config;
|
||||
import eu.univento.core.api.command.CommandFramework;
|
||||
import eu.univento.core.api.effects.Blackscreen;
|
||||
import eu.univento.core.api.events.MoveEventFilter;
|
||||
import eu.univento.core.api.items.InventoryManager;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.api.update.PluginUpdater;
|
||||
import eu.univento.core.api.utils.NettyInjection;
|
||||
import eu.univento.core.commands.*;
|
||||
import eu.univento.core.listeners.*;
|
||||
import eu.univento.core.listeners.cloud.Servers;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* main class
|
||||
@ -31,34 +28,17 @@ import java.util.List;
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
@Getter
|
||||
private static Core instance;
|
||||
@Getter
|
||||
private static Commons commons;
|
||||
|
||||
private ArrayList<String> registeredPlugins = new ArrayList<>();
|
||||
|
||||
public void registerPlugin(Plugin plugin) {
|
||||
registeredPlugins.add(plugin.getName());
|
||||
}
|
||||
|
||||
public void unregisterPlugin(Plugin plugin) {
|
||||
if (registeredPlugins.contains(plugin.getName())) registeredPlugins.remove(plugin.getName());
|
||||
}
|
||||
@Getter private static Core instance;
|
||||
@Getter private static Commons commons;
|
||||
@Getter private static CommandFramework commandFramework;
|
||||
|
||||
public static String getNMSVersion() {
|
||||
final String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
private NettyInjection injection;
|
||||
private static List<CustomPlayer> timeout = new LinkedList<>();
|
||||
public static List<CustomPlayer> getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public static Collection<CustomPlayer> getOnlinePlayers() {
|
||||
Collection<CustomPlayer> list = new LinkedList<>();
|
||||
for (Player players : Bukkit.getOnlinePlayers()) {
|
||||
@ -71,8 +51,8 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
commons = new Commons();
|
||||
registerPlugin(this);
|
||||
commons.getLoggingHandler().getCore().info("\n" +
|
||||
|
||||
System.out.println("\n" +
|
||||
"\n" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
@ -114,22 +94,22 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
pm.registerEvents(new SpectatorEvents(), this);
|
||||
pm.registerEvents(new MoveEventFilter(getServer()), this);
|
||||
pm.registerEvents(new InventoryManager(), this);
|
||||
pm.registerEvents(new WorkbenchEvents(), this);
|
||||
pm.registerEvents(new NPCEvents(), this);
|
||||
|
||||
if (ServerSettings.isGame()) {
|
||||
new Fix(this, "fix", "fix your self or other players");
|
||||
new Nick(this, "nick", "nick/unnick your self");
|
||||
}
|
||||
//AntiHack.registerListeners();
|
||||
commandFramework = new CommandFramework(this);
|
||||
|
||||
commandFramework.registerCommands(new DevCommands());
|
||||
commandFramework.registerCommands(new ModCommands());
|
||||
commandFramework.registerCommands(new BuilderCommands());
|
||||
commandFramework.registerCommands(new VIPCommands());
|
||||
commandFramework.registerCommands(new PlayerCommands());
|
||||
|
||||
commandFramework.registerCommands(new HologramCommands());
|
||||
|
||||
new AntiHack().registerListeners();
|
||||
|
||||
new RunAs(this, "RunAs", "run commands as other players");
|
||||
new SystemInfo(this, "SystemInfo", "gives info about the server system");
|
||||
new Vanish(this, "vanish", "vanish/unvanish your self");
|
||||
new GameMode(this, "gamemode", "sets your gamemode", "gm");
|
||||
new SetRank(this, "setrank", "sets the rank for other players", "sr");
|
||||
new GlobalMute(this, "globalmute", "mutes the server");
|
||||
new ChatClear(this, "chatclear", "clears the chat", "cc");
|
||||
new Timeout(this, "timeout", "timeout other players");
|
||||
new Hologram(this, "hologram", "manages holograms");
|
||||
|
||||
PluginMessenger pluginMessenger = new PluginMessenger();
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "5zig_Set");
|
||||
@ -141,8 +121,10 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "PERMISSIONSREPL", pluginMessenger);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "schematica");
|
||||
|
||||
Servers.register();
|
||||
|
||||
Blackscreen.setupUtil(getInstance());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> commons.getLoggingHandler().getCore().info("\n" +
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> System.out.println("\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" _ _ \n" +
|
||||
@ -154,50 +136,16 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
" \n" +
|
||||
" \n" +
|
||||
"\n"), 0L);
|
||||
/*
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
for (Plugin plugin : pm.getPlugins()) {
|
||||
if (!plugin.getName().equalsIgnoreCase("WorldEdit") && !plugin.getName().equalsIgnoreCase("VoxelSniper") && !registeredPlugins.contains(plugin.getName())) {
|
||||
commons.getLoggingHandler().getCore().warn("§cDas Plugin " + plugin.getName() + " ist nicht für den Server zugelassen.");
|
||||
getServer().shutdown();
|
||||
}
|
||||
}
|
||||
}, 5L);
|
||||
|
||||
this.injection = new NettyInjection(this, this.getName());
|
||||
this.injection.addHandler("TIMEOUT", new NettyInjection.PacketHandler() {
|
||||
public Object onPacketIn(Player sender, Channel channel, Object packet) {
|
||||
getCommons().getLoggingHandler().getCore().info("PacketIN: " + sender.getName() + " | " + channel + " | " + packet);
|
||||
if (timeout.contains(CustomPlayer.getPlayer(sender)))
|
||||
return null;
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onPacketOut(Player target, Channel channel, Object packet) {
|
||||
getCommons().getLoggingHandler().getCore().info("PacketOUT: " + target.getName() + " | " + channel + " | " + packet);
|
||||
return packet;
|
||||
}
|
||||
});
|
||||
|
||||
commons.getSecurityHandler().isValidServer(getServer().getIp(), aBoolean -> {
|
||||
if(!aBoolean) {
|
||||
getServer().shutdown();
|
||||
}
|
||||
});
|
||||
*/
|
||||
Bukkit.getScheduler().runTask(this, new TPS());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
commons.shutdown();
|
||||
Bukkit.getMessenger().unregisterIncomingPluginChannel(this);
|
||||
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this);
|
||||
|
||||
//this.injection.disable();
|
||||
|
||||
commons.getLoggingHandler().getCore().info("\n" +
|
||||
System.out.println("\n" +
|
||||
"\n" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
@ -223,8 +171,9 @@ public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
||||
" \n" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
"\nd");
|
||||
new PluginUpdater("Core").update();
|
||||
"\n");
|
||||
//new PluginUpdater("Core").update();
|
||||
commons.shutdown();
|
||||
}
|
||||
|
||||
}
|
@ -3,24 +3,20 @@ package eu.univento.core.antihack;
|
||||
import eu.univento.commons.player.warn.WarnReason;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.antihack.modules.*;
|
||||
import eu.univento.core.antihack.utils.PacketInjector;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AntiHack implements Listener{
|
||||
|
||||
private static final PacketInjector packetInjector = new PacketInjector();
|
||||
|
||||
//TODO: add nofication system
|
||||
public static void registerListeners() {
|
||||
public void registerListeners() {
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new AntiHack(), Core.getInstance());
|
||||
pm.registerEvents(this, Core.getInstance());
|
||||
pm.registerEvents(new Movement(), Core.getInstance());
|
||||
pm.registerEvents(new AutoClicker(), Core.getInstance());
|
||||
pm.registerEvents(new Criticals(), Core.getInstance());
|
||||
@ -32,7 +28,7 @@ public class AntiHack implements Listener{
|
||||
pm.registerEvents(new Nuker(), Core.getInstance());
|
||||
pm.registerEvents(new SelfHit(), Core.getInstance());
|
||||
pm.registerEvents(new BowAimbot(), Core.getInstance());
|
||||
//pm.registerEvents(new KillAura(), Core.getInstance());
|
||||
pm.registerEvents(new Packets(), Core.getInstance());
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), () -> {
|
||||
for(Map.Entry<CustomPlayer, Integer> entry : AutoClicker.clicks.entrySet()) {
|
||||
@ -44,9 +40,4 @@ public class AntiHack implements Listener{
|
||||
}
|
||||
}, 20L, 20L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
packetInjector.addPlayer(e.getPlayer());
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package eu.univento.core.antihack.modules;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.fakeplayer.FakePlayer;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KillAura implements Listener{
|
||||
|
||||
public static final HashMap<Player, FakePlayer> players = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
|
||||
CustomPlayer damager = CustomPlayer.getPlayer((Player) e.getDamager());
|
||||
CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
|
||||
FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, p);
|
||||
players.put(p, fp);
|
||||
fp.spawn(p.getLocation().add((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
fp.removeTablist();
|
||||
fp.despawn();
|
||||
if(players.containsKey(p)) players.remove(p);
|
||||
}, 5L);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ public class Movement implements Listener{
|
||||
if(p.getVehicle() != null) return;
|
||||
if(p.getAllowFlight()) return;
|
||||
double distance = e.getTo().distance(e.getFrom());
|
||||
if(p.getFallDistance() == 0.0F && p.getLocation().getBlock().getRelative(BlockFace.UP).getType() == Material.AIR) {
|
||||
if(p.getFallDistance() == 0.0F && p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
|
||||
if(distance > 0.6D && !p.isOnGround()) {
|
||||
e.setCancelled(true);
|
||||
p.teleport(e.getFrom());
|
||||
|
17
src/main/java/eu/univento/core/antihack/modules/Packets.java
Normal file
17
src/main/java/eu/univento/core/antihack/modules/Packets.java
Normal file
@ -0,0 +1,17 @@
|
||||
package eu.univento.core.antihack.modules;
|
||||
|
||||
import com.destroystokyo.paper.event.player.IllegalPacketEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Packets implements Listener{
|
||||
|
||||
@EventHandler
|
||||
public void onIllegalPacket(IllegalPacketEvent e) {
|
||||
System.out.println("IllegalPacket: " + e.getType() + " | " + e.getExceptionMessage());
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package eu.univento.core.antihack.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.univento.commons.player.warn.WarnReason;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.antihack.modules.KillAura;
|
||||
import eu.univento.core.api.fakeplayer.FakePlayer;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
class PacketHandler extends ChannelDuplexHandler {
|
||||
private final Player player;
|
||||
private final HashMap<Player, Integer> killAura = new HashMap<>();
|
||||
private final HashMap<Player, Integer> count = new HashMap<>();
|
||||
private final HashMap<Player, Long> inventory = new HashMap<>();
|
||||
private final ArrayList<Player> swing = new ArrayList<>();
|
||||
|
||||
public PacketHandler(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception {
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
|
||||
private void destroy(final FakePlayer fp, Player p) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
fp.removeTablist();
|
||||
fp.despawn();
|
||||
if (KillAura.players.containsKey(p)) {
|
||||
KillAura.players.remove(p);
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
|
||||
public void channelRead(final ChannelHandlerContext c, final Object m) throws Exception {
|
||||
if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInArmAnimation")) {
|
||||
swing.add(player);
|
||||
}
|
||||
if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
|
||||
final int id = (int) Reflection.getFieldValue(m, "a");
|
||||
if (Reflection.getFieldValue(m, "action").toString().equals("ATTACK") && KillAura.players.containsKey(player) && id == KillAura.players.get(player).getEntityID()) {
|
||||
if (!killAura.containsKey(player)) {
|
||||
final FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, player);
|
||||
KillAura.players.put(player, fp);
|
||||
fp.spawn(player.getLocation().subtract((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
|
||||
destroy(fp, player);
|
||||
killAura.put(player, 1);
|
||||
return;
|
||||
}
|
||||
if (killAura.containsKey(player) && killAura.get(player) == 1) {
|
||||
final FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, player);
|
||||
KillAura.players.put(player, fp);
|
||||
fp.spawn(player.getLocation().subtract((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
|
||||
destroy(fp, player);
|
||||
killAura.put(player, 2);
|
||||
return;
|
||||
}
|
||||
if (count.get(player) < 4) {
|
||||
count.put(player, count.get(player) + 1);
|
||||
} else {
|
||||
count.remove(player);
|
||||
CustomPlayer p = CustomPlayer.getPlayer(player);
|
||||
p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks");
|
||||
}
|
||||
killAura.remove(player);
|
||||
}
|
||||
}
|
||||
if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInClientCommand")) {
|
||||
final String s = Reflection.getFieldValue(m, "a").toString();
|
||||
if (s.equals("OPEN_INVENTORY_ACHIEVEMENT")) {
|
||||
inventory.put(player, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
super.channelRead(c, m);
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package eu.univento.core.antihack.utils;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class PacketInjector {
|
||||
|
||||
private Field EntityPlayer_playerConnection;
|
||||
private Field PlayerConnection_networkManager;
|
||||
private Field k;
|
||||
private Field m;
|
||||
|
||||
public PacketInjector() {
|
||||
try {
|
||||
this.EntityPlayer_playerConnection = Reflection.getField(Reflection.getClass("{nms}.EntityPlayer"), "playerConnection");
|
||||
Class<?> playerConnection = Reflection.getClass("{nms}.PlayerConnection");
|
||||
this.PlayerConnection_networkManager = Reflection.getField(playerConnection, "networkManager");
|
||||
Class<?> networkManager = Reflection.getClass("{nms}.NetworkManager");
|
||||
Field[] fields2;
|
||||
for (int length = (fields2 = networkManager.getFields()).length, i = 0; i < length; ++i) {
|
||||
final Field fields = fields2[i];
|
||||
if (fields.getType().equals(Channel.class)) {
|
||||
this.k = fields;
|
||||
}
|
||||
}
|
||||
if (this.k == null) {
|
||||
this.k = Reflection.getField(networkManager, "i");
|
||||
}
|
||||
this.m = Reflection.getField(networkManager, "m");
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(final Player p) {
|
||||
try {
|
||||
final Channel ch = this.getChannel(this.getNetworkManager(Reflection.getNmsPlayer(p)));
|
||||
if (ch.pipeline().get("PacketInjector") == null) {
|
||||
final PacketHandler h = new PacketHandler(p);
|
||||
ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(final Player p) {
|
||||
try {
|
||||
final Channel ch = this.getChannel(this.getNetworkManager(Reflection.getNmsPlayer(p)));
|
||||
if (ch.pipeline().get("PacketInjector") != null) {
|
||||
ch.pipeline().remove("PacketInjector");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Object getNetworkManager(final Object ep) {
|
||||
return Reflection.getFieldValue(this.PlayerConnection_networkManager, (Object) Reflection.getFieldValue(this.EntityPlayer_playerConnection, ep));
|
||||
}
|
||||
|
||||
private Channel getChannel(final Object networkManager) {
|
||||
Channel ch;
|
||||
try {
|
||||
ch = Reflection.getFieldValue(this.k, networkManager);
|
||||
} catch (Exception e) {
|
||||
ch = Reflection.getFieldValue(this.m, networkManager);
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package eu.univento.core.antihack.utils;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import net.minecraft.server.v1_11_R1.Packet;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class PacketReader {
|
||||
|
||||
private final Player player;
|
||||
private Channel channel;
|
||||
|
||||
public PacketReader(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void inject() {
|
||||
final CraftPlayer player = (CraftPlayer) this.player;
|
||||
this.channel = player.getHandle().playerConnection.networkManager.channel;
|
||||
this.channel.pipeline().addAfter("decoder", "PacketInjector", new MessageToMessageDecoder<Packet<?>>() {
|
||||
protected void decode(final ChannelHandlerContext arg0, final Packet<?> packet, final List<Object> arg2) throws Exception {
|
||||
arg2.add(packet);
|
||||
PacketReader.this.readPackets(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void uninject() {
|
||||
if (this.channel.pipeline().get("PacketInjector") != null) {
|
||||
this.channel.pipeline().remove("PacketInjector");
|
||||
}
|
||||
}
|
||||
|
||||
private void readPackets(final Packet<?> packet) {
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package eu.univento.core.antihack.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
class Reflection {
|
||||
public static Class<?> getClass(final String classname) {
|
||||
try {
|
||||
final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
final String path = classname.replace("{nms}", "net.minecraft.server." + version).replace("{nm}", "net.minecraft." + version).replace("{cb}", "org.bukkit.craftbukkit.." + version);
|
||||
return Class.forName(path);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getNmsPlayer(final Player p) throws Exception {
|
||||
final Method getHandle = p.getClass().getMethod("getHandle");
|
||||
return getHandle.invoke(p);
|
||||
}
|
||||
|
||||
public static Object getNmsScoreboard(final Scoreboard s) throws Exception {
|
||||
final Method getHandle = s.getClass().getMethod("getHandle");
|
||||
return getHandle.invoke(s);
|
||||
}
|
||||
|
||||
public static Object getFieldValue(final Object instance, final String fieldName) throws Exception {
|
||||
final Field field = instance.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field.get(instance);
|
||||
}
|
||||
|
||||
public static <T> T getFieldValue(final Field field, final Object obj) {
|
||||
try {
|
||||
return (T) field.get(obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(final Class<?> clazz, final String fieldName) throws Exception {
|
||||
final Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static void setValue(final Object instance, final String field, final Object value) {
|
||||
try {
|
||||
final Field f = instance.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendAllPacket(final Object packet) throws Exception {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
final Object nmsPlayer = getNmsPlayer(p);
|
||||
final Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
|
||||
connection.getClass().getMethod("sendPacket", getClass("{nms}.Packet")).invoke(connection, packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendListPacket(final List<String> players, final Object packet) {
|
||||
try {
|
||||
for (final String name : players) {
|
||||
final Object nmsPlayer = getNmsPlayer(Bukkit.getPlayer(name));
|
||||
final Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
|
||||
connection.getClass().getMethod("sendPacket", getClass("{nms}.Packet")).invoke(connection, packet);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPlayerPacket(final Player p, final Object packet) throws Exception {
|
||||
final Object nmsPlayer = getNmsPlayer(p);
|
||||
final Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
|
||||
connection.getClass().getMethod("sendPacket", getClass("{nms}.Packet")).invoke(connection, packet);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package eu.univento.core.api;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
@ -17,6 +16,7 @@ import java.util.List;
|
||||
* @see "http://postcrafter.de/viewtopic.php?f=15&t=143"
|
||||
* @param <P> main class
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AutoCommand<P extends JavaPlugin> extends Command {
|
||||
|
||||
private static String VERSION;
|
||||
@ -24,7 +24,7 @@ public abstract class AutoCommand<P extends JavaPlugin> extends Command {
|
||||
static {
|
||||
String path = Bukkit.getServer().getClass().getPackage().getName();
|
||||
AutoCommand.VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
|
||||
Core.getCommons().getLoggingHandler().getCore().info("AutoCommand hook for Bukkit " + AutoCommand.VERSION);
|
||||
System.out.println("AutoCommand hook for Bukkit " + AutoCommand.VERSION);
|
||||
}
|
||||
|
||||
private final P plugin;
|
||||
|
@ -168,20 +168,10 @@ public class Utils {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), () -> {
|
||||
if(Core.getOnlinePlayers().size() != 0) {
|
||||
for(CustomPlayer players : Core.getOnlinePlayers())
|
||||
//TODO: add connect to optimal lobby server here
|
||||
players.connectToServer("Lobby01");
|
||||
}
|
||||
Bukkit.spigot().restart();
|
||||
}, 10 * 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* shots random firework at specified location
|
||||
*
|
||||
* @param loc Location
|
||||
*/
|
||||
public static void randomFirework(Location loc) {
|
||||
FireworkEffect.Builder builder = FireworkEffect.builder();
|
||||
FireworkEffect effect = builder.flicker(false).trail(false).with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLUE).build();
|
||||
//TODO: make a random fireworks effect
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command Framework - BukkitCommand <br>
|
||||
* An implementation of Bukkit's Command class allowing for registering of
|
||||
* commands without plugin.yml
|
||||
*
|
||||
* @author minnymin3
|
||||
*
|
||||
*/
|
||||
public class BukkitCommand extends org.bukkit.command.Command {
|
||||
|
||||
private final Plugin owningPlugin;
|
||||
private CommandExecutor executor;
|
||||
protected BukkitCompleter completer;
|
||||
|
||||
/**
|
||||
* A slimmed down PluginCommand
|
||||
*/
|
||||
protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
|
||||
super(label);
|
||||
this.executor = executor;
|
||||
this.owningPlugin = owner;
|
||||
this.usageMessage = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
boolean success;
|
||||
|
||||
if (!owningPlugin.isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!testPermission(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
success = executor.onCommand(sender, this, commandLabel, args);
|
||||
} catch (Throwable ex) {
|
||||
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin "
|
||||
+ owningPlugin.getDescription().getFullName(), ex);
|
||||
}
|
||||
|
||||
if (!success && usageMessage.length() > 0) {
|
||||
for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
throws CommandException, IllegalArgumentException {
|
||||
Validate.notNull(sender, "Sender cannot be null");
|
||||
Validate.notNull(args, "Arguments cannot be null");
|
||||
Validate.notNull(alias, "Alias cannot be null");
|
||||
|
||||
List<String> completions = null;
|
||||
try {
|
||||
if (completer != null) {
|
||||
completions = completer.onTabComplete(sender, this, alias, args);
|
||||
}
|
||||
if (completions == null && executor instanceof TabCompleter) {
|
||||
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
|
||||
for (String arg : args) {
|
||||
message.append(arg).append(' ');
|
||||
}
|
||||
message.deleteCharAt(message.length() - 1).append("' in plugin ")
|
||||
.append(owningPlugin.getDescription().getFullName());
|
||||
throw new CommandException(message.toString(), ex);
|
||||
}
|
||||
|
||||
if (completions == null) {
|
||||
return super.tabComplete(sender, alias, args);
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Command Framework - BukkitCompleter <br>
|
||||
* An implementation of the TabCompleter class allowing for multiple tab
|
||||
* completers per command
|
||||
*
|
||||
* @author minnymin3
|
||||
*
|
||||
*/
|
||||
public class BukkitCompleter implements TabCompleter {
|
||||
|
||||
private Map<String, Map.Entry<Method, Object>> completers = new HashMap<>();
|
||||
|
||||
public void addCompleter(String label, Method m, Object obj) {
|
||||
completers.put(label, new AbstractMap.SimpleEntry<>(m, obj));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(label.toLowerCase());
|
||||
for (int x = 0; x < i; x++) {
|
||||
if (!args[x].equals("") && !args[x].equals(" ")) buffer.append(".").append(args[x].toLowerCase());
|
||||
}
|
||||
String cmdLabel = buffer.toString();
|
||||
if (completers.containsKey(cmdLabel)) {
|
||||
Map.Entry<Method, Object> entry = completers.get(cmdLabel);
|
||||
try {
|
||||
return (List<String>) entry.getKey().invoke(entry.getValue(), new CommandArgs(sender, command, label, args, cmdLabel.split("\\.").length - 1));
|
||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
79
src/main/java/eu/univento/core/api/command/Command.java
Normal file
79
src/main/java/eu/univento/core/api/command/Command.java
Normal file
@ -0,0 +1,79 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import eu.univento.commons.player.rank.Group;
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Command Framework - Command <br>
|
||||
* The command annotation used to designate methods as commands. All methods
|
||||
* should have a single CommandArgs argument
|
||||
*
|
||||
* @author minnymin3, joethei
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Command {
|
||||
|
||||
/**
|
||||
* The name of the command. If it is a sub command then its values would be
|
||||
* separated by periods. ie. a command that would be a subcommand of test
|
||||
* would be 'test.subcommandname'
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String name();
|
||||
|
||||
/**
|
||||
* Gets the required permission of the command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Rank rank() default Rank.Player;
|
||||
public Group group() default Group.None;
|
||||
|
||||
public ServerType serverType() default ServerType.NONE;
|
||||
|
||||
/**
|
||||
* The message sent to the player when they do not have permission to
|
||||
* execute it
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String notAllowed() default "§cYou do not have permission to perform that action";
|
||||
|
||||
/**
|
||||
* A list of alternate names that the command is executed under. See
|
||||
* name() for details on how names work
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String[] aliases() default {};
|
||||
|
||||
/**
|
||||
* The description that will appear in /help of the command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String description() default "";
|
||||
|
||||
/**
|
||||
* The usage that will appear in /help (commandname)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String usage() default "";
|
||||
|
||||
/**
|
||||
* Whether or not the command is available to players only
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean inGameOnly() default false;
|
||||
}
|
108
src/main/java/eu/univento/core/api/command/CommandArgs.java
Normal file
108
src/main/java/eu/univento/core/api/command/CommandArgs.java
Normal file
@ -0,0 +1,108 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Command Framework - CommandArgs <br>
|
||||
* This class is passed to the command methods and contains various utilities as
|
||||
* well as the command info.
|
||||
*
|
||||
* @author minnymin3
|
||||
*
|
||||
*/
|
||||
public class CommandArgs {
|
||||
|
||||
private CommandSender sender;
|
||||
private org.bukkit.command.Command command;
|
||||
private String label;
|
||||
private String[] args;
|
||||
|
||||
protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args,
|
||||
int subCommand) {
|
||||
String[] modArgs = new String[args.length - subCommand];
|
||||
for (int i = 0; i < args.length - subCommand; i++) {
|
||||
modArgs[i] = args[i + subCommand];
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(label);
|
||||
for (int x = 0; x < subCommand; x++) {
|
||||
buffer.append("." + args[x]);
|
||||
}
|
||||
String cmdLabel = buffer.toString();
|
||||
this.sender = sender;
|
||||
this.command = command;
|
||||
this.label = cmdLabel;
|
||||
this.args = modArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command sender
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the original command object
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public org.bukkit.command.Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the label including sub command labels of this command
|
||||
*
|
||||
* @return Something like 'test.subcommand'
|
||||
*/
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the arguments after the command's label. ie. if the command
|
||||
* label was test.subcommand and the arguments were subcommand foo foo, it
|
||||
* would only return 'foo foo' because 'subcommand' is part of the command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the argument at the specified index
|
||||
* @param index The index to get
|
||||
* @return The string at the specified index
|
||||
*/
|
||||
public String getArg(int index) {
|
||||
return args[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the command arguments
|
||||
* @return int length of args
|
||||
*/
|
||||
public int length() {
|
||||
return args.length;
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
|
||||
public CustomPlayer getPlayer() {
|
||||
if (sender instanceof Player) {
|
||||
return CustomPlayer.getPlayer((Player) sender);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
220
src/main/java/eu/univento/core/api/command/CommandFramework.java
Normal file
220
src/main/java/eu/univento/core/api/command/CommandFramework.java
Normal file
@ -0,0 +1,220 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import eu.univento.commons.player.rank.Group;
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.help.GenericCommandHelpTopic;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
import org.bukkit.help.HelpTopicComparator;
|
||||
import org.bukkit.help.IndexHelpTopic;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Command Framework - CommandFramework <br>
|
||||
* The main command framework class used for controlling the framework.
|
||||
*
|
||||
* @author minnymin3
|
||||
*/
|
||||
public class CommandFramework implements CommandExecutor {
|
||||
|
||||
private Map<String, Map.Entry<Method, Object>> commandMap = new HashMap<>();
|
||||
private CommandMap map;
|
||||
private Plugin plugin;
|
||||
|
||||
/**
|
||||
* Initializes the command framework and sets up the command maps
|
||||
*/
|
||||
public CommandFramework(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
|
||||
SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
|
||||
try {
|
||||
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||
field.setAccessible(true);
|
||||
map = (CommandMap) field.get(manager);
|
||||
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
|
||||
return handleCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles commands. Used in the onCommand method in your JavaPlugin class
|
||||
*
|
||||
* @param sender The {@link org.bukkit.command.CommandSender} parsed from
|
||||
* onCommand
|
||||
* @param cmd The {@link org.bukkit.command.Command} parsed from onCommand
|
||||
* @param label The label parsed from onCommand
|
||||
* @param args The arguments parsed from onCommand
|
||||
* @return Always returns true for simplicity's sake in onCommand
|
||||
*/
|
||||
public boolean handleCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
|
||||
for (int i = args.length; i >= 0; i--) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(label.toLowerCase());
|
||||
for (int x = 0; x < i; x++) {
|
||||
buffer.append(".").append(args[x].toLowerCase());
|
||||
}
|
||||
String cmdLabel = buffer.toString();
|
||||
if (commandMap.containsKey(cmdLabel)) {
|
||||
Method method = commandMap.get(cmdLabel).getKey();
|
||||
Object methodObject = commandMap.get(cmdLabel).getValue();
|
||||
Command command = method.getAnnotation(Command.class);
|
||||
CustomPlayer player = CustomPlayer.getPlayer((Player) sender);
|
||||
if (Objects.equals(command.group(), Group.None) && !Objects.equals(command.rank(), Rank.Player) && !player.getDatabasePlayer().isAllowed(command.rank())) {
|
||||
sender.sendMessage(command.notAllowed());
|
||||
return true;
|
||||
}
|
||||
if (Objects.equals(command.rank(), Rank.Player) && !Objects.equals(command.group(), Group.None) && !player.getDatabasePlayer().isAllowed(command.group())) {
|
||||
sender.sendMessage(command.notAllowed());
|
||||
return true;
|
||||
}
|
||||
if (command.inGameOnly() && sender == null) {
|
||||
sender.sendMessage("This command is only performable in game");
|
||||
return true;
|
||||
}
|
||||
if (command.serverType() != ServerType.NONE && command.serverType() != ServerType.getServerType()) {
|
||||
sender.sendMessage("This command can only be performed on " + command.serverType().getName() + " servers");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
method.invoke(methodObject, new CommandArgs(sender, cmd, label, args,
|
||||
cmdLabel.split("\\.").length - 1));
|
||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
defaultCommand(new CommandArgs(sender, cmd, label, args, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all command and completer methods inside of the object. Similar
|
||||
* to Bukkit's registerEvents method.
|
||||
*
|
||||
* @param obj The object to register the commands of
|
||||
*/
|
||||
public void registerCommands(Object obj) {
|
||||
for (Method m : obj.getClass().getMethods()) {
|
||||
if (m.getAnnotation(Command.class) != null) {
|
||||
Command command = m.getAnnotation(Command.class);
|
||||
if (m.getParameterTypes().length > 1 || m.getParameterTypes()[0] != CommandArgs.class) {
|
||||
System.out.println("Unable to register command " + m.getName() + ". Unexpected method arguments");
|
||||
continue;
|
||||
}
|
||||
registerCommand(command, command.name(), m, obj);
|
||||
for (String alias : command.aliases()) {
|
||||
registerCommand(command, alias, m, obj);
|
||||
}
|
||||
} else if (m.getAnnotation(Completer.class) != null) {
|
||||
Completer comp = m.getAnnotation(Completer.class);
|
||||
if (m.getParameterTypes().length > 1 || m.getParameterTypes().length == 0
|
||||
|| m.getParameterTypes()[0] != CommandArgs.class) {
|
||||
System.out.println("Unable to register tab completer " + m.getName()
|
||||
+ ". Unexpected method arguments");
|
||||
continue;
|
||||
}
|
||||
if (m.getReturnType() != List.class) {
|
||||
System.out.println("Unable to register tab completer " + m.getName() + ". Unexpected return type");
|
||||
continue;
|
||||
}
|
||||
registerCompleter(comp.name(), m, obj);
|
||||
for (String alias : comp.aliases()) {
|
||||
registerCompleter(alias, m, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all the commands under the plugin's help
|
||||
*/
|
||||
public void registerHelp() {
|
||||
Set<HelpTopic> help = new TreeSet<>(HelpTopicComparator.helpTopicComparatorInstance());
|
||||
for (String s : commandMap.keySet()) {
|
||||
if (!s.contains(".")) {
|
||||
org.bukkit.command.Command cmd = map.getCommand(s);
|
||||
HelpTopic topic = new GenericCommandHelpTopic(cmd);
|
||||
help.add(topic);
|
||||
}
|
||||
}
|
||||
IndexHelpTopic topic = new IndexHelpTopic(plugin.getName(), "All commands for " + plugin.getName(), null, help,
|
||||
"Below is a list of all " + plugin.getName() + " commands:");
|
||||
Bukkit.getServer().getHelpMap().addTopic(topic);
|
||||
}
|
||||
|
||||
public void registerCommand(Command command, String label, Method m, Object obj) {
|
||||
commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
|
||||
commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
|
||||
String cmdLabel = label.split("\\.")[0].toLowerCase();
|
||||
if (map.getCommand(cmdLabel) == null) {
|
||||
org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin);
|
||||
map.register(plugin.getName(), cmd);
|
||||
}
|
||||
if (!command.description().equalsIgnoreCase("") && Objects.equals(cmdLabel, label)) {
|
||||
map.getCommand(cmdLabel).setDescription(command.description());
|
||||
}
|
||||
if (!command.usage().equalsIgnoreCase("") && Objects.equals(cmdLabel, label)) {
|
||||
map.getCommand(cmdLabel).setUsage(command.usage());
|
||||
}
|
||||
}
|
||||
|
||||
public void registerCompleter(String label, Method m, Object obj) {
|
||||
String cmdLabel = label.split("\\.")[0].toLowerCase();
|
||||
if (map.getCommand(cmdLabel) == null) {
|
||||
org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin);
|
||||
map.register(plugin.getName(), command);
|
||||
}
|
||||
if (map.getCommand(cmdLabel) instanceof BukkitCommand) {
|
||||
BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel);
|
||||
if (command.completer == null) {
|
||||
command.completer = new BukkitCompleter();
|
||||
}
|
||||
command.completer.addCompleter(label, m, obj);
|
||||
} else if (map.getCommand(cmdLabel) instanceof PluginCommand) {
|
||||
try {
|
||||
Object command = map.getCommand(cmdLabel);
|
||||
Field field = command.getClass().getDeclaredField("completer");
|
||||
field.setAccessible(true);
|
||||
if (field.get(command) == null) {
|
||||
BukkitCompleter completer = new BukkitCompleter();
|
||||
completer.addCompleter(label, m, obj);
|
||||
field.set(command, completer);
|
||||
} else if (field.get(command) instanceof BukkitCompleter) {
|
||||
BukkitCompleter completer = (BukkitCompleter) field.get(command);
|
||||
completer.addCompleter(label, m, obj);
|
||||
} else {
|
||||
System.out.println("Unable to register tab completer " + m.getName()
|
||||
+ ". A tab completer is already registered for that command!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void defaultCommand(CommandArgs args) {
|
||||
args.getSender().sendMessage(args.getLabel() + " is not handled! Oh noes!");
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/eu/univento/core/api/command/Completer.java
Normal file
37
src/main/java/eu/univento/core/api/command/Completer.java
Normal file
@ -0,0 +1,37 @@
|
||||
package eu.univento.core.api.command;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Command Framework - Completer <br>
|
||||
* The completer annotation used to designate methods as command completers. All
|
||||
* methods should have a single CommandArgs argument and return a String List
|
||||
* object
|
||||
*
|
||||
* @author minnymin3
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Completer {
|
||||
|
||||
/**
|
||||
* The command that this completer completes. If it is a sub command then
|
||||
* its values would be separated by periods. ie. a command that would be a
|
||||
* subcommand of test would be 'test.subcommandname'
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* A list of alternate names that the completer is executed under. See
|
||||
* name() for details on how names work
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String[] aliases() default {};
|
||||
}
|
@ -1,238 +0,0 @@
|
||||
package eu.univento.core.api.fakeplayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.univento.core.Core;
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.3
|
||||
*/
|
||||
public class FakePlayer {
|
||||
|
||||
//TODO: fix parts and add some stuff
|
||||
|
||||
private static final double MOVE_SPEED = 4.3D / 20;
|
||||
|
||||
private final Player player;
|
||||
private final int entityId;
|
||||
private final GameProfile gameProfile;
|
||||
private final DataWatcher dataWatcher;
|
||||
|
||||
private Location location;
|
||||
private ArmorStand armorStand;
|
||||
private LivingEntity target;
|
||||
private BukkitTask task;
|
||||
|
||||
private final boolean moveable;
|
||||
|
||||
public FakePlayer(GameProfile gameProfile, boolean moveable, Player player) {
|
||||
|
||||
this.player = player;
|
||||
|
||||
this.moveable = moveable;
|
||||
|
||||
this.entityId = (int) get(Entity.class, "entityCount");
|
||||
set(Entity.class, null, "entityCount", this.entityId + 1);
|
||||
this.gameProfile = gameProfile;
|
||||
|
||||
this.dataWatcher = new DataWatcher(null);
|
||||
byte status = 0;
|
||||
//this.dataWatcher.a(0, status);
|
||||
//this.dataWatcher.a(10, (byte) 127);
|
||||
//this.dataWatcher.a(6, 20F);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
private final BukkitRunnable tickTask = new BukkitRunnable() {
|
||||
|
||||
private int ticksLiving = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(target != null) {
|
||||
followEntity(target);
|
||||
|
||||
ticksLiving++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
private byte changeMask(byte bitMask, int bit, boolean state) {
|
||||
if(state)
|
||||
return bitMask | 1 << bit;
|
||||
else
|
||||
return bitMask & ~(1 << bit);
|
||||
}
|
||||
*/
|
||||
|
||||
public void setTarget(LivingEntity target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public void clearTarget() {
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
public void setFire(boolean fire) {
|
||||
setStatus(0, fire);
|
||||
}
|
||||
|
||||
public void setSneaking() {
|
||||
setStatus(1, true);
|
||||
}
|
||||
|
||||
public void setSprinting(boolean sprinting) {
|
||||
setStatus(3, sprinting);
|
||||
}
|
||||
|
||||
public void setUseItem(boolean useItem) {
|
||||
setStatus(4, useItem);
|
||||
}
|
||||
|
||||
public void setInvisible(boolean invisible) {
|
||||
setStatus(5, invisible);
|
||||
}
|
||||
|
||||
private void setStatus(int data, boolean bool) {
|
||||
DataWatcher dataWatcher = this.dataWatcher;
|
||||
byte status = 0;
|
||||
//dataWatcher.a(0, status);
|
||||
//dataWatcher.a(10, (byte) 127);
|
||||
//dataWatcher.a(6, 20F);
|
||||
}
|
||||
|
||||
public void followEntity(LivingEntity entity) {
|
||||
double diffX = entity.getLocation().getX() - location.getX();
|
||||
double diffY = (entity.getLocation().getY() + entity.getEyeHeight() * 0.9D) - location.getY() + 1.6F;
|
||||
double diffZ = entity.getLocation().getZ() - location.getZ();
|
||||
double hypoXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
float yaw = (float) (Math.atan2(diffZ, diffX) * 180D / Math.PI) - 90F;
|
||||
float pitch = (float) -(Math.atan2(diffY, hypoXZ) * 18D / Math.PI);
|
||||
look(yaw, pitch);
|
||||
|
||||
if(moveable) {
|
||||
if(Math.abs(diffX) > 3D || Math.abs(diffZ) > 3D) {
|
||||
yaw = (float) Math.toRadians(yaw);
|
||||
double x = Math.sin(yaw);
|
||||
double z = Math.cos(yaw);
|
||||
move(x * MOVE_SPEED, z * MOVE_SPEED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void move(double x, double z) {
|
||||
sendPackets(new PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook(this.entityId, (byte) toFixedPointNumber(x), (byte) toFixedPointNumber(0), (byte) toFixedPointNumber(z), toAngle(location.getYaw()), toAngle(location.getPitch()), true));
|
||||
this.location.add(toFixedPointNumber(x) / 32D, toFixedPointNumber(0) / 32D, toFixedPointNumber(z) / 32D);
|
||||
this.armorStand.teleport(this.location);
|
||||
}
|
||||
|
||||
public void spawn(Location location) {
|
||||
PacketPlayOutNamedEntitySpawn playerSpawn = new PacketPlayOutNamedEntitySpawn();
|
||||
set(playerSpawn, "a", this.entityId);
|
||||
set(playerSpawn, "b", this.gameProfile.getId());
|
||||
set(playerSpawn, "c", toFixedPointNumber(location.getX()));
|
||||
set(playerSpawn, "d", toFixedPointNumber(location.getY()));
|
||||
set(playerSpawn, "e", toFixedPointNumber(location.getZ()));
|
||||
set(playerSpawn, "f", toAngle(location.getYaw()));
|
||||
set(playerSpawn, "g", toAngle(location.getPitch()));
|
||||
set(playerSpawn, "h", 0);
|
||||
set(playerSpawn, "i", this.dataWatcher);
|
||||
|
||||
//XXX: cannot acess PlayerInfoData
|
||||
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
|
||||
//set(playerInfo, "b", Collections.singletonList(playerInfo.new PlayerInfoData(this.gameProfile, 0, WorldSettings.EnumGamemode.NOT_SET, new ChatComponentText(this.gameProfile.getName()))));
|
||||
sendPackets(playerInfo, playerSpawn);
|
||||
|
||||
this.location = location;
|
||||
this.armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
this.armorStand.setGravity(true);
|
||||
this.armorStand.setVisible(false);
|
||||
|
||||
this.task = tickTask.runTaskTimer(Core.getInstance(), 0L, 1L);
|
||||
}
|
||||
//XXX: cannot acess PlayerInfoData
|
||||
public void despawn() {
|
||||
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
|
||||
//set(playerInfo, "b", Collections.singletonList(playerInfo.new PlayerInfoData(this.gameProfile, 0, null, null)));
|
||||
sendPackets(new PacketPlayOutEntityDestroy(this.entityId), playerInfo);
|
||||
|
||||
this.armorStand.remove();
|
||||
this.armorStand = null;
|
||||
this.task.cancel();
|
||||
}
|
||||
|
||||
//XXX: cannot acess PlayerInfoData
|
||||
public void removeTablist() {
|
||||
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
|
||||
//set(playerInfo, "b", Arrays.asList(playerInfo.new PlayerInfoData(this.gameProfile, 0, null, null)));
|
||||
sendPackets(new PacketPlayOutEntityDestroy(this.entityId), playerInfo);
|
||||
}
|
||||
|
||||
|
||||
private void look(float yaw, float pitch) {
|
||||
PacketPlayOutEntityHeadRotation headRotation = new PacketPlayOutEntityHeadRotation();
|
||||
set(headRotation, "a", this.entityId);
|
||||
set(headRotation, "b", toAngle(yaw));
|
||||
sendPackets(headRotation, new PacketPlayOutEntity.PacketPlayOutEntityLook(this.entityId, toAngle(yaw), toAngle(pitch), false));
|
||||
this.location.setYaw(yaw);
|
||||
this.location.setPitch(pitch);
|
||||
}
|
||||
|
||||
private int toFixedPointNumber(double value) {
|
||||
return (int) Math.floor(value * 32D);
|
||||
}
|
||||
|
||||
private byte toAngle(float value) {
|
||||
return (byte) ((int) (value * 256.0F / 360.F));
|
||||
}
|
||||
|
||||
private void sendPackets(Packet<?>... packets) {
|
||||
for(Packet<?> packet : packets)
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
private void set(Object instance, String name, Object value) {
|
||||
set(instance.getClass(), instance, name, value);
|
||||
}
|
||||
|
||||
private void set(Class<?> clazz, Object instance, String name, Object value) {
|
||||
try{
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(instance, value);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Object get(Class<?> clazz, String name) {
|
||||
try{
|
||||
Field field = clazz.getDeclaredField("entityCount");
|
||||
field.setAccessible(true);
|
||||
return field.get(null);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package eu.univento.core.api.fakeplayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.univento.core.api.utils.GameProfileBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
class PlayerKi implements Listener{
|
||||
|
||||
private FakePlayer player;
|
||||
|
||||
private FakePlayer createPlayer(Player p, String uuid, String skinUrl, String capeUrl) {
|
||||
GameProfile gameProfile = GameProfileBuilder.getProfile(UUID.fromString(uuid), "TestUser", skinUrl, capeUrl);
|
||||
return new FakePlayer(gameProfile, true, p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent e) {
|
||||
if(e.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
if(e.getItem().getType() == Material.DIAMOND) {
|
||||
if(this.player != null) {
|
||||
this.player.despawn();
|
||||
}
|
||||
FakePlayer player = createPlayer(e.getPlayer(), e.getPlayer().getUniqueId().toString(),
|
||||
"http://textures.minecraft.net/texture/a116e69a845e227f7ca1fdde8c357c8c821ebd4ba619382ea4a1f87d4ae94",
|
||||
"http://textures.minecraft.net/texture/3f688e0e699b3d9fe448b5bb50a3a288f9c589762b3dae8308842122dcb81");
|
||||
this.player = player;
|
||||
player.spawn(e.getPlayer().getLocation());
|
||||
player.setTarget(e.getPlayer());
|
||||
player.setSneaking();
|
||||
player.removeTablist();
|
||||
}
|
||||
if(e.getItem().getType() == Material.DIAMOND_SWORD) {
|
||||
player.despawn();
|
||||
}
|
||||
if(e.getItem().getType() == Material.NETHER_STAR) {
|
||||
player.followEntity(e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ 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.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@ -50,13 +51,22 @@ public class Hologram implements Listener{
|
||||
}
|
||||
}
|
||||
|
||||
public void showAll() {
|
||||
for(CustomPlayer p : Core.getOnlinePlayers()) show(p);
|
||||
}
|
||||
|
||||
public void hide(CustomPlayer p) {
|
||||
for(EntityArmorStand stand : stands) {
|
||||
p.sendPacket(new PacketPlayOutEntityDestroy(stand.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
public void hideAll() {
|
||||
for(CustomPlayer p : Core.getOnlinePlayers()) hide(p);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
hideAll();
|
||||
for(EntityArmorStand armorStand : stands) {
|
||||
armorStand.die();
|
||||
}
|
||||
@ -67,7 +77,7 @@ public class Hologram implements Listener{
|
||||
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.setCustomName(ChatColor.translateAlternateColorCodes('&', text));
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setInvisible(true);
|
||||
entity.setNoGravity(true);
|
||||
|
@ -249,6 +249,7 @@ public class ItemBuilder {
|
||||
meta().addEnchant(Enchantment.ARROW_DAMAGE, 10, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the defined {@link String} of lore from the {@link ItemStack}
|
||||
*
|
||||
|
@ -2,152 +2,304 @@ package eu.univento.core.api.npc;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import eu.univento.commons.player.uuid.UUIDFetcher;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.utils.GameProfileBuilder;
|
||||
import lombok.Data;
|
||||
import net.minecraft.server.v1_11_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutNamedEntitySpawn;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.univento.core.api.npc.NPC;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
* @author Ploxh4D, joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class NPC extends EntityPlayer {
|
||||
|
||||
@Data
|
||||
public class NPC{
|
||||
@Getter private static List<NPC> npcs = new LinkedList<>();
|
||||
|
||||
private int entityID;
|
||||
private Location location;
|
||||
private static GameProfile gameProfile;
|
||||
private DataWatcher dataWatcher;
|
||||
public static NPC spawn(CustomPlayer p, GameProfile profile, Location location) {
|
||||
GameProfile npcProfile = new GameProfile(profile.getId(), profile.getName());
|
||||
for(Map.Entry<String, Property> properties : profile.getProperties().entries()) npcProfile.getProperties().put(properties.getKey(), properties.getValue());
|
||||
NPC npc = new NPC(((CraftServer)Bukkit.getServer()).getServer(), ((CraftWorld)p.getWorld()).getHandle(), npcProfile, new PlayerInteractManager(((CraftWorld)p.getWorld()).getHandle()), p, location.getBlockX(), location.getBlockZ());
|
||||
npcProfile.getProperties().put("npc", new Property("npc", "npc"));
|
||||
npcs.add(npc);
|
||||
return npc;
|
||||
}
|
||||
|
||||
public NPC(String name, Location location) {
|
||||
this.location = location;
|
||||
dataWatcher = new DataWatcher(null);
|
||||
gameProfile = new GameProfile(UUID.randomUUID(), name);
|
||||
entityID = (int) (Math.ceil(Math.random() * 1000) + 2000);
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(Core.getInstance(), () -> {
|
||||
try {
|
||||
gameProfile = GameProfileBuilder.fetch(UUIDFetcher.getRequest(name));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
public CustomPlayer detect;
|
||||
public PacketPlayOutNamedEntitySpawn packet;
|
||||
public int x;
|
||||
public int z;
|
||||
public String message;
|
||||
public EntityPlayer player;
|
||||
private BukkitTask task;
|
||||
|
||||
public NPC(final MinecraftServer minecraftserver, final WorldServer worldserver, final GameProfile gameprofile, final PlayerInteractManager playerinteractmanager, final Player player, final int x, final int z) {
|
||||
super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
|
||||
CustomPlayer p = CustomPlayer.getPlayer(player);
|
||||
this.detect = null;
|
||||
this.x = 0;
|
||||
this.z = 0;
|
||||
this.message = "";
|
||||
this.detect = p;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
try {
|
||||
final NetworkManager netManager = new NPCNetworkManager(EnumProtocolDirection.SERVERBOUND);
|
||||
netManager.setPacketListener(this.playerConnection = new NPCPlayerConnection(((CraftServer) Bukkit.getServer()).getServer(), netManager, this));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.setSneaking(this.detect.isSneaking());
|
||||
this.setSprinting(this.detect.isSprinting());
|
||||
this.getBukkitEntity().setCanPickupItems(this.detect.getCanPickupItems());
|
||||
final Location l = this.detect.getLocation();
|
||||
l.setX(l.getX() + x);
|
||||
l.setZ(l.getZ() + z);
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
if (l.getBlock().getRelative(BlockFace.DOWN, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.DOWN, i).getType().isSolid()) {
|
||||
l.setY(l.getY() - (i - 1));
|
||||
i = 500;
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
if (l.getBlock().getRelative(BlockFace.UP, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.UP, i).getType().isSolid()) {
|
||||
l.setY(l.getY() + (i + 1));
|
||||
}
|
||||
if (l.getBlock().getRelative(BlockFace.UP, i + 1).getType() == Material.AIR) {
|
||||
i = 500;
|
||||
}
|
||||
}
|
||||
this.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
||||
if (!l.getBlock().getRelative(BlockFace.UP, 0).getType().isSolid() && !l.getBlock().getRelative(BlockFace.UP, 1).getType().isSolid()) {
|
||||
this.enderTeleportTo(l.getX(), l.getY(), l.getZ());
|
||||
}
|
||||
this.packet = new PacketPlayOutNamedEntitySpawn(this);
|
||||
this.runPlayerUpdate();
|
||||
p.sendPacket(this.packet);
|
||||
this.fauxSleeping = true;
|
||||
this.player = this;
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(NPC npc : npcs) {
|
||||
PacketPlayOutEntityHeadRotation headRotationPacket = new PacketPlayOutEntityHeadRotation(npc.getBukkitEntity().getHandle(), getCompressedAngle(detect.getEyeLocation().getYaw()));
|
||||
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(npc.getBukkitEntity().getHandle());
|
||||
PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true);
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) {
|
||||
player.sendPacket(headRotationPacket);
|
||||
player.sendPacket(teleportPacket);
|
||||
player.sendPacket(metadataPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Core.getInstance(), 0L, 0L);
|
||||
}
|
||||
|
||||
public void spawn() {
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
|
||||
setField(packet, "a", entityID);
|
||||
setField(packet, "b", gameProfile.getId());
|
||||
setField(packet, "c", location.getX());
|
||||
setField(packet, "d", location.getY());
|
||||
setField(packet, "e", location.getZ());
|
||||
setField(packet, "f", location.getYaw());
|
||||
setField(packet, "g", location.getPitch());
|
||||
setField(packet, "h", dataWatcher);
|
||||
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet);
|
||||
}
|
||||
|
||||
public void setSkin(String value, String signature) {
|
||||
gameProfile.getProperties().put("textures", new Property("textures", value, signature));
|
||||
private byte getCompressedAngle(float value) {
|
||||
return (byte) (value * 256.0F / 360F);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(entityID);
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(packet);
|
||||
}
|
||||
|
||||
private void addToTablist() {
|
||||
|
||||
}
|
||||
|
||||
private void removeFromTablist() {
|
||||
|
||||
}
|
||||
|
||||
private void setField(Object instance, String field, Object value) {
|
||||
try {
|
||||
Field f = instance.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
this.task.cancel();
|
||||
for (CustomPlayer players : Core.getOnlinePlayers()) {
|
||||
final PacketPlayOutEntityDestroy teleport = new PacketPlayOutEntityDestroy(player.getId());
|
||||
players.sendPacket(teleport);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int entityID;
|
||||
Location location;
|
||||
GameProfile gameprofile;
|
||||
|
||||
|
||||
public NPC(String name,Location location){
|
||||
entityID = (int)Math.ceil(Math.random() * 1000) + 2000;
|
||||
gameprofile = new GameProfile(UUID.randomUUID(), name);
|
||||
this.location = location;
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void spawn(){
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
public void runPlayerUpdate() {
|
||||
this.task = new BukkitRunnable() {
|
||||
public void run() {
|
||||
if (detect != null) {
|
||||
if (Bukkit.getPlayerExact(detect.getName()) != null) {
|
||||
if (!getBukkitEntity().isDead()) {
|
||||
setSneaking(detect.isSneaking());
|
||||
setSprinting(detect.isSprinting());
|
||||
EnumItemSlot[] values;
|
||||
for (int length = (values = EnumItemSlot.values()).length, j = 0; j < length; ++j) {
|
||||
final EnumItemSlot slot = values[j];
|
||||
final PacketPlayOutEntityEquipment equip = new PacketPlayOutEntityEquipment(getBukkitEntity().getEntityId(), slot, getEquip(slot));
|
||||
for (CustomPlayer players : Core.getOnlinePlayers()) {
|
||||
players.sendPacket(equip);
|
||||
}
|
||||
}
|
||||
final Location l = detect.getLocation();
|
||||
l.setX(l.getX() + x);
|
||||
l.setZ(l.getZ() + z);
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
if (l.getBlock().getRelative(BlockFace.DOWN, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.DOWN, i).getType().isSolid()) {
|
||||
l.setY(l.getY() - (i - 1));
|
||||
i = 500;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
if (l.getBlock().getRelative(BlockFace.UP, i).getType() != Material.AIR && l.getBlock().getRelative(BlockFace.UP, i).getType().isSolid()) {
|
||||
l.setY(l.getY() + (i + 1));
|
||||
}
|
||||
if (l.getBlock().getRelative(BlockFace.UP, i + 1).getType() == Material.AIR) {
|
||||
i = 500;
|
||||
}
|
||||
}
|
||||
if (!l.getBlock().getRelative(BlockFace.UP, 0).getType().isSolid() && !l.getBlock().getRelative(BlockFace.UP, 1).getType().isSolid()) {
|
||||
enderTeleportTo(l.getX(), l.getY(), l.getZ());
|
||||
}
|
||||
NPC.access$0(NPC.this, l.getYaw(), l.getPitch());
|
||||
aK = l.getYaw();
|
||||
aL = l.getYaw();
|
||||
getBukkitEntity().setCanPickupItems(detect.getCanPickupItems());
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
setValue(packet, "a", entityID);
|
||||
setValue(packet, "b", gameprofile.getId());
|
||||
setValue(packet, "c", (int)MathHelper.floor(location.getX() * 32.0D));
|
||||
setValue(packet, "d", (int)MathHelper.floor(location.getY() * 32.0D));
|
||||
setValue(packet, "e", (int)MathHelper.floor(location.getZ() * 32.0D));
|
||||
setValue(packet, "f", (byte) ((int) (location.getYaw() * 256.0F / 360.0F)));
|
||||
setValue(packet, "g", (byte) ((int) (location.getPitch() * 256.0F / 360.0F)));
|
||||
setValue(packet, "h", 0);
|
||||
DataWatcher w = new DataWatcher(null);
|
||||
w.a(6,(float)20);
|
||||
w.a(10,(byte)127);
|
||||
setValue(packet, "i", w);
|
||||
addToTablist();
|
||||
sendPacket(packet);
|
||||
private ItemStack getEquip(final EnumItemSlot slot) {
|
||||
switch (slot) {
|
||||
case MAINHAND: return CraftItemStack.asNMSCopy(detect.getInventory().getItemInMainHand());
|
||||
case OFFHAND: return CraftItemStack.asNMSCopy(detect.getInventory().getItemInOffHand());
|
||||
case FEET: return CraftItemStack.asNMSCopy(detect.getInventory().getBoots());
|
||||
case LEGS: return CraftItemStack.asNMSCopy(detect.getInventory().getLeggings());
|
||||
case CHEST: return CraftItemStack.asNMSCopy(detect.getInventory().getChestplate());
|
||||
case HEAD: return CraftItemStack.asNMSCopy(detect.getInventory().getHelmet());
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(Core.getInstance(), 0L, 0L);
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] {entityID});
|
||||
rmvFromTablist();
|
||||
sendPacket(packet);
|
||||
public boolean damageEntity(final DamageSource damagesource, final float f) {
|
||||
if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.ARROW) {
|
||||
final Arrow a = (Arrow) damagesource.getEntity().getBukkitEntity();
|
||||
if (a.getShooter() != null) {
|
||||
if (a.getShooter() instanceof Player) {
|
||||
final Player shooter = (Player) a.getShooter();
|
||||
if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
|
||||
this.playEffect();
|
||||
this.remove();
|
||||
shooter.sendMessage(this.message);
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.SNOWBALL) {
|
||||
final Snowball a2 = (Snowball) damagesource.getEntity().getBukkitEntity();
|
||||
if (a2.getShooter() != null) {
|
||||
if (a2.getShooter() instanceof Player) {
|
||||
final Player shooter = (Player) a2.getShooter();
|
||||
if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
|
||||
this.playEffect();
|
||||
this.remove();
|
||||
shooter.sendMessage(this.message);
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.EGG) {
|
||||
final Egg a3 = (Egg) damagesource.getEntity().getBukkitEntity();
|
||||
if (a3.getShooter() != null) {
|
||||
if (a3.getShooter() instanceof Player) {
|
||||
final Player shooter = (Player) a3.getShooter();
|
||||
if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
|
||||
this.playEffect();
|
||||
this.remove();
|
||||
shooter.sendMessage(this.message);
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.FIREBALL) {
|
||||
final Fireball a4 = (Fireball) damagesource.getEntity().getBukkitEntity();
|
||||
if (a4.getShooter() != null) {
|
||||
if (a4.getShooter() instanceof Player) {
|
||||
final Player shooter = (Player) a4.getShooter();
|
||||
if (this.detect != null && !shooter.getName().equals(this.detect.getName())) {
|
||||
this.playEffect();
|
||||
this.remove();
|
||||
shooter.sendMessage(this.message);
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
if (damagesource.getEntity().getBukkitEntity().getType() == EntityType.PLAYER && this.detect != null && !damagesource.getEntity().getName().equals(this.detect.getName())) {
|
||||
this.playEffect();
|
||||
this.remove();
|
||||
final Player damager = (Player) damagesource.getEntity().getBukkitEntity();
|
||||
damager.sendMessage(this.message);
|
||||
if (npcs.contains(this)) {
|
||||
npcs.remove(this);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addToTablist(){
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
|
||||
PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packet, "b");
|
||||
players.add(data);
|
||||
|
||||
setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
|
||||
setValue(packet, "b", players);
|
||||
|
||||
sendPacket(packet);
|
||||
public void playEffect() {
|
||||
this.remove();
|
||||
for (final Player all : Bukkit.getOnlinePlayers()) {
|
||||
final Location l = this.getBukkitEntity().getLocation();
|
||||
float i = 0.3f;
|
||||
for (int a = 0; a <= 5; ++a) {
|
||||
i = i + 0.3f;
|
||||
final PacketPlayOutWorldParticles particle = new PacketPlayOutWorldParticles(EnumParticle.CLOUD, true, (float) l.getX(), (float) l.getY() + i, (float) l.getZ(), 0.0f, 0.0f, 0.0f, 0.0f, 10);
|
||||
((CraftPlayer) all).getHandle().playerConnection.sendPacket(particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rmvFromTablist(){
|
||||
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
|
||||
PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packet, "b");
|
||||
players.add(data);
|
||||
|
||||
setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
|
||||
setValue(packet, "b", players);
|
||||
|
||||
sendPacket(packet);
|
||||
public Player getPlayer() {
|
||||
return this.detect;
|
||||
}
|
||||
|
||||
static /* synthetic */ void access$0(final NPC npc, final float n, final float n2) {
|
||||
npc.setYawPitch(n, n2);
|
||||
}
|
||||
*/
|
||||
}
|
67
src/main/java/eu/univento/core/api/npc/NPCChannel.java
Normal file
67
src/main/java/eu/univento/core/api/npc/NPCChannel.java
Normal file
@ -0,0 +1,67 @@
|
||||
package eu.univento.core.api.npc;
|
||||
|
||||
import io.netty.channel.*;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* @author Ploxh4D
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class NPCChannel extends AbstractChannel {
|
||||
private final ChannelConfig config;
|
||||
|
||||
protected NPCChannel(final Channel parent) {
|
||||
super(parent);
|
||||
this.config = new DefaultChannelConfig(this);
|
||||
}
|
||||
|
||||
public ChannelConfig config() {
|
||||
this.config.setAutoRead(true);
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ChannelMetadata metadata() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void doBeginRead() throws Exception {
|
||||
}
|
||||
|
||||
protected void doBind(final SocketAddress arg0) throws Exception {
|
||||
}
|
||||
|
||||
protected void doClose() throws Exception {
|
||||
}
|
||||
|
||||
protected void doDisconnect() throws Exception {
|
||||
}
|
||||
|
||||
protected void doWrite(final ChannelOutboundBuffer arg0) throws Exception {
|
||||
}
|
||||
|
||||
protected boolean isCompatible(final EventLoop arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected SocketAddress localAddress0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected AbstractChannel.AbstractUnsafe newUnsafe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected SocketAddress remoteAddress0() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package eu.univento.core.api.npc;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_11_R1.NetworkManager;
|
||||
|
||||
/**
|
||||
* @author Ploxh4D
|
||||
* @version 1.0
|
||||
*/
|
||||
public class NPCNetworkManager extends NetworkManager{
|
||||
|
||||
public NPCNetworkManager(EnumProtocolDirection enumprotocoldirection) {
|
||||
super(enumprotocoldirection);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.univento.core.api.npc;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_11_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_11_R1.PlayerConnection;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class NPCPlayerConnection extends PlayerConnection{
|
||||
|
||||
public NPCPlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
|
||||
super(minecraftserver, networkmanager, entityplayer);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package eu.univento.core.api.npc.datawatcher;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author ingrim4, joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
enum EnumDataWatcher {
|
||||
|
||||
//TODO: fix field
|
||||
|
||||
ENTITY_BITMASK_00("Entity", "ay"),//
|
||||
ENTITY_AIR_01("Entity", "az"),//AIR
|
||||
ENTITY_NAME_02("Entity", "aA"),//CUSTOM_NAME
|
||||
ENTITY_NAME_VISIBLE_03("Entity", "aB"),//CUSTOM_NAME_VISIBLE
|
||||
ENTITY_SILENT_04("Entity", "aC"),//SILENT
|
||||
|
||||
LIVING_HAND_05("EntityLiving", "as"),
|
||||
LIVING_HEALTH_06("EntityLiving", "HEALTH"),
|
||||
LIVING_POTION_COLOR_07("EntityLiving", "f"),
|
||||
LIVING_POTION_AMBIENT_08("EntityLiving", "g"),
|
||||
LIVING_ARROWS_09("EntityLiving", "h"),
|
||||
|
||||
HUMAN_ABSORTION_10("EntityHuman", ""),
|
||||
HUMAN_SCORE_11("EntityHuman", ""),
|
||||
HUMAN_SKIN_12("EntityHuman", ""),
|
||||
HUMAN_HAND_13("EntityHuman", "");
|
||||
|
||||
@Getter
|
||||
private String owner;
|
||||
@Getter
|
||||
private String field;
|
||||
|
||||
EnumDataWatcher(String owner, String field) {
|
||||
this.owner = owner;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package eu.univento.core.api.npc.datawatcher;
|
||||
|
||||
import eu.univento.core.api.utils.reflection.IReflection;
|
||||
|
||||
/**
|
||||
* @author ingrim4, joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class NullDataWatcher {
|
||||
|
||||
private static final Class<?> CLASS_DATAWATCHER = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher");
|
||||
private static final IReflection.ConstructorAccessor CONSTRUCTOR_DATAWATCHER_ENTITY = IReflection.getConstructor(CLASS_DATAWATCHER, IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "Entity"));
|
||||
|
||||
private static final Class<?> CLASS_DATAWATCHER_OBJECT = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcherObject");
|
||||
|
||||
private static final Class<?> CLASS_DATAWATCHER_ITEM = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE, "DataWatcher$Item");
|
||||
private static final IReflection.MethodAccessor METHOD_DATAWATCHER_ITEM_SETDATA = IReflection.getMethod(CLASS_DATAWATCHER_ITEM, "a", Object.class);
|
||||
|
||||
private static final IReflection.MethodAccessor METHOD_DATAWATCHER_REGISTER = IReflection.getMethod(CLASS_DATAWATCHER, "register", CLASS_DATAWATCHER_OBJECT, Object.class);
|
||||
private static final IReflection.MethodAccessor METHOD_DATAWATCHER_GETITEM = IReflection.getMethod(CLASS_DATAWATCHER, "c", CLASS_DATAWATCHER_OBJECT, Object.class);
|
||||
|
||||
private static final IReflection.MethodAccessor METHOD_DATAWATCHER_C = IReflection.getMethod(CLASS_DATAWATCHER, "c");
|
||||
|
||||
private final Object dataWatcher;
|
||||
|
||||
public NullDataWatcher() {
|
||||
this.dataWatcher = CONSTRUCTOR_DATAWATCHER_ENTITY.newInstance(new Object[]{null});
|
||||
|
||||
}
|
||||
|
||||
public NullDataWatcher add(EnumDataWatcher dataWatcher, Object value) {
|
||||
METHOD_DATAWATCHER_REGISTER.invoke(this.dataWatcher, dataWatcher.getObject(), value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NullDataWatcher update(EnumDataWatcher dataWatcher, Object value) {
|
||||
Object item = METHOD_DATAWATCHER_GETITEM.invoke(this.dataWatcher, dataWatcher.getObject());
|
||||
METHOD_DATAWATCHER_ITEM_SETDATA.invoke(item, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object toPacket() {
|
||||
return METHOD_DATAWATCHER_C.invoke(this.dataWatcher);
|
||||
}
|
||||
|
||||
public Object toNMS() {
|
||||
return this.dataWatcher;
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ import eu.univento.core.api.gui.hologram.HologramData;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.server.v1_11_R1.*;
|
||||
import org.bukkit.*;
|
||||
@ -60,8 +59,7 @@ public class CustomPlayer extends CraftPlayer {
|
||||
|
||||
private final GameProfile gameProfile;
|
||||
|
||||
@Getter
|
||||
private HologramData hologramData;
|
||||
@Getter private HologramData hologramData;
|
||||
|
||||
private CustomPlayer(Player player) {
|
||||
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
||||
@ -79,15 +77,16 @@ public class CustomPlayer extends CraftPlayer {
|
||||
location.put("X", getLocation().getX());
|
||||
location.put("Y", getLocation().getY());
|
||||
location.put("Z", getLocation().getZ());
|
||||
location.put("Yaw", getLocation().getYaw());
|
||||
location.put("Pitch", getLocation().getPitch());
|
||||
location.put("Yaw", String.valueOf(getLocation().getYaw()));
|
||||
location.put("Pitch", String.valueOf(getLocation().getPitch()));
|
||||
|
||||
if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", new JsonObject(location));
|
||||
if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", location);
|
||||
|
||||
if (PLAYERS.containsKey(getUniqueId())) PLAYERS.remove(getUniqueId());
|
||||
}
|
||||
|
||||
public static CustomPlayer getPlayer(String player) {
|
||||
if(Bukkit.getPlayer(player) == null) return null;
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if (PLAYERS.containsKey(p.getUniqueId())) {
|
||||
return PLAYERS.get(p.getUniqueId());
|
||||
@ -120,11 +119,9 @@ public class CustomPlayer extends CraftPlayer {
|
||||
|
||||
public CompletableFuture<Location> getLastLocation() {
|
||||
CompletableFuture<Location> future = new CompletableFuture<>();
|
||||
DATABASE_PLAYER.getObjectFromDatabase("POS").whenComplete((entries, throwable) -> {
|
||||
future.complete(new Location(Bukkit.getWorld("world"), entries.getDouble("X"), entries.getDouble("Y"),
|
||||
entries.getDouble("Z"), entries.getFloat("Yaw"), entries.getFloat("Pitch")));
|
||||
});
|
||||
|
||||
DATABASE_PLAYER.getObjectFromDatabase("POS").whenComplete((entries, throwable) ->
|
||||
future.complete(new Location(Bukkit.getWorld("world"), entries.getDouble("X"), entries.getDouble("Y"), entries.getDouble("Z"),
|
||||
Float.parseFloat(entries.getString("Yaw")), Float.parseFloat(entries.getString("Pitch")))));
|
||||
return future;
|
||||
}
|
||||
|
||||
@ -416,7 +413,7 @@ public class CustomPlayer extends CraftPlayer {
|
||||
ByteBuf byteBuf = Unpooled.copiedBuffer(byteOut.toByteArray());
|
||||
PacketDataSerializer packetDataSerializer = new PacketDataSerializer(byteBuf);
|
||||
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload("LABYMOD", packetDataSerializer);
|
||||
getHandle().playerConnection.sendPacket(packet);
|
||||
sendPacket(packet);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package eu.univento.core.api.player;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
@Getter
|
||||
class Skin {
|
||||
private final String uuid;
|
||||
private String name;
|
||||
@ -17,9 +19,6 @@ class Skin {
|
||||
private String signature;
|
||||
|
||||
Skin(String uuid){this.uuid = uuid;load();}
|
||||
String getSkinValue(){return value;}
|
||||
String getSkinName(){return name;}
|
||||
String getSkinSignature(){return signature;}
|
||||
|
||||
private void load(){
|
||||
try {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.univento.core.api.server;
|
||||
|
||||
import eu.univento.commons.server.ServerInfo;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ package eu.univento.core.api.server;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -36,7 +37,7 @@ public class NetworkData implements PluginMessageListener{
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if(!channel.equals("BungeeCord")) return;
|
||||
|
||||
Core.getCommons().getLoggingHandler().getCore().info("Daten incomming");
|
||||
Core.getCommons().getLoggingHandler().log(ServerType.getServerType(), "Daten incomming");
|
||||
|
||||
ByteArrayDataInput input = ByteStreams.newDataInput(message);
|
||||
String subchannel = input.readUTF();
|
||||
|
@ -1,53 +0,0 @@
|
||||
package eu.univento.core.api.server;
|
||||
|
||||
import eu.univento.commons.server.ServerType;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ServerInfo {
|
||||
|
||||
private final String name;
|
||||
private final ServerPinger pinger;
|
||||
|
||||
public ServerInfo(String name) {
|
||||
this.name = name;
|
||||
pinger = new ServerPinger(name);
|
||||
pinger.ping();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ServerType getGame() {
|
||||
String[] parts = getMotd().split(Pattern.quote(";"));
|
||||
return ServerType.valueOf(parts[0]);
|
||||
}
|
||||
|
||||
public String getGameState() {
|
||||
String[] parts = getMotd().split(Pattern.quote(";"));
|
||||
return parts[1];
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return pinger.isOnline();
|
||||
}
|
||||
|
||||
public int getOnlinePlayers() {
|
||||
return pinger.getPlayerCount();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return pinger.getMaxPlayers();
|
||||
}
|
||||
|
||||
public String getMotd() {
|
||||
//return ServerDatabase.getMotd(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,96 +1,28 @@
|
||||
package eu.univento.core.api.server;
|
||||
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.commands.Build;
|
||||
import eu.univento.core.listeners.Blocks;
|
||||
import org.bukkit.Bukkit;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ServerSettings {
|
||||
|
||||
private static boolean build;
|
||||
private static boolean lobby;
|
||||
private static boolean debug;
|
||||
private static boolean mute;
|
||||
private static boolean game;
|
||||
private static ServerType serverType;
|
||||
private static GameMode gameMode;
|
||||
private static String gameState;
|
||||
|
||||
public static ServerType getServerType() {
|
||||
return serverType;
|
||||
}
|
||||
@Getter @Setter private static boolean lobby;
|
||||
@Getter @Setter private static boolean debug;
|
||||
@Getter @Setter private static boolean mute;
|
||||
@Getter @Setter private static boolean game;
|
||||
@Getter private static ServerType serverType;
|
||||
@Getter @Setter private static GameMode gameMode;
|
||||
@Getter @Setter private static String gameState;
|
||||
@Getter @Setter private static int maxPlayers;
|
||||
|
||||
public static void setServerType(ServerType serverType) {
|
||||
ServerSettings.serverType = serverType;
|
||||
}
|
||||
|
||||
public static GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public static void setGameMode(GameMode gameMode) {
|
||||
ServerSettings.gameMode = gameMode;
|
||||
}
|
||||
|
||||
public static boolean isGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public static void setGame(boolean game) {
|
||||
ServerSettings.game = game;
|
||||
}
|
||||
|
||||
public static boolean isBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
public static void setBuild(boolean build) {
|
||||
ServerSettings.build = build;
|
||||
Core.getCommons().getLoggingHandler().getCore().info("Build ist " + build);
|
||||
if(build) {
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
new Build(Core.getInstance(), "build", "Bau Modus an/ausschalten", "b");
|
||||
pm.registerEvents(new Blocks(), Core.getInstance());
|
||||
Core.getCommons().getLoggingHandler().getCore().info("Build Modus aktiviert");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLobby() {
|
||||
return lobby;
|
||||
}
|
||||
|
||||
public static void setLobby() {
|
||||
ServerSettings.lobby = true;
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static void setDebug() {
|
||||
ServerSettings.debug = true;
|
||||
}
|
||||
|
||||
public static boolean isMute() {
|
||||
return mute;
|
||||
}
|
||||
|
||||
public static void setMute(boolean mute) {
|
||||
ServerSettings.mute = mute;
|
||||
}
|
||||
|
||||
public static String getGameState() {
|
||||
return gameState;
|
||||
}
|
||||
|
||||
public static void setGameState(String gameState) {
|
||||
ServerSettings.gameState = gameState;
|
||||
ServerType.setServerType(serverType);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package eu.univento.core.api.update;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gitlab.api.GitlabAPI;
|
||||
import org.gitlab.api.TokenType;
|
||||
@ -47,7 +48,7 @@ public class PluginUpdater {
|
||||
FileUtils.deleteQuietly(zip);
|
||||
FileUtils.deleteDirectory(output);
|
||||
} catch (IOException e) {
|
||||
Core.getCommons().getLoggingHandler().getCore().error("Failed while trying to update plugin: " + name);
|
||||
Core.getCommons().getLoggingHandler().log(ServerSettings.getServerType(), "Failed while trying to update plugin: " + name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,7 @@
|
||||
|
||||
package eu.univento.core.api.world;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -31,43 +19,9 @@ public class WorldReset {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//TODO: add functionality
|
||||
public World reset() {
|
||||
World world = Bukkit.getWorld(name);
|
||||
if(world.getName().equals("world")) return null;
|
||||
for(Player player : world.getPlayers())
|
||||
player.teleport(Bukkit.getWorld("world").getSpawnLocation());
|
||||
|
||||
Bukkit.unloadWorld(world, true);
|
||||
try {
|
||||
File file = new File(name);
|
||||
FileUtils.deleteDirectory(file);
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
|
||||
HttpGet httpGet = new HttpGet("https://download.univento.eu/world" + name);
|
||||
httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
|
||||
httpGet.addHeader("Referer", "https://www.google.com");
|
||||
|
||||
try {
|
||||
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
|
||||
HttpEntity fileEntity = httpResponse.getEntity();
|
||||
|
||||
if (fileEntity != null) {
|
||||
FileUtils.copyInputStreamToFile(fileEntity.getContent(), new File(name));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
httpGet.releaseConnection();
|
||||
|
||||
//FileUtils.copyURLToFile(new URL(""), file);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Bukkit.createWorld(new WorldCreator(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* lets player build
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Build extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* player who can build
|
||||
*/
|
||||
private static final HashMap<CustomPlayer, ItemStack[]> players = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @return player that can build
|
||||
*/
|
||||
public static HashMap<CustomPlayer, ItemStack[]> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command command
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public Build(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.Builder)) {
|
||||
if(players.containsKey(p)) {
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_OFF());
|
||||
|
||||
ItemStack[] content = players.get(p);
|
||||
p.getInventory().setContents(content);
|
||||
players.remove(p);
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
}else {
|
||||
players.put(p, p.getInventory().getContents());
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_BUILD_ON());
|
||||
p.getInventory().clear();
|
||||
p.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
74
src/main/java/eu/univento/core/commands/BuilderCommands.java
Normal file
74
src/main/java/eu/univento/core/commands/BuilderCommands.java
Normal file
@ -0,0 +1,74 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.command.Completer;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BuilderCommands {
|
||||
|
||||
@Getter private static HashMap<CustomPlayer, ItemStack[]> buildPlayers = new HashMap<>();
|
||||
|
||||
@Command(name = "build", description = "set yourself into build mode", rank = Rank.JrBuilder, inGameOnly = true)
|
||||
public void build(CommandArgs args) {
|
||||
if(buildPlayers.containsKey(args.getPlayer())) {
|
||||
args.getPlayer().getInventory().setContents(buildPlayers.get(args.getPlayer()));
|
||||
buildPlayers.remove(args.getPlayer());
|
||||
args.getPlayer().setGameMode(ServerSettings.getGameMode());
|
||||
}else {
|
||||
buildPlayers.put(args.getPlayer(), args.getPlayer().getInventory().getContents());
|
||||
args.getPlayer().getInventory().clear();
|
||||
args.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Command(name = "gamemode", aliases = {"gm"}, description = "change your gamemode", rank = Rank.Builder, inGameOnly = true)
|
||||
public void gamemode(CommandArgs args) {
|
||||
if(args.length() == 1) {
|
||||
args.getPlayer().setGameMode(getModeFromString(args.getArg(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Completer(name = "gamemode", aliases = {"gm"})
|
||||
public List<String> gameModeCompletor(CommandArgs args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add("0");
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
list.add("Survival");
|
||||
list.add("Creative");
|
||||
list.add("Adventure");
|
||||
list.add("Spectator");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private GameMode getModeFromString(String string) {
|
||||
switch(string) {
|
||||
case "0" : return GameMode.SURVIVAL;
|
||||
case "1" : return GameMode.CREATIVE;
|
||||
case "2": return GameMode.ADVENTURE;
|
||||
case "3" : return GameMode.SPECTATOR;
|
||||
case "Survial" : return GameMode.SURVIVAL;
|
||||
case "Creative" : return GameMode.CREATIVE;
|
||||
case "Adventure" : return GameMode.ADVENTURE;
|
||||
case "Spectator" : return GameMode.SPECTATOR;
|
||||
default: return GameMode.SPECTATOR;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ChatClear extends AutoCommand<Core> {
|
||||
|
||||
public ChatClear(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.Supporter)) {
|
||||
for(int i = 0; i <= 100; i++) {
|
||||
Bukkit.broadcastMessage(" ");
|
||||
}
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
CustomPlayer player = CustomPlayer.getPlayer(players);
|
||||
if (player.getDatabasePlayer().isAllowed(Rank.Supporter)) {
|
||||
//Messages messages = new Messages(player);
|
||||
//player.sendMessage(messages.Core_CHAT_CLEARED(p));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
100
src/main/java/eu/univento/core/commands/DevCommands.java
Normal file
100
src/main/java/eu/univento/core/commands/DevCommands.java
Normal file
@ -0,0 +1,100 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.command.Completer;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DevCommands {
|
||||
|
||||
private ArrayList<CustomPlayer> trolledPlayers = new ArrayList<>();
|
||||
|
||||
@Command(name = "runas", description = "run commands as other players", usage = "runas", rank = Rank.SrDeveloper, inGameOnly = true)
|
||||
public void runAs(CommandArgs args) {
|
||||
if (args.length() >= 2) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args.getArg(0));
|
||||
if (t != null) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (int i = 1; i < args.length(); i++) {
|
||||
msg.append(args.getArg(i)).append(" ");
|
||||
}
|
||||
t.chat(msg.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Completer(name = "runas")
|
||||
public List<String> runAsCompleter(CommandArgs args) {
|
||||
return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@Command(name = "systeminfo", description = "some infos about the system", usage = "/systeminfo", rank = Rank.JrDeveloper, inGameOnly = true)
|
||||
public void systemInfo(CommandArgs args) {
|
||||
CustomPlayer p = args.getPlayer();
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">===");
|
||||
try {
|
||||
p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName());
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.sendMessage("§6TPS: " + Bukkit.getTPS()[0]);
|
||||
p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
|
||||
p.sendMessage("§6Java version: " + System.getProperty("java.version"));
|
||||
p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
|
||||
p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB");
|
||||
}
|
||||
|
||||
@Command(name = "troll", description = "troll other players", usage = "/troll <Troll to execute> <player>", rank = Rank.SrDeveloper, inGameOnly = true)
|
||||
public void troll(CommandArgs args) {
|
||||
args.getPlayer().sendMessage("§eavailable trolls: flip");
|
||||
}
|
||||
|
||||
@Command(name = "troll.flip", description = "flip other players around", usage = "/troll flip <player>", rank = Rank.SrDeveloper, inGameOnly = true)
|
||||
public void trollFlip(CommandArgs args) {
|
||||
if (args.length() == 3) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args.getArg(2));
|
||||
if (t != null && t != args.getPlayer()) {
|
||||
if(trolledPlayers.contains(t)) {
|
||||
t.getSpectatorTarget().remove();
|
||||
t.setGameMode(ServerSettings.getGameMode());
|
||||
trolledPlayers.remove(t);
|
||||
}else {
|
||||
trolledPlayers.add(t);
|
||||
ArmorStand armorStand = t.getWorld().spawn(t.getLocation(), ArmorStand.class);
|
||||
Location armorStandLocation = armorStand.getLocation();
|
||||
t.setGameMode(GameMode.SPECTATOR);
|
||||
t.setSpectatorTarget(armorStand);
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
armorStandLocation.setPitch(armorStandLocation.getPitch() + 0.5F);
|
||||
armorStandLocation.setYaw(armorStandLocation.getYaw() - 0.5F);
|
||||
((CraftEntity) armorStand).getHandle().setPositionRotation(armorStandLocation.getX(), armorStandLocation.getY(), armorStandLocation.getZ(), armorStandLocation.getYaw(), armorStandLocation.getPitch());
|
||||
}
|
||||
}.runTaskTimer(Core.getInstance(), 0, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* fixes players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Fix extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public Fix(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(args.length == 0) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.hidePlayer(p);
|
||||
player.showPlayer(p);
|
||||
}
|
||||
p.teleport(p.getLocation());
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_FIX_OWN());
|
||||
}
|
||||
if(args.length == 1) {
|
||||
if(Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
//Messages tMsgs = new Messages(t);
|
||||
if(t != p) {
|
||||
p.hidePlayer(t);
|
||||
p.showPlayer(t);
|
||||
p.teleport(p.getLocation());
|
||||
//p.sendMessage(msgs.Core_FIX_OTHER(t));
|
||||
//t.sendMessage(tMsgs.Core_FIX_BY_OTHER(p));
|
||||
}else {
|
||||
p.chat("/fix");
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* changes game modes
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GameMode extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param description command description
|
||||
* @param command commons to execute
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public GameMode(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.Builder)) {
|
||||
if(args.length == 1) {
|
||||
String mode = args[0];
|
||||
p.setGameMode(getModeFromString(mode));
|
||||
//p.sendMessage(msgs.Core_GM_CHANGED() + " auf " + p.getGameMode().name());
|
||||
}if(args.length == 0){
|
||||
//p.sendMessage(msgs.Core_GM_USAGE());
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add("0");
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
list.add("Survival");
|
||||
list.add("Creative");
|
||||
list.add("Adventure");
|
||||
list.add("Spectator");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string Mode
|
||||
* @return GameMode
|
||||
*/
|
||||
private org.bukkit.GameMode getModeFromString(String string) {
|
||||
switch(string) {
|
||||
case "0" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "1" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "2": return org.bukkit.GameMode.ADVENTURE;
|
||||
case "3" : return org.bukkit.GameMode.SPECTATOR;
|
||||
case "Survial" : return org.bukkit.GameMode.SURVIVAL;
|
||||
case "Creative" : return org.bukkit.GameMode.CREATIVE;
|
||||
case "Adventure" : return org.bukkit.GameMode.ADVENTURE;
|
||||
case "Spectator" : return org.bukkit.GameMode.SPECTATOR;
|
||||
default: return org.bukkit.GameMode.SPECTATOR;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mutes the whole server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GlobalMute extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public GlobalMute(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.Supporter)) {
|
||||
if(ServerSettings.isMute()) {
|
||||
ServerSettings.setMute(false);
|
||||
//p.sendMessage(msgs.Core_GLOBALMUTE_OFF());
|
||||
}else {
|
||||
ServerSettings.setMute(true);
|
||||
//p.sendMessage(msgs.Core_GLOBALMUTE_ON());
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.language.MessageConstant;
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.utils.Strings;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.hologram.HologramManager;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class Hologram extends AutoCommand<Core> {
|
||||
|
||||
public Hologram(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(((Player) sender));
|
||||
if (p.getDatabasePlayer().isAllowed(Rank.JrBuilder)) {
|
||||
if (args.length == 0) {
|
||||
p.sendMessage("/hologram add <Name> <Nachricht>");
|
||||
p.sendMessage("/hologram remove <Name>");
|
||||
p.sendMessage("/hologram list");
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
HologramManager.getHolograms().forEach((s, hologram) -> p.sendMessage("§6" + s + hologram.getLocation().toString()));
|
||||
}
|
||||
}
|
||||
if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (HologramManager.getHologram(args[1]) != null) {
|
||||
HologramManager.getHologram(args[1]).destroy();
|
||||
} else p.sendMessage("Dieses Hologram gibt es nicht");
|
||||
}
|
||||
} else {
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
if (HologramManager.getHologram(args[1]) != null) {
|
||||
p.sendMessage("Dieses Hologram gibt es schon");
|
||||
} else {
|
||||
String name = args[1];
|
||||
args = Strings.remove(args, "add");
|
||||
args = Strings.remove(args, name);
|
||||
new eu.univento.core.api.hologram.Hologram(name, args, p.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS);
|
||||
}/*
|
||||
}else sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
*/
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.utils.Strings;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.hologram.HologramManager;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class HologramCommands {
|
||||
|
||||
@Command(name = "hologram", description = "create awesome holograms", rank = Rank.Builder, inGameOnly = true)
|
||||
public void hologram(CommandArgs args) {
|
||||
if(args.length() == 0) {
|
||||
args.getPlayer().sendMessage("/hologram add <Name> <Nachricht>");
|
||||
args.getPlayer().sendMessage("/hologram remove <Name>");
|
||||
args.getPlayer().sendMessage("/hologram list");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(name = "hologram.list", description = "lists holograms", rank = Rank.Builder, inGameOnly = true)
|
||||
public void hologramList(CommandArgs args) {
|
||||
HologramManager.getHolograms().forEach((s, hologram) -> args.getPlayer().sendMessage("§6" + s +" | " + hologram.getLocation().toString()));
|
||||
}
|
||||
|
||||
@Command(name = "hologram.add", description = "add holograms", rank = Rank.Builder, inGameOnly = true)
|
||||
public void hologramAdd(CommandArgs args) {
|
||||
if(args.length() > 2) {
|
||||
if (HologramManager.getHologram(args.getArg(1)) != null) {
|
||||
args.getPlayer().sendMessage("§cDieses Hologram gibt es schon");
|
||||
} else {
|
||||
String name = args.getArg(1);
|
||||
String[] text = Strings.remove(args.getArgs(), "add");
|
||||
text = Strings.remove(text, name);
|
||||
new eu.univento.core.api.hologram.Hologram(name, text, args.getPlayer().getLocation()).showAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(name = "hologram.remove", description = "remove holograms", rank = Rank.Builder, inGameOnly = true)
|
||||
public void hologramRemove(CommandArgs args) {
|
||||
if(args.length() == 2) {
|
||||
if (HologramManager.getHologram(args.getArg(1)) != null) {
|
||||
HologramManager.getHologram(args.getArg(1)).destroy();
|
||||
} else args.getPlayer().sendMessage("§cDieses Hologram gibt es nicht");
|
||||
}
|
||||
}
|
||||
}
|
46
src/main/java/eu/univento/core/commands/ModCommands.java
Normal file
46
src/main/java/eu/univento/core/commands/ModCommands.java
Normal file
@ -0,0 +1,46 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ModCommands {
|
||||
|
||||
@Getter private static ArrayList<CustomPlayer> vanishedPlayers = new ArrayList<>();
|
||||
|
||||
@Command(name="chatclear", aliases = {"cc"}, description = "clears the chat", usage = "/clearchat", rank = Rank.JrModerator, inGameOnly = true)
|
||||
public void chatClear(CommandArgs args) {
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) {
|
||||
if(!player.getDatabasePlayer().isAllowed(Rank.JrSupporter)) {
|
||||
for(int i = 0; i <= 100; i++) player.sendMessage("");
|
||||
}else player.sendMessage("§cDer Chat wurde von " + args.getPlayer().getDatabasePlayer().getRank().getColor() + args.getPlayer().getName() + " §cgeleert");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(name="vanish", aliases={"v"}, description = "hide yourself", usage = "/vanish", rank = Rank.JrModerator, inGameOnly = true)
|
||||
public void vanish(CommandArgs args) {
|
||||
if(vanishedPlayers.contains(args.getPlayer())) {
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) player.showPlayer(args.getPlayer());
|
||||
vanishedPlayers.remove(args.getPlayer());
|
||||
}else {
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) player.hidePlayer(args.getPlayer());
|
||||
vanishedPlayers.add(args.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(name = "servermute", aliases = {"smute"}, description = "mute the entire server", usage = "/servermute", rank = Rank.SrModerator, inGameOnly = true)
|
||||
public void serverMute(CommandArgs args) {
|
||||
if(ServerSettings.isMute()) ServerSettings.setMute(false);
|
||||
else ServerSettings.setMute(true);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.NickName;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* nick commons
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Nick extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public Nick(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.VIP)) {
|
||||
if(p.getDatabasePlayer().getSettings().isNicked()) {
|
||||
p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).removeEntry(p.getDisplayName());
|
||||
p.getDatabasePlayer().getSettings().setNickStatus(false);
|
||||
p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName());
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_OFF());
|
||||
p.removeNickName();
|
||||
}else {
|
||||
p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).removeEntry(p.getDisplayName());
|
||||
p.getDatabasePlayer().getSettings().setNickStatus(true);
|
||||
p.getScoreboard().getTeam(p.getDatabasePlayer().getRank().getTeam()).addEntry(p.getDisplayName());
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_NICK_ON());
|
||||
String nick = NickName.getRandomNick();
|
||||
p.setNickName(nick);
|
||||
//Core.getDebugManager().sendOverlay("der Nick ist " + nick);
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/eu/univento/core/commands/PlayerCommands.java
Normal file
47
src/main/java/eu/univento/core/commands/PlayerCommands.java
Normal file
@ -0,0 +1,47 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.language.MessageConstant;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.command.Completer;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class PlayerCommands {
|
||||
|
||||
@Command(name = "fix", usage = "/fix", inGameOnly = true)
|
||||
public void fix(CommandArgs args) {
|
||||
if(args.length() == 0) {
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) {
|
||||
player.hidePlayer(args.getPlayer());
|
||||
player.showPlayer(args.getPlayer());
|
||||
}
|
||||
args.getPlayer().teleport(args.getPlayer().getLocation());
|
||||
|
||||
} if(args.length() == 1) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args.getArg(0));
|
||||
if(t != null) {
|
||||
if(t != args.getPlayer()) {
|
||||
args.getPlayer().hidePlayer(t);
|
||||
args.getPlayer().showPlayer(t);
|
||||
t.teleport(t.getLocation());
|
||||
}else args.getPlayer().chat("/fix");
|
||||
|
||||
}else args.getPlayer().sendMessage(args.getPlayer().getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE));
|
||||
}else {
|
||||
args.getPlayer().chat("/fix");
|
||||
}
|
||||
}
|
||||
|
||||
@Completer(name = "fix")
|
||||
public List<String> fixCompleter(CommandArgs args) {
|
||||
return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* lets other player run commands
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RunAs extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public RunAs(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.SrDeveloper)) {
|
||||
if(args.length >= 2) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
|
||||
if(t != null) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for(int i = 1; i < args.length; i++) {
|
||||
msg.append(args[i]).append(" ");
|
||||
}
|
||||
t.chat(msg.toString());
|
||||
//p.sendMessage(msgs.Core_RUNAS_RUN(t));
|
||||
return true;
|
||||
}else {
|
||||
//p.sendMessage(msgs.NOT_ONLINE(args[0]));
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.Core_RUNAS_USAGE());
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return Core.getOnlinePlayers().stream().map(CustomPlayer::getDisplayName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.server.TPS;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* prints infos about the server
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SystemInfo extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
|
||||
public SystemInfo(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.Developer)) {
|
||||
Runtime run = Runtime.getRuntime();
|
||||
p.sendMessage("§6§l===SystemInfo <" + Bukkit.getServerName() + ">===");
|
||||
try {
|
||||
p.sendMessage("§6Server: " + InetAddress.getLocalHost().getHostName());
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.sendMessage("§6TPS: " + TPS.getTPS());
|
||||
p.sendMessage("§6Spigot version: " + Bukkit.getVersion());
|
||||
p.sendMessage("§6Java version: " + System.getProperty("java.version"));
|
||||
p.sendMessage("§6OS: " + System.getProperty("os.name"));
|
||||
p.sendMessage("§6OS version: " + System.getProperty("os.version"));
|
||||
p.sendMessage("§6OS architecture: " + System.getProperty("os.arch"));
|
||||
p.sendMessage("§6User: " + System.getProperty("user.name"));
|
||||
p.sendMessage("§6used memory: " + (run.totalMemory() - run.freeMemory() / 1048576L) + " MB");
|
||||
p.sendMessage("§6free memory: " + run.freeMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6total memory: " + run.maxMemory() / 1048576L + " MB");
|
||||
p.sendMessage("§6avaiable cores: " + run.availableProcessors());
|
||||
p.sendMessage("§6System: " + System.getenv("COMPUTERNAME"));
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.commons.player.language.MessageConstant;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
|
||||
public class Timeout extends AutoCommand<Core> {
|
||||
|
||||
public Timeout(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer((Player) sender);
|
||||
if (p.getDatabasePlayer().isAllowed(Rank.SrDeveloper)) {
|
||||
if (args.length == 1) {
|
||||
if (Bukkit.getPlayer(args[0]) != null) {
|
||||
CustomPlayer t = CustomPlayer.getPlayer(args[0]);
|
||||
if(Core.getTimeout().contains(p)) {
|
||||
Core.getTimeout().remove(p);
|
||||
}else{
|
||||
Core.getTimeout().add(p);
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NOT_ONLINE));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage("Nicht genug Argumente");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.COMMAND_NO_PERMS));
|
||||
}
|
||||
} else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
26
src/main/java/eu/univento/core/commands/VIPCommands.java
Normal file
26
src/main/java/eu/univento/core/commands/VIPCommands.java
Normal file
@ -0,0 +1,26 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.api.command.Command;
|
||||
import eu.univento.core.api.command.CommandArgs;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.NickName;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class VIPCommands {
|
||||
|
||||
@Command(name = "nick", description = "nick yourself", usage = "/nick", rank = Rank.VIP, inGameOnly = true)
|
||||
public void nick(CommandArgs args) {
|
||||
CustomPlayer p = args.getPlayer();
|
||||
if(p.getDatabasePlayer().getSettings().isNicked()) {
|
||||
p.getDatabasePlayer().getSettings().setNickStatus(false);
|
||||
p.removeNickName();
|
||||
}else {
|
||||
p.getDatabasePlayer().getSettings().setNickStatus(true);
|
||||
p.setNickName(NickName.getRandomNick());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package eu.univento.core.commands;
|
||||
|
||||
import eu.univento.commons.player.rank.Rank;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.AutoCommand;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* vanish players
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class Vanish extends AutoCommand<Core>{
|
||||
|
||||
/**
|
||||
* contains vanished players
|
||||
*/
|
||||
private static final ArrayList<CustomPlayer> players = new ArrayList<>();
|
||||
/**
|
||||
* @return vanished players
|
||||
*/
|
||||
public static ArrayList<CustomPlayer> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin main class
|
||||
* @param command commons to execute
|
||||
* @param description describes the commons
|
||||
* @param aliases aliases of commons
|
||||
*/
|
||||
public Vanish(Core plugin, String command, String description, String... aliases) {
|
||||
super(plugin, command, description, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
if(sender instanceof Player) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(sender.getName());
|
||||
//Messages msgs = new Messages(p);
|
||||
if(p.getDatabasePlayer().isAllowed(Rank.JrSupporter)) {
|
||||
if(players.contains(p)) {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.showPlayer(p);
|
||||
}
|
||||
players.remove(p);
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_OFF());
|
||||
}else {
|
||||
for(Player players : Bukkit.getOnlinePlayers()) {
|
||||
players.hidePlayer(p);
|
||||
}
|
||||
players.add(p);
|
||||
//p.sendMessage(msgs.PREFIX() + msgs.Core_VANISH_ON());
|
||||
}
|
||||
}else {
|
||||
//p.sendMessage(msgs.NO_PERMS());
|
||||
}
|
||||
}else {
|
||||
//sender.sendMessage(Messages.Console.NOT_A_PLAYER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String label, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.commands.Build;
|
||||
import eu.univento.core.commands.BuilderCommands;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -24,7 +24,7 @@ public class Blocks implements Listener{
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p))
|
||||
if(!BuilderCommands.getBuildPlayers().containsKey(p))
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public class Blocks implements Listener{
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!Build.getPlayers().containsKey(p))
|
||||
if(!BuilderCommands.getBuildPlayers().containsKey(p))
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
@ -3,24 +3,16 @@ package eu.univento.core.listeners;
|
||||
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;
|
||||
import eu.univento.core.api.customitems.swords.BestSwordEver;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.api.shop.ShopItem;
|
||||
import eu.univento.core.api.shop.ShopMenu;
|
||||
import eu.univento.core.api.shop.entity.ShopVillager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -44,23 +36,10 @@ public class Chat implements Listener {
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
||||
String message = e.getMessage();
|
||||
|
||||
if (p.getDatabasePlayer().isMuted()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
//TODO: remove this, used for debugging
|
||||
if (message.equalsIgnoreCase("bestswordever")) {
|
||||
new BestSwordEver(p).addItem();
|
||||
}
|
||||
if (message.equalsIgnoreCase("shopvillager")) {
|
||||
ShopMenu menu = new ShopMenu(Core.getInstance(), "Shop Villager", ShopItem.TestItem);
|
||||
new ShopVillager(Core.getInstance(), "Shop Villager", p.getLocation(), Villager.Profession.LIBRARIAN, menu);
|
||||
}
|
||||
if (message.equalsIgnoreCase("miniblock")) {
|
||||
new MiniBlock(p.getLocation(), new ItemStack(Material.GRASS), 1);
|
||||
new MiniBlock(p.getEyeLocation(), new ItemStack(Material.DIAMOND_SWORD), 2);
|
||||
new MiniBlock(p.getWorld().getSpawnLocation(), new ItemStack(Material.WOOL), 3);
|
||||
}
|
||||
|
||||
if (ServerSettings.isMute()) {
|
||||
if (!p.getDatabasePlayer().isAllowed(Rank.Sound)) {
|
||||
e.setCancelled(true);
|
||||
|
@ -3,21 +3,23 @@ package eu.univento.core.listeners;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import eu.univento.core.api.player.SpectateManager;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.commands.Vanish;
|
||||
import eu.univento.core.commands.ModCommands;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* some basic events
|
||||
*
|
||||
@ -27,6 +29,9 @@ import org.bukkit.util.Vector;
|
||||
|
||||
public class Events implements Listener {
|
||||
|
||||
private HashMap<CustomPlayer, Location> seats = new HashMap<>();
|
||||
private HashMap<CustomPlayer, ArmorStand> seatEntities = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onServerListPing(ServerListPingEvent e) {
|
||||
e.setMotd(ServerSettings.getServerType().name() + ";" + (ServerSettings.isGame() ? ServerSettings.getGameState() : ""));
|
||||
@ -38,14 +43,54 @@ public class Events implements Listener {
|
||||
p.setOpenInventory(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(e.getClickedBlock() == null) return;
|
||||
if(e.getClickedBlock().getRelative(BlockFace.DOWN).getType() != Material.ANVIL) return;
|
||||
if(e.getClickedBlock().getState().getData() instanceof Stairs) {
|
||||
loadSeat(p, e.getClickedBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if (p.getLocation().getY() <= 0) {
|
||||
p.setVelocity(new Vector().setY(10.0D).multiply(1.0D));
|
||||
p.setGliding(true);
|
||||
|
||||
}
|
||||
if(e.getFrom().getY() != e.getTo().getY()) {
|
||||
if(!p.isInsideVehicle() && seatEntities.containsKey(p)) {
|
||||
if(seatEntities.get(p).isDead()) {
|
||||
seatEntities.remove(p);
|
||||
if(seats.get(p).getBlock().getState().getData() instanceof Stairs) loadSeat(p, seats.get(p).getBlock());
|
||||
}else {
|
||||
seatEntities.get(p).remove();
|
||||
seatEntities.remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(!p.isInsideVehicle() && seatEntities.containsKey(p)) {
|
||||
seatEntities.get(p).remove();
|
||||
seatEntities.remove(p);
|
||||
seats.remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
despawnSeat(CustomPlayer.getPlayer(e.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onKick(PlayerKickEvent e) {
|
||||
despawnSeat(CustomPlayer.getPlayer(e.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -55,7 +100,7 @@ public class Events implements Listener {
|
||||
final Entity target = e.getTarget();
|
||||
if (!(target instanceof Player)) return;
|
||||
CustomPlayer p = CustomPlayer.getPlayer((Player) target);
|
||||
if (Vanish.getPlayers().contains(p) || SpectateManager.contains(p)) {
|
||||
if (ModCommands.getVanishedPlayers().contains(p) || SpectateManager.contains(p)) {
|
||||
if (entity instanceof Tameable) {
|
||||
e.setTarget(null);
|
||||
}
|
||||
@ -91,4 +136,35 @@ public class Events implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSeat(CustomPlayer p, Block b) {
|
||||
if(seats.containsKey(p) || seats.containsValue(b.getLocation())) return;
|
||||
Location location = b.getLocation();
|
||||
Stairs stairs = (Stairs) b.getState().getData();
|
||||
if(stairs.getFacing() == null) return;
|
||||
location.setDirection(new Vector(stairs.getFacing().getModX(), stairs.getFacing().getModY(), stairs.getFacing().getModZ()));
|
||||
location.setX(location.getBlockX() + 0.5);
|
||||
location.setY(location.getY() + 0.3);
|
||||
location.setZ(location.getBlockZ() + 0.5);
|
||||
ArmorStand stand = p.getWorld().spawn(location, ArmorStand.class);
|
||||
stand.setVisible(false);
|
||||
stand.setMarker(true);
|
||||
stand.setSmall(true);
|
||||
stand.setBasePlate(false);
|
||||
stand.setGravity(false);
|
||||
stand.setPassenger(p);
|
||||
seats.put(p, b.getLocation());
|
||||
seatEntities.put(p, stand);
|
||||
}
|
||||
|
||||
public void despawnSeat(CustomPlayer p) {
|
||||
if (seats.containsKey(p) && seatEntities.containsKey(p)) {
|
||||
seatEntities.get(p).eject();
|
||||
if (seatEntities.get(p) != null) {
|
||||
seatEntities.get(p).remove();
|
||||
}
|
||||
seatEntities.remove(p);
|
||||
seats.remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,8 +4,8 @@ import eu.univento.commons.player.language.MessageConstant;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.player.*;
|
||||
import eu.univento.core.api.server.ServerSettings;
|
||||
import eu.univento.core.commands.Build;
|
||||
import eu.univento.core.commands.Vanish;
|
||||
import eu.univento.core.commands.BuilderCommands;
|
||||
import eu.univento.core.commands.ModCommands;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -45,10 +45,7 @@ public class JoinQuit implements Listener {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
p.getDatabasePlayer().load();
|
||||
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
||||
if (Vanish.getPlayers().contains(player)) {
|
||||
p.hidePlayer(player);
|
||||
}
|
||||
if (SpectateManager.contains(player)) {
|
||||
if (ModCommands.getVanishedPlayers().contains(player) || SpectateManager.contains(player)) {
|
||||
p.hidePlayer(player);
|
||||
}
|
||||
}
|
||||
@ -75,16 +72,18 @@ public class JoinQuit implements Listener {
|
||||
p.setGameMode(ServerSettings.getGameMode());
|
||||
p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
p.initScoreboard();
|
||||
//p.sendTabHeaderAndFooter(p.getMessages().Core_TAB_TITLE() + Bukkit.getServerName(), p.getMessages().TAB_PREFIX());
|
||||
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
|
||||
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
|
||||
p.setNickName(NickName.getRandomNick());
|
||||
}
|
||||
});
|
||||
|
||||
p.sendTabHeaderAndFooter("Nothing to see here", "hello");
|
||||
|
||||
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
||||
p.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> player.getScoreboard().getTeam(rank.getTeam()).addEntry(p.getDisplayName()));
|
||||
player.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> p.getScoreboard().getTeam(rank.getTeam()).addEntry(player.getDisplayName()));
|
||||
}
|
||||
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
|
||||
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
|
||||
p.setNickName(NickName.getRandomNick());
|
||||
}
|
||||
});
|
||||
p.setCollidable(false);
|
||||
|
||||
//p.setStoryResourcePack();
|
||||
@ -116,8 +115,8 @@ public class JoinQuit implements Listener {
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if (Build.getPlayers().containsKey(p))
|
||||
Build.getPlayers().remove(p);
|
||||
if (BuilderCommands.getBuildPlayers().containsKey(p))
|
||||
BuilderCommands.getBuildPlayers().remove(p);
|
||||
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
|
||||
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
|
||||
p.removeNickName();
|
||||
|
@ -1,6 +1,20 @@
|
||||
package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.npc.NPC;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
@ -9,4 +23,48 @@ import org.bukkit.event.Listener;
|
||||
|
||||
public class NPCEvents implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
for(NPC npc : NPC.getNpcs()) p.sendPacket(npc.packet);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
for(NPC npc : NPC.getNpcs()) {
|
||||
if(npc.detect.equals(p)) {
|
||||
PacketPlayOutAnimation animationPacket = new PacketPlayOutAnimation(npc.getBukkitEntity().getHandle(), 0);
|
||||
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(animationPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(p.getItemInHand() != null && p.getItemInHand().getType() == Material.NETHER_STAR && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
||||
for(NPC npc : NPC.getNpcs()) if(npc.detect.equals(p)) {
|
||||
npc.remove();
|
||||
return;
|
||||
}
|
||||
Random random = new Random();
|
||||
for(int i = 0; i <= 10; i++) {
|
||||
NPC.spawn(p, p.getProfile(), new Location(p.getWorld(), p.getLocation().getX() + random.nextInt(10), p.getLocation().getY(), p.getLocation().getZ() - random.nextInt(10)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
for(NPC npc : NPC.getNpcs()) {
|
||||
if (npc.detect.equals(p)) npc.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(PlayerKickEvent e) {
|
||||
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
||||
for(NPC npc : NPC.getNpcs()) {
|
||||
if(npc.detect.equals(p)) npc.remove();
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package eu.univento.core.listeners;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import eu.univento.commons.player.warn.WarnReason;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import eu.univento.core.Core;
|
||||
import eu.univento.core.api.player.CustomPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -39,7 +40,7 @@ public class PluginMessenger implements PluginMessageListener {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Core.getCommons().getLoggingHandler().getCore().info(p.getName() + " hat WDL installiert. Version : " + version);
|
||||
Core.getCommons().getLoggingHandler().log(ServerType.getServerType(), p.getName() + " hat WDL installiert. Version : " + version);
|
||||
p.sendMessage(p.getDatabasePlayer().getLanguage().getWord("Prefix") + p.getDatabasePlayer().getLanguage().getWord("Hack.WorldDownloader"));
|
||||
}
|
||||
if(channel.equals("WDL|CONTROL")) {
|
||||
|
@ -23,7 +23,7 @@ public class WeaponEvents implements Listener {
|
||||
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
sword.primaryAttack();
|
||||
}
|
||||
if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
sword.secondaryAttack();
|
||||
}
|
||||
if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
|
245
src/main/java/eu/univento/core/listeners/WorkbenchEvents.java
Normal file
245
src/main/java/eu/univento/core/listeners/WorkbenchEvents.java
Normal file
@ -0,0 +1,245 @@
|
||||
package eu.univento.core.listeners;
|
||||
|
||||
import eu.univento.core.Core;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Phloxz
|
||||
* @version 1.0
|
||||
*/
|
||||
public class WorkbenchEvents implements Listener {
|
||||
private static Map<Location, List<Player>> workbenchList = new HashMap<>();
|
||||
private static Map<Location, ItemStack[]> workbenchInventory = new HashMap<>();
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void clickWorkbench(final PlayerInteractEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.WORKBENCH) {
|
||||
if (player.getOpenInventory() != null) {
|
||||
player.getOpenInventory().close();
|
||||
}
|
||||
final Location location = e.getClickedBlock().getLocation();
|
||||
if (workbenchList.containsKey(location)) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
Inventory inventory = null;
|
||||
ItemStack[] items = null;
|
||||
if (workbenchList.get(location).size() <= 1) {
|
||||
items = workbenchInventory.get(location);
|
||||
} else {
|
||||
final Player randomPlayer = workbenchList.get(location).get(0);
|
||||
inventory = randomPlayer.getOpenInventory().getTopInventory();
|
||||
}
|
||||
if (inventory != null && inventory.getType() == InventoryType.WORKBENCH) {
|
||||
workbenchInventory.remove(location);
|
||||
}
|
||||
for (int i = 0; i <= 9; ++i) {
|
||||
if (inventory != null) {
|
||||
if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
|
||||
player.getOpenInventory().getTopInventory().setItem(i, inventory.getItem(i));
|
||||
}
|
||||
} else if (items != null && items.length > i && items[i] != null && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
|
||||
player.getOpenInventory().getTopInventory().setItem(i, items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskLater(Core.getInstance(), 2L);
|
||||
workbenchList.get(location).add(player);
|
||||
} else {
|
||||
workbenchList.put(location, new ArrayList<>());
|
||||
workbenchList.get(location).add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void breakWorkbench(final BlockBreakEvent e) {
|
||||
final Location location = e.getBlock().getLocation();
|
||||
if (workbenchList.containsKey(location)) {
|
||||
dropItems(location);
|
||||
workbenchList.remove(location);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickWorkbench(final InventoryClickEvent e) {
|
||||
if (e.getClickedInventory() == null) {
|
||||
return;
|
||||
}
|
||||
if (e.getInventory() == null) {
|
||||
return;
|
||||
}
|
||||
if (e.getClickedInventory().getType() == InventoryType.WORKBENCH && e.getSlot() >= 0 && e.getSlot() <= 9) {
|
||||
final Player player = (Player) e.getWhoClicked();
|
||||
Location location = null;
|
||||
for (final Map.Entry<Location, List<Player>> list : workbenchList.entrySet()) {
|
||||
for (final Player otherPlayer : list.getValue()) {
|
||||
if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getClickedInventory())) {
|
||||
location = list.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
for (final Player otherPlayer2 : workbenchList.get(location)) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
for (int i = 0; i <= 9; ++i) {
|
||||
if (otherPlayer2 != player) {
|
||||
otherPlayer2.getOpenInventory().getTopInventory().setItem(i, player.getOpenInventory().getTopInventory().getItem(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskLater(Core.getInstance(), 2L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void dragEvent(final InventoryDragEvent e) {
|
||||
if (e.getInventory() == null) {
|
||||
return;
|
||||
}
|
||||
if (e.getInventory().getType() == InventoryType.WORKBENCH) {
|
||||
final Player player = (Player) e.getWhoClicked();
|
||||
Location location = null;
|
||||
for (final Map.Entry<Location, List<Player>> list : workbenchList.entrySet()) {
|
||||
for (final Player otherPlayer : list.getValue()) {
|
||||
if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getInventory())) {
|
||||
location = list.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
for (final Player otherPlayer2 : workbenchList.get(location)) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
for (int i = 0; i <= 9; ++i) {
|
||||
if (otherPlayer2 != player) {
|
||||
otherPlayer2.getOpenInventory().getTopInventory().setItem(i, player.getOpenInventory().getTopInventory().getItem(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskLater(Core.getInstance(), 2L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void closeWorkbench(final InventoryCloseEvent e) {
|
||||
Location location = null;
|
||||
for (final Map.Entry<Location, List<Player>> list : workbenchList.entrySet()) {
|
||||
for (final Player otherPlayer : list.getValue()) {
|
||||
if (otherPlayer.getOpenInventory().getTopInventory().equals(e.getInventory())) {
|
||||
location = list.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
final Player player = (Player) e.getPlayer();
|
||||
workbenchList.get(location).remove(player);
|
||||
if (workbenchList.get(location).size() == 0) {
|
||||
if (e.getInventory().getType() == InventoryType.WORKBENCH) {
|
||||
workbenchInventory.put(location, e.getInventory().getContents());
|
||||
e.getInventory().clear();
|
||||
}
|
||||
} else {
|
||||
e.getInventory().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void quitWorkbench(final PlayerQuitEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
Location location = null;
|
||||
for (final Map.Entry<Location, List<Player>> list : workbenchList.entrySet()) {
|
||||
for (final Player otherPlayer : list.getValue()) {
|
||||
if (otherPlayer.equals(player)) {
|
||||
location = list.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
workbenchList.get(location).remove(player);
|
||||
if (workbenchList.get(location).size() == 0 && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
|
||||
workbenchInventory.put(location, player.getOpenInventory().getTopInventory().getContents());
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void kickWorkbench(final PlayerKickEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
Location location = null;
|
||||
for (final Map.Entry<Location, List<Player>> list : workbenchList.entrySet()) {
|
||||
for (final Player otherPlayer : list.getValue()) {
|
||||
if (otherPlayer.equals(player)) {
|
||||
location = list.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
workbenchList.get(location).remove(player);
|
||||
if (workbenchList.get(location).size() == 0 && player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
|
||||
workbenchInventory.put(location, player.getOpenInventory().getTopInventory().getContents());
|
||||
player.getOpenInventory().getTopInventory().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dropItems(final Location loc) {
|
||||
if (loc != null) {
|
||||
if (workbenchInventory.containsKey(loc)) {
|
||||
int id = 0;
|
||||
for (final ItemStack item : workbenchInventory.get(loc)) {
|
||||
if (item != null && item.getType() != Material.AIR && id > 0) {
|
||||
loc.getWorld().dropItemNaturally(loc, item);
|
||||
}
|
||||
++id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final Map.Entry<Location, List<Player>> entry : workbenchList.entrySet()) {
|
||||
for (final Player player : entry.getValue()) {
|
||||
if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory() != null && player.getOpenInventory().getTopInventory().getType() == InventoryType.WORKBENCH) {
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Map.Entry<Location, ItemStack[]> entry2 : workbenchInventory.entrySet()) {
|
||||
final Location location = entry2.getKey();
|
||||
int id2 = 0;
|
||||
for (final ItemStack item2 : entry2.getValue()) {
|
||||
if (item2 != null && item2.getType() != Material.AIR && id2 > 0) {
|
||||
location.getWorld().dropItemNaturally(location, item2);
|
||||
}
|
||||
++id2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
src/main/java/eu/univento/core/listeners/cloud/Servers.java
Normal file
32
src/main/java/eu/univento/core/listeners/cloud/Servers.java
Normal file
@ -0,0 +1,32 @@
|
||||
package eu.univento.core.listeners.cloud;
|
||||
|
||||
import eu.univento.commons.event.MessageEvent;
|
||||
import eu.univento.commons.messaging.MessageHandler;
|
||||
import eu.univento.commons.server.ServerType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Servers {
|
||||
|
||||
public static void register() {
|
||||
MessageHandler.registerListener("cloud.servers", new MessageEvent() {
|
||||
@Override
|
||||
public void onMessageReceived(String queue, String message) {
|
||||
String[] split = message.split(Pattern.quote("|"));
|
||||
if (split[1].equals("INFO") && split[2].equals(Bukkit.getServerName())) {
|
||||
MessageHandler.sendMessage("cloud.servers", split[0] + "|" + Bukkit.getServerName() + "|" + ServerType.getServerType() + "|" + Bukkit.getOnlinePlayers().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageSend(String queue, String message) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user