Skip to content

Commit

Permalink
Apply my checkstyle config file on source code
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Sep 22, 2023
1 parent ec5260b commit 8cd7698
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,19 @@
import org.bukkit.scheduler.BukkitRunnable;

public class BukkitPlugin extends JavaPlugin {
private static BukkitPlugin instance;

@Override
public void onLoad() {
instance = this;
}

protected void makeConfig() {
public void onEnable() {
// Make the config file
saveDefaultConfig();
getConfig().options().copyDefaults(true);
saveConfig();
}

@Override
public void onEnable() {
makeConfig();

// Load VR LS
final FileConfiguration config = getConfig();

new BukkitRunnable() {

@Override
public void run() {
int serverProtocol = Via.getAPI().getServerVersion().lowestSupportedVersion();
Expand All @@ -67,15 +60,15 @@ public void run() {
Bukkit.getPluginManager().registerEvents(new BounceListener(), BukkitPlugin.this);
}
if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("sound-fix")) {
Bukkit.getPluginManager().registerEvents(new SoundListener(), BukkitPlugin.this);
Bukkit.getPluginManager().registerEvents(new SoundListener(BukkitPlugin.this), BukkitPlugin.this);
}
// Added in 15w31a (1.9)
if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("ladder-fix")) {
BoundingBoxFixer.fixLadder(serverProtocol);
BoundingBoxFixer.fixLadder(getLogger(), serverProtocol);
}
// Added in 15w32c (1.9)
if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("area-effect-cloud-particles")) {
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(), BukkitPlugin.this);
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(BukkitPlugin.this), BukkitPlugin.this);
}
// Added in 15w40b (1.9)
if (serverProtocol > ProtocolVersion.v1_9.getVersion() && config.getBoolean("elytra-fix")) {
Expand All @@ -87,20 +80,16 @@ public void run() {
}
// Added in 15w44b (1.9)
if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("lily-pad-fix")) {
BoundingBoxFixer.fixLilyPad();
BoundingBoxFixer.fixLilyPad(getLogger());
}
if (serverProtocol >= ProtocolVersion.v1_14_4.getVersion() && config.getBoolean("carpet-fix")) {
BoundingBoxFixer.fixCarpet(serverProtocol);
BoundingBoxFixer.fixCarpet(getLogger(), serverProtocol);
}

if (config.getBoolean("versioninfo.active")) {
new VersionInformer();
new VersionInformer(BukkitPlugin.this, config);
}
}
}.runTaskTimer(this, 1L, 1L);
}

