-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
1.0: | ||
Initial release | ||
|
||
1.1: | ||
Changed constant multiplier to a variable one(commands) | ||
Changed "load" and "unload" messages | ||
|
||
1.1.1: | ||
Added more feedback on commands | ||
|
||
1.2: | ||
Sign-commands | ||
fly-signs | ||
|
||
1.2.1: | ||
Removed forgotten debug message spamming console | ||
|
||
1.3: | ||
Cmd uses now permissions | ||
|
||
1.3.1: | ||
Fixed nofly bug | ||
|
||
1.4: | ||
Full permissions support | ||
|
||
1.5: | ||
New event API | ||
1.2.3 -support | ||
|
||
1.6: | ||
1.2.5 -support | ||
|
||
1.6.2: | ||
Building against 1.4.6 | ||
|
||
1.6.3: | ||
Building against 1.5.2 | ||
Fixing version numbers | ||
|
||
13.2 | ||
Migration to SpigotAPI | ||
|
||
14.0 | ||
VehicleMoveEvent fix | ||
|
||
15.0.3 | ||
compatibility update for MC1.15+ | ||
|
||
16.0.3 | ||
stability update | ||
fixed CraftBukkit ignoring the global speed. | ||
|
||
17.0.2 | ||
Added support for 1.17, updated mapping and fixed "[msp] fly". | ||
Only tested on Spigot as other forks are not available yet. | ||
Backwards compatibility untested, but should work fine, | ||
please note there is currently cap at speed 4 when dynamically | ||
changing speed due to some strange minecart behavior that could | ||
occur when moving faster in versions grater than 1.13, if you | ||
need faster speed and have an older server version you can | ||
simply use an older version of this resource. | ||
|
||
17.0.3 | ||
This is just a quick update to fix a mistake i made in spelling. | ||
|
||
|
||
18.0.1 | ||
Migrated from the SpigotAPI to the PaperAPI and replaced all spigot | ||
packages with their bukkit equivalents for maximum compatibility | ||
Changed the blue text to a more modern style as requested by a multiple users | ||
forced a global minecart speed limit of 4 (forgot to cap global in the last update) | ||
it is now possible to use decimal numbers for a more specific speed | ||
Fully compatible with Bukkit, Spigot, Paper and all it's forks | ||
[ https://imgur.com/a/4T1SLcZ ] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
73 changes: 73 additions & 0 deletions
73
src/main/java/fi/dy/esav/Minecart_speedplus/Minecart_speedplus.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package fi.dy.esav.Minecart_speedplus; | ||
|
||
import java.util.logging.Logger; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class Minecart_speedplus extends JavaPlugin { | ||
Logger log = Logger.getLogger("Minecraft"); | ||
|
||
private final Minecart_speedplusVehicleListener VehicleListener = new Minecart_speedplusVehicleListener(this); | ||
|
||
private final Minecart_speedplusSignListener SignListener = new Minecart_speedplusSignListener(this); | ||
|
||
static double speedmultiplier = 1.25D; | ||
|
||
boolean result; | ||
|
||
double multiplier; | ||
|
||
public static double getSpeedMultiplier() { | ||
return speedmultiplier; | ||
} | ||
|
||
public boolean setSpeedMultiplier(double multiplier) { | ||
if ((((0.0D < multiplier) ? 1 : 0) & ((multiplier <= 4.0D) ? 1 : 0)) != 0) { | ||
speedmultiplier = multiplier; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void onEnable() { | ||
this.log.info(getDescription().getName() + " version " + getDescription().getVersion() + " started."); | ||
PluginManager pm = getServer().getPluginManager(); | ||
pm.registerEvents(this.VehicleListener, (Plugin)this); | ||
pm.registerEvents(this.SignListener, (Plugin)this); | ||
} | ||
|
||
public void onDisable() { | ||
this.log.info(getDescription().getName() + " version " + getDescription().getVersion() + " stopped."); | ||
} | ||
|
||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
if (cmd.getName().equalsIgnoreCase("msp")) { | ||
if (sender instanceof Player) { | ||
Player player = (Player)sender; | ||
if (!player.hasPermission("msp.cmd")) { | ||
player.sendMessage("You don't have permission to do that"); | ||
return true; | ||
} | ||
} | ||
try { | ||
this.multiplier = Double.parseDouble(args[0]); | ||
} catch (Exception e) { | ||
sender.sendMessage(ChatColor.YELLOW + "should be a number"); | ||
return false; | ||
} | ||
this.result = setSpeedMultiplier(this.multiplier); | ||
if (this.result) { | ||
sender.sendMessage(ChatColor.YELLOW + "multiplier for new Minecarts set to: + this.multiplier); | ||
return true; | ||
} | ||
sender.sendMessage(ChatColor.YELLOW + "can not be set to zero and must be below"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/fi/dy/esav/Minecart_speedplus/Minecart_speedplusSignListener.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fi.dy.esav.Minecart_speedplus; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.SignChangeEvent; | ||
|
||
public class Minecart_speedplusSignListener implements Listener { | ||
|
||
Minecart_speedplus plugin; | ||
|
||
public Minecart_speedplusSignListener(Minecart_speedplus instance) { | ||
|
||
plugin = instance; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL) | ||
public void onSignChange (SignChangeEvent e) { | ||
if(e.getLine(0).equalsIgnoreCase("[msp]")){ | ||
if(e.getLine(1).equalsIgnoreCase("fly") || e.getLine(1).equalsIgnoreCase("nofly")){ | ||
if(!(e.getPlayer().hasPermission("msp.signs.fly"))) { | ||
e.setLine(0, "NO PERMS"); | ||
} | ||
} else { | ||
boolean error = false; | ||
double speed = -1; | ||
|
||
try { | ||
speed = Double.parseDouble(e.getLine(1)); | ||
} catch (Exception ex) { | ||
error = true; | ||
} | ||
|
||
if (error || 50 < speed || speed < 0) { | ||
e.setLine(1, "WRONG VALUE"); | ||
} | ||
|
||
if(!(e.getPlayer().hasPermission("msp.signs.speed"))) { | ||
e.setLine(0, "NO PERMS"); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
127 changes: 127 additions & 0 deletions
127
src/main/java/fi/dy/esav/Minecart_speedplus/Minecart_speedplusVehicleListener.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package fi.dy.esav.Minecart_speedplus; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.entity.Minecart; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.vehicle.VehicleCreateEvent; | ||
import org.bukkit.event.vehicle.VehicleMoveEvent; | ||
import org.bukkit.util.Vector; | ||
|
||
public class Minecart_speedplusVehicleListener implements Listener { | ||
|
||
int[] xmodifier = { -1, 0, 1 }; | ||
int[] ymodifier = { -2, -1, 0, 1, 2 }; | ||
int[] zmodifier = { -1, 0, 1 }; | ||
|
||
int cartx, carty, cartz; | ||
int blockx, blocky, blockz; | ||
|
||
Block block; | ||
int blockid; | ||
|
||
double line1; | ||
|
||
public static Minecart_speedplus plugin; | ||
Logger log = Logger.getLogger("Minecraft"); | ||
|
||
boolean error; | ||
|
||
Vector flyingmod = new Vector(10 , 0.01 , 10); | ||
Vector noflyingmod = new Vector(1, 1, 1); | ||
|
||
public Minecart_speedplusVehicleListener(Minecart_speedplus instance) { | ||
plugin = instance; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL) | ||
public void onVehicleCreate(VehicleCreateEvent event) { | ||
if (event.getVehicle() instanceof Minecart) { | ||
|
||
Minecart cart = (Minecart) event.getVehicle(); | ||
cart.setMaxSpeed(0.4 * Minecart_speedplus.getSpeedMultiplier()); | ||
|
||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL) | ||
public void onVehicleMove(VehicleMoveEvent event) { | ||
|
||
if (event.getVehicle() instanceof Minecart) { | ||
|
||
Minecart cart = (Minecart) event.getVehicle(); | ||
for (int xmod : xmodifier) { | ||
for (int ymod : ymodifier) { | ||
for (int zmod : zmodifier) { | ||
|
||
cartx = cart.getLocation().getBlockX(); | ||
carty = cart.getLocation().getBlockY(); | ||
cartz = cart.getLocation().getBlockZ(); | ||
blockx = cartx + xmod; | ||
blocky = carty + ymod; | ||
blockz = cartz + zmod; | ||
block = cart.getWorld().getBlockAt(blockx, blocky, | ||
blockz); | ||
blockid = cart.getWorld().getBlockTypeIdAt(blockx, | ||
blocky, blockz); | ||
|
||
if (blockid == Material.WALL_SIGN.getId() | ||
|| blockid == Material.SIGN_POST.getId()) { | ||
Sign sign = (Sign) block.getState(); | ||
String[] text = sign.getLines(); | ||
|
||
if (text[0].equalsIgnoreCase("[msp]")) { | ||
|
||
if (text[1].equalsIgnoreCase("fly")) { | ||
cart.setFlyingVelocityMod(flyingmod); | ||
|
||
} else if (text[1].equalsIgnoreCase("nofly")) { | ||
|
||
cart.setFlyingVelocityMod(noflyingmod); | ||
|
||
} else { | ||
|
||
error = false; | ||
try { | ||
|
||
line1 = Double.parseDouble(text[1]); | ||
|
||
} catch (Exception e) { | ||
|
||
sign.setLine(2, " ERROR"); | ||
sign.setLine(3, "WRONG VALUE"); | ||
sign.update(); | ||
error = true; | ||
|
||
} | ||
if (!error) { | ||
|
||
if (0 < line1 & line1 <= 50) { | ||
|
||
cart.setMaxSpeed(0.4D * Double.parseDouble(text[1])); | ||
|
||
} else { | ||
|
||
sign.setLine(2, " ERROR"); | ||
sign.setLine(3, "WRONG VALUE"); | ||
sign.update(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: MinecartSpeedPlus | ||
main: fi.dy.esav.Minecart_speedplus.Minecart_speedplus | ||
version: 18.0.1 | ||
commands: | ||
msp: | ||
description: Sets new minecart speed limit. | ||
usage: | | ||
"/msp <multiplier>" #limet = 4 | ||
permissions: | ||
msp.*: | ||
description: Gives access to all msp features | ||
default: op | ||
children: | ||
msp.cmd: true | ||
msp.signs: true | ||
msp.cmd: | ||
description: Allows you to use speed cmd | ||
default: op | ||
msp.signs: | ||
description: Allows you to create both signs #limet = 4 | ||
default: op | ||
children: | ||
msp.signs.speed: true | ||
msp.signs.fly: true | ||
msp.signs.speed: | ||
description: Allows you to create speed-sings #limet = 4 | ||
default: op | ||
msp.signs.fly: | ||
description: Allows you to create fly-signs | ||
default: op |