Added Lombok, started fake player

This commit is contained in:
Norbi Peti 2017-07-03 23:45:14 +02:00
parent 92e7e6abc4
commit 39bbeafe6b
8 changed files with 2720 additions and 1540 deletions

15
pom.xml
View file

@ -117,6 +117,10 @@
<id>Essentials</id> <id>Essentials</id>
<url>http://repo.ess3.net/content/repositories/essrel/</url> <url>http://repo.ess3.net/content/repositories/essrel/</url>
</repository> </repository>
<repository>
<id>projectlombok.org</id>
<url>http://projectlombok.org/mavenrepo</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -129,7 +133,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.11-R0.1-SNAPSHOT</version> <version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -154,7 +158,7 @@
<dependency> <dependency>
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault --> <groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
<artifactId>VaultAPI</artifactId> <artifactId>VaultAPI</artifactId>
<version>master-SNAPSHOT</version> <!-- 1.6 --> <version>master-SNAPSHOT</version> <!-- 1.6 -->
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -167,5 +171,12 @@
<artifactId>D4J-OAuth</artifactId> <artifactId>D4J-OAuth</artifactId>
<version>master-SNAPSHOT</version> <version>master-SNAPSHOT</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

File diff suppressed because it is too large Load diff

View file

@ -27,8 +27,8 @@ import sx.blah.discord.api.internal.json.objects.EmbedObject;
import sx.blah.discord.handle.impl.events.ReadyEvent; import sx.blah.discord.handle.impl.events.ReadyEvent;
import sx.blah.discord.handle.obj.*; import sx.blah.discord.handle.obj.*;
import sx.blah.discord.util.*; import sx.blah.discord.util.*;
import sx.blah.discord.util.RequestBuffer.IRequest;
import sx.blah.discord.util.RequestBuffer.IVoidRequest; import sx.blah.discord.util.RequestBuffer.IVoidRequest;
import sx.blah.discord.util.RequestBuffer.RequestFuture;
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> { public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers"; private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
@ -148,27 +148,14 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
"You could make a religion out of this"); "You could make a religion out of this");
} }
} }
/*IDiscordOAuth doa = new DiscordOAuthBuilder(dc).withClientID("226443037893591041") /*
.withClientSecret(getConfig().getString("appsecret")) * IDiscordOAuth doa = new DiscordOAuthBuilder(dc).withClientID("226443037893591041") .withClientSecret(getConfig().getString("appsecret")) .withRedirectUrl("https://" +
.withRedirectUrl("https://" + (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com") * (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com") + ":8081/callback") .withScopes(Scope.IDENTIFY).withHttpServerOptions(new HttpServerOptions().setPort(8081))
+ ":8081/callback") * .withSuccessHandler((rc, user) -> { rc.response().headers().add("Location", "https://" + (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com") + ":8080/login?type=discord&"
.withScopes(Scope.IDENTIFY).withHttpServerOptions(new HttpServerOptions().setPort(8081)) * + rc.request().query()); rc.response().setStatusCode(303); rc.response().end("Redirecting"); rc.response().close(); }).withFailureHandler(rc -> { rc.response().headers().add("Location",
.withSuccessHandler((rc, user) -> { * "https://" + (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com") + ":8080/login?type=discord&" + rc.request().query()); rc.response().setStatusCode(303);
rc.response().headers().add("Location", * rc.response().end("Redirecting"); rc.response().close(); }).build(); getLogger().info("Auth URL: " + doa.buildAuthUrl());
"https://" + (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com") */
+ ":8080/login?type=discord&" + rc.request().query());
rc.response().setStatusCode(303);
rc.response().end("Redirecting");
rc.response().close();
}).withFailureHandler(rc -> {
rc.response().headers().add("Location",
"https://" + (TBMCCoreAPI.IsTestServer() ? "localhost" : "server.figytuna.com")
+ ":8080/login?type=discord&" + rc.request().query());
rc.response().setStatusCode(303);
rc.response().end("Redirecting");
rc.response().close();
}).build();
getLogger().info("Auth URL: " + doa.buildAuthUrl());*/
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while enabling DiscordPlugin!", e); TBMCCoreAPI.SendException("An error occured while enabling DiscordPlugin!", e);
} }
@ -317,30 +304,18 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
/** /**
* Performs Discord actions, retrying when ratelimited. May return null if action fails too many times or in safe mode. * Performs Discord actions, retrying when ratelimited. May return null if action fails too many times or in safe mode.
*/ */
public static <T extends IDiscordObject<T>> T perform(DiscordSupplier<T> action) public static <T> T perform(IRequest<T> action) {
throws DiscordException, MissingPermissionsException { if (SafeMode)
for (int i = 0; i < 20; i++) return null;
try { return RequestBuffer.request(action).get(); // Let the pros handle this
if (SafeMode)
return null;
return action.get();
} catch (RateLimitException e) {
try {
Thread.sleep(e.getRetryDelay() > 0 ? e.getRetryDelay() : 10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
return null;
} }
/** /**
* Performs Discord actions, retrying when ratelimited. * Performs Discord actions, retrying when ratelimited.
*/ */
public static <T> RequestFuture<Void> perform(IVoidRequest action) public static Void perform(IVoidRequest action) {
throws DiscordException, MissingPermissionsException {
if (SafeMode) if (SafeMode)
return null; return null;
return RequestBuffer.request(action); // Let the pros handle this return RequestBuffer.request(action).get(); // Let the pros handle this
} }
} }

View file

@ -97,9 +97,12 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
@Override @Override
public String getName() { public String getName() {
if (user == null) return name == null ? user == null ? "Discord user" : user.getDisplayName(DiscordPlugin.mainServer) : name;
return "Discord user"; }
return name == null ? user.getDisplayName(DiscordPlugin.mainServer) : name;
@Override
public Spigot spigot() {
return new CommandSender.Spigot();
} }
} }

