Skip to content

Commit

Permalink
1.16.5b3 (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mineshafter61 committed Apr 7, 2021
1 parent 9b4ca15 commit 98379ba
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>mikeshafter</groupId>
<artifactId>OldThrottle</artifactId>
<version>1.16.5b1</version>
<version>1.16.5b3</version>
<packaging>jar</packaging>

<name>OldThrottle</name>
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/mikeshafter/oldthrottle/OldThrottle.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ public void onEnable() {
saveConfig();

Throttle throttle = new Throttle();
TrainAnnounce trainAnnounce = new TrainAnnounce();
getServer().getPluginManager().registerEvents(throttle, this);
Objects.requireNonNull(getCommand("throttle")).setExecutor(throttle);
Objects.requireNonNull(getCommand("ta")).setExecutor(trainAnnounce);

getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
throttle.repeatThrottle();
}
}, 0L, 1L);
getServer().getScheduler().scheduleSyncRepeatingTask(this, throttle::repeatThrottle, 0L, 1L);
}

@Override
Expand Down
101 changes: 54 additions & 47 deletions src/main/java/mikeshafter/oldthrottle/Throttle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mikeshafter.oldthrottle;

import com.bergerkiller.bukkit.tc.controller.MinecartGroupStore;
import com.bergerkiller.bukkit.tc.properties.CartProperties;
import com.bergerkiller.bukkit.tc.properties.TrainProperties;
import com.bergerkiller.bukkit.tc.signactions.SignActionAnnounce;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -38,57 +40,61 @@ public class Throttle implements Listener, CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
if (command.getName().equalsIgnoreCase("throttle")){
FileConfiguration config = plugin.getConfig();

// Switch on Throttle
if (args.length == 1 && args[0].equalsIgnoreCase("on")){
Player player = (Player) sender;
// If it is already on do nothing
if (accelerationHashMap.get(player) != null){
sender.sendMessage(ChatColor.AQUA+"Throttle has already been turned on.");
}
// Else do something; include player in playerSpeed and playerAcceleration hashmaps
else {
speedHashMap.put(player, 0F);
accelerationHashMap.put(player, 0);
sender.sendMessage(ChatColor.AQUA+"Throttle has been enabled.");
// Store inventory
for (int i = 0; i < 41; i++){
config.set("inv."+player.getName()+"."+i, player.getInventory().getItem(i));
if (sender instanceof Player && sender.hasPermission("OldThrottle.throttle")){
FileConfiguration config = plugin.getConfig();

// Switch on Throttle
if (args.length == 1 && args[0].equalsIgnoreCase("on")){
Player player = (Player) sender;
// If it is already on do nothing
if (accelerationHashMap.get(player) != null){
sender.sendMessage(ChatColor.AQUA+"Throttle has already been turned on.");
}
plugin.saveConfig();
// Else do something; include player in playerSpeed and playerAcceleration hashmaps
else {
speedHashMap.put(player, 0F);
accelerationHashMap.put(player, 0);
modeHashMap.put(player, (byte) 0);
sender.sendMessage(ChatColor.AQUA+"Throttle has been enabled.");
// Store inventory
for (int i = 0; i < 41; i++){
config.set("inv."+player.getName()+"."+i, player.getInventory().getItem(i));
}
plugin.saveConfig();
}

// Make items into OldThrottle controls
invItemsPg1(player);
return true;
}

// Make items into OldThrottle controls
invItems(player);
return true;
}

// Switch off throttle
else if (args.length == 1 && args[0].equalsIgnoreCase("off")){
Player player = (Player) sender;
//but do nothing if throttle was already off
if (accelerationHashMap.get(player) == null){
sender.sendMessage(ChatColor.AQUA+"Throttle has already been turned off.");
} else {
//remove speed and acceleration hashmap entry
speedHashMap.remove(player);
accelerationHashMap.remove(player);
modeHashMap.remove(player);
//restore inventory
for (int i = 0; i < 41; i++){
player.getInventory().setItem(i, (ItemStack) config.get("inv."+player.getName()+"."+i));
// Switch off throttle
else if (args.length == 1 && args[0].equalsIgnoreCase("off")){
Player player = (Player) sender;
//but do nothing if throttle was already off
if (accelerationHashMap.get(player) == null){
sender.sendMessage(ChatColor.AQUA+"Throttle has already been turned off.");
} else {
//remove speed and acceleration hashmap entry
speedHashMap.remove(player);
accelerationHashMap.remove(player);
modeHashMap.remove(player);
//restore inventory
for (int i = 0; i < 41; i++){
player.getInventory().setItem(i, (ItemStack) config.get("inv."+player.getName()+"."+i));
}
//send message to player
sender.sendMessage(ChatColor.AQUA+"Throttle turned off");
}
//send message to player
sender.sendMessage(ChatColor.AQUA+"Throttle turned off");
return true;
}
return true;
}
}

return false;
}

public void invItems(Player player) {
public void invItemsPg1(Player player) {
ItemStack item = new ItemStack(Material.BLUE_CONCRETE, 1);
ItemMeta itemMeta = item.getItemMeta();
assert itemMeta != null;
Expand Down Expand Up @@ -120,11 +126,7 @@ public void invItems(Player player) {
item.setItemMeta(itemMeta);
player.getInventory().setItem(6, item);
item.setType(Material.LIGHT_GRAY_CONCRETE);
itemMeta.setDisplayName("Turn Left");
item.setItemMeta(itemMeta);
player.getInventory().setItem(7, item);
item.setType(Material.LIGHT_GRAY_CONCRETE);
itemMeta.setDisplayName("Turn Right");
itemMeta.setDisplayName("More");
item.setItemMeta(itemMeta);
player.getInventory().setItem(8, item);
}
Expand Down Expand Up @@ -173,6 +175,7 @@ public void onInteract(PlayerInteractEvent event){
accelerationHashMap.put(player, 0);
break;
case "Off and Release":
if (speedHashMap.get(player) < 0.1f) player.performCommand("train launch 15");
modeHashMap.put(player, (byte) 0);
accelerationHashMap.put(player, 0);
break;
Expand All @@ -189,12 +192,16 @@ public void onInteract(PlayerInteractEvent event){
modeHashMap.put(player, (byte) 0);
speedHashMap.put(player, Float.valueOf(String.format("%.1f", speedHashMap.get(player))));
accelerationHashMap.put(player, 0);
break;
case "More":
//TODO: Inventory Page 2
break;
}
}
event.setCancelled(true);
}
if (action == Action.RIGHT_CLICK_BLOCK && speedHashMap.containsKey(player)) // Make items into OldThrottle controls
invItems(player);
invItemsPg1(player);
}

public void repeatThrottle() {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/mikeshafter/oldthrottle/TrainAnnounce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mikeshafter.oldthrottle;

import com.bergerkiller.bukkit.tc.controller.MinecartGroupStore;
import com.bergerkiller.bukkit.tc.signactions.SignActionAnnounce;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Objects;


public class TrainAnnounce implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (command.getName().equalsIgnoreCase("ta")){
if (sender instanceof Player && sender.hasPermission("OldThrottle.ta")){
Player player = (Player) sender;
player.sendMessage("it works! (debug code)");
String message = String.join(" ", args);
SignActionAnnounce.sendMessage(null, MinecartGroupStore.get(player), message);
return true;
}
}

else if (command.getName().equalsIgnoreCase("setunloadedblock")){
if (args.length == 5) {
Location blockLoc = new Location(Bukkit.getWorld(args[0]), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]));
if (!blockLoc.getChunk().isLoaded())
blockLoc.getChunk().load();
blockLoc.getBlock().setType(Objects.requireNonNull(Material.getMaterial(args[4].toUpperCase())));
if (blockLoc.getBlock().getType() == Material.getMaterial(args[4].toUpperCase())) {
sender.sendMessage(String.format("Placed %s at world %s, x=%s y=%s z=%s]", args[4], args[0], args[1], args[2], args[3]));
blockLoc.getChunk().unload();
return true;
}
}
}

return false;
}
}
13 changes: 13 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ commands:
throttle:
usage: /throttle <on|off>
description: Toggles throttle
ta:
usage: /ta <message>
description: Makes an announcement
setunloadedblock:
usage: /setunloadedblock <world> <x> <y> <z> <block>
description: Sets a block in an unloaded chunk
permissions:
OldThrottle.throttle:
default: true
description: Lets players use throttle controls
OldThrottle.ta:
default: op
description: Gives access to the /ta command
description: Old throttle system inspired by the JR 103 series.

0 comments on commit 98379ba

Please sign in to comment.