public static BukkitPlugin getInstance() {
return instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BoundingBoxFixer {

public static void fixLilyPad() {
public static void fixLilyPad(final Logger logger) {
try {
final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), "a");

setBoundingBox(boundingBoxField.get(null), 0.0625, 0.0, 0.0625, 0.9375, 0.015625, 0.9375);
} catch (Exception ex) {
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix lily pad bounding box.", ex);
logger.log(Level.SEVERE, "Could not fix lily pad bounding box.", ex);
}
}

public static void fixCarpet(final int serverVersion) {
public static void fixCarpet(final Logger logger, final int serverVersion) {
try {
final Class<?> blockCarpetClass = serverVersion <= ProtocolVersion.v1_16_4.getVersion() ? NMSReflection.getNMSBlock("BlockCarpet") : NMSReflection.getNMSBlock("CarpetBlock");

final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, "a");
setBoundingBox(boundingBoxField.get(0), 0.0D, -0.0000001D, 0.0D, 1.0D, 0.0000001D, 1.0D);
} catch (Exception ex) {
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix carpet bounding box.", ex);
logger.log(Level.SEVERE, "Could not fix carpet bounding box.", ex);
}
}

public static void fixLadder(final int serverVersion) {
public static void fixLadder(final Logger logger, final int serverVersion) {
try {
final boolean pre1_12_2 = serverVersion <= ProtocolVersion.v1_12_2.getVersion();
final boolean pre1_13_2 = serverVersion <= ProtocolVersion.v1_13_2.getVersion();
Expand All @@ -69,7 +70,7 @@ public static void fixLadder(final int serverVersion) {
setBoundingBox(boundingBoxSouthField.get(null), 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
setBoundingBox(boundingBoxNorthField.get(null), 0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
} catch (Exception ex) {
BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix ladder bounding box.", ex);
logger.log(Level.SEVERE, "Could not fix ladder bounding box.", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
public class AreaEffectCloudListener implements Listener {
private final ArrayList<AreaEffectCloud> effectClouds = new ArrayList<>();

public AreaEffectCloudListener() {
Bukkit.getScheduler().runTaskTimer(BukkitPlugin.getInstance(), () -> {
public AreaEffectCloudListener(final BukkitPlugin plugin) {
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
final Set<Player> affectedPlayers = Bukkit.getOnlinePlayers().stream().filter(p -> Via.getAPI().getPlayerVersion(p) <= ProtocolVersion.v1_8.getVersion()).collect(Collectors.toSet());
effectClouds.removeIf(e -> !e.isValid());
effectClouds.forEach(cloud -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BrewingListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) {
if (!e.hasBlock() || e.getClickedBlock().getType() != Material.BREWING_STAND) return;
Player player = (Player) e.getPlayer();
Player player = e.getPlayer();
int version = Via.getAPI().getPlayerVersion(player);
if (version > 79) return;
ItemStack blazePowder = new ItemStack(Material.BLAZE_POWDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,66 @@
package com.viaversion.viarewind.legacysupport.listener;

import com.viaversion.viaversion.api.Via;
import org.bukkit.Location;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;

@SuppressWarnings("unchecked")
public class ElytraListener implements Listener {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
if (!p.isGliding()) return;
if (Via.getAPI().getPlayerVersion(p) > 76) return;
final Player player = e.getPlayer();

if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_9.getVersion()) return; // Only apply for 1.8 and below players
if (!player.isGliding()) return; // Only apply if the player is gliding

final Vector direction = player.getLocation().getDirection();
final Vector velocity = player.getVelocity();

Location loc = p.getLocation();
Vector velocity = p.getVelocity();
Vector direction = loc.getDirection();
double motionX = velocity.getX();
double motionY = velocity.getY();
double motionZ = velocity.getZ();

float pitch = loc.getPitch() * 0.017453292F;
float pitch = player.getLocation().getPitch() * 0.017453292F;
double directionH = Math.sqrt(direction.getX() * direction.getX() + direction.getZ() * direction.getZ());
double speedH = Math.sqrt(motionX * motionX + motionZ * motionZ);
float speedV = (float) Math.cos(pitch);

speedV = (float) (speedV * speedV * Math.min(1.0D, direction.length() / 0.4D));
motionY += -0.08D + speedV * 0.06D;

if ((motionY < 0.0D) && (directionH > 0.0D)) {
double d2 = motionY * -0.1D * speedV;
motionY += d2;
motionX += direction.getX() * d2 / directionH;
motionZ += direction.getZ() * d2 / directionH;
}

if (pitch < 0.0F) {
double speed = speedH * -Math.sin(pitch) * 0.04D;
motionY += speed * 3.2D;
motionX -= direction.getX() * speed / directionH;
motionZ -= direction.getZ() * speed / directionH;
}

if (directionH > 0.0D) {
motionX += (direction.getX() / directionH * speedH - motionX) * 0.1D;
motionZ += (direction.getZ() / directionH * speedH - motionZ) * 0.1D;
}

motionX *= 0.9900000095367432D;
motionY *= 0.9800000190734863D;
motionZ *= 0.9900000095367432D;

velocity.setX(motionX);
velocity.setY(motionY);
velocity.setZ(motionZ);

p.setVelocity(velocity);
player.setVelocity(velocity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.viaversion.viarewind.legacysupport.listener;

import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -32,52 +33,76 @@

import java.util.Map;

@SuppressWarnings("unchecked")
public class EnchantingListener implements Listener {

private final boolean newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null;
private final Material lapisMaterial = newMaterialNames ? Material.LAPIS_LAZULI : Material.getMaterial("INK_SACK");
private final boolean newMaterialNames;
private final Material lapisMaterial;

public EnchantingListener() {
newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null;

if (newMaterialNames) {
lapisMaterial = Material.LAPIS_LAZULI;
} else {
lapisMaterial = Material.getMaterial("INK_SACK");
}
}

@EventHandler
public void onInventoryOpen(InventoryOpenEvent e) {
if (!(e.getInventory() instanceof EnchantingInventory)) return;
Player player = (Player) e.getPlayer();
if (Via.getAPI().getPlayerVersion(player) > 5) return;
PlayerInventory playerInventory = player.getInventory();
ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4);

final Player player = (Player) e.getPlayer();
if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return;

final PlayerInventory inv = player.getInventory();
final ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4);

int amount = 0;
for (int i = 0; i < playerInventory.getSize(); i++) {
ItemStack item = playerInventory.getItem(i);
for (int i = 0; i < inv.getSize(); i++) {
ItemStack item = inv.getItem(i);

if (item == null || !item.isSimilar(lapis)) continue;

if (amount + item.getAmount() > 64) {
item.setAmount(amount + item.getAmount() - 64);
amount = 64;
} else {
amount += item.getAmount();
item = new ItemStack(Material.AIR);
}
playerInventory.setItem(i, item);

inv.setItem(i, item);
if (amount == 64) break;
}

if (amount == 0) return;
EnchantingInventory inventory = (EnchantingInventory) e.getInventory();

final EnchantingInventory replacement = (EnchantingInventory) e.getInventory();
lapis.setAmount(amount);
inventory.setSecondary(lapis);
replacement.setSecondary(lapis);
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
if (!(e.getInventory() instanceof EnchantingInventory)) return;
Player player = (Player) e.getPlayer();
int version = Via.getAPI().getPlayerVersion(player);
if (version > 5) return;
PlayerInventory playerInventory = player.getInventory();
EnchantingInventory inventory = (EnchantingInventory) e.getInventory();
ItemStack item = inventory.getSecondary();

final Player player = (Player) e.getPlayer();
if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return;

final PlayerInventory inv = player.getInventory();
final EnchantingInventory replacement = (EnchantingInventory) e.getInventory();

final ItemStack item = replacement.getSecondary();
if (item == null || item.getType() == Material.AIR) return;
inventory.setSecondary(new ItemStack(Material.AIR));
Map<Integer, ItemStack> remaining = playerInventory.addItem(item);

replacement.setSecondary(new ItemStack(Material.AIR));

Map<Integer, ItemStack> remaining = inv.addItem(item);
if (!remaining.isEmpty()) {
Location location = player.getLocation();
final Location location = player.getLocation();

for (ItemStack value : remaining.values()) {
player.getWorld().dropItem(location, value);
}
Expand Down
Loading

0 comments on commit 8cd7698

Please sign in to comment.