View file

@ -0,0 +1,317 @@
package buttondevteam.discordplugin.playerfaker;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.ServerOperator;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
import buttondevteam.discordplugin.DiscordSenderBase;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser;
@Getter
@Setter
public abstract class DiscordEntity extends DiscordSenderBase implements Entity {
protected DiscordEntity(IUser user, IChannel channel, int entityId, UUID uuid) {
super(user, channel);
this.entityId = entityId;
uniqueId = uuid;
}
private HashMap<String, MetadataValue> metadata = new HashMap<String, MetadataValue>();
@Delegate
private PermissibleBase perm = new PermissibleBase(new ServerOperator() {
private @Getter @Setter boolean op;
});
private Location location;
private Vector velocity;
private final int entityId;
private EntityDamageEvent lastDamageCause;
private final Set<String> scoreboardTags = new HashSet<String>();
private final UUID uniqueId;
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
metadata.put(metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
return Arrays.asList(metadata.get(metadataKey)); // Who needs multiple data anyways
}
@Override
public boolean hasMetadata(String metadataKey) {
return metadata.containsKey(metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
metadata.remove(metadataKey);
}
@Override
public Location getLocation(Location loc) {
if (loc != null) {
loc.setWorld(getWorld());
loc.setX(location.getX());
loc.setY(location.getY());
loc.setZ(location.getZ());
loc.setYaw(location.getYaw());
loc.setPitch(location.getPitch());
}
return loc;
}
@Override
public double getHeight() {
return 0;
}
@Override
public double getWidth() {
return 0;
}
@Override
public boolean isOnGround() {
return false;
}
@Override
public World getWorld() {
return location.getWorld();
}
@Override
public boolean teleport(Location location) {
this.location = location;
return true;
}
@Override
public boolean teleport(Location location, TeleportCause cause) {
this.location = location;
return true;
}
@Override
public boolean teleport(Entity destination) {
this.location = destination.getLocation();
return true;
}
@Override
public boolean teleport(Entity destination, TeleportCause cause) {
this.location = destination.getLocation();
return true;
}
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
return Arrays.asList();
}
@Override
public int getFireTicks() {
return 0;
}
@Override
public int getMaxFireTicks() {
return 0;
}
@Override
public void setFireTicks(int ticks) {
}
@Override
public void remove() {
}
@Override
public boolean isDead() { // Impossible to kill
return false;
}
@Override
public boolean isValid() {
return true;
}
@Override
public Server getServer() {
return Bukkit.getServer();
}
@Override
public Entity getPassenger() {
return null;
}
@Override
public boolean setPassenger(Entity passenger) {
return false;
}
@Override
public List<Entity> getPassengers() {
return Arrays.asList();
}
@Override
public boolean addPassenger(Entity passenger) {
return false;
}
@Override
public boolean removePassenger(Entity passenger) { // Don't support passengers
return false;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean eject() {
return false;
}
@Override
public float getFallDistance() {
return 0;
}
@Override
public void setFallDistance(float distance) {
}
@Override
public int getTicksLived() {
return 1;
}
@Override
public void setTicksLived(int value) {
}
@Override
public void playEffect(EntityEffect type) {
}
@Override
public boolean isInsideVehicle() {
return false;
}
@Override
public boolean leaveVehicle() {
return false;
}
@Override
public Entity getVehicle() { // Don't support vehicles
return null;
}
@Override
public void setCustomNameVisible(boolean flag) {
}
@Override
public boolean isCustomNameVisible() {
return true;
}
@Override
public void setGlowing(boolean flag) {
}
@Override
public boolean isGlowing() {
return false;
}
@Override
public void setInvulnerable(boolean flag) {
}
@Override
public boolean isInvulnerable() {
return true;
}
@Override
public boolean isSilent() {
return true;
}
@Override
public void setSilent(boolean flag) {
}
@Override
public boolean hasGravity() {
return false;
}
@Override
public void setGravity(boolean gravity) {
}
@Override
public int getPortalCooldown() {
return 0;
}
@Override
public void setPortalCooldown(int cooldown) {
}
@Override
public boolean addScoreboardTag(String tag) {
return scoreboardTags.add(tag);
}
@Override
public boolean removeScoreboardTag(String tag) {
return scoreboardTags.remove(tag);
}
@Override
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.IGNORE;
}
@Override
public Entity.Spigot spigot() {
return new Entity.Spigot();
}
}

