Skip to content

Commit

Permalink
added the 1.12 piston dupe
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan8or committed Jan 12, 2023
1 parent 2de3f36 commit 8c130a2
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 12 deletions.
12 changes: 4 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ plugins {

repositories {
mavenLocal()
maven {
url = 'https://nexus.umbcraft.online/repository/umbcraft-pub/'
}
maven {
url = 'https://nexus.umbcraft.online/repository/proxies/'
}
mavenCentral()
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
}

dependencies {
implementation 'org.bstats:bstats-bukkit:2.2.1'
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
}

final String basePackage = "online.umbcraft.libs"
Expand All @@ -28,7 +24,7 @@ shadowJar {
}

group = 'online.umbcraft.libraries'
version = '1.4.7'
version = '1.5.0'
description = 'Golden Dupes - dupes from the Golden days of minecraft!'
sourceCompatibility = '1.8'

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/online/umbcraft/libraries/GoldenDupes.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ public void onEnable() {
return categories[categories.length-1];
}));

final ConfigPath[] allDoFlags = {
ConfigPath.AUTOCRAFT_DO,
ConfigPath.PISTON_DO,
ConfigPath.NETHER_DO,
ConfigPath.ANVIL_DO,
ConfigPath.DONKEY_DO};


for(ConfigPath dupe: allDoFlags) {
metrics.addCustomChart(new SimplePie(dupe.toString(),
() -> {
return getConfig().getString(dupe.path());
}));
}


// fixing up config if it doesn't have some particular settings
ConfigAutofill.autofill(this);
Expand All @@ -84,10 +99,18 @@ public void onEnable() {
new NetherPortalDupe(this), this);
}

// starts anvil dupe handler if the dupe is enabled
if (getConfig().getBoolean(ConfigPath.ANVIL_DO.path())) {
getServer().getPluginManager().registerEvents(
new AnvilDupe(this), this);
}

// starts piston dupe handler if the dupe is enabled
if (getConfig().getBoolean(ConfigPath.PISTON_DO.path())) {
getServer().getPluginManager().registerEvents(
new PistonDupe(this), this);
}

}

}
14 changes: 12 additions & 2 deletions src/main/java/online/umbcraft/libraries/config/ConfigPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@ public enum ConfigPath {
NETHER_DO(ConfigRoot.NETHER_PORTAL, "enabled", "true"),

// how many ticks of freedom should be given before the items are no longer dupeable
NETHER_TICKDELAY(ConfigRoot.NETHER_PORTAL, "tick-delay", "3"),
NETHER_TICKDELAY(ConfigRoot.NETHER_PORTAL, "tick-delay", "5"),



// is the donkey dupe enabled?
// is the anvil dupe enabled?
ANVIL_DO(ConfigRoot.ANVIL, "enabled", "true"),



// is the piston dupe enabled?
PISTON_DO(ConfigRoot.PISTON, "enabled", "true"),

PISTON_TICKDELAY(ConfigRoot.PISTON, "tick-delay", "5"),

PISTON_NONPLAYER(ConfigRoot.PISTON, "non-players", "true"),





// should shulker boxes be duped at all?
NON_STACK_DO_DUPE(ConfigRoot.NON_STACK, "dupe", "true"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public enum ConfigRoot {
// 1.17 anvil dupe root path
ANVIL("anvil-dupe"),

// 1.12 piston dupe
PISTON("piston-dupe"),



// item limits root path
NON_STACK("non-stackables"),
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/online/umbcraft/libraries/dupes/PistonDupe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package online.umbcraft.libraries.dupes;

import online.umbcraft.libraries.GoldenDupes;
import online.umbcraft.libraries.config.ConfigPath;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import java.util.*;

public class PistonDupe extends Dupe implements Listener {

// set of all item frames which qualify to have their items duped
final private Set<UUID> dupableFrames = new HashSet<>();

public PistonDupe(final GoldenDupes plugin) {
super(plugin);
}

// marks an item frame as dupable if it was recently exposed to the back of a retracting piston
@EventHandler(priority = EventPriority.NORMAL)
public void onPistonRetract(final BlockPistonRetractEvent e) {
World world = e.getBlock().getWorld();
Vector pistonLoc = e.getBlock().getLocation().toVector();

int xoff = -1 * e.getDirection().getModX();
int yoff = -1 * e.getDirection().getModY();
int zoff = -1 * e.getDirection().getModZ();

// amount to offset the regular piston coords by
Vector buttOffset = new Vector(0.5*xoff + 0.5,0.5*yoff + 0.5,0.5*zoff + 0.5);

// center of the face of the butt of the piston
Location pistonButtInWorld = pistonLoc.add(buttOffset).toLocation(world);

// all entities pressed against the butt of the piston
Collection<Entity> nearbyEntities = e.getBlock().getWorld().getNearbyEntities(pistonButtInWorld,0.05,0.05,0.05);

// mark the itemframe as valid for duping for the next few ticks, specified by tickdelay in the config
for(Entity frame : nearbyEntities) {
if (!(frame instanceof ItemFrame))
continue;

dupableFrames.add(frame.getUniqueId());
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
dupableFrames.remove(frame.getUniqueId());
}, plugin.getConfig().getLong(ConfigPath.PISTON_TICKDELAY.path()));
return;
}
}


// dupes the item in an item frame as it is being broken (if it was marked as dupable)
@EventHandler(priority = EventPriority.HIGH)
public void onBreakFrame(EntityDamageByEntityEvent e) {

// only continue if an itemframe is damaged
if(!(e.getEntity() instanceof ItemFrame))
return;

ItemFrame frame = (ItemFrame) e.getEntity();

// ignore frames that are not being duped from
if(!dupableFrames.contains(frame.getUniqueId()))
return;

// only players can trigger the dupe if non-players is set to false
if(!plugin.getConfig().getBoolean(ConfigPath.PISTON_NONPLAYER.path()) && !(e.getDamager() instanceof Player))
return;

// dupe the item and spawn it along with the original item
ItemStack duped = this.dupe(frame.getItem(),1);
frame.getWorld().dropItemNaturally(frame.getLocation(), duped);
}
}
17 changes: 15 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nether-portal:
enabled: true

# how long should the minecart wait before it doesn't dupe items removed from it
tick-delay: 3
tick-delay: 5


# 1.17 anvil dupe
Expand All @@ -52,6 +52,19 @@ anvil-dupe:
enabled: true


# 1.12 piston dupe
piston-dupe:

# is this dupe enabled?
enabled: true

# how long should the piston's itemframe wait before it doesn't dupe after it is broken
tick-delay: 5

# can dispensers and other non-player sources dupe items from item frames
non-players: true


########################
# GLOBAL ITEM SETTINGS #
########################
Expand All @@ -70,7 +83,7 @@ shulkers:
# what is the max duped stack size?
stack-to: 1

# totems pf undying
# totems of undying
totems:
# can they be duped?
dupe: true
Expand Down

0 comments on commit 8c130a2

Please sign in to comment.