Last active
August 20, 2017 14:07
-
-
Save Alvin-LB/06c7707a4269f196eb31e5df0a3f0bc7 to your computer and use it in GitHub Desktop.
HorseCharge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration file for the HorseCharge bukkit plugin | |
# The constant amount of damage to add to a melee attack if the damager is on a horse | |
static-melee-damage-bonus: 0.0 | |
# The amount to multiply with the horse's speed on a melee attack and then add to the damage | |
multiplier-melee-damage-bonus: 0.0 | |
# The constant amount of damage to add to a ranged attack if the damager is on a horse | |
static-ranged-damage-bonus: 0.0 | |
# The amount to multiply with the horse's speed on a melee attack and then add to the damage | |
multiplier-ranged-damage-bonus: 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bringholm.horsecharge; | |
import com.google.common.collect.Sets; | |
import org.bstats.bukkit.Metrics; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Boat; | |
import org.bukkit.entity.Horse; | |
import org.bukkit.entity.Player; | |
import org.bukkit.entity.Projectile; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.EntityDamageByEntityEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.projectiles.ProjectileSource; | |
import org.bukkit.scheduler.BukkitRunnable; | |
import org.bukkit.util.Vector; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.util.Set; | |
import java.util.UUID; | |
public class HorseCharge extends JavaPlugin implements Listener { | |
private Set<UUID> debugUsers = Sets.newHashSet(); | |
@Override | |
public void onEnable() { | |
new Metrics(this); | |
this.getServer().getPluginManager().registerEvents(this, this); | |
saveDefaultConfig(); | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
if (args.length != 1 || (!args[0].equalsIgnoreCase("reload") && !args[0].equalsIgnoreCase("debug"))) { | |
sender.sendMessage(ChatColor.RED + "Incorrect arguments!"); | |
} else { | |
if (args[0].equalsIgnoreCase("reload")) { | |
if (sender.hasPermission("horsecharge.reload")) { | |
saveDefaultConfig(); | |
reloadConfig(); | |
sender.sendMessage(ChatColor.GOLD + "Reloaded configuration file!"); | |
} else { | |
sender.sendMessage(ChatColor.RED + "You don't have permission to do this!"); | |
} | |
} else { | |
if (sender.hasPermission("horsecharge.debug")) { | |
if (sender instanceof Player) { | |
UUID uuid = ((Player) sender).getUniqueId(); | |
if (debugUsers.contains(uuid)) { | |
debugUsers.remove(uuid); | |
sender.sendMessage(ChatColor.GOLD + "You will no longer receive debug messages!"); | |
} else { | |
debugUsers.add(uuid); | |
sender.sendMessage(ChatColor.GOLD + "You will now receive debug messages!"); | |
} | |
} else { | |
sender.sendMessage(ChatColor.RED + "Only players can do this!"); | |
} | |
} else { | |
sender.sendMessage(ChatColor.RED + "You don't have permission to do this!"); | |
} | |
} | |
} | |
return true; | |
} | |
@EventHandler | |
public void onDamage(EntityDamageByEntityEvent e) { | |
boolean isRanged = false; | |
Player damager = null; | |
if (e.getDamager() instanceof Player) { | |
damager = (Player) e.getDamager(); | |
} else if (e.getDamager() instanceof Projectile) { | |
ProjectileSource source = ((Projectile) e.getDamager()).getShooter(); | |
if (source != null && source instanceof Player) { | |
damager = (Player) source; | |
isRanged = true; | |
} | |
} | |
if (damager != null && damager.isInsideVehicle() && damager.getVehicle() instanceof Horse) { | |
boolean isMoving = damager.getVelocity().getX() != 0 || damager.getVelocity().getZ() != 0; | |
double currentHorseSpeed = isMoving ? ((Horse) damager.getVehicle()).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getValue() : 0; | |
double newDamage = e.getDamage(); | |
if (isRanged) { | |
newDamage += getConfig().getDouble("static-ranged-damage-bonus"); | |
newDamage += getConfig().getDouble("multiplier-ranged-damage-bonus") * currentHorseSpeed; | |
} else { | |
newDamage += getConfig().getDouble("static-melee-damage-bonus"); | |
newDamage += getConfig().getDouble("multiplier-melee-damage-bonus") * currentHorseSpeed; | |
} | |
e.setDamage(newDamage); | |
if (debugUsers.contains(damager.getUniqueId())) { | |
damager.sendMessage("[" + ChatColor.BLUE + "HorseCharge-Debug" + ChatColor.WHITE + "] Damage: " + newDamage); | |
damager.sendMessage("[" + ChatColor.BLUE + "HorseCharge-Debug" + ChatColor.WHITE + "] Speed: " + currentHorseSpeed); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: HorseCharge | |
main: com.bringholm.horsecharge.HorseCharge | |
version: 1.0-SNAPSHOT | |
author: AlvinB | |
commands: | |
horsecharge: | |
description: | | |
/horsecharge reload - Reloads the configuration file | |
/horsecharge debug - Displays debug info when you hit a mob on a horse | |
usage: /horsecharge <reload|debug> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<!-- NOTE: For the craftbukkit dependency to work correctly, you need to run BuildTools at least | |
once with the appropriate version --> | |
<groupId>com.bringholm.horsecharge</groupId> | |
<artifactId>HorseCharge</artifactId> | |
<packaging>jar</packaging> | |
<version>1.0-SNAPSHOT</version> | |
<name>HorseCharge</name> | |
<url>http://www.bringholm.com</url> | |
<properties> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
</properties> | |
<repositories> | |
<repository> | |
<id>bstats-repo</id> | |
<url>http://repo.bstats.org/content/repositories/releases/</url> | |
</repository> | |
</repositories> | |
<dependencies> | |
<dependency> | |
<groupId>org.bukkit</groupId> | |
<artifactId>craftbukkit</artifactId> | |
<version>1.12.1-R0.1-SNAPSHOT</version> | |
</dependency> | |
<dependency> | |
<groupId>org.bstats</groupId> | |
<artifactId>bstats-bukkit</artifactId> | |
<version>1.2</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-jar-plugin</artifactId> | |
<version>2.3.1</version> | |
<configuration> | |
<outputDirectory>run/plugins</outputDirectory> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-shade-plugin</artifactId> | |
<version>2.4</version> | |
<configuration> | |
<artifactSet> | |
<includes> | |
<include>org.bstats:*</include> | |
</includes> | |
</artifactSet> | |
<relocations> | |
<relocation> | |
<pattern>org.bstats</pattern> | |
<shadedPattern>com.bringholm.horsecharge.metrics</shadedPattern> | |
</relocation> | |
</relocations> | |
</configuration> | |
<executions> | |
<execution> | |
<phase>package</phase> | |
<goals> | |
<goal>shade</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment