Skip to content

Instantly share code, notes, and snippets.

@inklit
Created October 2, 2016 07:42
Show Gist options
  • Save inklit/c208a36bd5901d56db13ec9b0add94a1 to your computer and use it in GitHub Desktop.
Save inklit/c208a36bd5901d56db13ec9b0add94a1 to your computer and use it in GitHub Desktop.
package me.acul.me;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import java.util.Arrays;
/**
* Created by Luca on 02.10.16.
*/
@Plugin(id = "logdupepatch", name = "LogDupePatch", version = "1.0")
public class main {
String[] players = {};
@Listener
public void PlayerJoin(ClientConnectionEvent.Join evt) {
String uuid = evt.getTargetEntity().getUniqueId().toString();
if (Arrays.asList(players).contains(uuid)){
evt.getTargetEntity().kick(Text.of("You are already logged in!"));
} else {
players = ArrayUtils.add(players, uuid);
}
}
@Listener
public void PlayerLeave(ClientConnectionEvent.Disconnect evt) {
players = ArrayUtils.removeElement(players, evt.getTargetEntity().getUniqueId().toString());
}
}
@Luca0208
Copy link

Luca0208 commented Oct 2, 2016

Thanks I applied the changes(I made the plugin for inklit)

package me.acul.logdupepatch;

import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;

/**
 * Created by Luca on 02.10.16.
 */
@Plugin(id = "logdupepatch", name = "LogDupePatch", version = "1.0")
public class Main {
    Set<UUID> players = new LinkedHashSet<>();
    @Listener
    public void PlayerJoin(ClientConnectionEvent.Join evt) {
        if (!players.add(evt.getTargetEntity().getUniqueId())){
            evt.getTargetEntity().kick(Text.of("You are already logged in!"));
        }
    }

    @Listener
    public void PlayerLeave(ClientConnectionEvent.Disconnect evt) {
        players.remove(evt.getTargetEntity().getUniqueId());
    }
}

@inklit
Copy link
Author

inklit commented Oct 2, 2016

Let me test the update and I will then upload it to my site for distribution. Thanks @Luca0208!

EDIT: Tested and it works. Here's the updated jar. http://switchcraft.pw/logdupepatch-2.0-snapshot.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment