Skip to content

Commit

Permalink
[CI skip] Very small improvements to cargo networks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Mar 24, 2020
1 parent aa5ab65 commit f8d1747
Show file tree
Hide file tree
Showing 20 changed files with 608 additions and 478 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
* Teleporters are now significantly faster
* Item permissions have been moved to a seperate permissions.yml file
* Salt now only requires 2 blocks of Sand
* Firework from researcheing no longer damages entities
* Fireworks from researching no longer damages entities
* Very slight performance improvements for Cargo networks

#### Fixes
* Fixed some languages showing numbers larger than 100%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import org.bukkit.event.HandlerList;

import io.github.thebusybiscuit.slimefun4.implementation.items.androids.AndroidInstance;
import io.github.thebusybiscuit.slimefun4.implementation.items.androids.MinerAndroid;

/**
* This event is fired before a miner android mines a block.
* If this event is cancelled, the block will not be mined.
* This {@link Event} is fired before a {@link MinerAndroid} mines a {@link Block}.
* If this {@link Event} is cancelled, the {@link Block} will not be mined.
*
* @author poma123
*
Expand All @@ -24,9 +25,9 @@ public class AndroidMineEvent extends Event implements Cancellable {

/**
* @param block
* - mined block
* The mined {@link Block}
* @param android
* - the block of the android
* The {@link AndroidInstance} that triggered this {@link Event}
*/
public AndroidMineEvent(Block block, AndroidInstance android) {
this.block = block;
Expand All @@ -42,19 +43,19 @@ public HandlerList getHandlers() {
}

/**
* This method returns the mined block
* This method returns the mined {@link Block}
*
* @return the mined block
* @return the mined {@link Block}
*/
public Block getBlock() {
return block;
}

/**
* This method returns the block of the
* android who wants to mine a block.
* This method returns the {@link AndroidInstance} who
* triggered this {@link Event}
*
* @return the block of the android
* @return the involved {@link AndroidInstance}
*/
public AndroidInstance getAndroid() {
return android;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static HandlerList getHandlerList() {
return handlers;
}

/**
* This returns the {@link ItemStack} that is being disenchanted.
*
* @return The {@link ItemStack} that is being disenchanted
*/
public ItemStack getItem() {
return this.item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import io.github.thebusybiscuit.slimefun4.core.MultiBlock;

/**
* This {@link Event} is called when a {@link Player} interacts with a {@link MultiBlock}.
*
* @author TheBusyBiscuit
*
*/
public class MultiBlockInteractEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,30 @@ public HandlerList getHandlers() {
return handlers;
}

/**
* Returns the {@link Player} who triggered this {@link Event},
* the {@link Player} who switched his {@link Language} to be precise.
*
* @return The {@link Player} who switched his {@link Language}
*/
public Player getPlayer() {
return player;
}

/**
* This returns the {@link Language} that this {@link Player} was using before.
*
* @return The previous {@link Language} of our {@link Player}
*/
public Language getPreviousLanguage() {
return from;
}

/**
* This returns the {@link Language} that this {@link Player} wants to switch to.
*
* @return The new {@link Language}
*/
public Language getNewLanguage() {
return to;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* This {@link Event} is called whenever a {@link Player} unlocks a {@link Research}.
*
* @author TheBusyBiscuit
*
* @see Research
*
*/
public class ResearchUnlockEvent extends Event implements Cancellable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public abstract class Network {
*/
public abstract NetworkComponent classifyLocation(Location l);

/**
* This method is called whenever a {@link Location} in this {@link Network} changes
* its classification.
*
* @param l
* The {@link Location} that is changing its classification
* @param from
* The {@link NetworkComponent} this {@link Location} was previously classified as
* @param to
* The {@link NetworkComponent} this {@link Location} is changing to
*/
public abstract void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to);

protected Location regulator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,14 @@ private boolean compareBlocks(Material a, Material b) {
return true;
}

/**
* This returns whether this {@link MultiBlock} is a symmetric structure or whether
* the left and right side differ.
*
* @return Whether this {@link MultiBlock} is a symmetric structure
*/
public boolean isSymmetric() {
return this.isSymmetric;
return isSymmetric;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public class SlimefunCommand implements CommandExecutor, Listener {
private final Map<SubCommand, Integer> commandUsage = new HashMap<>();

public SlimefunCommand(SlimefunPlugin plugin) {
this.plugin = plugin;
}

public void register() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);

plugin.getCommand("slimefun").setExecutor(this);
plugin.getCommand("slimefun").setTabCompleter(new SlimefunTabCompleter(this));

this.plugin = plugin;
Commands.addCommands(this, commands);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ public static EnergyNetComponentType getComponent(Block b) {
}

public static EnergyNetComponentType getComponent(String id) {
if (SlimefunPlugin.getRegistry().getEnergyGenerators().contains(id)) return EnergyNetComponentType.GENERATOR;
if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(id)) return EnergyNetComponentType.CAPACITOR;
if (SlimefunPlugin.getRegistry().getEnergyConsumers().contains(id)) return EnergyNetComponentType.CONSUMER;
if (SlimefunPlugin.getRegistry().getEnergyGenerators().contains(id)) {
return EnergyNetComponentType.GENERATOR;
}

if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(id)) {
return EnergyNetComponentType.CAPACITOR;
}

if (SlimefunPlugin.getRegistry().getEnergyConsumers().contains(id)) {
return EnergyNetComponentType.CONSUMER;
}

return EnergyNetComponentType.NONE;
}

Expand Down Expand Up @@ -83,9 +92,9 @@ public static EnergyNet getNetworkFromLocationOrCreate(Location l) {
return energyNetwork;
}

private Set<Location> input = new HashSet<>();
private Set<Location> storage = new HashSet<>();
private Set<Location> output = new HashSet<>();
private final Set<Location> generators = new HashSet<>();
private final Set<Location> storage = new HashSet<>();
private final Set<Location> consumers = new HashSet<>();

protected EnergyNet(Location l) {
super(l);
Expand All @@ -98,7 +107,10 @@ public int getRange() {

@Override
public NetworkComponent classifyLocation(Location l) {
if (regulator.equals(l)) return NetworkComponent.REGULATOR;
if (regulator.equals(l)) {
return NetworkComponent.REGULATOR;
}

switch (getComponent(l)) {
case CAPACITOR:
return NetworkComponent.CONNECTOR;
Expand All @@ -113,19 +125,19 @@ public NetworkComponent classifyLocation(Location l) {
@Override
public void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to) {
if (from == NetworkComponent.TERMINUS) {
input.remove(l);
output.remove(l);
generators.remove(l);
consumers.remove(l);
}

switch (getComponent(l)) {
case CAPACITOR:
storage.add(l);
break;
case CONSUMER:
output.add(l);
consumers.add(l);
break;
case GENERATOR:
input.add(l);
generators.add(l);
break;
default:
break;
Expand All @@ -149,7 +161,7 @@ public void tick(Block b) {

int available = (int) supply;

for (Location destination : output) {
for (Location destination : consumers) {
int capacity = ChargableBlock.getMaxCharge(destination);
int charge = ChargableBlock.getCharge(destination);

Expand Down Expand Up @@ -186,7 +198,7 @@ public void tick(Block b) {
else ChargableBlock.setUnsafeCharge(battery, 0, true);
}

for (Location source : input) {
for (Location source : generators) {
if (ChargableBlock.isChargable(source)) {
if (available > 0) {
int capacity = ChargableBlock.getMaxCharge(source);
Expand All @@ -212,7 +224,7 @@ private double tickAllGenerators() {
double supply = 0;
Set<Location> exploded = new HashSet<>();

for (Location source : input) {
for (Location source : generators) {
long timestamp = System.currentTimeMillis();
SlimefunItem item = BlockStorage.check(source);
Config config = BlockStorage.getLocationInfo(source);
Expand All @@ -235,7 +247,7 @@ private double tickAllGenerators() {
SlimefunPlugin.getTicker().addBlockTimings(source, System.currentTimeMillis() - timestamp);
}

input.removeAll(exploded);
generators.removeAll(exploded);

return supply;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.IcyBow;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SwordOfBeheading;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.Categories;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/me/mrCookieSlime/Slimefun/Lists/Categories.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.mrCookieSlime.Slimefun.Lists;

import java.time.Month;

import org.bukkit.Material;
import org.bukkit.NamespacedKey;

Expand Down Expand Up @@ -48,10 +50,10 @@ private Categories() {}
public static final LockedCategory TALISMANS_2 = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, TALISMANS_1);

// Seasonal Categories
public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "christmas"), 12, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December only)"));
public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "valentines_day"), 2, 2, new CustomItem(Material.POPPY, "&dValentine's Day" + " &7(14th February)"));
public static final SeasonalCategory EASTER = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "easter"), 4, 2, new CustomItem(Material.EGG, "&6Easter" + " &7(April)"));
public static final SeasonalCategory BIRTHDAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "birthday"), 10, 1, new CustomItem(Material.FIREWORK_ROCKET, "&a&lTheBusyBiscuit's Birthday &7(26th October)"));
public static final SeasonalCategory HALLOWEEN = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "halloween"), 10, 1, new CustomItem(Material.JACK_O_LANTERN, "&6&lHalloween &7(31st October)"));
public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "christmas"), Month.DECEMBER, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December only)"));
public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "valentines_day"), Month.FEBRUARY, 2, new CustomItem(Material.POPPY, "&dValentine's Day" + " &7(14th February)"));
public static final SeasonalCategory EASTER = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "easter"), Month.APRIL, 2, new CustomItem(Material.EGG, "&6Easter" + " &7(April)"));
public static final SeasonalCategory BIRTHDAY = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "birthday"), Month.OCTOBER, 1, new CustomItem(Material.FIREWORK_ROCKET, "&a&lTheBusyBiscuit's Birthday &7(26th October)"));
public static final SeasonalCategory HALLOWEEN = new SeasonalCategory(new NamespacedKey(SlimefunPlugin.instance, "halloween"), Month.OCTOBER, 1, new CustomItem(Material.JACK_O_LANTERN, "&6&lHalloween &7(31st October)"));

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.mrCookieSlime.Slimefun.Objects;

import java.time.Month;
import java.util.Calendar;

import org.bukkit.NamespacedKey;
Expand All @@ -18,7 +19,7 @@
*/
public class SeasonalCategory extends Category {

private final int month;
private final Month month;

/**
* The constructor for a SeasonCategory.
Expand All @@ -32,23 +33,19 @@ public class SeasonalCategory extends Category {
* @param item
* The display item for this category
*/
public SeasonalCategory(NamespacedKey key, int month, int tier, ItemStack item) {
public SeasonalCategory(NamespacedKey key, Month month, int tier, ItemStack item) {
super(key, item, tier);

if (month < 1 || month > 12) {
throw new IllegalArgumentException("There is no month no. " + month);
}

this.month = month - 1;
this.month = month;
}

/**
* Gets the month during which the category should be displayed.
*
* @return the id of the month this {@link SeasonalCategory} is assigned to (from 1 = January ; to 12 = December)
*/
public int getMonth() {
return this.month;
public Month getMonth() {
return month;
}

/**
Expand All @@ -59,6 +56,6 @@ public int getMonth() {
*/
public boolean isUnlocked() {
Calendar calendar = Calendar.getInstance();
return month == calendar.get(Calendar.MONTH);
return month.ordinal() == calendar.get(Calendar.MONTH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
Expand All @@ -20,9 +19,6 @@

public final class SlimefunManager {

private static final String EMERALDENCHANTS_LORE = ChatColor.YELLOW.toString() + ChatColor.YELLOW.toString() + ChatColor.GRAY.toString();
private static final String SOULBOUND_LORE = ChatColor.GRAY + "Soulbound";

private SlimefunManager() {}

public static void registerArmorSet(ItemStack baseComponent, ItemStack[] items, String idSyntax, PotionEffect[][] effects, boolean magical, SlimefunAddon addon) {
Expand Down
Loading

0 comments on commit f8d1747

Please sign in to comment.