View file

@ -0,0 +1,205 @@
package buttondevteam.discordplugin.playerfaker;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.InventoryView.Property;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MainHand;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.PlayerInventory;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser;
public abstract class DiscordHumanEntity extends DiscordLivingEntity implements HumanEntity {
protected DiscordHumanEntity(IUser user, IChannel channel, int entityId, UUID uuid) {
super(user, channel, entityId, uuid);
}
@Override
public PlayerInventory getInventory() { // TODO
return null;
}
@Override
public Inventory getEnderChest() {
// TODO Auto-generated method stub
return null;
}
@Override
public MainHand getMainHand() {
return MainHand.RIGHT;
}
@Override
public boolean setWindowProperty(Property prop, int value) {
return false;
}
@Override
public InventoryView getOpenInventory() {
// TODO Auto-generated method stub
return null;
}
@Override
public InventoryView openInventory(Inventory inventory) {
// TODO Auto-generated method stub
return null;
}
@Override
public InventoryView openWorkbench(Location location, boolean force) {
// TODO Auto-generated method stub
return null;
}
@Override
public InventoryView openEnchanting(Location location, boolean force) {
// TODO Auto-generated method stub
return null;
}
@Override
public void openInventory(InventoryView inventory) {
// TODO Auto-generated method stub
}
@Override
public InventoryView openMerchant(Villager trader, boolean force) {
// TODO Auto-generated method stub
return null;
}
@Override
public InventoryView openMerchant(Merchant merchant, boolean force) {
// TODO Auto-generated method stub
return null;
}
@Override
public void closeInventory() {
// TODO Auto-generated method stub
}
@Override
public ItemStack getItemInHand() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setItemInHand(ItemStack item) {
// TODO Auto-generated method stub
}
@Override
public ItemStack getItemOnCursor() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setItemOnCursor(ItemStack item) {
// TODO Auto-generated method stub
}
@Override
public boolean hasCooldown(Material material) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getCooldown(Material material) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setCooldown(Material material, int ticks) {
// TODO Auto-generated method stub
}
@Override
public boolean isSleeping() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getSleepTicks() {
// TODO Auto-generated method stub
return 0;
}
@Override
public GameMode getGameMode() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setGameMode(GameMode mode) {
// TODO Auto-generated method stub
}
@Override
public boolean isBlocking() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isHandRaised() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getExpToLevel() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Entity getShoulderEntityLeft() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setShoulderEntityLeft(Entity entity) {
// TODO Auto-generated method stub
}
@Override
public Entity getShoulderEntityRight() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setShoulderEntityRight(Entity entity) {
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,303 @@
package buttondevteam.discordplugin.playerfaker;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import lombok.Getter;
import lombok.Setter;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser;
public abstract class DiscordLivingEntity extends DiscordEntity implements LivingEntity {
protected DiscordLivingEntity(IUser user, IChannel channel, int entityId, UUID uuid) {
super(user, channel, entityId, uuid);
}
private @Getter EntityEquipment equipment = new DiscordEntityEquipment(this);
@Getter
@Setter
private static class DiscordEntityEquipment implements EntityEquipment {
private float leggingsDropChance;
private ItemStack leggings;
private float itemInOffHandDropChance;
private ItemStack itemInOffHand;
private float itemInMainHandDropChance;
private ItemStack itemInMainHand;
private float itemInHandDropChance;
private ItemStack itemInHand;
private float helmetDropChance;
private ItemStack helmet;
private float chestplateDropChance;
private ItemStack chestplate;
private float bootsDropChance;
private ItemStack boots;
private ItemStack[] armorContents = new ItemStack[0]; // TODO
private final Entity holder;
public DiscordEntityEquipment(Entity holder) {
this.holder = holder;
}
@Override
public void clear() {
armorContents = new ItemStack[0];
}
}
@Override
public AttributeInstance getAttribute(Attribute attribute) { // We don't support any attribute
return null;
}
@Override
public void damage(double amount) {
}
@Override
public void damage(double amount, Entity source) {
}
@Override
public double getHealth() {
return getMaxHealth();
}
@Override
public void setHealth(double health) {
}
@Override
public double getMaxHealth() {
return 100;
}
@Override
public void setMaxHealth(double health) {
}
@Override
public void resetMaxHealth() {
}
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile) {
return null;
}
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
return null;
}
@Override
public double getEyeHeight() {
return 0;
}
@Override
public double getEyeHeight(boolean ignoreSneaking) {
return 0;
}
@Override
public Location getEyeLocation() {
return getLocation();
}
@Override
public List<Block> getLineOfSight(Set<Material> transparent, int maxDistance) {
return Arrays.asList();
}
@Override
public Block getTargetBlock(HashSet<Byte> transparent, int maxDistance) {
return null;
}
@Override
public Block getTargetBlock(Set<Material> transparent, int maxDistance) {
return null;
}
@Override
public List<Block> getLastTwoTargetBlocks(HashSet<Byte> transparent, int maxDistance) {
return Arrays.asList();
}
@Override
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
return Arrays.asList();
}
@Override
public int getRemainingAir() {
return 100;
}
@Override
public void setRemainingAir(int ticks) {
}
@Override
public int getMaximumAir() {
return 100;
}
@Override
public void setMaximumAir(int ticks) {
}
@Override
public int getMaximumNoDamageTicks() {
return 100;
}
@Override
public void setMaximumNoDamageTicks(int ticks) {
}
@Override
public double getLastDamage() {
return 0;
}
@Override
public void setLastDamage(double damage) {
}
@Override
public int getNoDamageTicks() {
return 100;
}
@Override
public void setNoDamageTicks(int ticks) {
}
@Override
public Player getKiller() {
return null;
}
@Override
public boolean addPotionEffect(PotionEffect effect) {
return false;
}
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
return false;
}
@Override
public boolean addPotionEffects(Collection<PotionEffect> effects) {
return false;
}
@Override
public boolean hasPotionEffect(PotionEffectType type) {
return false;
}
@Override
public PotionEffect getPotionEffect(PotionEffectType type) {
return null;
}
@Override
public void removePotionEffect(PotionEffectType type) {
}
@Override
public Collection<PotionEffect> getActivePotionEffects() {
return Arrays.asList();
}
@Override
public boolean hasLineOfSight(Entity other) {
return false;
}
@Override
public boolean getRemoveWhenFarAway() {
return false;
}
@Override
public void setRemoveWhenFarAway(boolean remove) {
}
@Override
public void setCanPickupItems(boolean pickup) {
}
@Override
public boolean getCanPickupItems() {
return false;
}
@Override
public boolean isLeashed() {
return false;
}
@Override
public Entity getLeashHolder() throws IllegalStateException {
throw new IllegalStateException();
}
@Override
public boolean setLeashHolder(Entity holder) {
return false;
}
@Override
public boolean isGliding() {
return false;
}
@Override
public void setGliding(boolean gliding) {
}
@Override
public void setAI(boolean ai) {
}
@Override
public boolean hasAI() {
return false;
}
@Override
public void setCollidable(boolean collidable) {
}
@Override
public boolean isCollidable() {
return false;
}
}